Skip to content

Commit 78cdc5b

Browse files
authored
swap over to using generated config in prep for lambda (#50)
1 parent b822cf1 commit 78cdc5b

File tree

6 files changed

+130
-26
lines changed

6 files changed

+130
-26
lines changed

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
GOOS = $(shell go env GOOS)
22
GOARCH = $(shell go env GOARCH)
33
BUILD_DIR = dist/${GOOS}_${GOARCH}
4+
GENERATED_CONF := pkg/config/conf.gen.go
45

56
ifeq ($(GOOS),windows)
67
OUTPUT_PATH = ${BUILD_DIR}/baton-github.exe
78
else
89
OUTPUT_PATH = ${BUILD_DIR}/baton-github
910
endif
1011

12+
# Set the build tag conditionally based on ENABLE_LAMBDA
13+
ifdef BATON_LAMBDA_SUPPORT
14+
BUILD_TAGS=-tags baton_lambda_support
15+
else
16+
BUILD_TAGS=
17+
endif
18+
1119
.PHONY: build
12-
build:
13-
go build -o ${OUTPUT_PATH} ./cmd/baton-github
20+
build: $(GENERATED_CONF)
21+
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/baton-github
22+
23+
$(GENERATED_CONF): pkg/config/config.go go.mod
24+
@echo "Generating $(GENERATED_CONF)..."
25+
go generate ./pkg/config
26+
27+
generate: $(GENERATED_CONF)
1428

1529
.PHONY: update-deps
1630
update-deps:

cmd/baton-github/main.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66
"os"
77

8+
cfg "github.com/conductorone/baton-github/pkg/config"
89
"github.com/conductorone/baton-sdk/pkg/config"
910
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
1011
"github.com/conductorone/baton-sdk/pkg/field"
1112
"github.com/conductorone/baton-sdk/pkg/types"
1213
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
13-
"github.com/spf13/viper"
1414
"go.uber.org/zap"
1515

1616
"github.com/conductorone/baton-github/pkg/connector"
@@ -25,7 +25,7 @@ func main() {
2525
ctx,
2626
"baton-github",
2727
getConnector,
28-
configuration,
28+
cfg.Config,
2929
)
3030
if err != nil {
3131
fmt.Fprintln(os.Stderr, err.Error())
@@ -40,20 +40,15 @@ func main() {
4040
}
4141
}
4242

43-
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
43+
func getConnector(ctx context.Context, ghc *cfg.Github) (types.ConnectorServer, error) {
4444
l := ctxzap.Extract(ctx)
4545

46-
err := field.Validate(configuration, v)
46+
err := field.Validate(cfg.Config, ghc)
4747
if err != nil {
4848
return nil, err
4949
}
5050

51-
cb, err := connector.New(
52-
ctx,
53-
v.GetStringSlice(orgsField.FieldName),
54-
v.GetString(instanceUrlField.FieldName),
55-
v.GetString(accessTokenField.FieldName),
56-
)
51+
cb, err := connector.New(ctx, ghc)
5752
if err != nil {
5853
l.Error("error creating connector", zap.Error(err))
5954
return nil, err

pkg/config/conf.gen.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package config
22

33
import (
44
"github.com/conductorone/baton-sdk/pkg/field"
@@ -18,12 +18,11 @@ var (
1818
"instance-url",
1919
field.WithDescription(`The GitHub instance URL to connect to. (default "https://github.com")`),
2020
)
21-
// configuration defines the external configuration required for the connector to run.
22-
configuration = field.Configuration{
23-
Fields: []field.SchemaField{
24-
accessTokenField,
25-
orgsField,
26-
instanceUrlField,
27-
},
28-
}
2921
)
22+
23+
//go:generate go run ./gen
24+
var Config = field.NewConfiguration([]field.SchemaField{
25+
accessTokenField,
26+
orgsField,
27+
instanceUrlField,
28+
})

pkg/config/gen/gen.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
import (
4+
cfg "github.com/conductorone/baton-github/pkg/config"
5+
"github.com/conductorone/baton-sdk/pkg/config"
6+
)
7+
8+
func main() {
9+
config.Generate("github", cfg.Config)
10+
}

pkg/connector/connector.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"strings"
99

10+
cfg "github.com/conductorone/baton-github/pkg/config"
1011
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
1112
"github.com/conductorone/baton-sdk/pkg/annotations"
1213
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
@@ -155,19 +156,19 @@ func newGitHubClient(ctx context.Context, instanceURL string, accessToken string
155156
}
156157

157158
// New returns the GitHub connector configured to sync against the instance URL.
158-
func New(ctx context.Context, githubOrgs []string, instanceURL, accessToken string) (*GitHub, error) {
159-
client, err := newGitHubClient(ctx, instanceURL, accessToken)
159+
func New(ctx context.Context, ghc *cfg.Github) (*GitHub, error) {
160+
client, err := newGitHubClient(ctx, ghc.InstanceUrl, ghc.Token)
160161
if err != nil {
161162
return nil, err
162163
}
163-
graphqlClient, err := newGitHubGraphqlClient(ctx, instanceURL, accessToken)
164+
graphqlClient, err := newGitHubGraphqlClient(ctx, ghc.InstanceUrl, ghc.Token)
164165
if err != nil {
165166
return nil, err
166167
}
167168
gh := &GitHub{
168169
client: client,
169-
instanceURL: instanceURL,
170-
orgs: githubOrgs,
170+
instanceURL: ghc.InstanceUrl,
171+
orgs: ghc.Orgs,
171172
graphqlClient: graphqlClient,
172173
orgCache: newOrgNameCache(client),
173174
}

0 commit comments

Comments
 (0)