Commit b3012ec0 authored by chlins's avatar chlins Committed by Ziming
Browse files

fix(replication): fix quay adapter authorization


Signed-off-by: default avatarchlins <chlins.zhang@gmail.com>
parent 7970f77c
...@@ -23,8 +23,8 @@ const ADAPTERS_MAP = { ...@@ -23,8 +23,8 @@ const ADAPTERS_MAP = {
"harbor": "Harbor", "harbor": "Harbor",
"helm-hub": "Helm Hub", "helm-hub": "Helm Hub",
"huawei-SWR": "Huawei SWR", "huawei-SWR": "Huawei SWR",
"jfrog-artifactory": "jFrog Artifactory", "jfrog-artifactory": "JFrog Artifactory",
"quay-io": "Quay.io" "quay": "Quay"
}; };
......
...@@ -10,11 +10,10 @@ import ( ...@@ -10,11 +10,10 @@ import (
"net/http" "net/http"
"strings" "strings"
"github.com/goharbor/harbor/src/pkg/registry/auth/basic"
common_http "github.com/goharbor/harbor/src/common/http" common_http "github.com/goharbor/harbor/src/common/http"
"github.com/goharbor/harbor/src/common/http/modifier" "github.com/goharbor/harbor/src/common/http/modifier"
"github.com/goharbor/harbor/src/lib/log" "github.com/goharbor/harbor/src/lib/log"
"github.com/goharbor/harbor/src/pkg/registry/auth"
adp "github.com/goharbor/harbor/src/replication/adapter" adp "github.com/goharbor/harbor/src/replication/adapter"
"github.com/goharbor/harbor/src/replication/adapter/native" "github.com/goharbor/harbor/src/replication/adapter/native"
"github.com/goharbor/harbor/src/replication/model" "github.com/goharbor/harbor/src/replication/model"
...@@ -47,7 +46,7 @@ func newAdapter(registry *model.Registry) (*adapter, error) { ...@@ -47,7 +46,7 @@ func newAdapter(registry *model.Registry) (*adapter, error) {
var ( var (
autoCreateNs bool autoCreateNs bool
basicAuthorizer, apiKeyAuthorizer modifier.Modifier tokenAuthorizer, apiKeyAuthorizer modifier.Modifier
) )
if registry.Credential != nil && len(registry.Credential.AccessSecret) != 0 { if registry.Credential != nil && len(registry.Credential.AccessSecret) != 0 {
...@@ -56,14 +55,14 @@ func newAdapter(registry *model.Registry) (*adapter, error) { ...@@ -56,14 +55,14 @@ func newAdapter(registry *model.Registry) (*adapter, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
basicAuthorizer = basic.NewAuthorizer(jsonCred.AccountName, jsonCred.DockerCliPassword) tokenAuthorizer = auth.NewAuthorizer(jsonCred.AccountName, jsonCred.DockerCliPassword, registry.Insecure)
if len(jsonCred.OAuth2Token) != 0 { if len(jsonCred.OAuth2Token) != 0 {
autoCreateNs = true autoCreateNs = true
apiKeyAuthorizer = NewAPIKeyAuthorizer("Authorization", fmt.Sprintf("Bearer %s", jsonCred.OAuth2Token), APIKeyInHeader) apiKeyAuthorizer = NewAPIKeyAuthorizer("Authorization", fmt.Sprintf("Bearer %s", jsonCred.OAuth2Token), APIKeyInHeader)
} }
} }
nativeRegistryAdapter := native.NewAdapterWithAuthorizer(registry, basicAuthorizer) nativeRegistryAdapter := native.NewAdapterWithAuthorizer(registry, tokenAuthorizer)
if apiKeyAuthorizer != nil { if apiKeyAuthorizer != nil {
modifiers = append(modifiers, apiKeyAuthorizer) modifiers = append(modifiers, apiKeyAuthorizer)
...@@ -128,16 +127,6 @@ func (a *adapter) Info() (*model.RegistryInfo, error) { ...@@ -128,16 +127,6 @@ func (a *adapter) Info() (*model.RegistryInfo, error) {
}, nil }, nil
} }
// HealthCheck checks health status of a registry
func (a *adapter) HealthCheck() (model.HealthStatus, error) {
err := a.PingSimple()
if err != nil {
return model.Unhealthy, nil
}
return model.Healthy, nil
}
// PrepareForPush does the prepare work that needed for pushing/uploading the resource // PrepareForPush does the prepare work that needed for pushing/uploading the resource
// eg: create the namespace or repository // eg: create the namespace or repository
func (a *adapter) PrepareForPush(resources []*model.Resource) error { func (a *adapter) PrepareForPush(resources []*model.Resource) error {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment