diff --git a/internal/jimm/access.go b/internal/jimm/access.go index 5a38642b0..49eb872bc 100644 --- a/internal/jimm/access.go +++ b/internal/jimm/access.go @@ -519,10 +519,13 @@ func resolveTag(jimmUUID string, db *db.Database, tag string) (*ofganames.Tag, e "Resolving JIMM tags to Juju tags for tag kind: group", zap.String("group-name", trailer), ) - entry := &dbmodel.GroupEntry{ - Name: trailer, + var entry dbmodel.GroupEntry + if resourceUUID != "" { + entry.UUID = resourceUUID + } else if trailer != "" { + entry.Name = trailer } - err := db.GetGroup(ctx, entry) + err := db.GetGroup(ctx, &entry) if err != nil { return nil, errors.E(fmt.Sprintf("group %s not found", trailer)) } diff --git a/internal/jimm/access_test.go b/internal/jimm/access_test.go index e27fb7268..32de6de59 100644 --- a/internal/jimm/access_test.go +++ b/internal/jimm/access_test.go @@ -636,9 +636,13 @@ func TestResolveTupleObjectMapsGroups(t *testing.T) { } err = j.Database.GetGroup(ctx, group) c.Assert(err, qt.IsNil) + // Test resolution via name and via UUID. tag, err := jimm.ResolveTag(j.UUID, &j.Database, "group-"+group.Name+"#member") c.Assert(err, qt.IsNil) c.Assert(tag, qt.DeepEquals, ofganames.ConvertTagWithRelation(jimmnames.NewGroupTag(group.UUID), ofganames.MemberRelation)) + tag, err = jimm.ResolveTag(j.UUID, &j.Database, "group-"+group.UUID+"#member") + c.Assert(err, qt.IsNil) + c.Assert(tag, qt.DeepEquals, ofganames.ConvertTagWithRelation(jimmnames.NewGroupTag(group.UUID), ofganames.MemberRelation)) } func TestResolveTagObjectMapsUsers(t *testing.T) { diff --git a/pkg/names/group.go b/pkg/names/group.go index 6d9f4f066..ac1d07978 100644 --- a/pkg/names/group.go +++ b/pkg/names/group.go @@ -12,7 +12,7 @@ const ( ) var ( - validGroupName = regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9._-]{4,}[a-zA-Z0-9]$") + validGroupName = regexp.MustCompile("^[a-zA-Z][a-zA-Z0-9._-]+[a-zA-Z0-9]$") validGroupIdSnippet = `^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}((#|\z)[a-z]+)?$` validGroupId = regexp.MustCompile(validGroupIdSnippet) ) diff --git a/pkg/names/group_test.go b/pkg/names/group_test.go index 1a495889b..5317214fc 100644 --- a/pkg/names/group_test.go +++ b/pkg/names/group_test.go @@ -121,8 +121,14 @@ func TestIsValidGroupName(t *testing.T) { name: "", expectedValidity: false, }, { - name: "short", + name: "no", expectedValidity: false, + }, { + name: "foo", + expectedValidity: true, + }, { + name: "short", + expectedValidity: true, }, { name: "short1", expectedValidity: true,