コード例 #1
0
        static string DeclareLocalVariables(CalamariVariableDictionary variables)
        {
            var output = new StringBuilder();

            foreach (var variableName in variables.GetNames().Where(name => !SpecialVariables.IsLibraryScriptModule(name)))
            {
                if (SpecialVariables.IsExcludedFromLocalVariables(variableName))
                {
                    continue;
                }

                // This is the way we used to fix up the identifiers - people might still rely on this behavior
                var legacyKey = new string(variableName.Where(char.IsLetterOrDigit).ToArray());

                // This is the way we should have done it
                var smartKey = new string(variableName.Where(IsValidPowerShellIdentifierChar).ToArray());

                if (legacyKey != smartKey)
                {
                    WriteVariableAssignment(output, legacyKey, variableName);
                }

                WriteVariableAssignment(output, smartKey, variableName);
            }

            return(output.ToString());
        }
コード例 #2
0
ファイル: FSharpBootstrapper.cs プロジェクト: yamina/Calamari
        static string WritePatternMatching(CalamariVariableDictionary variables)
        {
            var builder = new StringBuilder();

            foreach (var variableName in variables.GetNames())
            {
                var variableValue = variables.Get(variableName);
                if (variableValue == null)
                {
                    builder.AppendFormat("        | \"{0}\" -> Some null", EncodeValue(variableName));
                }
                else if (variables.IsSensitive(variableName))
                {
                    builder.AppendFormat("        | \"{0}\" -> {1} |> Some", EncodeValue(variableName),
                                         EncryptVariable(variableValue));
                }
                else
                {
                    builder.AppendFormat("        | \"{0}\" -> \"{1}\" |> decode |> Some", EncodeValue(variableName),
                                         EncodeValue(variableValue));
                }

                builder.Append(Environment.NewLine);
            }
            builder.Append("        | _ -> None");

            return(builder.ToString());
        }
コード例 #3
0
        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);
            }));
        }
コード例 #4
0
        private VariableDictionary AddEnvironmentVariables()
        {
            var variables  = new CalamariVariableDictionary();
            var convention = new ContributeEnvironmentVariablesConvention();

            convention.Install(new RunningDeployment("C:\\Package.nupkg", variables));

            Assert.That(variables.GetNames().Count, Is.GreaterThan(3));
            Assert.That(variables.GetRaw(SpecialVariables.Tentacle.Agent.InstanceName), Is.EqualTo("#{env:TentacleInstanceName}"));
            return(variables);
        }
コード例 #5
0
        static IEnumerable <string> GetVariables(CalamariVariableDictionary variables)
        {
            return(variables.GetNames().Select(variable =>
            {
                var variableValue = variables.IsSensitive(variable)
                    ? DecryptValueCommand(variables.Get(variable))
                    : $"decode(\"{EncodeValue(variables.Get(variable))}\")";

                return $"decode(\"{EncodeValue(variable)}\") : {variableValue}";
            }));
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        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());
        }
コード例 #8
0
        static (string encrypted, string iv) GetEncryptedVariablesString(CalamariVariableDictionary variables)
        {
            var sb = new StringBuilder();

            foreach (var variableName in variables.GetNames().Where(name => !SpecialVariables.IsLibraryScriptModule(name)))
            {
                var value          = variables.Get(variableName);
                var encryptedValue = value == null ? "nul" : EncodeAsBase64(value); // "nul" is not a valid Base64 string
                sb.Append(EncodeAsBase64(variableName)).Append("$").AppendLine(encryptedValue);
            }

            var encrypted    = VariableEncryptor.Encrypt(sb.ToString());
            var rawEncrypted = AesEncryption.ExtractIV(encrypted, out var iv);

            return(
                Convert.ToBase64String(rawEncrypted, Base64FormattingOptions.InsertLineBreaks),
                Convert.ToBase64String(iv)
                );
        }