Skip to content

Commit 6ec9438

Browse files
thiyaguk09release-please[bot]gcf-owl-bot[bot]danielduhhjjaareet
authored
fix: Improve projectId handling in authentication (#2584)
* feat: add ability to configure and utilize soft-delete and restore buckets (#2566) * Adds support for the restore token feature * description fix * lint fix * fetch softDeleted bucket list & details fetch softDeleted bucket list & details * initial commit for bucket restore initial commit for bucket restore * fix missing license headers fix missing license headers * lint fix * test case bug fix * added restore bucket unit test cases * added restore bucket system test added restore bucket system test * lint fix * format format * system test fix * chore(main): release 7.15.0 (#2568) * chore(main): release 7.15.0 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> * docs: replace reference docs link with RAD (#2571) * fix(getFiles): add nextPageToken to fields for autoPaginate (#2570) * chore: fix type errors in build (#2577) * chore: fix type errors in build * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix docs links --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> * chore(main): release 7.15.1 (#2573) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * fix: export SaveData type from index.ts (#2580) * chore(main): release 7.15.2 (#2581) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> * chore: set gcs-sdk-team as CODEOWNERS (#2582) * Set CODEOWNERS as gcs-sdk-team * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * update repo metadata with new team * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fix broken types causing compilation failures --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Denis DelGrosso <ddelgrosso@google.com> * fix: Improve projectId handling in authentication Improve projectId handling in authentication and resolve issue in patch request * bug fix --------- Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Daniel B <danielduhh@gmail.com> Co-authored-by: Jarrett <2613089+jjaareet@users.noreply.github.com> Co-authored-by: Denis DelGrosso <85250797+ddelgrosso1@users.noreply.github.com> Co-authored-by: David Stensland <me@terite.com> Co-authored-by: Denis DelGrosso <ddelgrosso@google.com>
1 parent b1ea781 commit 6ec9438

15 files changed

Lines changed: 85 additions & 39 deletions

File tree

handwritten/storage/.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77

88
# Unless specified, the jsteam is the default owner for nodejs repositories.
9-
* @googleapis/cloud-storage-dpe @googleapis/jsteam
9+
* @googleapis/gcs-sdk-team @googleapis/jsteam

handwritten/storage/.repo-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"distribution_name": "@google-cloud/storage",
1111
"api_id": "storage-api.googleapis.com",
1212
"requires_billing": true,
13-
"codeowner_team": "@googleapis/cloud-storage-dpe",
13+
"codeowner_team": "@googleapis/gcs-sdk-team",
1414
"api_shortname": "storage",
1515
"library_type": "GAPIC_MANUAL"
1616
}

handwritten/storage/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
[1]: https://www.npmjs.com/package/@google-cloud/storage?activeTab=versions
66

7+
## [7.15.2](https://github.com/googleapis/nodejs-storage/compare/v7.15.1...v7.15.2) (2025-02-20)
8+
9+
10+
### Bug Fixes
11+
12+
* Export SaveData type from index.ts ([#2580](https://github.com/googleapis/nodejs-storage/issues/2580)) ([dbf510c](https://github.com/googleapis/nodejs-storage/commit/dbf510c08f28c720ba66268eea6a62e139179ab4))
13+
714
## [7.15.1](https://github.com/googleapis/nodejs-storage/compare/v7.15.0...v7.15.1) (2025-02-11)
815

916

handwritten/storage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@google-cloud/storage",
33
"description": "Cloud Storage Client Library for Node.js",
4-
"version": "7.15.1",
4+
"version": "7.15.2",
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
77
"engines": {

handwritten/storage/samples/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@google-cloud/pubsub": "^4.0.0",
20-
"@google-cloud/storage": "^7.15.1",
20+
"@google-cloud/storage": "^7.15.2",
2121
"node-fetch": "^2.6.7",
2222
"uuid": "^8.0.0",
2323
"yargs": "^16.0.0"

handwritten/storage/src/bucket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ class Bucket extends ServiceObject<Bucket, BucketMetadata> {
20242024
const body = Object.assign({topic}, options);
20252025

20262026
if (body.topic.indexOf('projects') !== 0) {
2027-
body.topic = 'projects/{{projectId}}/topics/' + body.topic;
2027+
body.topic = `projects/${this.storage.projectId}/topics/` + body.topic;
20282028
}
20292029

20302030
body.topic = `//pubsub.${this.storage.universeDomain}/` + body.topic;

handwritten/storage/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export {
220220
RotateEncryptionKeyOptions,
221221
RotateEncryptionKeyResponse,
222222
SaveCallback,
223+
SaveData,
223224
SaveOptions,
224225
SetFileMetadataCallback,
225226
SetFileMetadataOptions,

handwritten/storage/src/nodejs-common/service-object.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,14 +506,17 @@ class ServiceObject<T, K extends BaseMetadata> extends EventEmitter {
506506
responseType: 'json',
507507
url,
508508
...methodConfig.reqOpts,
509-
body: {
509+
body: JSON.stringify({
510510
...methodConfig.reqOpts?.body,
511511
...metadata,
512-
},
512+
}),
513513
queryParameters: {
514514
...methodConfig.reqOpts?.queryParameters,
515515
...options,
516516
},
517+
headers: {
518+
'Content-Type': 'application/json',
519+
},
517520
},
518521
(err, data, resp) => {
519522
this.metadata = data!;

handwritten/storage/src/resumable-upload.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,19 @@ export class Upload extends Writable {
421421
this.isPartialUpload = cfg.isPartialUpload ?? false;
422422

423423
if (cfg.key) {
424-
const base64Key = Buffer.from(cfg.key).toString('base64');
425-
this.encryption = {
426-
key: base64Key,
427-
hash: createHash('sha256').update(cfg.key).digest('base64'),
428-
};
424+
if (typeof cfg.key === 'string') {
425+
const base64Key = Buffer.from(cfg.key).toString('base64');
426+
this.encryption = {
427+
key: base64Key,
428+
hash: createHash('sha256').update(cfg.key).digest('base64'),
429+
};
430+
} else {
431+
const base64Key = cfg.key.toString('base64');
432+
this.encryption = {
433+
key: base64Key,
434+
hash: createHash('sha256').update(cfg.key).digest('base64'),
435+
};
436+
}
429437
}
430438

431439
this.predefinedAcl = cfg.predefinedAcl;

handwritten/storage/src/storage-transport.ts

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface StorageTransportCallback<T> {
9090
fullResponse?: GaxiosResponse,
9191
): void;
9292
}
93+
let projectId: string;
9394

9495
export class StorageTransport {
9596
authClient: GoogleAuth<AuthClient>;
@@ -98,6 +99,7 @@ export class StorageTransport {
9899
private retryOptions: RetryOptions;
99100
private baseUrl: string;
100101
private timeout?: number;
102+
private projectId?: string;
101103
private useAuthWithCustomEndpoint?: boolean;
102104

103105
constructor(options: TransportParameters) {
@@ -115,6 +117,7 @@ export class StorageTransport {
115117
this.retryOptions = options.retryOptions;
116118
this.baseUrl = options.baseUrl;
117119
this.timeout = options.timeout;
120+
this.projectId = options.projectId;
118121
this.useAuthWithCustomEndpoint = options.useAuthWithCustomEndpoint;
119122
}
120123

@@ -134,19 +137,39 @@ export class StorageTransport {
134137
transport.instance.interceptors.request.add(inter);
135138
}
136139
}
137-
const requestPromise = this.authClient.request<T>({
138-
retryConfig: {
139-
retry: this.retryOptions.maxRetries,
140-
noResponseRetries: this.retryOptions.maxRetries,
141-
maxRetryDelay: this.retryOptions.maxRetryDelay,
142-
retryDelayMultiplier: this.retryOptions.retryDelayMultiplier,
143-
shouldRetry: this.retryOptions.retryableErrorFn,
144-
totalTimeout: this.retryOptions.totalTimeout,
145-
},
146-
...reqOpts,
147-
headers,
148-
url: this.#buildUrl(reqOpts.url?.toString(), reqOpts.queryParameters),
149-
timeout: this.timeout,
140+
const prepareRequest = async () => {
141+
try {
142+
const getProjectId = async () => {
143+
if (reqOpts.projectId) return reqOpts.projectId;
144+
projectId = await this.authClient.getProjectId();
145+
return projectId;
146+
};
147+
const _projectId = await getProjectId();
148+
if (_projectId) {
149+
projectId = _projectId;
150+
this.projectId = projectId;
151+
}
152+
return projectId;
153+
} catch (e) {
154+
if (callback) return callback(e as GaxiosError);
155+
throw e;
156+
}
157+
};
158+
const requestPromise = prepareRequest().then(() => {
159+
return this.authClient.request<T>({
160+
retryConfig: {
161+
retry: this.retryOptions.maxRetries,
162+
noResponseRetries: this.retryOptions.maxRetries,
163+
maxRetryDelay: this.retryOptions.maxRetryDelay,
164+
retryDelayMultiplier: this.retryOptions.retryDelayMultiplier,
165+
shouldRetry: this.retryOptions.retryableErrorFn,
166+
totalTimeout: this.retryOptions.totalTimeout,
167+
},
168+
...reqOpts,
169+
headers,
170+
url: this.#buildUrl(reqOpts.url?.toString(), reqOpts.queryParameters),
171+
timeout: this.timeout,
172+
});
150173
});
151174

152175
return callback
@@ -157,6 +180,13 @@ export class StorageTransport {
157180
}
158181

159182
#buildUrl(pathUri = '', queryParameters: StorageQueryParameters = {}): URL {
183+
if (
184+
'project' in queryParameters &&
185+
(queryParameters.project !== this.projectId ||
186+
queryParameters.project !== projectId)
187+
) {
188+
queryParameters.project = this.projectId;
189+
}
160190
const qp = this.#buildRequestQueryParams(queryParameters);
161191
let url: URL;
162192
if (this.#isValidUrl(pathUri)) {

0 commit comments

Comments
 (0)