-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from OctopusDeploy/enhancement-keyvault
Azure Key Vault specific xml does not break calmari
- Loading branch information
Showing
13 changed files
with
135 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
source/Calamari.Azure.Tests/ResourceGroups/ResourceGroupTemplateNormalizerFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.IO; | ||
using Calamari.Azure.Deployment.Integration.ResourceGroups; | ||
using NUnit.Framework; | ||
|
||
namespace Calamari.Azure.Tests.ResourceGroups | ||
{ | ||
[TestFixture] | ||
public class ResourceGroupTemplateNormalizerFixture | ||
{ | ||
ResourceGroupTemplateNormalizer subject; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
subject = new ResourceGroupTemplateNormalizer(); | ||
} | ||
|
||
[Test] | ||
public void ShouldNormallizeParametersWithEnvelope() | ||
{ | ||
var result = subject.Normalize(ReadParametersFile("params_with_envelope.json")); | ||
|
||
Assert.AreEqual(StripWhiteSpace(GetParameter()), StripWhiteSpace(result)); | ||
} | ||
|
||
[Test] | ||
public void ShouldNormallizeParametersSansEnvelope() | ||
{ | ||
var result = subject.Normalize(ReadParametersFile("params_sans_envelope.json")); | ||
|
||
Assert.AreEqual(StripWhiteSpace(GetParameter()), StripWhiteSpace(result)); | ||
} | ||
|
||
private string ReadParametersFile(string fileName) | ||
{ | ||
var path = GetType().Namespace.Replace("Calamari.Azure.Tests.", String.Empty); | ||
path = path.Replace('.', Path.DirectorySeparatorChar); | ||
return File.ReadAllText(Path.Combine(AzureTestEnvironment.TestWorkingDirectory, path, fileName)); | ||
} | ||
|
||
private string StripWhiteSpace(string input) | ||
{ | ||
return input.Replace(" ", string.Empty) | ||
.Replace(Environment.NewLine, string.Empty); | ||
} | ||
|
||
private string GetParameter() | ||
{ | ||
return @"{ | ||
'lifeTheUniverseAndEverything': { | ||
'value': '42' | ||
}, | ||
'password': { | ||
'reference': { | ||
'keyVault': { | ||
'id': 'id/othervalue/test' | ||
}, | ||
'secretName': 'secretName' | ||
} | ||
} | ||
}".Replace("'", "\""); | ||
} | ||
} | ||
} |
45 changes: 0 additions & 45 deletions
45
source/Calamari.Azure.Tests/ResourceGroups/ResourceGroupTemplateParserFixture.cs
This file was deleted.
Oops, something went wrong.
14 changes: 11 additions & 3 deletions
14
source/Calamari.Azure.Tests/ResourceGroups/params_sans_envelope.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
{ | ||
"lifeTheUniverseAndEverything": { | ||
"value": "42" | ||
} | ||
"lifeTheUniverseAndEverything": { | ||
"value": "42" | ||
}, | ||
"password": { | ||
"reference": { | ||
"keyVault": { | ||
"id": "id/othervalue/test" | ||
}, | ||
"secretName": "secretName" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...e/Calamari.Azure/Deployment/Integration/ResourceGroups/ResourceGroupTemplateNormalizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Calamari.Azure.Deployment.Integration.ResourceGroups | ||
{ | ||
public interface IResourceGroupTemplateNormalizer | ||
{ | ||
string Normalize(string json); | ||
} | ||
|
||
/// <summary> | ||
/// There are 2 ways the parameters can be passed to Clamari but the Resource Group Client supports only one format so we need to | ||
/// normalize the input. Have a look at ResourceGroupTemplateNormalizerFixture for more details. | ||
/// </summary> | ||
public class ResourceGroupTemplateNormalizer : IResourceGroupTemplateNormalizer | ||
{ | ||
public string Normalize(string json) | ||
{ | ||
try | ||
{ | ||
var envelope = JsonConvert.DeserializeObject<ParameterEnvelope>(json); | ||
return JsonConvert.SerializeObject(envelope.Parameters); | ||
} | ||
catch (JsonSerializationException) | ||
{ | ||
return json; | ||
} | ||
} | ||
|
||
class ParameterEnvelope | ||
{ | ||
[JsonProperty("parameters", Required = Required.Always)] | ||
public JObject Parameters { get; set; } | ||
} | ||
} | ||
} |
10 changes: 0 additions & 10 deletions
10
...ce/Calamari.Azure/Deployment/Integration/ResourceGroups/ResourceGroupTemplateParameter.cs
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
...amari.Azure/Deployment/Integration/ResourceGroups/ResourceGroupTemplateParameterParser.cs
This file was deleted.
Oops, something went wrong.