Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #44 from reverson/master
Browse files Browse the repository at this point in the history
Add Duration flags to login cmd
  • Loading branch information
dfuentes committed May 8, 2018
2 parents 5dcb035 + 54cdf0a commit ed134f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io/ioutil"
"net/http"
"net/url"
"os"
"time"

"github.com/99designs/keyring"
analytics "github.com/segmentio/analytics-go"
Expand All @@ -16,9 +18,10 @@ import (

// loginCmd represents the login command
var loginCmd = &cobra.Command{
Use: "login <profile>",
Short: "login will authenticate you through okta and allow you to access your AWS environment through a browser",
RunE: loginRun,
Use: "login <profile>",
Short: "login will authenticate you through okta and allow you to access your AWS environment through a browser",
RunE: loginRun,
PreRun: loginPre,
}

// Stdout is the bool for -stdout
Expand All @@ -27,6 +30,18 @@ var Stdout bool
func init() {
RootCmd.AddCommand(loginCmd)
loginCmd.Flags().BoolVarP(&Stdout, "stdout", "", false, "Print login URL to stdout instead of opening in default browser")
loginCmd.Flags().DurationVarP(&sessionTTL, "session-ttl", "t", time.Hour, "Expiration time for okta role session")
loginCmd.Flags().DurationVarP(&assumeRoleTTL, "assume-role-ttl", "a", time.Hour, "Expiration time for assumed role")
}

func loginPre(cmd *cobra.Command, args []string) {
if err := loadDurationFlagFromEnv(cmd, "session-ttl", "AWS_SESSION_TTL", &sessionTTL); err != nil {
fmt.Fprintln(os.Stderr, "warning: failed to parse duration from AWS_SESSION_TTL")
}

if err := loadDurationFlagFromEnv(cmd, "assume-role-ttl", "AWS_ASSUME_ROLE_TTL", &assumeRoleTTL); err != nil {
fmt.Fprintln(os.Stderr, "warning: failed to parse duration from AWS_ASSUME_ROLE_TTL")
}
}

func loginRun(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
MaxSessionDuration = time.Hour * 36
MinSessionDuration = time.Minute * 15
MinAssumeRoleDuration = time.Minute * 15
MaxAssumeRoleDuration = time.Hour
MaxAssumeRoleDuration = time.Hour * 12

DefaultSessionDuration = time.Hour * 4
DefaultAssumeRoleDuration = time.Minute * 15
Expand Down

0 comments on commit ed134f4

Please sign in to comment.