Skip to content

Commit

Permalink
fix: Added the profile name to the mfa token prompt when setting an a…
Browse files Browse the repository at this point in the history
…ws environment (#12)
  • Loading branch information
jeff-roche authored Jul 28, 2022
1 parent ede245b commit 6d5a905
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ $ biome save -b my-biome -f my.env

## Future Plans
- Have goreleaser create a docker image and publish to ghcr
- :white_check_mark: Custom MFA token message for AWS profiles
- :white_check_mark: Export loaded variables to a dotenv file
- :white_check_mark: Switch to [cobra](https://github.com/spf13/cobra) for the cli
- :white_check_mark: Allow CLI input to be a secret (for passwords)
Expand Down
15 changes: 14 additions & 1 deletion src/repos/aws_sts.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package repos

import (
"context"
"fmt"
"os"

"github.com/aws/aws-sdk-go-v2/aws"
Expand All @@ -11,6 +12,8 @@ import (
"github.com/jeff-roche/biome/src/lib/types"
)

var awsProfileName string = ""

type AwsStsRepositoryIfc interface {
ConfigureSession(profile string) (*types.AwsEnvConfig, error)
SetAwsEnvs(*types.AwsEnvConfig)
Expand Down Expand Up @@ -67,6 +70,8 @@ func (repo AwsStsRepository) loadProfile(profile string) (config.SharedConfig, e
}

func (repo AwsStsRepository) loadAwsConfig(profCfg *config.SharedConfig) (aws.Config, error) {
awsProfileName = profCfg.Profile

return config.LoadDefaultConfig(
context.TODO(),
config.WithSharedConfigProfile(profCfg.Profile),
Expand All @@ -75,7 +80,7 @@ func (repo AwsStsRepository) loadAwsConfig(profCfg *config.SharedConfig) (aws.Co
func(aro *stscreds.AssumeRoleOptions) {
if profCfg.MFASerial != "" {
aro.SerialNumber = &profCfg.MFASerial
aro.TokenProvider = stscreds.StdinTokenProvider
aro.TokenProvider = CustomStdinTokenProvider
}
},
),
Expand All @@ -99,3 +104,11 @@ func (repo AwsStsRepository) setupAwsSession(cfg *aws.Config, profile *config.Sh

return creds, nil
}

func CustomStdinTokenProvider() (string, error) {
var v string
fmt.Printf("MFA token for AWS profile '%s': ", awsProfileName)
_, err := fmt.Scanln(&v)

return v, err
}

0 comments on commit 6d5a905

Please sign in to comment.