gateway: move remaining project(group) logic from api to actions
This commit is contained in:
parent
64044df94d
commit
c889c2c1c2
|
@ -28,6 +28,14 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (h *ActionHandler) GetProject(ctx context.Context, projectRef string) (*csapi.Project, error) {
|
||||||
|
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrFromRemote(resp, err)
|
||||||
|
}
|
||||||
|
return project, nil
|
||||||
|
}
|
||||||
|
|
||||||
type CreateProjectRequest struct {
|
type CreateProjectRequest struct {
|
||||||
CurrentUserID string
|
CurrentUserID string
|
||||||
Name string
|
Name string
|
||||||
|
@ -200,3 +208,11 @@ func (h *ActionHandler) ReconfigProject(ctx context.Context, projectRef string)
|
||||||
|
|
||||||
return h.SetupProject(ctx, rs, user, la, p)
|
return h.SetupProject(ctx, rs, user, la, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *ActionHandler) DeleteProject(ctx context.Context, projectRef string) error {
|
||||||
|
resp, err := h.configstoreClient.DeleteProject(ctx, projectRef)
|
||||||
|
if err != nil {
|
||||||
|
return ErrFromRemote(resp, err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,30 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (h *ActionHandler) GetProjectGroup(ctx context.Context, projectGroupRef string) (*csapi.ProjectGroup, error) {
|
||||||
|
projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrFromRemote(resp, err)
|
||||||
|
}
|
||||||
|
return projectGroup, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ActionHandler) GetProjectGroupSubgroups(ctx context.Context, projectGroupRef string) ([]*csapi.ProjectGroup, error) {
|
||||||
|
projectGroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupRef)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrFromRemote(resp, err)
|
||||||
|
}
|
||||||
|
return projectGroups, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *ActionHandler) GetProjectGroupProjects(ctx context.Context, projectGroupRef string) ([]*csapi.Project, error) {
|
||||||
|
projects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupRef)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrFromRemote(resp, err)
|
||||||
|
}
|
||||||
|
return projects, nil
|
||||||
|
}
|
||||||
|
|
||||||
type CreateProjectGroupRequest struct {
|
type CreateProjectGroupRequest struct {
|
||||||
CurrentUserID string
|
CurrentUserID string
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -41,12 +41,11 @@ type CreateProjectRequest struct {
|
||||||
type CreateProjectHandler struct {
|
type CreateProjectHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
ah *action.ActionHandler
|
ah *action.ActionHandler
|
||||||
configstoreClient *csapi.Client
|
|
||||||
exposedURL string
|
exposedURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreateProjectHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csapi.Client, exposedURL string) *CreateProjectHandler {
|
func NewCreateProjectHandler(logger *zap.Logger, ah *action.ActionHandler, exposedURL string) *CreateProjectHandler {
|
||||||
return &CreateProjectHandler{log: logger.Sugar(), ah: ah, configstoreClient: configstoreClient, exposedURL: exposedURL}
|
return &CreateProjectHandler{log: logger.Sugar(), ah: ah, exposedURL: exposedURL}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -92,12 +91,11 @@ func (h *CreateProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||||
type ProjectReconfigHandler struct {
|
type ProjectReconfigHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
ah *action.ActionHandler
|
ah *action.ActionHandler
|
||||||
configstoreClient *csapi.Client
|
|
||||||
exposedURL string
|
exposedURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProjectReconfigHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csapi.Client, exposedURL string) *ProjectReconfigHandler {
|
func NewProjectReconfigHandler(logger *zap.Logger, ah *action.ActionHandler, exposedURL string) *ProjectReconfigHandler {
|
||||||
return &ProjectReconfigHandler{log: logger.Sugar(), ah: ah, configstoreClient: configstoreClient, exposedURL: exposedURL}
|
return &ProjectReconfigHandler{log: logger.Sugar(), ah: ah, exposedURL: exposedURL}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -120,11 +118,11 @@ func (h *ProjectReconfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
|
||||||
|
|
||||||
type DeleteProjectHandler struct {
|
type DeleteProjectHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
configstoreClient *csapi.Client
|
ah *action.ActionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDeleteProjectHandler(logger *zap.Logger, configstoreClient *csapi.Client) *DeleteProjectHandler {
|
func NewDeleteProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *DeleteProjectHandler {
|
||||||
return &DeleteProjectHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
|
return &DeleteProjectHandler{log: logger.Sugar(), ah: ah}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -136,14 +134,8 @@ func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
|
err = h.ah.DeleteProject(ctx, projectRef)
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err = h.configstoreClient.DeleteProject(ctx, project.ID)
|
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -155,11 +147,11 @@ func (h *DeleteProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
type ProjectHandler struct {
|
type ProjectHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
configstoreClient *csapi.Client
|
ah *action.ActionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProjectHandler(logger *zap.Logger, configstoreClient *csapi.Client) *ProjectHandler {
|
func NewProjectHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectHandler {
|
||||||
return &ProjectHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
|
return &ProjectHandler{log: logger.Sugar(), ah: ah}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -171,8 +163,8 @@ func (h *ProjectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
project, resp, err := h.configstoreClient.GetProject(ctx, projectRef)
|
project, err := h.ah.GetProject(ctx, projectRef)
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,12 +38,11 @@ type CreateProjectGroupRequest struct {
|
||||||
type CreateProjectGroupHandler struct {
|
type CreateProjectGroupHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
ah *action.ActionHandler
|
ah *action.ActionHandler
|
||||||
configstoreClient *csapi.Client
|
|
||||||
exposedURL string
|
exposedURL string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCreateProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler, configstoreClient *csapi.Client, exposedURL string) *CreateProjectGroupHandler {
|
func NewCreateProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler, exposedURL string) *CreateProjectGroupHandler {
|
||||||
return &CreateProjectGroupHandler{log: logger.Sugar(), ah: ah, configstoreClient: configstoreClient, exposedURL: exposedURL}
|
return &CreateProjectGroupHandler{log: logger.Sugar(), ah: ah, exposedURL: exposedURL}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -85,11 +84,11 @@ func (h *CreateProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
||||||
|
|
||||||
type ProjectGroupHandler struct {
|
type ProjectGroupHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
configstoreClient *csapi.Client
|
ah *action.ActionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProjectGroupHandler(logger *zap.Logger, configstoreClient *csapi.Client) *ProjectGroupHandler {
|
func NewProjectGroupHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectGroupHandler {
|
||||||
return &ProjectGroupHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
|
return &ProjectGroupHandler{log: logger.Sugar(), ah: ah}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -101,8 +100,8 @@ func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
projectGroup, resp, err := h.configstoreClient.GetProjectGroup(ctx, projectGroupRef)
|
projectGroup, err := h.ah.GetProjectGroup(ctx, projectGroupRef)
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -115,11 +114,11 @@ func (h *ProjectGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
type ProjectGroupProjectsHandler struct {
|
type ProjectGroupProjectsHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
configstoreClient *csapi.Client
|
ah *action.ActionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProjectGroupProjectsHandler(logger *zap.Logger, configstoreClient *csapi.Client) *ProjectGroupProjectsHandler {
|
func NewProjectGroupProjectsHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectGroupProjectsHandler {
|
||||||
return &ProjectGroupProjectsHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
|
return &ProjectGroupProjectsHandler{log: logger.Sugar(), ah: ah}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -131,8 +130,8 @@ func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
csprojects, resp, err := h.configstoreClient.GetProjectGroupProjects(ctx, projectGroupRef)
|
csprojects, err := h.ah.GetProjectGroupProjects(ctx, projectGroupRef)
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -149,11 +148,11 @@ func (h *ProjectGroupProjectsHandler) ServeHTTP(w http.ResponseWriter, r *http.R
|
||||||
|
|
||||||
type ProjectGroupSubgroupsHandler struct {
|
type ProjectGroupSubgroupsHandler struct {
|
||||||
log *zap.SugaredLogger
|
log *zap.SugaredLogger
|
||||||
configstoreClient *csapi.Client
|
ah *action.ActionHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewProjectGroupSubgroupsHandler(logger *zap.Logger, configstoreClient *csapi.Client) *ProjectGroupSubgroupsHandler {
|
func NewProjectGroupSubgroupsHandler(logger *zap.Logger, ah *action.ActionHandler) *ProjectGroupSubgroupsHandler {
|
||||||
return &ProjectGroupSubgroupsHandler{log: logger.Sugar(), configstoreClient: configstoreClient}
|
return &ProjectGroupSubgroupsHandler{log: logger.Sugar(), ah: ah}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -165,8 +164,8 @@ func (h *ProjectGroupSubgroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cssubgroups, resp, err := h.configstoreClient.GetProjectGroupSubgroups(ctx, projectGroupRef)
|
cssubgroups, err := h.ah.GetProjectGroupSubgroups(ctx, projectGroupRef)
|
||||||
if httpErrorFromRemote(w, resp, err) {
|
if httpError(w, err) {
|
||||||
h.log.Errorf("err: %+v", err)
|
h.log.Errorf("err: %+v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,15 +148,15 @@ func (g *Gateway) Run(ctx context.Context) error {
|
||||||
|
|
||||||
webhooksHandler := &webhooksHandler{log: log, ah: g.ah, configstoreClient: g.configstoreClient, runserviceClient: g.runserviceClient, apiExposedURL: g.c.APIExposedURL}
|
webhooksHandler := &webhooksHandler{log: log, ah: g.ah, configstoreClient: g.configstoreClient, runserviceClient: g.runserviceClient, apiExposedURL: g.c.APIExposedURL}
|
||||||
|
|
||||||
projectGroupHandler := api.NewProjectGroupHandler(logger, g.configstoreClient)
|
projectGroupHandler := api.NewProjectGroupHandler(logger, g.ah)
|
||||||
projectGroupSubgroupsHandler := api.NewProjectGroupSubgroupsHandler(logger, g.configstoreClient)
|
projectGroupSubgroupsHandler := api.NewProjectGroupSubgroupsHandler(logger, g.ah)
|
||||||
projectGroupProjectsHandler := api.NewProjectGroupProjectsHandler(logger, g.configstoreClient)
|
projectGroupProjectsHandler := api.NewProjectGroupProjectsHandler(logger, g.ah)
|
||||||
createProjectGroupHandler := api.NewCreateProjectGroupHandler(logger, g.ah, g.configstoreClient, g.c.APIExposedURL)
|
createProjectGroupHandler := api.NewCreateProjectGroupHandler(logger, g.ah, g.c.APIExposedURL)
|
||||||
|
|
||||||
projectHandler := api.NewProjectHandler(logger, g.configstoreClient)
|
projectHandler := api.NewProjectHandler(logger, g.ah)
|
||||||
createProjectHandler := api.NewCreateProjectHandler(logger, g.ah, g.configstoreClient, g.c.APIExposedURL)
|
createProjectHandler := api.NewCreateProjectHandler(logger, g.ah, g.c.APIExposedURL)
|
||||||
deleteProjectHandler := api.NewDeleteProjectHandler(logger, g.configstoreClient)
|
deleteProjectHandler := api.NewDeleteProjectHandler(logger, g.ah)
|
||||||
projectReconfigHandler := api.NewProjectReconfigHandler(logger, g.ah, g.configstoreClient, g.c.APIExposedURL)
|
projectReconfigHandler := api.NewProjectReconfigHandler(logger, g.ah, g.c.APIExposedURL)
|
||||||
|
|
||||||
secretHandler := api.NewSecretHandler(logger, g.ah)
|
secretHandler := api.NewSecretHandler(logger, g.ah)
|
||||||
createSecretHandler := api.NewCreateSecretHandler(logger, g.ah)
|
createSecretHandler := api.NewCreateSecretHandler(logger, g.ah)
|
||||||
|
|
Loading…
Reference in New Issue