Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Config schema #11

Merged
merged 4 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,19 @@ Available Commands:
help Help about any command

Flags:
--account-id string Account ID used to generate token providing access to Zoom API. ($BATON_ACCOUNT_ID)
--account-id string required: Account ID used to generate token providing access to Zoom API. ($BATON_ACCOUNT_ID)
--client-id string The client ID used to authenticate with ConductorOne ($BATON_CLIENT_ID)
--client-secret string The client secret used to authenticate with ConductorOne ($BATON_CLIENT_SECRET)
-f, --file string The path to the c1z file to sync with ($BATON_FILE) (default "sync.c1z")
-h, --help help for baton-zoom
--log-format string The output format for logs: json, console ($BATON_LOG_FORMAT) (default "json")
--log-level string The log level: debug, info, warn, error ($BATON_LOG_LEVEL) (default "info")
-p, --provisioning This must be set in order for provisioning actions to be enabled. ($BATON_PROVISIONING)
-p, --provisioning This must be set in order for provisioning actions to be enabled ($BATON_PROVISIONING)
--skip-full-sync This must be set to skip a full sync ($BATON_SKIP_FULL_SYNC)
--ticketing This must be set to enable ticketing support ($BATON_TICKETING)
-v, --version version for baton-zoom
--zoom-client-id string Client ID used to generate token providing access to Zoom API. ($BATON_ZOOM_CLIENT_ID)
--zoom-client-secret string Client Secret used to generate token providing access to Zoom API. ($BATON_ZOOM_CLIENT_SECRET)
--zoom-client-id string required: Client ID used to generate token providing access to Zoom API. ($BATON_ZOOM_CLIENT_ID)
--zoom-client-secret string required: Client Secret used to generate token providing access to Zoom API. ($BATON_ZOOM_CLIENT_SECRET)

