Skip to content

Containerize baton-sendgrid connector#20

Draft
laurenleach wants to merge 7 commits intomainfrom
containerize-baton-sendgrid
Draft

Containerize baton-sendgrid connector#20
laurenleach wants to merge 7 commits intomainfrom
containerize-baton-sendgrid

Conversation

@laurenleach
Copy link

@laurenleach laurenleach commented Jan 29, 2026

Containerizes the connector following baton-databricks#35 and baton-contentful#48.

Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com

Summary by CodeRabbit

  • Chores

    • Updated Baton SDK and numerous underlying dependencies to newer stable versions.
  • Refactor

    • Restructured SendGrid connector initialization and simplified creation workflow.
    • Updated configuration wiring and connector sync interfaces to a new initialization model.
    • Added richer metadata and help links for SendGrid configuration fields.
  • New Features

    • Added a public SendGrid configuration type with convenient accessors and a dedicated configuration instance.

- Update baton-sdk to v0.7.10
- Create pkg/config package with generated configuration
- Update main.go to use config.RunConnector API
- Update connector to use V2 interface
- Update Makefile for config generation and lambda support
- Update GitHub workflows

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@laurenleach laurenleach requested a review from a team January 29, 2026 23:16
@coderabbitai
Copy link

coderabbitai bot commented Jan 29, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Walkthrough

Upgrades multiple dependencies, adds a generated Sendgrid config type with reflection-based accessors, refactors package config (removing viper and ValidateConfig), and rewrites the connector constructor to accept a config object and build the SendGrid client internally.

Changes

Cohort / File(s) Summary
Dependency Updates
go.mod
Bumped github.com/conductorone/baton-sdk and many indirect deps; removed direct viper require; various minor version upgrades across system and utility libs.
Generated Config
pkg/config/conf.gen.go
Adds Sendgrid struct and reflection-based accessors: GetStringSlice, GetString, GetInt, GetBool, GetStringMap, plus findFieldByTag. (Code-generated file.)
Configuration Refactor
pkg/config/config.go
Changed package to config; removed viper import and ValidateConfig; added display names and secret flag for fields, go:generate directive, and a public Config via field.NewConfiguration(...).
Connector API & Wiring
pkg/connector/connector.go
Reworked New to accept *cfg.Sendgrid and *cli.ConnectorOpts, construct SendGrid client internally (region→base URL), return connectorbuilder.ConnectorBuilderV2 and opts; updated ResourceSyncers to V2 signatures and adjusted imports/wiring.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Config as Config (pkg/config)
    participant ConnectorCtor as Connector.New
    participant ClientPkg as client.NewClient
    participant Connector as Connector (builder)

    rect rgba(100,149,237,0.5)
    Caller->>ConnectorCtor: call New(ctx, cfg.Sendgrid, opts)
    end

    rect rgba(144,238,144,0.5)
    ConnectorCtor->>Config: read API key, region, ignoreSubusers
    ConnectorCtor->>ClientPkg: NewClient(apiKey, baseURL)
    ClientPkg-->>ConnectorCtor: client or error
    ConnectorCtor->>Connector: construct Connector with client & cache
    ConnectorCtor-->>Caller: return ConnectorBuilderV2, opts
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I tucked a key in reflected rows,

hopped past viper where the clean wind blows,
new client built where the region flows,
dependencies pranced in tidy rows,
connector stitched — and off I go! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Containerize baton-sendgrid connector' accurately describes the main objective of the changeset, which focuses on containerizing the connector and updating it to work with the containerization framework.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch containerize-baton-sendgrid

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a 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 (1)
pkg/connector/connector.go (1)

57-64: ⚠️ Potential issue | 🔴 Critical

Critical: *Connector does not implement connectorbuilder.ConnectorBuilderV2 interface.

The ResourceSyncers method returns []connectorbuilder.ResourceSyncer (lines 57-64), but ConnectorBuilderV2 requires []connectorbuilder.ResourceSyncerV2. Additionally, all resource builder implementations (teammates.go, subuser.go, scopes.go, teammate_invitations.go) must be updated to implement ResourceSyncerV2Limited with the new method signatures:

  • Change List, Entitlements, and Grants method signatures from using *pagination.Token to resource.SyncOpAttrs
  • Update return types from (string, annotations.Annotations, error) to (*resource.SyncOpResults, error)

Also applies to: 122-151

🧹 Nitpick comments (2)
pkg/connector/connector.go (2)

21-23: Consider removing unused error variable.

ErrSendgridClientNotProvided appears to be unused now that the New function creates the client internally rather than accepting it as a parameter.

