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

Commit

Permalink
feat: support regapic LRO
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 456946341
Source-Link: googleapis/googleapis@88fd18d
Source-Link: https://github.com/googleapis/googleapis-gen/commit/accfa371f667439313335c64042b063c1c53102e
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYWNjZmEzNzFmNjY3NDM5MzEzMzM1YzY0MDQyYjA2M2MxYzUzMTAyZSJ9
PiperOrigin-RevId: 458552034
Source-Link: googleapis/googleapis@ae65014
Source-Link: https://github.com/googleapis/googleapis-gen/commit/b09ede435cce110446d4ab9f62a081b571d37e3f
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjA5ZWRlNDM1Y2NlMTEwNDQ2ZDRhYjlmNjJhMDgxYjU3MWQzN2UzZiJ9
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
  • Loading branch information
3 people authored Jul 5, 2022
1 parent 58abc39 commit 350626e
Show file tree
Hide file tree
Showing 5 changed files with 505 additions and 54 deletions.
11 changes: 5 additions & 6 deletions src/v1/autoscaling_policy_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AutoscalingPolicyServiceClient {
*
* @param {object} [options] - The configuration object.
* The options accepted by the constructor are described in detail
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
* The common options are:
* @param {object} [options.credentials] - Credentials object.
* @param {string} [options.credentials.client_email]
Expand All @@ -94,11 +94,10 @@ export class AutoscalingPolicyServiceClient {
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
* if you need to override this behavior.
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
*/
constructor(opts?: ClientOptions) {
// Ensure that options include all the required fields.
Expand Down
137 changes: 125 additions & 12 deletions src/v1/batch_controller_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CallOptions,
Descriptors,
ClientOptions,
GrpcClientOptions,
LROperation,
PaginationCallback,
GaxCall,
Expand Down Expand Up @@ -72,7 +73,7 @@ export class BatchControllerClient {
*
* @param {object} [options] - The configuration object.
* The options accepted by the constructor are described in detail
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
* The common options are:
* @param {object} [options.credentials] - Credentials object.
* @param {string} [options.credentials.client_email]
Expand All @@ -95,11 +96,10 @@ export class BatchControllerClient {
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
* if you need to override this behavior.
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
*/
constructor(opts?: ClientOptions) {
// Ensure that options include all the required fields.
Expand Down Expand Up @@ -205,16 +205,129 @@ export class BatchControllerClient {
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// This API contains "long-running operations", which return a
// an Operation object that allows for tracking of the operation,
// rather than holding a request open.

const lroOptions: GrpcClientOptions = {
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
};
if (opts.fallback === 'rest') {
lroOptions.protoJson = protoFilesRoot;
lroOptions.httpRules = [
{
selector: 'google.iam.v1.IAMPolicy.GetIamPolicy',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:getIamPolicy',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:getIamPolicy',
body: '*',
},
],
},
{
selector: 'google.iam.v1.IAMPolicy.SetIamPolicy',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:setIamPolicy',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:setIamPolicy',
body: '*',
},
],
},
{
selector: 'google.iam.v1.IAMPolicy.TestIamPermissions',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:testIamPermissions',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:testIamPermissions',
body: '*',
},
],
},
{
selector: 'google.longrunning.Operations.CancelOperation',
post: '/v1/{name=projects/*/regions/*/operations/*}:cancel',
},
{
selector: 'google.longrunning.Operations.DeleteOperation',
delete: '/v1/{name=projects/*/regions/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.GetOperation',
get: '/v1/{name=projects/*/regions/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.ListOperations',
get: '/v1/{name=projects/*/regions/*/operations}',
},
];
}
this.operationsClient = this._gaxModule
.lro({
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
})
.lro(lroOptions)
.operationsClient(opts);
const createBatchResponse = protoFilesRoot.lookup(
'.google.cloud.dataproc.v1.Batch'
Expand Down
137 changes: 125 additions & 12 deletions src/v1/cluster_controller_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
CallOptions,
Descriptors,
ClientOptions,
GrpcClientOptions,
LROperation,
PaginationCallback,
GaxCall,
Expand Down Expand Up @@ -73,7 +74,7 @@ export class ClusterControllerClient {
*
* @param {object} [options] - The configuration object.
* The options accepted by the constructor are described in detail
* in [this document](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#creating-the-client-instance).
* in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
* The common options are:
* @param {object} [options.credentials] - Credentials object.
* @param {string} [options.credentials.client_email]
Expand All @@ -96,11 +97,10 @@ export class ClusterControllerClient {
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
* if you need to override this behavior.
* @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
* Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
* For more information, please check the
* {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
*/
constructor(opts?: ClientOptions) {
// Ensure that options include all the required fields.
Expand Down Expand Up @@ -203,16 +203,129 @@ export class ClusterControllerClient {
};

const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);

// This API contains "long-running operations", which return a
// an Operation object that allows for tracking of the operation,
// rather than holding a request open.

const lroOptions: GrpcClientOptions = {
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
};
if (opts.fallback === 'rest') {
lroOptions.protoJson = protoFilesRoot;
lroOptions.httpRules = [
{
selector: 'google.iam.v1.IAMPolicy.GetIamPolicy',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:getIamPolicy',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:getIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:getIamPolicy',
body: '*',
},
],
},
{
selector: 'google.iam.v1.IAMPolicy.SetIamPolicy',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:setIamPolicy',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:setIamPolicy',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:setIamPolicy',
body: '*',
},
],
},
{
selector: 'google.iam.v1.IAMPolicy.TestIamPermissions',
post: '/v1/{resource=projects/*/regions/*/clusters/*}:testIamPermissions',
body: '*',
additional_bindings: [
{
post: '/v1/{resource=projects/*/regions/*/jobs/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/operations/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/workflowTemplates/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/workflowTemplates/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/regions/*/autoscalingPolicies/*}:testIamPermissions',
body: '*',
},
{
post: '/v1/{resource=projects/*/locations/*/autoscalingPolicies/*}:testIamPermissions',
body: '*',
},
],
},
{
selector: 'google.longrunning.Operations.CancelOperation',
post: '/v1/{name=projects/*/regions/*/operations/*}:cancel',
},
{
selector: 'google.longrunning.Operations.DeleteOperation',
delete: '/v1/{name=projects/*/regions/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.GetOperation',
get: '/v1/{name=projects/*/regions/*/operations/*}',
},
{
selector: 'google.longrunning.Operations.ListOperations',
get: '/v1/{name=projects/*/regions/*/operations}',
},
];
}
this.operationsClient = this._gaxModule
.lro({
auth: this.auth,
grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
})
.lro(lroOptions)
.operationsClient(opts);
const createClusterResponse = protoFilesRoot.lookup(
'.google.cloud.dataproc.v1.Cluster'
Expand Down
Loading

0 comments on commit 350626e

Please sign in to comment.