// Provide returns credentials TODO: cache response from metadata in memory
Provide returns credentials TODO: cache response from metadata in memory
// Provide returns credentials TODO : cache response from metadata in memory
func (p *Provider) Provide(ctx context.Context, req *dockerregistryproxyv1.ProvideRequest) (*dockerregistryproxyv1.ProvideResponse, error) {
	metaReq, err := http.NewRequestWithContext(ctx, "GET", gcp.MetadataToken(), nil)
	if err != nil {
		return nil, fmt.Errorf("could not construct metadata request: %w", err)
	}
	metaReq.Header = *gcp.MetadataHeader
	metaResp, err := p.client.Do(metaReq)
	if err != nil {
		return nil, fmt.Errorf("could not execute metadata request: %w", err)
	}
	defer metaResp.Body.Close()
	tokenBytes, err := ioutil.ReadAll(metaResp.Body)
	if err != nil {
		return nil, fmt.Errorf("could not read metadata response: %w", err)
	}
	return &dockerregistryproxyv1.ProvideResponse{
		Username: p.username,
		Password: string(tokenBytes),
	}, nil
}
func ( p * Provider ) Provide ( ctx context . Context , req * dockerregistryproxyv1 . ProvideRequest ) ( * dockerregistryproxyv1 . ProvideResponse , error ) { metaReq , err := http . NewRequestWithContext ( ctx , " " , gcp . MetadataToken ( ) , nil ) if err != nil { return nil , fmt . Errorf ( " " , err ) } metaReq . Header = * gcp . MetadataHeader metaResp , err := p . client . Do ( metaReq ) if err != nil { return nil , fmt . Errorf ( " " , err ) } defer metaResp . Body . Close ( ) tokenBytes , err := ioutil . ReadAll ( metaResp . Body ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return & dockerregistryproxyv1 . ProvideResponse { Username : p . username , Password : string ( tokenBytes ) , } , nil }
Provide returns credentials TODO: cache response from metadata in memory
Provide returns credentials TODO : cache response from metadata in memory