Skip to content

Commit

Permalink
wip: oas config
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jul 18, 2024
1 parent bbe826a commit 39aac34
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pkg/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type Flags struct {
FGAAuthorizationModelID string `envconfig:"KNOX_FGA_AUTHORIZATION_MODEL_ID" default:""`
}

// NewFlags ...
// NewFlags returns a new instance of Flags.
func NewFlags() *Flags {
return &Flags{}
}

// New ...
// New returns a new instance of Config.
func New() *Config {
return &Config{
Flags: NewFlags(),
}
}

// Config ...
// Config contains the configuration.
type Config struct {
Flags *Flags
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/oas/oas.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func NewNoop() *noopImpl {
}

// Allowed returns true if user has the relation with the object.
func (n *noopImpl) Allowed(ctx context.Context, user User, relation Relation, object Object) (bool, error) {
func (n *noopImpl) Allowed(_ context.Context, _ User, _ Relation, _ Object) (bool, error) {
return false, nil
}

Expand All @@ -88,14 +88,17 @@ func NoopResolvers() map[string]AuthzResolverFunc {
return map[string]AuthzResolverFunc{}
}

// ResolverMap is a map of resolvers.
type ResolverMap map[string]AuthzResolverFunc

// Config ...
type Config struct {
// Next defines a function to skip the current middleware.
Next func(c *fiber.Ctx) bool
// Checker defines a function to check the authorization.
Checker Checker
// Resolvers defines the resolvers for a specific operation.
Resolvers map[string]AuthzResolverFunc
Resolvers ResolverMap
// DefaultError defines the default error.
DefaultError error
}
Expand Down Expand Up @@ -129,7 +132,7 @@ func NewAuthz(config ...Config) openapi.StrictMiddlewareFunc {
}

resolver, ok := cfg.Resolvers[operationID]
if !ok {
if !ok { // bail out if there is no resolver matching
return nil, cfg.DefaultError
}

Expand Down

0 comments on commit 39aac34

Please sign in to comment.