use the method in standard lib

This commit is contained in:
Tan Jiang 2016-03-08 11:53:13 +08:00
parent 615e4973c1
commit 3e942e3db7
3 changed files with 3 additions and 21 deletions

View File

@ -23,7 +23,6 @@ import (
"github.com/vmware/harbor/auth"
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/utils"
"github.com/astaxie/beego"
)
@ -55,8 +54,8 @@ func (b *BaseAPI) DecodeJSONReq(v interface{}) {
// ValidateUser checks if the request triggered by a valid user
func (b *BaseAPI) ValidateUser() int {
username, password := utils.ParseBasicAuth(b.Ctx.Request)
if username != "" {
username, password, ok := b.Ctx.Request.BasicAuth()
if ok {
log.Printf("Requst with Basic Authentication header, username: %s", username)
user, err := auth.Login(models.AuthModel{username, password})
if err != nil {

View File

@ -22,7 +22,6 @@ import (
"github.com/vmware/harbor/auth"
"github.com/vmware/harbor/models"
svc_utils "github.com/vmware/harbor/service/utils"
"github.com/vmware/harbor/utils"
"github.com/astaxie/beego"
"github.com/docker/distribution/registry/auth/token"
@ -40,7 +39,7 @@ func (a *TokenHandler) Get() {
request := a.Ctx.Request
log.Println("request url: " + request.URL.String())
username, password := utils.ParseBasicAuth(request)
username, password, _ := request.BasicAuth()
authenticated := authenticate(username, password)
service := a.GetString("service")
scope := a.GetString("scope")

View File

@ -16,11 +16,8 @@
package utils
import (
"encoding/base64"
"net/http"
"strings"
"github.com/astaxie/beego"
"github.com/vmware/harbor/models"
)
@ -29,19 +26,6 @@ type Repository struct {
Name string
}
// ParseBasicAuth parses the basic authorization
func ParseBasicAuth(req *http.Request) (username, password string) {
authorization := req.Header["Authorization"]
if authorization == nil || len(authorization) == 0 {
beego.Debug("Authorization header is not set.")
return "", ""
}
auth := strings.SplitN(authorization[0], " ", 2)
payload, _ := base64.StdEncoding.DecodeString(auth[1])
pair := strings.SplitN(string(payload), ":", 2)
return pair[0], pair[1]
}
// GetProject parses the repository and return the name of project.
func (r *Repository) GetProject() string {
if !strings.ContainsRune(r.Name, '/') {