This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I can never remember the names of the profiles I have configured, so this command will list them for you. Caveat: It assumes you only care about profiles that are assuming from another role. It only lists profiles with a source_profile.
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
|
||
analytics "github.com/segmentio/analytics-go" | ||
"github.com/segmentio/aws-okta/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// listCmd represents the list command | ||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "list will show you the profiles currently configured", | ||
RunE: listRun, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(listCmd) | ||
} | ||
|
||
func listRun(cmd *cobra.Command, args []string) error { | ||
config, err := lib.NewConfigFromEnv() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
profiles, err := config.Parse() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
w := new(tabwriter.Writer) | ||
w.Init(os.Stdout, 0, 8, 2, '\t', 0) | ||
fmt.Fprintln(w, "profile\tarn\tsource_role\t") | ||
fmt.Fprintln(w, "---\t---\t---\t") | ||
for profile, v := range profiles { | ||
if role, exist := v["role_arn"]; exist { | ||
if src, exist := v["source_profile"]; exist { | ||
s := fmt.Sprintf("%s\t%s\t%s\t", profile, role, src) | ||
fmt.Fprintln(w, s) | ||
} | ||
} | ||
} | ||
w.Flush() | ||
|
||
if analyticsEnabled && analyticsClient != nil { | ||
analyticsClient.Enqueue(analytics.Track{ | ||
UserId: username, | ||
Event: "Listed Profiles", | ||
Properties: analytics.NewProperties(). | ||
Set("backend", backend). | ||
Set("aws-okta-version", version). | ||
Set("profile-count", len(profiles)). | ||
Set("command", "list"), | ||
}) | ||
} | ||
return nil | ||
} |