Skip to content

Commit

Permalink
Add #412 Default application mode should be single-tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 31, 2023
1 parent 42f709e commit 1bef762
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/start_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func StartApiCmdHandler(cmd *cobra.Command, args []string) {
tenant.SingleTenantConfiguration(loadedConfig)
case config.MultiTenant:
default:
panic("Application mode is mandatory. Specify either 'single-tenant' or 'multi-tenant'.")
tenant.SingleTenantConfiguration(loadedConfig)
}

// Router
Expand Down
26 changes: 22 additions & 4 deletions internal/middleware/application_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,38 @@ func SetApplicationMode() Middleware {

// Define the http.HandlerFunc
return func(w http.ResponseWriter, r *http.Request) {
if ApplicationMode == config.SingleTenant {
switch ApplicationMode {
case config.SingleTenant:
err := singleTenantConfig(r)
if err != nil {
m := "Failed to find organization"
common.HandleError(w, http.StatusBadRequest, m, err)
return
}

organization, err := org.GetFirstOrganization()
case config.MultiTenant:
default:
err := singleTenantConfig(r)
if err != nil {
m := "Failed to find organization"
common.HandleError(w, http.StatusBadRequest, m, err)
return
}
organizationId := organization.ID.Hex()
r.Header.Set(config.OrganizationId, organizationId)
}

// Call the next middleware/handler in chain
f(w, r)
}
}
}

// singleTenantConfig
func singleTenantConfig(r *http.Request) error {
organization, err := org.GetFirstOrganization()
if err != nil {
return err
}
organizationId := organization.ID.Hex()
r.Header.Set(config.OrganizationId, organizationId)
return nil
}

0 comments on commit 1bef762

Please sign in to comment.