-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46a71fd
commit 892471a
Showing
5 changed files
with
112 additions
and
1,278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/Laica-Lunasys/awsctx/service" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// openCmd represents the login command | ||
var openCmd = &cobra.Command{ | ||
Use: "open", | ||
Short: "Open browser", | ||
Long: `Open browser`, | ||
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | ||
p, err := service.GetSAML2AWS() | ||
if err != nil { | ||
panic(err) | ||
} | ||
profiles, err := p.GetProfiles() | ||
if err != nil { | ||
return []string{}, cobra.ShellCompDirectiveError | ||
} | ||
return profiles, cobra.ShellCompDirectiveDefault | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 1 { | ||
fmt.Println("Invalid args") | ||
os.Exit(1) | ||
} | ||
p, err := service.GetSAML2AWS() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Firefox | ||
firefox, err := cmd.Flags().GetBool("firefox") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// MFA | ||
token, err := cmd.Flags().GetString("mfa") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := p.Login(args[0], | ||
&service.LoginOption{ | ||
Console: true, | ||
LinkOnly: false, | ||
Firefox: firefox, | ||
UpdateProfile: false, | ||
}, | ||
func() *service.MFA { | ||
if token != "" { | ||
return &service.MFA{Token: token} | ||
} | ||
return nil | ||
}(), | ||
); err != nil { | ||
panic(err) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(openCmd) | ||
openCmd.Flags().BoolP("firefox", "F", false, "Open as Firefox") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.