mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-23 10:45:45 +01:00
commit
116cc15804
@ -31,7 +31,10 @@ import (
|
|||||||
svc_utils "github.com/vmware/harbor/service/utils"
|
svc_utils "github.com/vmware/harbor/service/utils"
|
||||||
"github.com/vmware/harbor/utils/log"
|
"github.com/vmware/harbor/utils/log"
|
||||||
"github.com/vmware/harbor/utils/registry"
|
"github.com/vmware/harbor/utils/registry"
|
||||||
|
|
||||||
registry_error "github.com/vmware/harbor/utils/registry/error"
|
registry_error "github.com/vmware/harbor/utils/registry/error"
|
||||||
|
|
||||||
|
"github.com/vmware/harbor/utils/registry/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RepositoryAPI handles request to /api/repositories /api/repositories/tags /api/repositories/manifests, the parm has to be put
|
// RepositoryAPI handles request to /api/repositories /api/repositories/tags /api/repositories/manifests, the parm has to be put
|
||||||
@ -245,27 +248,27 @@ func (ra *RepositoryAPI) GetManifests() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ra *RepositoryAPI) initRepositoryClient(repoName string) (r *registry.Repository, err error) {
|
func (ra *RepositoryAPI) initRepositoryClient(repoName string) (r *registry.Repository, err error) {
|
||||||
username, err := ra.getUsername()
|
endpoint := os.Getenv("REGISTRY_URL")
|
||||||
|
|
||||||
|
username, password, ok := ra.Ctx.Request.BasicAuth()
|
||||||
|
if ok {
|
||||||
|
credential := auth.NewBasicAuthCredential(username, password)
|
||||||
|
return registry.NewRepositoryWithCredential(repoName, endpoint, credential)
|
||||||
|
}
|
||||||
|
|
||||||
|
username, err = ra.getUsername()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint := os.Getenv("REGISTRY_URL")
|
|
||||||
|
|
||||||
return registry.NewRepositoryWithUsername(repoName, endpoint, username)
|
return registry.NewRepositoryWithUsername(repoName, endpoint, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ra *RepositoryAPI) getUsername() (string, error) {
|
func (ra *RepositoryAPI) getUsername() (string, error) {
|
||||||
// get username from basic auth
|
|
||||||
username, _, ok := ra.Ctx.Request.BasicAuth()
|
|
||||||
if ok {
|
|
||||||
return username, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// get username from session
|
// get username from session
|
||||||
sessionUsername := ra.GetSession("username")
|
sessionUsername := ra.GetSession("username")
|
||||||
if sessionUsername != nil {
|
if sessionUsername != nil {
|
||||||
username, ok = sessionUsername.(string)
|
username, ok := sessionUsername.(string)
|
||||||
if ok {
|
if ok {
|
||||||
return username, nil
|
return username, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user