public void ShouldIncludeEncryptedSensitiveVariables() { CreateSensitiveVariableFile(); CreateInSensitiveVariableFile(); var result = new CalamariVariableDictionary(insensitiveVariablesFileName, sensitiveVariablesFileName, encryptionPassword); Assert.AreEqual("sensitiveVariableValue", result.Get("sensitiveVariableName")); Assert.AreEqual("insensitiveVariableValue", result.Get("insensitiveVariableName")); }
public void ShouldIncludeCleartextSensitiveVariables() { CreateSensitiveVariableFile(); var sensitiveVariables = new Dictionary<string, string> { {"sensitiveVariableName", "sensitiveVariableValue"} }; File.WriteAllText(sensitiveVariablesFileName, JsonConvert.SerializeObject(sensitiveVariables)); var result = new CalamariVariableDictionary(insensitiveVariablesFileName, sensitiveVariablesFileName, null); Assert.AreEqual("sensitiveVariableValue", result.Get("sensitiveVariableName")); Assert.AreEqual("insensitiveVariableValue", result.Get("insensitiveVariableName")); }
static IEnumerable<string> GetVariableSwitchConditions(CalamariVariableDictionary variables) { return variables.GetNames().Select(variable => { var variableValue = variables.IsSensitive(variable) ? DecryptValueCommand(variables.Get(variable)) : string.Format("decode_servicemessagevalue \"{0}\"", EncodeValue(variables.Get(variable))); return string.Format(" \"{1}\"){0} {2} ;;{0}", Environment.NewLine, EncodeValue(variable), variableValue); }); }
public CommandResult Execute(string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner) { var powerShellEngine = new PowerShellScriptEngine(); if (variables.Get(SpecialVariables.Account.AccountType) == "AzureSubscription") { return new AzurePowerShellContext().ExecuteScript(powerShellEngine, scriptFile, variables, commandLineRunner); } return powerShellEngine.Execute(scriptFile, variables, commandLineRunner); }
public CommandResult ExecuteScript(IScriptEngine scriptEngine, string scriptFile, CalamariVariableDictionary variables, ICommandLineRunner commandLineRunner) { var workingDirectory = Path.GetDirectoryName(scriptFile); variables.Set("OctopusAzureTargetScript", scriptFile); // If the Azure PowerShell module to use has not been explicitly configured, then default to the version // bundled with Calamari SetOutputVariable(SpecialVariables.Action.Azure.Output.ModulePath, variables.Get(SpecialVariables.Action.Azure.PowerShellModulePath, BuiltInAzurePowershellModulePath), variables); SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionId, variables.Get(SpecialVariables.Action.Azure.SubscriptionId), variables); SetOutputVariable(SpecialVariables.Action.Azure.Output.SubscriptionName, variables.Get(SpecialVariables.Account.Name), variables); using (new TemporaryFile(CreateAzureCertificate(workingDirectory, variables))) using (var contextScriptFile = new TemporaryFile(CreateContextScriptFile(workingDirectory))) { return scriptEngine.Execute(contextScriptFile.FilePath, variables, commandLineRunner); } }
static void WriteVariableDictionary(CalamariVariableDictionary variables, StringBuilder output) { output.AppendLine("$OctopusParameters = New-Object 'System.Collections.Generic.Dictionary[String,String]' (,[System.StringComparer]::OrdinalIgnoreCase)"); foreach (var variableName in variables.GetNames().Where(name => !SpecialVariables.IsLibraryScriptModule(name))) { var variableValue = variables.IsSensitive(variableName) ? EncryptVariable(variables.Get(variableName)) : EncodeValue(variables.Get(variableName)); output.Append("$OctopusParameters[").Append(EncodeValue(variableName)).Append("] = ").AppendLine(variableValue); } }
static string WriteVariableDictionary(CalamariVariableDictionary variables) { var builder = new StringBuilder(); foreach (var variable in variables.GetNames()) { var variableValue = variables.IsSensitive(variable) ? EncryptVariable(variables.Get(variable)) : EncodeValue(variables.Get(variable)); builder.Append("\t\t\tthis[").Append(EncodeValue(variable)).Append("] = ").Append(variableValue).AppendLine(";"); } return builder.ToString(); }