Skip to content

Commit

Permalink
fix issue for token basic auth
Browse files Browse the repository at this point in the history
Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero committed Apr 17, 2022
1 parent eb6db27 commit e23ca07
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions manager/job/preheat.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (p *preheat) getResolver(ctx context.Context, username, password string) re

}

func getAuthToken(ctx context.Context, header http.Header) (string, error) {
func getAuthToken(ctx context.Context, header http.Header, preheatArgs types.PreheatArgs) (string, error) {
ctx, span := tracer.Start(ctx, config.SpanAuthWithRegistry, trace.WithSpanKind(trace.SpanKindProducer))
defer span.End()

Expand All @@ -241,6 +241,9 @@ func getAuthToken(ctx context.Context, header http.Header) (string, error) {
if err != nil {
return "", err
}
if preheatArgs.Username != "" && preheatArgs.Password != "" {
req.SetBasicAuth(preheatArgs.Username, preheatArgs.Password)
}

client := &http.Client{
Timeout: timeout,
Expand Down Expand Up @@ -357,10 +360,6 @@ func (p *preheat) parseLayers(om ocispec.Manifest, preheatArgs types.PreheatArgs
return nil, err
}

if preheatArgs.Username != "" && preheatArgs.Password != "" {
req.SetBasicAuth(preheatArgs.Username, preheatArgs.Password)
}

client := &http.Client{
Timeout: timeout,
Transport: &http.Transport{
Expand All @@ -380,7 +379,7 @@ func (p *preheat) parseLayers(om ocispec.Manifest, preheatArgs types.PreheatArgs

layerHeader := httputils.MapToHeader(preheatArgs.Headers).Clone()
if resp.StatusCode == http.StatusUnauthorized {
token, err := getAuthToken(context.Background(), resp.Header)
token, err := getAuthToken(context.Background(), resp.Header, preheatArgs)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit e23ca07

Please sign in to comment.