Skip to content

Commit

Permalink
correct lint issues
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Mason <[email protected]>
  • Loading branch information
mikemrm committed Jul 25, 2023
1 parent 030f958 commit aefb5ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions internal/api/permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ import (
"go.uber.org/multierr"
)

const maxCheckDuration = 5 * time.Second
const (
defaultMaxCheckConcurrency = 5

maxCheckDuration = 5 * time.Second
)

var (
// ErrNoActionDefined is the error returned when an access request is has no action defined
ErrNoActionDefined = errors.New("no action defined")

// ErrAccessDenied is returned when access is denied
ErrAccessDenied = errors.New("access denied")
)

// checkAction will check if a subject is allowed to perform an action on a resource.
// This is the permissions check endpoint.
Expand Down Expand Up @@ -128,7 +140,7 @@ func (r *Router) checkAllActions(c echo.Context) error {

for i, check := range reqBody.Actions {
if check.Action == "" {
errs = append(errs, fmt.Errorf("check %d: no action defined", i))
errs = append(errs, fmt.Errorf("check %d: %w", i, ErrNoActionDefined))

continue
}
Expand Down Expand Up @@ -214,8 +226,8 @@ func (r *Router) checkAllActions(c echo.Context) error {
for i, check := range results {
if check.Error != nil {
if errors.Is(check.Error, query.ErrActionNotAssigned) {
err := fmt.Errorf("subject '%s' does not have permission to perform action '%s' on resource '%s'",
subject, check.Action, check.Resource.ID.String())
err := fmt.Errorf("%w: subject '%s' does not have permission to perform action '%s' on resource '%s'",
ErrAccessDenied, subject, check.Action, check.Resource.ID.String())

unauthorizedErrors = append(unauthorizedErrors, err)
allErrors = append(allErrors, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewRouter(authCfg echojwtx.AuthConfig, engine query.Engine, options ...Opti
engine: engine,
logger: zap.NewNop().Sugar(),

concurrentChecks: 5,
concurrentChecks: defaultMaxCheckConcurrency,
}

for _, opt := range options {
Expand Down

0 comments on commit aefb5ec

Please sign in to comment.