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

Function listRoleNames

pkg/credentials/iam_aws.go:276–304  ·  view source on GitHub ↗

listRoleNames lists of credential role names associated with the current EC2 service. If there are no credentials, or there is an error making or receiving the request. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html

(client *http.Client, u *url.URL, token string)

Source from the content-addressed store, hash-verified

274// or there is an error making or receiving the request.
275// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
276func listRoleNames(client *http.Client, u *url.URL, token string) ([]string, error) {
277 req, err := http.NewRequest(http.MethodGet, u.String(), nil)
278 if err != nil {
279 return nil, err
280 }
281 if token != "" {
282 req.Header.Add(TokenRequestHeader, token)
283 }
284 resp, err := client.Do(req)
285 if err != nil {
286 return nil, err
287 }
288 defer resp.Body.Close()
289 if resp.StatusCode != http.StatusOK {
290 return nil, errors.New(resp.Status)
291 }
292
293 credsList := []string{}
294 s := bufio.NewScanner(resp.Body)
295 for s.Scan() {
296 credsList = append(credsList, s.Text())
297 }
298
299 if err := s.Err(); err != nil {
300 return nil, err
301 }
302
303 return credsList, nil
304}
305
306func getEcsTaskCredentials(client *http.Client, endpoint, token string) (ec2RoleCredRespBody, error) {
307 req, err := http.NewRequest(http.MethodGet, endpoint, nil)

Callers 1

getCredentialsFunction · 0.85

Calls 4

DoMethod · 0.80
StringMethod · 0.45
AddMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected