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

chore: Update cloud-api usage #2045

Merged
merged 1 commit into from
Mar 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/cerbos/cerbos-sdk-go v0.2.3
github.com/cerbos/cerbos/api/genpb v0.34.0
github.com/cerbos/cloud-api v0.1.17
github.com/cerbos/cloud-api v0.1.18-0.20240311082340-cd73b618b1fd
github.com/cespare/xxhash v1.1.0
github.com/cespare/xxhash/v2 v2.2.0
github.com/cloudflare/certinel v0.4.1
Expand Down Expand Up @@ -122,7 +122,7 @@ require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240221180331-f05a6f4403ce.1 // indirect
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1 // indirect
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ atomicgo.dev/schedule v0.1.0 h1:nTthAbhZS5YZmgYbb2+DH8uQIZcTlIrd4eYr3UQxEjs=
atomicgo.dev/schedule v0.1.0/go.mod h1:xeUa3oAkiuHYh8bKiQBRojqAMq3PXXbJujjb0hw8pEU=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240221180331-f05a6f4403ce.1 h1:AmmAwHbvaeOIxDKG2+aTn5C36HjmFIMkrdTp49rp80Q=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.32.0-20240221180331-f05a6f4403ce.1/go.mod h1:tiTMKD8j6Pd/D2WzREoweufjzaJKHZg35f/VGcZ2v3I=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.33.0-20240221180331-f05a6f4403ce.1/go.mod h1:Tgn5bgL220vkFOI0KPStlcClPeOJzAv4uT+V8JXGUnw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.112.0 h1:tpFCD7hpHFlQ8yPwT3x+QeXqc2T6+n6T+hmABHfDUSM=
cloud.google.com/go v0.112.0/go.mod h1:3jEEVwZ/MHU4djK5t5RHuKOA/GbLddgTdVubX1qnPD4=
Expand Down Expand Up @@ -160,6 +161,8 @@ github.com/cerbos/cerbos/api/genpb v0.34.0 h1:HY8k9HVHv000EKU61KrhAia5TmjW4sX2AX
github.com/cerbos/cerbos/api/genpb v0.34.0/go.mod h1:KEUMaRkMsCvEcOI8aptMFscKh6H2bfWgjjjSmRWKg8g=
github.com/cerbos/cloud-api v0.1.17 h1:DiiVhrkGQVPfRSipqAOhhmPXwGDjuy8KVE/G5D9ZAyA=
github.com/cerbos/cloud-api v0.1.17/go.mod h1:iXJaWIfuho/FpIhYyonsLDLiDBqNghvj1hgOPlAXCQE=
github.com/cerbos/cloud-api v0.1.18-0.20240311082340-cd73b618b1fd h1:bGjPBhNwtsKxSibrkAtF9y/nwonylgcXRL7kJwHG/48=
github.com/cerbos/cloud-api v0.1.18-0.20240311082340-cd73b618b1fd/go.mod h1:enuBEz4y/96jl0ejsd91H2kWgda5ausOqRAeMH6e7tw=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down
29 changes: 16 additions & 13 deletions internal/storage/bundle/remote_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cerbos/cerbos/internal/observability/metrics"
"github.com/cerbos/cerbos/internal/storage"
"github.com/cerbos/cerbos/internal/util"
"github.com/cerbos/cloud-api/base"
cloudapi "github.com/cerbos/cloud-api/bundle"
"github.com/cerbos/cloud-api/credentials"
"github.com/go-logr/zapr"
Expand Down Expand Up @@ -97,18 +98,20 @@ func (s *RemoteSource) Init(ctx context.Context) error {
}

clientConf := cloudapi.ClientConf{
Logger: zapr.NewLogger(s.log),
PDPIdentifier: pdpID,
TLS: tlsConf,
Credentials: s.credentials,
APIEndpoint: s.conf.Remote.Connection.APIEndpoint,
BootstrapEndpoint: s.conf.Remote.Connection.BootstrapEndpoint,
RetryWaitMin: s.conf.Remote.Connection.MinRetryWait,
RetryWaitMax: s.conf.Remote.Connection.MaxRetryWait,
RetryMaxAttempts: int(s.conf.Remote.Connection.NumRetries),
HeartbeatInterval: s.conf.Remote.Connection.HeartbeatInterval,
CacheDir: s.conf.Remote.CacheDir,
TempDir: s.conf.Remote.TempDir,
ClientConf: base.ClientConf{
Logger: zapr.NewLogger(s.log),
PDPIdentifier: pdpID,
TLS: tlsConf,
Credentials: s.credentials,
APIEndpoint: s.conf.Remote.Connection.APIEndpoint,
BootstrapEndpoint: s.conf.Remote.Connection.BootstrapEndpoint,
RetryWaitMin: s.conf.Remote.Connection.MinRetryWait,
RetryWaitMax: s.conf.Remote.Connection.MaxRetryWait,
RetryMaxAttempts: int(s.conf.Remote.Connection.NumRetries),
HeartbeatInterval: s.conf.Remote.Connection.HeartbeatInterval,
},
CacheDir: s.conf.Remote.CacheDir,
TempDir: s.conf.Remote.TempDir,
}

client, err := cloudapi.NewClient(clientConf)
Expand Down Expand Up @@ -311,7 +314,7 @@ func (s *RemoteSource) startWatch(ctx context.Context) (time.Duration, error) {
s.mu.Unlock()
incEventMetric("error")

if errors.Is(err, cloudapi.ErrAuthenticationFailed) {
if errors.Is(err, base.ErrAuthenticationFailed) {
s.log.Error("Failed to authenticate to Cerbos Hub", zap.Error(err))
s.removeBundle(false)
return backoff.Permanent(err)
Expand Down
3 changes: 2 additions & 1 deletion internal/storage/bundle/remote_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cerbos/cerbos/internal/storage/bundle"
"github.com/cerbos/cerbos/internal/test"
"github.com/cerbos/cerbos/internal/test/mocks"
"github.com/cerbos/cloud-api/base"
cloudapi "github.com/cerbos/cloud-api/bundle"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -115,7 +116,7 @@ func TestRemoteSource(t *testing.T) {
Run(func(_ context.Context, _ string) {
close(callsDone)
}).
Return(nil, cloudapi.ErrAuthenticationFailed).
Return(nil, base.ErrAuthenticationFailed).
Once()

rs, err := bundle.NewRemoteSource(mkConf(t, false))
Expand Down