diff --git a/plugins/providers/dataplex/client.go b/plugins/providers/dataplex/client.go index 2b8fea57..0a7afc6c 100644 --- a/plugins/providers/dataplex/client.go +++ b/plugins/providers/dataplex/client.go @@ -21,14 +21,17 @@ type policyTagClient struct { taxonomyLocation string } -func newPolicyTagClient(projectID, location string, credentialsJSON []byte) (*policyTagClient, error) { +func NewPolicyTagClient(projectID, location string, credentialsJSON []byte) (*policyTagClient, error) { ctx := context.Background() clientOptions := []option.ClientOption{ - option.WithCredentialsJSON(credentialsJSON), option.WithGRPCDialOption(grpc.WithChainUnaryInterceptor(otelgrpc.UnaryClientInterceptor())), option.WithGRPCDialOption(grpc.WithChainStreamInterceptor(otelgrpc.StreamClientInterceptor())), } + if credentialsJSON != nil { + clientOptions = append(clientOptions, option.WithCredentialsJSON(credentialsJSON)) + } + policyManager, err := datacatalog.NewPolicyTagManagerClient(ctx, clientOptions...) if err != nil { return nil, err diff --git a/plugins/providers/dataplex/client_test.go b/plugins/providers/dataplex/client_test.go new file mode 100644 index 00000000..68ed7606 --- /dev/null +++ b/plugins/providers/dataplex/client_test.go @@ -0,0 +1,26 @@ +package dataplex_test + +import ( + "testing" + + "github.com/goto/guardian/plugins/providers/dataplex" + "github.com/stretchr/testify/assert" +) + +func TestNewPolicyTagClient(t *testing.T) { + t.Run("should return error if credentials are invalid", func(t *testing.T) { + invalidCredentials := []byte("invalid-credentials") + + actualClient, actualError := dataplex.NewPolicyTagClient("test-project", "test-location", invalidCredentials) + + assert.Nil(t, actualClient) + assert.Error(t, actualError) + }) + + t.Run("should return client and nil error on success", func(t *testing.T) { + actualClient, actualError := dataplex.NewPolicyTagClient("test-project", "test-location", nil) + + assert.NotNil(t, actualClient) + assert.Nil(t, actualError) + }) +} diff --git a/plugins/providers/dataplex/provider.go b/plugins/providers/dataplex/provider.go index e27abc6a..7f5db633 100644 --- a/plugins/providers/dataplex/provider.go +++ b/plugins/providers/dataplex/provider.go @@ -201,7 +201,7 @@ func (p *Provider) getPolicyTagClient(credentials Credentials) (PolicyTagClient, if err != nil { return nil, ErrUnableToDecryptCredentials } - client, err := newPolicyTagClient(projectID, taxonomyLocation, []byte(credentials.ServiceAccountKey)) + client, err := NewPolicyTagClient(projectID, taxonomyLocation, []byte(credentials.ServiceAccountKey)) if err != nil { return nil, err }