-
Notifications
You must be signed in to change notification settings - Fork 90
/
assumer_aws_google_auth.go
55 lines (47 loc) · 1.52 KB
/
assumer_aws_google_auth.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package cfaws
import (
"context"
"fmt"
"os"
"os/exec"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"gopkg.in/ini.v1"
)
// Implements Assumer
type AwsGoogleAuthAssumer struct {
}
// launch the aws-google-auth utility to generate the credentials
// then fetch them from the environment for use
func (aia *AwsGoogleAuthAssumer) AssumeTerminal(ctx context.Context, c *Profile, configOpts ConfigOpts) (aws.Credentials, error) {
cmd := exec.Command("aws-google-auth", fmt.Sprintf("--profile=%s", c.Name))
cmd.Stdout = os.Stderr
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
return aws.Credentials{}, err
}
creds := GetEnvCredentials(ctx)
if !creds.HasKeys() {
return aws.Credentials{}, fmt.Errorf("no credentials exported to terminal when using %s to assume profile: %s", aia.Type(), c.Name)
}
return creds, nil
}
func (aia *AwsGoogleAuthAssumer) AssumeConsole(ctx context.Context, c *Profile, configOpts ConfigOpts) (aws.Credentials, error) {
return aia.AssumeTerminal(ctx, c, configOpts)
}
// A unique key which identifies this assumer e.g AWS-SSO or GOOGLE-AWS-AUTH
func (aia *AwsGoogleAuthAssumer) Type() string {
return "AWS_GOOGLE_AUTH"
}
// inspect for any items on the profile prefixed with "google_config."
func (aia *AwsGoogleAuthAssumer) ProfileMatchesType(rawProfile *ini.Section, parsedProfile config.SharedConfig) bool {
for _, k := range rawProfile.KeyStrings() {
if strings.HasPrefix(k, "google_config.") {
return true
}
}
return false
}