mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
fix golint errors
This commit is contained in:
parent
d2ba4f7c40
commit
3ff3128921
@ -89,7 +89,7 @@ func (r *Registry) Catalog() ([]string, error) {
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return repos, e
|
||||
}
|
||||
|
@ -111,14 +111,15 @@ func NewRepositoryWithUsername(name, endpoint, username string) (*Repository, er
|
||||
return repository, nil
|
||||
}
|
||||
|
||||
func isUnauthorizedError(err error) (error, bool) {
|
||||
// try to convert err to errors.Error if it is
|
||||
func isUnauthorizedError(err error) (bool, error) {
|
||||
if strings.Contains(err.Error(), http.StatusText(http.StatusUnauthorized)) {
|
||||
return errors.Error{
|
||||
return true, errors.Error{
|
||||
StatusCode: http.StatusUnauthorized,
|
||||
StatusText: http.StatusText(http.StatusUnauthorized),
|
||||
}, true
|
||||
}
|
||||
}
|
||||
return err, false
|
||||
return false, err
|
||||
}
|
||||
|
||||
// ListTag ...
|
||||
@ -131,7 +132,7 @@ func (r *Repository) ListTag() ([]string, error) {
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return tags, e
|
||||
}
|
||||
@ -178,7 +179,7 @@ func (r *Repository) ManifestExist(reference string) (digest string, exist bool,
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
err = e
|
||||
return
|
||||
@ -224,7 +225,7 @@ func (r *Repository) PullManifest(reference string, acceptMediaTypes []string) (
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
err = e
|
||||
return
|
||||
@ -265,7 +266,7 @@ func (r *Repository) PushManifest(reference, mediaType string, payload []byte) (
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
err = e
|
||||
return
|
||||
@ -303,7 +304,7 @@ func (r *Repository) DeleteManifest(digest string) error {
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return e
|
||||
}
|
||||
@ -354,7 +355,7 @@ func (r *Repository) BlobExist(digest string) (bool, error) {
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return false, e
|
||||
}
|
||||
@ -392,7 +393,7 @@ func (r *Repository) PullBlob(digest string) (size int64, data []byte, err error
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
err = e
|
||||
return
|
||||
@ -431,7 +432,7 @@ func (r *Repository) initiateBlobUpload(name string) (location, uploadUUID strin
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
err = e
|
||||
return
|
||||
@ -469,7 +470,7 @@ func (r *Repository) monolithicBlobUpload(location, digest string, size int64, d
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return e
|
||||
}
|
||||
@ -523,7 +524,7 @@ func (r *Repository) DeleteBlob(digest string) error {
|
||||
|
||||
resp, err := r.client.Do(req)
|
||||
if err != nil {
|
||||
e, ok := isUnauthorizedError(err)
|
||||
ok, e := isUnauthorizedError(err)
|
||||
if ok {
|
||||
return e
|
||||
}
|
||||
|
@ -31,12 +31,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
username string = "user"
|
||||
password string = "P@ssw0rd"
|
||||
repo string = "samalba/my-app"
|
||||
tags tagResp = tagResp{Tags: []string{"1.0", "2.0", "3.0"}}
|
||||
validToken string = "valid_token"
|
||||
invalidToken string = "invalid_token"
|
||||
username = "user"
|
||||
password = "P@ssw0rd"
|
||||
repo = "samalba/my-app"
|
||||
tags = tagResp{Tags: []string{"1.0", "2.0", "3.0"}}
|
||||
validToken = "valid_token"
|
||||
invalidToken = "invalid_token"
|
||||
credential auth.Credential
|
||||
registryServer *httptest.Server
|
||||
tokenServer *httptest.Server
|
||||
|
Loading…
Reference in New Issue
Block a user