Skip to content

Commit

Permalink
qc
Browse files Browse the repository at this point in the history
  • Loading branch information
monde committed Jan 9, 2025
1 parent 9f8a7ec commit ee05f32
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
9 changes: 7 additions & 2 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 @@ -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
10 changes: 5 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ type Config struct {
Logger logger.Logger
}

// ConfigAttributes attributes for config construction
type ConfigAttributes struct {
// Attributes attributes for config construction
type Attributes struct {
AllProfiles bool
AuthzID string
AWSCredentials string
Expand Down Expand Up @@ -342,7 +342,7 @@ func NewEvaluatedConfig() (*Config, error) {
}

// NewConfig create config from attributes
func NewConfig(attrs *ConfigAttributes) (*Config, error) {
func NewConfig(attrs *Attributes) (*Config, error) {
var err error
cfg := &Config{
allProfiles: attrs.AllProfiles,
Expand Down Expand Up @@ -430,7 +430,7 @@ func (c *Config) ReadConfigProfileKeys() ([]string, error) {

// loadConfigAttributesFromFlagsAndVars helper function to load configuration
// attributes with viper by inspecting CLI flags then environment variables.
func loadConfigAttributesFromFlagsAndVars() (ConfigAttributes, error) {
func loadConfigAttributesFromFlagsAndVars() (Attributes, error) {
// Side loading multiple profiles from okta.yaml file if it exists
if oktaYamlConfig, err := NewOktaYamlConfig(); err == nil {
profiles := oktaYamlConfig.AWSCLI.PROFILES
Expand Down Expand Up @@ -461,7 +461,7 @@ func loadConfigAttributesFromFlagsAndVars() (ConfigAttributes, error) {
awsProfile = "default"
}

attrs := ConfigAttributes{
attrs := Attributes{
AllProfiles: viper.GetBool(getFlagNameFromProfile(awsProfile, AllProfilesFlag)),
AuthzID: viper.GetString(getFlagNameFromProfile(awsProfile, AuthzIDFlag)),
AWSCredentials: viper.GetString(getFlagNameFromProfile(awsProfile, AWSCredentialsFlag)),
Expand Down
13 changes: 7 additions & 6 deletions internal/logger/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ import (
)

// FullLogger logger for stderr (warn) and stdout (info) logging
type FullLogger struct {
}
type FullLogger struct{}

func (l *FullLogger) Info(format string, a ...any) (int, error) {
return fmt.Fprintf(os.Stdout, format, a...)
// Info prints formatted message to stdout
func (l *FullLogger) Info(format string, a ...any) {
_, _ = fmt.Fprintf(os.Stdout, format, a...)
}

func (l *FullLogger) Warn(format string, a ...any) (int, error) {
return fmt.Fprintf(os.Stderr, format, a...)
// Warn prints formatted message to stderr
func (l *FullLogger) Warn(format string, a ...any) {
_, _ = fmt.Fprintf(os.Stderr, format, a...)
}
4 changes: 2 additions & 2 deletions internal/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ package logger

// Logger Interface used for logging ouput
type Logger interface {
Info(format string, a ...any) (int, error)
Warn(format string, a ...any) (int, error)
Info(format string, a ...any)
Warn(format string, a ...any)
}
13 changes: 6 additions & 7 deletions internal/logger/terse.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import (
)

// TerseLogger logger that only prints info level lines
type TerseLogger struct {
}
type TerseLogger struct{}

func (l *TerseLogger) Info(format string, a ...any) (int, error) {
return fmt.Fprintf(os.Stdout, format, a...)
// Info prints formatted message to stdout
func (l *TerseLogger) Info(format string, a ...any) {
_, _ = fmt.Fprintf(os.Stdout, format, a...)
}

func (l *TerseLogger) Warn(format string, a ...any) (int, error) {
return -1, nil
}
// Warn is a no-op, it prints nothing
func (l *TerseLogger) Warn(format string, a ...any) {}
2 changes: 1 addition & 1 deletion internal/m2mauth/m2mauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestM2MAuthAccessToken(t *testing.T) {
}

func setupTest(t *testing.T) (*config.Config, func(t *testing.T)) {
attrs := &config.ConfigAttributes{
attrs := &config.Attributes{
OrgDomain: os.Getenv("OKTA_AWSCLI_ORG_DOMAIN"),
OIDCAppID: os.Getenv("OKTA_AWSCLI_OIDC_CLIENT_ID"),
AWSIAMRole: os.Getenv("OKTA_AWSCLI_IAM_ROLE"),
Expand Down
2 changes: 1 addition & 1 deletion internal/webssoauth/webssoauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestWebSSOAuthAccessToken(t *testing.T) {
}

func setupTest(t *testing.T) (*config.Config, func(t *testing.T)) {
attrs := &config.ConfigAttributes{
attrs := &config.Attributes{
OrgDomain: os.Getenv("OKTA_AWSCLI_ORG_DOMAIN"),
OIDCAppID: os.Getenv("OKTA_AWSCLI_OIDC_CLIENT_ID"),
}
Expand Down

0 comments on commit ee05f32

Please sign in to comment.