//--- Methods -- public void Register(CommandLineApplication app) { app.Command("init", cmd => { cmd.HelpOption(); cmd.Description = "Initialize LambdaSharp deployment tier"; // init options var allowDataLossOption = cmd.Option("--allow-data-loss", "(optional) Allow CloudFormation resource update operations that could lead to data loss", CommandOptionType.NoValue); var protectStackOption = cmd.Option("--protect", "(optional) Enable termination protection for the CloudFormation stack", CommandOptionType.NoValue); var forceDeployOption = cmd.Option("--force-deploy", "(optional) Force module deployment", CommandOptionType.NoValue); var versionOption = cmd.Option("--version <VERSION>", "(optional) Specify version for LambdaSharp modules (default: same as CLI version)", CommandOptionType.SingleValue); var localOption = cmd.Option("--local <PATH>", "(optional) Provide a path to a local check-out of the LambdaSharp modules (default: LAMBDASHARP environment variable)", CommandOptionType.SingleValue); var usePublishedOption = cmd.Option("--use-published", "(optional) Force the init command to use the published LambdaSharp modules", CommandOptionType.NoValue); var parametersFileOption = cmd.Option("--parameters <FILE>", "(optional) Specify source filename for module parameters (default: none)", CommandOptionType.SingleValue); var forcePublishOption = CliBuildPublishDeployCommand.AddForcePublishOption(cmd); var promptAllParametersOption = cmd.Option("--prompt-all", "(optional) Prompt for all missing parameters values (default: only prompt for missing parameters with no default value)", CommandOptionType.NoValue); var promptsAsErrorsOption = cmd.Option("--prompts-as-errors", "(optional) Missing parameters cause an error instead of a prompts (use for CI/CD to avoid unattended prompts)", CommandOptionType.NoValue); var initSettingsCallback = CreateSettingsInitializer(cmd); cmd.OnExecute(async() => { Console.WriteLine($"{app.FullName} - {cmd.Description}"); var settings = await initSettingsCallback(); if (settings == null) { return; } // determine if we want to install modules from a local check-out await Init( settings, allowDataLossOption.HasValue(), protectStackOption.HasValue(), forceDeployOption.HasValue(), versionOption.HasValue() ? VersionInfo.Parse(versionOption.Value()) : Version, usePublishedOption.HasValue() ? null : (localOption.Value() ?? Environment.GetEnvironmentVariable("LAMBDASHARP")), parametersFileOption.Value(), forcePublishOption.HasValue(), promptAllParametersOption.HasValue(), promptsAsErrorsOption.HasValue() ); }); }); }
//--- Methods -- public void Register(CommandLineApplication app) { app.Command("init", cmd => { cmd.HelpOption(); cmd.Description = "Create or update a LambdaSharp deployment tier"; // init options var allowDataLossOption = cmd.Option("--allow-data-loss", "(optional) Allow CloudFormation resource update operations that could lead to data loss", CommandOptionType.NoValue); var protectStackOption = cmd.Option("--protect", "(optional) Enable termination protection for the CloudFormation stack", CommandOptionType.NoValue); var enableXRayTracingOption = cmd.Option("--xray[:<LEVEL>]", "(optional) Enable service-call tracing with AWS X-Ray for all resources in module (0=Disabled, 1=RootModule, 2=AllModules; RootModule if LEVEL is omitted)", CommandOptionType.SingleOrNoValue); var versionOption = cmd.Option("--version <VERSION>", "(optional) Specify version for LambdaSharp modules (default: same as CLI version)", CommandOptionType.SingleValue); var parametersFileOption = cmd.Option("--parameters <FILE>", "(optional) Specify source filename for module parameters (default: none)", CommandOptionType.SingleValue); var forcePublishOption = CliBuildPublishDeployCommand.AddForcePublishOption(cmd); var forceDeployOption = cmd.Option("--force-deploy", "(optional) Force module deployment", CommandOptionType.NoValue); var quickStartOption = cmd.Option("--quick-start", "(optional, create-only) Use safe defaults for quickly setting up a LambdaSharp deployment tier.", CommandOptionType.NoValue); var coreServicesOption = cmd.Option("--core-services <VALUE>", "(optional, create-only) Select if LambdaSharp.Core services should be enabled or not (either Enabled or Disabled, default prompts)", CommandOptionType.SingleValue); var existingS3BucketNameOption = cmd.Option("--existing-s3-bucket-name <NAME>", "(optional, create-only) Existing S3 bucket name for module deployments (blank value creates new bucket)", CommandOptionType.SingleValue); var localOption = cmd.Option("--local <PATH>", "(optional) Provide a path to a local check-out of the LambdaSharp modules (default: LAMBDASHARP environment variable)", CommandOptionType.SingleValue); var usePublishedOption = cmd.Option("--use-published", "(optional) Force the init command to use the published LambdaSharp modules", CommandOptionType.NoValue); var promptAllParametersOption = cmd.Option("--prompt-all", "(optional) Prompt for all missing parameters values (default: only prompt for missing parameters with no default value)", CommandOptionType.NoValue); var allowUpgradeOption = cmd.Option("--allow-upgrade", "(optional) Allow upgrading LambdaSharp.Core across major releases (default: prompt)", CommandOptionType.NoValue); var initSettingsCallback = CreateSettingsInitializer(cmd); cmd.OnExecute(async() => { Console.WriteLine($"{app.FullName} - {cmd.Description}"); var settings = await initSettingsCallback(); if (settings == null) { return; } // check x-ray settings if (!TryParseEnumOption(enableXRayTracingOption, XRayTracingLevel.Disabled, XRayTracingLevel.RootModule, out var xRayTracingLevel)) { // NOTE (2018-08-04, bjorg): no need to add an error message since it's already added by 'TryParseEnumOption' return; } if (!TryParseEnumOption(coreServicesOption, CoreServices.Undefined, CoreServices.Undefined, out var coreServices)) { // NOTE (2018-08-04, bjorg): no need to add an error message since it's already added by 'TryParseEnumOption' return; } // set initialization parameters var existingS3BucketName = existingS3BucketNameOption.Value(); if (quickStartOption.HasValue()) { coreServices = CoreServices.Disabled; existingS3BucketName = ""; } // determine if we want to install modules from a local check-out await Init( settings, allowDataLossOption.HasValue(), protectStackOption.HasValue(), forceDeployOption.HasValue(), versionOption.HasValue() ? VersionInfo.Parse(versionOption.Value()) : Version.GetCompatibleCoreServicesVersion(), usePublishedOption.HasValue() ? null : (localOption.Value() ?? Environment.GetEnvironmentVariable("LAMBDASHARP")), parametersFileOption.Value(), forcePublishOption.HasValue(), promptAllParametersOption.HasValue(), xRayTracingLevel, coreServices, existingS3BucketName, allowUpgradeOption.HasValue() ); }); }); }
//--- Methods -- public void Register(CommandLineApplication app) { app.Command("init", cmd => { cmd.HelpOption(); cmd.Description = "Create or update a LambdaSharp deployment tier"; // init options var allowDataLossOption = cmd.Option("--allow-data-loss", "(optional) Allow CloudFormation resource update operations that could lead to data loss", CommandOptionType.NoValue); var protectStackOption = cmd.Option("--protect", "(optional) Enable termination protection for the CloudFormation stack", CommandOptionType.NoValue); var enableXRayTracingOption = cmd.Option("--xray[:<LEVEL>]", "(optional) Enable service-call tracing with AWS X-Ray for all resources in module (0=Disabled, 1=RootModule, 2=AllModules; RootModule if LEVEL is omitted)", CommandOptionType.SingleOrNoValue); var versionOption = cmd.Option("--version <VERSION>", "(optional) Specify version for LambdaSharp modules (default: same as CLI version)", CommandOptionType.SingleValue); var parametersFileOption = cmd.Option("--parameters <FILE>", "(optional) Specify source filename for module parameters (default: none)", CommandOptionType.SingleValue); var forcePublishOption = CliBuildPublishDeployCommand.AddForcePublishOption(cmd); var forceDeployOption = cmd.Option("--force-deploy", "(optional) Force module deployment", CommandOptionType.NoValue); var quickStartOption = cmd.Option("--quick-start", "(optional, create-only) Use safe defaults for quickly setting up a LambdaSharp deployment tier.", CommandOptionType.NoValue); var coreServicesOption = cmd.Option("--core-services <VALUE>", "(optional, create-only) Select if LambdaSharp.Core services should be enabled or not (either Enabled or Disabled, default prompts)", CommandOptionType.SingleValue); var existingS3BucketNameOption = cmd.Option("--existing-s3-bucket-name <NAME>", "(optional, create-only) Existing S3 bucket name for module deployments (blank value creates new bucket)", CommandOptionType.SingleValue); var localOption = cmd.Option("--local <PATH>", "(optional) Provide a path to a local check-out of the LambdaSharp modules (default: LAMBDASHARP environment variable)", CommandOptionType.SingleValue); var usePublishedOption = cmd.Option("--use-published", "(optional) Force the init command to use the published LambdaSharp modules", CommandOptionType.NoValue); var promptAllParametersOption = cmd.Option("--prompt-all", "(optional) Prompt for all missing parameters values (default: only prompt for missing parameters with no default value)", CommandOptionType.NoValue); var allowUpgradeOption = cmd.Option("--allow-upgrade", "(optional) Allow upgrading LambdaSharp.Core across major releases (default: prompt)", CommandOptionType.NoValue); var forceBuildOption = cmd.Option("--force-build", "(optional) Always build function packages", CommandOptionType.NoValue); var initSettingsCallback = CreateSettingsInitializer(cmd); cmd.OnExecute(async() => { Console.WriteLine($"{app.FullName} - {cmd.Description}"); // check if .aws/credentials file needs to be created if ( !File.Exists(CredentialsFilePath) && ( (Environment.GetEnvironmentVariable("AWS_ACCESS_KEY_ID") == null) || (Environment.GetEnvironmentVariable("AWS_SECRET_ACCESS_KEY") == null) ) ) { var tmpSettings = new Settings(); // prompt for AWS credentials information Console.WriteLine(); tmpSettings.PromptLabel("Create AWS profile"); var accessKey = tmpSettings.PromptString("Enter the AWS Access Key ID"); var secretAccessKey = tmpSettings.PromptString("Enter the AWS Secret Access Key"); var region = tmpSettings.PromptString("Enter the AWS region", "us-east-1"); // create credentials file var credentialsTemplate = ReadResource("credentials.txt", new Dictionary <string, string> { ["REGION"] = region, ["ACCESSKEY"] = accessKey, ["SECRETACCESSKEY"] = secretAccessKey }); try { File.WriteAllText(CredentialsFilePath, credentialsTemplate); } catch { LogError("unable to create .aws/credentials file"); return; } } // initialize settings var settings = await initSettingsCallback(); if (settings == null) { return; } // check x-ray settings if (!TryParseEnumOption(enableXRayTracingOption, XRayTracingLevel.Disabled, XRayTracingLevel.RootModule, out var xRayTracingLevel)) { // NOTE (2018-08-04, bjorg): no need to add an error message since it's already added by 'TryParseEnumOption' return; } if (!TryParseEnumOption(coreServicesOption, CoreServices.Undefined, CoreServices.Undefined, out var coreServices)) { // NOTE (2018-08-04, bjorg): no need to add an error message since it's already added by 'TryParseEnumOption' return; } // set initialization parameters var existingS3BucketName = existingS3BucketNameOption.Value(); if (quickStartOption.HasValue()) { coreServices = CoreServices.Disabled; existingS3BucketName = ""; } // determine if we want to install modules from a local check-out await Init( settings, allowDataLossOption.HasValue(), protectStackOption.HasValue(), forceDeployOption.HasValue(), versionOption.HasValue() ? VersionInfo.Parse(versionOption.Value()) : Version.GetCoreServicesReferenceVersion(), usePublishedOption.HasValue() ? null : (localOption.Value() ?? Environment.GetEnvironmentVariable("LAMBDASHARP")), parametersFileOption.Value(), forcePublishOption.HasValue(), promptAllParametersOption.HasValue(), xRayTracingLevel, coreServices, existingS3BucketName, allowUpgradeOption.HasValue(), forceBuildOption.HasValue() ); }); }); }