-
Notifications
You must be signed in to change notification settings - Fork 1
Upgrade baton-sdk to v0.4.2. Fix lint errors. #105
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
Conversation
1b87fc0 to
36da96c
Compare
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the WalkthroughUpdates Go toolchain and dependencies in go.mod. Adjusts an annotation value retrieval in enterprise_role entitlement generation. Changes CreateAccount parameter type to LocalCredentialOptions and adds a compile-time interface conformance assertion for invitation resource type. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant InvitationResourceType as invitationResourceType
participant ConnectorBuilder as connectorbuilder.AccountManager
participant AccountStore as Account Storage
Note over Client,InvitationResourceType: Account creation with LocalCredentialOptions
Client->>InvitationResourceType: CreateAccount(ctx, accountInfo, localCredOpts)
InvitationResourceType->>ConnectorBuilder: Validate/Use LocalCredentialOptions
alt valid options
InvitationResourceType->>AccountStore: Create account with credentials
AccountStore-->>InvitationResourceType: Account created
InvitationResourceType-->>Client: Result (success)
else invalid options/error
InvitationResourceType-->>Client: Error
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
pkg/connector/enterprise_role.go (1)
44-54: Data race + leaking internal map from cache
- len(o.roleUsersCache) checked without lock; concurrent writes can panic.
- Returning the internal map exposes it to unsynchronized reads while writers hold the lock.
Fix by gating fill with a separate mutex and returning a copy.
type enterpriseRoleResourceType struct { resourceType *v2.ResourceType client *github.Client customClient *customclient.Client enterprises []string roleUsersCache map[string][]string - mu *sync.Mutex + mu *sync.Mutex // protects roleUsersCache + loadMu *sync.Mutex // gates initial fill } @@ func (o *enterpriseRoleResourceType) getRoleUsersCache(ctx context.Context) (map[string][]string, error) { - if len(o.roleUsersCache) == 0 { - if err := o.fillCache(ctx); err != nil { - return nil, fmt.Errorf("baton-github: error caching user roles: %w", err) - } - } - - o.mu.Lock() - defer o.mu.Unlock() - return o.roleUsersCache, nil + // Ensure single fill without holding o.mu (fillCache locks via cacheRole) + o.mu.Lock() + empty := len(o.roleUsersCache) == 0 + o.mu.Unlock() + if empty { + o.loadMu.Lock() + // Double-check after acquiring loadMu + o.mu.Lock() + empty = len(o.roleUsersCache) == 0 + o.mu.Unlock() + if empty { + if err := o.fillCache(ctx); err != nil { + o.loadMu.Unlock() + return nil, fmt.Errorf("baton-github: error caching user roles: %w", err) + } + } + o.loadMu.Unlock() + } + // Return a copy to avoid exposing internal map + o.mu.Lock() + out := make(map[string][]string, len(o.roleUsersCache)) + for k, v := range o.roleUsersCache { + out[k] = append([]string(nil), v...) + } + o.mu.Unlock() + return out, nil } @@ func enterpriseRoleBuilder(client *github.Client, customClient *customclient.Client, enterprises []string) *enterpriseRoleResourceType { return &enterpriseRoleResourceType{ resourceType: resourceTypeEnterpriseRole, client: client, customClient: customClient, enterprises: enterprises, roleUsersCache: make(map[string][]string), - mu: &sync.Mutex{}, + mu: &sync.Mutex{}, + loadMu: &sync.Mutex{}, } }pkg/connector/invitation.go (3)
55-56: Shadowing package name ‘annotations’ causes compile errorLocal var named annotations shadows the imported package, so annotations.WithRateLimiting(...) won’t compile.
- var annotations annotations.Annotations + var ann annotations.Annotations @@ - annotations.WithRateLimiting(restApiRateLimit) - return invitationResources, pageToken, annotations, nil + ann.WithRateLimiting(restApiRateLimit) + return invitationResources, pageToken, ann, nilAlso applies to: 103-105
151-153: Same shadowing bug in CreateAccountRename the var.
- var annotations annotations.Annotations - annotations.WithRateLimiting(restApiRateLimit) - return &v2.CreateAccountResponse_SuccessResult{ + var ann annotations.Annotations + ann.WithRateLimiting(restApiRateLimit) + return &v2.CreateAccountResponse_SuccessResult{ Resource: r, - }, nil, annotations, nil + }, nil, ann, nil
199-201: Same shadowing bug in DeleteRename the var.
- var annotations annotations.Annotations - annotations.WithRateLimiting(restApiRateLimit) - return annotations, nil + var ann annotations.Annotations + ann.WithRateLimiting(restApiRateLimit) + return ann, nil
🧹 Nitpick comments (4)
pkg/connector/enterprise_role.go (1)
93-99: Avoid double Split; use Cut/SplitN onceMinor tidy-up.
- for roleId := range cache { - roleName := strings.Split(roleId, ":")[1] - enterprise := strings.Split(roleId, ":")[0] + for roleId := range cache { + enterprise, roleName, _ := strings.Cut(roleId, ":")pkg/connector/invitation.go (3)
77-77: Typo in error messageInvitatioins → Invitations.
- return nil, "", nil, fmt.Errorf("github-connector: ListPendingOrgInvitatioins failed: %w", err) + return nil, "", nil, fmt.Errorf("github-connector: ListPendingOrgInvitations failed: %w", err)
69-73: Pagination params: handle nil pt defensivelyIf pt is nil, pt.Size may panic. If upstream guarantees non-nil, ignore. Otherwise, guard or default PerPage.
- invitations, resp, err := i.client.Organizations.ListPendingOrgInvitations(ctx, orgName, &github.ListOptions{ - Page: page, - PerPage: pt.Size, - }) + perPage := 0 + if pt != nil { + perPage = pt.Size + } + invitations, resp, err := i.client.Organizations.ListPendingOrgInvitations(ctx, orgName, &github.ListOptions{ + Page: page, + PerPage: perPage, + })
16-40: Nil-safe inviter access (optional)Current go-github getters are nil-safe, but a defensive map write avoids empty "inviter": "" entries if undesired.
- resource.WithUserProfile(map[string]interface{}{ - "login": login, - "inviter": invitation.GetInviter().GetLogin(), - }), + func() resource.UserTraitOption { + prof := map[string]interface{}{"login": login} + if inv := invitation.GetInviter(); inv != nil && inv.GetLogin() != "" { + prof["inviter"] = inv.GetLogin() + } + return resource.WithUserProfile(prof) + }(),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (98)
.github/workflows/ci.yamlis excluded by none and included by none.github/workflows/main.yamlis excluded by none and included by nonego.sumis excluded by!**/*.sumand included by nonevendor/github.com/conductorone/baton-sdk/internal/connector/connector.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_resource_tree.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_resource_tree.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_sync_id.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/annotation_sync_id.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/connector.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/event_feed.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/event_feed.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/resource.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connector/v2/resource.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/baton.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/baton.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/session.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/session.pb.validate.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pb/c1/connectorapi/baton/v1/session_grpc.pb.gois excluded by!**/*.pb.go,!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/annotations/annotations.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/bid/bid.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/cli/cli.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/cli/commands.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/cli/lambda_server__added.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/config/config.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/connectorbuilder/connectorbuilder.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/connectorrunner/runner.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/connectorstore/connectorstore.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/crypto/client_secret.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/crypto/crypto.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/crypto/password.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/crypto/providers/jwk/jwk.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/crypto/providers/registry.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/c1file.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/c1file_attached.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/clone_sync.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/decoder.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/diff.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/dotc1z.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/file.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/manager/local/local.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/manager/manager.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/manager/s3/s3.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/sql_helpers.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/dotc1z/sync_runs.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/field/defaults.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/field/validation.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/lambda/grpc/config/config.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/lambda/grpc/transport.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/provisioner/provisioner.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/ratelimit/mem_ratelimiter.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sdk/version.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/session/README.mdis excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/session/grpc_session.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/session/json.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/session/memory.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/session/session.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/client_wrapper.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/expand/cycle.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/expand/graph.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/expand/scc/bitset.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/expand/scc/scc.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/expand/scc/test_source.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/state.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/sync/syncer.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/synccompactor/attached/attached.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/synccompactor/compactor.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/delete_resource.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/full_sync.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/manager.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/c1api/service_client.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/tasks/local/syncer.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/types/session_cache.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/types/types.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/ugrpc/c1_credential_provider.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/ugrpc/interceptors.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/uhttp/dbcache.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.gois excluded by!vendor/**and included by nonevendor/github.com/conductorone/baton-sdk/pkg/us3/s3.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/README.mdis excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/huff0/bitreader.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/internal/le/le.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/internal/le/unsafe_disabled.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/internal/le/unsafe_enabled.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/s2sx.modis excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/README.mdis excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/bitreader.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/blockdec.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/blockenc.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/decoder.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/enc_base.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/matchlen_generic.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/seqdec.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/seqdec_amd64.sis excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/seqdec_generic.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/seqenc.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/snappy.gois excluded by!vendor/**and included by nonevendor/github.com/klauspost/compress/zstd/zstd.gois excluded by!vendor/**and included by nonevendor/modules.txtis excluded by!vendor/**and included by none
📒 Files selected for processing (3)
go.mod(2 hunks)pkg/connector/enterprise_role.go(1 hunks)pkg/connector/invitation.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: ci
🔇 Additional comments (6)
go.mod (3)
73-73: klauspost/compress → v1.18.0LGTM.
3-3: Go 1.25 bump — verify CI/toolchain alignmentgo.mod at repo root contains "go 1.25". No .github/workflows, Dockerfiles with golang base images, or .tool-versions/asdf pins were detected in this repo — confirm any external CI (org-level Actions), Docker/image build pipelines, and developer toolchains are aligned to Go 1.25.
6-6: Approve: baton-sdk v0.4.2 upgrade validated — no v0.3 stragglers foundCreateAccount now accepts v2.LocalCredentialOptions (pkg/connector/invitation.go:124–127). No occurrences of the old CredentialOptions were found; annotation identifiers are consistently using &v2.V1Identifier across the codebase.
pkg/connector/enterprise_role.go (1)
122-123: Annotation Id change matches v0.4.xUsing resource.Id.Resource directly is correct.
pkg/connector/invitation.go (2)
48-49: Interface conformance assertionGood addition; prevents drift.
124-131: CreateAccount now takes LocalCredentialOptionsMatches baton-sdk v0.4.x.
Confirm CreateAccountCapabilityDetails options align with LocalCredentialOptions (NO_PASSWORD only).
36da96c to
57fb5f2
Compare
57fb5f2 to
4d4718b
Compare
Summary by CodeRabbit