Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit cf6f787

Browse files
samples: set client endpoint (#1812)
* samples: set client endpoint * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * removed unused variable * updated comment * added test for sample * updated header * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * fixed typo Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent ac786c3 commit cf6f787

5 files changed

Lines changed: 98 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-storage/tre
189189
| Remove Retention Policy | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/removeRetentionPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/removeRetentionPolicy.js,samples/README.md) |
190190
| Rename File | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/renameFile.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/renameFile.js,samples/README.md) |
191191
| Rotate Encryption Key | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/rotateEncryptionKey.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/rotateEncryptionKey.js,samples/README.md) |
192+
| Set Client Endpoint | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setClientEndpoint.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setClientEndpoint.js,samples/README.md) |
192193
| Set Event Based Hold | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setEventBasedHold.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setEventBasedHold.js,samples/README.md) |
193194
| Set Public Access Prevention Enforced | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionEnforced.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionEnforced.js,samples/README.md) |
194195
| Set Public Access Prevention Inherited | [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setPublicAccessPreventionInherited.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setPublicAccessPreventionInherited.js,samples/README.md) |

samples/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ objects to users via direct download.
108108
* [Remove Retention Policy](#remove-retention-policy)
109109
* [Rename File](#rename-file)
110110
* [Rotate Encryption Key](#rotate-encryption-key)
111+
* [Set Client Endpoint](#set-client-endpoint)
111112
* [Set Event Based Hold](#set-event-based-hold)
112113
* [Set Public Access Prevention Enforced](#set-public-access-prevention-enforced)
113114
* [Set Public Access Prevention Inherited](#set-public-access-prevention-inherited)
@@ -1725,6 +1726,23 @@ __Usage:__
17251726

17261727

17271728

1729+
### Set Client Endpoint
1730+
1731+
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setClientEndpoint.js).
1732+
1733+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-storage&page=editor&open_in_editor=samples/setClientEndpoint.js,samples/README.md)
1734+
1735+
__Usage:__
1736+
1737+
1738+
`node samples/setClientEndpoint.js`
1739+
1740+
1741+
-----
1742+
1743+
1744+
1745+
17281746
### Set Event Based Hold
17291747

17301748
View the [source code](https://github.com/googleapis/nodejs-storage/blob/main/samples/setEventBasedHold.js).

samples/setClientEndpoint.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* This application demonstrates set a custom endpoint with
17+
* the Google Cloud Storage API.
18+
*
19+
* For more information, see the README.md under /storage and the documentation
20+
* at https://cloud.google.com/storage/docs.
21+
*/
22+
23+
function main(apiEndpoint = 'https://storage.googleapis.com') {
24+
// [START storage_set_client_endpoint]
25+
/**
26+
* TODO(developer): Uncomment the following lines before running the sample.
27+
*/
28+
// The custom endpoint to which requests should be made
29+
// const apiEndpoint = 'https://yourcustomendpoint.com';
30+
31+
// Imports the Google Cloud client library
32+
const {Storage} = require('@google-cloud/storage');
33+
34+
// Creates a client
35+
const storage = new Storage({
36+
apiEndpoint: apiEndpoint,
37+
useAuthWithCustomEndpoint: true,
38+
});
39+
40+
console.log(`Client initiated with endpoint: ${storage.apiEndpoint}.`);
41+
42+
// [END storage_set_client_endpoint]
43+
}
44+
process.on('unhandledRejection', err => {
45+
console.error(err.message);
46+
process.exitCode = 1;
47+
});
48+
main(...process.argv.slice(2));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {it} = require('mocha');
19+
const cp = require('child_process');
20+
21+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
22+
23+
it('should intialize storage with a custom api endpoint', async () => {
24+
const apiEndpoint = 'https://storage.googleapis.com';
25+
const output = execSync(`node setClientEndpoint.js ${apiEndpoint}`);
26+
assert.match(
27+
output,
28+
new RegExp(`Client initiated with endpoint: ${apiEndpoint}.`)
29+
);
30+
});

src/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ export class Storage extends Service {
540540
* @property {number} [timeout] The amount of time in milliseconds to wait per http request before timing out.
541541
* @property {object[]} [interceptors_] Array of custom request interceptors to be returned in the order they were assigned.
542542
* @property {string} [apiEndpoint = storage.google.com] The API endpoint of the service used to make requests.
543-
* @property {boolean} [useAuthWithCustomEndpoint] Controls whether or not to use authentication when using a custom endpoint.
543+
* @property {boolean} [useAuthWithCustomEndpoint = false] Controls whether or not to use authentication when using a custom endpoint.
544544
*/
545545
/**
546546
* Constructs the Storage client.

0 commit comments

Comments
 (0)