diff --git a/src/common/security/admiral/authcontext/authcontext.go b/src/common/security/admiral/authcontext/authcontext.go index 6cfca96c7..407df9250 100644 --- a/src/common/security/admiral/authcontext/authcontext.go +++ b/src/common/security/admiral/authcontext/authcontext.go @@ -141,20 +141,7 @@ func convertRoles(roles []string) []int { // GetAuthCtx returns the auth context of the current user func GetAuthCtx(client *http.Client, url, token string) (*AuthContext, error) { - return get(client, url, token) -} - -// 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) + req, err := http.NewRequest(http.MethodGet, buildCurrentUserAuthCtxURL(url), nil) if err != nil { return nil, err } @@ -218,11 +205,6 @@ func buildCurrentUserAuthCtxURL(url string) string { 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 { return fmt.Sprintf("%s/auth/idm/principals/%s/security-context", strings.TrimRight(url, "/"), principalID) diff --git a/src/jobservice/api/scan.go b/src/jobservice/api/scan.go index 2a7b986eb..be5874538 100644 --- a/src/jobservice/api/scan.go +++ b/src/jobservice/api/scan.go @@ -21,8 +21,6 @@ import ( "github.com/vmware/harbor/src/common/dao" "github.com/vmware/harbor/src/common/models" "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/utils" ) @@ -42,15 +40,7 @@ func (isj *ImageScanJob) Post() { var data models.ImageScanReq isj.DecodeJSONReq(&data) log.Debugf("data: %+v", data) - regURL, err := config.LocalRegURL() - 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) + repoClient, err := utils.NewRepositoryClientForJobservice(data.Repo) if err != nil { log.Errorf("An error occurred while creating repository client: %v", err) isj.RenderError(http.StatusInternalServerError, "Failed to repository client")