@causa/workspace-google 0.3.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/backfilling/bigquery.d.ts +53 -0
- package/dist/backfilling/bigquery.js +99 -0
- package/dist/backfilling/index.d.ts +2 -0
- package/dist/backfilling/index.js +2 -0
- package/dist/backfilling/pubsub.d.ts +34 -0
- package/dist/backfilling/pubsub.js +63 -0
- package/dist/configurations/google.d.ts +81 -0
- package/dist/functions/emulator/index.d.ts +10 -0
- package/dist/functions/emulator/index.js +10 -0
- package/dist/functions/{emulator-start-firebase-storage.js → emulator/start-firebase-storage.js} +4 -4
- package/dist/functions/{emulator-start-firestore.js → emulator/start-firestore.js} +3 -3
- package/dist/functions/{emulator-start-identity-platform.js → emulator/start-identity-platform.js} +3 -3
- package/dist/functions/{emulator-start-pubsub.js → emulator/start-pubsub.js} +3 -3
- package/dist/functions/{emulator-start-spanner.js → emulator/start-spanner.js} +5 -5
- package/dist/functions/{emulator-stop-firebase-storage.js → emulator/stop-firebase-storage.js} +1 -1
- package/dist/functions/{emulator-stop-firestore.js → emulator/stop-firestore.js} +1 -1
- package/dist/functions/{emulator-stop-identity-platform.js → emulator/stop-identity-platform.js} +1 -1
- package/dist/functions/{emulator-stop-pubsub.js → emulator/stop-pubsub.js} +1 -1
- package/dist/functions/{emulator-stop-spanner.js → emulator/stop-spanner.js} +1 -1
- package/dist/functions/event-topic/broker-create-topic-pubsub.d.ts +11 -0
- package/dist/functions/event-topic/broker-create-topic-pubsub.js +27 -0
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.d.ts +11 -0
- package/dist/functions/event-topic/broker-create-trigger-cloud-run.js +38 -0
- package/dist/functions/event-topic/broker-delete-topic-pubsub.d.ts +10 -0
- package/dist/functions/event-topic/broker-delete-topic-pubsub.js +26 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.d.ts +11 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-cloud-run-invoker-role.js +29 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.d.ts +10 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-pubsub-subscription.js +31 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.d.ts +11 -0
- package/dist/functions/event-topic/broker-delete-trigger-resource-service-account.js +28 -0
- package/dist/functions/event-topic/broker-get-topic-id-pubsub.d.ts +10 -0
- package/dist/functions/event-topic/broker-get-topic-id-pubsub.js +16 -0
- package/dist/functions/event-topic/broker-publish-events-google.d.ts +17 -0
- package/dist/functions/event-topic/broker-publish-events-google.js +45 -0
- package/dist/functions/event-topic/index.d.ts +8 -0
- package/dist/functions/event-topic/index.js +8 -0
- package/dist/functions/{google-app-check-generate-token.js → google-app-check/generate-token.js} +2 -2
- package/dist/functions/google-app-check/index.d.ts +1 -0
- package/dist/functions/google-app-check/index.js +1 -0
- package/dist/functions/google-firebase-storage/index.d.ts +1 -0
- package/dist/functions/google-firebase-storage/index.js +1 -0
- package/dist/functions/{google-firebase-storage-merge-rules.d.ts → google-firebase-storage/merge-rules.d.ts} +1 -1
- package/dist/functions/{google-firebase-storage-merge-rules.js → google-firebase-storage/merge-rules.js} +2 -2
- package/dist/functions/google-firestore/index.d.ts +1 -0
- package/dist/functions/google-firestore/index.js +1 -0
- package/dist/functions/{google-firestore-merge-rules.d.ts → google-firestore/merge-rules.d.ts} +1 -1
- package/dist/functions/{google-firestore-merge-rules.js → google-firestore/merge-rules.js} +2 -2
- package/dist/functions/{google-identity-platform-generate-custom-token.js → google-identity-platform/generate-custom-token.js} +1 -1
- package/dist/functions/{google-identity-platform-generate-token.js → google-identity-platform/generate-token.js} +3 -3
- package/dist/functions/google-identity-platform/index.d.ts +2 -0
- package/dist/functions/google-identity-platform/index.js +2 -0
- package/dist/functions/google-pubsub/index.d.ts +1 -0
- package/dist/functions/google-pubsub/index.js +1 -0
- package/dist/functions/google-pubsub/write-topics.d.ts +22 -0
- package/dist/functions/google-pubsub/write-topics.js +80 -0
- package/dist/functions/{google-services-enable.d.ts → google-services/enable.d.ts} +1 -1
- package/dist/functions/{google-services-enable.js → google-services/enable.js} +1 -1
- package/dist/functions/google-services/index.d.ts +1 -0
- package/dist/functions/google-services/index.js +1 -0
- package/dist/functions/google-spanner/index.d.ts +2 -0
- package/dist/functions/google-spanner/index.js +2 -0
- package/dist/functions/google-spanner/write-databases.d.ts +22 -0
- package/dist/functions/google-spanner/write-databases.js +73 -0
- package/dist/functions/index.js +12 -22
- package/dist/functions/project/index.d.ts +3 -0
- package/dist/functions/project/index.js +3 -0
- package/dist/functions/{project-push-artefact-cloud-functions.js → project/push-artefact-cloud-functions.js} +1 -1
- package/dist/functions/{secret-fetch-secret-manager.js → secret/fetch-secret-manager.js} +1 -1
- package/dist/functions/secret/index.d.ts +1 -0
- package/dist/functions/secret/index.js +1 -0
- package/dist/services/bigquery.d.ts +16 -0
- package/dist/services/bigquery.js +19 -0
- package/dist/services/cloud-run-pubsub-trigger.d.ts +101 -0
- package/dist/services/cloud-run-pubsub-trigger.js +177 -0
- package/dist/services/cloud-run.d.ts +35 -0
- package/dist/services/cloud-run.js +72 -0
- package/dist/services/iam.d.ts +43 -0
- package/dist/services/iam.js +65 -0
- package/dist/services/index.d.ts +6 -0
- package/dist/services/index.js +6 -0
- package/dist/services/pubsub.d.ts +41 -0
- package/dist/services/pubsub.js +62 -0
- package/dist/services/resource-manager.d.ts +18 -0
- package/dist/services/resource-manager.js +35 -0
- package/package.json +26 -22
- /package/dist/functions/{emulator-start-firebase-storage.d.ts → emulator/start-firebase-storage.d.ts} +0 -0
- /package/dist/functions/{emulator-start-firestore.d.ts → emulator/start-firestore.d.ts} +0 -0
- /package/dist/functions/{emulator-start-identity-platform.d.ts → emulator/start-identity-platform.d.ts} +0 -0
- /package/dist/functions/{emulator-start-pubsub.d.ts → emulator/start-pubsub.d.ts} +0 -0
- /package/dist/functions/{emulator-start-spanner.d.ts → emulator/start-spanner.d.ts} +0 -0
- /package/dist/functions/{emulator-stop-firebase-storage.d.ts → emulator/stop-firebase-storage.d.ts} +0 -0
- /package/dist/functions/{emulator-stop-firestore.d.ts → emulator/stop-firestore.d.ts} +0 -0
- /package/dist/functions/{emulator-stop-identity-platform.d.ts → emulator/stop-identity-platform.d.ts} +0 -0
- /package/dist/functions/{emulator-stop-pubsub.d.ts → emulator/stop-pubsub.d.ts} +0 -0
- /package/dist/functions/{emulator-stop-spanner.d.ts → emulator/stop-spanner.d.ts} +0 -0
- /package/dist/functions/{google-app-check-generate-token.d.ts → google-app-check/generate-token.d.ts} +0 -0
- /package/dist/functions/{google-identity-platform-generate-custom-token.d.ts → google-identity-platform/generate-custom-token.d.ts} +0 -0
- /package/dist/functions/{google-identity-platform-generate-token.d.ts → google-identity-platform/generate-token.d.ts} +0 -0
- /package/dist/functions/{google-spanner-list-databases.d.ts → google-spanner/list-databases.d.ts} +0 -0
- /package/dist/functions/{google-spanner-list-databases.js → google-spanner/list-databases.js} +0 -0
- /package/dist/functions/{project-get-artefact-destination-cloud-functions.d.ts → project/get-artefact-destination-cloud-functions.d.ts} +0 -0
- /package/dist/functions/{project-get-artefact-destination-cloud-functions.js → project/get-artefact-destination-cloud-functions.js} +0 -0
- /package/dist/functions/{project-get-artefact-destination-cloud-run.d.ts → project/get-artefact-destination-cloud-run.d.ts} +0 -0
- /package/dist/functions/{project-get-artefact-destination-cloud-run.js → project/get-artefact-destination-cloud-run.js} +0 -0
- /package/dist/functions/{project-push-artefact-cloud-functions.d.ts → project/push-artefact-cloud-functions.d.ts} +0 -0
- /package/dist/functions/{secret-fetch-secret-manager.d.ts → secret/fetch-secret-manager.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -35,6 +35,12 @@ The following emulators are implemented:
|
|
|
35
35
|
- `google.pubSub`: The Pub/Sub emulator from the `gcloud` tools. It automatically creates the topics for all event topics found in the Causa workspace. `events.broker` must be set to `google.pubSub` for this.
|
|
36
36
|
- `google.spanner`: The Spanner emulator. It automatically creates all the Spanner databases defined in the Causa workspace, and sets up their DDLs. See the `google.spanner` [configuration](./src/configurations/google.ts) for more details.
|
|
37
37
|
|
|
38
|
+
### Backfilling
|
|
39
|
+
|
|
40
|
+
Backfilling is supported when `google.pubSub` is set as the `events.broker`. Temporary triggers can be created for Cloud Run services, by referencing them using the format `[[projects/<projectId>/]locations/<location>/]services/<name>/path-to-trigger`.
|
|
41
|
+
|
|
42
|
+
When no source is specified, the default is to fetch events to backfill from the BigQuery dataset configured in `google.pubSub.bigQueryStorage`. A custom BigQuery table can also be set as source using the `bq://<projectId>.<datasetId>.<tableId>` format. It should have the `data` and `attributes` columns.
|
|
43
|
+
|
|
38
44
|
### Secrets backend
|
|
39
45
|
|
|
40
46
|
This module implements the `google.secretManager` secret backend, allowing fetching secrets from the Google Secret Manager service. Here are some example of how secrets with the `google.secretManager` backend should be defined:
|
|
@@ -114,3 +120,11 @@ The Google module provides several infrastructure processors, which can be used
|
|
|
114
120
|
[GoogleServicesEnable](./src/functions/google-services-enable.ts) is the same underlying function as the `cs google enableServices` command. It enables GCP services before preparing or deploying the infrastructure.
|
|
115
121
|
|
|
116
122
|
Although infrastructure as code tools usually expose this feature as well (e.g. the [`google_project_service`](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_project_service) Terraform resource), it might be more convenient to enable all the required services before running those tools. It avoids having to define dependencies between the services and all the actual resources being deployed.
|
|
123
|
+
|
|
124
|
+
### `GoogleSpannerWriteDatabases`
|
|
125
|
+
|
|
126
|
+
[GoogleSpannerWriteDatabases](./src/functions/google-spanner-write-databases.ts) writes a configuration file for each Spanner database, such that it can be picked up by the Causa Spanner Terraform module. This allows automatic setup of Spanner databases and their DDLs.
|
|
127
|
+
|
|
128
|
+
### `GooglePubSubWriteTopics`
|
|
129
|
+
|
|
130
|
+
[GooglePubSubWriteTopics](./src/functions/google-pubsub-write-topics.ts) writes a configuration file for each event topic, such that it can be picked up by the Causa Pub/Sub Terraform module. This allows automatic setup of Pub/Sub topics, and optionally of the corresponding BigQuery tables.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { BackfillEvent, BackfillEventsSource } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* An events source that reads events from a BigQuery table.
|
|
5
|
+
*/
|
|
6
|
+
export declare class BigQueryEventsSource implements BackfillEventsSource {
|
|
7
|
+
readonly tableId: string;
|
|
8
|
+
readonly filter?: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The BigQuery client.
|
|
11
|
+
*/
|
|
12
|
+
private readonly bigQuery;
|
|
13
|
+
/**
|
|
14
|
+
* The job from which the events are read.
|
|
15
|
+
*/
|
|
16
|
+
private job;
|
|
17
|
+
/**
|
|
18
|
+
* The request for the next page of results.
|
|
19
|
+
* If this is `null` after initializing the job, there are no more results.
|
|
20
|
+
*/
|
|
21
|
+
private nextPageRequest;
|
|
22
|
+
/**
|
|
23
|
+
* The logger.
|
|
24
|
+
*/
|
|
25
|
+
private readonly logger;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new events source that reads events from a BigQuery table.
|
|
28
|
+
*
|
|
29
|
+
* @param context The {@link WorkspaceContext}.
|
|
30
|
+
* @param tableId The ID of the BigQuery table from which the events should be read.
|
|
31
|
+
* @param filter A SQL boolean expression that filters the events from the table.
|
|
32
|
+
*/
|
|
33
|
+
constructor(context: WorkspaceContext, tableId: string, filter?: string | undefined);
|
|
34
|
+
/**
|
|
35
|
+
* Creates a BigQuery job that reads the events from the table.
|
|
36
|
+
* The `data` and `attributes` columns are read to get the corresponding event properties.
|
|
37
|
+
* If a filter was specified, it is applied to the query as a where clause.
|
|
38
|
+
*
|
|
39
|
+
* @returns The BigQuery job that reads the events from the table.
|
|
40
|
+
*/
|
|
41
|
+
private createJob;
|
|
42
|
+
getBatch(): Promise<BackfillEvent[] | null>;
|
|
43
|
+
dispose(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Tries to create a new {@link BigQueryEventsSource} from the given source string.
|
|
46
|
+
*
|
|
47
|
+
* @param context The {@link WorkspaceContext}.
|
|
48
|
+
* @param source The string representing the source, in the format `bq://<projectId>.<datasetId>.<tableId>`.
|
|
49
|
+
* @param filter A SQL boolean expression that filters the events from the table.
|
|
50
|
+
* @returns A new {@link BigQueryEventsSource} if the source string is valid, otherwise `null`.
|
|
51
|
+
*/
|
|
52
|
+
static fromSourceAndFilter(context: WorkspaceContext, source: string, filter?: string): Promise<BigQueryEventsSource | null>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BigQueryService } from '../services/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The number of rows (events) in a single batch.
|
|
4
|
+
*/
|
|
5
|
+
const BIGQUERY_MAX_RESULTS = 10000;
|
|
6
|
+
/**
|
|
7
|
+
* An events source that reads events from a BigQuery table.
|
|
8
|
+
*/
|
|
9
|
+
export class BigQueryEventsSource {
|
|
10
|
+
tableId;
|
|
11
|
+
filter;
|
|
12
|
+
/**
|
|
13
|
+
* The BigQuery client.
|
|
14
|
+
*/
|
|
15
|
+
bigQuery;
|
|
16
|
+
/**
|
|
17
|
+
* The job from which the events are read.
|
|
18
|
+
*/
|
|
19
|
+
job = null;
|
|
20
|
+
/**
|
|
21
|
+
* The request for the next page of results.
|
|
22
|
+
* If this is `null` after initializing the job, there are no more results.
|
|
23
|
+
*/
|
|
24
|
+
nextPageRequest = null;
|
|
25
|
+
/**
|
|
26
|
+
* The logger.
|
|
27
|
+
*/
|
|
28
|
+
logger;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new events source that reads events from a BigQuery table.
|
|
31
|
+
*
|
|
32
|
+
* @param context The {@link WorkspaceContext}.
|
|
33
|
+
* @param tableId The ID of the BigQuery table from which the events should be read.
|
|
34
|
+
* @param filter A SQL boolean expression that filters the events from the table.
|
|
35
|
+
*/
|
|
36
|
+
constructor(context, tableId, filter) {
|
|
37
|
+
this.tableId = tableId;
|
|
38
|
+
this.filter = filter;
|
|
39
|
+
this.bigQuery = context.service(BigQueryService).bigQuery;
|
|
40
|
+
this.logger = context.logger;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a BigQuery job that reads the events from the table.
|
|
44
|
+
* The `data` and `attributes` columns are read to get the corresponding event properties.
|
|
45
|
+
* If a filter was specified, it is applied to the query as a where clause.
|
|
46
|
+
*
|
|
47
|
+
* @returns The BigQuery job that reads the events from the table.
|
|
48
|
+
*/
|
|
49
|
+
async createJob() {
|
|
50
|
+
let query = `
|
|
51
|
+
SELECT
|
|
52
|
+
data,
|
|
53
|
+
attributes,
|
|
54
|
+
FROM
|
|
55
|
+
\`${this.tableId}\``;
|
|
56
|
+
if (this.filter) {
|
|
57
|
+
query += `
|
|
58
|
+
WHERE
|
|
59
|
+
(${this.filter})`;
|
|
60
|
+
}
|
|
61
|
+
this.logger.debug(`Creating BigQuery job from query '${query}'.`);
|
|
62
|
+
const [job] = await this.bigQuery.createQueryJob(query);
|
|
63
|
+
return job;
|
|
64
|
+
}
|
|
65
|
+
async getBatch() {
|
|
66
|
+
if (!this.job) {
|
|
67
|
+
this.job = await this.createJob();
|
|
68
|
+
}
|
|
69
|
+
else if (!this.nextPageRequest) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const [rows, nextPageRequest] = await this.job.getQueryResults(this.nextPageRequest ?? {
|
|
73
|
+
autoPaginate: false,
|
|
74
|
+
maxResults: BIGQUERY_MAX_RESULTS,
|
|
75
|
+
});
|
|
76
|
+
this.nextPageRequest = nextPageRequest ?? null;
|
|
77
|
+
return rows.map((row) => ({
|
|
78
|
+
data: Buffer.from(row.data),
|
|
79
|
+
attributes: JSON.parse(row.attributes),
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
async dispose() { }
|
|
83
|
+
/**
|
|
84
|
+
* Tries to create a new {@link BigQueryEventsSource} from the given source string.
|
|
85
|
+
*
|
|
86
|
+
* @param context The {@link WorkspaceContext}.
|
|
87
|
+
* @param source The string representing the source, in the format `bq://<projectId>.<datasetId>.<tableId>`.
|
|
88
|
+
* @param filter A SQL boolean expression that filters the events from the table.
|
|
89
|
+
* @returns A new {@link BigQueryEventsSource} if the source string is valid, otherwise `null`.
|
|
90
|
+
*/
|
|
91
|
+
static async fromSourceAndFilter(context, source, filter) {
|
|
92
|
+
const match = source.match(/^bq:\/\/(?<tableId>.+)$/);
|
|
93
|
+
if (!match?.groups?.tableId) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const tableId = match.groups.tableId;
|
|
97
|
+
return new BigQueryEventsSource(context, tableId, filter);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { BackfillEvent, BackfillEventPublisher } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* A publisher that publishes events to backfill to a Pub/Sub topic.
|
|
5
|
+
*/
|
|
6
|
+
export declare class PubSubBackfillEventPublisher extends BackfillEventPublisher {
|
|
7
|
+
readonly topicId: string;
|
|
8
|
+
/**
|
|
9
|
+
* The actual publisher, which handles batching and flow control.
|
|
10
|
+
*/
|
|
11
|
+
private readonly publisher;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link PubSubBackfillEventPublisher}.
|
|
14
|
+
*
|
|
15
|
+
* @param context The {@link WorkspaceContext}.
|
|
16
|
+
* @param topicId The ID of the Pub/Sub topic to publish to.
|
|
17
|
+
* This should be a full Pub/Sub topic ID, e.g. `projects/<projectId>/topics/<topicId>`.
|
|
18
|
+
*/
|
|
19
|
+
constructor(context: WorkspaceContext, topicId: string);
|
|
20
|
+
/**
|
|
21
|
+
* Publishes an event to the Pub/Sub topic.
|
|
22
|
+
* Publishing actually occurs asynchronously. {@link PubSubBackfillEventPublisher.flush} must be called to wait for
|
|
23
|
+
* all events to be published.
|
|
24
|
+
*
|
|
25
|
+
* @param event The event to publish.
|
|
26
|
+
* @returns A promise that resolves when the publisher has caught up with publishing, or `null` if other events can be
|
|
27
|
+
* published immediately.
|
|
28
|
+
*/
|
|
29
|
+
protected publishEvent(event: BackfillEvent): Promise<void> | null;
|
|
30
|
+
/**
|
|
31
|
+
* Waits for all events to be published.
|
|
32
|
+
*/
|
|
33
|
+
protected flush(): Promise<void>;
|
|
34
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { BackfillEventPublisher } from '@causa/workspace-core';
|
|
2
|
+
import { PubSubService } from '../services/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Options when publishing events in batches to Pub/Sub.
|
|
5
|
+
*/
|
|
6
|
+
const PUBLISH_OPTIONS = {
|
|
7
|
+
flowControlOptions: {
|
|
8
|
+
maxOutstandingBytes: 512 * 1024 * 1024,
|
|
9
|
+
maxOutstandingMessages: 100000,
|
|
10
|
+
},
|
|
11
|
+
batching: {
|
|
12
|
+
maxBytes: 10 * 1024 * 1024,
|
|
13
|
+
maxMessages: 1000,
|
|
14
|
+
maxMilliseconds: 1000,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A publisher that publishes events to backfill to a Pub/Sub topic.
|
|
19
|
+
*/
|
|
20
|
+
export class PubSubBackfillEventPublisher extends BackfillEventPublisher {
|
|
21
|
+
topicId;
|
|
22
|
+
/**
|
|
23
|
+
* The actual publisher, which handles batching and flow control.
|
|
24
|
+
*/
|
|
25
|
+
publisher;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new {@link PubSubBackfillEventPublisher}.
|
|
28
|
+
*
|
|
29
|
+
* @param context The {@link WorkspaceContext}.
|
|
30
|
+
* @param topicId The ID of the Pub/Sub topic to publish to.
|
|
31
|
+
* This should be a full Pub/Sub topic ID, e.g. `projects/<projectId>/topics/<topicId>`.
|
|
32
|
+
*/
|
|
33
|
+
constructor(context, topicId) {
|
|
34
|
+
super(context);
|
|
35
|
+
this.topicId = topicId;
|
|
36
|
+
this.publisher = context
|
|
37
|
+
.service(PubSubService)
|
|
38
|
+
.pubSub.topic(topicId, PUBLISH_OPTIONS)
|
|
39
|
+
.flowControlled();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Publishes an event to the Pub/Sub topic.
|
|
43
|
+
* Publishing actually occurs asynchronously. {@link PubSubBackfillEventPublisher.flush} must be called to wait for
|
|
44
|
+
* all events to be published.
|
|
45
|
+
*
|
|
46
|
+
* @param event The event to publish.
|
|
47
|
+
* @returns A promise that resolves when the publisher has caught up with publishing, or `null` if other events can be
|
|
48
|
+
* published immediately.
|
|
49
|
+
*/
|
|
50
|
+
publishEvent(event) {
|
|
51
|
+
return this.publisher.publish({
|
|
52
|
+
data: event.data,
|
|
53
|
+
attributes: event.attributes,
|
|
54
|
+
orderingKey: event.key,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Waits for all events to be published.
|
|
59
|
+
*/
|
|
60
|
+
async flush() {
|
|
61
|
+
await this.publisher.all();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -10,6 +10,10 @@ export type GoogleConfiguration = {
|
|
|
10
10
|
* The ID of the default GCP project used when performing operations.
|
|
11
11
|
*/
|
|
12
12
|
readonly project?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The GCP region in which resource should be created and managed.
|
|
15
|
+
*/
|
|
16
|
+
readonly region?: string;
|
|
13
17
|
/**
|
|
14
18
|
* The ID of a local GCP project (which does not exist on GCP).
|
|
15
19
|
* This is for example used by emulators. It should usually start with `demo-` to be compatible with some emulators.
|
|
@@ -153,6 +157,24 @@ export type GoogleConfiguration = {
|
|
|
153
157
|
*/
|
|
154
158
|
readonly containerName?: string;
|
|
155
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* The directory where the topic configuration files are written by the `GooglePubSubWriteTopics` processor.
|
|
162
|
+
*/
|
|
163
|
+
readonly topicConfigurationsDirectory?: string;
|
|
164
|
+
/**
|
|
165
|
+
* Configuration for the storage of Pub/Sub events in BigQuery.
|
|
166
|
+
*/
|
|
167
|
+
readonly bigQueryStorage?: {
|
|
168
|
+
/**
|
|
169
|
+
* The ID of the BigQuery dataset where raw Pub/Sub events should be stored.
|
|
170
|
+
*/
|
|
171
|
+
readonly rawEventsDatasetId?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The BigQuery location for the datasets.
|
|
174
|
+
* See https://cloud.google.com/bigquery/docs/locations for more details.
|
|
175
|
+
*/
|
|
176
|
+
readonly location?: string;
|
|
177
|
+
};
|
|
156
178
|
};
|
|
157
179
|
/**
|
|
158
180
|
* Configuration for the Spanner service.
|
|
@@ -175,6 +197,25 @@ export type GoogleConfiguration = {
|
|
|
175
197
|
*/
|
|
176
198
|
readonly instanceName?: string;
|
|
177
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* Configuration for the Spanner instance.
|
|
202
|
+
*/
|
|
203
|
+
readonly instance?: {
|
|
204
|
+
/**
|
|
205
|
+
* The name of the Spanner instance.
|
|
206
|
+
*/
|
|
207
|
+
readonly name?: string;
|
|
208
|
+
/**
|
|
209
|
+
* The instance geographic configuration.
|
|
210
|
+
* See https://cloud.google.com/spanner/docs/instance-configurations for more details.
|
|
211
|
+
*/
|
|
212
|
+
readonly configuration?: string;
|
|
213
|
+
/**
|
|
214
|
+
* The compute capacity of the instance.
|
|
215
|
+
* See https://cloud.google.com/spanner/docs/compute-capacity for more details.
|
|
216
|
+
*/
|
|
217
|
+
readonly processingUnits?: number;
|
|
218
|
+
};
|
|
178
219
|
/**
|
|
179
220
|
* Defines how DDLs are found for the Spanner databases in the workspace.
|
|
180
221
|
*/
|
|
@@ -192,6 +233,11 @@ export type GoogleConfiguration = {
|
|
|
192
233
|
*/
|
|
193
234
|
readonly regularExpression?: string;
|
|
194
235
|
};
|
|
236
|
+
/**
|
|
237
|
+
* The directory where the database configuration files are written by the `GoogleSpannerWriteDatabases`
|
|
238
|
+
* processor.
|
|
239
|
+
*/
|
|
240
|
+
readonly databaseConfigurationsDirectory?: string;
|
|
195
241
|
};
|
|
196
242
|
/**
|
|
197
243
|
* Configuration for Cloud Functions.
|
|
@@ -210,6 +256,41 @@ export type GoogleConfiguration = {
|
|
|
210
256
|
* The Docker repository where Cloud Run containers should be uploaded.
|
|
211
257
|
*/
|
|
212
258
|
readonly dockerRepository?: string;
|
|
259
|
+
/**
|
|
260
|
+
* The location where Cloud Run services should be deployed.
|
|
261
|
+
*/
|
|
262
|
+
readonly location?: string;
|
|
263
|
+
/**
|
|
264
|
+
* A map where keys are the name of environment variables, and values are secret versions IDs (e.g.
|
|
265
|
+
* `projects/my-project/secrets/my-secret/versions/1`).
|
|
266
|
+
*/
|
|
267
|
+
readonly secretEnvironmentVariables?: Record<string, string>;
|
|
268
|
+
/**
|
|
269
|
+
* Whether the container is running between requests and can perform background operations.
|
|
270
|
+
*/
|
|
271
|
+
readonly cpuAlwaysAllocated?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* The max duration the instance is allowed for responding to a request, in seconds.
|
|
274
|
+
*/
|
|
275
|
+
readonly timeout?: number;
|
|
276
|
+
/**
|
|
277
|
+
* The maximum allowed in-flight (concurrent) requests per container.
|
|
278
|
+
*/
|
|
279
|
+
readonly requestConcurrency?: number;
|
|
280
|
+
/**
|
|
281
|
+
* The type of allowed ingress that can reach the container.
|
|
282
|
+
* See https://cloud.google.com/run/docs/securing/ingress#settings for more details.
|
|
283
|
+
*/
|
|
284
|
+
readonly ingress?: 'all' | 'internal' | 'internal-and-cloud-load-balancing';
|
|
285
|
+
/**
|
|
286
|
+
* The name of the VPC access connector through which egress traffic should be routed.
|
|
287
|
+
*/
|
|
288
|
+
readonly vpcAccessConnector?: string;
|
|
289
|
+
/**
|
|
290
|
+
* The setting for egress traffic that goes through the VPC access connector.
|
|
291
|
+
* See https://cloud.google.com/run/docs/configuring/connecting-vpc#manage for more details.
|
|
292
|
+
*/
|
|
293
|
+
readonly vpcAccessConnectorEgressSettings?: 'all-traffic' | 'private-ranges-only';
|
|
213
294
|
};
|
|
214
295
|
};
|
|
215
296
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { EmulatorStartForFirebaseStorage } from './start-firebase-storage.js';
|
|
2
|
+
export { EmulatorStartForFirestore } from './start-firestore.js';
|
|
3
|
+
export { EmulatorStartForIdentityPlatform } from './start-identity-platform.js';
|
|
4
|
+
export { EmulatorStartForPubSub } from './start-pubsub.js';
|
|
5
|
+
export { EmulatorStartForSpanner } from './start-spanner.js';
|
|
6
|
+
export { EmulatorStopForFirebaseStorage } from './stop-firebase-storage.js';
|
|
7
|
+
export { EmulatorStopForFirestore } from './stop-firestore.js';
|
|
8
|
+
export { EmulatorStopForIdentityPlatform } from './stop-identity-platform.js';
|
|
9
|
+
export { EmulatorStopForPubSub } from './stop-pubsub.js';
|
|
10
|
+
export { EmulatorStopForSpanner } from './stop-spanner.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { EmulatorStartForFirebaseStorage } from './start-firebase-storage.js';
|
|
2
|
+
export { EmulatorStartForFirestore } from './start-firestore.js';
|
|
3
|
+
export { EmulatorStartForIdentityPlatform } from './start-identity-platform.js';
|
|
4
|
+
export { EmulatorStartForPubSub } from './start-pubsub.js';
|
|
5
|
+
export { EmulatorStartForSpanner } from './start-spanner.js';
|
|
6
|
+
export { EmulatorStopForFirebaseStorage } from './stop-firebase-storage.js';
|
|
7
|
+
export { EmulatorStopForFirestore } from './stop-firestore.js';
|
|
8
|
+
export { EmulatorStopForIdentityPlatform } from './stop-identity-platform.js';
|
|
9
|
+
export { EmulatorStopForPubSub } from './stop-pubsub.js';
|
|
10
|
+
export { EmulatorStopForSpanner } from './stop-spanner.js';
|
package/dist/functions/{emulator-start-firebase-storage.js → emulator/start-firebase-storage.js}
RENAMED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { EmulatorStart } from '@causa/workspace-core';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { FIREBASE_CONTAINER_STORAGE_RULES_FILE, FIREBASE_STORAGE_EMULATOR_NAME, FIREBASE_STORAGE_PORT, getFirebaseStorageContainerName, } from '
|
|
4
|
-
import { FirebaseEmulatorService } from '
|
|
5
|
-
import { GoogleFirebaseStorageMergeRules } from '
|
|
3
|
+
import { FIREBASE_CONTAINER_STORAGE_RULES_FILE, FIREBASE_STORAGE_EMULATOR_NAME, FIREBASE_STORAGE_PORT, getFirebaseStorageContainerName, } from '../../emulators/index.js';
|
|
4
|
+
import { FirebaseEmulatorService } from '../../services/index.js';
|
|
5
|
+
import { GoogleFirebaseStorageMergeRules } from '../google-firebase-storage/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* The Firebase configuration file enabling only the Storage emulator.
|
|
8
8
|
*/
|
|
9
|
-
const FIREBASE_CONF_FILE = fileURLToPath(new URL('
|
|
9
|
+
const FIREBASE_CONF_FILE = fileURLToPath(new URL('../../assets/firebase-storage.json', import.meta.url));
|
|
10
10
|
/**
|
|
11
11
|
* Implements {@link EmulatorStart} for the Firebase Storage container.
|
|
12
12
|
* This first merges the Firebase Storage security rules into a single file, and uses this file to configure the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EmulatorStart } from '@causa/workspace-core';
|
|
2
|
-
import { FIRESTORE_CONTAINER_RULES_FILE, FIRESTORE_EMULATOR_NAME, FIRESTORE_PORT, getFirestoreContainerName, } from '
|
|
3
|
-
import { GcloudEmulatorService } from '
|
|
4
|
-
import { GoogleFirestoreMergeRules } from '
|
|
2
|
+
import { FIRESTORE_CONTAINER_RULES_FILE, FIRESTORE_EMULATOR_NAME, FIRESTORE_PORT, getFirestoreContainerName, } from '../../emulators/index.js';
|
|
3
|
+
import { GcloudEmulatorService } from '../../services/index.js';
|
|
4
|
+
import { GoogleFirestoreMergeRules } from '../google-firestore/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* Implements {@link EmulatorStart} for the Firestore emulator.
|
|
7
7
|
* This first merges the Firestore security rules into a single file, and uses this file to configure the emulator.
|
package/dist/functions/{emulator-start-identity-platform.js → emulator/start-identity-platform.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { EmulatorStart } from '@causa/workspace-core';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
import { FIREBASE_AUTH_PORT, IDENTITY_PLATFORM_EMULATOR_NAME, getIdentityPlatformContainerName, } from '
|
|
4
|
-
import { FirebaseEmulatorService } from '
|
|
3
|
+
import { FIREBASE_AUTH_PORT, IDENTITY_PLATFORM_EMULATOR_NAME, getIdentityPlatformContainerName, } from '../../emulators/index.js';
|
|
4
|
+
import { FirebaseEmulatorService } from '../../services/index.js';
|
|
5
5
|
/**
|
|
6
6
|
* The Firebase configuration file enabling only the Auth emulator.
|
|
7
7
|
*/
|
|
8
|
-
const FIREBASE_CONF_FILE = fileURLToPath(new URL('
|
|
8
|
+
const FIREBASE_CONF_FILE = fileURLToPath(new URL('../../assets/firebase-auth.json', import.meta.url));
|
|
9
9
|
/**
|
|
10
10
|
* Implements {@link EmulatorStart} for the Identity Platform emulator.
|
|
11
11
|
* This actually runs the "legacy" Firebase Auth emulator, which is the same service before it was re-branded.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EmulatorStart, EventTopicList, } from '@causa/workspace-core';
|
|
2
2
|
import { PubSub } from '@google-cloud/pubsub';
|
|
3
|
-
import { getLocalGcpProject } from '
|
|
4
|
-
import { PUBSUB_EMULATOR_NAME, PUBSUB_PORT, formatPubSubTopicAsEnvironmentVariable, getPubSubContainerName, } from '
|
|
5
|
-
import { GcloudEmulatorService } from '
|
|
3
|
+
import { getLocalGcpProject } from '../../configurations/utils.js';
|
|
4
|
+
import { PUBSUB_EMULATOR_NAME, PUBSUB_PORT, formatPubSubTopicAsEnvironmentVariable, getPubSubContainerName, } from '../../emulators/index.js';
|
|
5
|
+
import { GcloudEmulatorService } from '../../services/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* Implements {@link EmulatorStart} for the Pub/Sub emulator.
|
|
8
8
|
* This first starts the Pub/Sub emulator, and then creates the topics defined in the workspace (if the workspace is
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStart, } from '@causa/workspace-core';
|
|
2
2
|
import { Spanner } from '@google-cloud/spanner';
|
|
3
|
-
import {
|
|
4
|
-
import { getLocalGcpProject, } from '
|
|
5
|
-
import { SPANNER_EMULATOR_NAME, SPANNER_GRPC_PORT, SPANNER_HTTP_PORT, SPANNER_IMAGE, getSpannerContainerName, } from '
|
|
6
|
-
import { GoogleSpannerListDatabases } from '
|
|
3
|
+
import { credentials } from '@grpc/grpc-js';
|
|
4
|
+
import { getLocalGcpProject, } from '../../configurations/index.js';
|
|
5
|
+
import { SPANNER_EMULATOR_NAME, SPANNER_GRPC_PORT, SPANNER_HTTP_PORT, SPANNER_IMAGE, getSpannerContainerName, } from '../../emulators/index.js';
|
|
6
|
+
import { GoogleSpannerListDatabases } from '../google-spanner/index.js';
|
|
7
7
|
/**
|
|
8
8
|
* Implements {@link EmulatorStart} for the Spanner emulator.
|
|
9
9
|
* This starts the emulator, creates a local instance, and creates the databases using the DDLs found in the workspace.
|
|
@@ -75,7 +75,7 @@ export class EmulatorStartForSpanner extends EmulatorStart {
|
|
|
75
75
|
servicePath: '127.0.0.1',
|
|
76
76
|
port: SPANNER_GRPC_PORT,
|
|
77
77
|
projectId: getLocalGcpProject(context),
|
|
78
|
-
sslCreds:
|
|
78
|
+
sslCreds: credentials.createInsecure(),
|
|
79
79
|
});
|
|
80
80
|
const [instance, operation] = await spanner.createInstance(instanceName, {
|
|
81
81
|
config: 'emulator-config',
|
package/dist/functions/{emulator-stop-firebase-storage.js → emulator/stop-firebase-storage.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
-
import { FIREBASE_STORAGE_EMULATOR_NAME, getFirebaseStorageContainerName, } from '
|
|
2
|
+
import { FIREBASE_STORAGE_EMULATOR_NAME, getFirebaseStorageContainerName, } from '../../emulators/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements {@link EmulatorStop} for the Firebase Storage emulator.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
-
import { FIRESTORE_EMULATOR_NAME, getFirestoreContainerName, } from '
|
|
2
|
+
import { FIRESTORE_EMULATOR_NAME, getFirestoreContainerName, } from '../../emulators/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements {@link EmulatorStop} for the Firestore emulator.
|
|
5
5
|
*/
|
package/dist/functions/{emulator-stop-identity-platform.js → emulator/stop-identity-platform.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
-
import { IDENTITY_PLATFORM_EMULATOR_NAME, getIdentityPlatformContainerName, } from '
|
|
2
|
+
import { IDENTITY_PLATFORM_EMULATOR_NAME, getIdentityPlatformContainerName, } from '../../emulators/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements {@link EmulatorStop} for the Identity Platform emulator.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
-
import { PUBSUB_EMULATOR_NAME, getPubSubContainerName, } from '
|
|
2
|
+
import { PUBSUB_EMULATOR_NAME, getPubSubContainerName, } from '../../emulators/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements {@link EmulatorStop} for the Pub/Sub emulator.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DockerEmulatorService, EmulatorStop } from '@causa/workspace-core';
|
|
2
|
-
import { SPANNER_EMULATOR_NAME, getSpannerContainerName, } from '
|
|
2
|
+
import { SPANNER_EMULATOR_NAME, getSpannerContainerName, } from '../../emulators/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Implements {@link EmulatorStop} for the Spanner emulator.
|
|
5
5
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EventTopicBrokerCreateTopic } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EventTopicBrokerCreateTopic} for Pub/Sub.
|
|
5
|
+
* Topics are created in the GCP project set in the `google.project` configuration.
|
|
6
|
+
* If a `google.region` configuration is set, the message storage policy for the topic is set accordingly.
|
|
7
|
+
*/
|
|
8
|
+
export declare class EventTopicBrokerCreateTopicForPubSub extends EventTopicBrokerCreateTopic {
|
|
9
|
+
_call(context: WorkspaceContext): Promise<string>;
|
|
10
|
+
_supports(context: WorkspaceContext): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventTopicBrokerCreateTopic, } from '@causa/workspace-core';
|
|
2
|
+
import { PubSubService } from '../../services/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EventTopicBrokerCreateTopic} for Pub/Sub.
|
|
5
|
+
* Topics are created in the GCP project set in the `google.project` configuration.
|
|
6
|
+
* If a `google.region` configuration is set, the message storage policy for the topic is set accordingly.
|
|
7
|
+
*/
|
|
8
|
+
export class EventTopicBrokerCreateTopicForPubSub extends EventTopicBrokerCreateTopic {
|
|
9
|
+
async _call(context) {
|
|
10
|
+
const googleConf = context.asConfiguration();
|
|
11
|
+
const projectId = googleConf.getOrThrow('google.project');
|
|
12
|
+
const region = googleConf.get('google.region');
|
|
13
|
+
const topicId = `projects/${projectId}/topics/${this.name}`;
|
|
14
|
+
context.logger.info(`📫 Creating Pub/Sub topic '${topicId}'.`);
|
|
15
|
+
await context.service(PubSubService).pubSub.createTopic({
|
|
16
|
+
name: topicId,
|
|
17
|
+
...(region
|
|
18
|
+
? { messageStoragePolicy: { allowedPersistenceRegions: [region] } }
|
|
19
|
+
: {}),
|
|
20
|
+
});
|
|
21
|
+
return topicId;
|
|
22
|
+
}
|
|
23
|
+
_supports(context) {
|
|
24
|
+
return (context.asConfiguration().get('events.broker') ===
|
|
25
|
+
'google.pubSub');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WorkspaceContext } from '@causa/workspace';
|
|
2
|
+
import { EventTopicBrokerCreateTrigger } from '@causa/workspace-core';
|
|
3
|
+
/**
|
|
4
|
+
* Implements {@link EventTopicBrokerCreateTrigger} for Cloud Run endpoints being triggered by Pub/Sub messages.
|
|
5
|
+
* The `id` argument should be a Cloud Run service ID, followed by the path to the trigger, e.g.
|
|
6
|
+
* `[[projects/<projectId>/]locations/<location>/]services/<name>/path-to-trigger`.
|
|
7
|
+
*/
|
|
8
|
+
export declare class EventTopicBrokerCreateTriggerForCloudRun extends EventTopicBrokerCreateTrigger {
|
|
9
|
+
_call(context: WorkspaceContext): Promise<string[]>;
|
|
10
|
+
_supports(context: WorkspaceContext): boolean;
|
|
11
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EventTopicBrokerCreateTrigger, } from '@causa/workspace-core';
|
|
2
|
+
import { CloudRunPubSubTriggerService } from '../../services/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* The regular expression used to match Cloud Run trigger IDs, consisting of the service ID and the path to the trigger.
|
|
5
|
+
* [[projects/<projectId>/]locations/<location>/]services/<name>/path-to-trigger
|
|
6
|
+
*/
|
|
7
|
+
const CLOUD_RUN_TRIGGER_ID_REGEX = /^(?:(?:projects\/(?<projectId>[\w-]+)\/)?locations\/(?<location>[\w-]+)\/)?services\/(?<name>[\w-]+)(?<path>\/.*)$/;
|
|
8
|
+
/**
|
|
9
|
+
* Implements {@link EventTopicBrokerCreateTrigger} for Cloud Run endpoints being triggered by Pub/Sub messages.
|
|
10
|
+
* The `id` argument should be a Cloud Run service ID, followed by the path to the trigger, e.g.
|
|
11
|
+
* `[[projects/<projectId>/]locations/<location>/]services/<name>/path-to-trigger`.
|
|
12
|
+
*/
|
|
13
|
+
export class EventTopicBrokerCreateTriggerForCloudRun extends EventTopicBrokerCreateTrigger {
|
|
14
|
+
async _call(context) {
|
|
15
|
+
const match = this.trigger.match(CLOUD_RUN_TRIGGER_ID_REGEX);
|
|
16
|
+
if (!match?.groups) {
|
|
17
|
+
throw new Error('Oops.');
|
|
18
|
+
}
|
|
19
|
+
const googleConf = context.asConfiguration();
|
|
20
|
+
const projectId = match.groups.projectId ?? googleConf.getOrThrow('google.project');
|
|
21
|
+
const location = match.groups.location ??
|
|
22
|
+
googleConf.getOrThrow('google.cloudRun.location');
|
|
23
|
+
const name = match.groups.name;
|
|
24
|
+
const path = match.groups.path;
|
|
25
|
+
if (!name || !path) {
|
|
26
|
+
throw new Error('Oops.');
|
|
27
|
+
}
|
|
28
|
+
const serviceId = `projects/${projectId}/locations/${location}/services/${name}`;
|
|
29
|
+
return await context
|
|
30
|
+
.service(CloudRunPubSubTriggerService)
|
|
31
|
+
.create(this.backfillId, this.topicId, serviceId, path);
|
|
32
|
+
}
|
|
33
|
+
_supports(context) {
|
|
34
|
+
return (this.trigger.match(CLOUD_RUN_TRIGGER_ID_REGEX) != null &&
|
|
35
|
+
context.asConfiguration().get('events.broker') ===
|
|
36
|
+
'google.pubSub');
|
|
37
|
+
}
|
|
38
|
+
}
|