Skip to content

Commit

Permalink
Add open command
Browse files Browse the repository at this point in the history
  • Loading branch information
Laica-Lunasys committed Sep 8, 2022
1 parent 46a71fd commit 892471a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 1,278 deletions.
14 changes: 11 additions & 3 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ var loginCmd = &cobra.Command{
if err != nil {
panic(err)
}

// Update Profile
updateProfile := true
if os.Getenv("NO_AWS_PROFILE") != "" {
updateProfile = false
}

if err := p.Login(args[0],
&service.LoginOption{
Console: console,
LinkOnly: link,
Firefox: firefox,
Console: console,
LinkOnly: link,
Firefox: firefox,
UpdateProfile: updateProfile,
},
func() *service.MFA {
if token != "" {
Expand Down
71 changes: 71 additions & 0 deletions cmd/open.go
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")
}
34 changes: 2 additions & 32 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@ module github.com/Laica-Lunasys/awsctx
go 1.16

require (
cloud.google.com/go/kms v1.0.0 // indirect
cloud.google.com/go/storage v1.18.0 // indirect
github.com/Azure/azure-sdk-for-go v58.1.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.21 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.16 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/DisgoOrg/disgohook v1.4.4 // indirect
github.com/DisgoOrg/log v1.1.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7 // indirect
github.com/aws/aws-sdk-go v1.41.1 // indirect
github.com/aws/aws-sdk-go-v2/config v1.8.3 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.7.0 // indirect
github.com/caarlos0/env/v6 v6.7.1 // indirect
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
github.com/dghubble/go-twitter v0.0.0-20211002212826-ad02880e616b // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/golang-jwt/jwt/v4 v4.1.0 // indirect
github.com/goreleaser/goreleaser v0.182.1 // indirect
github.com/goreleaser/nfpm/v2 v2.7.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/slack-go/slack v0.9.5 // indirect
github.com/spf13/cobra v1.2.1
github.com/vartanbeno/go-reddit/v2 v2.0.1 // indirect
github.com/xanzy/go-gitlab v0.51.1 // indirect
golang.org/x/net v0.0.0-20211011170408-caeb26a5c8c0 // indirect
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 // indirect
google.golang.org/api v0.58.0 // indirect
google.golang.org/genproto v0.0.0-20211013025323-ce878158c4d4 // indirect
google.golang.org/grpc v1.41.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/spf13/cobra v1.5.0
)
Loading

0 comments on commit 892471a

Please sign in to comment.