@sebspark/gcp-iam 0.1.0 → 0.2.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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -2
- package/dist/index.mjs +9 -2
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -8,6 +8,6 @@ import { Logger } from 'winston';
|
|
|
8
8
|
* @param logger An optional logger to use for logging.
|
|
9
9
|
* @returns A JWT.
|
|
10
10
|
*/
|
|
11
|
-
declare const getApiGatewayToken: (apiURL: string,
|
|
11
|
+
declare const getApiGatewayToken: (apiURL: string, logger?: Logger) => Promise<string>;
|
|
12
12
|
|
|
13
13
|
export { getApiGatewayToken };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ import { Logger } from 'winston';
|
|
|
8
8
|
* @param logger An optional logger to use for logging.
|
|
9
9
|
* @returns A JWT.
|
|
10
10
|
*/
|
|
11
|
-
declare const getApiGatewayToken: (apiURL: string,
|
|
11
|
+
declare const getApiGatewayToken: (apiURL: string, logger?: Logger) => Promise<string>;
|
|
12
12
|
|
|
13
13
|
export { getApiGatewayToken };
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
26
26
|
|
|
27
27
|
// src/apiGatewayToken.ts
|
|
28
28
|
var import_iam_credentials = require("@google-cloud/iam-credentials");
|
|
29
|
+
var import_google_auth_library = require("google-auth-library");
|
|
29
30
|
|
|
30
31
|
// src/lruCache.ts
|
|
31
32
|
var LruCache = class {
|
|
@@ -64,14 +65,20 @@ var expInSeconds = 60 * 60;
|
|
|
64
65
|
var apiGatewayJwtCache = new LruCache({
|
|
65
66
|
ttl: 1e3 * expInSeconds / 2
|
|
66
67
|
});
|
|
67
|
-
var getApiGatewayToken = async (apiURL,
|
|
68
|
+
var getApiGatewayToken = async (apiURL, logger) => {
|
|
68
69
|
const cachedJwt = apiGatewayJwtCache.get(apiURL);
|
|
69
|
-
console.log(cachedJwt);
|
|
70
70
|
if (cachedJwt) {
|
|
71
71
|
return cachedJwt;
|
|
72
72
|
}
|
|
73
73
|
try {
|
|
74
74
|
const iamClient = new import_iam_credentials.IAMCredentialsClient();
|
|
75
|
+
const auth = new import_google_auth_library.GoogleAuth();
|
|
76
|
+
const cred = await auth.getCredentials();
|
|
77
|
+
const serviceAccountEmail = cred.client_email;
|
|
78
|
+
if (!serviceAccountEmail) {
|
|
79
|
+
throw new Error("No service account e-mail could be found.");
|
|
80
|
+
}
|
|
81
|
+
logger == null ? void 0 : logger.info(`Serice account e-mail beeing used: ${serviceAccountEmail}`);
|
|
75
82
|
const header = {
|
|
76
83
|
alg: "RS256",
|
|
77
84
|
typ: "JWT"
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/apiGatewayToken.ts
|
|
2
2
|
import { IAMCredentialsClient } from "@google-cloud/iam-credentials";
|
|
3
|
+
import { GoogleAuth } from "google-auth-library";
|
|
3
4
|
|
|
4
5
|
// src/lruCache.ts
|
|
5
6
|
var LruCache = class {
|
|
@@ -38,14 +39,20 @@ var expInSeconds = 60 * 60;
|
|
|
38
39
|
var apiGatewayJwtCache = new LruCache({
|
|
39
40
|
ttl: 1e3 * expInSeconds / 2
|
|
40
41
|
});
|
|
41
|
-
var getApiGatewayToken = async (apiURL,
|
|
42
|
+
var getApiGatewayToken = async (apiURL, logger) => {
|
|
42
43
|
const cachedJwt = apiGatewayJwtCache.get(apiURL);
|
|
43
|
-
console.log(cachedJwt);
|
|
44
44
|
if (cachedJwt) {
|
|
45
45
|
return cachedJwt;
|
|
46
46
|
}
|
|
47
47
|
try {
|
|
48
48
|
const iamClient = new IAMCredentialsClient();
|
|
49
|
+
const auth = new GoogleAuth();
|
|
50
|
+
const cred = await auth.getCredentials();
|
|
51
|
+
const serviceAccountEmail = cred.client_email;
|
|
52
|
+
if (!serviceAccountEmail) {
|
|
53
|
+
throw new Error("No service account e-mail could be found.");
|
|
54
|
+
}
|
|
55
|
+
logger == null ? void 0 : logger.info(`Serice account e-mail beeing used: ${serviceAccountEmail}`);
|
|
49
56
|
const header = {
|
|
50
57
|
alg: "RS256",
|
|
51
58
|
typ: "JWT"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/gcp-iam",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"tsconfig": "*"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@google-cloud/iam-credentials": "3.3.0"
|
|
22
|
+
"@google-cloud/iam-credentials": "3.3.0",
|
|
23
|
+
"google-auth-library": "^9.15.0"
|
|
23
24
|
}
|
|
24
|
-
}
|
|
25
|
+
}
|