Skip to content

Commit 4b7dfd7

Browse files
author
Baton Admin
committed
chore: update connector skills via baton-admin
1 parent 112cf67 commit 4b7dfd7

File tree

1 file changed

+239
-0
lines changed

1 file changed

+239
-0
lines changed
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# build-config
2+
3+
Configuration schema and CLI flags.
4+
5+
---
6+
7+
## Field Definitions
8+
9+
```go
10+
// pkg/config/config.go
11+
package config
12+
13+
import "github.com/conductorone/baton-sdk/pkg/field"
14+
15+
var (
16+
APIKeyField = field.StringField(
17+
"api-key",
18+
field.WithDescription("API key for authentication"),
19+
field.WithRequired(true),
20+
)
21+
22+
DomainField = field.StringField(
23+
"domain",
24+
field.WithDescription("Service domain (e.g., example.okta.com)"),
25+
field.WithRequired(true),
26+
)
27+
28+
IncludeDisabledField = field.BoolField(
29+
"include-disabled",
30+
field.WithDescription("Include disabled users in sync"),
31+
field.WithDefaultValue(false),
32+
)
33+
34+
PageSizeField = field.IntField(
35+
"page-size",
36+
field.WithDescription("API page size"),
37+
field.WithDefaultValue(100),
38+
)
39+
)
40+
41+
var Configuration = field.NewConfiguration([]field.SchemaField{
42+
APIKeyField,
43+
DomainField,
44+
IncludeDisabledField,
45+
PageSizeField,
46+
})
47+
```
48+
49+
---
50+
51+
## Environment Variables
52+
53+
Fields automatically become environment variables:
54+
55+
| Field Name | Environment Variable |
56+
|------------|---------------------|
57+
| `api-key` | `BATON_API_KEY` |
58+
| `domain` | `BATON_DOMAIN` |
59+
| `include-disabled` | `BATON_INCLUDE_DISABLED` |
60+
61+
Pattern: `BATON_` + uppercase + underscores
62+
63+
---
64+
65+
## Main Entry Point
66+
67+
```go
68+
// cmd/baton-myservice/main.go
69+
package main
70+
71+
import (
72+
"context"
73+
"fmt"
74+
"os"
75+
76+
"github.com/myorg/baton-myservice/pkg/config"
77+
"github.com/myorg/baton-myservice/pkg/connector"
78+
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
79+
"github.com/conductorone/baton-sdk/pkg/connectorrunner"
80+
"github.com/conductorone/baton-sdk/pkg/types"
81+
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
82+
"go.uber.org/zap"
83+
)
84+
85+
var version = "dev"
86+
87+
func main() {
88+
ctx := context.Background()
89+
90+
_, cmd, err := configschema.DefineConfiguration(
91+
ctx,
92+
"baton-myservice",
93+
getConnector,
94+
config.Configuration,
95+
connectorrunner.WithDefaultCapabilitiesConnectorBuilder(&connector.MyService{}),
96+
)
97+
if err != nil {
98+
fmt.Fprintln(os.Stderr, err.Error())
99+
os.Exit(1)
100+
}
101+
102+
cmd.Version = version
103+
104+
if err := cmd.Execute(); err != nil {
105+
fmt.Fprintln(os.Stderr, err.Error())
106+
os.Exit(1)
107+
}
108+
}
109+
110+
func getConnector(ctx context.Context, cfg *config.Config) (types.ConnectorServer, error) {
111+
l := ctxzap.Extract(ctx)
112+
113+
cb, err := connector.New(ctx, cfg)
114+
if err != nil {
115+
l.Error("error creating connector", zap.Error(err))
116+
return nil, err
117+
}
118+
119+
c, err := connectorbuilder.NewConnector(ctx, cb)
120+
if err != nil {
121+
l.Error("error creating connector server", zap.Error(err))
122+
return nil, err
123+
}
124+
125+
return c, nil
126+
}
127+
```
128+
129+
---
130+
131+
## OAuth Configuration
132+
133+
For OAuth2 client credentials:
134+
135+
```go
136+
var (
137+
ClientIDField = field.StringField(
138+
"client-id",
139+
field.WithDescription("OAuth2 client ID"),
140+
field.WithRequired(true),
141+
)
142+
143+
ClientSecretField = field.StringField(
144+
"client-secret",
145+
field.WithDescription("OAuth2 client secret"),
146+
field.WithRequired(true),
147+
field.WithIsSecret(true), // Marked as secret
148+
)
149+
150+
TokenURLField = field.StringField(
151+
"token-url",
152+
field.WithDescription("OAuth2 token endpoint"),
153+
)
154+
)
155+
```
156+
157+
---
158+
159+
## Testability Configuration
160+
161+
For mock server testing:
162+
163+
```go
164+
var (
165+
BaseURLField = field.StringField(
166+
"base-url",
167+
field.WithDescription("Override API base URL (for testing)"),
168+
)
169+
170+
InsecureField = field.BoolField(
171+
"insecure",
172+
field.WithDescription("Skip TLS verification (for testing)"),
173+
field.WithDefaultValue(false),
174+
)
175+
)
176+
```
177+
178+
These enable pointing connector at mock servers in CI.
179+
180+
---
181+
182+
## Field Validation
183+
184+
```go
185+
var (
186+
PageSizeField = field.IntField(
187+
"page-size",
188+
field.WithDescription("API page size (1-1000)"),
189+
field.WithDefaultValue(100),
190+
field.WithValidation(func(v int) error {
191+
if v < 1 || v > 1000 {
192+
return fmt.Errorf("page-size must be between 1 and 1000")
193+
}
194+
return nil
195+
}),
196+
)
197+
)
198+
```
199+
200+
---
201+
202+
## Field Relationships
203+
204+
For mutually exclusive or dependent fields:
205+
206+
```go
207+
var relationships = []field.SchemaFieldRelationship{
208+
field.FieldsExclusivelyRequired(
209+
APIKeyField,
210+
ClientIDField,
211+
), // One or the other, not both
212+
}
213+
214+
var Configuration = field.NewConfiguration(
215+
[]field.SchemaField{...},
216+
field.WithConstraints(relationships...),
217+
)
218+
```
219+
220+
---
221+
222+
## CLI Usage
223+
224+
```bash
225+
# With flags
226+
baton-myservice --api-key="..." --domain="example.com"
227+
228+
# With environment variables
229+
BATON_API_KEY="..." BATON_DOMAIN="example.com" baton-myservice
230+
231+
# Mixed (env vars override flags)
232+
BATON_API_KEY="..." baton-myservice --domain="example.com"
233+
234+
# Output to specific file
235+
baton-myservice --file=/path/to/sync.c1z
236+
237+
# With logging
238+
baton-myservice --log-level=debug --log-format=json
239+
```

0 commit comments

Comments
 (0)