Skip to content

Commit afbd152

Browse files
authored
fix: Schema Fields (#41)
* go mod * fix schema fields * replace README section * Update main.go
1 parent 389b190 commit afbd152

File tree

15 files changed

+161
-61
lines changed

15 files changed

+161
-61
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,23 @@ Usage:
6161
baton-github [command]
6262
6363
Available Commands:
64+
capabilities Get connector capabilities
6465
completion Generate the autocompletion script for the specified shell
6566
help Help about any command
6667
6768
Flags:
68-
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
69-
-h, --help help for baton-github
70-
--instance-url string The GitHub instance URL to connect to. ($BATON_INSTANCE_URL) (default "https://github.com")
71-
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
72-
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
73-
--orgs strings Limit syncing to specific organizations. ($BATON_ORGS)
74-
--token string The GitHub access token used to connect to the GitHub API. ($BATON_TOKEN)
75-
-v, --version version for baton-github
69+
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
70+
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
71+
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
72+
-h, --help help for baton-github
73+
--instance-url string The GitHub instance URL to connect to. (default "https://github.com") ($BATON_INSTANCE_URL)
74+
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
75+
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
76+
--orgs stringArray Limit syncing to specific organizations. ($BATON_ORGS)
77+
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
78+
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
79+
--token string The GitHub access token used to connect to the GitHub API. ($BATON_TOKEN)
80+
-v, --version version for baton-github
7681
7782
Use "baton-github [command] --help" for more information about a command.
7883
```

cmd/baton-github/config.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,29 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
6-
74
"github.com/conductorone/baton-sdk/pkg/field"
8-
"github.com/spf13/viper"
95
)
106

117
var (
128
accessTokenField = field.StringField(
139
"token",
14-
field.WithDescription("The GitHub access token used to connect to the GitHub API. ($BATON_TOKEN)"),
10+
field.WithDescription("The GitHub access token used to connect to the GitHub API."),
11+
field.WithRequired(true),
1512
)
16-
17-
orgsField = field.StringArrayField(
13+
orgsField = field.StringSliceField(
1814
"orgs",
19-
field.WithDescription("Limit syncing to specific organizations. ($BATON_ORGS)"),
15+
field.WithDescription("Limit syncing to specific organizations."),
2016
)
2117
instanceUrlField = field.StringField(
2218
"instance-url",
23-
field.WithDescription(`The GitHub instance URL to connect to. ($BATON_INSTANCE_URL) (default "https://github.com")`),
19+
field.WithDescription(`The GitHub instance URL to connect to. (default "https://github.com")`),
2420
)
25-
)
26-
27-
// configurationFields defines the external configuration required for the connector to run.
28-
var configurationFields = []field.SchemaField{
29-
accessTokenField,
30-
orgsField,
31-
instanceUrlField,
32-
}
33-
34-
// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
35-
func validateConfig(ctx context.Context, v *viper.Viper) error {
36-
if v.GetString(accessTokenField.FieldName) == "" {
37-
return fmt.Errorf("access token is missing")
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+
},
3828
}
39-
return nil
40-
}
29+
)

cmd/baton-github/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ func main() {
2525
ctx,
2626
"baton-github",
2727
getConnector,
28-
field.Configuration{
29-
Fields: configurationFields,
30-
},
31-
nil,
28+
configuration,
3229
)
3330
if err != nil {
3431
fmt.Fprintln(os.Stderr, err.Error())
@@ -46,7 +43,8 @@ func main() {
4643
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
4744
l := ctxzap.Extract(ctx)
4845

49-
if err := validateConfig(ctx, v); err != nil {
46+
err := field.Validate(configuration, v)
47+
if err != nil {
5048
return nil, err
5149
}
5250

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.21
55
toolchain go1.22.3
66

77
require (
8-
github.com/conductorone/baton-sdk v0.2.8
8+
github.com/conductorone/baton-sdk v0.2.14
99
github.com/deckarep/golang-set/v2 v2.6.0
1010
github.com/google/go-github/v63 v63.0.0
1111
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
5050
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5151
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5252
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
53-
github.com/conductorone/baton-sdk v0.2.8 h1:DLHTQXhl50A5AB0cbSoMOmzrUwwbpP7poCXI69Lcdtw=
54-
github.com/conductorone/baton-sdk v0.2.8/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
53+
github.com/conductorone/baton-sdk v0.2.14 h1:6Z0n+yQv470XIO8T6DtkEiLP/2Gkz/lhFOzm//A8qJA=
54+
github.com/conductorone/baton-sdk v0.2.14/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
5555
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
5656
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5757
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

vendor/github.com/conductorone/baton-sdk/pkg/config/config.go

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

vendor/github.com/conductorone/baton-sdk/pkg/field/fields.go

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

vendor/github.com/conductorone/baton-sdk/pkg/field/relationships.go

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

vendor/github.com/conductorone/baton-sdk/pkg/field/validation.go

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/conductorone/baton-sdk/pkg/pagination/pagination.go

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

0 commit comments

Comments
 (0)