Example #1
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);
        }
Example #2
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("-------------");
        }