🧹 Proposed removal
-var (
-	ErrSendgridClientNotProvided = errors.New("sendgrid client not provided")
-)

Also remove the errors import if no other errors are defined in this file.

 import (
 	"context"
-	"errors"
 	"io"

131-139: Region handling logs warning for empty string default value.

When sendgridRegion is empty (e.g., if the config field wasn't set despite having a default), the switch falls through to default and logs a warning. Since SendGridRegionField has WithDefaultValue("global"), this should typically be fine, but the warning message "invalid sendgrid region" may be misleading if the region is simply empty rather than invalid.

💡 Consider handling empty string explicitly
 	switch sendgridRegion {
 	case "eu":
 		baseUrl = client.SendGridEUBaseUrl
-	case "global":
+	case "global", "":
 		baseUrl = client.SendGridBaseUrl
 	default:
 		baseUrl = client.SendGridBaseUrl
 		l.Warn("invalid sendgrid region, using the default global URL", zap.String("region", sendgridRegion))
 	}

- Use RunConnector with WithDefaultCapabilitiesConnectorBuilder
- Update connector.New signature (already correct)
- Update ResourceSyncers to return ResourceSyncerV2
- Fix workflow to generate capabilities_and_config.yaml
- Run go mod tidy -v && go mod vendor

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Copy link

@coderabbitai coderabbitai bot left a 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 (1)
pkg/connector/connector.go (1)

57-63: ⚠️ Potential issue | 🔴 Critical

Build failure: Builders do not implement connectorbuilder.ResourceSyncerV2 interface correctly.

The builders (e.g., *teammateBuilder, *scopeBuilder, etc.) have incorrect method signatures that don't match ResourceSyncerV2. Specifically:

  • Parameter mismatch: Methods use *pagination.Token but ResourceSyncerV2 requires resource.SyncOpAttrs
  • Return type mismatch: Methods return (result, string, annotations.Annotations, error) but ResourceSyncerV2 requires (result, *resource.SyncOpResults, error)

Update the List, Entitlements, and Grants method signatures in all builder files (teammates.go, scopes.go, subuser.go, teammate_invitations.go) to match the ResourceSyncerV2Limited interface.

Additionally, the opts *cli.ConnectorOpts parameter in the New() function (line 122) is unused and can be removed.

🧹 Nitpick comments (3)
pkg/connector/connector.go (3)

122-122: Unused parameter opts *cli.ConnectorOpts.

The opts parameter is accepted but never referenced in the function body. If this is required by the ConnectorBuilderV2 constructor signature convention, consider adding a comment to clarify. Otherwise, if it's intended for future use, ensure it gets wired in or remove it to avoid confusion.


21-23: ErrSendgridClientNotProvided is now dead code.

Since the constructor now creates the client internally rather than accepting it as a parameter, this error is no longer used. Consider removing it.

🧹 Proposed fix
-var (
-	ErrSendgridClientNotProvided = errors.New("sendgrid client not provided")
-)

Also remove the "errors" import at line 5 if no longer needed elsewhere in this file.


131-139: Region handling logic looks good, minor suggestion on empty string case.

The region validation with a default fallback is appropriate. However, when the region is an empty string (unset), the warning "invalid sendgrid region" might be misleading. Consider distinguishing between an empty/unset region and an actually invalid value.

💡 Optional: Distinguish empty from invalid region
 	switch sendgridRegion {
 	case "eu":
 		baseUrl = client.SendGridEUBaseUrl
-	case "global":
+	case "global", "":
 		baseUrl = client.SendGridBaseUrl
 	default:
 		baseUrl = client.SendGridBaseUrl
 		l.Warn("invalid sendgrid region, using the default global URL", zap.String("region", sendgridRegion))
 	}

@laurenleach laurenleach marked this pull request as draft February 3, 2026 20:08
laurenleach and others added 4 commits February 3, 2026 12:15
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace pagination.Token with rs.SyncOpAttrs parameter and return *rs.SyncOpResults instead of string/annotations in List, Entitlements, and Grants methods across all resource syncers (teammates, subuser, scopes, teammate_invitations). This aligns with the V2 SDK pattern for resource synchronization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fix pagination token pointer usage in 5 locations:
  - Changed opts.PageToken == nil check to opts.PageToken.Token == ""
  - Changed opts.PageToken to &opts.PageToken when passing to client methods
- Update main.go to use WithDefaultCapabilitiesConnectorBuilderV2
- Add baton-sendgrid binary to .gitignore

Resolves compilation errors in:
- pkg/connector/scopes.go:34
- pkg/connector/subuser.go:35
- pkg/connector/teammate_invitations.go:27
- pkg/connector/teammates.go:32,71

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant