// 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,
	_ *dockerregistryproxyv1.ProvideRequest,
) (*dockerregistryproxyv1.ProvideResponse, error) {
	metaReq, _ := http.NewRequestWithContext(ctx, "GET", aws.MetadataIdentity(), nil)
	metaResp, err := p.client.Do(metaReq)
	if err != nil {
		return nil, fmt.Errorf("could not execute metadata request: %w", err)
	}
	defer metaResp.Body.Close()
	metaJSONBytes, err := ioutil.ReadAll(metaResp.Body)
	if err != nil {
		return nil, fmt.Errorf("could not read metadata response: %w", err)
	}
	sigReq, _ := http.NewRequestWithContext(ctx, "GET", aws.MetadataIdentitySignature(), nil)
	sigResp, err := p.client.Do(sigReq)
	if err != nil {
		return nil, fmt.Errorf("could not execute metadata request: %w", err)
	}
	defer sigResp.Body.Close()
	sigBytes, err := ioutil.ReadAll(sigResp.Body)
	if err != nil {
		return nil, fmt.Errorf("could not read metadata response: %w", err)
	}
	instanceIdentityPassword := &aws.InstanceIdentityPassword{
		Payload:   metaJSONBytes,
		Signature: sigBytes,
	}
	encodedInstanceIdentityPassword, err := instanceIdentityPassword.Encode()
	if err != nil {
		return nil, fmt.Errorf("could not encode instance identity password: %w", err)
	}
	return &dockerregistryproxyv1.ProvideResponse{
		Username: p.username,
		Password: encodedInstanceIdentityPassword,
	}, nil
}
func ( p * Provider ) Provide ( ctx context . Context , _ * dockerregistryproxyv1 . ProvideRequest , ) ( * dockerregistryproxyv1 . ProvideResponse , error ) { metaReq , _ := http . NewRequestWithContext ( ctx , " " , aws . MetadataIdentity ( ) , nil ) metaResp , err := p . client . Do ( metaReq ) if err != nil { return nil , fmt . Errorf ( " " , err ) } defer metaResp . Body . Close ( ) metaJSONBytes , err := ioutil . ReadAll ( metaResp . Body ) if err != nil { return nil , fmt . Errorf ( " " , err ) } sigReq , _ := http . NewRequestWithContext ( ctx , " " , aws . MetadataIdentitySignature ( ) , nil ) sigResp , err := p . client . Do ( sigReq ) if err != nil { return nil , fmt . Errorf ( " " , err ) } defer sigResp . Body . Close ( ) sigBytes , err := ioutil . ReadAll ( sigResp . Body ) if err != nil { return nil , fmt . Errorf ( " " , err ) } instanceIdentityPassword := & aws . InstanceIdentityPassword { Payload : metaJSONBytes , Signature : sigBytes , } encodedInstanceIdentityPassword , err := instanceIdentityPassword . Encode ( ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return & dockerregistryproxyv1 . ProvideResponse { Username : p . username , Password : encodedInstanceIdentityPassword , } , nil }
Provide returns credentials TODO: cache response from metadata in memory.
Provide returns credentials TODO : cache response from metadata in memory .
// tokenReq, _ := http.NewRequest("PUT", aws.ApiToken(), nil) // tokenReq.Header = *aws.TokenHeader // tokenResp, err := p.client.Do(tokenReq) // if err != nil { // 	return nil, fmt.Errorf("could not execute token request: %w", err) // } // token, err := ioutil.ReadAll(tokenResp.Body) // if err != nil { // 	return nil, fmt.Errorf("could not read token from body: %w", err) // } // metaReq.Header = aws.GetMetadataHeader(string(token)) // sigReq.Header = aws.GetMetadataHeader(string(token))