mirror of
https://github.com/goharbor/harbor
synced 2025-04-18 02:45:51 +00:00
fix go vet and golint errors
This commit is contained in:
parent
7620cd3b86
commit
776c34a0ae
|
@ -24,7 +24,7 @@ import (
|
|||
)
|
||||
|
||||
var adminServerDefaultConfig = map[string]interface{}{
|
||||
config.ExtEndpoint: "host01.com",
|
||||
config.ExtEndpoint: "https://host01.com",
|
||||
config.AUTHMode: config.DBAuth,
|
||||
config.DatabaseType: "mysql",
|
||||
config.MySQLHost: "127.0.0.1",
|
||||
|
|
|
@ -116,20 +116,18 @@ func MakeRawToken(username, service string, access []*token.ResourceActions) (to
|
|||
return rs, expiresIn, issuedAt, nil
|
||||
}
|
||||
|
||||
// TokenJSON represents the json to be returned to docker/notary client
|
||||
type TokenJSON struct {
|
||||
Token string `json: token`
|
||||
ExpiresIn int `json: expires_in`
|
||||
issuedAt string `json: issued_at`
|
||||
type tokenJSON struct {
|
||||
Token string `json:"token"`
|
||||
ExpiresIn int `json:"expires_in"`
|
||||
IssuedAt string `json:"issued_at"`
|
||||
}
|
||||
|
||||
// MakeToken returns a json that can be consumed by docker/notary client
|
||||
func MakeToken(username, service string, access []*token.ResourceActions) (*TokenJSON, error) {
|
||||
func makeToken(username, service string, access []*token.ResourceActions) (*tokenJSON, error) {
|
||||
raw, expires, issued, err := MakeRawToken(username, service, access)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TokenJSON{raw, expires, issued.Format(time.RFC3339)}, nil
|
||||
return &tokenJSON{raw, expires, issued.Format(time.RFC3339)}, nil
|
||||
}
|
||||
|
||||
func permToActions(p string) []string {
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var creatorMap map[string]TokenCreator
|
||||
var creatorMap map[string]Creator
|
||||
|
||||
const (
|
||||
notary = "harbor-notary"
|
||||
|
@ -34,12 +34,12 @@ const (
|
|||
|
||||
//InitCreators initialize the token creators for different services
|
||||
func InitCreators() {
|
||||
creatorMap = make(map[string]TokenCreator)
|
||||
creatorMap = make(map[string]Creator)
|
||||
ext, err := config.ExtEndpoint()
|
||||
if err != nil {
|
||||
log.Warningf("Failed to get ext enpoint, err: %v, the token service will not be functional with notary requests", err)
|
||||
} else {
|
||||
creatorMap[notary] = &generalTokenCreator{
|
||||
creatorMap[notary] = &generalCreator{
|
||||
validators: []ReqValidator{
|
||||
&basicAuthValidator{},
|
||||
},
|
||||
|
@ -54,7 +54,7 @@ func InitCreators() {
|
|||
}
|
||||
}
|
||||
|
||||
creatorMap[registry] = &generalTokenCreator{
|
||||
creatorMap[registry] = &generalCreator{
|
||||
validators: []ReqValidator{
|
||||
&secretValidator{config.JobserviceSecret()},
|
||||
&basicAuthValidator{},
|
||||
|
@ -72,9 +72,9 @@ func InitCreators() {
|
|||
}
|
||||
}
|
||||
|
||||
// TokenCreator creates a token ready to be served based on the http request.
|
||||
type TokenCreator interface {
|
||||
create(r *http.Request) (*TokenJSON, error)
|
||||
// Creator creates a token ready to be served based on the http request.
|
||||
type Creator interface {
|
||||
Create(r *http.Request) (*tokenJSON, error)
|
||||
}
|
||||
|
||||
type imageParser interface {
|
||||
|
@ -108,9 +108,8 @@ func (e endpointParser) parse(s string) (*image, error) {
|
|||
return nil, fmt.Errorf("Mismatch endpoint from string: %s, expected endpoint: %s", s, e.endpoint)
|
||||
}
|
||||
return parseImg(repo[1])
|
||||
} else {
|
||||
return parseImg(s)
|
||||
}
|
||||
return parseImg(s)
|
||||
}
|
||||
|
||||
//build Image accepts a string like library/ubuntu:14.04 and build a image struct
|
||||
|
@ -187,7 +186,7 @@ func (rep repositoryFilter) filter(user userInfo, a *token.ResourceActions) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
type generalTokenCreator struct {
|
||||
type generalCreator struct {
|
||||
validators []ReqValidator
|
||||
service string
|
||||
filterMap map[string]accessFilter
|
||||
|
@ -199,7 +198,7 @@ func (e *unauthorizedError) Error() string {
|
|||
return "Unauthorized"
|
||||
}
|
||||
|
||||
func (g generalTokenCreator) create(r *http.Request) (*TokenJSON, error) {
|
||||
func (g generalCreator) Create(r *http.Request) (*tokenJSON, error) {
|
||||
var user *userInfo
|
||||
var err error
|
||||
var scopes []string
|
||||
|
@ -234,5 +233,5 @@ func (g generalTokenCreator) create(r *http.Request) (*TokenJSON, error) {
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
return MakeToken(user.name, g.service, access)
|
||||
return makeToken(user.name, g.service, access)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ type Handler struct {
|
|||
// Get handles GET request, it checks the http header for user credentials
|
||||
// and parse service and scope based on docker registry v2 standard,
|
||||
// checkes the permission agains local DB and generates jwt token.
|
||||
|
||||
func (h *Handler) Get() {
|
||||
request := h.Ctx.Request
|
||||
log.Debugf("URL for token request: %s", request.URL.String())
|
||||
|
@ -42,7 +41,7 @@ func (h *Handler) Get() {
|
|||
log.Errorf(errMsg)
|
||||
h.CustomAbort(http.StatusBadRequest, errMsg)
|
||||
}
|
||||
token, err := tokenCreator.create(request)
|
||||
token, err := tokenCreator.Create(request)
|
||||
if err != nil {
|
||||
if _, ok := err.(*unauthorizedError); ok {
|
||||
h.CustomAbort(http.StatusUnauthorized, "")
|
||||
|
|
|
@ -94,7 +94,7 @@ func TestMakeToken(t *testing.T) {
|
|||
}}
|
||||
svc := "harbor-registry"
|
||||
u := "tester"
|
||||
tokenJSON, err := MakeToken(u, svc, ra)
|
||||
tokenJSON, err := makeToken(u, svc, ra)
|
||||
if err != nil {
|
||||
t.Errorf("Error while making token: %v", err)
|
||||
}
|
||||
|
@ -140,6 +140,10 @@ type parserTestRec struct {
|
|||
expectError bool
|
||||
}
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
InitCreators()
|
||||
}
|
||||
|
||||
func TestBasicParser(t *testing.T) {
|
||||
testList := []parserTestRec{parserTestRec{"library/ubuntu:14.04", image{"library", "ubuntu", "14.04"}, false},
|
||||
parserTestRec{"test/hello", image{"test", "hello", ""}, false},
|
||||
|
|
|
@ -30,7 +30,7 @@ type userInfo struct {
|
|||
allPerm bool
|
||||
}
|
||||
|
||||
//Validate request based on different rules and returns userInfo
|
||||
//ReqValidator validates request based on different rules and returns userInfo
|
||||
type ReqValidator interface {
|
||||
validate(req *http.Request) (*userInfo, error)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user