Skip to content
Draft
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
16 changes: 9 additions & 7 deletions .github/workflows/capabilities.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Generate connector capabilities
name: Generate capabilities and config schema

on:
push:
branches:
- main

jobs:
calculate-capabilities:
generate_outputs:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest

steps:
Expand All @@ -18,19 +19,20 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
go-version-file: "go.mod"

- name: Build
run: go build -o connector ./cmd/baton-sendgrid

- name: Run and save output
- name: Run and save capabilities and config output
env:
BATON_SENDGRID_API_KEY: "${{ secrets.BATON_SENDGRID_API_KEY }}"
run: ./connector capabilities > baton_capabilities.json
run: ./connector capabilities-and-config > capabilities_and_config.yaml

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: 'Updating baton capabilities.'
add: 'baton_capabilities.json'
message: "Updating baton config schema and capabilities."
add: |
capabilities_and_config.yaml
40 changes: 40 additions & 0 deletions .github/workflows/capabilities_and_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Generate capabilities and config schema

on:
push:
branches:
- main

jobs:
generate_outputs:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.RELENG_GITHUB_TOKEN }}

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Build
run: go build -o connector ./cmd/baton-sendgrid

- name: Run and save config output
run: ./connector config > config_schema.json

- name: Run and save capabilities output
run: ./connector capabilities > baton_capabilities.json

- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
default_author: github_actions
message: "Updating baton config schema and capabilities."
add: |
config_schema.json
baton_capabilities.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
*.c1z
/baton-sendgrid

# Test binary, built with `go test -c`
*.test
Expand Down
22 changes: 18 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
BUILD_DIR = dist/${GOOS}_${GOARCH}
GENERATED_CONF := pkg/config/conf.gen.go

ifeq ($(GOOS),windows)
OUTPUT_PATH = ${BUILD_DIR}/baton-sendgrid.exe
else
OUTPUT_PATH = ${BUILD_DIR}/baton-sendgrid
endif

# Set the build tag conditionally based on ENABLE_LAMBDA
ifdef BATON_LAMBDA_SUPPORT
BUILD_TAGS=-tags baton_lambda_support
else
BUILD_TAGS=
endif

.PHONY: build
build:
go build -o ${OUTPUT_PATH} ./cmd/baton-sendgrid
build: $(GENERATED_CONF)
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/baton-sendgrid

$(GENERATED_CONF): pkg/config/config.go go.mod
@echo "Generating $(GENERATED_CONF)..."
go generate ./pkg/config

generate: $(GENERATED_CONF)

.PHONY: update-deps
update-deps:
go get -d -u ./...
go mod tidy -v
go mod vendor

.PHONY: add-dep
add-dep:
.PHONY: add-deps
add-deps:
go mod tidy -v
go mod vendor

Expand Down
20 changes: 0 additions & 20 deletions cmd/baton-sendgrid/config_test.go

This file was deleted.

79 changes: 9 additions & 70 deletions cmd/baton-sendgrid/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,23 @@ package main

import (
"context"
"fmt"
"os"

"github.com/conductorone/baton-sdk/pkg/config"
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
"github.com/conductorone/baton-sdk/pkg/field"
"github.com/conductorone/baton-sdk/pkg/types"
cfg "github.com/conductorone/baton-sendgrid/pkg/config"
"github.com/conductorone/baton-sendgrid/pkg/connector"
"github.com/conductorone/baton-sendgrid/pkg/connector/client"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/spf13/viper"
"go.uber.org/zap"
"github.com/conductorone/baton-sdk/pkg/config"
"github.com/conductorone/baton-sdk/pkg/connectorrunner"
)

var version = "dev"

func main() {
ctx := context.Background()

_, cmd, err := config.DefineConfiguration(
ctx,
config.RunConnector(ctx,
"baton-sendgrid",
getConnector,
field.Configuration{
Fields: ConfigurationFields,
},
version,
cfg.Config,
connector.New,
connectorrunner.WithSessionStoreEnabled(),
connectorrunner.WithDefaultCapabilitiesConnectorBuilderV2(&connector.Connector{}),
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}

cmd.Version = version

err = cmd.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}

func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)
if err := ValidateConfig(v); err != nil {
return nil, err
}

sendGridApyKey := v.GetString(SendGridApiKeyField.GetName())
sendgridRegion := v.GetString(SendGridRegionField.GetName())
sendgridIgnoreSubusers := v.GetBool(IgnoreSubusers.GetName())

var baseUrl string

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

sendGridCliet, err := client.NewClient(ctx, baseUrl, sendGridApyKey)
if err != nil {
l.Error("error creating sendgrid client", zap.Error(err))
return nil, err
}

cb, err := connector.New(ctx, sendGridCliet, sendgridIgnoreSubusers)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
}
connector, err := connectorbuilder.NewConnector(ctx, cb)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
}
return connector, nil
}
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/conductorone/baton-sendgrid
go 1.25.2

require (
github.com/conductorone/baton-sdk v0.5.25
github.com/conductorone/baton-sdk v0.7.10
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/spf13/viper v1.19.0
go.uber.org/zap v1.27.0
)

Expand Down Expand Up @@ -39,11 +38,10 @@ require (
github.com/conductorone/dpop v0.2.3 // indirect
github.com/conductorone/dpop/integrations/dpop_grpc v0.2.3 // indirect
github.com/conductorone/dpop/integrations/dpop_oauth2 v0.2.3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/deckarep/golang-set/v2 v2.7.0 // indirect
github.com/doug-martin/goqu/v9 v9.19.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ebitengine/purego v0.8.4 // indirect
github.com/ebitengine/purego v0.9.1 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/glebarez/go-sqlite v1.22.0 // indirect
Expand All @@ -65,7 +63,6 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/pquerna/xjwt v0.3.0 // indirect
Expand All @@ -74,16 +71,17 @@ require (
github.com/sagikazarmark/locafero v0.7.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/shirou/gopsutil/v4 v4.25.8 // indirect
github.com/shirou/gopsutil/v4 v4.25.11 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.12.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.15 // indirect
github.com/tklauser/numcpus v0.10.0 // indirect
github.com/tklauser/go-sysconf v0.3.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/contrib/bridges/otelzap v0.10.0 // indirect
Expand All @@ -102,12 +100,14 @@ require (
go.uber.org/ratelimit v0.3.1 // indirect
golang.org/x/crypto v0.34.0 // indirect
golang.org/x/exp v0.0.0-20250128182459-e0ece0dbea4c // indirect
golang.org/x/mod v0.23.0 // indirect
golang.org/x/net v0.35.0 // indirect
golang.org/x/oauth2 v0.33.0 // indirect
golang.org/x/sync v0.11.0 // indirect
golang.org/x/sys v0.37.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.29.0 // indirect
golang.org/x/text v0.22.0 // indirect
golang.org/x/tools v0.30.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250219182151-9fdb1cabc7b2 // indirect
google.golang.org/grpc v1.71.0 // indirect
Expand Down
Loading