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/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func projectResource(project *linear.Project, parentId *v2.ResourceId) (*v2.Reso
"project_slug": project.SlugID,
"project_id": project.ID,
}
groupTraitOptions := []rs.GroupTraitOption{rs.WithGroupProfile(profile)}
groupTraitOptions := []rs.GroupTraitOption{}

ret, err := rs.NewGroupResource(
project.Name,
resourceTypeProject,
project.ID,
groupTraitOptions,
rs.WithResourceProfile(profile),
rs.WithParentResourceID(parentId),
)

Expand Down Expand Up @@ -120,12 +121,7 @@ func (o *projectResourceType) Grants(ctx context.Context, resource *v2.Resource,
return nil, "", nil, err
}

projectTrait, err := rs.GetGroupTrait(resource)
if err != nil {
return nil, "", nil, err
}

projectId, ok := rs.GetProfileStringValue(projectTrait.Profile, "project_id")
projectId, ok := rs.GetProfileStringValue(rs.GetProfile(resource), "project_id")
if !ok {
return nil, "", nil, fmt.Errorf("error fetching project_id from project profile")
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/connector/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ func roleResource(ctx context.Context, role string, parentResourceID *v2.Resourc
"role_id": role,
}

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

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: Now that the profile moved to WithResourceProfile, this slice is always empty — the local variable is dead scaffolding. Passing nil directly to resource.NewRoleResource(...) is clearer. Same applies to project.go:40 and team.go:43.


ret, err := resource.NewRoleResource(
roleDisplayName,
resourceTypeRole,
role,
roleTraitOptions,
resource.WithResourceProfile(profile),
resource.WithParentResourceID(parentResourceID),
)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions pkg/connector/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

var (
_ connectorbuilder.ResourceSyncer = (*teamResourceType)(nil)
_ connectorbuilder.ResourceSyncer = (*teamResourceType)(nil)
_ connectorbuilder.ResourceProvisioner = (*teamResourceType)(nil)
)

Expand All @@ -40,13 +40,14 @@ func teamResource(team *linear.Team, parentResourceID *v2.ResourceId) (*v2.Resou
"team_name": team.Name,
}

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

ret, err := rs.NewGroupResource(
team.Name,
resourceTypeTeam,
team.ID,
groupTraitOptions,
rs.WithResourceProfile(profile),
rs.WithParentResourceID(parentResourceID),
)
if err != nil {
Expand Down
16 changes: 6 additions & 10 deletions pkg/connector/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

var (
_ connectorbuilder.ResourceSyncer = (*userResourceType)(nil)
_ connectorbuilder.AccountManagerLimited = (*userResourceType)(nil)
_ connectorbuilder.ResourceDeleterLimited = (*userResourceType)(nil)
_ connectorbuilder.ResourceSyncer = (*userResourceType)(nil)
_ connectorbuilder.AccountManagerLimited = (*userResourceType)(nil)
_ connectorbuilder.ResourceDeleterLimited = (*userResourceType)(nil)
)

const userRoleProfileKey = "user_role"
Expand Down Expand Up @@ -65,16 +65,16 @@ func userResource(ctx context.Context, user *linear.User, parentResourceID *v2.R
}

userTraitOptions := []sdkResource.UserTraitOption{
sdkResource.WithUserProfile(profile),
sdkResource.WithEmail(user.Email, true),
sdkResource.WithStatus(v2.UserTrait_Status_STATUS_ENABLED),
}

ret, err := sdkResource.NewUserResource(
user.Name,
resourceTypeUser,
user.ID,
userTraitOptions,
sdkResource.WithResourceProfile(profile),
sdkResource.WithResourceStatus(v2.Status_RESOURCE_STATUS_ENABLED, ""),

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: The profile/status emission path changed shape here (trait-level → resource-level), but user_test.go only covers accountRole, so nothing asserts what userResource actually produces. Consider a small table test asserting sdkResource.GetProfile(res) contains user_role/user_id and sdkResource.GetStatus(res).GetStatus() == v2.Status_RESOURCE_STATUS_ENABLED — that pins the behavior the Grants path depends on. (confidence: high that coverage is absent; the migration itself reads correct)

sdkResource.WithParentResourceID(parentResourceID),
)
if err != nil {
Expand Down Expand Up @@ -125,11 +125,7 @@ func (o *userResourceType) Entitlements(_ context.Context, _ *v2.Resource, _ *pa

func (o *userResourceType) Grants(ctx context.Context, resource *v2.Resource, pt *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) {
var rv []*v2.Grant
userTrait, err := sdkResource.GetUserTrait(resource)
if err != nil {
return nil, "", nil, fmt.Errorf("list-grants: Failed to get user trait from user: %w", err)
}
userProfile := userTrait.GetProfile()
userProfile := sdkResource.GetProfile(resource)

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: The read path for the role profile key moved from the user trait to the resource, which is the one place this refactor could silently regress (Grants would fail with "user role was not present on profile"). user_test.go only covers CreateAccount/Delete — consider a small test that builds userResource(...) and asserts Grants still emits the role membership grant, so the write/read pairing is locked in.

userRole, present := sdkResource.GetProfileStringValue(userProfile, userRoleProfileKey)
if !present {
return nil, "", nil, fmt.Errorf("list-grants: user role was not present on profile")
Expand Down
Loading