@nu-art/google-services-backend 0.400.14 → 0.401.1
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/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export * from './modules/ModuleBE_GcpManager.js';
|
|
|
2
2
|
export * from './modules/ModuleBE_GoogleContacts.js';
|
|
3
3
|
export * from './modules/ModuleBE_Auth.js';
|
|
4
4
|
export * from './modules/ModuleBE_GooglePubSub.js';
|
|
5
|
+
export * from './modules/ModuleBE_SecretManager.js';
|
|
6
|
+
export * from './modules/ModuleBE_WhoAmI_GCP.js';
|
package/index.js
CHANGED
|
@@ -20,3 +20,5 @@ export * from './modules/ModuleBE_GcpManager.js';
|
|
|
20
20
|
export * from './modules/ModuleBE_GoogleContacts.js';
|
|
21
21
|
export * from './modules/ModuleBE_Auth.js';
|
|
22
22
|
export * from './modules/ModuleBE_GooglePubSub.js';
|
|
23
|
+
export * from './modules/ModuleBE_SecretManager.js';
|
|
24
|
+
export * from './modules/ModuleBE_WhoAmI_GCP.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnyPrimitive, Module } from '@nu-art/ts-common';
|
|
2
2
|
import { google } from '@google-cloud/secret-manager/build/protos/protos.js';
|
|
3
3
|
import ISecret = google.cloud.secretmanager.v1.ISecret;
|
|
4
|
-
export declare const printCallerIdentity: () => Promise<void>;
|
|
5
4
|
type Secret = {
|
|
6
5
|
key: string;
|
|
7
6
|
projectId: string;
|
|
@@ -1,17 +1,5 @@
|
|
|
1
|
-
import { exists,
|
|
1
|
+
import { exists, Module, MUSTNeverHappenException, ThisShouldNotHappenException } from '@nu-art/ts-common';
|
|
2
2
|
import { SecretManagerServiceClient } from '@google-cloud/secret-manager';
|
|
3
|
-
import { GoogleAuth } from 'google-auth-library';
|
|
4
|
-
export const printCallerIdentity = async () => {
|
|
5
|
-
const logger = new Logger('GCP-Caller');
|
|
6
|
-
const auth = new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' });
|
|
7
|
-
const client = await auth.getClient();
|
|
8
|
-
const projectId = await auth.getProjectId();
|
|
9
|
-
const token = await client.getAccessToken();
|
|
10
|
-
const res = await fetch(`https://oauth2.googleapis.com/tokeninfo?access_token=${token.token}`);
|
|
11
|
-
const info = await res.json();
|
|
12
|
-
logger.logInfo(`🔐 GCP Caller Identity: ${info.email || info.sub}`);
|
|
13
|
-
logger.logInfo(`🏗️ GCP Project ID: ${projectId}`);
|
|
14
|
-
};
|
|
15
3
|
function composeSecretKey(secret) {
|
|
16
4
|
return `projects/${secret.projectId}/secrets/${secret.key}${secret.version ? `/versions/${secret.version}` : ''}`;
|
|
17
5
|
}
|
|
@@ -67,7 +55,6 @@ export class ModuleBE_SecretManager_Class extends Module {
|
|
|
67
55
|
catch (err) {
|
|
68
56
|
if (err.code === 5)
|
|
69
57
|
return undefined;
|
|
70
|
-
await printCallerIdentity();
|
|
71
58
|
throw new ThisShouldNotHappenException(`Failed to retrieve secret \n Secret: ${JSON.stringify(secret)}`, err);
|
|
72
59
|
}
|
|
73
60
|
};
|
|
@@ -90,7 +77,6 @@ export class ModuleBE_SecretManager_Class extends Module {
|
|
|
90
77
|
});
|
|
91
78
|
}
|
|
92
79
|
catch (err) {
|
|
93
|
-
await printCallerIdentity();
|
|
94
80
|
throw new ThisShouldNotHappenException(`Failed to update secret version (${secret})`, err);
|
|
95
81
|
}
|
|
96
82
|
};
|
|
@@ -114,7 +100,6 @@ export class ModuleBE_SecretManager_Class extends Module {
|
|
|
114
100
|
}
|
|
115
101
|
catch (err) {
|
|
116
102
|
if (err.code !== 5) {
|
|
117
|
-
await printCallerIdentity();
|
|
118
103
|
throw new ThisShouldNotHappenException(`Failed to get secret (${_secret})`, err);
|
|
119
104
|
}
|
|
120
105
|
const [created] = await this.client.createSecret({
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Module } from '@nu-art/ts-common';
|
|
2
|
+
export declare class ModuleBE_WhoAmI_GCP_Class extends Module {
|
|
3
|
+
init(): void;
|
|
4
|
+
printCallerIdentity: () => Promise<{
|
|
5
|
+
projectId: string;
|
|
6
|
+
info: any;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare const ModuleBE_WhoAmI_GCP: ModuleBE_WhoAmI_GCP_Class;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Module } from '@nu-art/ts-common';
|
|
2
|
+
import { GoogleAuth } from 'google-auth-library';
|
|
3
|
+
export class ModuleBE_WhoAmI_GCP_Class extends Module {
|
|
4
|
+
init() {
|
|
5
|
+
this.printCallerIdentity().then(({ projectId, info }) => {
|
|
6
|
+
this.logInfo('env: ', process.env);
|
|
7
|
+
this.logInfo('GOOGLE_APPLICATION_CREDENTIALS: ', process.env.GOOGLE_APPLICATION_CREDENTIALS ?? 'not set');
|
|
8
|
+
this.logInfo(`🔐 GCP Caller Identity: ${info.email || info.sub}`);
|
|
9
|
+
this.logInfo(`🏗️ GCP Project ID: ${projectId}`);
|
|
10
|
+
}).catch(err => {
|
|
11
|
+
this.logError('error: ', err);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
printCallerIdentity = async () => {
|
|
15
|
+
const auth = new GoogleAuth({ scopes: 'https://www.googleapis.com/auth/cloud-platform' });
|
|
16
|
+
const client = await auth.getClient();
|
|
17
|
+
const projectId = await auth.getProjectId();
|
|
18
|
+
const token = await client.getAccessToken();
|
|
19
|
+
const res = await fetch(`https://oauth2.googleapis.com/tokeninfo?access_token=${token.token}`);
|
|
20
|
+
const info = await res.json();
|
|
21
|
+
return { projectId, info };
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export const ModuleBE_WhoAmI_GCP = new ModuleBE_WhoAmI_GCP_Class();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/google-services-backend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.401.1",
|
|
4
4
|
"description": "google-services Backend",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"build": "tsc"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nu-art/ts-common": "0.
|
|
36
|
+
"@nu-art/ts-common": "0.401.1",
|
|
37
37
|
"@google-cloud/pubsub": "^4.0.0",
|
|
38
38
|
"@google-cloud/secret-manager": "^6.1.0",
|
|
39
39
|
"google-auth-library": "^10.0.0",
|