From 681b32f0fd4e49c0322c4f4b69e8d323e223cfbe Mon Sep 17 00:00:00 2001 From: khmoryz Date: Sun, 11 Feb 2024 19:35:46 +0900 Subject: [PATCH 1/3] Add logout option to console command --- cmd/aws-console/main.go | 4 +++- internal/aws/console/console.go | 6 +++++- internal/cmd/console/console.go | 4 +++- internal/cmd/console/util.go | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/aws-console/main.go b/cmd/aws-console/main.go index 1056db67..aa697a65 100644 --- a/cmd/aws-console/main.go +++ b/cmd/aws-console/main.go @@ -9,6 +9,7 @@ import ( ) var printOnly = false +var logout = false var userName = "" // Cmd is the console command's entrypoint @@ -28,12 +29,13 @@ Unless you specify the --name/-n flag, your AWS console user name will be derive service = args[0] } - console.Open(printOnly, service, "", userName) + console.Open(printOnly, logout, service, "", userName) }, } func init() { Cmd.Flags().BoolVarP(&printOnly, "url", "u", false, "Just construct the sign-in URL; don't attempt to open it") + Cmd.Flags().BoolVarP(&logout, "logout", "l", false, "Log out of the AWS console") Cmd.Flags().StringVarP(&config.Profile, "profile", "p", "", "AWS profile name; read from the AWS CLI configuration file") Cmd.Flags().StringVarP(&config.Region, "region", "r", "", "AWS region to use") Cmd.Flags().StringVarP(&userName, "name", "n", "", "Specify a user name to use in the AWS console") diff --git a/internal/aws/console/console.go b/internal/aws/console/console.go index c7dbdd23..3aa60f9b 100644 --- a/internal/aws/console/console.go +++ b/internal/aws/console/console.go @@ -20,6 +20,7 @@ import ( var signinURI string var consoleURI string +const signoutURI = "https://signin.aws.amazon.com/oauth?Action=logout&redirect_uri=https://aws.amazon.com" const issuer = "https://aws-cloudformation.github.io/rain/rain_console.html" const defaultService = "cloudformation" const sessionDuration = 43200 @@ -118,7 +119,10 @@ func getSigninToken(userName string) (string, error) { } // GetURI returns a sign-in uri for the current credentials and region -func GetURI(service, stackName, userName string) (string, error) { +func GetURI(logout bool, service, stackName, userName string) (string, error) { + if logout { + return signoutURI, nil + } config.Debugf("GetURI %v, %v, %v", service, stackName, userName) diff --git a/internal/cmd/console/console.go b/internal/cmd/console/console.go index 7fcd5878..0f18dbb5 100644 --- a/internal/cmd/console/console.go +++ b/internal/cmd/console/console.go @@ -5,6 +5,7 @@ import ( ) var printOnlyFlag = false +var logoutFlag = false var serviceParam = "cloudformation" var userName = "" @@ -27,12 +28,13 @@ Unless you specify the --name/-n flag, your AWS console user name will be derive stackName = args[0] } - Open(printOnlyFlag, serviceParam, stackName, userName) + Open(printOnlyFlag, logoutFlag, serviceParam, stackName, userName) }, } func init() { Cmd.Flags().BoolVarP(&printOnlyFlag, "url", "u", false, "Just construct the sign-in URL; don't attempt to open it") + Cmd.Flags().BoolVarP(&logoutFlag, "logout", "l", false, "Log out of the AWS console") Cmd.Flags().StringVarP(&serviceParam, "service", "s", "cloudformation", "Choose an AWS service home page to launch") Cmd.Flags().StringVarP(&userName, "name", "n", "", "Specify a user name to use in the AWS console") } diff --git a/internal/cmd/console/util.go b/internal/cmd/console/util.go index d789d18c..2172eb64 100644 --- a/internal/cmd/console/util.go +++ b/internal/cmd/console/util.go @@ -13,9 +13,9 @@ import ( // Open generates a sign-in URL to the AWS console with an optional service and resource // If printOnly is true, the URL is printed to the console // If printOnly is false, Open attempts to call the OS's browser with the URL -func Open(printOnly bool, service, resource, userName string) { - spinner.Push("Generating sign-in URL") - uri, err := console.GetURI(service, resource, userName) +func Open(printOnly bool, logout bool, service, resource, userName string) { + spinner.Push("Generating URL") + uri, err := console.GetURI(logout, service, resource, userName) if err != nil { panic(err) } From 3a1581586cc7de660983896f8a3bdf0a9f4cdd1a Mon Sep 17 00:00:00 2001 From: khmoryz Date: Sun, 11 Feb 2024 19:39:36 +0900 Subject: [PATCH 2/3] docs: Execute go generate --- README.md | 5 +- docs/bash_completion.sh | 236 +++++++++++++++++++++++++++++++---- docs/index.md | 5 +- docs/rain_bootstrap.md | 2 +- docs/rain_build.md | 20 +-- docs/rain_cat.md | 2 +- docs/rain_cc.md | 35 ++++++ docs/rain_cc_deploy.md | 43 +++++++ docs/rain_cc_drift.md | 36 ++++++ docs/rain_cc_rm.md | 36 ++++++ docs/rain_cc_state.md | 36 ++++++ docs/rain_console.md | 3 +- docs/rain_deploy.md | 2 +- docs/rain_diff.md | 2 +- docs/rain_fmt.md | 2 +- docs/rain_forecast.md | 2 +- docs/rain_info.md | 2 +- docs/rain_logs.md | 2 +- docs/rain_ls.md | 2 +- docs/rain_merge.md | 2 +- docs/rain_pkg.md | 2 +- docs/rain_rm.md | 2 +- docs/rain_stackset.md | 2 +- docs/rain_stackset_deploy.md | 2 +- docs/rain_stackset_ls.md | 2 +- docs/rain_stackset_rm.md | 2 +- docs/rain_tree.md | 2 +- docs/rain_watch.md | 2 +- 28 files changed, 435 insertions(+), 56 deletions(-) create mode 100644 docs/rain_cc.md create mode 100644 docs/rain_cc_deploy.md create mode 100644 docs/rain_cc_drift.md create mode 100644 docs/rain_cc_rm.md create mode 100644 docs/rain_cc_state.md diff --git a/README.md b/README.md index 501f01be..f5d283f5 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ cfn-lint, Guard and more: ## Key features -* **Interactive deployments**: With `rain deploy`, rain packages your CloudFormation templates using [`aws cloudformation package`](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/package.html), prompts you for any parameters that have not yet been defined, shows you a summary of the changes that will be made, and then displays real-time updates as your stack is being deployed. Once finished, you get a summary of the outcome along with any error messages collected along the way - including errors messages for stacks that have been rolled back and no longer exist. +* **Interactive deployments**: With `rain deploy`, rain packages your CloudFormation templates, prompts you for any parameters that have not yet been defined, shows you a summary of the changes that will be made, and then displays real-time updates as your stack is being deployed. Once finished, you get a summary of the outcome along with any error messages collected along the way - including errors messages for stacks that have been rolled back and no longer exist. * **Consistent formatting of CloudFormation templates**: Using `rain fmt`, you can format your CloudFormation templates to a consistent standard or reformat a template from JSON to YAML (or YAML to JSON if you prefer). Rain preserves your comments when using YAML and switches use of [intrinsic functions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html) to use the short syntax where possible. @@ -51,8 +51,7 @@ Usage: Stack commands: cat Get the CloudFormation template from a running stack - ccdeploy Deploy a local template directly using the Cloud Control API (Experimental!) - ccrm Delete a deployment created by ccdeploy (Experimental!) + cc Interact with templates using Cloud Control API instead of CloudFormation deploy Deploy a CloudFormation stack from a local template logs Show the event log for the named stack ls List running CloudFormation stacks diff --git a/docs/bash_completion.sh b/docs/bash_completion.sh index c2689ee9..aee50806 100644 --- a/docs/bash_completion.sh +++ b/docs/bash_completion.sh @@ -434,10 +434,18 @@ _rain_build() flags+=("-l") local_nonpersistent_flags+=("--list") local_nonpersistent_flags+=("-l") + flags+=("--omit-patches") + flags+=("-o") + local_nonpersistent_flags+=("--omit-patches") + local_nonpersistent_flags+=("-o") flags+=("--prompt") flags+=("-p") local_nonpersistent_flags+=("--prompt") local_nonpersistent_flags+=("-p") + flags+=("--schema") + flags+=("-s") + local_nonpersistent_flags+=("--schema") + local_nonpersistent_flags+=("-s") flags+=("--no-colour") must_have_one_flag=() @@ -495,9 +503,9 @@ _rain_cat() noun_aliases=() } -_rain_ccdeploy() +_rain_cc_deploy() { - last_command="rain_ccdeploy" + last_command="rain_cc_deploy" command_aliases=() @@ -525,6 +533,8 @@ _rain_ccdeploy() flags+=("-h") local_nonpersistent_flags+=("--help") local_nonpersistent_flags+=("-h") + flags+=("--ignore-unknown-params") + local_nonpersistent_flags+=("--ignore-unknown-params") flags+=("--params=") two_word_flags+=("--params") local_nonpersistent_flags+=("--params") @@ -553,6 +563,16 @@ _rain_ccdeploy() two_word_flags+=("--tags") local_nonpersistent_flags+=("--tags") local_nonpersistent_flags+=("--tags=") + flags+=("--unlock=") + two_word_flags+=("--unlock") + two_word_flags+=("-u") + local_nonpersistent_flags+=("--unlock") + local_nonpersistent_flags+=("--unlock=") + local_nonpersistent_flags+=("-u") + flags+=("--yes") + flags+=("-y") + local_nonpersistent_flags+=("--yes") + local_nonpersistent_flags+=("-y") flags+=("--no-colour") must_have_one_flag=() @@ -560,9 +580,9 @@ _rain_ccdeploy() noun_aliases=() } -_rain_ccrm() +_rain_cc_drift() { - last_command="rain_ccrm" + last_command="rain_cc_drift" command_aliases=() @@ -574,10 +594,82 @@ _rain_ccrm() flags_with_completion=() flags_completion=() - flags+=("--detach") - flags+=("-d") - local_nonpersistent_flags+=("--detach") - local_nonpersistent_flags+=("-d") + flags+=("--debug") + local_nonpersistent_flags+=("--debug") + flags+=("--experimental") + flags+=("-x") + local_nonpersistent_flags+=("--experimental") + local_nonpersistent_flags+=("-x") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + local_nonpersistent_flags+=("-h") + flags+=("--profile=") + two_word_flags+=("--profile") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--profile") + local_nonpersistent_flags+=("--profile=") + local_nonpersistent_flags+=("-p") + flags+=("--region=") + two_word_flags+=("--region") + two_word_flags+=("-r") + local_nonpersistent_flags+=("--region") + local_nonpersistent_flags+=("--region=") + local_nonpersistent_flags+=("-r") + flags+=("--s3-bucket=") + two_word_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket=") + flags+=("--s3-prefix=") + two_word_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix=") + flags+=("--no-colour") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_rain_cc_help() +{ + last_command="rain_cc_help" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--debug") + flags+=("--no-colour") + + must_have_one_flag=() + must_have_one_noun=() + has_completion_function=1 + noun_aliases=() +} + +_rain_cc_rm() +{ + last_command="rain_cc_rm" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--debug") + local_nonpersistent_flags+=("--debug") flags+=("--experimental") flags+=("-x") local_nonpersistent_flags+=("--experimental") @@ -598,10 +690,6 @@ _rain_ccrm() local_nonpersistent_flags+=("--region") local_nonpersistent_flags+=("--region=") local_nonpersistent_flags+=("-r") - flags+=("--role-arn=") - two_word_flags+=("--role-arn") - local_nonpersistent_flags+=("--role-arn") - local_nonpersistent_flags+=("--role-arn=") flags+=("--s3-bucket=") two_word_flags+=("--s3-bucket") local_nonpersistent_flags+=("--s3-bucket") @@ -614,6 +702,115 @@ _rain_ccrm() flags+=("-y") local_nonpersistent_flags+=("--yes") local_nonpersistent_flags+=("-y") + flags+=("--no-colour") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_rain_cc_state() +{ + last_command="rain_cc_state" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--debug") + local_nonpersistent_flags+=("--debug") + flags+=("--experimental") + flags+=("-x") + local_nonpersistent_flags+=("--experimental") + local_nonpersistent_flags+=("-x") + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + local_nonpersistent_flags+=("-h") + flags+=("--profile=") + two_word_flags+=("--profile") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--profile") + local_nonpersistent_flags+=("--profile=") + local_nonpersistent_flags+=("-p") + flags+=("--region=") + two_word_flags+=("--region") + two_word_flags+=("-r") + local_nonpersistent_flags+=("--region") + local_nonpersistent_flags+=("--region=") + local_nonpersistent_flags+=("-r") + flags+=("--s3-bucket=") + two_word_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket=") + flags+=("--s3-prefix=") + two_word_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix=") + flags+=("--no-colour") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + +_rain_cc() +{ + last_command="rain_cc" + + command_aliases=() + + commands=() + commands+=("deploy") + commands+=("drift") + commands+=("help") + commands+=("rm") + if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then + command_aliases+=("ccdel") + aliashash["ccdel"]="rm" + command_aliases+=("ccdelete") + aliashash["ccdelete"]="rm" + command_aliases+=("ccremove") + aliashash["ccremove"]="rm" + fi + commands+=("state") + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--help") + flags+=("-h") + local_nonpersistent_flags+=("--help") + local_nonpersistent_flags+=("-h") + flags+=("--profile=") + two_word_flags+=("--profile") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--profile") + local_nonpersistent_flags+=("--profile=") + local_nonpersistent_flags+=("-p") + flags+=("--region=") + two_word_flags+=("--region") + two_word_flags+=("-r") + local_nonpersistent_flags+=("--region") + local_nonpersistent_flags+=("--region=") + local_nonpersistent_flags+=("-r") + flags+=("--s3-bucket=") + two_word_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket") + local_nonpersistent_flags+=("--s3-bucket=") + flags+=("--s3-prefix=") + two_word_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix") + local_nonpersistent_flags+=("--s3-prefix=") flags+=("--debug") flags+=("--no-colour") @@ -640,6 +837,10 @@ _rain_console() flags+=("-h") local_nonpersistent_flags+=("--help") local_nonpersistent_flags+=("-h") + flags+=("--logout") + flags+=("-l") + local_nonpersistent_flags+=("--logout") + local_nonpersistent_flags+=("-l") flags+=("--name=") two_word_flags+=("--name") two_word_flags+=("-n") @@ -1532,16 +1733,7 @@ _rain_root_command() fi commands+=("build") commands+=("cat") - commands+=("ccdeploy") - commands+=("ccrm") - if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then - command_aliases+=("ccdel") - aliashash["ccdel"]="ccrm" - command_aliases+=("ccdelete") - aliashash["ccdelete"]="ccrm" - command_aliases+=("ccremove") - aliashash["ccremove"]="ccrm" - fi + commands+=("cc") commands+=("console") commands+=("deploy") commands+=("diff") diff --git a/docs/index.md b/docs/index.md index a3f64a77..3db835a9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,8 +19,7 @@ Rain is a command line tool for working with AWS CloudFormation templates and st * [rain bootstrap](rain_bootstrap.md) - Creates the artifacts bucket * [rain build](rain_build.md) - Create CloudFormation templates * [rain cat](rain_cat.md) - Get the CloudFormation template from a running stack -* [rain ccdeploy](rain_ccdeploy.md) - Deploy a local template directly using the Cloud Control API (Experimental!) -* [rain ccrm](rain_ccrm.md) - Delete a deployment created by ccdeploy (Experimental!) +* [rain cc](rain_cc.md) - Interact with templates using Cloud Control API instead of CloudFormation * [rain console](rain_console.md) - Login to the AWS console * [rain deploy](rain_deploy.md) - Deploy a CloudFormation stack from a local template * [rain diff](rain_diff.md) - Compare CloudFormation templates @@ -36,4 +35,4 @@ Rain is a command line tool for working with AWS CloudFormation templates and st * [rain tree](rain_tree.md) - Find dependencies of Resources and Outputs in a local template * [rain watch](rain_watch.md) - Display an updating view of a CloudFormation stack -###### Auto generated by spf13/cobra on 16-Jan-2024 +###### Auto generated by spf13/cobra on 11-Feb-2024 diff --git a/docs/rain_bootstrap.md b/docs/rain_bootstrap.md index 9c35d8e1..db6bb942 100644 --- a/docs/rain_bootstrap.md +++ b/docs/rain_bootstrap.md @@ -30,4 +30,4 @@ rain bootstrap * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Jan-2024 +###### Auto generated by spf13/cobra on 11-Feb-2024 diff --git a/docs/rain_build.md b/docs/rain_build.md index 60fad612..49b655aa 100644 --- a/docs/rain_build.md +++ b/docs/rain_build.md @@ -4,21 +4,23 @@ Create CloudFormation templates ### Synopsis -Outputs a CloudFormation template containing the named resource types. +The build command interacts with the CloudFormation registry to list types, output schema files, and build starter CloudFormation templates containing the named resource types. ``` -rain build [ or ] +rain build [] or ``` ### Options ``` - -b, --bare Produce a minimal template, omitting all optional resource properties - --debug Output debugging information - -h, --help help for build - -j, --json Output the template as JSON (default format: YAML) - -l, --list List all CloudFormation resource types - -p, --prompt Generate a template using Bedrock and a prompt + -b, --bare Produce a minimal template, omitting all optional resource properties + --debug Output debugging information + -h, --help help for build + -j, --json Output the template as JSON (default format: YAML) + -l, --list List all CloudFormation resource types + -o, --omit-patches Omit patches and use the raw schema + -p, --prompt Generate a template using Bedrock and a prompt + -s, --schema Output the raw un-patched registry schema for a resource type ``` ### Options inherited from parent commands @@ -31,4 +33,4 @@ rain build [ or ] * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Jan-2024 +###### Auto generated by spf13/cobra on 11-Feb-2024 diff --git a/docs/rain_cat.md b/docs/rain_cat.md index 9ae9e5c4..0ce1c5af 100644 --- a/docs/rain_cat.md +++ b/docs/rain_cat.md @@ -35,4 +35,4 @@ rain cat * [rain](index.md) - -###### Auto generated by spf13/cobra on 16-Jan-2024 +###### Auto generated by spf13/cobra on 11-Feb-2024 diff --git a/docs/rain_cc.md b/docs/rain_cc.md new file mode 100644 index 00000000..248a2eb7 --- /dev/null +++ b/docs/rain_cc.md @@ -0,0 +1,35 @@ +## rain cc + +Interact with templates using Cloud Control API instead of CloudFormation + +### Synopsis + +You must pass the --experimental (-x) flag to use this command, to acknowledge that it is experimental and likely to be unstable! + + +### Options + +``` + -h, --help help for cc + -p, --profile string AWS profile name; read from the AWS CLI configuration file + -r, --region string AWS region to use + --s3-bucket string Name of the S3 bucket that is used to upload assets + --s3-prefix string Prefix to add to objects uploaded to S3 bucket +``` + +### Options inherited from parent commands + +``` + --debug Output debugging information + --no-colour Disable colour output +``` + +### SEE ALSO + +* [rain](index.md) - +* [rain cc deploy](rain_cc_deploy.md) - Deploy a local template directly using the Cloud Control API (Experimental!) +* [rain cc drift](rain_cc_drift.md) - Compare the state file to the live state of the resources +* [rain cc rm](rain_cc_rm.md) - Delete a deployment created by cc deploy (Experimental!) +* [rain cc state](rain_cc_state.md) - Download the state file for a template deployed with cc deploy + +###### Auto generated by spf13/cobra on 11-Feb-2024 diff --git a/docs/rain_cc_deploy.md b/docs/rain_cc_deploy.md new file mode 100644 index 00000000..7bbe7768 --- /dev/null +++ b/docs/rain_cc_deploy.md @@ -0,0 +1,43 @@ +## rain cc deploy + +Deploy a local template directly using the Cloud Control API (Experimental!) + +### Synopsis + +Creates or updates resources directly using Cloud Control API from the template file