in pkg/ec2metadata/ec2metadata.go [221:244]
func (e *Service) GetMetadataInfo(path string, allowMissing bool) (info string, err error) {
metadataInfo := ""
resp, err := e.Request(path)
if err != nil {
return "", fmt.Errorf("Unable to parse metadata response: %w", err)
}
if resp != nil {
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("Unable to parse http response. Status code: %d. %w", resp.StatusCode, err)
}
metadataInfo = string(body)
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
if resp.StatusCode != 404 || !allowMissing {
log.Info().Msgf("Metadata response status code: %d. Body: %s", resp.StatusCode, metadataInfo)
return "", fmt.Errorf("Metadata request received http status code: %d", resp.StatusCode)
} else {
return "", nil
}
}
}
return metadataInfo, nil
}