Skip to content

Commit

Permalink
Merge pull request #261 from okta/process_credentials_output
Browse files Browse the repository at this point in the history
Control stdio for process credentials output
  • Loading branch information
monde authored Jan 11, 2025
2 parents ed51fe0 + ee05f32 commit e26279e
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 103 deletions.
7 changes: 2 additions & 5 deletions cmd/root/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
package debug

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/okta/okta-aws-cli/internal/config"
Expand All @@ -31,13 +28,13 @@ func NewDebugCommand() *cobra.Command {
Use: "debug",
Short: "Simple debug of okta.yaml and exit",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := config.EvaluateSettings()
config, err := config.NewEvaluatedConfig()
if err != nil {
return err
}
err = config.RunConfigChecks()
// NOTE: still print out the done message, even if there was an error it will get printed as well
fmt.Fprintf(os.Stderr, "debugging okta-aws-cli config $HOME/.okta/okta.yaml is complete\n")
config.Logger.Warn("debugging okta-aws-cli config $HOME/.okta/okta.yaml is complete\n")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root/m2m/m2m.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewM2MCommand() *cobra.Command {
Use: "m2m",
Short: "Machine to machine / headless authorization",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := config.EvaluateSettings()
config, err := config.NewEvaluatedConfig()
if err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/root/profileslist/profiles-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package profileslist

import (
"fmt"

"github.com/spf13/cobra"

"github.com/okta/okta-aws-cli/internal/config"
Expand All @@ -30,20 +28,20 @@ func NewProfilesListCommand() *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()
config, err := config.NewEvaluatedConfig()
if err != nil {
return err
}

fmt.Println("Profiles:")
config.Logger.Info("Profiles:\n")

keys, err := config.ReadConfigProfileKeys()
if err != nil {
return err
}

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

return nil
Expand Down
13 changes: 9 additions & 4 deletions cmd/root/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"github.com/okta/okta-aws-cli/internal/webssoauth"
)

const (
// InvalidGrant constant
InvalidGrant = "invalid_grant"
)

var (
flags = []cliFlag.Flag{
{
Expand Down Expand Up @@ -81,12 +86,12 @@ func NewWebCommand() *cobra.Command {
Use: "web",
Short: "Human oriented authentication and device authorization",
RunE: func(cmd *cobra.Command, args []string) error {
cfg, err := config.EvaluateSettings()
cfg, err := config.NewEvaluatedConfig()
if err != nil {
return err
}

_, err = config.OktaConfig()
_, err = config.NewOktaYamlConfig()
if err != nil {
if _, pathError := err.(*fs.PathError); !pathError {
// Warn if okta.yaml exists and there is an error with it.
Expand All @@ -111,7 +116,7 @@ func NewWebCommand() *cobra.Command {
err = wsa.EstablishIAMCredentials()
apiErr, ok = err.(*okta.APIError)
if ok {
if apiErr.ErrorType == "invalid_grant" && webssoauth.RemoveCachedAccessToken() {
if apiErr.ErrorType == InvalidGrant && webssoauth.RemoveCachedAccessToken() {
webssoauth.ConsolePrint(cfg, "Cached access token appears to be stale, removing token and retrying device authorization ...\n\n")
continue
}
Expand All @@ -124,7 +129,7 @@ func NewWebCommand() *cobra.Command {
}

if err != nil {
if apiErr != nil && apiErr.ErrorType == "invalid_grant" {
if apiErr != nil && apiErr.ErrorType == InvalidGrant {
webssoauth.ConsolePrint(cfg, "Authentication failed after multiple attempts. Please log out of Okta in your browser and log back in to resolve the issue.\n")
}
return err
Expand Down
Loading

0 comments on commit e26279e

Please sign in to comment.