Skip to content
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
10 changes: 3 additions & 7 deletions pkg/connector/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ func groupResource(group *client.Group, parentResourceID *v2.ResourceId) (*v2.Re
"group_name": group.Name,
}

groupTraitOptions := []rs.GroupTraitOption{rs.WithGroupProfile(profile)}
groupTraitOptions := []rs.GroupTraitOption{}

ret, err := rs.NewGroupResource(
group.Name,
resourceTypeGroup,
group.ID,
groupTraitOptions,
rs.WithResourceProfile(profile),
rs.WithParentResourceID(parentResourceID),
)
if err != nil {
Expand Down Expand Up @@ -94,12 +95,7 @@ func (g *groupBuilder) Entitlements(_ context.Context, resource *v2.Resource, _
}

func (g *groupBuilder) Grants(ctx context.Context, resource *v2.Resource, opts rs.SyncOpAttrs) ([]*v2.Grant, *rs.SyncOpResults, error) {
groupTrait, err := rs.GetGroupTrait(resource)
if err != nil {
return nil, nil, fmt.Errorf("failed to get group trait: %w", err)
}

groupId, ok := rs.GetProfileStringValue(groupTrait.Profile, "group_id")
groupId, ok := rs.GetProfileStringValue(rs.GetProfile(resource), "group_id")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: Grants now depends on the profile round-tripping through the resource-level field rather than the group trait, and there is no test covering it (license_test.go only asserts LicenseProfileTrait). A small test that builds groupResource(...) and asserts rs.GetProfileStringValue(rs.GetProfile(res), "group_id") returns the ID would lock in this migration and guard the grant path.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

GetProfile will fall back to group trait if resource profile is not set

if !ok {
return nil, nil, fmt.Errorf("missing group_id in group profile")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/connector/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ func licenseResource(license string, purchased *string, consumed int64) (*v2.Res
"license_id": licenseID,
}

roleTraitOptions := []rs.RoleTraitOption{
rs.WithRoleProfile(profile),
}
roleTraitOptions := []rs.RoleTraitOption{}

stub := &v2.Resource{
Id: &v2.ResourceId{
Expand All @@ -111,6 +109,7 @@ func licenseResource(license string, purchased *string, consumed int64) (*v2.Res
}

ret, err := rs.NewRoleResource(license, resourceTypeLicense, licenseID, roleTraitOptions,
rs.WithResourceProfile(profile),
rs.WithLicenseProfileTrait(licenseTraitOptions...),
)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func userResource(user *client.User, parentResourceID *v2.ResourceId) (*v2.Resou
}

userTraitOptions := []rs.UserTraitOption{
rs.WithUserProfile(profile),
rs.WithStatus(v2.UserTrait_Status_STATUS_ENABLED),
rs.WithEmail(user.Email, true),
}
if user.LastLogin != nil {
Expand All @@ -60,6 +58,8 @@ func userResource(user *client.User, parentResourceID *v2.ResourceId) (*v2.Resou
resourceTypeUser,
user.ID,
userTraitOptions,
rs.WithResourceProfile(profile),
rs.WithResourceStatus(v2.Status_RESOURCE_STATUS_ENABLED, ""),
rs.WithParentResourceID(parentResourceID),
rs.WithExternalID(&v2.ExternalId{Id: user.ID}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Suggestion: rs.WithExternalID is also deprecated in this SDK version (resource.go: "Deprecated. This field is no longer used.") and nothing in this connector reads GetExternalId() — Grant/Revoke here use principal.Id.Resource / grant.Principal.Id.Resource. staticcheck doesn't flag it only because the SDK's comment isn't in the Deprecated: paragraph form, so it slipped past the SA1019 sweep. Consider dropping it in this same cleanup.

)
Expand Down
Loading