Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial pass * more porting * clean up linting * update deps * fix confirm-text prompt * initial rotate support * fix double-confirm * set rotator store * fix readme
- Loading branch information
Showing
19 changed files
with
1,048 additions
and
25 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
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
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,25 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/akerl/voyager/v2/cartogram" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(profilesCmd) | ||
} | ||
|
||
var profilesCmd = &cobra.Command{ | ||
Use: "profiles", | ||
Short: "manage stored AWS credentials", | ||
} | ||
|
||
func getAllProfiles() ([]string, error) { | ||
pack := cartogram.Pack{} | ||
if err := pack.Load(); err != nil { | ||
return []string{}, err | ||
} | ||
|
||
return pack.AllProfiles(), nil | ||
} |
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,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/akerl/voyager/v2/profiles" | ||
|
||
"github.com/akerl/input/list" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
profilesCmd.AddCommand(profilesAddCmd) | ||
} | ||
|
||
var profilesAddCmd = &cobra.Command{ | ||
Use: "add", | ||
Short: "add new AWS credentials", | ||
RunE: profilesAddRunner, | ||
} | ||
|
||
func profilesAddRunner(_ *cobra.Command, args []string) error { | ||
var inputProfile string | ||
if len(args) != 0 { | ||
inputProfile = args[0] | ||
} | ||
|
||
store := profiles.NewDefaultStore() | ||
|
||
allProfiles, err := getAllProfiles() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
profile, err := list.WithInputString( | ||
list.Default(), | ||
allProfiles, | ||
inputProfile, | ||
"Profile to add", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
check := store.Check(profile) | ||
if check { | ||
fmt.Println( | ||
"Profile is already stored; if you wish to update it, use the rotate command. " + | ||
"If you want to remove it, use the remove command", | ||
) | ||
return nil | ||
} | ||
_, err = store.Lookup(profile) | ||
if err == nil { | ||
fmt.Println("Successfully added profile") | ||
} | ||
return err | ||
} |
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,49 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/akerl/voyager/v2/profiles" | ||
"github.com/akerl/voyager/v2/utils" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
profilesCmd.AddCommand(profilesDeleteCmd) | ||
} | ||
|
||
var profilesDeleteCmd = &cobra.Command{ | ||
Use: "delete PROFILE", | ||
Short: "delete a stored AWS credential", | ||
RunE: profilesDeleteRunner, | ||
} | ||
|
||
func profilesDeleteRunner(_ *cobra.Command, args []string) error { | ||
if len(args) != 1 { | ||
return fmt.Errorf("no profile name provided") | ||
} | ||
profile := args[0] | ||
|
||
store := profiles.NewDefaultStore() | ||
|
||
check := store.Check(profile) | ||
if !check { | ||
fmt.Printf("No credentials stored for profile: %s\n", profile) | ||
return nil | ||
} | ||
|
||
err := utils.ConfirmText( | ||
"this is a destructive operation", | ||
fmt.Sprintf("This will delete the following profile: %s", profile), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = store.Delete(profile) | ||
if err == nil { | ||
fmt.Println("Deleted stored profile") | ||
} | ||
return err | ||
} |
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,45 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/akerl/voyager/v2/profiles" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
profilesCmd.AddCommand(profilesListCmd) | ||
} | ||
|
||
var profilesListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "list stored AWS credentials", | ||
RunE: profilesListRunner, | ||
} | ||
|
||
func profilesListRunner(_ *cobra.Command, _ []string) error { | ||
allProfiles, err := getAllProfiles() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
store := profiles.NewDefaultStore() | ||
existing := profiles.BulkCheck(store, allProfiles) | ||
|
||
if len(existing) == 0 { | ||
fmt.Println("No credentials found") | ||
return nil | ||
} | ||
|
||
sort.Strings(existing) | ||
for _, item := range existing { | ||
creds, err := store.Lookup(item) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%s (%s)\n", item, creds.AccessKeyID) | ||
} | ||
return nil | ||
} |
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,38 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/akerl/voyager/v2/profiles" | ||
"github.com/akerl/voyager/v2/rotate" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
profilesCmd.AddCommand(profilesRotateCmd) | ||
profilesRotateCmd.Flags().BoolP("yubikey", "y", false, "Store MFA on yubikey") | ||
} | ||
|
||
var profilesRotateCmd = &cobra.Command{ | ||
Use: "rotate", | ||
Short: "saves a new AWS keypair and MFA device from existing creds", | ||
RunE: profilesRotateRunner, | ||
} | ||
|
||
func profilesRotateRunner(cmd *cobra.Command, args []string) error { | ||
var inputProfile string | ||
if len(args) != 0 { | ||
inputProfile = args[0] | ||
} | ||
|
||
useYubikey, err := cmd.Flags().GetBool("yubikey") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r := rotate.Rotator{ | ||
UseYubikey: useYubikey, | ||
InputProfile: inputProfile, | ||
Store: profiles.NewDefaultStore(), | ||
} | ||
return r.Execute() | ||
} |
Oops, something went wrong.