Skip to content

Commit

Permalink
Log errors when granting/revoking access
Browse files Browse the repository at this point in the history
Signed-off-by: Babak K. Shandiz <[email protected]>
  • Loading branch information
babakks committed Oct 11, 2023
1 parent 0cf9f3e commit 42a373b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
33 changes: 31 additions & 2 deletions internal/jimm/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

jujuparams "github.com/juju/juju/rpc/params"
"github.com/juju/names/v4"
"github.com/juju/zaputil"
"github.com/juju/zaputil/zapctx"
"go.uber.org/zap"

Expand Down Expand Up @@ -558,7 +559,13 @@ func (j *JIMM) GrantCloudAccess(ctx context.Context, user *openfga.User, ct name

targetRelation, err := ToCloudRelation(access)
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
zapctx.Debug(
ctx,
"failed to recognize given access",
zaputil.Error(err),
zap.String("access", string(access)),
)
return errors.E(op, errors.CodeBadRequest, fmt.Sprintf("failed to recognize given access: %q", access), err)
}

err = j.doCloudAdmin(ctx, user, ct, func(_ *dbmodel.Cloud, _ API) error {
Expand Down Expand Up @@ -594,6 +601,14 @@ func (j *JIMM) GrantCloudAccess(ctx context.Context, user *openfga.User, ct name
})

if err != nil {
zapctx.Error(
ctx,
"failed to grant cloud access",
zaputil.Error(err),
zap.String("targetUser", string(ut.Id())),
zap.String("cloud", string(ct.Id())),
zap.String("access", string(access)),
)
return errors.E(op, err)
}
return nil
Expand All @@ -609,7 +624,13 @@ func (j *JIMM) RevokeCloudAccess(ctx context.Context, user *openfga.User, ct nam

targetRelation, err := ToCloudRelation(access)
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
zapctx.Debug(
ctx,
"failed to recognize given access",
zaputil.Error(err),
zap.String("access", string(access)),
)
return errors.E(op, errors.CodeBadRequest, fmt.Sprintf("failed to recognize given access: %q", access), err)
}

err = j.doCloudAdmin(ctx, user, ct, func(_ *dbmodel.Cloud, _ API) error {
Expand Down Expand Up @@ -655,6 +676,14 @@ func (j *JIMM) RevokeCloudAccess(ctx context.Context, user *openfga.User, ct nam
})

if err != nil {
zapctx.Error(
ctx,
"failed to revoke cloud access",
zaputil.Error(err),
zap.String("targetUser", string(ut.Id())),
zap.String("cloud", string(ct.Id())),
zap.String("access", string(access)),
)
return errors.E(op, err)
}
return nil
Expand Down
32 changes: 30 additions & 2 deletions internal/jimm/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,13 @@ func (j *JIMM) GrantModelAccess(ctx context.Context, user *openfga.User, mt name

targetRelation, err := ToModelRelation(string(access))
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
zapctx.Debug(
ctx,
"failed to recognize given access",
zaputil.Error(err),
zap.String("access", string(access)),
)
return errors.E(op, errors.CodeBadRequest, fmt.Sprintf("failed to recognize given access: %q", access), err)
}

err = j.doModelAdmin(ctx, user, mt, func(_ *dbmodel.Model, _ API) error {
Expand Down Expand Up @@ -906,6 +912,14 @@ func (j *JIMM) GrantModelAccess(ctx context.Context, user *openfga.User, mt name
})

if err != nil {
zapctx.Error(
ctx,
"failed to grant model access",
zaputil.Error(err),
zap.String("targetUser", string(ut.Id())),
zap.String("model", string(mt.Id())),
zap.String("access", string(access)),
)
return errors.E(op, err)
}
return nil
Expand All @@ -921,7 +935,13 @@ func (j *JIMM) RevokeModelAccess(ctx context.Context, user *openfga.User, mt nam

targetRelation, err := ToModelRelation(string(access))
if err != nil {
return errors.E(op, errors.CodeBadRequest, "failed to recognize given access", err)
zapctx.Debug(
ctx,
"failed to recognize given access",
zaputil.Error(err),
zap.String("access", string(access)),
)
return errors.E(op, errors.CodeBadRequest, fmt.Sprintf("failed to recognize given access: %q", access), err)
}

requiredAccess := "admin"
Expand Down Expand Up @@ -981,6 +1001,14 @@ func (j *JIMM) RevokeModelAccess(ctx context.Context, user *openfga.User, mt nam
})

if err != nil {
zapctx.Error(
ctx,
"failed to revoke model access",
zaputil.Error(err),
zap.String("targetUser", string(ut.Id())),
zap.String("model", string(mt.Id())),
zap.String("access", string(access)),
)
return errors.E(op, err)
}
return nil
Expand Down

0 comments on commit 42a373b

Please sign in to comment.