Use "baton-zoom [command] --help" for more information about a command.
```
28 changes: 28 additions & 0 deletions cmd/baton-zoom/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"github.com/conductorone/baton-sdk/pkg/field"
)

var (
AccountIdField = field.StringField(
"account-id",
field.WithRequired(true),
field.WithDescription("Account ID used to generate token providing access to Zoom API."),
)
ZoomClientIdField = field.StringField(
"zoom-client-id",
field.WithRequired(true),
field.WithDescription("Client ID used to generate token providing access to Zoom API."),
)
ZoomClientSecretField = field.StringField(
"zoom-client-secret",
field.WithRequired(true),
field.WithDescription("Client Secret used to generate token providing access to Zoom API."),
)
ConfigurationFields = []field.SchemaField{
AccountIdField,
ZoomClientIdField,
ZoomClientSecretField,
}
)
45 changes: 45 additions & 0 deletions cmd/baton-zoom/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"testing"

"github.com/conductorone/baton-sdk/pkg/field"
"github.com/conductorone/baton-sdk/pkg/test"
"github.com/conductorone/baton-sdk/pkg/ustrings"
)

func TestConfigs(t *testing.T) {
test.ExerciseTestCasesFromExpressions(
t,
field.NewConfiguration(ConfigurationFields),
nil,
ustrings.ParseFlags,
[]test.TestCaseFromExpression{
{
"",
false,
"empty",
},
{
"--client-id 1 --zoom-client-secret 1",
false,
"account id missing",
},
{
"--account-id 1 --zoom-client-secret 1",
false,
"client-id missing",
},
{
"--account-id 1 --zoom-client-id 1",
false,
"client id missing",
},
{
"--account-id 1 --zoom-client-id 1 --zoom-client-secret 1",
true,
"all",
},
},
)
}
19 changes: 9 additions & 10 deletions cmd/baton-zoom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,12 @@ const (
connectorName = "baton-zoom"
)

var (
accountId = field.StringField(connector.AccountId, field.WithRequired(true), field.WithDescription("Account ID used to generate token providing access to Zoom API."))
zoomClientId = field.StringField(connector.ZoomClientId, field.WithRequired(true), field.WithDescription("Client ID used to generate token providing access to Zoom API."))
zoomClientSecret = field.StringField(connector.ZoomClientSecret, field.WithRequired(true), field.WithDescription("Client Secret used to generate token providing access to Zoom API."))
configurationFields = []field.SchemaField{accountId, zoomClientId, zoomClientSecret}
)

func main() {
ctx := context.Background()
_, cmd, err := configSchema.DefineConfiguration(ctx,
connectorName,
getConnector,
field.NewConfiguration(configurationFields),
field.NewConfiguration(ConfigurationFields),
)
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
Expand All @@ -47,9 +40,15 @@ func main() {
}
}

func getConnector(ctx context.Context, cfg *viper.Viper) (types.ConnectorServer, error) {
func getConnector(ctx context.Context, v *viper.Viper) (types.ConnectorServer, error) {
l := ctxzap.Extract(ctx)
cb, err := connector.New(ctx, cfg)

cb, err := connector.New(
ctx,
v.GetString(AccountIdField.FieldName),
v.GetString(ZoomClientIdField.FieldName),
v.GetString(ZoomClientSecretField.FieldName),
)
if err != nil {
l.Error("error creating connector", zap.Error(err))
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ go 1.21
toolchain go1.22.3

require (
github.com/conductorone/baton-sdk v0.2.12
github.com/conductorone/baton-sdk v0.2.27
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/spf13/viper v1.18.2
github.com/spf13/viper v1.19.0
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
)

require (
filippo.io/age v1.1.1 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/allegro/bigcache/v3 v3.1.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.26.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
github.com/aws/aws-sdk-go-v2/config v1.27.11 // indirect
Expand Down
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk=
github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I=
github.com/aws/aws-sdk-go-v2 v1.26.1 h1:5554eUqIYVWpU0YmeeYZ0wU64H2VLBs8TlhRB2L+EkA=
github.com/aws/aws-sdk-go-v2 v1.26.1/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 h1:x6xsQXGSmW6frevwDA+vi/wqhp1ct18mVXYN08/93to=
Expand Down Expand Up @@ -50,8 +52,8 @@ github.com/benbjohnson/clock v1.3.5/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/conductorone/baton-sdk v0.2.12 h1:u5tbqpSgk/hTsZ8auwEQFqS8UxprK9k8yuJddY8hsfE=
github.com/conductorone/baton-sdk v0.2.12/go.mod h1:cg5FyUcJnD7xK5SPbHe/KNpwUVVlpHJ9rnmd3UwxSkU=
github.com/conductorone/baton-sdk v0.2.27 h1:WHme/pPfnXFkVhToceRrs0ofVozGEbomov3j9o2ltRQ=
github.com/conductorone/baton-sdk v0.2.27/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -186,8 +188,8 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
github.com/spf13/viper v1.19.0/go.mod h1:GQUN9bilAbhU/jgc1bKs99f/suXKeUMct8Adx5+Ntkg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down Expand Up @@ -357,8 +359,8 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM=
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
Expand Down
19 changes: 6 additions & 13 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/conductorone/baton-sdk/pkg/uhttp"
"github.com/conductorone/baton-zoom/pkg/zoom"
"github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap"
"github.com/spf13/viper"
)

var (
Expand Down Expand Up @@ -45,22 +44,16 @@ var (
}
)

const (
AccountId = "account-id"
ZoomClientId = "zoom-client-id"
ZoomClientSecret = "zoom-client-secret" // #nosec G101
)

type Zoom struct {
client *zoom.Client
}

func New(ctx context.Context, cfg *viper.Viper) (*Zoom, error) {
var (
accountId = cfg.GetString(AccountId)
clientId = cfg.GetString(ZoomClientId)
clientSecret = cfg.GetString(ZoomClientSecret)
)
func New(
ctx context.Context,
accountId string,
clientId string,
clientSecret string,
) (*Zoom, error) {
httpClient, err := uhttp.NewClient(ctx, uhttp.WithLogger(true, ctxzap.Extract(ctx)))
if err != nil {
return nil, err
Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/allegro/bigcache/v3/.codecov.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions vendor/github.com/allegro/bigcache/v3/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading