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)
| 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 |
| 276 | func 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 | |
| 306 | func getEcsTaskCredentials(client *http.Client, endpoint, token string) (ec2RoleCredRespBody, error) { |
| 307 | req, err := http.NewRequest(http.MethodGet, endpoint, nil) |
no test coverage detected