コード例 #1
0
        public void LogVariables()
        {
            string ToString(bool useRawValue)
            {
                var text = new StringBuilder();

                var namesToPrint = variables.GetNames().Where(name => !name.Contains("CustomScripts.")).OrderBy(name => name);

                foreach (var name in namesToPrint)
                {
                    var value = useRawValue ? variables.GetRaw(name) : variables.Get(name);
                    text.AppendLine($"[{name}] = '{value}'");
                }

                return(text.ToString());
            }

            if (variables.GetFlag(KnownVariables.PrintVariables))
            {
                log.Warn($"{KnownVariables.PrintVariables} is enabled. This should only be used for debugging problems with variables, and then disabled again for normal deployments.");
                log.Verbose("The following variables are available:" + Environment.NewLine + ToString(true));
            }

            if (variables.GetFlag(KnownVariables.PrintEvaluatedVariables))
            {
                log.Warn($"{KnownVariables.PrintEvaluatedVariables} is enabled. This should only be used for debugging problems with variables, and then disabled again for normal deployments.");
                log.Verbose("The following evaluated variables are available:" + Environment.NewLine + ToString(false));
            }
        }
コード例 #2
0
        protected override void Execute(SubstituteInFilesCommandInputs inputs)
        {
            var targetPath = variables.GetRaw(inputs.TargetPathVariable);

            if (targetPath == null)
            {
                throw new CommandException($"Could not locate target path from variable {inputs.TargetPathVariable} for {nameof(SubstituteInFilesCommand)}");
            }

            substituteInFiles.Substitute(targetPath, inputs.FilesToTarget);
        }
コード例 #3
0
        protected override void Execute(StructuredConfigVariablesCommandInputs inputs)
        {
            var targetPath = variables.GetRaw(inputs.TargetPathVariable);

            if (targetPath == null)
            {
                throw new CommandException($"Could not locate target path from variable {inputs.TargetPathVariable} for {nameof(StructuredConfigVariablesCommand)}");
            }

            structuredConfigVariablesService.ReplaceVariables(targetPath);
        }
コード例 #4
0
        bool TryGetScriptFromVariables(out string scriptBody, out string scriptFileName, out ScriptSyntax syntax)
        {
            scriptBody = variables.GetRaw(ScriptVariables.ScriptBody);
            if (WasProvided(scriptBody))
            {
                var scriptSyntax = variables.Get(ScriptVariables.Syntax);
                if (scriptSyntax == null)
                {
                    syntax = scriptEngine.GetSupportedTypes().FirstOrDefault();
                    Log.Warn($"No script syntax provided. Defaulting to first known supported type {syntax}");
                }
                else if (!Enum.TryParse(scriptSyntax, out syntax))
                {
                    throw new CommandException($"Unknown script syntax `{scriptSyntax}` provided");
                }

                scriptFileName = "Script." + syntax.FileExtension();
                return(true);
            }

            // Try get any supported script body variable
            foreach (var supportedSyntax in scriptEngine.GetSupportedTypes())
            {
                scriptBody = variables.GetRaw(SpecialVariables.Action.Script.ScriptBodyBySyntax(supportedSyntax));
                if (scriptBody == null)
                {
                    continue;
                }

                scriptFileName = "Script." + supportedSyntax.FileExtension();
                syntax         = supportedSyntax;
                return(true);
            }

            scriptBody     = null;
            syntax         = 0;
            scriptFileName = null;
            return(false);
        }
コード例 #5
0
        internal static ICollection<PrivateKeyAccessRule> GetPrivateKeyAccessRules(IVariables variables)
        {
            // The private-key access-rules are stored as escaped JSON. However, they may contain nested
            // variables (for example the user-name may be an Octopus variable) which may not be escaped,
            // causing JSON parsing to fail.

            // So, we get the raw text
            var raw = variables.GetRaw(SpecialVariables.Certificate.PrivateKeyAccessRules);

            if (string.IsNullOrWhiteSpace(raw))
                return new List<PrivateKeyAccessRule>();

            // Unescape it (we only care about backslashes)
            var unescaped = raw.Replace(@"\\", @"\");
            // Perform variable-substitution and re-escape
            var escapedAndSubstituted = variables.Evaluate(unescaped).Replace(@"\", @"\\");
            return PrivateKeyAccessRule.FromJson(escapedAndSubstituted);
        }
コード例 #6
0
        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);
            }
        }