Skip to content

Commit

Permalink
Add MFA support
Browse files Browse the repository at this point in the history
  • Loading branch information
stilvoid committed Nov 13, 2019
1 parent 635b440 commit 6d84c17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 14 additions & 1 deletion client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"

"github.com/aws-cloudformation/rain/config"
"github.com/aws-cloudformation/rain/console"
"github.com/aws-cloudformation/rain/console/run"
"github.com/aws-cloudformation/rain/console/spinner"
"github.com/aws-cloudformation/rain/version"
Expand All @@ -21,6 +22,16 @@ import (
"github.com/aws/aws-sdk-go-v2/aws/external"
)

func MFAProvider() (string, error) {
spinner.Pause()
defer func() {
fmt.Println()
spinner.Resume()
}()

return console.Ask("MFA Token:"), nil
}

var awsCfg *aws.Config

var defaultPython = []string{"/usr/bin/env", "python"}
Expand Down Expand Up @@ -77,7 +88,9 @@ func loadConfig() aws.Config {
var cfg aws.Config
var err error

configs := make([]external.Config, 0)
configs := []external.Config{
external.WithMFATokenFunc(MFAProvider),
}

if config.Profile != "" {
configs = append(configs, external.WithSharedConfigProfile(config.Profile))
Expand Down
8 changes: 8 additions & 0 deletions console/spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ func Stop() {
console.ClearLine()
}

func Pause() {
spinRunning = false
}

func Resume() {
spinRunning = true
}

// Update redisplays the spinner. Use this if your programme has updated
// the screen and may have interfered with the spinners display location.
func Update() {
Expand Down

0 comments on commit 6d84c17

Please sign in to comment.