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); }
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); }
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."); } } }
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."); } }