diff --git a/cmd/jimmctl/cmd/relation_test.go b/cmd/jimmctl/cmd/relation_test.go index 209316430..a1e4d32fb 100644 --- a/cmd/jimmctl/cmd/relation_test.go +++ b/cmd/jimmctl/cmd/relation_test.go @@ -360,11 +360,11 @@ func (s *relationSuite) TestListRelations(c *gc.C) { }, { Object: "group-group-1#member", Relation: "administrator", - TargetObject: "model-" + env.controllers[0].Name + ":" + env.models[0].OwnerIdentityName + "/" + env.models[0].Name, + TargetObject: "model-" + env.models[0].OwnerIdentityName + "/" + env.models[0].Name, }, { Object: "user-" + env.users[1].Name, Relation: "administrator", - TargetObject: "applicationoffer-" + env.controllers[0].Name + ":" + env.applicationOffers[0].Model.OwnerIdentityName + "/" + env.applicationOffers[0].Model.Name + "." + env.applicationOffers[0].Name, + TargetObject: "applicationoffer-" + env.applicationOffers[0].URL, }, { Object: "user-" + env.users[0].Name, Relation: "administrator", diff --git a/internal/errors/errors.go b/internal/errors/errors.go index 08fbc7695..26f4d57bc 100644 --- a/internal/errors/errors.go +++ b/internal/errors/errors.go @@ -122,7 +122,7 @@ const ( CodeStillAlive Code = apiparams.CodeStillAlive CodeUnauthorized Code = jujuparams.CodeUnauthorized CodeUpgradeInProgress Code = jujuparams.CodeUpgradeInProgress - CodeFailedToParseTupleKey Code = "failed to parse tuple object key" + CodeFailedToParseTupleKey Code = "failed to parse tuple" CodeFailedToResolveTupleResource Code = "failed resolve resource" CodeOpenFGARequestFailed Code = "failed request to OpenFGA" CodeJWKSRetrievalFailed Code = "jwks retrieval failure" diff --git a/internal/jimm/access_test.go b/internal/jimm/access_test.go index eddfa3b89..58292071e 100644 --- a/internal/jimm/access_test.go +++ b/internal/jimm/access_test.go @@ -605,6 +605,10 @@ func TestResolveTupleObjectHandlesErrors(t *testing.T) { input: "abc", want: "failed to setup tag resolver: tag is not properly formatted", }, + { + input: "model-test-unknowncontroller-1:alice@canonical.com/test-model-1", + want: "model not found", + }, } for i, tc := range tests { t.Run(fmt.Sprintf("test %d", i), func(t *testing.T) { diff --git a/internal/jujuapi/access_control.go b/internal/jujuapi/access_control.go index 5f8faf2d0..403359cc4 100644 --- a/internal/jujuapi/access_control.go +++ b/internal/jujuapi/access_control.go @@ -4,6 +4,7 @@ package jujuapi import ( "context" + "fmt" "strconv" "time" @@ -198,7 +199,7 @@ func (r *controllerRoot) parseTuple(ctx context.Context, tuple apiparams.Relatio // to be specific to the erroneous offender. parseTagError := func(msg string, key string, err error) error { zapctx.Debug(ctx, msg, zap.String("key", key), zap.Error(err)) - return errors.E(op, errors.CodeFailedToParseTupleKey, err, msg+" "+key) + return errors.E(op, errors.CodeFailedToParseTupleKey, fmt.Errorf("%s, key %s: %w", msg, key, err)) } if tuple.TargetObject == "" { @@ -207,14 +208,14 @@ func (r *controllerRoot) parseTuple(ctx context.Context, tuple apiparams.Relatio if tuple.TargetObject != "" { targetTag, err := r.jimm.ParseTag(ctx, tuple.TargetObject) if err != nil { - return nil, parseTagError("failed to parse tuple target object key", tuple.TargetObject, err) + return nil, parseTagError("failed to parse tuple target", tuple.TargetObject, err) } t.Target = targetTag } if tuple.Object != "" { objectTag, err := r.jimm.ParseTag(ctx, tuple.Object) if err != nil { - return nil, parseTagError("failed to parse tuple object key", tuple.Object, err) + return nil, parseTagError("failed to parse tuple object", tuple.Object, err) } t.Object = objectTag } diff --git a/internal/jujuapi/access_control_test.go b/internal/jujuapi/access_control_test.go index 22fff1934..533d89dcf 100644 --- a/internal/jujuapi/access_control_test.go +++ b/internal/jujuapi/access_control_test.go @@ -935,6 +935,15 @@ func (s *accessControlSuite) TestListRelationshipTuples(c *gc.C) { c.Assert(err, jc.ErrorIsNil) c.Assert(response.Tuples, jc.DeepEquals, []apiparams.RelationshipTuple{tuples[3]}) c.Assert(len(response.Errors), gc.Equals, 0) + + // Test error message when a resource is not found + _, err = client.ListRelationshipTuples(&apiparams.ListRelationshipTuplesRequest{ + Tuple: apiparams.RelationshipTuple{ + TargetObject: "applicationoffer-" + "fake-offer", + }, + ResolveUUIDs: true, + }) + c.Assert(err, gc.ErrorMatches, "failed to parse tuple target, key applicationoffer-fake-offer: application offer not found.*") } func (s *accessControlSuite) TestListRelationshipTuplesNoUUIDResolution(c *gc.C) {