Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--debug flag and release candidate #113

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.1.0 (July 13, 2023)

* Print out operational debugging information flag [#113](https://github.com/okta/okta-aws-cli/pull/113), thanks [@monde](https://github.com/monde)!

## 1.0.2 (June 27, 2023)

* [#112](https://github.com/okta/okta-aws-cli/pull/112), thanks [@monde](https://github.com/monde)!
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Also see the CLI's online help `$ okta-aws-cli --help`
| (Over)write the given profile to the AWS credentials file (optional). WARNING: When enabled, overwriting can inadvertently remove dangling comments and extraneous formatting from the creds file. | `OKTA_AWSCLI_WRITE_AWS_CREDENTIALS=true` | `--write-aws-credentials` | `true` if flag is present |
| Emit deprecated AWS variable `aws_security_token` with duplicated value from `aws_session_token` | `OKTA_AWSCLI_LEGACY_AWS_VARIABLES=true` | `--legacy-aws-variables` | `true` if flag is present |
| Emit expiry timestamp `x_security_token_expires` in RFC3339 format for the session/security token (AWS credentials file only) | `OKTA_AWSCLI_EXPIRY_AWS_VARIABLES=true` | `--expiry-aws-variables` | `true` if flag is present |
| Print operational information to the screen for debugging purposes | `OKTA_AWSCLI_DEBUG=true` | `--debug` | `true` if flag is present |
| Verbosely print all API calls/responses to the screen | `OKTA_AWSCLI_DEBUG_API_CALLS=true` | `--debug-api-calls` | `true` if flag is present |
| HTTP/HTTPS Proxy support | `HTTP_PROXY` or `HTTPS_PROXY` | n/a | HTTP/HTTPS URL of proxy service (based on golang [net/http/httpproxy](https://pkg.go.dev/golang.org/x/net/http/httpproxy) package) |
| Debug okta.yaml config file and exit | `OKTA_AWSCLI_DEBUG_CONFIG=true` | `--debug-config` | `true` if flag is present |
Expand Down
7 changes: 7 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ func init() {
usage: "Cache Okta access token to reduce need for opening grant URL",
envVar: config.CacheAccessTokenEnvVar,
},
{
name: config.DebugFlag,
short: "g",
value: false,
usage: "Print operational information to the screen for debugging purposes",
envVar: config.DebugEnvVar,
},
{
name: config.DebugAPICallsFlag,
short: "d",
Expand Down
24 changes: 23 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

const (
// Version app version
Version = "1.0.2"
Version = "1.1.0"

// AWSCredentialsFormat format const
AWSCredentialsFormat = "aws-credentials"
Expand All @@ -46,6 +46,8 @@ const (
AWSIAMIdPFlag = "aws-iam-idp"
// AWSIAMRoleFlag cli flag const
AWSIAMRoleFlag = "aws-iam-role"
// DebugFlag cli flag const
DebugFlag = "debug"
// DebugAPICallsFlag cli flag const
DebugAPICallsFlag = "debug-api-calls"
// DebugConfigFlag cli flag const
Expand Down Expand Up @@ -97,6 +99,8 @@ const (
QRCodeEnvVar = "OKTA_AWSCLI_QR_CODE"
// WriteAWSCredentialsEnvVar env var const
WriteAWSCredentialsEnvVar = "OKTA_AWSCLI_WRITE_AWS_CREDENTIALS"
// DebugEnvVar env var const
DebugEnvVar = "OKTA_AWSCLI_DEBUG"
// DebugAPICallsEnvVar env var const
DebugAPICallsEnvVar = "OKTA_AWSCLI_DEBUG_API_CALLS"
// DebugConfigEnvVar env var const
Expand Down Expand Up @@ -133,6 +137,7 @@ type Config struct {
awsCredentials string
writeAWSCredentials bool
openBrowser bool
debug bool
debugAPICalls bool
debugConfig bool
legacyAWSVariables bool
Expand Down Expand Up @@ -162,6 +167,7 @@ type Attributes struct {
AWSCredentials string
WriteAWSCredentials bool
OpenBrowser bool
Debug bool
DebugAPICalls bool
DebugConfig bool
LegacyAWSVariables bool
Expand Down Expand Up @@ -194,6 +200,7 @@ func NewConfig(attrs Attributes) (*Config, error) {
awsCredentials: attrs.AWSCredentials,
writeAWSCredentials: attrs.WriteAWSCredentials,
openBrowser: attrs.OpenBrowser,
debug: attrs.Debug,
debugAPICalls: attrs.DebugAPICalls,
debugConfig: attrs.DebugConfig,
legacyAWSVariables: attrs.LegacyAWSVariables,
Expand Down Expand Up @@ -232,6 +239,7 @@ func readConfig() (Attributes, error) {
AWSIAMIdP: viper.GetString(AWSIAMIdPFlag),
AWSIAMRole: viper.GetString(AWSIAMRoleFlag),
AWSSessionDuration: viper.GetInt64(SessionDurationFlag),
Debug: viper.GetBool(DebugFlag),
DebugAPICalls: viper.GetBool(DebugAPICallsFlag),
DebugConfig: viper.GetBool(DebugConfigFlag),
FedAppID: viper.GetString(AWSAcctFedAppIDFlag),
Expand Down Expand Up @@ -325,6 +333,9 @@ func readConfig() (Attributes, error) {
if !attrs.OpenBrowser {
attrs.OpenBrowser = viper.GetBool(downCase(OpenBrowserEnvVar))
}
if !attrs.Debug {
attrs.Debug = viper.GetBool(downCase(DebugEnvVar))
}
if !attrs.DebugAPICalls {
attrs.DebugAPICalls = viper.GetBool(downCase(DebugAPICallsEnvVar))
}
Expand Down Expand Up @@ -486,6 +497,17 @@ func (c *Config) SetOpenBrowser(openBrowser bool) error {
return nil
}

// Debug --
func (c *Config) Debug() bool {
return c.debug
}

// SetDebug --
func (c *Config) SetDebug(debug bool) error {
c.debug = debug
return nil
}

// DebugAPICalls --
func (c *Config) DebugAPICalls() bool {
return c.debugAPICalls
Expand Down
10 changes: 10 additions & 0 deletions internal/sessiontoken/sessiontoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,17 @@ func (s *SessionToken) selectFedApp(apps []*oktaApplication) (string, error) {
choice = fmt.Sprintf(choiceArnPrintFmt, choice, app.Settings.App.IdentityProviderARN)
if oktaConfig != nil && len(oktaConfig.AWSCLI.IDPS) > 0 {
if label, ok := oktaConfig.AWSCLI.IDPS[app.Settings.App.IdentityProviderARN]; ok {
if s.config.Debug() {
fmt.Fprintf(os.Stderr, " found IdP ARN %q having friendly label %q\n", app.Settings.App.IdentityProviderARN, label)
}
choice = label
} else if s.config.Debug() {
fmt.Fprintf(os.Stderr, " did not find friendly label for IdP ARN\n")
fmt.Fprintf(os.Stderr, " %q\n", app.Settings.App.IdentityProviderARN)
fmt.Fprintf(os.Stderr, " in okta.yaml awscli.idps map:\n")
for arn, label := range oktaConfig.AWSCLI.IDPS {
fmt.Fprintf(os.Stderr, " %q: %q\n", arn, label)
}
}
}
}
Expand Down