Skip to content

Commit

Permalink
Merge pull request goharbor#9887 from chlins/fix/replication-huawei-a…
Browse files Browse the repository at this point in the history
…dapter-authorization

fix(replication): huawei adapter multi authorization
  • Loading branch information
ywk253100 authored Jan 17, 2020
2 parents 2ea41ca + 130e406 commit 8809b7a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/replication/adapter/huawei/huawei_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type adapter struct {
*native.Adapter
registry *model.Registry
client *common_http.Client
// original http client with no modifer,
// huawei's some api interface with basic authorization,
// some with bearer token authorization.
oriClient *http.Client
}

// Info gets info about Huawei SWR
Expand Down Expand Up @@ -243,15 +247,19 @@ func newAdapter(registry *model.Registry) (adp.Adapter, error) {
modifiers = append(modifiers, authorizer)
}

transport := util.GetHTTPTransport(registry.Insecure)
return &adapter{
Adapter: dockerRegistryAdapter,
registry: registry,
client: common_http.NewClient(
&http.Client{
Transport: util.GetHTTPTransport(registry.Insecure),
Transport: transport,
},
modifiers...,
),
oriClient: &http.Client{
Transport: transport,
},
}, nil

}
Expand Down
4 changes: 2 additions & 2 deletions src/replication/adapter/huawei/image_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *adapter) ManifestExist(repository, reference string) (exist bool, diges
r.Header.Add("content-type", "application/json; charset=utf-8")
r.Header.Add("Authorization", "Bearer "+token.Token)

resp, err := a.client.Do(r)
resp, err := a.oriClient.Do(r)
if err != nil {
return exist, digest, err
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (a *adapter) DeleteManifest(repository, reference string) error {
r.Header.Add("content-type", "application/json; charset=utf-8")
r.Header.Add("Authorization", "Bearer "+token.Token)

resp, err := a.client.Do(r)
resp, err := a.oriClient.Do(r)
if err != nil {
return err
}
Expand Down

0 comments on commit 8809b7a

Please sign in to comment.