Skip to content

Commit 50634b5

Browse files
authored
Merge pull request #23 from ConductorOne/marcos/fix/config-schema
fix: Config schema
2 parents 1591a6b + 7a0610a commit 50634b5

Some content is hidden

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

47 files changed

+5075
-195
lines changed

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ linters:
6666
- bodyclose # checks whether HTTP response body is closed successfully
6767
- durationcheck # check for two durations multiplied together
6868
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
69-
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
7069
- exhaustive # check exhaustiveness of enum switch statements
71-
- exportloopref # checks for pointers to enclosing loop variables
7270
- forbidigo # Forbids identifiers
7371
- gochecknoinits # Checks that no init functions are present in Go code
7472
- goconst # Finds repeated strings that could be replaced by a constant

cmd/baton-snowflake/config.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package main
2+
3+
import (
4+
"github.com/conductorone/baton-sdk/pkg/field"
5+
)
6+
7+
var (
8+
AccountUrlField = field.StringField(
9+
"account-url",
10+
field.WithRequired(true),
11+
field.WithDescription("Account URL."),
12+
)
13+
AccountIdentifierField = field.StringField(
14+
"account-identifier",
15+
field.WithRequired(true),
16+
field.WithDescription("Account Identifier."),
17+
)
18+
UserIdentifierField = field.StringField(
19+
"user-identifier",
20+
field.WithRequired(true),
21+
field.WithDescription("User Identifier."),
22+
)
23+
PublicKeyFingerprintField = field.StringField(
24+
"public-key-fingerprint",
25+
field.WithRequired(true),
26+
field.WithDescription("Public Key Fingerprint."),
27+
)
28+
PrivateKeyPathField = field.StringField(
29+
"private-key-path",
30+
field.WithDescription("Private Key Path."),
31+
)
32+
PrivateKeyField = field.StringField(
33+
"private-key",
34+
field.WithDescription("Private Key (PEM format)."),
35+
)
36+
configurationSchema = field.NewConfiguration(
37+
[]field.SchemaField{
38+
AccountIdentifierField,
39+
AccountUrlField,
40+
PrivateKeyField,
41+
PrivateKeyPathField,
42+
PublicKeyFingerprintField,
43+
UserIdentifierField,
44+
},
45+
field.FieldsMutuallyExclusive(
46+
PrivateKeyPathField,
47+
PrivateKeyField,
48+
),
49+
field.FieldsAtLeastOneUsed(
50+
PrivateKeyPathField,
51+
PrivateKeyField,
52+
),
53+
)
54+
)

cmd/baton-snowflake/config_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/conductorone/baton-sdk/pkg/test"
7+
"github.com/conductorone/baton-sdk/pkg/ustrings"
8+
)
9+
10+
func TestConfigSchema(t *testing.T) {
11+
test.ExerciseTestCasesFromExpressions(
12+
t,
13+
configurationSchema,
14+
nil,
15+
ustrings.ParseFlags,
16+
[]test.TestCaseFromExpression{
17+
{
18+
"",
19+
false,
20+
"empty config",
21+
},
22+
{
23+
"--account-url 1 --account-identifier 1 --user-identifier --public-key-fingerprint 1",
24+
false,
25+
"missing private key",
26+
},
27+
{
28+
"--account-url 1 --account-identifier 1 --user-identifier --public-key-fingerprint 1 --private-key-path 1 --private-key 1",
29+
false,
30+
"both private key types",
31+
},
32+
{
33+
"--account-url 1 --account-identifier 1 --user-identifier --public-key-fingerprint 1 --private-key-path 1",
34+
true,
35+
"private key path",
36+
},
37+
{
38+
"--account-url 1 --account-identifier 1 --user-identifier --public-key-fingerprint 1 --private-key 1",
39+
true,
40+
"private key",
41+
},
42+
},
43+
)
44+
}

cmd/baton-snowflake/main.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77

88
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
9-
"github.com/conductorone/baton-sdk/pkg/field"
109
"github.com/conductorone/baton-sdk/pkg/types"
1110
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
1211
"github.com/spf13/viper"
@@ -17,32 +16,16 @@ import (
1716
)
1817

