mirror of
https://github.com/goharbor/harbor.git
synced 2024-10-01 06:47:33 +02:00
remove useless codes
This commit is contained in:
parent
3c64ae340e
commit
7fedca3a4a
@ -141,20 +141,7 @@ func convertRoles(roles []string) []int {
|
|||||||
|
|
||||||
// GetAuthCtx returns the auth context of the current user
|
// GetAuthCtx returns the auth context of the current user
|
||||||
func GetAuthCtx(client *http.Client, url, token string) (*AuthContext, error) {
|
func GetAuthCtx(client *http.Client, url, token string) (*AuthContext, error) {
|
||||||
return get(client, url, token)
|
req, err := http.NewRequest(http.MethodGet, buildCurrentUserAuthCtxURL(url), nil)
|
||||||
}
|
|
||||||
|
|
||||||
// get the user's auth context, if the username is not provided
|
|
||||||
// get the default auth context of the token
|
|
||||||
func get(client *http.Client, url, token string, username ...string) (*AuthContext, error) {
|
|
||||||
endpoint := ""
|
|
||||||
if len(username) > 0 && len(username[0]) > 0 {
|
|
||||||
endpoint = buildSpecificUserAuthCtxURL(url, username[0])
|
|
||||||
} else {
|
|
||||||
endpoint = buildCurrentUserAuthCtxURL(url)
|
|
||||||
}
|
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -218,11 +205,6 @@ func buildCurrentUserAuthCtxURL(url string) string {
|
|||||||
return strings.TrimRight(url, "/") + "/auth/session"
|
return strings.TrimRight(url, "/") + "/auth/session"
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildSpecificUserAuthCtxURL(url, principalID string) string {
|
|
||||||
return fmt.Sprintf("%s/auth/idm/principals/%s/security-context",
|
|
||||||
strings.TrimRight(url, "/"), principalID)
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildLoginURL(url, principalID string) string {
|
func buildLoginURL(url, principalID string) string {
|
||||||
return fmt.Sprintf("%s/auth/idm/principals/%s/security-context",
|
return fmt.Sprintf("%s/auth/idm/principals/%s/security-context",
|
||||||
strings.TrimRight(url, "/"), principalID)
|
strings.TrimRight(url, "/"), principalID)
|
||||||
|
@ -21,8 +21,6 @@ import (
|
|||||||
"github.com/vmware/harbor/src/common/dao"
|
"github.com/vmware/harbor/src/common/dao"
|
||||||
"github.com/vmware/harbor/src/common/models"
|
"github.com/vmware/harbor/src/common/models"
|
||||||
"github.com/vmware/harbor/src/common/utils/log"
|
"github.com/vmware/harbor/src/common/utils/log"
|
||||||
"github.com/vmware/harbor/src/common/utils/registry/auth"
|
|
||||||
"github.com/vmware/harbor/src/jobservice/config"
|
|
||||||
"github.com/vmware/harbor/src/jobservice/job"
|
"github.com/vmware/harbor/src/jobservice/job"
|
||||||
"github.com/vmware/harbor/src/jobservice/utils"
|
"github.com/vmware/harbor/src/jobservice/utils"
|
||||||
)
|
)
|
||||||
@ -42,15 +40,7 @@ func (isj *ImageScanJob) Post() {
|
|||||||
var data models.ImageScanReq
|
var data models.ImageScanReq
|
||||||
isj.DecodeJSONReq(&data)
|
isj.DecodeJSONReq(&data)
|
||||||
log.Debugf("data: %+v", data)
|
log.Debugf("data: %+v", data)
|
||||||
regURL, err := config.LocalRegURL()
|
repoClient, err := utils.NewRepositoryClientForJobservice(data.Repo)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to read regURL, error: %v", err)
|
|
||||||
isj.RenderError(http.StatusInternalServerError, "Failed to read registry URL from config")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c := &http.Cookie{Name: models.UISecretCookie, Value: config.JobserviceSecret()}
|
|
||||||
repoClient, err := utils.NewRepositoryClient(regURL, false, auth.NewCookieCredential(c),
|
|
||||||
config.InternalTokenServiceEndpoint(), data.Repo)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("An error occurred while creating repository client: %v", err)
|
log.Errorf("An error occurred while creating repository client: %v", err)
|
||||||
isj.RenderError(http.StatusInternalServerError, "Failed to repository client")
|
isj.RenderError(http.StatusInternalServerError, "Failed to repository client")
|
||||||
|
Loading…
Reference in New Issue
Block a user