Skip to content

Commit

Permalink
Fixes GCP components failing to authenticate
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Kolevska <[email protected]>
  • Loading branch information
elena-kolevska committed Oct 9, 2023
1 parent 1208b3e commit b6c8819
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
24 changes: 12 additions & 12 deletions .github/scripts/test-info.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ const components = {
'conformance-pubsub.aws.snssqs.terraform-destroy.sh',
sourcePkg: 'pubsub/aws/snssqs',
},
// 'pubsub.gcp.pubsub': {
// certification: true,
// requireTerraform: true,
// requireGCPCredentials: true,
// certificationSetup: 'certification-pubsub.gcp.pubsub-setup.sh',
// certificationDestroy: 'certification-pubsub.gcp.pubsub-destroy.sh',
// },
'pubsub.gcp.pubsub': {
certification: true,
requireTerraform: true,
requireGCPCredentials: true,
certificationSetup: 'certification-pubsub.gcp.pubsub-setup.sh',
certificationDestroy: 'certification-pubsub.gcp.pubsub-destroy.sh',
},
// 'pubsub.gcp.pubsub.docker': {
// conformance: true,
// conformanceSetup: 'docker-compose.sh gcp-pubsub',
Expand Down Expand Up @@ -709,11 +709,11 @@ const components = {
requireGCPCredentials: true,
conformanceSetup: 'conformance-state.gcp.firestore-setup.sh',
},
// 'state.gcp.firestore': {
// certification: true,
// requireGCPCredentials: true,
// certificationSetup: 'certification-state.gcp.firestore-setup.sh',
// },
'state.gcp.firestore': {
certification: true,
requireGCPCredentials: true,
certificationSetup: 'certification-state.gcp.firestore-setup.sh',
},
'workflows.temporal': {
conformance: true,
conformanceSetup: 'docker-compose.sh temporal',
Expand Down
7 changes: 5 additions & 2 deletions pubsub/gcp/pubsub/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func (g *GCPPubSub) getPubSubClient(ctx context.Context, metadata *metadata) (*g
var pubsubClient *gcppubsub.Client
var err error

// context.Background is used here, as this the context used to Dial the
// server in the gRPC DialPool. Callers should always call `Close` on the
// component to ensure all resources are released.
if metadata.PrivateKeyID != "" {
// TODO: validate that all auth json fields are filled
authJSON := &GCPAuthJSON{
Expand All @@ -141,7 +144,7 @@ func (g *GCPPubSub) getPubSubClient(ctx context.Context, metadata *metadata) (*g
gcpCompatibleJSON, _ := json.Marshal(authJSON)
g.logger.Debugf("Using explicit credentials for GCP")
clientOptions := option.WithCredentialsJSON(gcpCompatibleJSON)
pubsubClient, err = gcppubsub.NewClient(ctx, metadata.ProjectID, clientOptions)
pubsubClient, err = gcppubsub.NewClient(context.Background(), metadata.ProjectID, clientOptions)
if err != nil {
return pubsubClient, err
}
Expand All @@ -156,7 +159,7 @@ func (g *GCPPubSub) getPubSubClient(ctx context.Context, metadata *metadata) (*g
g.logger.Debugf("setting GCP PubSub Emulator environment variable to 'PUBSUB_EMULATOR_HOST=%s'", metadata.ConnectionEndpoint)
os.Setenv("PUBSUB_EMULATOR_HOST", metadata.ConnectionEndpoint)
}
pubsubClient, err = gcppubsub.NewClient(ctx, metadata.ProjectID)
pubsubClient, err = gcppubsub.NewClient(context.Background(), metadata.ProjectID)
if err != nil {
return pubsubClient, err
}
Expand Down
15 changes: 13 additions & 2 deletions state/gcp/firestore/firestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,21 @@ func getFirestoreMetadata(meta state.Metadata) (*firestoreMetadata, error) {
return &m, nil
}

func (f *Firestore) Close() error {
if f.client != nil {
return f.client.Close()
}

return nil
}

func getGCPClient(ctx context.Context, metadata *firestoreMetadata, l logger.Logger) (*datastore.Client, error) {
var gcpClient *datastore.Client
var err error

// context.Background is used here, as this the context used to Dial the
// server in the gRPC DialPool. Callers should always call `Close` on the
// component to ensure all resources are released.
if metadata.PrivateKeyID != "" {
var b []byte
b, err = json.Marshal(metadata)
Expand All @@ -223,7 +234,7 @@ func getGCPClient(ctx context.Context, metadata *firestoreMetadata, l logger.Log
}

opt := option.WithCredentialsJSON(b)
gcpClient, err = datastore.NewClient(ctx, metadata.ProjectID, opt)
gcpClient, err = datastore.NewClient(context.Background(), metadata.ProjectID, opt)
if err != nil {
return nil, err
}
Expand All @@ -238,7 +249,7 @@ func getGCPClient(ctx context.Context, metadata *firestoreMetadata, l logger.Log
l.Debugf("setting GCP Datastore Emulator environment variable to 'DATASTORE_EMULATOR_HOST=%s'", metadata.ConnectionEndpoint)
os.Setenv("DATASTORE_EMULATOR_HOST", metadata.ConnectionEndpoint)
}
gcpClient, err = datastore.NewClient(ctx, metadata.ProjectID)
gcpClient, err = datastore.NewClient(context.Background(), metadata.ProjectID)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit b6c8819

Please sign in to comment.