func (p *WebIdentityRoleProvider) RetrieveWithContext(ctx credentials.Context) (credentials.Value, error) {
	b, err := p.tokenFetcher.FetchToken(ctx)
	if err != nil {
		return credentials.Value{}, awserr.New(ErrCodeWebIdentity, "failed fetching WebIdentity token: ", err)
	}

	sessionName := p.roleSessionName
	if len(sessionName) == 0 {
		// session name is used to uniquely identify a session. This simply
		// uses unix time in nanoseconds to uniquely identify sessions.
		sessionName = strconv.FormatInt(now().UnixNano(), 10)
	}

	var duration *int64
	if p.Duration != 0 {
		duration = aws.Int64(int64(p.Duration / time.Second))
	}

	req, resp := p.client.AssumeRoleWithWebIdentityRequest(&sts.AssumeRoleWithWebIdentityInput{
		PolicyArns:       p.PolicyArns,
		RoleArn:          &p.roleARN,
		RoleSessionName:  &sessionName,
		WebIdentityToken: aws.String(string(b)),
		DurationSeconds:  duration,
	})

	req.SetContext(ctx)

	// InvalidIdentityToken error is a temporary error that can occur
	// when assuming an Role with a JWT web identity token.
	req.RetryErrorCodes = append(req.RetryErrorCodes, sts.ErrCodeInvalidIdentityTokenException)
	if err := req.Send(); err != nil {
		return credentials.Value{}, awserr.New(ErrCodeWebIdentity, "failed to retrieve credentials", err)
	}

	p.SetExpiration(aws.TimeValue(resp.Credentials.Expiration), p.ExpiryWindow)

	value := credentials.Value{
		AccessKeyID:     aws.StringValue(resp.Credentials.AccessKeyId),
		SecretAccessKey: aws.StringValue(resp.Credentials.SecretAccessKey),
		SessionToken:    aws.StringValue(resp.Credentials.SessionToken),
		ProviderName:    WebIdentityProviderName,
	}
	return value, nil
}
// RetrieveWithContext will attempt to assume a role from a token which is located at
// 'WebIdentityTokenFilePath' specified destination and if that is empty an
// error will be returned.
RetrieveWithContext will attempt to assume a role from a token which is located at
'WebIdentityTokenFilePath' specified destination and if that is empty an
error will be returned.
// RetrieveWithContext will attempt to assume a role from a token which is located at // ' WebIdentityTokenFilePath ' specified destination and if that is empty an // error will be returned .
func (p *WebIdentityRoleProvider) RetrieveWithContext(ctx credentials.Context) (credentials.Value, error) {
	b, err := p.tokenFetcher.FetchToken(ctx)
	if err != nil {
		return credentials.Value{}, awserr.New(ErrCodeWebIdentity, "failed fetching WebIdentity token: ", err)
	}
	sessionName := p.roleSessionName
	if len(sessionName) == 0 {
		sessionName = strconv.FormatInt(now().UnixNano(), 10)
	}
	var duration *int64
	if p.Duration != 0 {
		duration = aws.Int64(int64(p.Duration / time.Second))
	}
	req, resp := p.client.AssumeRoleWithWebIdentityRequest(&sts.AssumeRoleWithWebIdentityInput{
		PolicyArns:       p.PolicyArns,
		RoleArn:          &p.roleARN,
		RoleSessionName:  &sessionName,
		WebIdentityToken: aws.String(string(b)),
		DurationSeconds:  duration,
	})
	req.SetContext(ctx)
	req.RetryErrorCodes = append(req.RetryErrorCodes, sts.ErrCodeInvalidIdentityTokenException)
	if err := req.Send(); err != nil {
		return credentials.Value{}, awserr.New(ErrCodeWebIdentity, "failed to retrieve credentials", err)
	}
	p.SetExpiration(aws.TimeValue(resp.Credentials.Expiration), p.ExpiryWindow)
	value := credentials.Value{
		AccessKeyID:     aws.StringValue(resp.Credentials.AccessKeyId),
		SecretAccessKey: aws.StringValue(resp.Credentials.SecretAccessKey),
		SessionToken:    aws.StringValue(resp.Credentials.SessionToken),
		ProviderName:    WebIdentityProviderName,
	}
	return value, nil
}
func ( p * WebIdentityRoleProvider ) RetrieveWithContext ( ctx credentials . Context ) ( credentials . Value , error ) { b , err := p . tokenFetcher . FetchToken ( ctx ) if err != nil { return credentials . Value { } , awserr . New ( ErrCodeWebIdentity , " " , err ) } sessionName := p . roleSessionName if len ( sessionName ) == 0 { sessionName = strconv . FormatInt ( now ( ) . UnixNano ( ) , 10 ) } var duration * int64 if p . Duration != 0 { duration = aws . Int64 ( int64 ( p . Duration / time . Second ) ) } req , resp := p . client . AssumeRoleWithWebIdentityRequest ( & sts . AssumeRoleWithWebIdentityInput { PolicyArns : p . PolicyArns , RoleArn : & p . roleARN , RoleSessionName : & sessionName , WebIdentityToken : aws . String ( string ( b ) ) , DurationSeconds : duration , } ) req . SetContext ( ctx ) req . RetryErrorCodes = append ( req . RetryErrorCodes , sts . ErrCodeInvalidIdentityTokenException ) if err := req . Send ( ) ; err != nil { return credentials . Value { } , awserr . New ( ErrCodeWebIdentity , " " , err ) } p . SetExpiration ( aws . TimeValue ( resp . Credentials . Expiration ) , p . ExpiryWindow ) value := credentials . Value { AccessKeyID : aws . StringValue ( resp . Credentials . AccessKeyId ) , SecretAccessKey : aws . StringValue ( resp . Credentials . SecretAccessKey ) , SessionToken : aws . StringValue ( resp . Credentials . SessionToken ) , ProviderName : WebIdentityProviderName , } return value , nil }
RetrieveWithContext will attempt to assume a role from a token which is located at
'WebIdentityTokenFilePath' specified destination and if that is empty an
error will be returned.
RetrieveWithContext will attempt to assume a role from a token which is located at ' WebIdentityTokenFilePath ' specified destination and if that is empty an error will be returned .
// session name is used to uniquely identify a session. This simply // uses unix time in nanoseconds to uniquely identify sessions. // InvalidIdentityToken error is a temporary error that can occur // when assuming an Role with a JWT web identity token.