Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Refactor interfaces to take ctx as first arg
Browse files Browse the repository at this point in the history
- And pass request context as a first arg to route/domain repositories
  where they were previously defaulted to context.Background()

Co-authored-by: Dave Walter <walterda@vmware.com>
  • Loading branch information
acosta11 and davewalter committed Sep 20, 2021
1 parent f982035 commit b4b8c13
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 118 deletions.
20 changes: 10 additions & 10 deletions apis/app_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (

//counterfeiter:generate -o fake -fake-name CFAppRepository . CFAppRepository
type CFAppRepository interface {
FetchApp(client.Client, context.Context, string) (repositories.AppRecord, error)
FetchNamespace(client.Client, context.Context, string) (repositories.SpaceRecord, error)
AppExists(client.Client, context.Context, string, string) (bool, error)
CreateAppEnvironmentVariables(client.Client, context.Context, repositories.AppEnvVarsRecord) (repositories.AppEnvVarsRecord, error)
CreateApp(client.Client, context.Context, repositories.AppRecord) (repositories.AppRecord, error)
FetchApp(context.Context, client.Client, string) (repositories.AppRecord, error)
FetchNamespace(context.Context, client.Client, string) (repositories.SpaceRecord, error)
AppExists(context.Context, client.Client, string, string) (bool, error)
CreateAppEnvironmentVariables(context.Context, client.Client, repositories.AppEnvVarsRecord) (repositories.AppEnvVarsRecord, error)
CreateApp(context.Context, client.Client, repositories.AppRecord) (repositories.AppRecord, error)
}

type AppHandler struct {
Expand All @@ -52,7 +52,7 @@ func (h *AppHandler) AppGetHandler(w http.ResponseWriter, r *http.Request) {
return
}

app, err := h.AppRepo.FetchApp(client, ctx, appGUID)
app, err := h.AppRepo.FetchApp(ctx, client, appGUID)
if err != nil {
switch err.(type) {
case repositories.NotFoundError:
Expand Down Expand Up @@ -103,7 +103,7 @@ func (h *AppHandler) AppCreateHandler(w http.ResponseWriter, r *http.Request) {
}

namespaceGUID := appCreateMessage.Relationships.Space.Data.GUID
_, err = h.AppRepo.FetchNamespace(client, ctx, namespaceGUID)
_, err = h.AppRepo.FetchNamespace(ctx, client, namespaceGUID)
if err != nil {
switch err.(type) {
case repositories.PermissionDeniedOrNotFoundError:
Expand All @@ -118,7 +118,7 @@ func (h *AppHandler) AppCreateHandler(w http.ResponseWriter, r *http.Request) {
}

appName := appCreateMessage.Name
appExists, err := h.AppRepo.AppExists(client, ctx, appName, namespaceGUID)
appExists, err := h.AppRepo.AppExists(ctx, client, appName, namespaceGUID)
if err != nil {
h.Logger.Error(err, "Failed to fetch app from Kubernetes", "App Name", appName)
writeUnknownErrorResponse(w)
Expand All @@ -141,7 +141,7 @@ func (h *AppHandler) AppCreateHandler(w http.ResponseWriter, r *http.Request) {
SpaceGUID: namespaceGUID,
EnvironmentVariables: appCreateMessage.EnvironmentVariables,
}
responseAppEnvSecretRecord, err := h.AppRepo.CreateAppEnvironmentVariables(client, ctx, appEnvSecretRecord)
responseAppEnvSecretRecord, err := h.AppRepo.CreateAppEnvironmentVariables(ctx, client, appEnvSecretRecord)
if err != nil {
h.Logger.Error(err, "Failed to create app environment vars", "App Name", appName)
writeUnknownErrorResponse(w)
Expand All @@ -155,7 +155,7 @@ func (h *AppHandler) AppCreateHandler(w http.ResponseWriter, r *http.Request) {
createAppRecord.GUID = appGUID
createAppRecord.EnvSecretName = appEnvSecretName

responseAppRecord, err := h.AppRepo.CreateApp(client, ctx, createAppRecord)
responseAppRecord, err := h.AppRepo.CreateApp(ctx, client, createAppRecord)
if err != nil {
switch errtype := err.(type) {
case *k8serrors.StatusError:
Expand Down
80 changes: 40 additions & 40 deletions apis/fake/cfapp_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 15 additions & 12 deletions apis/fake/cfdomain_repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b4b8c13

Please sign in to comment.