Skip to content

Commit

Permalink
fix: apply validation handler at constructor function
Browse files Browse the repository at this point in the history
Signed-off-by: Babak K. Shandiz <[email protected]>
  • Loading branch information
babakks committed Mar 28, 2024
1 parent 366749f commit 23a4159
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions rebac-admin-backend/v1/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,37 @@ type ReBACAdminBackend struct {
// NewReBACAdminBackend returns a new ReBACAdminBackend instance, configured
// with given backends.
func NewReBACAdminBackend(params ReBACAdminBackendParams) *ReBACAdminBackend {
return newReBACAdminBackendWithService(params, &handler{
Identities: params.Identities,
IdentitiesAuthorization: params.IdentitiesAuthorization,
IdentitiesErrorMapper: params.IdentitiesErrorMapper,

Roles: params.Roles,
RolesAuthorization: params.RolesAuthorization,
RolesErrorMapper: params.RolesErrorMapper,

IdentityProviders: params.IdentityProviders,
IdentityProvidersAuthorization: params.IdentityProvidersAuthorization,
IdentityProvidersErrorMapper: params.IdentityProvidersErrorMapper,

Capabilities: params.Capabilities,
CapabilitiesAuthorization: params.CapabilitiesAuthorization,
CapabilitiesErrorMapper: params.CapabilitiesErrorMapper,

Entitlements: params.Entitlements,
EntitlementsAuthorization: params.EntitlementsAuthorization,
EntitlementsErrorMapper: params.EntitlementsErrorMapper,

Groups: params.Groups,
GroupsAuthorization: params.GroupsAuthorization,
GroupsErrorMapper: params.GroupsErrorMapper,

Resources: params.Resources,
ResourcesAuthorization: params.ResourcesAuthorization,
ResourcesErrorMapper: params.ResourcesErrorMapper,
})
return newReBACAdminBackendWithService(
params,
newHandlerWithValidation(&handler{
Identities: params.Identities,
IdentitiesAuthorization: params.IdentitiesAuthorization,
IdentitiesErrorMapper: params.IdentitiesErrorMapper,

Roles: params.Roles,
RolesAuthorization: params.RolesAuthorization,
RolesErrorMapper: params.RolesErrorMapper,

IdentityProviders: params.IdentityProviders,
IdentityProvidersAuthorization: params.IdentityProvidersAuthorization,
IdentityProvidersErrorMapper: params.IdentityProvidersErrorMapper,

Capabilities: params.Capabilities,
CapabilitiesAuthorization: params.CapabilitiesAuthorization,
CapabilitiesErrorMapper: params.CapabilitiesErrorMapper,

Entitlements: params.Entitlements,
EntitlementsAuthorization: params.EntitlementsAuthorization,
EntitlementsErrorMapper: params.EntitlementsErrorMapper,

Groups: params.Groups,
GroupsAuthorization: params.GroupsAuthorization,
GroupsErrorMapper: params.GroupsErrorMapper,

Resources: params.Resources,
ResourcesAuthorization: params.ResourcesAuthorization,
ResourcesErrorMapper: params.ResourcesErrorMapper,
}))
}

// newReBACAdminBackendWithService returns a new ReBACAdminBackend instance, configured
Expand All @@ -102,8 +104,7 @@ func newReBACAdminBackendWithService(params ReBACAdminBackendParams, handler res
// Handler returns HTTP handlers implementing the ReBAC Admin OpenAPI spec.
func (b *ReBACAdminBackend) Handler(baseURL string) http.Handler {
baseURL, _ = strings.CutSuffix(baseURL, "/")
h := newHandlerWithValidation(b.handler)
return resources.HandlerWithOptions(h, resources.ChiServerOptions{
return resources.HandlerWithOptions(b.handler, resources.ChiServerOptions{
BaseURL: baseURL + "/v1",
Middlewares: []resources.MiddlewareFunc{
b.authenticationMiddleware(),
Expand Down

0 comments on commit 23a4159

Please sign in to comment.