Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 1a369b4

Browse files
feat: support regapic LRO (#140)
* feat: support regapic LRO Use gapic-generator-typescript v2.15.1. PiperOrigin-RevId: 456946341 Source-Link: googleapis/googleapis@88fd18d Source-Link: https://github.com/googleapis/googleapis-gen/commit/accfa371f667439313335c64042b063c1c53102e Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWNjZmEzNzFmNjY3NDM5MzEzMzM1YzY0MDQyYjA2M2MxYzUzMTAyZSJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 7697186 commit 1a369b4

2 files changed

Lines changed: 155 additions & 24 deletions

File tree

src/v1/hub_service_client.ts

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
26+
GrpcClientOptions,
2627
LROperation,
2728
PaginationCallback,
2829
GaxCall,
@@ -74,7 +75,7 @@ export class HubServiceClient {
7475
*
7576
* @param {object} [options] - The configuration object.
7677
* The options accepted by the constructor are described in detail
77-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
78+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7879
* The common options are:
7980
* @param {object} [options.credentials] - Credentials object.
8081
* @param {string} [options.credentials.client_email]
@@ -97,11 +98,10 @@ export class HubServiceClient {
9798
* API remote host.
9899
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
99100
* Follows the structure of {@link gapicConfig}.
100-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
101-
* In fallback mode, a special browser-compatible transport implementation is used
102-
* instead of gRPC transport. In browser context (if the `window` object is defined)
103-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
104-
* if you need to override this behavior.
101+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
102+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
103+
* For more information, please check the
104+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
105105
*/
106106
constructor(opts?: ClientOptions) {
107107
// Ensure that options include all the required fields.
@@ -208,16 +208,87 @@ export class HubServiceClient {
208208
};
209209

210210
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
211-
212211
// This API contains "long-running operations", which return a
213212
// an Operation object that allows for tracking of the operation,
214213
// rather than holding a request open.
215-
214+
const lroOptions: GrpcClientOptions = {
215+
auth: this.auth,
216+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
217+
};
218+
if (opts.fallback === 'rest') {
219+
lroOptions.protoJson = protoFilesRoot;
220+
lroOptions.httpRules = [
221+
{
222+
selector: 'google.cloud.location.Locations.GetLocation',
223+
get: '/v1/{name=projects/*/locations/*}',
224+
},
225+
{
226+
selector: 'google.cloud.location.Locations.ListLocations',
227+
get: '/v1/{name=projects/*}/locations',
228+
},
229+
{
230+
selector: 'google.iam.v1.IAMPolicy.GetIamPolicy',
231+
get: '/v1/{resource=projects/*/locations/global/hubs/*}:getIamPolicy',
232+
additional_bindings: [
233+
{
234+
get: '/v1/{resource=projects/*/locations/*/spokes/*}:getIamPolicy',
235+
},
236+
{
237+
get: '/v1/{resource=projects/*/locations/global/policyBasedRoutes/*}:getIamPolicy',
238+
},
239+
],
240+
},
241+
{
242+
selector: 'google.iam.v1.IAMPolicy.SetIamPolicy',
243+
post: '/v1/{resource=projects/*/locations/global/hubs/*}:setIamPolicy',
244+
body: '*',
245+
additional_bindings: [
246+
{
247+
post: '/v1/{resource=projects/*/locations/*/spokes/*}:setIamPolicy',
248+
body: '*',
249+
},
250+
{
251+
post: '/v1/{resource=projects/*/locations/global/policyBasedRoutes/*}:setIamPolicy',
252+
body: '*',
253+
},
254+
],
255+
},
256+
{
257+
selector: 'google.iam.v1.IAMPolicy.TestIamPermissions',
258+
post: '/v1/{resource=projects/*/locations/global/hubs/*}:testIamPermissions',
259+
body: '*',
260+
additional_bindings: [
261+
{
262+
post: '/v1/{resource=projects/*/locations/*/spokes/*}:testIamPermissions',
263+
body: '*',
264+
},
265+
{
266+
post: '/v1/{resource=projects/*/locations/global/policyBasedRoutes/*}:testIamPermissions',
267+
body: '*',
268+
},
269+
],
270+
},
271+
{
272+
selector: 'google.longrunning.Operations.CancelOperation',
273+
post: '/v1/{name=projects/*/locations/*/operations/*}:cancel',
274+
body: '*',
275+
},
276+
{
277+
selector: 'google.longrunning.Operations.DeleteOperation',
278+
delete: '/v1/{name=projects/*/locations/*/operations/*}',
279+
},
280+
{
281+
selector: 'google.longrunning.Operations.GetOperation',
282+
get: '/v1/{name=projects/*/locations/*/operations/*}',
283+
},
284+
{
285+
selector: 'google.longrunning.Operations.ListOperations',
286+
get: '/v1/{name=projects/*/locations/*}/operations',
287+
},
288+
];
289+
}
216290
this.operationsClient = this._gaxModule
217-
.lro({
218-
auth: this.auth,
219-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
220-
})
291+
.lro(lroOptions)
221292
.operationsClient(opts);
222293
const createHubResponse = protoFilesRoot.lookup(
223294
'.google.cloud.networkconnectivity.v1.Hub'

src/v1alpha1/hub_service_client.ts

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
CallOptions,
2424
Descriptors,
2525
ClientOptions,
26+
GrpcClientOptions,
2627
LROperation,
2728
PaginationCallback,
2829
GaxCall,
@@ -75,7 +76,7 @@ export class HubServiceClient {
7576
*
7677
* @param {object} [options] - The configuration object.
7778
* The options accepted by the constructor are described in detail
78-
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
79+
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
7980
* The common options are:
8081
* @param {object} [options.credentials] - Credentials object.
8182
* @param {string} [options.credentials.client_email]
@@ -98,11 +99,10 @@ export class HubServiceClient {
9899
* API remote host.
99100
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
100101
* Follows the structure of {@link gapicConfig}.
101-
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
102-
* In fallback mode, a special browser-compatible transport implementation is used
103-
* instead of gRPC transport. In browser context (if the `window` object is defined)
104-
* the fallback mode is enabled automatically; set `options.fallback` to `false`
105-
* if you need to override this behavior.
102+
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
103+
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
104+
* For more information, please check the
105+
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
106106
*/
107107
constructor(opts?: ClientOptions) {
108108
// Ensure that options include all the required fields.
@@ -206,16 +206,76 @@ export class HubServiceClient {
206206
};
207207

208208
const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
209-
210209
// This API contains "long-running operations", which return a
211210
// an Operation object that allows for tracking of the operation,
212211
// rather than holding a request open.
213-
212+
const lroOptions: GrpcClientOptions = {
213+
auth: this.auth,
214+
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
215+
};
216+
if (opts.fallback === 'rest') {
217+
lroOptions.protoJson = protoFilesRoot;
218+
lroOptions.httpRules = [
219+
{
220+
selector: 'google.cloud.location.Locations.GetLocation',
221+
get: '/v1alpha1/{name=projects/*/locations/*}',
222+
},
223+
{
224+
selector: 'google.cloud.location.Locations.ListLocations',
225+
get: '/v1alpha1/{name=projects/*}/locations',
226+
},
227+
{
228+
selector: 'google.iam.v1.IAMPolicy.GetIamPolicy',
229+
get: '/v1alpha1/{resource=projects/*/locations/global/hubs/*}:getIamPolicy',
230+
additional_bindings: [
231+
{
232+
get: '/v1alpha1/{resource=projects/*/locations/*/spokes/*}:getIamPolicy',
233+
},
234+
],
235+
},
236+
{
237+
selector: 'google.iam.v1.IAMPolicy.SetIamPolicy',
238+
post: '/v1alpha1/{resource=projects/*/locations/global/hubs/*}:setIamPolicy',
239+
body: '*',
240+
additional_bindings: [
241+
{
242+
post: '/v1alpha1/{resource=projects/*/locations/*/spokes/*}:setIamPolicy',
243+
body: '*',
244+
},
245+
],
246+
},
247+
{
248+
selector: 'google.iam.v1.IAMPolicy.TestIamPermissions',
249+
post: '/v1alpha1/{resource=projects/*/locations/global/hubs/*}:testIamPermissions',
250+
body: '*',
251+
additional_bindings: [
252+
{
253+
post: '/v1alpha1/{resource=projects/*/locations/*/spokes/*}:testIamPermissions',
254+
body: '*',
255+
},
256+
],
257+
},
258+
{
259+
selector: 'google.longrunning.Operations.CancelOperation',
260+
post: '/v1alpha1/{name=projects/*/locations/*/operations/*}:cancel',
261+
body: '*',
262+
},
263+
{
264+
selector: 'google.longrunning.Operations.DeleteOperation',
265+
delete: '/v1alpha1/{name=projects/*/locations/*/operations/*}',
266+
},
267+
{
268+
selector: 'google.longrunning.Operations.GetOperation',
269+
get: '/v1alpha1/{name=projects/*/locations/*/operations/*}',
270+
},
271+
{
272+
selector: 'google.longrunning.Operations.ListOperations',
273+
get: '/v1alpha1/{name=projects/*/locations/*}/operations',
274+
},
275+
];
276+
}
214277
this.operationsClient = this._gaxModule
215-
.lro({
216-
auth: this.auth,
217-
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
218-
})
278+
.lro(lroOptions)
219279
.operationsClient(opts);
220280
const createHubResponse = protoFilesRoot.lookup(
221281
'.google.cloud.networkconnectivity.v1alpha1.Hub'

0 commit comments

Comments
 (0)