示例#1
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);
        }
示例#2
0
        void ReadUnencryptedVariablesFromFile(CommonOptions options, CalamariVariables variables)
        {
            var variablesFile = options.InputVariables.VariablesFile;

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

            if (!fileSystem.FileExists(variablesFile))
            {
                throw new CommandException("Could not find variables file: " + variablesFile);
            }

            var readVars = new VariableDictionary(variablesFile);

            variables.Merge(readVars);
        }
示例#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.");
                }
            }
        }
示例#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.");
            }
        }