MCPcopy Create free account
hub / github.com/barnybug/cli53 / getConfig

Function getConfig

util.go:42–83  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

40}
41
42func getConfig(c *cli.Context) (aws.Config, error) {
43 ctx := context.Background()
44 debug := c.Bool("debug")
45 endpoint := c.String("endpoint-url")
46 profile := c.String("profile")
47
48 options := []func(*config.LoadOptions) error{
49 config.WithRetryMaxAttempts(100),
50 }
51
52 if profile != "" {
53 options = append(options, config.WithSharedConfigProfile(profile))
54 }
55
56 cfg, err := config.LoadDefaultConfig(ctx, options...)
57 if err != nil {
58 fallbackCfg, handled, fallbackErr := loadConfigWithSourceProfileFallback(ctx, effectiveSharedConfigProfile(profile))
59 if handled {
60 if fallbackErr != nil {
61 return aws.Config{}, fallbackErr
62 }
63 return fallbackCfg, nil
64 }
65 return aws.Config{}, err
66 }
67
68 if debug {
69 cfg.Logger = smithylogging.NewStandardLogger(os.Stderr)
70 cfg.ClientLogMode = aws.LogRetries | aws.LogRequestWithBody | aws.LogResponseWithBody
71 }
72
73 if cfg.Region == "" {
74 cfg.Region = "us-east-1"
75 }
76
77 // SDK requires region to be set when endpoint-url is set.
78 if endpoint != "" && cfg.Region == "" {
79 return aws.Config{}, cli.NewExitError("AWS_REGION must be set when using --endpoint-url", 1)
80 }
81
82 return cfg, nil
83}
84
85func loadConfigWithSourceProfileFallback(ctx context.Context, profile string) (aws.Config, bool, error) {
86 target, found, err := loadAWSProfileSettings(profile)

Callers 2

getServiceFunction · 0.85
MainFunction · 0.85

Calls 3

StringMethod · 0.65

Tested by

no test coverage detected