Skip to content

Commit 3a803e8

Browse files
authored
Update baton sdk and regenerate capabiltiies (#21)
* Update baton-sdk dep * Updates to be compatible with new version of baton-sdk * Regenerate capabilities to include new capabilities * Default to public schemas * remove execinquery from linter config
1 parent de2eddf commit 3a803e8

File tree

1,534 files changed

+4576547
-1965452
lines changed

Some content is hidden

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

1,534 files changed

+4576547
-1965452
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ linters:
7070
- bodyclose # checks whether HTTP response body is closed successfully
7171
- durationcheck # check for two durations multiplied together
7272
- 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.
73-
- execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds
7473
- exhaustive # check exhaustiveness of enum switch statements
7574
- exportloopref # checks for pointers to enclosing loop variables
7675
- forbidigo # Forbids identifiers

baton_capabilities.json

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,115 @@
11
{
2-
"@type": "type.googleapis.com/c1.connector.v2.ConnectorCapabilities",
3-
"resourceTypeCapabilities": [
2+
"@type": "type.googleapis.com/c1.connector.v2.ConnectorCapabilities",
3+
"resourceTypeCapabilities": [
44
{
5-
"resourceType": {
6-
"id": "column",
7-
"displayName": "Column"
5+
"resourceType": {
6+
"id": "column",
7+
"displayName": "Column"
88
},
9-
"capabilities": [
9+
"capabilities": [
1010
"CAPABILITY_SYNC"
1111
]
1212
},
1313
{
14-
"resourceType": {
15-
"id": "database",
16-
"displayName": "Database"
14+
"resourceType": {
15+
"id": "database",
16+
"displayName": "Database"
1717
},
18-
"capabilities": [
19-
"CAPABILITY_SYNC"
18+
"capabilities": [
19+
"CAPABILITY_SYNC",
20+
"CAPABILITY_PROVISION",
21+
"CAPABILITY_RESOURCE_CREATE",
22+
"CAPABILITY_RESOURCE_DELETE"
2023
]
2124
},
2225
{
23-
"resourceType": {
24-
"id": "function",
25-
"displayName": "Function"
26+
"resourceType": {
27+
"id": "function",
28+
"displayName": "Function"
2629
},
27-
"capabilities": [
30+
"capabilities": [
2831
"CAPABILITY_SYNC"
2932
]
3033
},
3134
{
32-
"resourceType": {
33-
"id": "large-object",
34-
"displayName": "Large Object"
35+
"resourceType": {
36+
"id": "large-object",
37+
"displayName": "Large Object"
3538
},
36-
"capabilities": [
39+
"capabilities": [
3740
"CAPABILITY_SYNC"
3841
]
3942
},
4043
{
41-
"resourceType": {
42-
"id": "procedure",
43-
"displayName": "Procedure"
44+
"resourceType": {
45+
"id": "procedure",
46+
"displayName": "Procedure"
4447
},
45-
"capabilities": [
48+
"capabilities": [
4649
"CAPABILITY_SYNC"
4750
]
4851
},
4952
{
50-
"resourceType": {
51-
"id": "role",
52-
"displayName": "Role",
53-
"traits": [
53+
"resourceType": {
54+
"id": "role",
55+
"displayName": "Role",
56+
"traits": [
5457
"TRAIT_ROLE",
5558
"TRAIT_USER"
5659
]
5760
},
58-
"capabilities": [
59-
"CAPABILITY_SYNC"
61+
"capabilities": [
62+
"CAPABILITY_SYNC",
63+
"CAPABILITY_PROVISION",
64+
"CAPABILITY_ACCOUNT_PROVISIONING",
65+
"CAPABILITY_CREDENTIAL_ROTATION",
66+
"CAPABILITY_RESOURCE_CREATE",
67+
"CAPABILITY_RESOURCE_DELETE"
6068
]
6169
},
6270
{
63-
"resourceType": {
64-
"id": "schema",
65-
"displayName": "Schema"
71+
"resourceType": {
72+
"id": "schema",
73+
"displayName": "Schema"
6674
},
67-
"capabilities": [
75+
"capabilities": [
6876
"CAPABILITY_SYNC"
6977
]
7078
},
7179
{
72-
"resourceType": {
73-
"id": "sequence",
74-
"displayName": "Sequence"
80+
"resourceType": {
81+
"id": "sequence",
82+
"displayName": "Sequence"
7583
},
76-
"capabilities": [
84+
"capabilities": [
7785
"CAPABILITY_SYNC"
7886
]
7987
},
8088
{
81-
"resourceType": {
82-
"id": "table",
83-
"displayName": "Table"
89+
"resourceType": {
90+
"id": "table",
91+
"displayName": "Table"
8492
},
85-
"capabilities": [
93+
"capabilities": [
8694
"CAPABILITY_SYNC"
8795
]
8896
},
8997
{
90-
"resourceType": {
91-
"id": "view",
92-
"displayName": "View"
98+
"resourceType": {
99+
"id": "view",
100+
"displayName": "View"
93101
},
94-
"capabilities": [
102+
"capabilities": [
95103
"CAPABILITY_SYNC"
96104
]
97105
}
106+
],
107+
"connectorCapabilities": [
108+
"CAPABILITY_SYNC",
109+
"CAPABILITY_PROVISION",
110+
"CAPABILITY_RESOURCE_CREATE",
111+
"CAPABILITY_RESOURCE_DELETE",
112+
"CAPABILITY_ACCOUNT_PROVISIONING",
113+
"CAPABILITY_CREDENTIAL_ROTATION"
98114
]
99115
}

cmd/baton-postgresql/config.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
6-
7-
"github.com/conductorone/baton-sdk/pkg/cli"
4+
"github.com/conductorone/baton-sdk/pkg/field"
85
)
96

10-
// config defines the external configuration required for the connector to run.
11-
type config struct {
12-
cli.BaseConfig `mapstructure:",squash"` // Puts the base config options in the same place as the connector options
13-
14-
Dsn string `mapstructure:"dsn"`
15-
Schemas []string `mapstructure:"schemas"`
16-
IncludeColumns bool `mapstructure:"include-columns"`
17-
IncludeLargeObjects bool `mapstructure:"include-large-objects"`
18-
}
7+
var (
8+
dsn = field.StringField("dsn", field.WithRequired(true), field.WithDescription("The DSN to connect to the database"))
9+
schemas = field.StringSliceField("schemas", field.WithDefaultValue([]string{"public"}), field.WithDescription("The schemas to include in the sync"))
10+
includeColumns = field.BoolField("include-columns", field.WithDescription("Include column privileges when syncing. This can result in large amounts of data"))
11+
includeLargeObjects = field.BoolField("include-large-objects", field.WithDescription("Include large objects when syncing. This can result in large amounts of data"))
12+
)
1913

20-
// validateConfig is run after the configuration is loaded, and should return an error if it isn't valid.
21-
func validateConfig(ctx context.Context, cfg *config) error {
22-
if cfg.Dsn == "" {
23-
return fmt.Errorf("--dsn is required")
24-
}
14+
var relationships = []field.SchemaFieldRelationship{}
2515

26-
return nil
27-
}
16+
var configuration = field.NewConfiguration([]field.SchemaField{
17+
dsn, schemas, includeColumns, includeLargeObjects,
18+
}, relationships...)

cmd/baton-postgresql/main.go

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

8-
"github.com/conductorone/baton-sdk/pkg/cli"
98
"github.com/conductorone/baton-sdk/pkg/connectorbuilder"
109
"github.com/conductorone/baton-sdk/pkg/types"
1110
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
11+
"github.com/spf13/viper"
1212
"go.uber.org/zap"
1313

1414
"github.com/conductorone/baton-postgresql/pkg/connector"
15+
configschema "github.com/conductorone/baton-sdk/pkg/config"
1516
)
1617

1718
var version = "dev"
1819

1920
func main() {
2021
ctx := context.Background()
2122

22-
cfg := &config{}
23-
cmd, err := cli.NewCmd(ctx, "baton-postgresql", cfg, validateConfig, getConnector)
23+
_, cmd, err := configschema.DefineConfiguration(ctx, "baton-postgresql", getConnector, configuration)
2424
if err != nil {
2525
fmt.Fprintln(os.Stderr, err.Error())
2626
os.Exit(1)
2727
}
2828

2929
cmd.Version = version
3030

31-
cmd.PersistentFlags().String(
32-
"dsn",
33-
"",
34-
"The connection string for the PostgreSQL database ($BATON_DSN)\nexample: postgres://username:password@localhost:5432/database_name",
35-
)
36-
37-
cmd.PersistentFlags().StringSlice(
38-
"schemas",
39-
[]string{"public"},
40-
"The schemas to include in the sync. ($BATON_SCHEMAS)\nThis defaults to 'public' only.",
41-
)
42-
43-
cmd.PersistentFlags().Bool(
44-
"include-columns",
45-
false,
46-
"Include column privileges when syncing. This can result in large amounts of data. ($BATON_INCLUDE_COLUMNS)\nThis defaults to false.",
47-
)
48-
49-
cmd.PersistentFlags().Bool(
50-
"include-large-objects",
51-
false,
52-
"Include large objects when syncing. This can result in large amounts of data. ($BATON_INCLUDE_LARGE_OBJECTS)\nThis defaults to false.",
53-
)
54-
5531
err = cmd.Execute()
5632
if err != nil {
5733
fmt.Fprintln(os.Stderr, err.Error())
5834
os.Exit(1)
5935
}
6036
}
6137

62-
func getConnector(ctx context.Context, cfg *config) (types.ConnectorServer, error) {
38+
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
6339
l := ctxzap.Extract(ctx)
6440

65-
cb, err := connector.New(ctx, cfg.Dsn, cfg.Schemas, cfg.IncludeColumns, cfg.IncludeLargeObjects)
41+
cb, err := connector.New(ctx, v.GetString("dsn"), v.GetStringSlice("schemas"), v.GetBool("include-columns"), v.GetBool("include-large-objects"))
6642
if err != nil {
6743
l.Error("error creating connector", zap.Error(err))
6844
return nil, err
6945
}
7046

71-
connector, err := connectorbuilder.NewConnector(ctx, cb)
47+
newConnector, err := connectorbuilder.NewConnector(ctx, cb)
7248
if err != nil {
7349
l.Error("error creating connector", zap.Error(err))
7450
return nil, err
7551
}
7652

77-
return connector, nil
53+
return newConnector, nil
7854
}

0 commit comments

Comments
 (0)