public void InvalidVariableExpressionFails() { var variables = new CalamariVariables { }; string jsonInputs = "{\"package\":{\"extractedToPath\":\"#{Octopus.Action.Package[package]...ExtractedPath}\"}}"; Assert.Throws <CommandException>(() => InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, Substitute.For <ILog>())); }
public void MissingVariableValue_LogsAWarning() { var variables = new CalamariVariables { }; string jsonInputs = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"#{Octopus.Action.Package[package].ExtractedPath}\"},\"target\":{\"files\":[]}}"; var log = Substitute.For <ILog>(); InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, log); log.Received().Warn(Arg.Any <string>()); }
public void SimpleExpressionsAreEvaluated() { var variableDictionary = new CalamariVariables(); string jsonInputs = "{\"testValue\":\"#{ | NowDateUtc}\"}"; var log = Substitute.For <ILog>(); string evaluatedInputs = InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variableDictionary, log); evaluatedInputs.Should().NotBeEmpty(); evaluatedInputs.Should().NotBeEquivalentTo(jsonInputs); log.DidNotReceive().Warn(Arg.Any <string>()); }
public void CommonExpressionsAreEvaluated(string expression, string variables, string expectedResult) { var variableDictionary = ParseVariables(variables); string jsonInputs = "{\"testValue\":\"" + expression + "\"}"; var log = Substitute.For <ILog>(); string evaluatedInputs = InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variableDictionary, log); string expectedEvaluatedInputs = "{\"testValue\":\"" + expectedResult + "\"}"; Assert.AreEqual(expectedEvaluatedInputs, evaluatedInputs); log.DidNotReceive().Warn(Arg.Any <string>()); }
public void VariablesInJsonInputsShouldBeEvaluated() { var variables = new CalamariVariables { { "Octopus.Action.Package[package].ExtractedPath", "C:\\OctopusTest\\Api Test\\1\\Octopus-Primary\\Work\\20210804020317-7-11\\package" }, }; string jsonInputs = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"#{Octopus.Action.Package[package].ExtractedPath}\"},\"target\":{\"files\":[{\"path\":\"azure-blob-container-target.0.0.0.zip\",\"fileName\":{\"type\":\"original file name\"}}]}}"; string evaluatedInputs = InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, Substitute.For <ILog>()); string expectedEvaluatedInputs = "{\"containerNameOverride\":\"payload\",\"package\":{\"extractedToPath\":\"C:\\\\OctopusTest\\\\Api Test\\\\1\\\\Octopus-Primary\\\\Work\\\\20210804020317-7-11\\\\package\"},\"target\":{\"files\":[{\"path\":\"azure-blob-container-target.0.0.0.zip\",\"fileName\":{\"type\":\"original file name\"}}]}}"; Assert.AreEqual(expectedEvaluatedInputs, evaluatedInputs); }
protected override int ExecuteInternal(NodeInstructions instructions) { using (var variableFile = new TemporaryFile(Path.GetTempFileName())) { var jsonInputs = variables.GetRaw(instructions.InputsVariable) ?? string.Empty; variables.Set(instructions.InputsVariable, InputSubstitution.SubstituteAndEscapeAllVariablesInJson(jsonInputs, variables, log)); var variablesAsJson = variables.CloneAndEvaluate().SaveAsString(); File.WriteAllBytes(variableFile.FilePath, new AesEncryption(options.InputVariables.SensitiveVariablesPassword).Encrypt(variablesAsJson)); var pathToNode = variables.Get(instructions.NodePathVariable); var nodeExecutablePath = BuildNodePath(pathToNode); var parameters = BuildParams(instructions, variableFile.FilePath); var runningDeployment = new RunningDeployment(variables); var commandLineInvocation = new CommandLineInvocation(nodeExecutablePath, parameters) { WorkingDirectory = runningDeployment.CurrentDirectory, OutputToLog = true, EnvironmentVars = ProxyEnvironmentVariablesGenerator.GenerateProxyEnvironmentVariables().ToDictionary(e => e.Key, e => e.Value) }; var commandResult = commandLineRunner.Execute(commandLineInvocation); return(commandResult.ExitCode); } }