diff --git a/aws/profile.go b/aws/profile.go index eada6b8..8038dc1 100644 --- a/aws/profile.go +++ b/aws/profile.go @@ -10,7 +10,6 @@ import ( "github.com/nanih98/aws-sso/dto" "github.com/nanih98/aws-sso/logger" "github.com/nanih98/aws-sso/utils" - "golang.design/x/clipboard" ) func getProfiles(filepath string) []dto.Profile { @@ -35,18 +34,7 @@ func getProfiles(filepath string) []dto.Profile { return items } -func clipBoard(log *logger.CustomLogger, profile string) { - err := clipboard.Init() - if err != nil { - log.Fatal(err) - } - clipboard.Write(clipboard.FmtText, []byte(fmt.Sprintf("export AWS_PROFILE='%s'", profile))) - log.Info(fmt.Sprintf("Profile %s copied to the clipboard, paste the command in your terminal to set the AWS_PROFILE env", profile)) -} - func Profile(log *logger.CustomLogger) { - log.Info("Setting your AWS_PROFILE environment variable...") - log.Info("Reading file .aws/credentials") credentialsPath := utils.GetUserHome(log) + "/.aws/credentials" profiles := getProfiles(credentialsPath) @@ -81,6 +69,6 @@ func Profile(log *logger.CustomLogger) { return } - // Return the selected profile to the clipboard - clipBoard(log, profiles[i].Key) + log.Info(fmt.Sprintf("Execute $ export AWS_PROFILE='%s' or see this following README...", profiles[i].Key)) + utils.RenderREADME("https://raw.githubusercontent.com/nanih98/aws-sso/main/docs/profile.md") } diff --git a/cmd/commands.go b/cmd/commands.go index 9f48403..fb8351b 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -90,7 +90,8 @@ func Usage() *cobra.Command { Short: "Usage will print the README.md of the project", Long: "Usage will print the readme of the project. You need internet connection because it will download the README from the github repository", Run: func(cmd *cobra.Command, args []string) { - utils.RenderREADME() + var url string = "https://raw.githubusercontent.com/nanih98/aws-sso/main/docs/usage.md" + utils.RenderREADME(url) }, } } diff --git a/docs/profile.md b/docs/profile.md new file mode 100644 index 0000000..9ae282d --- /dev/null +++ b/docs/profile.md @@ -0,0 +1,23 @@ +```bash +$ aws-sso profile +``` + +Once your credentials are configured (with the previous symlink) inside your **.aws/credentials** file, this command will read and promt each profile in an interactive terminal list. Then, the profile you selected, will be copied in your clipboard and then you will execute the command **export AWS_PROFILE=yourprofile** You can export the variable directly from a child process. Something like this issue + +> Note: in the interactive terminal, you can search for your profiles using SHIFT+/ + +This command at the end will do nothing, since we can export a variable from a child process. So, other solutions once you have all your credentials in inside `.aws/credentials` is the following: +```bash +aws-profile () { + PROFILE=$(cat ~/.aws/credentials|grep "^\["|sed "s/]$//"|sed "s/^\[//"| fzf) + export AWS_PROFILE=$PROFILE +} +``` +Save this function inside your `.bashrc` or `.zshrc`. + +* Requirements: `fzf` (`brew install fzf`) + +Is an interactive menu terminal to change `AWS_PROFILE` at the moment in your terminal. + +https://raw.githubusercontent.com/nanih98/aws-sso/main/docs/profile.md + diff --git a/docs/usage.md b/docs/usage.md index ccba24f..ecb2eab 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -10,14 +10,12 @@ $ aws-sso config --startURL "https://myaccount.awsapps.com/start" --region us-ea You can save more accounts: ```bash -aws-sso config --startURL "https://myaccount2.awsapps.com/start" --region eu-west-1 --profileName="myaccount2" +$ aws-sso config --startURL "https://myaccount2.awsapps.com/start" --region eu-west-1 --profileName="myaccount2" ``` * **startURL:** The AWS SSO url (get it from the AWS CONSOLE where you have your configured SSO). *Is required* * **region:** region of AWS of your SSO resource. The region where you created the SSO inside your AWS account. *Is required* * **profileName:** the name of the account, for example, the name of the company or the platform. *Is required* -> **NOTE:** this configuration will be saved inside your home `.aws-sso/profilename.json` - 2. Start the application This will open the browser where you are login with your external IDP provider and will start getting the aws credentials for each account your user have access. Will write all the access key, secret key and token inside your **.aws/credentials** file. @@ -51,9 +49,7 @@ This will create a symlink in your home `.aws/`. The selected profile will be a 4. Set the profile -Once your credentials are configured (with the previous symlink) inside your **.aws/credentials** file, this command will read and promt each profile in an interactive terminal list. Then, the profile you selected, will be copied in your clipboard and then you will execute the command **export AWS_PROFILE=yourprofile** You can export the variable directly from a child process. Something like this issue - -> Note: in the interactive terminal, you can search for your profiles using SHIFT+/ +Take a look [profile](./profile.md) 5. Usage @@ -63,7 +59,7 @@ This will show this file in a terminal markdown render. $ aws-sso usage ``` -1. Version +6. Version Get your aws-sso version installed in your local. diff --git a/utils/readme.go b/utils/readme.go index 4d6ec87..0bb4461 100644 --- a/utils/readme.go +++ b/utils/readme.go @@ -9,9 +9,7 @@ import ( "github.com/charmbracelet/glamour" ) -var url string = "https://raw.githubusercontent.com/nanih98/aws-sso/main/docs/usage.md" - -func RenderREADME() { +func RenderREADME(url string) { resp, err := http.Get(url) if err != nil {