(ctx context.Context, profile string)
| 83 | } |
| 84 | |
| 85 | func loadConfigWithSourceProfileFallback(ctx context.Context, profile string) (aws.Config, bool, error) { |
| 86 | target, found, err := loadAWSProfileSettings(profile) |
| 87 | if err != nil { |
| 88 | return aws.Config{}, false, nil |
| 89 | } |
| 90 | if !found || target.RoleARN == "" || target.SourceProfileName == "" { |
| 91 | return aws.Config{}, false, nil |
| 92 | } |
| 93 | |
| 94 | source, found, err := loadAWSProfileSettings(target.SourceProfileName) |
| 95 | if err != nil { |
| 96 | return aws.Config{}, false, nil |
| 97 | } |
| 98 | if !found || source.LoginSession == "" { |
| 99 | return aws.Config{}, false, nil |
| 100 | } |
| 101 | if target.MFASerial != "" { |
| 102 | return aws.Config{}, true, fmt.Errorf("profile %q requires MFA serial %q; cli53 fallback does not support prompting for MFA", profile, target.MFASerial) |
| 103 | } |
| 104 | |
| 105 | options := []func(*config.LoadOptions) error{ |
| 106 | config.WithRetryMaxAttempts(100), |
| 107 | config.WithSharedConfigProfile(target.SourceProfileName), |
| 108 | } |
| 109 | |
| 110 | cfg, err := config.LoadDefaultConfig(ctx, options...) |
| 111 | if err != nil { |
| 112 | return aws.Config{}, true, err |
| 113 | } |
| 114 | |
| 115 | if target.Region != "" { |
| 116 | cfg.Region = target.Region |
| 117 | } |
| 118 | |
| 119 | assumeRoleOptions := []func(*stscreds.AssumeRoleOptions){ |
| 120 | func(o *stscreds.AssumeRoleOptions) { |
| 121 | if target.ExternalID != "" { |
| 122 | o.ExternalID = aws.String(target.ExternalID) |
| 123 | } |
| 124 | if target.RoleSessionName != "" { |
| 125 | o.RoleSessionName = target.RoleSessionName |
| 126 | } |
| 127 | if target.Duration > 0 { |
| 128 | o.Duration = target.Duration |
| 129 | } |
| 130 | }, |
| 131 | } |
| 132 | cfg.Credentials = aws.NewCredentialsCache(stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), target.RoleARN, assumeRoleOptions...)) |
| 133 | |
| 134 | return cfg, true, nil |
| 135 | } |
| 136 | |
| 137 | func effectiveSharedConfigProfile(profile string) string { |
| 138 | switch { |
no test coverage detected