Skip to content

Commit

Permalink
Check role exists before deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
F21 committed Mar 21, 2024
1 parent e5a0daa commit ff45dac
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ func (b *grafanaBackend) pathRolesWrite(ctx context.Context, req *logical.Reques
}

func (b *grafanaBackend) pathRolesDelete(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
err := req.Storage.Delete(ctx, "roles/"+d.Get("name").(string))
roleName := d.Get("role").(string)
if roleName == "" {
return logical.ErrorResponse("missing role"), nil
}

err := req.Storage.Delete(ctx, "roles/"+roleName)
if err != nil {
return nil, fmt.Errorf("error deleting grafana role: %w", err)
}
Expand Down

0 comments on commit ff45dac

Please sign in to comment.