Skip to content

Commit

Permalink
- Adding list-profiles command
Browse files Browse the repository at this point in the history
- Fixing warning
- Fixing warnings
- Adding whitespace
- Updating CONTRIBUTING.md to include signing instructions

Bringing in @pmgalea's #220 `okta-aws-cli list-profiles` command.

Closes #220
  • Loading branch information
Philip Galea authored and monde committed Jul 12, 2024
1 parent 2fb145e commit 97fc651
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ dist/
.vscode
.env*
!.env.example
bin/
.idea
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ $ git checkout -b feature_x
(make your changes)
$ git status
$ git add <files>
$ git commit -m "descriptive commit message for your changes"
$ git commit -S -m "descriptive commit message for your changes"
```

> The `-b` specifies that you want to create a new branch called `feature_x`.
> You only specify `-b` the first time you checkout because you are creating a
> new branch. Once the `feature_x` branch exists, you can later switch to it
> with only `git checkout feature_x`.
> The `-S` on the commit signs the commit. Please ensure you follow the instructions on
> [https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits)

Rebase `feature_x` to include updates from `upstream/master`
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ format.
- [Non-Admin Users](#non-admin-users)
- [M2M Command](#m2m-command)
- [M2M Command Requirements](#m2m-command-requirements)
- [List-Profiles Command](#list-profiles-command)
- [Configuration](#configuration)
- [Global settings](#global-settings)
- [Web command settings](#web-command-settings)
Expand All @@ -70,6 +71,7 @@ format.
| (empty) | When `okta-aws-cli` is executed without a subcommand and without arguments it will print the online help and exit. |
| `web` | Human oriented retrieval of temporary IAM credentials through Okta authentication and device authorization. Note: if `okta-aws-cli` is not given a subcommand it defaults to this original `web` command when other arguments are present. |
| `m2m` | Machine/headless oriented retrieval of temporary IAM credentials through Okta authentication with a private key. IMPORTANT! This a not a feature intended for a human use case. Be sure to use industry state of the art secrets management techniques with the private key. |
| `list-profiles` | Lists profile names in ~/.okta/okta.yaml. |
| `debug` | Debug okta.yaml config file and exit. |

## Web Command
Expand Down Expand Up @@ -319,6 +321,20 @@ role of the `sts:AssumeRoleWithWebIdentity` action type. This setting is on the
trust relationship tab when viewing a specific role in the AWS Console. Also
note the ARNs of these roles for later use.

## List-Profiles Command

```shell
$ okta-aws-cli list-profiles
Profiles:

sample-account X(Non-Prod)
sample-account X (Prod)
another-sample-account Y (Non-Prod)
```

List-profiles command is a human oriented command to show the list of profile names stored in the ~/.okta/okta.yaml file. The user
executes `okta-aws-cli list-profiles` where a list of profile name shall be listed for convenience. The names will be indented.

## Configuration
### Global settings

Expand Down
54 changes: 54 additions & 0 deletions cmd/root/profileslist/profiles-list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023-Present, Okta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package profileslist

import (
"fmt"
"github.com/spf13/cobra"

"github.com/okta/okta-aws-cli/internal/config"
)

// NewProfilesListCommand Sets up the debug cobra sub command
func NewProfilesListCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "list-profiles",
Short: "Lists profile names in ~/.okta/okta.yaml",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := config.EvaluateSettings()
if err != nil {
return err
}

fmt.Println("Profiles:")

keys, err := config.ReadConfigProfileKeys()

if err != nil {
return err
}

for _, key := range keys {
fmt.Printf(" %s\n", key)
}

return nil
},
}

return cmd
}
3 changes: 3 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package root

import (
"fmt"
"github.com/okta/okta-aws-cli/cmd/root/profileslist"
"os"
"path/filepath"

Expand Down Expand Up @@ -157,6 +158,8 @@ func init() {
rootCmd.AddCommand(m2mCmd)
debugCfgCmd := debugCmd.NewDebugCommand()
rootCmd.AddCommand(debugCfgCmd)
listProfilesCmd := profileslist.NewProfilesListCommand()
rootCmd.AddCommand(listProfilesCmd)
}

// NewRootCommand Sets up the root cobra command
Expand Down
17 changes: 17 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,23 @@ func getFlagNameFromProfile(awsProfile string, flag string) string {
return flag
}

// ReadConfigProfileKeys returns the config profile names
func (c *Config) ReadConfigProfileKeys() ([]string, error) {
// Side loading multiple profiles from okta.yaml file if it exists
if oktaConfig, err := OktaConfig(); err == nil {
profiles := oktaConfig.AWSCLI.PROFILES

keys := make([]string, 0, len(profiles))

for k := range profiles {
keys = append(keys, k)
}
return keys, err
}

return nil, nil
}

func readConfig() (Attributes, error) {
// Side loading multiple profiles from okta.yaml file if it exists
if oktaConfig, err := OktaConfig(); err == nil {
Expand Down

0 comments on commit 97fc651

Please sign in to comment.