mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-22 18:25:56 +01:00
Change to get uri from http request, and response with relative path of resource.
This commit is contained in:
parent
94422e9a71
commit
9c655e710b
10
api/base.go
10
api/base.go
@ -87,8 +87,10 @@ func (b *BaseAPI) ValidateUser() int {
|
||||
return userID
|
||||
}
|
||||
|
||||
// Redirect does redirection to localurl with http header status code.
|
||||
// It sends http response header directly.
|
||||
func (b *BaseAPI) Redirect(statusCode int, location string) {
|
||||
b.Ctx.Redirect(statusCode, location)
|
||||
// Redirect does redirection to resource URI with http header status code.
|
||||
func (b *BaseAPI) Redirect(statusCode int, resouceID string) {
|
||||
requestURI := b.Ctx.Request.RequestURI
|
||||
resoucreURI := requestURI + "/" + resouceID
|
||||
|
||||
b.Ctx.Redirect(statusCode, resoucreURI)
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ package api
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/harbor/dao"
|
||||
"github.com/vmware/harbor/models"
|
||||
@ -34,7 +32,6 @@ type ProjectAPI struct {
|
||||
BaseAPI
|
||||
userID int
|
||||
projectID int64
|
||||
HarborURL string
|
||||
}
|
||||
|
||||
type projectReq struct {
|
||||
@ -46,8 +43,6 @@ const projectNameMaxLen int = 30
|
||||
|
||||
// Prepare validates the URL and the user
|
||||
func (p *ProjectAPI) Prepare() {
|
||||
p.HarborURL = strings.ToLower(os.Getenv("HARBOR_URL"))
|
||||
|
||||
p.userID = p.ValidateUser()
|
||||
idStr := p.Ctx.Input.Param(":id")
|
||||
if len(idStr) > 0 {
|
||||
@ -98,8 +93,7 @@ func (p *ProjectAPI) Post() {
|
||||
p.RenderError(http.StatusInternalServerError, "Failed to add project")
|
||||
}
|
||||
|
||||
projectLocation := p.HarborURL + "/api/projects/" + strconv.FormatInt(projectID, 10)
|
||||
p.Redirect(http.StatusCreated, projectLocation)
|
||||
p.Redirect(http.StatusCreated, strconv.FormatInt(projectID, 10))
|
||||
}
|
||||
|
||||
// Head ...
|
||||
|
@ -34,7 +34,6 @@ type UserAPI struct {
|
||||
SelfRegistration bool
|
||||
IsAdmin bool
|
||||
AuthMode string
|
||||
HarborURL string
|
||||
}
|
||||
|
||||
type passwordReq struct {
|
||||
@ -55,7 +54,6 @@ func (ua *UserAPI) Prepare() {
|
||||
if selfRegistration == "on" {
|
||||
ua.SelfRegistration = true
|
||||
}
|
||||
ua.HarborURL = strings.ToLower(os.Getenv("HARBOR_URL"))
|
||||
|
||||
if ua.Ctx.Input.IsPost() {
|
||||
sessionUserID := ua.GetSession("userId")
|
||||
@ -167,8 +165,7 @@ func (ua *UserAPI) Post() {
|
||||
return
|
||||
}
|
||||
|
||||
userLocation := ua.HarborURL + "/api/users/" + strconv.FormatInt(userID, 10)
|
||||
ua.Redirect(http.StatusCreated, userLocation)
|
||||
ua.Redirect(http.StatusCreated, strconv.FormatInt(userID, 10))
|
||||
}
|
||||
|
||||
// Delete ...
|
||||
|
Loading…
Reference in New Issue
Block a user