Example #1
0
        public IVariables CloneAndEvaluate()
        {
            var dict = new CalamariVariables();

            GetNames().ForEach(name => dict.Set(name, Get(name)));
            return(dict);
        }
Example #2
0
        public IVariables Create(CommonOptions options)
        {
            var variables = new CalamariVariables();

            ReadUnencryptedVariablesFromFile(options, variables);
            ReadEncryptedVariablesFromFile(options, variables);
            ReadOutputVariablesFromOfflineDropPreviousSteps(options, variables);

            AddEnvironmentVariables(variables);
            variables.Set(TentacleVariables.Agent.InstanceName, "#{env:TentacleInstanceName}");
            ReadAdditionalVariablesFromFile(variables);
            DeploymentJournalVariableContributor.Contribute(fileSystem, variables);

            return(variables);
        }
Example #3
0
        void ReadEncryptedVariablesFromFile(CommonOptions options, CalamariVariables variables)
        {
            foreach (var sensitiveFilePath in options.InputVariables.SensitiveVariablesFiles.Where(f => !string.IsNullOrEmpty(f)))
            {
                var sensitiveFilePassword = options.InputVariables.SensitiveVariablesPassword;
                var rawVariables          = string.IsNullOrWhiteSpace(sensitiveFilePassword)
                    ? fileSystem.ReadFile(sensitiveFilePath)
                    : Decrypt(fileSystem.ReadAllBytes(sensitiveFilePath), sensitiveFilePassword);

                try
                {
                    var sensitiveVariables = JsonConvert.DeserializeObject <Dictionary <string, string> >(rawVariables);
                    foreach (var variable in sensitiveVariables)
                    {
                        variables.Set(variable.Key, variable.Value);
                    }
                }
                catch (JsonReaderException)
                {
                    throw new CommandException("Unable to parse sensitive-variables as valid JSON.");
                }
            }
        }
Example #4
0
        void ReadOutputVariablesFromOfflineDropPreviousSteps(CommonOptions options, CalamariVariables variables)
        {
            var outputVariablesFilePath = options.InputVariables.OutputVariablesFile;

            if (string.IsNullOrEmpty(outputVariablesFilePath))
            {
                return;
            }

            var rawVariables = DecryptWithMachineKey(fileSystem.ReadFile(outputVariablesFilePath), options.InputVariables.OutputVariablesPassword);

            try
            {
                var outputVariables = JsonConvert.DeserializeObject <Dictionary <string, string> >(rawVariables);
                foreach (var variable in outputVariables)
                {
                    variables.Set(variable.Key, variable.Value);
                }
            }
            catch (JsonReaderException)
            {
                throw new CommandException("Unable to parse output variables as valid JSON.");
            }
        }