gateway: rename projectid to projectref

This commit is contained in:
Simone Gotti 2019-04-08 09:04:55 +02:00
parent f3781c9087
commit 763d77d899
4 changed files with 22 additions and 25 deletions

View File

@ -103,13 +103,13 @@ func NewProjectReconfigHandler(logger *zap.Logger, ch *command.CommandHandler, c
func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectID, err := url.PathUnescape(vars["projectid"])
projectRef, err := url.PathUnescape(vars["projectref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := h.ch.ReconfigProject(ctx, projectID); err != nil {
if err := h.ch.ReconfigProject(ctx, projectRef); err != nil {
h.log.Errorf("err: %+v", err)
httpError(w, err)
return
@ -128,16 +128,16 @@ func NewDeleteProjectHandler(logger *zap.Logger, configstoreClient *csapi.Client
func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectID, err := url.PathUnescape(vars["projectid"])
projectRef, err := url.PathUnescape(vars["projectref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
project, resp, err := h.configstoreClient.GetProject(ctx, projectID)
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
http.Error(w, fmt.Sprintf("project with id %q doesn't exist", projectID), http.StatusNotFound)
http.Error(w, fmt.Sprintf("project with ref %q doesn't exist", projectRef), http.StatusNotFound)
return
}
h.log.Errorf("err: %+v", err)
@ -169,13 +169,13 @@ func NewProjectHandler(logger *zap.Logger, configstoreClient *csapi.Client) *Pro
func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectID, err := url.PathUnescape(vars["projectid"])
projectRef, err := url.PathUnescape(vars["projectref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
project, resp, err := h.configstoreClient.GetProject(ctx, projectID)
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
http.Error(w, err.Error(), http.StatusNotFound)

View File

@ -93,14 +93,13 @@ func NewProjectGroupHandler(logger *zap.Logger, configstoreClient *csapi.Client)
func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectGroupID, err := url.PathUnescape(vars["projectgroupid"])
projectGroupRef, err := url.PathUnescape(vars["projectgroupref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
h.log.Infof("projectGroupID: %s", projectGroupID)
projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupID)
projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
@ -131,14 +130,13 @@ func NewProjectGroupProjectsHandler(logger *zap.Logger, configstoreClient *csapi
func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectGroupID, err := url.PathUnescape(vars["projectgroupid"])
projectGroupRef, err := url.PathUnescape(vars["projectgroupref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
h.log.Infof("projectGroupID: %s", projectGroupID)
csprojects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupID)
csprojects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupRef)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
@ -173,14 +171,13 @@ func NewProjectGroupSubgroupsHandler(logger *zap.Logger, configstoreClient *csap
func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
projectGroupID, err := url.PathUnescape(vars["projectgroupid"])
projectGroupRef, err := url.PathUnescape(vars["projectgroupref"])
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
h.log.Infof("projectGroupID: %s", projectGroupID)
cssubgroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupID)
cssubgroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupRef)
if err != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
http.Error(w, err.Error(), http.StatusNotFound)

View File

@ -151,8 +151,8 @@ func (c *CommandHandler) SetupProject(ctx context.Context, rs *types.RemoteSourc
return nil
}
func (c *CommandHandler) ReconfigProject(ctx context.Context, projectID string) error {
p, _, err := c.configstoreClient.GetProject(ctx, projectID)
func (c *CommandHandler) ReconfigProject(ctx context.Context, projectRef string) error {
p, _, err := c.configstoreClient.GetProject(ctx, projectRef)
if err != nil {
return err
}

View File

@ -213,16 +213,16 @@ func (g *Gateway) Run(ctx context.Context) error {
apirouter.Handle("/logs", logsHandler).Methods("GET")
//apirouter.Handle("/projectgroups", authForcedHandler(projectsHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupid}", authForcedHandler(projectGroupHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupid}/subgroups", authForcedHandler(projectGroupSubgroupsHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupid}/projects", authForcedHandler(projectGroupProjectsHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupref}", authForcedHandler(projectGroupHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupref}/subgroups", authForcedHandler(projectGroupSubgroupsHandler)).Methods("GET")
apirouter.Handle("/projectgroups/{projectgroupref}/projects", authForcedHandler(projectGroupProjectsHandler)).Methods("GET")
apirouter.Handle("/projectgroups", authForcedHandler(createProjectGroupHandler)).Methods("POST")
//apirouter.Handle("/projectgroups/{projectgroupid}", authForcedHandler(deleteProjectGroupHandler)).Methods("DELETE")
//apirouter.Handle("/projectgroups/{projectgroupref}", authForcedHandler(deleteProjectGroupHandler)).Methods("DELETE")
apirouter.Handle("/projects/{projectid}", authForcedHandler(projectHandler)).Methods("GET")
apirouter.Handle("/projects/{projectref}", authForcedHandler(projectHandler)).Methods("GET")
apirouter.Handle("/projects", authForcedHandler(createProjectHandler)).Methods("POST")
apirouter.Handle("/projects/{projectid}", authForcedHandler(deleteProjectHandler)).Methods("DELETE")
apirouter.Handle("/projects/{projectid}/reconfig", authForcedHandler(projectReconfigHandler)).Methods("PUT")
apirouter.Handle("/projects/{projectref}", authForcedHandler(deleteProjectHandler)).Methods("DELETE")
apirouter.Handle("/projects/{projectref}/reconfig", authForcedHandler(projectReconfigHandler)).Methods("PUT")
apirouter.Handle("/projectgroups/{projectgroupref}/secrets", authForcedHandler(secretHandler)).Methods("GET")
apirouter.Handle("/projects/{projectref}/secrets", authForcedHandler(secretHandler)).Methods("GET")