1918
const (
20-
version = "dev"
21-
connectorName = "baton-snowflake"
22-
accountUrl = "account-url"
23-
accountIdentifier = "account-identifier"
24-
userIdentifier = "user-identifier"
25-
publicKeyFingerPrint = "public-key-fingerprint"
26-
privateKeyPath = "private-key-path"
27-
privateKey = "private-key"
28-
)
29-
30-
var (
31-
AccountUrlField = field.StringField(accountUrl, field.WithRequired(true), field.WithDescription("Account URL."))
32-
AccountIdentifierField = field.StringField(accountIdentifier, field.WithRequired(true), field.WithDescription("Account Identifier."))
33-
UserIdentifierField = field.StringField(userIdentifier, field.WithRequired(true), field.WithDescription("User Identifier."))
34-
PublicKeyFingerprintField = field.StringField(publicKeyFingerPrint, field.WithRequired(true), field.WithDescription("Public Key Fingerprint."))
35-
PrivateKeyPathField = field.StringField(privateKeyPath, field.WithRequired(false), field.WithDescription("Private Key Path."))
36-
PrivateKeyField = field.StringField(privateKey, field.WithRequired(false), field.WithDescription("Private Key (PEM format)."))
37-
configurationFields = []field.SchemaField{AccountUrlField, AccountIdentifierField, UserIdentifierField, PublicKeyFingerprintField, PrivateKeyPathField, PrivateKeyField}
19+
version = "dev"
20+
connectorName = "baton-snowflake"
3821
)
3922

4023
func main() {
4124
ctx := context.Background()
4225
_, cmd, err := configSchema.DefineConfiguration(ctx,
4326
connectorName,
4427
getConnector,
45-
field.NewConfiguration(configurationFields),
28+
configurationSchema,
4629
)
4730
if err != nil {
4831
fmt.Fprintln(os.Stderr, err.Error())
@@ -59,13 +42,14 @@ func main() {
5942

6043
func getConnector(ctx context.Context, cfg *viper.Viper) (types.ConnectorServer, error) {
6144
l := ctxzap.Extract(ctx)
62-
cb, err := connector.New(ctx,
63-
cfg.GetString(accountUrl),
64-
cfg.GetString(accountIdentifier),
65-
cfg.GetString(userIdentifier),
66-
cfg.GetString(publicKeyFingerPrint),
67-
cfg.GetString(privateKeyPath),
68-
cfg.GetString(privateKey),
45+
cb, err := connector.New(
46+
ctx,
47+
cfg.GetString(AccountUrlField.FieldName),
48+
cfg.GetString(AccountIdentifierField.FieldName),
49+
cfg.GetString(UserIdentifierField.FieldName),
50+
cfg.GetString(PublicKeyFingerprintField.FieldName),
51+
cfg.GetString(PrivateKeyPathField.FieldName),
52+
cfg.GetString(PrivateKeyField.FieldName),
6953
)
7054
if err != nil {
7155
l.Error("error creating connector", zap.Error(err))

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module github.com/conductorone/baton-snowflake
33
go 1.22.1
44

55
require (
6-
github.com/conductorone/baton-sdk v0.2.20
6+
github.com/conductorone/baton-sdk v0.2.24
77
github.com/golang-jwt/jwt v3.2.2+incompatible
88
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
9-
github.com/spf13/viper v1.18.2
9+
github.com/spf13/viper v1.19.0
1010
github.com/stretchr/testify v1.9.0
1111
go.uber.org/zap v1.27.0
1212
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
5252
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
5353
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
5454
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
55-
github.com/conductorone/baton-sdk v0.2.20 h1:IpXur6BYJkePwDqOv3AsTP5oFeIDEzgtMvo7FSlOTzE=
56-
github.com/conductorone/baton-sdk v0.2.20/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
55+
github.com/conductorone/baton-sdk v0.2.24 h1:o/zndd/fxHFb49+k6w9l9F5uF1faFzzWKx1C/a50FIw=
56+
github.com/conductorone/baton-sdk v0.2.24/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
5757
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
5858
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5959
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -190,8 +190,8 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
190190
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
191191
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
192192
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
193-
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
194-
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
193+
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
194+
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
195195
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
196196
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
197197
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=

vendor/github.com/conductorone/baton-sdk/internal/connector/connector_server_unix.go

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

0 commit comments

Comments
 (0)