From ac7657e30835a9d0ad7d39b7ccba2ec32e7c70ba Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:29:18 +0000 Subject: [PATCH] Bump github.com/conductorone/baton-sdk from 0.2.35 to 0.2.41 Bumps [github.com/conductorone/baton-sdk](https://github.com/conductorone/baton-sdk) from 0.2.35 to 0.2.41. - [Release notes](https://github.com/conductorone/baton-sdk/releases) - [Commits](https://github.com/conductorone/baton-sdk/compare/v0.2.35...v0.2.41) --- updated-dependencies: - dependency-name: github.com/conductorone/baton-sdk dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../baton-sdk/pkg/config/config.go | 17 +++++- .../baton-sdk/pkg/logging/logging.go | 8 +++ .../baton-sdk/pkg/pagination/pagination.go | 8 +++ .../conductorone/baton-sdk/pkg/sdk/version.go | 2 +- .../baton-sdk/pkg/uhttp/wrapper.go | 60 ++++++++++++++++--- vendor/modules.txt | 2 +- 8 files changed, 87 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index b3e17512..b3fd9e6f 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 toolchain go1.22.3 require ( - github.com/conductorone/baton-sdk v0.2.35 + github.com/conductorone/baton-sdk v0.2.41 github.com/go-ldap/ldap/v3 v3.4.8 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/jackc/puddle/v2 v2.2.1 diff --git a/go.sum b/go.sum index fb8a8b1b..462ac32f 100644 --- a/go.sum +++ b/go.sum @@ -56,8 +56,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.35 h1:aSdNvlM5HMti8WdhotrXTHWs+b+BmSqMxtGwsSUFxjY= -github.com/conductorone/baton-sdk v0.2.35/go.mod h1:hmd/Oz3DPIKD+9QmkusZaA18ZoiinnTDdrxh2skcdUc= +github.com/conductorone/baton-sdk v0.2.41 h1:JvEDbiLozo6GaikyUycKTPKkpqhIDFlMD/122oDlrDg= +github.com/conductorone/baton-sdk v0.2.41/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= diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/config/config.go b/vendor/github.com/conductorone/baton-sdk/pkg/config/config.go index 291192df..d2d4f249 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/config/config.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/config/config.go @@ -43,13 +43,24 @@ func DefineConfiguration( v.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) v.AutomaticEnv() + confschema := schema + confschema.Fields = append(field.DefaultFields, confschema.Fields...) + // Ensure unique fields + uniqueFields := make(map[string]field.SchemaField) + for _, f := range confschema.Fields { + uniqueFields[f.FieldName] = f + } + confschema.Fields = make([]field.SchemaField, 0, len(uniqueFields)) + for _, f := range uniqueFields { + confschema.Fields = append(confschema.Fields, f) + } // setup CLI with cobra mainCMD := &cobra.Command{ Use: connectorName, Short: connectorName, SilenceErrors: true, SilenceUsage: true, - RunE: cli.MakeMainCommand(ctx, connectorName, v, schema, connector, options...), + RunE: cli.MakeMainCommand(ctx, connectorName, v, confschema, connector, options...), } // set persistent flags only on the main subcommand err = setFlagsAndConstraints(mainCMD, field.NewConfiguration(field.DefaultFields, field.DefaultRelationships...)) @@ -67,7 +78,7 @@ func DefineConfiguration( Use: "_connector-service", Short: "Start the connector service", Hidden: true, - RunE: cli.MakeGRPCServerCommand(ctx, connectorName, v, schema, connector), + RunE: cli.MakeGRPCServerCommand(ctx, connectorName, v, confschema, connector), } err = setFlagsAndConstraints(grpcServerCmd, schema) if err != nil { @@ -78,7 +89,7 @@ func DefineConfiguration( capabilitiesCmd := &cobra.Command{ Use: "capabilities", Short: "Get connector capabilities", - RunE: cli.MakeCapabilitiesCommand(ctx, connectorName, v, schema, connector), + RunE: cli.MakeCapabilitiesCommand(ctx, connectorName, v, confschema, connector), } err = setFlagsAndConstraints(capabilitiesCmd, schema) if err != nil { diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/logging/logging.go b/vendor/github.com/conductorone/baton-sdk/pkg/logging/logging.go index 50c6fe36..33578389 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/logging/logging.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/logging/logging.go @@ -43,6 +43,14 @@ func WithOutputPaths(paths []string) Option { } } +// WithInitialFields allows the logger to be configured with static fields at creation time. +// This is useful for setting fields that are constant across all log messages. +func WithInitialFields(fields map[string]interface{}) Option { + return func(c *zap.Config) { + c.InitialFields = fields + } +} + // Init creates a new zap logger and attaches it to the provided context. func Init(ctx context.Context, opts ...Option) (context.Context, error) { zc := zap.NewProductionConfig() diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/pagination/pagination.go b/vendor/github.com/conductorone/baton-sdk/pkg/pagination/pagination.go index 74082b65..a714ca99 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/pagination/pagination.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/pagination/pagination.go @@ -93,6 +93,14 @@ func (pb *Bag) Next(pageToken string) error { // Next pops the current token, and pushes a copy of it with an updated page token. func (pb *Bag) NextToken(pageToken string) (string, error) { + // assume that `pb` was passed an empty token + if pb.currentState == nil { + pb.currentState = &PageState{ + Token: pageToken, + } + return pb.Marshal() + } + st := pb.pop() if st == nil { return "", fmt.Errorf("no active page state") diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go index ed9800c8..7309ce1b 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/sdk/version.go @@ -1,3 +1,3 @@ package sdk -const Version = "v0.2.34" +const Version = "v0.2.40" diff --git a/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go b/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go index 377ca9e1..fb465719 100644 --- a/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go +++ b/vendor/github.com/conductorone/baton-sdk/pkg/uhttp/wrapper.go @@ -12,13 +12,16 @@ import ( "net/url" "os" "strconv" + "time" - v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" - "github.com/conductorone/baton-sdk/pkg/ratelimit" "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" + uRateLimit "go.uber.org/ratelimit" "go.uber.org/zap" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2" + "github.com/conductorone/baton-sdk/pkg/ratelimit" ) const ( @@ -39,6 +42,31 @@ type WrapperResponse struct { StatusCode int } +type rateLimiterOption struct { + rate int + per time.Duration +} + +func (o rateLimiterOption) Apply(c *BaseHttpClient) { + opts := []uRateLimit.Option{} + if o.per > 0 { + opts = append(opts, uRateLimit.Per(o.per)) + } + c.rateLimiter = uRateLimit.New(o.rate, opts...) +} + +// WithRateLimiter returns a WrapperOption that sets the rate limiter for the http client. +// `rate` is the number of requests allowed per `per` duration. +// `per` is the duration in which the rate limit is enforced. +// Example: WithRateLimiter(10, time.Second) will allow 10 requests per second. +func WithRateLimiter(rate int, per time.Duration) WrapperOption { + return rateLimiterOption{rate: rate, per: per} +} + +type WrapperOption interface { + Apply(*BaseHttpClient) +} + // Keep a handle on all caches so we can clear them later. var caches []GoCache @@ -64,6 +92,7 @@ type ( BaseHttpClient struct { HttpClient *http.Client baseHttpCache GoCache + rateLimiter uRateLimit.Limiter } DoOption func(resp *WrapperResponse) error @@ -77,9 +106,9 @@ type ( } ) -func NewBaseHttpClient(httpClient *http.Client) *BaseHttpClient { +func NewBaseHttpClient(httpClient *http.Client, opts ...WrapperOption) *BaseHttpClient { ctx := context.TODO() - client, err := NewBaseHttpClientWithContext(ctx, httpClient) + client, err := NewBaseHttpClientWithContext(ctx, httpClient, opts...) if err != nil { return nil } @@ -102,7 +131,7 @@ func getCacheTTL() int32 { return int32(cacheTTL) } -func NewBaseHttpClientWithContext(ctx context.Context, httpClient *http.Client) (*BaseHttpClient, error) { +func NewBaseHttpClientWithContext(ctx context.Context, httpClient *http.Client, opts ...WrapperOption) (*BaseHttpClient, error) { l := ctxzap.Extract(ctx) disableCache, err := strconv.ParseBool(os.Getenv("BATON_DISABLE_HTTP_CACHE")) if err != nil { @@ -134,10 +163,16 @@ func NewBaseHttpClientWithContext(ctx context.Context, httpClient *http.Client) } caches = append(caches, cache) - return &BaseHttpClient{ + baseClient := &BaseHttpClient{ HttpClient: httpClient, baseHttpCache: cache, - }, nil + } + + for _, opt := range opts { + opt.Apply(baseClient) + } + + return baseClient, nil } // WithJSONResponse is a wrapper that marshals the returned response body into @@ -254,6 +289,12 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo resp *http.Response ) l := ctxzap.Extract(req.Context()) + + // If a rate limiter is defined, take a token before making the request. + if c.rateLimiter != nil { + c.rateLimiter.Take() + } + if req.Method == http.MethodGet { cacheKey, err = CreateCacheKey(req) if err != nil { @@ -290,7 +331,10 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - return nil, err + if len(body) > 0 { + resp.Body = io.NopCloser(bytes.NewBuffer(body)) + } + return resp, err } // Replace resp.Body with a no-op closer so nobody has to worry about closing the reader. diff --git a/vendor/modules.txt b/vendor/modules.txt index 97c0d4fb..b8908b3a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -147,7 +147,7 @@ github.com/aws/smithy-go/waiter # github.com/benbjohnson/clock v1.3.5 ## explicit; go 1.15 github.com/benbjohnson/clock -# github.com/conductorone/baton-sdk v0.2.35 +# github.com/conductorone/baton-sdk v0.2.41 ## explicit; go 1.21 github.com/conductorone/baton-sdk/internal/connector github.com/conductorone/baton-sdk/pb/c1/c1z/v1