예제 #1
0
        public int Run(
            [Operand("module", Description = "The name of the module.")] string moduleName,
            [Operand("commands", Description = "The space-separated list of task names.")] List <string> commands)
        {
            var commandContext = CommandLineHandler.Context;

            if (string.IsNullOrEmpty(moduleName))
            {
                CommandLineHandler.DisplayHelp("run module");
                return((int)ExecutionResult.HostArgumentError);
            }

            commandContext.Logger.Information("loading module {Module}", moduleName);

            var loadResult = ModuleLoader.LoadModule(commandContext, moduleName, false, out var module);

            if (loadResult != ExecutionResult.Success)
            {
                return((int)loadResult);
            }

            var executionResult = ExecutionResult.Success;

            if (commands.Count > 0)
            {
                executionResult = ModuleExecuter.Execute(commandContext, module, commands.ToArray());
            }

            ModuleLoader.UnloadModule(commandContext, module);

            return((int)executionResult);
        }
예제 #2
0
        public int ValidateModule(
            [Operand("names", Description = "The space-separated list of module names.")] List <string> moduleNames,
            [Option('a', "all")] bool all)
        {
            if (moduleNames == null || moduleNames.Count == 0)
            {
                if (!all)
                {
                    CommandLineHandler.DisplayHelp("test modules");
                    return((int)ExecutionResult.HostArgumentError);
                }
            }
            else if (all)
            {
                CommandLineHandler.DisplayHelp("test modules");
                return((int)ExecutionResult.HostArgumentError);
            }

            var commandContext = CommandLineHandler.Context;

            if (all)
            {
                moduleNames = ModuleLister.GetAllModules(commandContext);
            }

            var result = ExecutionResult.Success;

            foreach (var moduleName in moduleNames)
            {
                commandContext.Logger.Information("loading module {Module}", moduleName);

                ModuleLoader.LoadModule(commandContext, moduleName, true, out var module);
                if (module != null)
                {
                    ModuleLoader.UnloadModule(commandContext, module);
                    commandContext.Logger.Information("validation {ValidationResult} for {Module}", "PASSED", moduleName);
                }
                else
                {
                    commandContext.Logger.Information("validation {ValidationResult} for {Module}", "FAILED", moduleName);
                    result = ExecutionResult.ModuleLoadError;
                }
            }

            return((int)result);
        }
예제 #3
0
        public void ProtectSecret([Operand("secret", Description = "The secret to protect.")] string secret)
        {
            var commandContext = CommandLineHandler.Context;

            if (commandContext.HostConfiguration.SecretProtector == null)
            {
                commandContext.Logger.Write(LogEventLevel.Fatal, "secret protector is not set in {HostConfigurationFileName}", PathHelpers.GetFriendlyPathName(commandContext.LoadedConfigurationFileName));
                return;
            }

            if (string.IsNullOrEmpty(secret))
            {
                CommandLineHandler.DisplayHelp("protect");
                return;
            }

            var protectedSecret = commandContext.HostConfiguration.SecretProtector.Encrypt(secret);

            Console.WriteLine("The protected secret is:");
            Console.WriteLine("-------------");
            Console.WriteLine(protectedSecret);
            Console.WriteLine("-------------");
        }