Skip to content

Commit 5ad51d3

Browse files
authored
sessions (#59)
* migrate to sessions * fix config * use connector name * use connector name * add missing vendor packages * update baton-sdk * use setWorkspaceNames instead of setWorkspaceName * use getworkspacenames * handle codes * add cache to avoid network calls * remove useless cache * fix imports
1 parent 4e69b95 commit 5ad51d3

File tree

322 files changed

+67068
-15600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+67068
-15600
lines changed

Makefile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
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-slack.exe
78
else
89
OUTPUT_PATH = ${BUILD_DIR}/baton-slack
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-slack
20+
build: $(GENERATED_CONF)
21+
go build ${BUILD_TAGS} -o ${OUTPUT_PATH} ./cmd/baton-slack
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:
1731
go get -d -u ./...
1832
go mod tidy -v
1933
go mod vendor
2034

21-
.PHONY: add-dep
22-
add-dep:
35+
.PHONY: add-deps
36+
add-deps:
2337
go mod tidy -v
2438
go mod vendor
2539

cmd/baton-slack/main.go

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ package main
22

33
import (
44
"context"
5-
"fmt"
6-
"os"
75

8-
configSdk "github.com/conductorone/baton-sdk/pkg/config"
9-
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
10-
"github.com/conductorone/baton-sdk/pkg/types"
11-
"github.com/conductorone/baton-slack/pkg/config"
6+
"github.com/conductorone/baton-sdk/pkg/config"
7+
"github.com/conductorone/baton-sdk/pkg/connectorrunner"
8+
cfg "github.com/conductorone/baton-slack/pkg/config"
129
"github.com/conductorone/baton-slack/pkg/connector"
13-
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
14-
"github.com/spf13/viper"
15-
"go.uber.org/zap"
1610
)
1711

1812
var (
@@ -22,46 +16,6 @@ var (
2216

2317
func main() {
2418
ctx := context.Background()
25-
26-
_, cmd, err := configSdk.DefineConfiguration(
27-
ctx,
28-
connectorName,
29-
getConnector,
30-
config.Configuration,
31-
)
32-
if err != nil {
33-
fmt.Fprintln(os.Stderr, err.Error())
34-
os.Exit(1)
35-
}
36-
37-
cmd.Version = version
38-
39-
err = cmd.Execute()
40-
if err != nil {
41-
fmt.Fprintln(os.Stderr, err.Error())
42-
os.Exit(1)
43-
}
44-
}
45-
46-
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
47-
logger := ctxzap.Extract(ctx)
48-
cb, err := connector.New(
49-
ctx,
50-
v.GetString(config.AccessTokenField.FieldName),
51-
v.GetString(config.EnterpriseTokenField.FieldName),
52-
v.GetBool(config.SSOEnabledField.FieldName),
53-
v.GetBool(config.GovEnvironmentField.FieldName),
54-
)
55-
if err != nil {
56-
logger.Error("error creating connector", zap.Error(err))
57-
return nil, err
58-
}
59-
60-
c, err := connectorbuilder.NewConnector(ctx, cb)
61-
if err != nil {
62-
logger.Error("error creating connector", zap.Error(err))
63-
return nil, err
64-
}
65-
66-
return c, nil
19+
config.RunConnector(ctx, connectorName, version, cfg.Configuration, connector.New,
20+
connectorrunner.WithSessionStoreEnabled())
6721
}

go.mod

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ module github.com/conductorone/baton-slack
33
go 1.25.2
44

55
require (
6-
github.com/conductorone/baton-sdk v0.4.11
6+
github.com/conductorone/baton-sdk v0.5.12
77
github.com/ennyjfrick/ruleguard-logfatal v0.0.2
88
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
99
github.com/quasilyte/go-ruleguard/dsl v0.3.22
1010
github.com/slack-go/slack v0.14.0
11-
github.com/spf13/viper v1.19.0
1211
github.com/stretchr/testify v1.11.1
1312
go.uber.org/zap v1.27.0
1413
google.golang.org/grpc v1.71.0
@@ -47,13 +46,11 @@ require (
4746
github.com/conductorone/dpop/integrations/dpop_oauth2 v0.2.3 // indirect
4847
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
4948
github.com/deckarep/golang-set/v2 v2.7.0 // indirect
50-
github.com/dolthub/maphash v0.1.0 // indirect
5149
github.com/doug-martin/goqu/v9 v9.19.0 // indirect
5250
github.com/dustin/go-humanize v1.0.1 // indirect
5351
github.com/ebitengine/purego v0.8.4 // indirect
5452
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
5553
github.com/fsnotify/fsnotify v1.8.0 // indirect
56-
github.com/gammazero/deque v1.0.0 // indirect
5754
github.com/glebarez/go-sqlite v1.22.0 // indirect
5855
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
5956
github.com/go-logr/logr v1.4.2 // indirect
@@ -70,7 +67,7 @@ require (
7067
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
7168
github.com/magiconair/properties v1.8.9 // indirect
7269
github.com/mattn/go-isatty v0.0.20 // indirect
73-
github.com/maypok86/otter v1.2.4 // indirect
70+
github.com/maypok86/otter/v2 v2.2.1 // indirect
7471
github.com/mitchellh/mapstructure v1.5.0 // indirect
7572
github.com/ncruces/go-strftime v0.1.9 // indirect
7673
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
@@ -89,6 +86,7 @@ require (
8986
github.com/spf13/cast v1.7.1 // indirect
9087
github.com/spf13/cobra v1.8.1 // indirect
9188
github.com/spf13/pflag v1.0.6 // indirect
89+
github.com/spf13/viper v1.19.0 // indirect
9290
github.com/subosito/gotenv v1.6.0 // indirect
9391
github.com/tklauser/go-sysconf v0.3.15 // indirect
9492
github.com/tklauser/numcpus v0.10.0 // indirect
@@ -113,7 +111,7 @@ require (
113111
golang.org/x/net v0.35.0 // indirect
114112
golang.org/x/oauth2 v0.26.0 // indirect
115113
golang.org/x/sync v0.11.0 // indirect
116-
golang.org/x/sys v0.35.0 // indirect
114+
golang.org/x/sys v0.37.0 // indirect
117115
golang.org/x/term v0.29.0 // indirect
118116
golang.org/x/text v0.22.0 // indirect
119117
google.golang.org/genproto/googleapis/api v0.0.0-20250218202821-56aae31c358a // indirect

pkg/config/conf.gen.go

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/config/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package config
22

3+
//go:generate go run ./gen
4+
35
import (
46
"github.com/conductorone/baton-sdk/pkg/field"
57
)
@@ -10,11 +12,13 @@ var (
1012
field.WithDisplayName("Access Token"),
1113
field.WithDescription("The Slack bot user oauth token used to connect to the Slack API"),
1214
field.WithRequired(true),
15+
field.WithIsSecret(true),
1316
)
1417
EnterpriseTokenField = field.StringField(
1518
"enterprise-token",
1619
field.WithDisplayName("Enterprise Token"),
1720
field.WithDescription("The Slack user oauth token used to connect to the Slack Enterprise Grid Admin API"),
21+
field.WithIsSecret(true),
1822
)
1923
SSOEnabledField = field.BoolField(
2024
"sso-enabled",
@@ -49,5 +53,11 @@ var (
4953
),
5054
}
5155

52-
Configuration = field.NewConfiguration(ConfigurationFields, field.WithConstraints(FieldRelationships...))
56+
Configuration = field.NewConfiguration(
57+
ConfigurationFields,
58+
field.WithConnectorDisplayName("Slack"),
59+
field.WithHelpUrl("/docs/baton/slack"),
60+
field.WithIconUrl("/static/app-icons/slack.svg"),
61+
field.WithConstraints(FieldRelationships...),
62+
)
5363
)

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+
"github.com/conductorone/baton-sdk/pkg/config"
5+
cfg "github.com/conductorone/baton-slack/pkg/config"
6+
)
7+
8+
func main() {
9+
config.Generate("slack", cfg.Configuration)
10+
}

0 commit comments

Comments
 (0)