func (c *ContainerAPI) GetCPEs(ctx context.Context, nvr, arch string) ([]string, error) {
	log := zerolog.Ctx(ctx).With().Logger()
	uri, err := c.Root.Parse(path.Join("v1/images/nvr/", nvr))
	if err != nil {
		return nil, err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri.String(), nil)
	if err != nil {
		return nil, err
	}

	log.Debug().
		Str("uri", uri.String()).
		Msg("making container API request")
	res, err := c.Client.Do(req)
	if res != nil {
		defer res.Body.Close()
	}
	if err != nil {
		return nil, err
	}
	if res.StatusCode != http.StatusOK {
		var b strings.Builder
		if _, err := io.Copy(&b, res.Body); err != nil {
			log.Warn().Err(err).Msg("additional error while reading response")
		} else {
			log.Warn().Str("response", b.String()).Msg("received error response")
		}
		return nil, fmt.Errorf("rhel: unexpected response: %d %s", res.StatusCode, res.Status)
	}

	var ci ContainerImages
	if err := json.NewDecoder(res.Body).Decode(&ci); err != nil {
		return nil, err
	}
	for _, image := range ci.Images {
		for _, label := range image.ParsedData.Labels {
			if label.Name == "architecture" {
				if label.Value == arch {
					return image.CPEs, nil
				}
			}
		}
	}
	return nil, nil
}
// GetCPEs fetches CPE information for given build from Red Hat Container API.
GetCPEs fetches CPE information for given build from Red Hat Container API.
// GetCPEs fetches CPE information for given build from Red Hat Container API .
func (c *ContainerAPI) GetCPEs(ctx context.Context, nvr, arch string) ([]string, error) {
	log := zerolog.Ctx(ctx).With().Logger()
	uri, err := c.Root.Parse(path.Join("v1/images/nvr/", nvr))
	if err != nil {
		return nil, err
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri.String(), nil)
	if err != nil {
		return nil, err
	}
	log.Debug().
		Str("uri", uri.String()).
		Msg("making container API request")
	res, err := c.Client.Do(req)
	if res != nil {
		defer res.Body.Close()
	}
	if err != nil {
		return nil, err
	}
	if res.StatusCode != http.StatusOK {
		var b strings.Builder
		if _, err := io.Copy(&b, res.Body); err != nil {
			log.Warn().Err(err).Msg("additional error while reading response")
		} else {
			log.Warn().Str("response", b.String()).Msg("received error response")
		}
		return nil, fmt.Errorf("rhel: unexpected response: %d %s", res.StatusCode, res.Status)
	}
	var ci ContainerImages
	if err := json.NewDecoder(res.Body).Decode(&ci); err != nil {
		return nil, err
	}
	for _, image := range ci.Images {
		for _, label := range image.ParsedData.Labels {
			if label.Name == "architecture" {
				if label.Value == arch {
					return image.CPEs, nil
				}
			}
		}
	}
	return nil, nil
}
func ( c * ContainerAPI ) GetCPEs ( ctx context . Context , nvr , arch string ) ( [ ] string , error ) { log := zerolog . Ctx ( ctx ) . With ( ) . Logger ( ) uri , err := c . Root . Parse ( path . Join ( " " , nvr ) ) if err != nil { return nil , err } req , err := http . NewRequestWithContext ( ctx , http . MethodGet , uri . String ( ) , nil ) if err != nil { return nil , err } log . Debug ( ) . Str ( " " , uri . String ( ) ) . Msg ( " " ) res , err := c . Client . Do ( req ) if res != nil { defer res . Body . Close ( ) } if err != nil { return nil , err } if res . StatusCode != http . StatusOK { var b strings . Builder if _ , err := io . Copy ( & b , res . Body ) ; err != nil { log . Warn ( ) . Err ( err ) . Msg ( " " ) } else { log . Warn ( ) . Str ( " " , b . String ( ) ) . Msg ( " " ) } return nil , fmt . Errorf ( " " , res . StatusCode , res . Status ) } var ci ContainerImages if err := json . NewDecoder ( res . Body ) . Decode ( & ci ) ; err != nil { return nil , err } for _ , image := range ci . Images { for _ , label := range image . ParsedData . Labels { if label . Name == " " { if label . Value == arch { return image . CPEs , nil } } } } return nil , nil }
GetCPEs fetches CPE information for given build from Red Hat Container API.
GetCPEs fetches CPE information for given build from Red Hat Container API .