@flashbacktech/flashbackclient 0.0.77 → 0.0.78
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/gcs/storage.d.ts +3 -0
- package/dist/gcs/storage.js +14 -5
- package/package.json +1 -1
package/dist/gcs/storage.d.ts
CHANGED
|
@@ -17,8 +17,11 @@ export interface SignedUrlOptions {
|
|
|
17
17
|
}
|
|
18
18
|
export declare class FlashbackGCSStorage extends Storage {
|
|
19
19
|
protected credentials: ServiceCredentials;
|
|
20
|
+
private debug;
|
|
20
21
|
constructor(opts: FlashbackStorageOptions);
|
|
21
22
|
cleanup(): void;
|
|
22
23
|
bucket(name: string): import("@google-cloud/storage").Bucket;
|
|
24
|
+
setDebug(debug: boolean): void;
|
|
25
|
+
private doLog;
|
|
23
26
|
getSignedUrl(cfg: SignedUrlOptions): Promise<[string]>;
|
|
24
27
|
}
|
package/dist/gcs/storage.js
CHANGED
|
@@ -22,6 +22,7 @@ class FlashbackGCSStorage extends storage_1.Storage {
|
|
|
22
22
|
maxRetries: 3,
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
|
+
this.debug = false;
|
|
25
26
|
this.credentials = credentials;
|
|
26
27
|
// Intercept Gaxios instance creation
|
|
27
28
|
require('gaxios').instance.request = async function (opts) {
|
|
@@ -41,13 +42,21 @@ class FlashbackGCSStorage extends storage_1.Storage {
|
|
|
41
42
|
bucket(name) {
|
|
42
43
|
return super.bucket(name);
|
|
43
44
|
}
|
|
45
|
+
setDebug(debug) {
|
|
46
|
+
this.debug = debug;
|
|
47
|
+
}
|
|
48
|
+
doLog(...args) {
|
|
49
|
+
if (this.debug) {
|
|
50
|
+
console.log(...args);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
44
53
|
// Override the getSignedUrl method
|
|
45
54
|
async getSignedUrl(cfg) {
|
|
46
55
|
const { version, action, expires, contentType } = cfg;
|
|
47
56
|
const accessibleAt = new Date();
|
|
48
57
|
const millisecondsToSeconds = 1.0 / 1000.0;
|
|
49
58
|
const expiresPeriodInSeconds = Math.floor((expires - accessibleAt.valueOf()) * millisecondsToSeconds);
|
|
50
|
-
|
|
59
|
+
this.doLog('Signing Parameters:', {
|
|
51
60
|
action,
|
|
52
61
|
expires,
|
|
53
62
|
expiresPeriodInSeconds,
|
|
@@ -103,19 +112,19 @@ class FlashbackGCSStorage extends storage_1.Storage {
|
|
|
103
112
|
signedHeaders,
|
|
104
113
|
'UNSIGNED-PAYLOAD',
|
|
105
114
|
].join('\n');
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
this.doLog('Canonical Request:', canonicalRequest);
|
|
116
|
+
this.doLog('Canonical Request Hash:', crypto_1.default.createHash('sha256').update(canonicalRequest).digest('hex'));
|
|
108
117
|
const stringToSign = [
|
|
109
118
|
'GOOG4-RSA-SHA256',
|
|
110
119
|
dateISO,
|
|
111
120
|
credentialScope,
|
|
112
121
|
crypto_1.default.createHash('sha256').update(canonicalRequest).digest('hex'),
|
|
113
122
|
].join('\n');
|
|
114
|
-
|
|
123
|
+
this.doLog('String to Sign:', stringToSign);
|
|
115
124
|
const sign = crypto_1.default.createSign('RSA-SHA256');
|
|
116
125
|
sign.update(stringToSign);
|
|
117
126
|
const signature = sign.sign(this.credentials.private_key, 'hex');
|
|
118
|
-
|
|
127
|
+
this.doLog('Generated Signature:', signature);
|
|
119
128
|
return [`${this.apiEndpoint}/${cfg.file.bucket.name}/${cfg.file.name}?${canonicalQueryString}&X-Goog-Signature=${signature}`];
|
|
120
129
|
}
|
|
121
130
|
}
|