MCPcopy
hub / github.com/minio/minio-go / fetchIMDSToken

Function fetchIMDSToken

pkg/credentials/iam_aws.go:345–367  ·  view source on GitHub ↗
(client *http.Client, endpoint string)

Source from the content-addressed store, hash-verified

343}
344
345func fetchIMDSToken(client *http.Client, endpoint string) (string, error) {
346 ctx, cancel := context.WithTimeout(context.Background(), time.Second)
347 defer cancel()
348
349 req, err := http.NewRequestWithContext(ctx, http.MethodPut, endpoint+TokenPath, nil)
350 if err != nil {
351 return "", err
352 }
353 req.Header.Add(TokenRequestTTLHeader, TokenTTL)
354 resp, err := client.Do(req)
355 if err != nil {
356 return "", err
357 }
358 defer resp.Body.Close()
359 data, err := io.ReadAll(resp.Body)
360 if err != nil {
361 return "", err
362 }
363 if resp.StatusCode != http.StatusOK {
364 return "", errors.New(resp.Status)
365 }
366 return string(data), nil
367}
368
369// getCredentials - obtains the credentials from the IAM role name associated with
370// the current EC2 service.

Callers 1

getCredentialsFunction · 0.85

Calls 3

DoMethod · 0.80
AddMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected