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

Added CLI arguments for aws-okta add #137

Merged
merged 3 commits into from
Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
51 changes: 35 additions & 16 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (
"github.com/spf13/cobra"
)

var (
organization string
oktaRegion string
oktaDomain string
)

// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add",
Expand All @@ -21,6 +27,10 @@ var addCmd = &cobra.Command{

func init() {
RootCmd.AddCommand(addCmd)
addCmd.Flags().StringVarP(&organization, "organization", "", "", "Okta organization name")
addCmd.Flags().StringVarP(&oktaRegion, "okta-region", "", "", "Okta region (us, emea, preview)")
nickatsegment marked this conversation as resolved.
Show resolved Hide resolved
addCmd.Flags().StringVarP(&oktaDomain, "okta-domain", "", "", "Okta domain (e.g. <orgname>.okta.com)")
addCmd.Flags().StringVarP(&username, "okta-username", "", "", "Okta username")
}

func add(cmd *cobra.Command, args []string) error {
Expand All @@ -45,30 +55,39 @@ func add(cmd *cobra.Command, args []string) error {
})
}

// Ask username password from prompt
organization, err := lib.Prompt("Okta organization", false)
if err != nil {
return err
// Ask Okta organization details and username if not given in command line arguments
if organization == "" {
organization, err = lib.Prompt("Okta organization", false)
if err != nil {
return err
}
}

oktaRegion, err := lib.Prompt("Okta region ([us], emea, preview)", false)
if err != nil {
return err
if oktaRegion == "" {
nickatsegment marked this conversation as resolved.
Show resolved Hide resolved
oktaRegion, err = lib.Prompt("Okta region ([us], emea, preview)", false)
if err != nil {
return err
}
}
if oktaRegion == "" {
oktaRegion = "us"
}

oktaDomain, err := lib.Prompt("Okta domain ["+oktaRegion+".okta.com]", false)
if err != nil {
return err
if oktaDomain == "" {
oktaDomain, err = lib.Prompt("Okta domain ["+organization+".okta.com]", false)
nickatsegment marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
}

username, err := lib.Prompt("Okta username", false)
if err != nil {
return err
if username == "" {
username, err = lib.Prompt("Okta username", false)
if err != nil {
return err
}
}

// Ask for password from prompt
password, err := lib.Prompt("Okta password", true)
if err != nil {
return err
Expand Down Expand Up @@ -98,9 +117,9 @@ func add(cmd *cobra.Command, args []string) error {
}

item := keyring.Item{
Key: "okta-creds",
Data: encoded,
Label: "okta credentials",
Key: "okta-creds",
Data: encoded,
Label: "okta credentials",
KeychainNotTrustApplication: false,
}

Expand Down
7 changes: 4 additions & 3 deletions lib/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func NewOktaClient(creds OktaCreds, oktaAwsSAMLUrl string, sessionCookie string,
},
})
}
log.Debug("domain: " + domain)

return &OktaClient{
// Setting Organization for backwards compatibility
Expand Down Expand Up @@ -561,9 +562,9 @@ func (p *OktaProvider) Retrieve() (sts.Credentials, string, error) {
}

newCookieItem := keyring.Item{
Key: p.OktaSessionCookieKey,
Data: []byte(newSessionCookie),
Label: "okta session cookie",
Key: p.OktaSessionCookieKey,
Data: []byte(newSessionCookie),
Label: "okta session cookie",
KeychainNotTrustApplication: false,
}

Expand Down