Skip to content

Commit a772c25

Browse files
committed
Migrate off deprecated trait profile/status attributes
baton-sdk v0.20.6 moved `profile`, `status`, and `created_at` off the trait messages onto attributes on `Resource`, deprecating the trait-level options and getters. staticcheck flags every remaining call with `SA1019`, so `verify / lint` is red on `main`. This migrates the connector to the resource-level API: - `With{User,Group,Role,App}Profile` -> `WithResourceProfile` - `WithStatus` / `WithDetailedStatus` -> `WithResourceStatus` - `WithCreatedAt` / `WithSecretCreatedAt` -> `WithResourceCreatedAt` - trait `GetProfile()` / `GetStatus()` reads -> the equivalent read on the resource The option type changes from a `*TraitOption` to a `ResourceOption`, so the calls move out of the trait slice and into the variadic tail of the `New*Resource` call. The two status enums are numerically identical, so the values map 1:1. Non-deprecated trait data (login, aliases, emails, secret type/expiry) is untouched. No behavioural change intended: the deprecated options already populated the resource-level fields. `golangci-lint run ./...` reports 0 issues after this change, and the package tests pass.
1 parent 93473d6 commit a772c25

5 files changed

Lines changed: 17 additions & 22 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@
1515
# Dependency directories (remove the comment below to include it)
1616
# vendor/
1717
dist/
18+
19+
# Stray local build output
20+
/connector

pkg/connector/project.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ func projectResource(project *linear.Project, parentId *v2.ResourceId) (*v2.Reso
3737
"project_slug": project.SlugID,
3838
"project_id": project.ID,
3939
}
40-
groupTraitOptions := []rs.GroupTraitOption{rs.WithGroupProfile(profile)}
40+
groupTraitOptions := []rs.GroupTraitOption{}
4141

4242
ret, err := rs.NewGroupResource(
4343
project.Name,
4444
resourceTypeProject,
4545
project.ID,
4646
groupTraitOptions,
47+
rs.WithResourceProfile(profile),
4748
rs.WithParentResourceID(parentId),
4849
)
4950

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

123-
projectTrait, err := rs.GetGroupTrait(resource)
124-
if err != nil {
125-
return nil, "", nil, err
126-
}
127-
128-
projectId, ok := rs.GetProfileStringValue(projectTrait.Profile, "project_id")
124+
projectId, ok := rs.GetProfileStringValue(rs.GetProfile(resource), "project_id")
129125
if !ok {
130126
return nil, "", nil, fmt.Errorf("error fetching project_id from project profile")
131127
}

pkg/connector/role.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ func roleResource(ctx context.Context, role string, parentResourceID *v2.Resourc
4646
"role_id": role,
4747
}
4848

49-
roleTraitOptions := []resource.RoleTraitOption{
50-
resource.WithRoleProfile(profile),
51-
}
49+
roleTraitOptions := []resource.RoleTraitOption{}
5250

5351
ret, err := resource.NewRoleResource(
5452
roleDisplayName,
5553
resourceTypeRole,
5654
role,
5755
roleTraitOptions,
56+
resource.WithResourceProfile(profile),
5857
resource.WithParentResourceID(parentResourceID),
5958
)
6059
if err != nil {

pkg/connector/team.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
var (
21-
_ connectorbuilder.ResourceSyncer = (*teamResourceType)(nil)
21+
_ connectorbuilder.ResourceSyncer = (*teamResourceType)(nil)
2222
_ connectorbuilder.ResourceProvisioner = (*teamResourceType)(nil)
2323
)
2424

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

43-
groupTraitOptions := []rs.GroupTraitOption{rs.WithGroupProfile(profile)}
43+
groupTraitOptions := []rs.GroupTraitOption{}
4444

4545
ret, err := rs.NewGroupResource(
4646
team.Name,
4747
resourceTypeTeam,
4848
team.ID,
4949
groupTraitOptions,
50+
rs.WithResourceProfile(profile),
5051
rs.WithParentResourceID(parentResourceID),
5152
)
5253
if err != nil {

pkg/connector/user.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616
)
1717

1818
var (
19-
_ connectorbuilder.ResourceSyncer = (*userResourceType)(nil)
20-
_ connectorbuilder.AccountManagerLimited = (*userResourceType)(nil)
21-
_ connectorbuilder.ResourceDeleterLimited = (*userResourceType)(nil)
19+
_ connectorbuilder.ResourceSyncer = (*userResourceType)(nil)
20+
_ connectorbuilder.AccountManagerLimited = (*userResourceType)(nil)
21+
_ connectorbuilder.ResourceDeleterLimited = (*userResourceType)(nil)
2222
)
2323

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

6767
userTraitOptions := []sdkResource.UserTraitOption{
68-
sdkResource.WithUserProfile(profile),
6968
sdkResource.WithEmail(user.Email, true),
70-
sdkResource.WithStatus(v2.UserTrait_Status_STATUS_ENABLED),
7169
}
7270

7371
ret, err := sdkResource.NewUserResource(
7472
user.Name,
7573
resourceTypeUser,
7674
user.ID,
7775
userTraitOptions,
76+
sdkResource.WithResourceProfile(profile),
77+
sdkResource.WithResourceStatus(v2.Status_RESOURCE_STATUS_ENABLED, ""),
7878
sdkResource.WithParentResourceID(parentResourceID),
7979
)
8080
if err != nil {
@@ -125,11 +125,7 @@ func (o *userResourceType) Entitlements(_ context.Context, _ *v2.Resource, _ *pa
125125

126126
func (o *userResourceType) Grants(ctx context.Context, resource *v2.Resource, pt *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) {
127127
var rv []*v2.Grant
128-
userTrait, err := sdkResource.GetUserTrait(resource)
129-
if err != nil {
130-
return nil, "", nil, fmt.Errorf("list-grants: Failed to get user trait from user: %w", err)
131-
}
132-
userProfile := userTrait.GetProfile()
128+
userProfile := sdkResource.GetProfile(resource)
133129
userRole, present := sdkResource.GetProfileStringValue(userProfile, userRoleProfileKey)
134130
if !present {
135131
return nil, "", nil, fmt.Errorf("list-grants: user role was not present on profile")

0 commit comments

Comments
 (0)