Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow querying groups by UUID #1286

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions internal/jimm/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 4 additions & 0 deletions internal/jimm/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/names/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]$")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you change this? to comply with both uuid and name format?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the description of the PR mentions the reason. It currently enforces that names must be 6 characters long - first group, second group 4 or more times, last group. The + makes the match "one or more" instead. So now the minimum length of a group name is 3.

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)
)
Expand Down
8 changes: 7 additions & 1 deletion pkg/names/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading