@causa/workspace-google 0.4.0 → 0.6.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 +9 -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.d.ts → emulator/start-spanner.d.ts} +8 -0
- package/dist/functions/{emulator-start-spanner.js → emulator/start-spanner.js} +29 -14
- 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} +4 -3
- 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} +4 -3
- 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} +4 -3
- 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} +5 -4
- 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-services-enable.d.ts → google-services/enable.d.ts} +1 -1
- package/dist/functions/{google-services-enable.js → google-services/enable.js} +3 -2
- 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.js → google-spanner/write-databases.js} +1 -1
- package/dist/functions/index.js +12 -24
- 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-access-token.d.ts +18 -0
- package/dist/functions/secret/fetch-access-token.js +30 -0
- package/dist/functions/{secret-fetch-secret-manager.js → secret/fetch-secret-manager.js} +1 -1
- package/dist/functions/secret/index.d.ts +2 -0
- package/dist/functions/secret/index.js +2 -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/google-apis.d.ts +3 -2
- package/dist/services/google-apis.js +3 -2
- 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 +30 -25
- /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-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-pubsub-write-topics.d.ts → google-pubsub/write-topics.d.ts} +0 -0
- /package/dist/functions/{google-pubsub-write-topics.js → google-pubsub/write-topics.js} +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/{google-spanner-write-databases.d.ts → google-spanner/write-databases.d.ts} +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
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PubSub } from '@google-cloud/pubsub';
|
|
2
|
+
import { ResourceManagerService } from './resource-manager.js';
|
|
3
|
+
/**
|
|
4
|
+
* A service for managing Pub/Sub resources
|
|
5
|
+
*/
|
|
6
|
+
export class PubSubService {
|
|
7
|
+
/**
|
|
8
|
+
* The Pub/Sub client.
|
|
9
|
+
*/
|
|
10
|
+
pubSub;
|
|
11
|
+
/**
|
|
12
|
+
* The resource manager service used to get the project number.
|
|
13
|
+
*/
|
|
14
|
+
resourceManagerService;
|
|
15
|
+
/**
|
|
16
|
+
* The ID of the GCP project in which to create Pub/Sub resources.
|
|
17
|
+
*/
|
|
18
|
+
projectId;
|
|
19
|
+
constructor(context) {
|
|
20
|
+
this.pubSub = new PubSub();
|
|
21
|
+
this.resourceManagerService = context.service(ResourceManagerService);
|
|
22
|
+
this.projectId = context
|
|
23
|
+
.asConfiguration()
|
|
24
|
+
.getOrThrow('google.project');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The cached promise that resolves to the GCP service account used by Pub/Sub.
|
|
28
|
+
*/
|
|
29
|
+
gcpServiceAccountPromise;
|
|
30
|
+
/**
|
|
31
|
+
* Constructs the email of the GCP-owned service account used by Pub/Sub.
|
|
32
|
+
* This can be used to grant roles to the service account, e.g. for push subscriptions.
|
|
33
|
+
*
|
|
34
|
+
* @returns The email of the GCP service account used by Pub/Sub.
|
|
35
|
+
*/
|
|
36
|
+
async getGcpServiceAccount() {
|
|
37
|
+
if (!this.gcpServiceAccountPromise) {
|
|
38
|
+
this.gcpServiceAccountPromise = (async () => {
|
|
39
|
+
const projectNumber = await this.resourceManagerService.getProjectNumber(this.projectId);
|
|
40
|
+
return `service-${projectNumber}@gcp-sa-pubsub.iam.gserviceaccount.com`;
|
|
41
|
+
})();
|
|
42
|
+
}
|
|
43
|
+
return await this.gcpServiceAccountPromise;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Constructs the IAM policy bindings that should be added to a service account meant to be used by push
|
|
47
|
+
* subscriptions.
|
|
48
|
+
* Those bindings allow the GCP-owned Pub/Sub service account to authenticate as the service account when pushing
|
|
49
|
+
* messages.
|
|
50
|
+
*
|
|
51
|
+
* @returns The bindings.
|
|
52
|
+
*/
|
|
53
|
+
async getPushServiceAccountBindings() {
|
|
54
|
+
const pubSubGcpServiceAccount = await this.getGcpServiceAccount();
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
role: 'roles/iam.serviceAccountTokenCreator',
|
|
58
|
+
members: [`serviceAccount:${pubSubGcpServiceAccount}`],
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ProjectsClient } from '@google-cloud/resource-manager';
|
|
2
|
+
/**
|
|
3
|
+
* A service for interacting with the GCP Resource Manager API, handling organizations, folders, and projects.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ResourceManagerService {
|
|
6
|
+
/**
|
|
7
|
+
* The client used to manage GCP projects.
|
|
8
|
+
*/
|
|
9
|
+
readonly projectsClient: ProjectsClient;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves the project number for a given GCP project ID.
|
|
13
|
+
*
|
|
14
|
+
* @param projectId The ID of the GCP project.
|
|
15
|
+
* @returns The number of the GCP project.
|
|
16
|
+
*/
|
|
17
|
+
getProjectNumber(projectId: string): Promise<string>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ProjectsClient } from '@google-cloud/resource-manager';
|
|
2
|
+
/**
|
|
3
|
+
* A service for interacting with the GCP Resource Manager API, handling organizations, folders, and projects.
|
|
4
|
+
*/
|
|
5
|
+
export class ResourceManagerService {
|
|
6
|
+
/**
|
|
7
|
+
* The client used to manage GCP projects.
|
|
8
|
+
*/
|
|
9
|
+
projectsClient;
|
|
10
|
+
constructor() {
|
|
11
|
+
this.projectsClient = new ProjectsClient();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves the project number for a given GCP project ID.
|
|
15
|
+
*
|
|
16
|
+
* @param projectId The ID of the GCP project.
|
|
17
|
+
* @returns The number of the GCP project.
|
|
18
|
+
*/
|
|
19
|
+
async getProjectNumber(projectId) {
|
|
20
|
+
const [projects] = await this.projectsClient.searchProjects({
|
|
21
|
+
query: `projectId:${projectId}`,
|
|
22
|
+
pageSize: 1,
|
|
23
|
+
});
|
|
24
|
+
if (projects.length < 1) {
|
|
25
|
+
throw new Error(`Could not find GCP project '${projectId}'.`);
|
|
26
|
+
}
|
|
27
|
+
const [project] = projects;
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
29
|
+
const [projectsConst, projectNumber] = project.name?.split('/') ?? [];
|
|
30
|
+
if (!projectNumber) {
|
|
31
|
+
throw new Error(`Failed to parse invalid project name '${project.name}'.`);
|
|
32
|
+
}
|
|
33
|
+
return projectNumber;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@causa/workspace-google",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "The Causa workspace module providing many functionalities related to GCP and its services.",
|
|
5
5
|
"repository": "github:causa-io/workspace-module-google",
|
|
6
6
|
"license": "ISC",
|
|
@@ -31,37 +31,42 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@causa/cli": ">= 0.4.0 < 1.0.0",
|
|
33
33
|
"@causa/workspace": ">= 0.12.0 < 1.0.0",
|
|
34
|
-
"@causa/workspace-core": ">= 0.
|
|
35
|
-
"@google-cloud/apikeys": "^0.
|
|
36
|
-
"@google-cloud/
|
|
37
|
-
"@google-cloud/
|
|
38
|
-
"@google-cloud/
|
|
39
|
-
"@google-cloud/
|
|
40
|
-
"@google-cloud/
|
|
41
|
-
"@google-cloud/
|
|
42
|
-
"@
|
|
34
|
+
"@causa/workspace-core": ">= 0.16.0 < 1.0.0",
|
|
35
|
+
"@google-cloud/apikeys": "^1.0.1",
|
|
36
|
+
"@google-cloud/bigquery": "^7.3.0",
|
|
37
|
+
"@google-cloud/iam-credentials": "^3.0.1",
|
|
38
|
+
"@google-cloud/pubsub": "^4.0.6",
|
|
39
|
+
"@google-cloud/resource-manager": "^5.0.1",
|
|
40
|
+
"@google-cloud/run": "^1.0.1",
|
|
41
|
+
"@google-cloud/secret-manager": "^5.0.1",
|
|
42
|
+
"@google-cloud/service-usage": "^3.1.0",
|
|
43
|
+
"@google-cloud/spanner": "^7.0.0",
|
|
44
|
+
"@google-cloud/storage": "^7.1.0",
|
|
45
|
+
"@grpc/grpc-js": "^1.9.4",
|
|
43
46
|
"class-validator": "^0.14.0",
|
|
44
|
-
"firebase": "^10.
|
|
45
|
-
"firebase-admin": "^11.
|
|
47
|
+
"firebase": "^10.4.0",
|
|
48
|
+
"firebase-admin": "^11.11.0",
|
|
46
49
|
"globby": "^13.2.2",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
50
|
+
"google-auth-library": "^9.0.0",
|
|
51
|
+
"googleapis": "^126.0.1",
|
|
52
|
+
"pino": "^8.15.1",
|
|
53
|
+
"uuid": "^9.0.1"
|
|
49
54
|
},
|
|
50
55
|
"devDependencies": {
|
|
51
|
-
"@tsconfig/node18": "^18.2.
|
|
52
|
-
"@types/jest": "^29.5.
|
|
53
|
-
"@types/node": "^18.
|
|
54
|
-
"@types/uuid": "^9.0.
|
|
55
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
56
|
+
"@tsconfig/node18": "^18.2.2",
|
|
57
|
+
"@types/jest": "^29.5.5",
|
|
58
|
+
"@types/node": "^18.18.0",
|
|
59
|
+
"@types/uuid": "^9.0.4",
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "^6.7.3",
|
|
56
61
|
"copyfiles": "^2.4.1",
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"eslint-config-prettier": "^
|
|
62
|
+
"eslint": "^8.50.0",
|
|
63
|
+
"eslint-config-prettier": "^9.0.0",
|
|
59
64
|
"eslint-plugin-prettier": "^5.0.0",
|
|
60
|
-
"jest": "^29.
|
|
61
|
-
"jest-extended": "^4.0.
|
|
62
|
-
"rimraf": "^5.0.
|
|
65
|
+
"jest": "^29.7.0",
|
|
66
|
+
"jest-extended": "^4.0.1",
|
|
67
|
+
"rimraf": "^5.0.5",
|
|
63
68
|
"ts-jest": "^29.1.1",
|
|
64
69
|
"ts-node": "^10.9.1",
|
|
65
|
-
"typescript": "^5.
|
|
70
|
+
"typescript": "^5.2.2"
|
|
66
71
|
}
|
|
67
72
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/functions/{emulator-stop-firebase-storage.d.ts → emulator/stop-firebase-storage.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/functions/{google-spanner-list-databases.d.ts → google-spanner/list-databases.d.ts}
RENAMED
|
File without changes
|
/package/dist/functions/{google-spanner-list-databases.js → google-spanner/list-databases.js}
RENAMED
|
File without changes
|
/package/dist/functions/{google-spanner-write-databases.d.ts → google-spanner/write-databases.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/functions/{secret-fetch-secret-manager.d.ts → secret/fetch-secret-manager.d.ts}
RENAMED
|
File without changes
|