MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / loadAWSSystemManagerParams

Function loadAWSSystemManagerParams

env/aws.go:84–155  ·  view source on GitHub ↗

loadAWSSystemManagerParams loads environment variables from AWS System Manager

(ctx context.Context)

Source from the content-addressed store, hash-verified

82
83// loadAWSSystemManagerParams loads environment variables from AWS System Manager
84func loadAWSSystemManagerParams(ctx context.Context) error {
85 var paramsPath, paramsRegion string
86
87 IMGPROXY_ENV_AWS_SSM_PARAMETERS_PATH.Parse(&paramsPath)
88 IMGPROXY_ENV_AWS_SSM_PARAMETERS_REGION.Parse(&paramsRegion)
89
90 // Path is not set: can't use SSM
91 if len(paramsPath) == 0 {
92 return nil
93 }
94
95 conf, err := awsConfig.LoadDefaultConfig(ctx)
96 if err != nil {
97 return fmt.Errorf("can't load AWS SSM config: %w", err)
98 }
99
100 if len(paramsRegion) > 0 {
101 conf.Region = paramsRegion
102 }
103
104 if len(conf.Region) == 0 {
105 conf.Region = defaultAWSRegion
106 }
107
108 // Let's create SSM client
109 client := ssm.NewFromConfig(conf)
110
111 ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
112 defer cancel()
113
114 var nextToken *string
115
116 for {
117 input := ssm.GetParametersByPathInput{
118 Path: aws.String(paramsPath),
119 WithDecryption: aws.Bool(true),
120 NextToken: nextToken,
121 }
122
123 output, err := client.GetParametersByPath(ctx, &input)
124 if err != nil {
125 return fmt.Errorf("can't retrieve parameters from AWS SSM: %w", err)
126 }
127
128 for _, p := range output.Parameters {
129 if p.Name == nil || p.Value == nil {
130 continue
131 }
132
133 if p.DataType == nil || *p.DataType != "text" {
134 continue
135 }
136
137 name := *p.Name
138
139 env := strings.ReplaceAll(
140 strings.TrimPrefix(strings.TrimPrefix(name, paramsPath), "/"),
141 "/", "_",

Callers 1

LoadFunction · 0.85

Calls 3

ParseMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected