Skip to content

Commit

Permalink
chore: improve permission error
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Oct 1, 2024
1 parent 06496a6 commit 07c1267
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 2 additions & 2 deletions api/v1/playbook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const (
PlaybookParameterTypePeople = "people"
PlaybookParameterTypeTeam = "team"
PlaybookParameterTypeText = "text"
PlaybookParameterTypeMillis = "Millis"
PlaybookParameterTypeBytes = "Bytes"
PlaybookParameterTypeMillis = "millicores"
PlaybookParameterTypeBytes = "bytes"
)

// PlaybookParameter defines a parameter that a playbook needs to run.
Expand Down
3 changes: 1 addition & 2 deletions playbook/approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package playbook
import (
"encoding/json"
"errors"
"fmt"
"net/http"

"github.com/flanksource/commons/collections"
Expand Down Expand Up @@ -57,7 +56,7 @@ func approveRun(ctx context.Context, run *models.PlaybookRun) error {
if objects, err := run.GetRBACAttributes(ctx.DB()); err != nil {
return ctx.Oops().Wrap(err)
} else if !rbac.HasPermission(ctx, approver.ID.String(), objects, rbac.ActionPlaybookApprove) {
return ctx.Oops().Code(api.EFORBIDDEN).Hint(fmt.Sprintf("Required permission: %s", rbac.ActionPlaybookApprove)).Wrap(errors.New("forbidden to approve playbook"))
return ctx.Oops().With("permission", rbac.ActionPlaybookRun, "objects", objects).Code(api.EFORBIDDEN).Wrap(errors.New("access denied: approval permission required"))
}

var spec v1.PlaybookSpec
Expand Down
2 changes: 1 addition & 1 deletion playbook/playbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func Run(ctx context.Context, playbook *models.Playbook, req RunParams) (*models
if objects, err := run.GetRBACAttributes(ctx.DB()); err != nil {
return nil, ctx.Oops().Wrap(err)
} else if !rbac.HasPermission(ctx, ctx.User().ID.String(), objects, rbac.ActionPlaybookRun) {
return nil, ctx.Oops().Code(dutyAPI.EFORBIDDEN).Hint(fmt.Sprintf("Required permission: %s", rbac.ActionPlaybookRun)).Wrap(errors.New("forbidden to run playbook"))
return nil, ctx.Oops().With("permission", rbac.ActionPlaybookRun, "objects", objects).Code(dutyAPI.EFORBIDDEN).Wrap(errors.New("access denied: run permission required"))
}

if err := req.setDefaults(ctx, spec, templateEnv); err != nil {
Expand Down

0 comments on commit 07c1267

Please sign in to comment.