Commit ffa068f5 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Rename authorizationResponse to apiResponse

parent 59dc7cdc
...@@ -17,7 +17,7 @@ import ( ...@@ -17,7 +17,7 @@ import (
"time" "time"
) )
func handleGetArchive(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { func handleGetArchive(w http.ResponseWriter, r *http.Request, a *apiResponse) {
var format string var format string
urlPath := r.URL.Path urlPath := r.URL.Path
switch filepath.Base(urlPath) { switch filepath.Base(urlPath) {
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
) )
func (api *API) artifactsAuthorizeHandler(h httpHandleFunc) httpHandleFunc { func (api *API) artifactsAuthorizeHandler(h httpHandleFunc) httpHandleFunc {
return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *apiResponse) {
r.Header.Set(tempPathHeader, a.TempPath) r.Header.Set(tempPathHeader, a.TempPath)
h(w, r) h(w, r)
}, "/authorize") }, "/authorize")
......
...@@ -86,7 +86,7 @@ func (api *API) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpHand ...@@ -86,7 +86,7 @@ func (api *API) preAuthorizeHandler(h serviceHandleFunc, suffix string) httpHand
return return
} }
a := &authorizationResponse{} a := &apiResponse{}
// The auth backend validated the client request and told us additional // The auth backend validated the client request and told us additional
// request metadata. We must extract this information from the auth // request metadata. We must extract this information from the auth
// response body. // response body.
......
...@@ -8,14 +8,14 @@ import ( ...@@ -8,14 +8,14 @@ import (
"testing" "testing"
) )
func okHandler(w http.ResponseWriter, _ *http.Request, _ *authorizationResponse) { func okHandler(w http.ResponseWriter, _ *http.Request, _ *apiResponse) {
w.WriteHeader(201) w.WriteHeader(201)
fmt.Fprint(w, "{\"status\":\"ok\"}") fmt.Fprint(w, "{\"status\":\"ok\"}")
} }
func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, authorizationResponse interface{}, returnCode, expectedCode int) *httptest.ResponseRecorder { func runPreAuthorizeHandler(t *testing.T, suffix string, url *regexp.Regexp, apiResponse interface{}, returnCode, expectedCode int) *httptest.ResponseRecorder {
// Prepare test server and backend // Prepare test server and backend
ts := testAuthServer(url, returnCode, authorizationResponse) ts := testAuthServer(url, returnCode, apiResponse)
defer ts.Close() defer ts.Close()
// Create http request // Create http request
...@@ -35,7 +35,7 @@ func TestPreAuthorizeHappyPath(t *testing.T) { ...@@ -35,7 +35,7 @@ func TestPreAuthorizeHappyPath(t *testing.T) {
runPreAuthorizeHandler( runPreAuthorizeHandler(
t, "/authorize", t, "/authorize",
regexp.MustCompile(`/authorize\z`), regexp.MustCompile(`/authorize\z`),
&authorizationResponse{}, &apiResponse{},
200, 201) 200, 201)
} }
...@@ -43,7 +43,7 @@ func TestPreAuthorizeSuffix(t *testing.T) { ...@@ -43,7 +43,7 @@ func TestPreAuthorizeSuffix(t *testing.T) {
runPreAuthorizeHandler( runPreAuthorizeHandler(
t, "/different-authorize", t, "/different-authorize",
regexp.MustCompile(`/authorize\z`), regexp.MustCompile(`/authorize\z`),
&authorizationResponse{}, &apiResponse{},
200, 404) 200, 404)
} }
......
...@@ -27,7 +27,7 @@ func looksLikeRepo(p string) bool { ...@@ -27,7 +27,7 @@ func looksLikeRepo(p string) bool {
} }
func (api *API) repoPreAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc { func (api *API) repoPreAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc {
return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *apiResponse) {
if a.RepoPath == "" { if a.RepoPath == "" {
fail500(w, errors.New("repoPreAuthorizeHandler: RepoPath empty")) fail500(w, errors.New("repoPreAuthorizeHandler: RepoPath empty"))
return return
...@@ -42,7 +42,7 @@ func (api *API) repoPreAuthorizeHandler(handleFunc serviceHandleFunc) httpHandle ...@@ -42,7 +42,7 @@ func (api *API) repoPreAuthorizeHandler(handleFunc serviceHandleFunc) httpHandle
}, "") }, "")
} }
func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *apiResponse) {
rpc := r.URL.Query().Get("service") rpc := r.URL.Query().Get("service")
if !(rpc == "git-upload-pack" || rpc == "git-receive-pack") { if !(rpc == "git-upload-pack" || rpc == "git-receive-pack") {
// The 'dumb' Git HTTP protocol is not supported // The 'dumb' Git HTTP protocol is not supported
...@@ -86,7 +86,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *authorizationR ...@@ -86,7 +86,7 @@ func handleGetInfoRefs(w http.ResponseWriter, r *http.Request, a *authorizationR
} }
} }
func handlePostRPC(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { func handlePostRPC(w http.ResponseWriter, r *http.Request, a *apiResponse) {
var err error var err error
// Get Git action from URL // Get Git action from URL
......
...@@ -18,7 +18,7 @@ import ( ...@@ -18,7 +18,7 @@ import (
) )
func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc { func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc {
return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { return api.preAuthorizeHandler(func(w http.ResponseWriter, r *http.Request, a *apiResponse) {
if a.StoreLFSPath == "" { if a.StoreLFSPath == "" {
fail500(w, errors.New("lfsAuthorizeHandler: StoreLFSPath empty")) fail500(w, errors.New("lfsAuthorizeHandler: StoreLFSPath empty"))
...@@ -39,7 +39,7 @@ func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc ...@@ -39,7 +39,7 @@ func (api *API) lfsAuthorizeHandler(handleFunc serviceHandleFunc) httpHandleFunc
}, "/authorize") }, "/authorize")
} }
func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *http.Request, a *authorizationResponse) { func (u *upstream) handleStoreLfsObject(w http.ResponseWriter, r *http.Request, a *apiResponse) {
file, err := ioutil.TempFile(a.StoreLFSPath, a.LfsOid) file, err := ioutil.TempFile(a.StoreLFSPath, a.LfsOid)
if err != nil { if err != nil {
fail500(w, fmt.Errorf("handleStoreLfsObject: create tempfile: %v", err)) fail500(w, fmt.Errorf("handleStoreLfsObject: create tempfile: %v", err))
......
...@@ -340,7 +340,7 @@ func runOrFail(t *testing.T, cmd *exec.Cmd) { ...@@ -340,7 +340,7 @@ func runOrFail(t *testing.T, cmd *exec.Cmd) {
} }
func gitOkBody(t *testing.T) interface{} { func gitOkBody(t *testing.T) interface{} {
return &authorizationResponse{ return &apiResponse{
GL_ID: "user-123", GL_ID: "user-123",
RepoPath: repoPath(t), RepoPath: repoPath(t),
} }
...@@ -353,7 +353,7 @@ func archiveOkBody(t *testing.T, archiveName string) interface{} { ...@@ -353,7 +353,7 @@ func archiveOkBody(t *testing.T, archiveName string) interface{} {
} }
archivePath := path.Join(cwd, cacheDir, archiveName) archivePath := path.Join(cwd, cacheDir, archiveName)
return &authorizationResponse{ return &apiResponse{
RepoPath: repoPath(t), RepoPath: repoPath(t),
ArchivePath: archivePath, ArchivePath: archivePath,
CommitId: "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd", CommitId: "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd",
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"strings" "strings"
) )
type serviceHandleFunc func(http.ResponseWriter, *http.Request, *authorizationResponse) type serviceHandleFunc func(http.ResponseWriter, *http.Request, *apiResponse)
type API struct { type API struct {
*http.Client *http.Client
...@@ -29,7 +29,7 @@ type upstream struct { ...@@ -29,7 +29,7 @@ type upstream struct {
relativeURLRoot string relativeURLRoot string
} }
type authorizationResponse struct { type apiResponse struct {
// GL_ID is an environment variable used by gitlab-shell hooks during 'git // GL_ID is an environment variable used by gitlab-shell hooks during 'git
// push' and 'git pull' // push' and 'git pull'
GL_ID string GL_ID string
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment