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
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,22 @@ 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
env:
BATON_SENDGRID_API_KEY: "${{ secrets.BATON_SENDGRID_API_KEY }}"
- 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 capabilities.'
add: 'baton_capabilities.json'
message: "Updating baton config schema and capabilities."
add: |
config_schema.json
baton_capabilities.json
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
52 changes: 0 additions & 52 deletions cmd/baton-sendgrid/config.go

This file was deleted.

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
}
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/ennyjfrick/ruleguard-logfatal v0.0.2
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/quasilyte/go-ruleguard/dsl v0.3.23
github.com/spf13/viper v1.19.0
go.uber.org/zap v1.27.1
)

Expand Down Expand Up @@ -42,7 +41,6 @@ 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
Expand All @@ -68,7 +66,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 @@ -83,7 +80,8 @@ require (
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.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
Expand Down
87 changes: 87 additions & 0 deletions pkg/config/conf.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading