From acdb6e43ef6f7b0bad0798c48bfac519d68e1097 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 20 Aug 2021 23:07:11 +0000 Subject: [PATCH 1/2] feat: turns on self-signed JWT feature flag PiperOrigin-RevId: 392067151 Source-Link: https://github.com/googleapis/googleapis/commit/06345f7b95c4b4a3ffe4303f1f2984ccc304b2e0 Source-Link: https://github.com/googleapis/googleapis-gen/commit/95882b37970e41e4cd51b22fa507cfd46dc7c4b6 --- owl-bot-staging/v2/.eslintignore | 6 + owl-bot-staging/v2/.eslintrc.json | 3 + owl-bot-staging/v2/.gitignore | 14 + owl-bot-staging/v2/.jsdoc.js | 55 + owl-bot-staging/v2/.mocharc.js | 33 + owl-bot-staging/v2/.prettierrc.js | 22 + owl-bot-staging/v2/README.md | 1 + owl-bot-staging/v2/linkinator.config.json | 10 + owl-bot-staging/v2/package.json | 64 + .../cloud/orgpolicy/v2/constraint.proto | 127 ++ .../google/cloud/orgpolicy/v2/orgpolicy.proto | 479 ++++++ owl-bot-staging/v2/src/index.ts | 25 + owl-bot-staging/v2/src/v2/gapic_metadata.json | 101 ++ owl-bot-staging/v2/src/v2/index.ts | 19 + .../v2/src/v2/org_policy_client.ts | 1385 +++++++++++++++++ .../v2/src/v2/org_policy_client_config.json | 70 + .../v2/src/v2/org_policy_proto_list.json | 4 + .../system-test/fixtures/sample/src/index.js | 27 + .../system-test/fixtures/sample/src/index.ts | 32 + owl-bot-staging/v2/system-test/install.ts | 49 + .../v2/test/gapic_org_policy_v2.ts | 1297 +++++++++++++++ owl-bot-staging/v2/tsconfig.json | 19 + owl-bot-staging/v2/webpack.config.js | 64 + 23 files changed, 3906 insertions(+) create mode 100644 owl-bot-staging/v2/.eslintignore create mode 100644 owl-bot-staging/v2/.eslintrc.json create mode 100644 owl-bot-staging/v2/.gitignore create mode 100644 owl-bot-staging/v2/.jsdoc.js create mode 100644 owl-bot-staging/v2/.mocharc.js create mode 100644 owl-bot-staging/v2/.prettierrc.js create mode 100644 owl-bot-staging/v2/README.md create mode 100644 owl-bot-staging/v2/linkinator.config.json create mode 100644 owl-bot-staging/v2/package.json create mode 100644 owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto create mode 100644 owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto create mode 100644 owl-bot-staging/v2/src/index.ts create mode 100644 owl-bot-staging/v2/src/v2/gapic_metadata.json create mode 100644 owl-bot-staging/v2/src/v2/index.ts create mode 100644 owl-bot-staging/v2/src/v2/org_policy_client.ts create mode 100644 owl-bot-staging/v2/src/v2/org_policy_client_config.json create mode 100644 owl-bot-staging/v2/src/v2/org_policy_proto_list.json create mode 100644 owl-bot-staging/v2/system-test/fixtures/sample/src/index.js create mode 100644 owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts create mode 100644 owl-bot-staging/v2/system-test/install.ts create mode 100644 owl-bot-staging/v2/test/gapic_org_policy_v2.ts create mode 100644 owl-bot-staging/v2/tsconfig.json create mode 100644 owl-bot-staging/v2/webpack.config.js diff --git a/owl-bot-staging/v2/.eslintignore b/owl-bot-staging/v2/.eslintignore new file mode 100644 index 0000000..521dc25 --- /dev/null +++ b/owl-bot-staging/v2/.eslintignore @@ -0,0 +1,6 @@ +**/node_modules +**/.coverage +build/ +docs/ +protos/ +system-test/ diff --git a/owl-bot-staging/v2/.eslintrc.json b/owl-bot-staging/v2/.eslintrc.json new file mode 100644 index 0000000..7821534 --- /dev/null +++ b/owl-bot-staging/v2/.eslintrc.json @@ -0,0 +1,3 @@ +{ + "extends": "./node_modules/gts" +} diff --git a/owl-bot-staging/v2/.gitignore b/owl-bot-staging/v2/.gitignore new file mode 100644 index 0000000..5d32b23 --- /dev/null +++ b/owl-bot-staging/v2/.gitignore @@ -0,0 +1,14 @@ +**/*.log +**/node_modules +.coverage +coverage +.nyc_output +docs/ +out/ +build/ +system-test/secrets.js +system-test/*key.json +*.lock +.DS_Store +package-lock.json +__pycache__ diff --git a/owl-bot-staging/v2/.jsdoc.js b/owl-bot-staging/v2/.jsdoc.js new file mode 100644 index 0000000..fed1fe0 --- /dev/null +++ b/owl-bot-staging/v2/.jsdoc.js @@ -0,0 +1,55 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +'use strict'; + +module.exports = { + opts: { + readme: './README.md', + package: './package.json', + template: './node_modules/jsdoc-fresh', + recurse: true, + verbose: true, + destination: './docs/' + }, + plugins: [ + 'plugins/markdown', + 'jsdoc-region-tag' + ], + source: { + excludePattern: '(^|\\/|\\\\)[._]', + include: [ + 'build/src', + 'protos' + ], + includePattern: '\\.js$' + }, + templates: { + copyright: 'Copyright 2021 Google LLC', + includeDate: false, + sourceFiles: false, + systemName: '@google-cloud/org-policy', + theme: 'lumen', + default: { + outputSourceFiles: false + } + }, + markdown: { + idInHeadings: true + } +}; diff --git a/owl-bot-staging/v2/.mocharc.js b/owl-bot-staging/v2/.mocharc.js new file mode 100644 index 0000000..50bc7f7 --- /dev/null +++ b/owl-bot-staging/v2/.mocharc.js @@ -0,0 +1,33 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +const config = { + "enable-source-maps": true, + "throw-deprecation": true, + "timeout": 10000 +} +if (process.env.MOCHA_THROW_DEPRECATION === 'false') { + delete config['throw-deprecation']; +} +if (process.env.MOCHA_REPORTER) { + config.reporter = process.env.MOCHA_REPORTER; +} +if (process.env.MOCHA_REPORTER_OUTPUT) { + config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; +} +module.exports = config diff --git a/owl-bot-staging/v2/.prettierrc.js b/owl-bot-staging/v2/.prettierrc.js new file mode 100644 index 0000000..84f4713 --- /dev/null +++ b/owl-bot-staging/v2/.prettierrc.js @@ -0,0 +1,22 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +module.exports = { + ...require('gts/.prettierrc.json') +} diff --git a/owl-bot-staging/v2/README.md b/owl-bot-staging/v2/README.md new file mode 100644 index 0000000..1c081c6 --- /dev/null +++ b/owl-bot-staging/v2/README.md @@ -0,0 +1 @@ +Orgpolicy: Nodejs Client diff --git a/owl-bot-staging/v2/linkinator.config.json b/owl-bot-staging/v2/linkinator.config.json new file mode 100644 index 0000000..29a223b --- /dev/null +++ b/owl-bot-staging/v2/linkinator.config.json @@ -0,0 +1,10 @@ +{ + "recurse": true, + "skip": [ + "https://codecov.io/gh/googleapis/", + "www.googleapis.com", + "img.shields.io" + ], + "silent": true, + "concurrency": 10 +} diff --git a/owl-bot-staging/v2/package.json b/owl-bot-staging/v2/package.json new file mode 100644 index 0000000..e16c9ca --- /dev/null +++ b/owl-bot-staging/v2/package.json @@ -0,0 +1,64 @@ +{ + "name": "@google-cloud/org-policy", + "version": "0.1.0", + "description": "Orgpolicy client for Node.js", + "repository": "googleapis/nodejs-orgpolicy", + "license": "Apache-2.0", + "author": "Google LLC", + "main": "build/src/index.js", + "files": [ + "build/src", + "build/protos" + ], + "keywords": [ + "google apis client", + "google api client", + "google apis", + "google api", + "google", + "google cloud platform", + "google cloud", + "cloud", + "google orgpolicy", + "orgpolicy", + "org policy" + ], + "scripts": { + "clean": "gts clean", + "compile": "tsc -p . && cp -r protos build/", + "compile-protos": "compileProtos src", + "docs": "jsdoc -c .jsdoc.js", + "predocs-test": "npm run docs", + "docs-test": "linkinator docs", + "fix": "gts fix", + "lint": "gts check", + "prepare": "npm run compile-protos && npm run compile", + "system-test": "c8 mocha build/system-test", + "test": "c8 mocha build/test" + }, + "dependencies": { + "google-gax": "^2.19.0" + }, + "devDependencies": { + "@types/mocha": "^9.0.0", + "@types/node": "^14.17.3", + "@types/sinon": "^10.0.2", + "c8": "^7.7.3", + "gts": "^3.1.0", + "jsdoc": "^3.6.7", + "jsdoc-fresh": "^1.1.0", + "jsdoc-region-tag": "^1.1.0", + "linkinator": "^2.13.6", + "mocha": "^9.0.2", + "null-loader": "^4.0.1", + "pack-n-play": "^1.0.0-2", + "sinon": "^11.1.1", + "ts-loader": "^9.2.3", + "typescript": "^4.3.4", + "webpack": "^5.39.1", + "webpack-cli": "^4.7.2" + }, + "engines": { + "node": ">=v10.24.0" + } +} diff --git a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto new file mode 100644 index 0000000..a9051ac --- /dev/null +++ b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto @@ -0,0 +1,127 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.cloud.orgpolicy.v2; + +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; + +option csharp_namespace = "Google.Cloud.OrgPolicy.V2"; +option go_package = "google.golang.org/genproto/googleapis/cloud/orgpolicy/v2;orgpolicy"; +option java_multiple_files = true; +option java_outer_classname = "ConstraintProto"; +option java_package = "com.google.cloud.orgpolicy.v2"; +option php_namespace = "Google\\Cloud\\OrgPolicy\\V2"; +option ruby_package = "Google::Cloud::OrgPolicy::V2"; + +// A `constraint` describes a way to restrict resource's configuration. For +// example, you could enforce a constraint that controls which cloud services +// can be activated across an organization, or whether a Compute Engine instance +// can have serial port connections established. `Constraints` can be configured +// by the organization's policy adminstrator to fit the needs of the organzation +// by setting a `policy` that includes `constraints` at different locations in +// the organization's resource hierarchy. Policies are inherited down the +// resource hierarchy from higher levels, but can also be overridden. For +// details about the inheritance rules please read about +// [`policies`][google.cloud.OrgPolicy.v2.Policy]. +// +// `Constraints` have a default behavior determined by the `constraint_default` +// field, which is the enforcement behavior that is used in the absence of a +// `policy` being defined or inherited for the resource in question. +message Constraint { + option (google.api.resource) = { + type: "orgpolicy.googleapis.com/Constraint" + pattern: "projects/{project}/constraints/{constraint}" + pattern: "folders/{folder}/constraints/{constraint}" + pattern: "organizations/{organization}/constraints/{constraint}" + }; + + // A `Constraint` that allows or disallows a list of string values, which are + // configured by an Organization's policy administrator with a `Policy`. + message ListConstraint { + // Indicates whether values grouped into categories can be used in + // `Policy.allowed_values` and `Policy.denied_values`. For example, + // `"in:Python"` would match any value in the 'Python' group. + bool supports_in = 1; + + // Indicates whether subtrees of Cloud Resource Manager resource hierarchy + // can be used in `Policy.allowed_values` and `Policy.denied_values`. For + // example, `"under:folders/123"` would match any resource under the + // 'folders/123' folder. + bool supports_under = 2; + } + + // A `Constraint` that is either enforced or not. + // + // For example a constraint `constraints/compute.disableSerialPortAccess`. + // If it is enforced on a VM instance, serial port connections will not be + // opened to that instance. + message BooleanConstraint { + + } + + // Specifies the default behavior in the absence of any `Policy` for the + // `Constraint`. This must not be `CONSTRAINT_DEFAULT_UNSPECIFIED`. + // + // Immutable after creation. + enum ConstraintDefault { + // This is only used for distinguishing unset values and should never be + // used. + CONSTRAINT_DEFAULT_UNSPECIFIED = 0; + + // Indicate that all values are allowed for list constraints. + // Indicate that enforcement is off for boolean constraints. + ALLOW = 1; + + // Indicate that all values are denied for list constraints. + // Indicate that enforcement is on for boolean constraints. + DENY = 2; + } + + // Immutable. The resource name of the Constraint. Must be in one of + // the following forms: + // * `projects/{project_number}/constraints/{constraint_name}` + // * `folders/{folder_id}/constraints/{constraint_name}` + // * `organizations/{organization_id}/constraints/{constraint_name}` + // + // For example, "/projects/123/constraints/compute.disableSerialPortAccess". + string name = 1 [(google.api.field_behavior) = IMMUTABLE]; + + // The human readable name. + // + // Mutable. + string display_name = 2; + + // Detailed description of what this `Constraint` controls as well as how and + // where it is enforced. + // + // Mutable. + string description = 3; + + // The evaluation behavior of this constraint in the absence of 'Policy'. + ConstraintDefault constraint_default = 4; + + // The type of restrictions for this `Constraint`. + // + // Immutable after creation. + oneof constraint_type { + // Defines this constraint as being a ListConstraint. + ListConstraint list_constraint = 5; + + // Defines this constraint as being a BooleanConstraint. + BooleanConstraint boolean_constraint = 6; + } +} diff --git a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto new file mode 100644 index 0000000..2b2bb47 --- /dev/null +++ b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto @@ -0,0 +1,479 @@ +// Copyright 2020 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +package google.cloud.orgpolicy.v2; + +import "google/api/annotations.proto"; +import "google/api/client.proto"; +import "google/api/field_behavior.proto"; +import "google/api/resource.proto"; +import "google/cloud/orgpolicy/v2/constraint.proto"; +import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; +import "google/type/expr.proto"; + +option csharp_namespace = "Google.Cloud.OrgPolicy.V2"; +option go_package = "google.golang.org/genproto/googleapis/cloud/orgpolicy/v2;orgpolicy"; +option java_multiple_files = true; +option java_outer_classname = "OrgPolicyProto"; +option java_package = "com.google.cloud.orgpolicy.v2"; +option php_namespace = "Google\\Cloud\\OrgPolicy\\V2"; +option ruby_package = "Google::Cloud::OrgPolicy::V2"; + +// An interface for managing organization policies. +// +// The Cloud Org Policy service provides a simple mechanism for organizations to +// restrict the allowed configurations across their entire Cloud Resource +// hierarchy. +// +// You can use a `policy` to configure restrictions in Cloud resources. For +// example, you can enforce a `policy` that restricts which Google +// Cloud Platform APIs can be activated in a certain part of your resource +// hierarchy, or prevents serial port access to VM instances in a particular +// folder. +// +// `Policies` are inherited down through the resource hierarchy. A `policy` +// applied to a parent resource automatically applies to all its child resources +// unless overridden with a `policy` lower in the hierarchy. +// +// A `constraint` defines an aspect of a resource's configuration that can be +// controlled by an organization's policy administrator. `Policies` are a +// collection of `constraints` that defines their allowable configuration on a +// particular resource and its child resources. +service OrgPolicy { + option (google.api.default_host) = "orgpolicy.googleapis.com"; + option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; + + // Lists `Constraints` that could be applied on the specified resource. + rpc ListConstraints(ListConstraintsRequest) returns (ListConstraintsResponse) { + option (google.api.http) = { + get: "/v2/{parent=projects/*}/constraints" + additional_bindings { + get: "/v2/{parent=folders/*}/constraints" + } + additional_bindings { + get: "/v2/{parent=organizations/*}/constraints" + } + }; + option (google.api.method_signature) = "parent"; + } + + // Retrieves all of the `Policies` that exist on a particular resource. + rpc ListPolicies(ListPoliciesRequest) returns (ListPoliciesResponse) { + option (google.api.http) = { + get: "/v2/{parent=projects/*}/policies" + additional_bindings { + get: "/v2/{parent=folders/*}/policies" + } + additional_bindings { + get: "/v2/{parent=organizations/*}/policies" + } + }; + option (google.api.method_signature) = "parent"; + } + + // Gets a `Policy` on a resource. + // + // If no `Policy` is set on the resource, NOT_FOUND is returned. The + // `etag` value can be used with `UpdatePolicy()` to update a + // `Policy` during read-modify-write. + rpc GetPolicy(GetPolicyRequest) returns (Policy) { + option (google.api.http) = { + get: "/v2/{name=projects/*/policies/*}" + additional_bindings { + get: "/v2/{name=folders/*/policies/*}" + } + additional_bindings { + get: "/v2/{name=organizations/*/policies/*}" + } + }; + option (google.api.method_signature) = "name"; + } + + // Gets the effective `Policy` on a resource. This is the result of merging + // `Policies` in the resource hierarchy and evaluating conditions. The + // returned `Policy` will not have an `etag` or `condition` set because it is + // a computed `Policy` across multiple resources. + // Subtrees of Resource Manager resource hierarchy with 'under:' prefix will + // not be expanded. + rpc GetEffectivePolicy(GetEffectivePolicyRequest) returns (Policy) { + option (google.api.http) = { + get: "/v2/{name=projects/*/policies/*}:getEffectivePolicy" + additional_bindings { + get: "/v2/{name=folders/*/policies/*}:getEffectivePolicy" + } + additional_bindings { + get: "/v2/{name=organizations/*/policies/*}:getEffectivePolicy" + } + }; + option (google.api.method_signature) = "name"; + } + + // Creates a Policy. + // + // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + // constraint does not exist. + // Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the + // policy already exists on the given Cloud resource. + rpc CreatePolicy(CreatePolicyRequest) returns (Policy) { + option (google.api.http) = { + post: "/v2/{parent=projects/*}/policies" + body: "policy" + additional_bindings { + post: "/v2/{parent=folders/*}/policies" + body: "policy" + } + additional_bindings { + post: "/v2/{parent=organizations/*}/policies" + body: "policy" + } + }; + option (google.api.method_signature) = "parent,policy"; + } + + // Updates a Policy. + // + // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + // constraint or the policy do not exist. + // Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag + // supplied in the request does not match the persisted etag of the policy + // + // Note: the supplied policy will perform a full overwrite of all + // fields. + rpc UpdatePolicy(UpdatePolicyRequest) returns (Policy) { + option (google.api.http) = { + patch: "/v2/{policy.name=projects/*/policies/*}" + body: "policy" + additional_bindings { + patch: "/v2/{policy.name=folders/*/policies/*}" + body: "policy" + } + additional_bindings { + patch: "/v2/{policy.name=organizations/*/policies/*}" + body: "policy" + } + }; + option (google.api.method_signature) = "policy"; + } + + // Deletes a Policy. + // + // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + // constraint or Org Policy does not exist. + rpc DeletePolicy(DeletePolicyRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v2/{name=projects/*/policies/*}" + additional_bindings { + delete: "/v2/{name=folders/*/policies/*}" + } + additional_bindings { + delete: "/v2/{name=organizations/*/policies/*}" + } + }; + option (google.api.method_signature) = "name"; + } +} + +// Defines a Cloud Organization `Policy` which is used to specify `Constraints` +// for configurations of Cloud Platform resources. +message Policy { + option (google.api.resource) = { + type: "orgpolicy.googleapis.com/Policy" + pattern: "projects/{project}/policies/{policy}" + pattern: "folders/{folder}/policies/{policy}" + pattern: "organizations/{organization}/policies/{policy}" + }; + + // Immutable. The resource name of the Policy. Must be one of the following + // forms, where constraint_name is the name of the constraint which this + // Policy configures: + // * `projects/{project_number}/policies/{constraint_name}` + // * `folders/{folder_id}/policies/{constraint_name}` + // * `organizations/{organization_id}/policies/{constraint_name}` + // + // For example, "projects/123/policies/compute.disableSerialPortAccess". + // + // Note: `projects/{project_id}/policies/{constraint_name}` is also an + // acceptable name for API requests, but responses will return the name using + // the equivalent project number. + string name = 1 [(google.api.field_behavior) = IMMUTABLE]; + + // Basic information about the Organization Policy. + PolicySpec spec = 2; + + // An alternate policy configuration that will be used instead of the baseline + // policy configurations as determined by the launch. + // Currently the only way the launch can trigger the alternate configuration + // is via dry-run/darklaunch. + AlternatePolicySpec alternate = 3; +} + +// Similar to PolicySpec but with an extra 'launch' field for launch reference. +// The PolicySpec here is specific for dry-run/darklaunch. +message AlternatePolicySpec { + // Reference to the launch that will be used while audit logging and to + // control the launch. + // Should be set only in the alternate policy. + string launch = 1; + + // Specify `Constraint` for configurations of Cloud Platform resources. + PolicySpec spec = 2; +} + +// Defines a Cloud Organization `PolicySpec` which is used to specify +// `Constraints` for configurations of Cloud Platform resources. +message PolicySpec { + // A rule used to express this policy. + message PolicyRule { + // A message that holds specific allowed and denied values. + // This message can define specific values and subtrees of Cloud Resource + // Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that + // are allowed or denied. This is achieved by using the `under:` and + // optional `is:` prefixes. + // The `under:` prefix is used to denote resource subtree values. + // The `is:` prefix is used to denote specific values, and is required only + // if the value contains a ":". Values prefixed with "is:" are treated the + // same as values with no prefix. + // Ancestry subtrees must be in one of the following formats: + // - "projects/", e.g. "projects/tokyo-rain-123" + // - "folders/", e.g. "folders/1234" + // - "organizations/", e.g. "organizations/1234" + // The `supports_under` field of the associated `Constraint` defines + // whether ancestry prefixes can be used. + message StringValues { + // List of values allowed at this resource. + repeated string allowed_values = 1; + + // List of values denied at this resource. + repeated string denied_values = 2; + } + + oneof kind { + // List of values to be used for this PolicyRule. This field can be set + // only in Policies for list constraints. + StringValues values = 1; + + // Setting this to true means that all values are allowed. This field can + // be set only in Policies for list constraints. + bool allow_all = 2; + + // Setting this to true means that all values are denied. This field can + // be set only in Policies for list constraints. + bool deny_all = 3; + + // If `true`, then the `Policy` is enforced. If `false`, then any + // configuration is acceptable. + // This field can be set only in Policies for boolean constraints. + bool enforce = 4; + } + + // A condition which determines whether this rule is used + // in the evaluation of the policy. When set, the `expression` field in + // the `Expr' must include from 1 to 10 subexpressions, joined by the "||" + // or "&&" operators. Each subexpression must be of the form + // "resource.matchLabels(key_name, value_name)", + // where key_name and value_name are the resource names for Label Keys + // and Values. These names are available from the Label Manager Service. An + // example expression is: + // "resource.matchLabels('labelKeys/123, 'labelValues/456')". + google.type.Expr condition = 5; + } + + // An opaque tag indicating the current version of the `Policy`, used for + // concurrency control. + // + // This field is ignored if used in a `CreatePolicy` request. + // + // When the `Policy` is returned from either a `GetPolicy` or a + // `ListPolicies` request, this `etag` indicates the version of the + // current `Policy` to use when executing a read-modify-write loop. + // + // When the `Policy` is returned from a `GetEffectivePolicy` request, the + // `etag` will be unset. + string etag = 1; + + // Output only. The time stamp this was previously updated. This + // represents the last time a call to `CreatePolicy` or `UpdatePolicy` was + // made for that `Policy`. + google.protobuf.Timestamp update_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Up to 10 PolicyRules are allowed. + // + // In Policies for boolean constraints, the following requirements apply: + // - There must be one and only one PolicyRule where condition is unset. + // - BooleanPolicyRules with conditions must set `enforced` to the opposite + // of the PolicyRule without a condition. + // - During policy evaluation, PolicyRules with conditions that are + // true for a target resource take precedence. + repeated PolicyRule rules = 3; + + // Determines the inheritance behavior for this `Policy`. + // + // If `inherit_from_parent` is true, PolicyRules set higher up in the + // hierarchy (up to the closest root) are inherited and present in the + // effective policy. If it is false, then no rules are inherited, and this + // Policy becomes the new root for evaluation. + // This field can be set only for Policies which configure list constraints. + bool inherit_from_parent = 4; + + // Ignores policies set above this resource and restores the + // `constraint_default` enforcement behavior of the specific `Constraint` at + // this resource. + // This field can be set in policies for either list or boolean + // constraints. If set, `rules` must be empty and `inherit_from_parent` + // must be set to false. + bool reset = 5; +} + +// The request sent to the [ListConstraints] +// [google.cloud.orgpolicy.v2.OrgPolicy.ListConstraints] method. +message ListConstraintsRequest { + // Required. The Cloud resource that parents the constraint. Must be in one of the + // following forms: + // * `projects/{project_number}` + // * `projects/{project_id}` + // * `folders/{folder_id}` + // * `organizations/{organization_id}` + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + child_type: "orgpolicy.googleapis.com/Constraint" + } + ]; + + // Size of the pages to be returned. This is currently unsupported and will + // be ignored. The server may at any point start using this field to limit + // page size. + int32 page_size = 2; + + // Page token used to retrieve the next page. This is currently unsupported + // and will be ignored. The server may at any point start using this field. + string page_token = 3; +} + +// The response returned from the [ListConstraints] +// [google.cloud.orgpolicy.v2.OrgPolicy.ListConstraints] method. +message ListConstraintsResponse { + // The collection of constraints that are available on the targeted resource. + repeated Constraint constraints = 1; + + // Page token used to retrieve the next page. This is currently not used. + string next_page_token = 2; +} + +// The request sent to the [ListPolicies] +// [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. +message ListPoliciesRequest { + // Required. The target Cloud resource that parents the set of constraints and policies + // that will be returned from this call. Must be in one of the following + // forms: + // * `projects/{project_number}` + // * `projects/{project_id}` + // * `folders/{folder_id}` + // * `organizations/{organization_id}` + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + child_type: "orgpolicy.googleapis.com/Policy" + } + ]; + + // Size of the pages to be returned. This is currently unsupported and will + // be ignored. The server may at any point start using this field to limit + // page size. + int32 page_size = 2; + + // Page token used to retrieve the next page. This is currently unsupported + // and will be ignored. The server may at any point start using this field. + string page_token = 3; +} + +// The response returned from the [ListPolicies] +// [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. It will be empty +// if no `Policies` are set on the resource. +message ListPoliciesResponse { + // All `Policies` that exist on the resource. It will be empty if no + // `Policies` are set. + repeated Policy policies = 1; + + // Page token used to retrieve the next page. This is currently not used, but + // the server may at any point start supplying a valid token. + string next_page_token = 2; +} + +// The request sent to the [GetPolicy] +// [google.cloud.orgpolicy.v2.OrgPolicy.GetPolicy] method. +message GetPolicyRequest { + // Required. Resource name of the policy. See `Policy` for naming requirements. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "orgpolicy.googleapis.com/Policy" + } + ]; +} + +// The request sent to the [GetEffectivePolicy] +// [google.cloud.orgpolicy.v2.OrgPolicy.GetEffectivePolicy] method. +message GetEffectivePolicyRequest { + // Required. The effective policy to compute. See `Policy` for naming rules. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "orgpolicy.googleapis.com/Policy" + } + ]; +} + +// The request sent to the [CreatePolicyRequest] +// [google.cloud.orgpolicy.v2.OrgPolicy.CreatePolicy] method. +message CreatePolicyRequest { + // Required. The Cloud resource that will parent the new Policy. Must be in one of the + // following forms: + // * `projects/{project_number}` + // * `projects/{project_id}` + // * `folders/{folder_id}` + // * `organizations/{organization_id}` + string parent = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + child_type: "orgpolicy.googleapis.com/Policy" + } + ]; + + // Required. `Policy` to create. + Policy policy = 3 [(google.api.field_behavior) = REQUIRED]; +} + +// The request sent to the [UpdatePolicyRequest] +// [google.cloud.orgpolicy.v2.OrgPolicy.UpdatePolicy] method. +message UpdatePolicyRequest { + // Required. `Policy` to update. + Policy policy = 1 [(google.api.field_behavior) = REQUIRED]; +} + +// The request sent to the [DeletePolicy] +// [google.cloud.orgpolicy.v2.OrgPolicy.DeletePolicy] method. +message DeletePolicyRequest { + // Required. Name of the policy to delete. + // See `Policy` for naming rules. + string name = 1 [ + (google.api.field_behavior) = REQUIRED, + (google.api.resource_reference) = { + type: "orgpolicy.googleapis.com/Policy" + } + ]; +} diff --git a/owl-bot-staging/v2/src/index.ts b/owl-bot-staging/v2/src/index.ts new file mode 100644 index 0000000..ea8b87a --- /dev/null +++ b/owl-bot-staging/v2/src/index.ts @@ -0,0 +1,25 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as v2 from './v2'; +const OrgPolicyClient = v2.OrgPolicyClient; +type OrgPolicyClient = v2.OrgPolicyClient; +export {v2, OrgPolicyClient}; +export default {v2, OrgPolicyClient}; +import * as protos from '../protos/protos'; +export {protos} diff --git a/owl-bot-staging/v2/src/v2/gapic_metadata.json b/owl-bot-staging/v2/src/v2/gapic_metadata.json new file mode 100644 index 0000000..3fd440b --- /dev/null +++ b/owl-bot-staging/v2/src/v2/gapic_metadata.json @@ -0,0 +1,101 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", + "language": "typescript", + "protoPackage": "google.cloud.orgpolicy.v2", + "libraryPackage": "@google-cloud/org-policy", + "services": { + "OrgPolicy": { + "clients": { + "grpc": { + "libraryClient": "OrgPolicyClient", + "rpcs": { + "GetPolicy": { + "methods": [ + "getPolicy" + ] + }, + "GetEffectivePolicy": { + "methods": [ + "getEffectivePolicy" + ] + }, + "CreatePolicy": { + "methods": [ + "createPolicy" + ] + }, + "UpdatePolicy": { + "methods": [ + "updatePolicy" + ] + }, + "DeletePolicy": { + "methods": [ + "deletePolicy" + ] + }, + "ListConstraints": { + "methods": [ + "listConstraints", + "listConstraintsStream", + "listConstraintsAsync" + ] + }, + "ListPolicies": { + "methods": [ + "listPolicies", + "listPoliciesStream", + "listPoliciesAsync" + ] + } + } + }, + "grpc-fallback": { + "libraryClient": "OrgPolicyClient", + "rpcs": { + "GetPolicy": { + "methods": [ + "getPolicy" + ] + }, + "GetEffectivePolicy": { + "methods": [ + "getEffectivePolicy" + ] + }, + "CreatePolicy": { + "methods": [ + "createPolicy" + ] + }, + "UpdatePolicy": { + "methods": [ + "updatePolicy" + ] + }, + "DeletePolicy": { + "methods": [ + "deletePolicy" + ] + }, + "ListConstraints": { + "methods": [ + "listConstraints", + "listConstraintsStream", + "listConstraintsAsync" + ] + }, + "ListPolicies": { + "methods": [ + "listPolicies", + "listPoliciesStream", + "listPoliciesAsync" + ] + } + } + } + } + } + } +} diff --git a/owl-bot-staging/v2/src/v2/index.ts b/owl-bot-staging/v2/src/v2/index.ts new file mode 100644 index 0000000..0046424 --- /dev/null +++ b/owl-bot-staging/v2/src/v2/index.ts @@ -0,0 +1,19 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +export {OrgPolicyClient} from './org_policy_client'; diff --git a/owl-bot-staging/v2/src/v2/org_policy_client.ts b/owl-bot-staging/v2/src/v2/org_policy_client.ts new file mode 100644 index 0000000..8235d58 --- /dev/null +++ b/owl-bot-staging/v2/src/v2/org_policy_client.ts @@ -0,0 +1,1385 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +/* global window */ +import * as gax from 'google-gax'; +import {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax'; + +import { Transform } from 'stream'; +import { RequestType } from 'google-gax/build/src/apitypes'; +import * as protos from '../../protos/protos'; +import jsonProtos = require('../../protos/protos.json'); +/** + * Client JSON configuration object, loaded from + * `src/v2/org_policy_client_config.json`. + * This file defines retry strategy and timeouts for all API methods in this library. + */ +import * as gapicConfig from './org_policy_client_config.json'; + +const version = require('../../../package.json').version; + +/** + * An interface for managing organization policies. + * + * The Cloud Org Policy service provides a simple mechanism for organizations to + * restrict the allowed configurations across their entire Cloud Resource + * hierarchy. + * + * You can use a `policy` to configure restrictions in Cloud resources. For + * example, you can enforce a `policy` that restricts which Google + * Cloud Platform APIs can be activated in a certain part of your resource + * hierarchy, or prevents serial port access to VM instances in a particular + * folder. + * + * `Policies` are inherited down through the resource hierarchy. A `policy` + * applied to a parent resource automatically applies to all its child resources + * unless overridden with a `policy` lower in the hierarchy. + * + * A `constraint` defines an aspect of a resource's configuration that can be + * controlled by an organization's policy administrator. `Policies` are a + * collection of `constraints` that defines their allowable configuration on a + * particular resource and its child resources. + * @class + * @memberof v2 + */ +export class OrgPolicyClient { + private _terminated = false; + private _opts: ClientOptions; + private _providedCustomServicePath: boolean; + private _gaxModule: typeof gax | typeof gax.fallback; + private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; + private _protos: {}; + private _defaults: {[method: string]: gax.CallSettings}; + auth: gax.GoogleAuth; + descriptors: Descriptors = { + page: {}, + stream: {}, + longrunning: {}, + batching: {}, + }; + warn: (code: string, message: string, warnType?: string) => void; + innerApiCalls: {[name: string]: Function}; + pathTemplates: {[name: string]: gax.PathTemplate}; + orgPolicyStub?: Promise<{[name: string]: Function}>; + + /** + * Construct an instance of OrgPolicyClient. + * + * @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). + * The common options are: + * @param {object} [options.credentials] - Credentials object. + * @param {string} [options.credentials.client_email] + * @param {string} [options.credentials.private_key] + * @param {string} [options.email] - Account email address. Required when + * using a .pem or .p12 keyFilename. + * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option below is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number} [options.port] - The port on which to connect to + * the remote host. + * @param {string} [options.projectId] - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {string} [options.apiEndpoint] - The domain name of the + * 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. + */ + constructor(opts?: ClientOptions) { + // Ensure that options include all the required fields. + const staticMembers = this.constructor as typeof OrgPolicyClient; + const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; + this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); + const port = opts?.port || staticMembers.port; + const clientConfig = opts?.clientConfig ?? {}; + const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); + opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); + + // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. + if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { + opts['scopes'] = staticMembers.scopes; + } + + // Choose either gRPC or proto-over-HTTP implementation of google-gax. + this._gaxModule = opts.fallback ? gax.fallback : gax; + + // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. + this._gaxGrpc = new this._gaxModule.GrpcClient(opts); + + // Save options to use in initialize() method. + this._opts = opts; + + // Save the auth object to the client, for use by other methods. + this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); + + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + + // Set the default scopes in auth client if needed. + if (servicePath === staticMembers.servicePath) { + this.auth.defaultScopes = staticMembers.scopes; + } + + // Determine the client header string. + const clientHeader = [ + `gax/${this._gaxModule.version}`, + `gapic/${version}`, + ]; + if (typeof process !== 'undefined' && 'versions' in process) { + clientHeader.push(`gl-node/${process.versions.node}`); + } else { + clientHeader.push(`gl-web/${this._gaxModule.version}`); + } + if (!opts.fallback) { + clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); + } else if (opts.fallback === 'rest' ) { + clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); + } + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); + + // This API contains "path templates"; forward-slash-separated + // identifiers to uniquely identify resources within the API. + // Create useful helper objects for these. + this.pathTemplates = { + folderConstraintPathTemplate: new this._gaxModule.PathTemplate( + 'folders/{folder}/constraints/{constraint}' + ), + folderPolicyPathTemplate: new this._gaxModule.PathTemplate( + 'folders/{folder}/policies/{policy}' + ), + organizationConstraintPathTemplate: new this._gaxModule.PathTemplate( + 'organizations/{organization}/constraints/{constraint}' + ), + organizationPolicyPathTemplate: new this._gaxModule.PathTemplate( + 'organizations/{organization}/policies/{policy}' + ), + projectPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}' + ), + projectConstraintPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/constraints/{constraint}' + ), + projectPolicyPathTemplate: new this._gaxModule.PathTemplate( + 'projects/{project}/policies/{policy}' + ), + }; + + // Some of the methods on this service return "paged" results, + // (e.g. 50 results at a time, with tokens to get subsequent + // pages). Denote the keys used for pagination and results. + this.descriptors.page = { + listConstraints: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'constraints'), + listPolicies: + new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') + }; + + // Put together the default options sent with requests. + this._defaults = this._gaxGrpc.constructSettings( + 'google.cloud.orgpolicy.v2.OrgPolicy', gapicConfig as gax.ClientConfig, + opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); + + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this.innerApiCalls = {}; + + // Add a warn function to the client constructor so it can be easily tested. + this.warn = gax.warn; + } + + /** + * Initialize the client. + * Performs asynchronous operations (such as authentication) and prepares the client. + * This function will be called automatically when any class method is called for the + * first time, but if you need to initialize it before calling an actual method, + * feel free to call initialize() directly. + * + * You can await on this method if you want to make sure the client is initialized. + * + * @returns {Promise} A promise that resolves to an authenticated service stub. + */ + initialize() { + // If the client stub promise is already initialized, return immediately. + if (this.orgPolicyStub) { + return this.orgPolicyStub; + } + + // Put together the "service stub" for + // google.cloud.orgpolicy.v2.OrgPolicy. + this.orgPolicyStub = this._gaxGrpc.createStub( + this._opts.fallback ? + (this._protos as protobuf.Root).lookupService('google.cloud.orgpolicy.v2.OrgPolicy') : + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (this._protos as any).google.cloud.orgpolicy.v2.OrgPolicy, + this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; + + // Iterate over each of the methods that the service provides + // and create an API call method for each. + const orgPolicyStubMethods = + ['listConstraints', 'listPolicies', 'getPolicy', 'getEffectivePolicy', 'createPolicy', 'updatePolicy', 'deletePolicy']; + for (const methodName of orgPolicyStubMethods) { + const callPromise = this.orgPolicyStub.then( + stub => (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, + (err: Error|null|undefined) => () => { + throw err; + }); + + const descriptor = + this.descriptors.page[methodName] || + undefined; + const apiCall = this._gaxModule.createApiCall( + callPromise, + this._defaults[methodName], + descriptor + ); + + this.innerApiCalls[methodName] = apiCall; + } + + return this.orgPolicyStub; + } + + /** + * The DNS address for this API service. + * @returns {string} The DNS address for this service. + */ + static get servicePath() { + return 'orgpolicy.googleapis.com'; + } + + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + * @returns {string} The DNS address for this service. + */ + static get apiEndpoint() { + return 'orgpolicy.googleapis.com'; + } + + /** + * The port for this API service. + * @returns {number} The default port for this service. + */ + static get port() { + return 443; + } + + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + * @returns {string[]} List of default scopes. + */ + static get scopes() { + return [ + 'https://www.googleapis.com/auth/cloud-platform' + ]; + } + + getProjectId(): Promise; + getProjectId(callback: Callback): void; + /** + * Return the project ID used by this class. + * @returns {Promise} A promise that resolves to string containing the project ID. + */ + getProjectId(callback?: Callback): + Promise|void { + if (callback) { + this.auth.getProjectId(callback); + return; + } + return this.auth.getProjectId(); + } + + // ------------------- + // -- Service calls -- + // ------------------- + getPolicy( + request?: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|undefined, {}|undefined + ]>; + getPolicy( + request: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, + {}|null|undefined>): void; + getPolicy( + request: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, + {}|null|undefined>): void; +/** + * Gets a `Policy` on a resource. + * + * If no `Policy` is set on the resource, NOT_FOUND is returned. The + * `etag` value can be used with `UpdatePolicy()` to update a + * `Policy` during read-modify-write. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Resource name of the policy. See `Policy` for naming requirements. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example + * const [response] = await client.getPolicy(request); + */ + getPolicy( + request?: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'name': request.name || '', + }); + this.initialize(); + return this.innerApiCalls.getPolicy(request, options, callback); + } + getEffectivePolicy( + request?: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|undefined, {}|undefined + ]>; + getEffectivePolicy( + request: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, + {}|null|undefined>): void; + getEffectivePolicy( + request: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, + {}|null|undefined>): void; +/** + * Gets the effective `Policy` on a resource. This is the result of merging + * `Policies` in the resource hierarchy and evaluating conditions. The + * returned `Policy` will not have an `etag` or `condition` set because it is + * a computed `Policy` across multiple resources. + * Subtrees of Resource Manager resource hierarchy with 'under:' prefix will + * not be expanded. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. The effective policy to compute. See `Policy` for naming rules. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example + * const [response] = await client.getEffectivePolicy(request); + */ + getEffectivePolicy( + request?: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'name': request.name || '', + }); + this.initialize(); + return this.innerApiCalls.getEffectivePolicy(request, options, callback); + } + createPolicy( + request?: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|undefined, {}|undefined + ]>; + createPolicy( + request: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, + {}|null|undefined>): void; + createPolicy( + request: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, + {}|null|undefined>): void; +/** + * Creates a Policy. + * + * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + * constraint does not exist. + * Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the + * policy already exists on the given Cloud resource. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The Cloud resource that will parent the new Policy. Must be in one of the + * following forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {google.cloud.orgpolicy.v2.Policy} request.policy + * Required. `Policy` to create. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example + * const [response] = await client.createPolicy(request); + */ + createPolicy( + request?: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + this.initialize(); + return this.innerApiCalls.createPolicy(request, options, callback); + } + updatePolicy( + request?: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|undefined, {}|undefined + ]>; + updatePolicy( + request: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, + {}|null|undefined>): void; + updatePolicy( + request: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, + callback: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, + {}|null|undefined>): void; +/** + * Updates a Policy. + * + * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + * constraint or the policy do not exist. + * Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag + * supplied in the request does not match the persisted etag of the policy + * + * Note: the supplied policy will perform a full overwrite of all + * fields. + * + * @param {Object} request + * The request object that will be sent. + * @param {google.cloud.orgpolicy.v2.Policy} request.policy + * Required. `Policy` to update. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example + * const [response] = await client.updatePolicy(request); + */ + updatePolicy( + request?: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy, + protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'policy.name': request.policy!.name || '', + }); + this.initialize(); + return this.innerApiCalls.updatePolicy(request, options, callback); + } + deletePolicy( + request?: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, + options?: CallOptions): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|undefined, {}|undefined + ]>; + deletePolicy( + request: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, + options: CallOptions, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, + {}|null|undefined>): void; + deletePolicy( + request: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, + callback: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, + {}|null|undefined>): void; +/** + * Deletes a Policy. + * + * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the + * constraint or Org Policy does not exist. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.name + * Required. Name of the policy to delete. + * See `Policy` for naming rules. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) + * for more details and examples. + * @example + * const [response] = await client.deletePolicy(request); + */ + deletePolicy( + request?: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, + optionsOrCallback?: CallOptions|Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, + {}|null|undefined>, + callback?: Callback< + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, + {}|null|undefined>): + Promise<[ + protos.google.protobuf.IEmpty, + protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|undefined, {}|undefined + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'name': request.name || '', + }); + this.initialize(); + return this.innerApiCalls.deletePolicy(request, options, callback); + } + + listConstraints( + request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IConstraint[], + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest|null, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse + ]>; + listConstraints( + request: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IConstraint>): void; + listConstraints( + request: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + callback: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IConstraint>): void; +/** + * Lists `Constraints` that could be applied on the specified resource. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The Cloud resource that parents the constraint. Must be in one of the + * following forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [Constraint]{@link google.cloud.orgpolicy.v2.Constraint}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listConstraintsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listConstraints( + request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IConstraint>, + callback?: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IConstraint>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IConstraint[], + protos.google.cloud.orgpolicy.v2.IListConstraintsRequest|null, + protos.google.cloud.orgpolicy.v2.IListConstraintsResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + this.initialize(); + return this.innerApiCalls.listConstraints(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The Cloud resource that parents the constraint. Must be in one of the + * following forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing [Constraint]{@link google.cloud.orgpolicy.v2.Constraint} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listConstraintsAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listConstraintsStream( + request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listConstraints.createStream( + this.innerApiCalls.listConstraints as gax.GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listConstraints`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The Cloud resource that parents the constraint. Must be in one of the + * following forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). + * When you iterate the returned iterable, each element will be an object representing + * [Constraint]{@link google.cloud.orgpolicy.v2.Constraint}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + * @example + * const iterable = client.listConstraintsAsync(request); + * for await (const response of iterable) { + * // process response + * } + */ + listConstraintsAsync( + request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listConstraints.asyncIterate( + this.innerApiCalls['listConstraints'] as GaxCall, + request as unknown as RequestType, + callSettings + ) as AsyncIterable; + } + listPolicies( + request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + options?: CallOptions): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy[], + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest|null, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse + ]>; + listPolicies( + request: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + options: CallOptions, + callback: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IPolicy>): void; + listPolicies( + request: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + callback: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IPolicy>): void; +/** + * Retrieves all of the `Policies` that exist on a particular resource. + * + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The target Cloud resource that parents the set of constraints and policies + * that will be returned from this call. Must be in one of the following + * forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is Array of [Policy]{@link google.cloud.orgpolicy.v2.Policy}. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed and will merge results from all the pages into this array. + * Note that it can affect your quota. + * We recommend using `listPoliciesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listPolicies( + request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + optionsOrCallback?: CallOptions|PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IPolicy>, + callback?: PaginationCallback< + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, + protos.google.cloud.orgpolicy.v2.IPolicy>): + Promise<[ + protos.google.cloud.orgpolicy.v2.IPolicy[], + protos.google.cloud.orgpolicy.v2.IListPoliciesRequest|null, + protos.google.cloud.orgpolicy.v2.IListPoliciesResponse + ]>|void { + request = request || {}; + let options: CallOptions; + if (typeof optionsOrCallback === 'function' && callback === undefined) { + callback = optionsOrCallback; + options = {}; + } + else { + options = optionsOrCallback as CallOptions; + } + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + this.initialize(); + return this.innerApiCalls.listPolicies(request, options, callback); + } + +/** + * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The target Cloud resource that parents the set of constraints and policies + * that will be returned from this call. Must be in one of the following + * forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Stream} + * An object stream which emits an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy} on 'data' event. + * The client library will perform auto-pagination by default: it will call the API as many + * times as needed. Note that it can affect your quota. + * We recommend using `listPoliciesAsync()` + * method described below for async iteration which you can stop as needed. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + */ + listPoliciesStream( + request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + options?: CallOptions): + Transform{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listPolicies.createStream( + this.innerApiCalls.listPolicies as gax.GaxCall, + request, + callSettings + ); + } + +/** + * Equivalent to `listPolicies`, but returns an iterable object. + * + * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. + * @param {Object} request + * The request object that will be sent. + * @param {string} request.parent + * Required. The target Cloud resource that parents the set of constraints and policies + * that will be returned from this call. Must be in one of the following + * forms: + * * `projects/{project_number}` + * * `projects/{project_id}` + * * `folders/{folder_id}` + * * `organizations/{organization_id}` + * @param {number} request.pageSize + * Size of the pages to be returned. This is currently unsupported and will + * be ignored. The server may at any point start using this field to limit + * page size. + * @param {string} request.pageToken + * Page token used to retrieve the next page. This is currently unsupported + * and will be ignored. The server may at any point start using this field. + * @param {object} [options] + * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. + * @returns {Object} + * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). + * When you iterate the returned iterable, each element will be an object representing + * [Policy]{@link google.cloud.orgpolicy.v2.Policy}. The API will be called under the hood as needed, once per the page, + * so you can stop the iteration when you don't need more results. + * Please see the + * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) + * for more details and examples. + * @example + * const iterable = client.listPoliciesAsync(request); + * for await (const response of iterable) { + * // process response + * } + */ + listPoliciesAsync( + request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, + options?: CallOptions): + AsyncIterable{ + request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); + options = options || {}; + const callSettings = new gax.CallSettings(options); + this.initialize(); + return this.descriptors.page.listPolicies.asyncIterate( + this.innerApiCalls['listPolicies'] as GaxCall, + request as unknown as RequestType, + callSettings + ) as AsyncIterable; + } + // -------------------- + // -- Path templates -- + // -------------------- + + /** + * Return a fully-qualified folderConstraint resource name string. + * + * @param {string} folder + * @param {string} constraint + * @returns {string} Resource name string. + */ + folderConstraintPath(folder:string,constraint:string) { + return this.pathTemplates.folderConstraintPathTemplate.render({ + folder: folder, + constraint: constraint, + }); + } + + /** + * Parse the folder from FolderConstraint resource. + * + * @param {string} folderConstraintName + * A fully-qualified path representing folder_constraint resource. + * @returns {string} A string representing the folder. + */ + matchFolderFromFolderConstraintName(folderConstraintName: string) { + return this.pathTemplates.folderConstraintPathTemplate.match(folderConstraintName).folder; + } + + /** + * Parse the constraint from FolderConstraint resource. + * + * @param {string} folderConstraintName + * A fully-qualified path representing folder_constraint resource. + * @returns {string} A string representing the constraint. + */ + matchConstraintFromFolderConstraintName(folderConstraintName: string) { + return this.pathTemplates.folderConstraintPathTemplate.match(folderConstraintName).constraint; + } + + /** + * Return a fully-qualified folderPolicy resource name string. + * + * @param {string} folder + * @param {string} policy + * @returns {string} Resource name string. + */ + folderPolicyPath(folder:string,policy:string) { + return this.pathTemplates.folderPolicyPathTemplate.render({ + folder: folder, + policy: policy, + }); + } + + /** + * Parse the folder from FolderPolicy resource. + * + * @param {string} folderPolicyName + * A fully-qualified path representing folder_policy resource. + * @returns {string} A string representing the folder. + */ + matchFolderFromFolderPolicyName(folderPolicyName: string) { + return this.pathTemplates.folderPolicyPathTemplate.match(folderPolicyName).folder; + } + + /** + * Parse the policy from FolderPolicy resource. + * + * @param {string} folderPolicyName + * A fully-qualified path representing folder_policy resource. + * @returns {string} A string representing the policy. + */ + matchPolicyFromFolderPolicyName(folderPolicyName: string) { + return this.pathTemplates.folderPolicyPathTemplate.match(folderPolicyName).policy; + } + + /** + * Return a fully-qualified organizationConstraint resource name string. + * + * @param {string} organization + * @param {string} constraint + * @returns {string} Resource name string. + */ + organizationConstraintPath(organization:string,constraint:string) { + return this.pathTemplates.organizationConstraintPathTemplate.render({ + organization: organization, + constraint: constraint, + }); + } + + /** + * Parse the organization from OrganizationConstraint resource. + * + * @param {string} organizationConstraintName + * A fully-qualified path representing organization_constraint resource. + * @returns {string} A string representing the organization. + */ + matchOrganizationFromOrganizationConstraintName(organizationConstraintName: string) { + return this.pathTemplates.organizationConstraintPathTemplate.match(organizationConstraintName).organization; + } + + /** + * Parse the constraint from OrganizationConstraint resource. + * + * @param {string} organizationConstraintName + * A fully-qualified path representing organization_constraint resource. + * @returns {string} A string representing the constraint. + */ + matchConstraintFromOrganizationConstraintName(organizationConstraintName: string) { + return this.pathTemplates.organizationConstraintPathTemplate.match(organizationConstraintName).constraint; + } + + /** + * Return a fully-qualified organizationPolicy resource name string. + * + * @param {string} organization + * @param {string} policy + * @returns {string} Resource name string. + */ + organizationPolicyPath(organization:string,policy:string) { + return this.pathTemplates.organizationPolicyPathTemplate.render({ + organization: organization, + policy: policy, + }); + } + + /** + * Parse the organization from OrganizationPolicy resource. + * + * @param {string} organizationPolicyName + * A fully-qualified path representing organization_policy resource. + * @returns {string} A string representing the organization. + */ + matchOrganizationFromOrganizationPolicyName(organizationPolicyName: string) { + return this.pathTemplates.organizationPolicyPathTemplate.match(organizationPolicyName).organization; + } + + /** + * Parse the policy from OrganizationPolicy resource. + * + * @param {string} organizationPolicyName + * A fully-qualified path representing organization_policy resource. + * @returns {string} A string representing the policy. + */ + matchPolicyFromOrganizationPolicyName(organizationPolicyName: string) { + return this.pathTemplates.organizationPolicyPathTemplate.match(organizationPolicyName).policy; + } + + /** + * Return a fully-qualified project resource name string. + * + * @param {string} project + * @returns {string} Resource name string. + */ + projectPath(project:string) { + return this.pathTemplates.projectPathTemplate.render({ + project: project, + }); + } + + /** + * Parse the project from Project resource. + * + * @param {string} projectName + * A fully-qualified path representing Project resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectName(projectName: string) { + return this.pathTemplates.projectPathTemplate.match(projectName).project; + } + + /** + * Return a fully-qualified projectConstraint resource name string. + * + * @param {string} project + * @param {string} constraint + * @returns {string} Resource name string. + */ + projectConstraintPath(project:string,constraint:string) { + return this.pathTemplates.projectConstraintPathTemplate.render({ + project: project, + constraint: constraint, + }); + } + + /** + * Parse the project from ProjectConstraint resource. + * + * @param {string} projectConstraintName + * A fully-qualified path representing project_constraint resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectConstraintName(projectConstraintName: string) { + return this.pathTemplates.projectConstraintPathTemplate.match(projectConstraintName).project; + } + + /** + * Parse the constraint from ProjectConstraint resource. + * + * @param {string} projectConstraintName + * A fully-qualified path representing project_constraint resource. + * @returns {string} A string representing the constraint. + */ + matchConstraintFromProjectConstraintName(projectConstraintName: string) { + return this.pathTemplates.projectConstraintPathTemplate.match(projectConstraintName).constraint; + } + + /** + * Return a fully-qualified projectPolicy resource name string. + * + * @param {string} project + * @param {string} policy + * @returns {string} Resource name string. + */ + projectPolicyPath(project:string,policy:string) { + return this.pathTemplates.projectPolicyPathTemplate.render({ + project: project, + policy: policy, + }); + } + + /** + * Parse the project from ProjectPolicy resource. + * + * @param {string} projectPolicyName + * A fully-qualified path representing project_policy resource. + * @returns {string} A string representing the project. + */ + matchProjectFromProjectPolicyName(projectPolicyName: string) { + return this.pathTemplates.projectPolicyPathTemplate.match(projectPolicyName).project; + } + + /** + * Parse the policy from ProjectPolicy resource. + * + * @param {string} projectPolicyName + * A fully-qualified path representing project_policy resource. + * @returns {string} A string representing the policy. + */ + matchPolicyFromProjectPolicyName(projectPolicyName: string) { + return this.pathTemplates.projectPolicyPathTemplate.match(projectPolicyName).policy; + } + + /** + * Terminate the gRPC channel and close the client. + * + * The client will no longer be usable and all future behavior is undefined. + * @returns {Promise} A promise that resolves when the client is closed. + */ + close(): Promise { + this.initialize(); + if (!this._terminated) { + return this.orgPolicyStub!.then(stub => { + this._terminated = true; + stub.close(); + }); + } + return Promise.resolve(); + } +} diff --git a/owl-bot-staging/v2/src/v2/org_policy_client_config.json b/owl-bot-staging/v2/src/v2/org_policy_client_config.json new file mode 100644 index 0000000..330aa9b --- /dev/null +++ b/owl-bot-staging/v2/src/v2/org_policy_client_config.json @@ -0,0 +1,70 @@ +{ + "interfaces": { + "google.cloud.orgpolicy.v2.OrgPolicy": { + "retry_codes": { + "non_idempotent": [], + "idempotent": [ + "DEADLINE_EXCEEDED", + "UNAVAILABLE" + ] + }, + "retry_params": { + "default": { + "initial_retry_delay_millis": 100, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 60000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + }, + "ce5b960a6ed052e690863808e4f0deff3dc7d49f": { + "initial_retry_delay_millis": 1000, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 10000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 600000 + } + }, + "methods": { + "ListConstraints": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "ListPolicies": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "GetPolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "GetEffectivePolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "CreatePolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "UpdatePolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + }, + "DeletePolicy": { + "timeout_millis": 60000, + "retry_codes_name": "idempotent", + "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" + } + } + } + } +} diff --git a/owl-bot-staging/v2/src/v2/org_policy_proto_list.json b/owl-bot-staging/v2/src/v2/org_policy_proto_list.json new file mode 100644 index 0000000..ad104ec --- /dev/null +++ b/owl-bot-staging/v2/src/v2/org_policy_proto_list.json @@ -0,0 +1,4 @@ +[ + "../../protos/google/cloud/orgpolicy/v2/constraint.proto", + "../../protos/google/cloud/orgpolicy/v2/orgpolicy.proto" +] diff --git a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js new file mode 100644 index 0000000..1afa574 --- /dev/null +++ b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js @@ -0,0 +1,27 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + + +/* eslint-disable node/no-missing-require, no-unused-vars */ +const orgpolicy = require('@google-cloud/org-policy'); + +function main() { + const orgPolicyClient = new orgpolicy.OrgPolicyClient(); +} + +main(); diff --git a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts new file mode 100644 index 0000000..6e10a5a --- /dev/null +++ b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts @@ -0,0 +1,32 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import {OrgPolicyClient} from '@google-cloud/org-policy'; + +// check that the client class type name can be used +function doStuffWithOrgPolicyClient(client: OrgPolicyClient) { + client.close(); +} + +function main() { + // check that the client instance can be created + const orgPolicyClient = new OrgPolicyClient(); + doStuffWithOrgPolicyClient(orgPolicyClient); +} + +main(); diff --git a/owl-bot-staging/v2/system-test/install.ts b/owl-bot-staging/v2/system-test/install.ts new file mode 100644 index 0000000..1f850b5 --- /dev/null +++ b/owl-bot-staging/v2/system-test/install.ts @@ -0,0 +1,49 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import { packNTest } from 'pack-n-play'; +import { readFileSync } from 'fs'; +import { describe, it } from 'mocha'; + +describe('📦 pack-n-play test', () => { + + it('TypeScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'TypeScript user can use the type definitions', + ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() + } + }; + await packNTest(options); + }); + + it('JavaScript code', async function() { + this.timeout(300000); + const options = { + packageDir: process.cwd(), + sample: { + description: 'JavaScript user can use the library', + ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() + } + }; + await packNTest(options); + }); + +}); diff --git a/owl-bot-staging/v2/test/gapic_org_policy_v2.ts b/owl-bot-staging/v2/test/gapic_org_policy_v2.ts new file mode 100644 index 0000000..31a41c9 --- /dev/null +++ b/owl-bot-staging/v2/test/gapic_org_policy_v2.ts @@ -0,0 +1,1297 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// ** This file is automatically generated by gapic-generator-typescript. ** +// ** https://github.com/googleapis/gapic-generator-typescript ** +// ** All changes to this file may be overwritten. ** + +import * as protos from '../protos/protos'; +import * as assert from 'assert'; +import * as sinon from 'sinon'; +import {SinonStub} from 'sinon'; +import { describe, it } from 'mocha'; +import * as orgpolicyModule from '../src'; + +import {PassThrough} from 'stream'; + +import {protobuf} from 'google-gax'; + +function generateSampleMessage(instance: T) { + const filledObject = (instance.constructor as typeof protobuf.Message) + .toObject(instance as protobuf.Message, {defaults: true}); + return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; +} + +function stubSimpleCall(response?: ResponseType, error?: Error) { + return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); +} + +function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { + return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); +} + +function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { + const pagingStub = sinon.stub(); + if (responses) { + for (let i = 0; i < responses.length; ++i) { + pagingStub.onCall(i).callsArgWith(2, null, responses[i]); + } + } + const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; + const mockStream = new PassThrough({ + objectMode: true, + transform: transformStub, + }); + // trigger as many responses as needed + if (responses) { + for (let i = 0; i < responses.length; ++i) { + setImmediate(() => { mockStream.write({}); }); + } + setImmediate(() => { mockStream.end(); }); + } else { + setImmediate(() => { mockStream.write({}); }); + setImmediate(() => { mockStream.end(); }); + } + return sinon.stub().returns(mockStream); +} + +function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { + let counter = 0; + const asyncIterable = { + [Symbol.asyncIterator]() { + return { + async next() { + if (error) { + return Promise.reject(error); + } + if (counter >= responses!.length) { + return Promise.resolve({done: true, value: undefined}); + } + return Promise.resolve({done: false, value: responses![counter++]}); + } + }; + } + }; + return sinon.stub().returns(asyncIterable); +} + +describe('v2.OrgPolicyClient', () => { + it('has servicePath', () => { + const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = orgpolicyModule.v2.OrgPolicyClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no option', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient(); + assert(client); + }); + + it('should create a client with gRPC fallback', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + fallback: true, + }); + assert(client); + }); + + it('has initialize method and supports deferred initialization', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + assert.strictEqual(client.orgPolicyStub, undefined); + await client.initialize(); + assert(client.orgPolicyStub); + }); + + it('has close method', () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.close(); + }); + + it('has getProjectId method', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); + const result = await client.getProjectId(); + assert.strictEqual(result, fakeProjectId); + assert((client.auth.getProjectId as SinonStub).calledWithExactly()); + }); + + it('has getProjectId method with callback', async () => { + const fakeProjectId = 'fake-project-id'; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); + const promise = new Promise((resolve, reject) => { + client.getProjectId((err?: Error|null, projectId?: string|null) => { + if (err) { + reject(err); + } else { + resolve(projectId); + } + }); + }); + const result = await promise; + assert.strictEqual(result, fakeProjectId); + }); + + describe('getPolicy', () => { + it('invokes getPolicy without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.getPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.getPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes getPolicy without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.getPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getPolicy( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes getPolicy with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getPolicy(request), expectedError); + assert((client.innerApiCalls.getPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('getEffectivePolicy', () => { + it('invokes getEffectivePolicy without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.getEffectivePolicy = stubSimpleCall(expectedResponse); + const [response] = await client.getEffectivePolicy(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getEffectivePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes getEffectivePolicy without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.getEffectivePolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.getEffectivePolicy( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.getEffectivePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes getEffectivePolicy with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.getEffectivePolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.getEffectivePolicy(request), expectedError); + assert((client.innerApiCalls.getEffectivePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('createPolicy', () => { + it('invokes createPolicy without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.createPolicy = stubSimpleCall(expectedResponse); + const [response] = await client.createPolicy(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.createPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes createPolicy without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.createPolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.createPolicy( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.createPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes createPolicy with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.createPolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.createPolicy(request), expectedError); + assert((client.innerApiCalls.createPolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('updatePolicy', () => { + it('invokes updatePolicy without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); + request.policy = {}; + request.policy.name = ''; + const expectedHeaderRequestParams = "policy.name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.updatePolicy = stubSimpleCall(expectedResponse); + const [response] = await client.updatePolicy(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.updatePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes updatePolicy without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); + request.policy = {}; + request.policy.name = ''; + const expectedHeaderRequestParams = "policy.name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); + client.innerApiCalls.updatePolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.updatePolicy( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.updatePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes updatePolicy with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); + request.policy = {}; + request.policy.name = ''; + const expectedHeaderRequestParams = "policy.name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.updatePolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.updatePolicy(request), expectedError); + assert((client.innerApiCalls.updatePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('deletePolicy', () => { + it('invokes deletePolicy without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.protobuf.Empty()); + client.innerApiCalls.deletePolicy = stubSimpleCall(expectedResponse); + const [response] = await client.deletePolicy(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.deletePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes deletePolicy without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = generateSampleMessage(new protos.google.protobuf.Empty()); + client.innerApiCalls.deletePolicy = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.deletePolicy( + request, + (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.deletePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes deletePolicy with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); + request.name = ''; + const expectedHeaderRequestParams = "name="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.deletePolicy = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.deletePolicy(request), expectedError); + assert((client.innerApiCalls.deletePolicy as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + }); + + describe('listConstraints', () => { + it('invokes listConstraints without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + ]; + client.innerApiCalls.listConstraints = stubSimpleCall(expectedResponse); + const [response] = await client.listConstraints(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listConstraints as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes listConstraints without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + ]; + client.innerApiCalls.listConstraints = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listConstraints( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IConstraint[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listConstraints as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes listConstraints with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listConstraints = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listConstraints(request), expectedError); + assert((client.innerApiCalls.listConstraints as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes listConstraintsStream without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + ]; + client.descriptors.page.listConstraints.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listConstraintsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.orgpolicy.v2.Constraint[] = []; + stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Constraint) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listConstraints.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listConstraints, request)); + assert.strictEqual( + (client.descriptors.page.listConstraints.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('invokes listConstraintsStream with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedError = new Error('expected'); + client.descriptors.page.listConstraints.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listConstraintsStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.orgpolicy.v2.Constraint[] = []; + stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Constraint) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listConstraints.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listConstraints, request)); + assert.strictEqual( + (client.descriptors.page.listConstraints.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listConstraints without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), + ]; + client.descriptors.page.listConstraints.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.orgpolicy.v2.IConstraint[] = []; + const iterable = client.listConstraintsAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listConstraints.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listConstraints.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listConstraints with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent=";const expectedError = new Error('expected'); + client.descriptors.page.listConstraints.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listConstraintsAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.orgpolicy.v2.IConstraint[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listConstraints.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listConstraints.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + }); + + describe('listPolicies', () => { + it('invokes listPolicies without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + ]; + client.innerApiCalls.listPolicies = stubSimpleCall(expectedResponse); + const [response] = await client.listPolicies(request); + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listPolicies as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes listPolicies without error using callback', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + ]; + client.innerApiCalls.listPolicies = stubSimpleCallWithCallback(expectedResponse); + const promise = new Promise((resolve, reject) => { + client.listPolicies( + request, + (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy[]|null) => { + if (err) { + reject(err); + } else { + resolve(result); + } + }); + }); + const response = await promise; + assert.deepStrictEqual(response, expectedResponse); + assert((client.innerApiCalls.listPolicies as SinonStub) + .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); + }); + + it('invokes listPolicies with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedOptions = { + otherArgs: { + headers: { + 'x-goog-request-params': expectedHeaderRequestParams, + }, + }, + }; + const expectedError = new Error('expected'); + client.innerApiCalls.listPolicies = stubSimpleCall(undefined, expectedError); + await assert.rejects(client.listPolicies(request), expectedError); + assert((client.innerApiCalls.listPolicies as SinonStub) + .getCall(0).calledWith(request, expectedOptions, undefined)); + }); + + it('invokes listPoliciesStream without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + ]; + client.descriptors.page.listPolicies.createStream = stubPageStreamingCall(expectedResponse); + const stream = client.listPoliciesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.orgpolicy.v2.Policy[] = []; + stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Policy) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + const responses = await promise; + assert.deepStrictEqual(responses, expectedResponse); + assert((client.descriptors.page.listPolicies.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listPolicies, request)); + assert.strictEqual( + (client.descriptors.page.listPolicies.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('invokes listPoliciesStream with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedError = new Error('expected'); + client.descriptors.page.listPolicies.createStream = stubPageStreamingCall(undefined, expectedError); + const stream = client.listPoliciesStream(request); + const promise = new Promise((resolve, reject) => { + const responses: protos.google.cloud.orgpolicy.v2.Policy[] = []; + stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Policy) => { + responses.push(response); + }); + stream.on('end', () => { + resolve(responses); + }); + stream.on('error', (err: Error) => { + reject(err); + }); + }); + await assert.rejects(promise, expectedError); + assert((client.descriptors.page.listPolicies.createStream as SinonStub) + .getCall(0).calledWith(client.innerApiCalls.listPolicies, request)); + assert.strictEqual( + (client.descriptors.page.listPolicies.createStream as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listPolicies without error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent="; + const expectedResponse = [ + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), + ]; + client.descriptors.page.listPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); + const responses: protos.google.cloud.orgpolicy.v2.IPolicy[] = []; + const iterable = client.listPoliciesAsync(request); + for await (const resource of iterable) { + responses.push(resource!); + } + assert.deepStrictEqual(responses, expectedResponse); + assert.deepStrictEqual( + (client.descriptors.page.listPolicies.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listPolicies.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + + it('uses async iteration with listPolicies with error', async () => { + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); + request.parent = ''; + const expectedHeaderRequestParams = "parent=";const expectedError = new Error('expected'); + client.descriptors.page.listPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); + const iterable = client.listPoliciesAsync(request); + await assert.rejects(async () => { + const responses: protos.google.cloud.orgpolicy.v2.IPolicy[] = []; + for await (const resource of iterable) { + responses.push(resource!); + } + }); + assert.deepStrictEqual( + (client.descriptors.page.listPolicies.asyncIterate as SinonStub) + .getCall(0).args[1], request); + assert.strictEqual( + (client.descriptors.page.listPolicies.asyncIterate as SinonStub) + .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], + expectedHeaderRequestParams + ); + }); + }); + + describe('Path templates', () => { + + describe('folderConstraint', () => { + const fakePath = "/rendered/path/folderConstraint"; + const expectedParameters = { + folder: "folderValue", + constraint: "constraintValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.folderConstraintPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.folderConstraintPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('folderConstraintPath', () => { + const result = client.folderConstraintPath("folderValue", "constraintValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.folderConstraintPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchFolderFromFolderConstraintName', () => { + const result = client.matchFolderFromFolderConstraintName(fakePath); + assert.strictEqual(result, "folderValue"); + assert((client.pathTemplates.folderConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchConstraintFromFolderConstraintName', () => { + const result = client.matchConstraintFromFolderConstraintName(fakePath); + assert.strictEqual(result, "constraintValue"); + assert((client.pathTemplates.folderConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('folderPolicy', () => { + const fakePath = "/rendered/path/folderPolicy"; + const expectedParameters = { + folder: "folderValue", + policy: "policyValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.folderPolicyPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.folderPolicyPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('folderPolicyPath', () => { + const result = client.folderPolicyPath("folderValue", "policyValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.folderPolicyPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchFolderFromFolderPolicyName', () => { + const result = client.matchFolderFromFolderPolicyName(fakePath); + assert.strictEqual(result, "folderValue"); + assert((client.pathTemplates.folderPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchPolicyFromFolderPolicyName', () => { + const result = client.matchPolicyFromFolderPolicyName(fakePath); + assert.strictEqual(result, "policyValue"); + assert((client.pathTemplates.folderPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('organizationConstraint', () => { + const fakePath = "/rendered/path/organizationConstraint"; + const expectedParameters = { + organization: "organizationValue", + constraint: "constraintValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.organizationConstraintPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.organizationConstraintPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('organizationConstraintPath', () => { + const result = client.organizationConstraintPath("organizationValue", "constraintValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.organizationConstraintPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchOrganizationFromOrganizationConstraintName', () => { + const result = client.matchOrganizationFromOrganizationConstraintName(fakePath); + assert.strictEqual(result, "organizationValue"); + assert((client.pathTemplates.organizationConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchConstraintFromOrganizationConstraintName', () => { + const result = client.matchConstraintFromOrganizationConstraintName(fakePath); + assert.strictEqual(result, "constraintValue"); + assert((client.pathTemplates.organizationConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('organizationPolicy', () => { + const fakePath = "/rendered/path/organizationPolicy"; + const expectedParameters = { + organization: "organizationValue", + policy: "policyValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.organizationPolicyPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.organizationPolicyPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('organizationPolicyPath', () => { + const result = client.organizationPolicyPath("organizationValue", "policyValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.organizationPolicyPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchOrganizationFromOrganizationPolicyName', () => { + const result = client.matchOrganizationFromOrganizationPolicyName(fakePath); + assert.strictEqual(result, "organizationValue"); + assert((client.pathTemplates.organizationPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchPolicyFromOrganizationPolicyName', () => { + const result = client.matchPolicyFromOrganizationPolicyName(fakePath); + assert.strictEqual(result, "policyValue"); + assert((client.pathTemplates.organizationPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('project', () => { + const fakePath = "/rendered/path/project"; + const expectedParameters = { + project: "projectValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectPath', () => { + const result = client.projectPath("projectValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectName', () => { + const result = client.matchProjectFromProjectName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('projectConstraint', () => { + const fakePath = "/rendered/path/projectConstraint"; + const expectedParameters = { + project: "projectValue", + constraint: "constraintValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectConstraintPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectConstraintPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectConstraintPath', () => { + const result = client.projectConstraintPath("projectValue", "constraintValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectConstraintPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectConstraintName', () => { + const result = client.matchProjectFromProjectConstraintName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchConstraintFromProjectConstraintName', () => { + const result = client.matchConstraintFromProjectConstraintName(fakePath); + assert.strictEqual(result, "constraintValue"); + assert((client.pathTemplates.projectConstraintPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + + describe('projectPolicy', () => { + const fakePath = "/rendered/path/projectPolicy"; + const expectedParameters = { + project: "projectValue", + policy: "policyValue", + }; + const client = new orgpolicyModule.v2.OrgPolicyClient({ + credentials: {client_email: 'bogus', private_key: 'bogus'}, + projectId: 'bogus', + }); + client.initialize(); + client.pathTemplates.projectPolicyPathTemplate.render = + sinon.stub().returns(fakePath); + client.pathTemplates.projectPolicyPathTemplate.match = + sinon.stub().returns(expectedParameters); + + it('projectPolicyPath', () => { + const result = client.projectPolicyPath("projectValue", "policyValue"); + assert.strictEqual(result, fakePath); + assert((client.pathTemplates.projectPolicyPathTemplate.render as SinonStub) + .getCall(-1).calledWith(expectedParameters)); + }); + + it('matchProjectFromProjectPolicyName', () => { + const result = client.matchProjectFromProjectPolicyName(fakePath); + assert.strictEqual(result, "projectValue"); + assert((client.pathTemplates.projectPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + + it('matchPolicyFromProjectPolicyName', () => { + const result = client.matchPolicyFromProjectPolicyName(fakePath); + assert.strictEqual(result, "policyValue"); + assert((client.pathTemplates.projectPolicyPathTemplate.match as SinonStub) + .getCall(-1).calledWith(fakePath)); + }); + }); + }); +}); diff --git a/owl-bot-staging/v2/tsconfig.json b/owl-bot-staging/v2/tsconfig.json new file mode 100644 index 0000000..c78f1c8 --- /dev/null +++ b/owl-bot-staging/v2/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "./node_modules/gts/tsconfig-google.json", + "compilerOptions": { + "rootDir": ".", + "outDir": "build", + "resolveJsonModule": true, + "lib": [ + "es2018", + "dom" + ] + }, + "include": [ + "src/*.ts", + "src/**/*.ts", + "test/*.ts", + "test/**/*.ts", + "system-test/*.ts" + ] +} diff --git a/owl-bot-staging/v2/webpack.config.js b/owl-bot-staging/v2/webpack.config.js new file mode 100644 index 0000000..52ea261 --- /dev/null +++ b/owl-bot-staging/v2/webpack.config.js @@ -0,0 +1,64 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +const path = require('path'); + +module.exports = { + entry: './src/index.ts', + output: { + library: 'OrgPolicy', + filename: './org-policy.js', + }, + node: { + child_process: 'empty', + fs: 'empty', + crypto: 'empty', + }, + resolve: { + alias: { + '../../../package.json': path.resolve(__dirname, 'package.json'), + }, + extensions: ['.js', '.json', '.ts'], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + use: 'ts-loader', + exclude: /node_modules/ + }, + { + test: /node_modules[\\/]@grpc[\\/]grpc-js/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]grpc/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]retry-request/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]https?-proxy-agent/, + use: 'null-loader' + }, + { + test: /node_modules[\\/]gtoken/, + use: 'null-loader' + }, + ], + }, + mode: 'production', +}; From 1a51177c37b89bb879719bc378049fb789359795 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Fri, 20 Aug 2021 23:08:22 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- owl-bot-staging/v2/.eslintignore | 6 - owl-bot-staging/v2/.eslintrc.json | 3 - owl-bot-staging/v2/.gitignore | 14 - owl-bot-staging/v2/.jsdoc.js | 55 - owl-bot-staging/v2/.mocharc.js | 33 - owl-bot-staging/v2/.prettierrc.js | 22 - owl-bot-staging/v2/README.md | 1 - owl-bot-staging/v2/linkinator.config.json | 10 - owl-bot-staging/v2/package.json | 64 - .../cloud/orgpolicy/v2/constraint.proto | 127 -- .../google/cloud/orgpolicy/v2/orgpolicy.proto | 479 ------ owl-bot-staging/v2/src/index.ts | 25 - owl-bot-staging/v2/src/v2/gapic_metadata.json | 101 -- owl-bot-staging/v2/src/v2/index.ts | 19 - .../v2/src/v2/org_policy_client.ts | 1385 ----------------- .../v2/src/v2/org_policy_client_config.json | 70 - .../v2/src/v2/org_policy_proto_list.json | 4 - .../system-test/fixtures/sample/src/index.js | 27 - .../system-test/fixtures/sample/src/index.ts | 32 - owl-bot-staging/v2/system-test/install.ts | 49 - .../v2/test/gapic_org_policy_v2.ts | 1297 --------------- owl-bot-staging/v2/tsconfig.json | 19 - owl-bot-staging/v2/webpack.config.js | 64 - src/v2/org_policy_client.ts | 6 + 24 files changed, 6 insertions(+), 3906 deletions(-) delete mode 100644 owl-bot-staging/v2/.eslintignore delete mode 100644 owl-bot-staging/v2/.eslintrc.json delete mode 100644 owl-bot-staging/v2/.gitignore delete mode 100644 owl-bot-staging/v2/.jsdoc.js delete mode 100644 owl-bot-staging/v2/.mocharc.js delete mode 100644 owl-bot-staging/v2/.prettierrc.js delete mode 100644 owl-bot-staging/v2/README.md delete mode 100644 owl-bot-staging/v2/linkinator.config.json delete mode 100644 owl-bot-staging/v2/package.json delete mode 100644 owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto delete mode 100644 owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto delete mode 100644 owl-bot-staging/v2/src/index.ts delete mode 100644 owl-bot-staging/v2/src/v2/gapic_metadata.json delete mode 100644 owl-bot-staging/v2/src/v2/index.ts delete mode 100644 owl-bot-staging/v2/src/v2/org_policy_client.ts delete mode 100644 owl-bot-staging/v2/src/v2/org_policy_client_config.json delete mode 100644 owl-bot-staging/v2/src/v2/org_policy_proto_list.json delete mode 100644 owl-bot-staging/v2/system-test/fixtures/sample/src/index.js delete mode 100644 owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts delete mode 100644 owl-bot-staging/v2/system-test/install.ts delete mode 100644 owl-bot-staging/v2/test/gapic_org_policy_v2.ts delete mode 100644 owl-bot-staging/v2/tsconfig.json delete mode 100644 owl-bot-staging/v2/webpack.config.js diff --git a/owl-bot-staging/v2/.eslintignore b/owl-bot-staging/v2/.eslintignore deleted file mode 100644 index 521dc25..0000000 --- a/owl-bot-staging/v2/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -**/node_modules -**/.coverage -build/ -docs/ -protos/ -system-test/ diff --git a/owl-bot-staging/v2/.eslintrc.json b/owl-bot-staging/v2/.eslintrc.json deleted file mode 100644 index 7821534..0000000 --- a/owl-bot-staging/v2/.eslintrc.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./node_modules/gts" -} diff --git a/owl-bot-staging/v2/.gitignore b/owl-bot-staging/v2/.gitignore deleted file mode 100644 index 5d32b23..0000000 --- a/owl-bot-staging/v2/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -**/*.log -**/node_modules -.coverage -coverage -.nyc_output -docs/ -out/ -build/ -system-test/secrets.js -system-test/*key.json -*.lock -.DS_Store -package-lock.json -__pycache__ diff --git a/owl-bot-staging/v2/.jsdoc.js b/owl-bot-staging/v2/.jsdoc.js deleted file mode 100644 index fed1fe0..0000000 --- a/owl-bot-staging/v2/.jsdoc.js +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -'use strict'; - -module.exports = { - opts: { - readme: './README.md', - package: './package.json', - template: './node_modules/jsdoc-fresh', - recurse: true, - verbose: true, - destination: './docs/' - }, - plugins: [ - 'plugins/markdown', - 'jsdoc-region-tag' - ], - source: { - excludePattern: '(^|\\/|\\\\)[._]', - include: [ - 'build/src', - 'protos' - ], - includePattern: '\\.js$' - }, - templates: { - copyright: 'Copyright 2021 Google LLC', - includeDate: false, - sourceFiles: false, - systemName: '@google-cloud/org-policy', - theme: 'lumen', - default: { - outputSourceFiles: false - } - }, - markdown: { - idInHeadings: true - } -}; diff --git a/owl-bot-staging/v2/.mocharc.js b/owl-bot-staging/v2/.mocharc.js deleted file mode 100644 index 50bc7f7..0000000 --- a/owl-bot-staging/v2/.mocharc.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -const config = { - "enable-source-maps": true, - "throw-deprecation": true, - "timeout": 10000 -} -if (process.env.MOCHA_THROW_DEPRECATION === 'false') { - delete config['throw-deprecation']; -} -if (process.env.MOCHA_REPORTER) { - config.reporter = process.env.MOCHA_REPORTER; -} -if (process.env.MOCHA_REPORTER_OUTPUT) { - config['reporter-option'] = `output=${process.env.MOCHA_REPORTER_OUTPUT}`; -} -module.exports = config diff --git a/owl-bot-staging/v2/.prettierrc.js b/owl-bot-staging/v2/.prettierrc.js deleted file mode 100644 index 84f4713..0000000 --- a/owl-bot-staging/v2/.prettierrc.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -module.exports = { - ...require('gts/.prettierrc.json') -} diff --git a/owl-bot-staging/v2/README.md b/owl-bot-staging/v2/README.md deleted file mode 100644 index 1c081c6..0000000 --- a/owl-bot-staging/v2/README.md +++ /dev/null @@ -1 +0,0 @@ -Orgpolicy: Nodejs Client diff --git a/owl-bot-staging/v2/linkinator.config.json b/owl-bot-staging/v2/linkinator.config.json deleted file mode 100644 index 29a223b..0000000 --- a/owl-bot-staging/v2/linkinator.config.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "recurse": true, - "skip": [ - "https://codecov.io/gh/googleapis/", - "www.googleapis.com", - "img.shields.io" - ], - "silent": true, - "concurrency": 10 -} diff --git a/owl-bot-staging/v2/package.json b/owl-bot-staging/v2/package.json deleted file mode 100644 index e16c9ca..0000000 --- a/owl-bot-staging/v2/package.json +++ /dev/null @@ -1,64 +0,0 @@ -{ - "name": "@google-cloud/org-policy", - "version": "0.1.0", - "description": "Orgpolicy client for Node.js", - "repository": "googleapis/nodejs-orgpolicy", - "license": "Apache-2.0", - "author": "Google LLC", - "main": "build/src/index.js", - "files": [ - "build/src", - "build/protos" - ], - "keywords": [ - "google apis client", - "google api client", - "google apis", - "google api", - "google", - "google cloud platform", - "google cloud", - "cloud", - "google orgpolicy", - "orgpolicy", - "org policy" - ], - "scripts": { - "clean": "gts clean", - "compile": "tsc -p . && cp -r protos build/", - "compile-protos": "compileProtos src", - "docs": "jsdoc -c .jsdoc.js", - "predocs-test": "npm run docs", - "docs-test": "linkinator docs", - "fix": "gts fix", - "lint": "gts check", - "prepare": "npm run compile-protos && npm run compile", - "system-test": "c8 mocha build/system-test", - "test": "c8 mocha build/test" - }, - "dependencies": { - "google-gax": "^2.19.0" - }, - "devDependencies": { - "@types/mocha": "^9.0.0", - "@types/node": "^14.17.3", - "@types/sinon": "^10.0.2", - "c8": "^7.7.3", - "gts": "^3.1.0", - "jsdoc": "^3.6.7", - "jsdoc-fresh": "^1.1.0", - "jsdoc-region-tag": "^1.1.0", - "linkinator": "^2.13.6", - "mocha": "^9.0.2", - "null-loader": "^4.0.1", - "pack-n-play": "^1.0.0-2", - "sinon": "^11.1.1", - "ts-loader": "^9.2.3", - "typescript": "^4.3.4", - "webpack": "^5.39.1", - "webpack-cli": "^4.7.2" - }, - "engines": { - "node": ">=v10.24.0" - } -} diff --git a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto deleted file mode 100644 index a9051ac..0000000 --- a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/constraint.proto +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.cloud.orgpolicy.v2; - -import "google/api/field_behavior.proto"; -import "google/api/resource.proto"; - -option csharp_namespace = "Google.Cloud.OrgPolicy.V2"; -option go_package = "google.golang.org/genproto/googleapis/cloud/orgpolicy/v2;orgpolicy"; -option java_multiple_files = true; -option java_outer_classname = "ConstraintProto"; -option java_package = "com.google.cloud.orgpolicy.v2"; -option php_namespace = "Google\\Cloud\\OrgPolicy\\V2"; -option ruby_package = "Google::Cloud::OrgPolicy::V2"; - -// A `constraint` describes a way to restrict resource's configuration. For -// example, you could enforce a constraint that controls which cloud services -// can be activated across an organization, or whether a Compute Engine instance -// can have serial port connections established. `Constraints` can be configured -// by the organization's policy adminstrator to fit the needs of the organzation -// by setting a `policy` that includes `constraints` at different locations in -// the organization's resource hierarchy. Policies are inherited down the -// resource hierarchy from higher levels, but can also be overridden. For -// details about the inheritance rules please read about -// [`policies`][google.cloud.OrgPolicy.v2.Policy]. -// -// `Constraints` have a default behavior determined by the `constraint_default` -// field, which is the enforcement behavior that is used in the absence of a -// `policy` being defined or inherited for the resource in question. -message Constraint { - option (google.api.resource) = { - type: "orgpolicy.googleapis.com/Constraint" - pattern: "projects/{project}/constraints/{constraint}" - pattern: "folders/{folder}/constraints/{constraint}" - pattern: "organizations/{organization}/constraints/{constraint}" - }; - - // A `Constraint` that allows or disallows a list of string values, which are - // configured by an Organization's policy administrator with a `Policy`. - message ListConstraint { - // Indicates whether values grouped into categories can be used in - // `Policy.allowed_values` and `Policy.denied_values`. For example, - // `"in:Python"` would match any value in the 'Python' group. - bool supports_in = 1; - - // Indicates whether subtrees of Cloud Resource Manager resource hierarchy - // can be used in `Policy.allowed_values` and `Policy.denied_values`. For - // example, `"under:folders/123"` would match any resource under the - // 'folders/123' folder. - bool supports_under = 2; - } - - // A `Constraint` that is either enforced or not. - // - // For example a constraint `constraints/compute.disableSerialPortAccess`. - // If it is enforced on a VM instance, serial port connections will not be - // opened to that instance. - message BooleanConstraint { - - } - - // Specifies the default behavior in the absence of any `Policy` for the - // `Constraint`. This must not be `CONSTRAINT_DEFAULT_UNSPECIFIED`. - // - // Immutable after creation. - enum ConstraintDefault { - // This is only used for distinguishing unset values and should never be - // used. - CONSTRAINT_DEFAULT_UNSPECIFIED = 0; - - // Indicate that all values are allowed for list constraints. - // Indicate that enforcement is off for boolean constraints. - ALLOW = 1; - - // Indicate that all values are denied for list constraints. - // Indicate that enforcement is on for boolean constraints. - DENY = 2; - } - - // Immutable. The resource name of the Constraint. Must be in one of - // the following forms: - // * `projects/{project_number}/constraints/{constraint_name}` - // * `folders/{folder_id}/constraints/{constraint_name}` - // * `organizations/{organization_id}/constraints/{constraint_name}` - // - // For example, "/projects/123/constraints/compute.disableSerialPortAccess". - string name = 1 [(google.api.field_behavior) = IMMUTABLE]; - - // The human readable name. - // - // Mutable. - string display_name = 2; - - // Detailed description of what this `Constraint` controls as well as how and - // where it is enforced. - // - // Mutable. - string description = 3; - - // The evaluation behavior of this constraint in the absence of 'Policy'. - ConstraintDefault constraint_default = 4; - - // The type of restrictions for this `Constraint`. - // - // Immutable after creation. - oneof constraint_type { - // Defines this constraint as being a ListConstraint. - ListConstraint list_constraint = 5; - - // Defines this constraint as being a BooleanConstraint. - BooleanConstraint boolean_constraint = 6; - } -} diff --git a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto b/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto deleted file mode 100644 index 2b2bb47..0000000 --- a/owl-bot-staging/v2/protos/google/cloud/orgpolicy/v2/orgpolicy.proto +++ /dev/null @@ -1,479 +0,0 @@ -// Copyright 2020 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -syntax = "proto3"; - -package google.cloud.orgpolicy.v2; - -import "google/api/annotations.proto"; -import "google/api/client.proto"; -import "google/api/field_behavior.proto"; -import "google/api/resource.proto"; -import "google/cloud/orgpolicy/v2/constraint.proto"; -import "google/protobuf/empty.proto"; -import "google/protobuf/timestamp.proto"; -import "google/type/expr.proto"; - -option csharp_namespace = "Google.Cloud.OrgPolicy.V2"; -option go_package = "google.golang.org/genproto/googleapis/cloud/orgpolicy/v2;orgpolicy"; -option java_multiple_files = true; -option java_outer_classname = "OrgPolicyProto"; -option java_package = "com.google.cloud.orgpolicy.v2"; -option php_namespace = "Google\\Cloud\\OrgPolicy\\V2"; -option ruby_package = "Google::Cloud::OrgPolicy::V2"; - -// An interface for managing organization policies. -// -// The Cloud Org Policy service provides a simple mechanism for organizations to -// restrict the allowed configurations across their entire Cloud Resource -// hierarchy. -// -// You can use a `policy` to configure restrictions in Cloud resources. For -// example, you can enforce a `policy` that restricts which Google -// Cloud Platform APIs can be activated in a certain part of your resource -// hierarchy, or prevents serial port access to VM instances in a particular -// folder. -// -// `Policies` are inherited down through the resource hierarchy. A `policy` -// applied to a parent resource automatically applies to all its child resources -// unless overridden with a `policy` lower in the hierarchy. -// -// A `constraint` defines an aspect of a resource's configuration that can be -// controlled by an organization's policy administrator. `Policies` are a -// collection of `constraints` that defines their allowable configuration on a -// particular resource and its child resources. -service OrgPolicy { - option (google.api.default_host) = "orgpolicy.googleapis.com"; - option (google.api.oauth_scopes) = "https://www.googleapis.com/auth/cloud-platform"; - - // Lists `Constraints` that could be applied on the specified resource. - rpc ListConstraints(ListConstraintsRequest) returns (ListConstraintsResponse) { - option (google.api.http) = { - get: "/v2/{parent=projects/*}/constraints" - additional_bindings { - get: "/v2/{parent=folders/*}/constraints" - } - additional_bindings { - get: "/v2/{parent=organizations/*}/constraints" - } - }; - option (google.api.method_signature) = "parent"; - } - - // Retrieves all of the `Policies` that exist on a particular resource. - rpc ListPolicies(ListPoliciesRequest) returns (ListPoliciesResponse) { - option (google.api.http) = { - get: "/v2/{parent=projects/*}/policies" - additional_bindings { - get: "/v2/{parent=folders/*}/policies" - } - additional_bindings { - get: "/v2/{parent=organizations/*}/policies" - } - }; - option (google.api.method_signature) = "parent"; - } - - // Gets a `Policy` on a resource. - // - // If no `Policy` is set on the resource, NOT_FOUND is returned. The - // `etag` value can be used with `UpdatePolicy()` to update a - // `Policy` during read-modify-write. - rpc GetPolicy(GetPolicyRequest) returns (Policy) { - option (google.api.http) = { - get: "/v2/{name=projects/*/policies/*}" - additional_bindings { - get: "/v2/{name=folders/*/policies/*}" - } - additional_bindings { - get: "/v2/{name=organizations/*/policies/*}" - } - }; - option (google.api.method_signature) = "name"; - } - - // Gets the effective `Policy` on a resource. This is the result of merging - // `Policies` in the resource hierarchy and evaluating conditions. The - // returned `Policy` will not have an `etag` or `condition` set because it is - // a computed `Policy` across multiple resources. - // Subtrees of Resource Manager resource hierarchy with 'under:' prefix will - // not be expanded. - rpc GetEffectivePolicy(GetEffectivePolicyRequest) returns (Policy) { - option (google.api.http) = { - get: "/v2/{name=projects/*/policies/*}:getEffectivePolicy" - additional_bindings { - get: "/v2/{name=folders/*/policies/*}:getEffectivePolicy" - } - additional_bindings { - get: "/v2/{name=organizations/*/policies/*}:getEffectivePolicy" - } - }; - option (google.api.method_signature) = "name"; - } - - // Creates a Policy. - // - // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - // constraint does not exist. - // Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the - // policy already exists on the given Cloud resource. - rpc CreatePolicy(CreatePolicyRequest) returns (Policy) { - option (google.api.http) = { - post: "/v2/{parent=projects/*}/policies" - body: "policy" - additional_bindings { - post: "/v2/{parent=folders/*}/policies" - body: "policy" - } - additional_bindings { - post: "/v2/{parent=organizations/*}/policies" - body: "policy" - } - }; - option (google.api.method_signature) = "parent,policy"; - } - - // Updates a Policy. - // - // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - // constraint or the policy do not exist. - // Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag - // supplied in the request does not match the persisted etag of the policy - // - // Note: the supplied policy will perform a full overwrite of all - // fields. - rpc UpdatePolicy(UpdatePolicyRequest) returns (Policy) { - option (google.api.http) = { - patch: "/v2/{policy.name=projects/*/policies/*}" - body: "policy" - additional_bindings { - patch: "/v2/{policy.name=folders/*/policies/*}" - body: "policy" - } - additional_bindings { - patch: "/v2/{policy.name=organizations/*/policies/*}" - body: "policy" - } - }; - option (google.api.method_signature) = "policy"; - } - - // Deletes a Policy. - // - // Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - // constraint or Org Policy does not exist. - rpc DeletePolicy(DeletePolicyRequest) returns (google.protobuf.Empty) { - option (google.api.http) = { - delete: "/v2/{name=projects/*/policies/*}" - additional_bindings { - delete: "/v2/{name=folders/*/policies/*}" - } - additional_bindings { - delete: "/v2/{name=organizations/*/policies/*}" - } - }; - option (google.api.method_signature) = "name"; - } -} - -// Defines a Cloud Organization `Policy` which is used to specify `Constraints` -// for configurations of Cloud Platform resources. -message Policy { - option (google.api.resource) = { - type: "orgpolicy.googleapis.com/Policy" - pattern: "projects/{project}/policies/{policy}" - pattern: "folders/{folder}/policies/{policy}" - pattern: "organizations/{organization}/policies/{policy}" - }; - - // Immutable. The resource name of the Policy. Must be one of the following - // forms, where constraint_name is the name of the constraint which this - // Policy configures: - // * `projects/{project_number}/policies/{constraint_name}` - // * `folders/{folder_id}/policies/{constraint_name}` - // * `organizations/{organization_id}/policies/{constraint_name}` - // - // For example, "projects/123/policies/compute.disableSerialPortAccess". - // - // Note: `projects/{project_id}/policies/{constraint_name}` is also an - // acceptable name for API requests, but responses will return the name using - // the equivalent project number. - string name = 1 [(google.api.field_behavior) = IMMUTABLE]; - - // Basic information about the Organization Policy. - PolicySpec spec = 2; - - // An alternate policy configuration that will be used instead of the baseline - // policy configurations as determined by the launch. - // Currently the only way the launch can trigger the alternate configuration - // is via dry-run/darklaunch. - AlternatePolicySpec alternate = 3; -} - -// Similar to PolicySpec but with an extra 'launch' field for launch reference. -// The PolicySpec here is specific for dry-run/darklaunch. -message AlternatePolicySpec { - // Reference to the launch that will be used while audit logging and to - // control the launch. - // Should be set only in the alternate policy. - string launch = 1; - - // Specify `Constraint` for configurations of Cloud Platform resources. - PolicySpec spec = 2; -} - -// Defines a Cloud Organization `PolicySpec` which is used to specify -// `Constraints` for configurations of Cloud Platform resources. -message PolicySpec { - // A rule used to express this policy. - message PolicyRule { - // A message that holds specific allowed and denied values. - // This message can define specific values and subtrees of Cloud Resource - // Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that - // are allowed or denied. This is achieved by using the `under:` and - // optional `is:` prefixes. - // The `under:` prefix is used to denote resource subtree values. - // The `is:` prefix is used to denote specific values, and is required only - // if the value contains a ":". Values prefixed with "is:" are treated the - // same as values with no prefix. - // Ancestry subtrees must be in one of the following formats: - // - "projects/", e.g. "projects/tokyo-rain-123" - // - "folders/", e.g. "folders/1234" - // - "organizations/", e.g. "organizations/1234" - // The `supports_under` field of the associated `Constraint` defines - // whether ancestry prefixes can be used. - message StringValues { - // List of values allowed at this resource. - repeated string allowed_values = 1; - - // List of values denied at this resource. - repeated string denied_values = 2; - } - - oneof kind { - // List of values to be used for this PolicyRule. This field can be set - // only in Policies for list constraints. - StringValues values = 1; - - // Setting this to true means that all values are allowed. This field can - // be set only in Policies for list constraints. - bool allow_all = 2; - - // Setting this to true means that all values are denied. This field can - // be set only in Policies for list constraints. - bool deny_all = 3; - - // If `true`, then the `Policy` is enforced. If `false`, then any - // configuration is acceptable. - // This field can be set only in Policies for boolean constraints. - bool enforce = 4; - } - - // A condition which determines whether this rule is used - // in the evaluation of the policy. When set, the `expression` field in - // the `Expr' must include from 1 to 10 subexpressions, joined by the "||" - // or "&&" operators. Each subexpression must be of the form - // "resource.matchLabels(key_name, value_name)", - // where key_name and value_name are the resource names for Label Keys - // and Values. These names are available from the Label Manager Service. An - // example expression is: - // "resource.matchLabels('labelKeys/123, 'labelValues/456')". - google.type.Expr condition = 5; - } - - // An opaque tag indicating the current version of the `Policy`, used for - // concurrency control. - // - // This field is ignored if used in a `CreatePolicy` request. - // - // When the `Policy` is returned from either a `GetPolicy` or a - // `ListPolicies` request, this `etag` indicates the version of the - // current `Policy` to use when executing a read-modify-write loop. - // - // When the `Policy` is returned from a `GetEffectivePolicy` request, the - // `etag` will be unset. - string etag = 1; - - // Output only. The time stamp this was previously updated. This - // represents the last time a call to `CreatePolicy` or `UpdatePolicy` was - // made for that `Policy`. - google.protobuf.Timestamp update_time = 2 [(google.api.field_behavior) = OUTPUT_ONLY]; - - // Up to 10 PolicyRules are allowed. - // - // In Policies for boolean constraints, the following requirements apply: - // - There must be one and only one PolicyRule where condition is unset. - // - BooleanPolicyRules with conditions must set `enforced` to the opposite - // of the PolicyRule without a condition. - // - During policy evaluation, PolicyRules with conditions that are - // true for a target resource take precedence. - repeated PolicyRule rules = 3; - - // Determines the inheritance behavior for this `Policy`. - // - // If `inherit_from_parent` is true, PolicyRules set higher up in the - // hierarchy (up to the closest root) are inherited and present in the - // effective policy. If it is false, then no rules are inherited, and this - // Policy becomes the new root for evaluation. - // This field can be set only for Policies which configure list constraints. - bool inherit_from_parent = 4; - - // Ignores policies set above this resource and restores the - // `constraint_default` enforcement behavior of the specific `Constraint` at - // this resource. - // This field can be set in policies for either list or boolean - // constraints. If set, `rules` must be empty and `inherit_from_parent` - // must be set to false. - bool reset = 5; -} - -// The request sent to the [ListConstraints] -// [google.cloud.orgpolicy.v2.OrgPolicy.ListConstraints] method. -message ListConstraintsRequest { - // Required. The Cloud resource that parents the constraint. Must be in one of the - // following forms: - // * `projects/{project_number}` - // * `projects/{project_id}` - // * `folders/{folder_id}` - // * `organizations/{organization_id}` - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "orgpolicy.googleapis.com/Constraint" - } - ]; - - // Size of the pages to be returned. This is currently unsupported and will - // be ignored. The server may at any point start using this field to limit - // page size. - int32 page_size = 2; - - // Page token used to retrieve the next page. This is currently unsupported - // and will be ignored. The server may at any point start using this field. - string page_token = 3; -} - -// The response returned from the [ListConstraints] -// [google.cloud.orgpolicy.v2.OrgPolicy.ListConstraints] method. -message ListConstraintsResponse { - // The collection of constraints that are available on the targeted resource. - repeated Constraint constraints = 1; - - // Page token used to retrieve the next page. This is currently not used. - string next_page_token = 2; -} - -// The request sent to the [ListPolicies] -// [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. -message ListPoliciesRequest { - // Required. The target Cloud resource that parents the set of constraints and policies - // that will be returned from this call. Must be in one of the following - // forms: - // * `projects/{project_number}` - // * `projects/{project_id}` - // * `folders/{folder_id}` - // * `organizations/{organization_id}` - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "orgpolicy.googleapis.com/Policy" - } - ]; - - // Size of the pages to be returned. This is currently unsupported and will - // be ignored. The server may at any point start using this field to limit - // page size. - int32 page_size = 2; - - // Page token used to retrieve the next page. This is currently unsupported - // and will be ignored. The server may at any point start using this field. - string page_token = 3; -} - -// The response returned from the [ListPolicies] -// [google.cloud.orgpolicy.v2.OrgPolicy.ListPolicies] method. It will be empty -// if no `Policies` are set on the resource. -message ListPoliciesResponse { - // All `Policies` that exist on the resource. It will be empty if no - // `Policies` are set. - repeated Policy policies = 1; - - // Page token used to retrieve the next page. This is currently not used, but - // the server may at any point start supplying a valid token. - string next_page_token = 2; -} - -// The request sent to the [GetPolicy] -// [google.cloud.orgpolicy.v2.OrgPolicy.GetPolicy] method. -message GetPolicyRequest { - // Required. Resource name of the policy. See `Policy` for naming requirements. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "orgpolicy.googleapis.com/Policy" - } - ]; -} - -// The request sent to the [GetEffectivePolicy] -// [google.cloud.orgpolicy.v2.OrgPolicy.GetEffectivePolicy] method. -message GetEffectivePolicyRequest { - // Required. The effective policy to compute. See `Policy` for naming rules. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "orgpolicy.googleapis.com/Policy" - } - ]; -} - -// The request sent to the [CreatePolicyRequest] -// [google.cloud.orgpolicy.v2.OrgPolicy.CreatePolicy] method. -message CreatePolicyRequest { - // Required. The Cloud resource that will parent the new Policy. Must be in one of the - // following forms: - // * `projects/{project_number}` - // * `projects/{project_id}` - // * `folders/{folder_id}` - // * `organizations/{organization_id}` - string parent = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - child_type: "orgpolicy.googleapis.com/Policy" - } - ]; - - // Required. `Policy` to create. - Policy policy = 3 [(google.api.field_behavior) = REQUIRED]; -} - -// The request sent to the [UpdatePolicyRequest] -// [google.cloud.orgpolicy.v2.OrgPolicy.UpdatePolicy] method. -message UpdatePolicyRequest { - // Required. `Policy` to update. - Policy policy = 1 [(google.api.field_behavior) = REQUIRED]; -} - -// The request sent to the [DeletePolicy] -// [google.cloud.orgpolicy.v2.OrgPolicy.DeletePolicy] method. -message DeletePolicyRequest { - // Required. Name of the policy to delete. - // See `Policy` for naming rules. - string name = 1 [ - (google.api.field_behavior) = REQUIRED, - (google.api.resource_reference) = { - type: "orgpolicy.googleapis.com/Policy" - } - ]; -} diff --git a/owl-bot-staging/v2/src/index.ts b/owl-bot-staging/v2/src/index.ts deleted file mode 100644 index ea8b87a..0000000 --- a/owl-bot-staging/v2/src/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as v2 from './v2'; -const OrgPolicyClient = v2.OrgPolicyClient; -type OrgPolicyClient = v2.OrgPolicyClient; -export {v2, OrgPolicyClient}; -export default {v2, OrgPolicyClient}; -import * as protos from '../protos/protos'; -export {protos} diff --git a/owl-bot-staging/v2/src/v2/gapic_metadata.json b/owl-bot-staging/v2/src/v2/gapic_metadata.json deleted file mode 100644 index 3fd440b..0000000 --- a/owl-bot-staging/v2/src/v2/gapic_metadata.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "schema": "1.0", - "comment": "This file maps proto services/RPCs to the corresponding library clients/methods", - "language": "typescript", - "protoPackage": "google.cloud.orgpolicy.v2", - "libraryPackage": "@google-cloud/org-policy", - "services": { - "OrgPolicy": { - "clients": { - "grpc": { - "libraryClient": "OrgPolicyClient", - "rpcs": { - "GetPolicy": { - "methods": [ - "getPolicy" - ] - }, - "GetEffectivePolicy": { - "methods": [ - "getEffectivePolicy" - ] - }, - "CreatePolicy": { - "methods": [ - "createPolicy" - ] - }, - "UpdatePolicy": { - "methods": [ - "updatePolicy" - ] - }, - "DeletePolicy": { - "methods": [ - "deletePolicy" - ] - }, - "ListConstraints": { - "methods": [ - "listConstraints", - "listConstraintsStream", - "listConstraintsAsync" - ] - }, - "ListPolicies": { - "methods": [ - "listPolicies", - "listPoliciesStream", - "listPoliciesAsync" - ] - } - } - }, - "grpc-fallback": { - "libraryClient": "OrgPolicyClient", - "rpcs": { - "GetPolicy": { - "methods": [ - "getPolicy" - ] - }, - "GetEffectivePolicy": { - "methods": [ - "getEffectivePolicy" - ] - }, - "CreatePolicy": { - "methods": [ - "createPolicy" - ] - }, - "UpdatePolicy": { - "methods": [ - "updatePolicy" - ] - }, - "DeletePolicy": { - "methods": [ - "deletePolicy" - ] - }, - "ListConstraints": { - "methods": [ - "listConstraints", - "listConstraintsStream", - "listConstraintsAsync" - ] - }, - "ListPolicies": { - "methods": [ - "listPolicies", - "listPoliciesStream", - "listPoliciesAsync" - ] - } - } - } - } - } - } -} diff --git a/owl-bot-staging/v2/src/v2/index.ts b/owl-bot-staging/v2/src/v2/index.ts deleted file mode 100644 index 0046424..0000000 --- a/owl-bot-staging/v2/src/v2/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -export {OrgPolicyClient} from './org_policy_client'; diff --git a/owl-bot-staging/v2/src/v2/org_policy_client.ts b/owl-bot-staging/v2/src/v2/org_policy_client.ts deleted file mode 100644 index 8235d58..0000000 --- a/owl-bot-staging/v2/src/v2/org_policy_client.ts +++ /dev/null @@ -1,1385 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -/* global window */ -import * as gax from 'google-gax'; -import {Callback, CallOptions, Descriptors, ClientOptions, PaginationCallback, GaxCall} from 'google-gax'; - -import { Transform } from 'stream'; -import { RequestType } from 'google-gax/build/src/apitypes'; -import * as protos from '../../protos/protos'; -import jsonProtos = require('../../protos/protos.json'); -/** - * Client JSON configuration object, loaded from - * `src/v2/org_policy_client_config.json`. - * This file defines retry strategy and timeouts for all API methods in this library. - */ -import * as gapicConfig from './org_policy_client_config.json'; - -const version = require('../../../package.json').version; - -/** - * An interface for managing organization policies. - * - * The Cloud Org Policy service provides a simple mechanism for organizations to - * restrict the allowed configurations across their entire Cloud Resource - * hierarchy. - * - * You can use a `policy` to configure restrictions in Cloud resources. For - * example, you can enforce a `policy` that restricts which Google - * Cloud Platform APIs can be activated in a certain part of your resource - * hierarchy, or prevents serial port access to VM instances in a particular - * folder. - * - * `Policies` are inherited down through the resource hierarchy. A `policy` - * applied to a parent resource automatically applies to all its child resources - * unless overridden with a `policy` lower in the hierarchy. - * - * A `constraint` defines an aspect of a resource's configuration that can be - * controlled by an organization's policy administrator. `Policies` are a - * collection of `constraints` that defines their allowable configuration on a - * particular resource and its child resources. - * @class - * @memberof v2 - */ -export class OrgPolicyClient { - private _terminated = false; - private _opts: ClientOptions; - private _providedCustomServicePath: boolean; - private _gaxModule: typeof gax | typeof gax.fallback; - private _gaxGrpc: gax.GrpcClient | gax.fallback.GrpcClient; - private _protos: {}; - private _defaults: {[method: string]: gax.CallSettings}; - auth: gax.GoogleAuth; - descriptors: Descriptors = { - page: {}, - stream: {}, - longrunning: {}, - batching: {}, - }; - warn: (code: string, message: string, warnType?: string) => void; - innerApiCalls: {[name: string]: Function}; - pathTemplates: {[name: string]: gax.PathTemplate}; - orgPolicyStub?: Promise<{[name: string]: Function}>; - - /** - * Construct an instance of OrgPolicyClient. - * - * @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). - * The common options are: - * @param {object} [options.credentials] - Credentials object. - * @param {string} [options.credentials.client_email] - * @param {string} [options.credentials.private_key] - * @param {string} [options.email] - Account email address. Required when - * using a .pem or .p12 keyFilename. - * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option below is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number} [options.port] - The port on which to connect to - * the remote host. - * @param {string} [options.projectId] - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {string} [options.apiEndpoint] - The domain name of the - * 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. - */ - constructor(opts?: ClientOptions) { - // Ensure that options include all the required fields. - const staticMembers = this.constructor as typeof OrgPolicyClient; - const servicePath = opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath; - this._providedCustomServicePath = !!(opts?.servicePath || opts?.apiEndpoint); - const port = opts?.port || staticMembers.port; - const clientConfig = opts?.clientConfig ?? {}; - const fallback = opts?.fallback ?? (typeof window !== 'undefined' && typeof window?.fetch === 'function'); - opts = Object.assign({servicePath, port, clientConfig, fallback}, opts); - - // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case. - if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) { - opts['scopes'] = staticMembers.scopes; - } - - // Choose either gRPC or proto-over-HTTP implementation of google-gax. - this._gaxModule = opts.fallback ? gax.fallback : gax; - - // Create a `gaxGrpc` object, with any grpc-specific options sent to the client. - this._gaxGrpc = new this._gaxModule.GrpcClient(opts); - - // Save options to use in initialize() method. - this._opts = opts; - - // Save the auth object to the client, for use by other methods. - this.auth = (this._gaxGrpc.auth as gax.GoogleAuth); - - // Set useJWTAccessWithScope on the auth object. - this.auth.useJWTAccessWithScope = true; - - // Set defaultServicePath on the auth object. - this.auth.defaultServicePath = staticMembers.servicePath; - - // Set the default scopes in auth client if needed. - if (servicePath === staticMembers.servicePath) { - this.auth.defaultScopes = staticMembers.scopes; - } - - // Determine the client header string. - const clientHeader = [ - `gax/${this._gaxModule.version}`, - `gapic/${version}`, - ]; - if (typeof process !== 'undefined' && 'versions' in process) { - clientHeader.push(`gl-node/${process.versions.node}`); - } else { - clientHeader.push(`gl-web/${this._gaxModule.version}`); - } - if (!opts.fallback) { - clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`); - } else if (opts.fallback === 'rest' ) { - clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`); - } - if (opts.libName && opts.libVersion) { - clientHeader.push(`${opts.libName}/${opts.libVersion}`); - } - // Load the applicable protos. - this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos); - - // This API contains "path templates"; forward-slash-separated - // identifiers to uniquely identify resources within the API. - // Create useful helper objects for these. - this.pathTemplates = { - folderConstraintPathTemplate: new this._gaxModule.PathTemplate( - 'folders/{folder}/constraints/{constraint}' - ), - folderPolicyPathTemplate: new this._gaxModule.PathTemplate( - 'folders/{folder}/policies/{policy}' - ), - organizationConstraintPathTemplate: new this._gaxModule.PathTemplate( - 'organizations/{organization}/constraints/{constraint}' - ), - organizationPolicyPathTemplate: new this._gaxModule.PathTemplate( - 'organizations/{organization}/policies/{policy}' - ), - projectPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}' - ), - projectConstraintPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/constraints/{constraint}' - ), - projectPolicyPathTemplate: new this._gaxModule.PathTemplate( - 'projects/{project}/policies/{policy}' - ), - }; - - // Some of the methods on this service return "paged" results, - // (e.g. 50 results at a time, with tokens to get subsequent - // pages). Denote the keys used for pagination and results. - this.descriptors.page = { - listConstraints: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'constraints'), - listPolicies: - new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'policies') - }; - - // Put together the default options sent with requests. - this._defaults = this._gaxGrpc.constructSettings( - 'google.cloud.orgpolicy.v2.OrgPolicy', gapicConfig as gax.ClientConfig, - opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}); - - // Set up a dictionary of "inner API calls"; the core implementation - // of calling the API is handled in `google-gax`, with this code - // merely providing the destination and request information. - this.innerApiCalls = {}; - - // Add a warn function to the client constructor so it can be easily tested. - this.warn = gax.warn; - } - - /** - * Initialize the client. - * Performs asynchronous operations (such as authentication) and prepares the client. - * This function will be called automatically when any class method is called for the - * first time, but if you need to initialize it before calling an actual method, - * feel free to call initialize() directly. - * - * You can await on this method if you want to make sure the client is initialized. - * - * @returns {Promise} A promise that resolves to an authenticated service stub. - */ - initialize() { - // If the client stub promise is already initialized, return immediately. - if (this.orgPolicyStub) { - return this.orgPolicyStub; - } - - // Put together the "service stub" for - // google.cloud.orgpolicy.v2.OrgPolicy. - this.orgPolicyStub = this._gaxGrpc.createStub( - this._opts.fallback ? - (this._protos as protobuf.Root).lookupService('google.cloud.orgpolicy.v2.OrgPolicy') : - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (this._protos as any).google.cloud.orgpolicy.v2.OrgPolicy, - this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>; - - // Iterate over each of the methods that the service provides - // and create an API call method for each. - const orgPolicyStubMethods = - ['listConstraints', 'listPolicies', 'getPolicy', 'getEffectivePolicy', 'createPolicy', 'updatePolicy', 'deletePolicy']; - for (const methodName of orgPolicyStubMethods) { - const callPromise = this.orgPolicyStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, - (err: Error|null|undefined) => () => { - throw err; - }); - - const descriptor = - this.descriptors.page[methodName] || - undefined; - const apiCall = this._gaxModule.createApiCall( - callPromise, - this._defaults[methodName], - descriptor - ); - - this.innerApiCalls[methodName] = apiCall; - } - - return this.orgPolicyStub; - } - - /** - * The DNS address for this API service. - * @returns {string} The DNS address for this service. - */ - static get servicePath() { - return 'orgpolicy.googleapis.com'; - } - - /** - * The DNS address for this API service - same as servicePath(), - * exists for compatibility reasons. - * @returns {string} The DNS address for this service. - */ - static get apiEndpoint() { - return 'orgpolicy.googleapis.com'; - } - - /** - * The port for this API service. - * @returns {number} The default port for this service. - */ - static get port() { - return 443; - } - - /** - * The scopes needed to make gRPC calls for every method defined - * in this service. - * @returns {string[]} List of default scopes. - */ - static get scopes() { - return [ - 'https://www.googleapis.com/auth/cloud-platform' - ]; - } - - getProjectId(): Promise; - getProjectId(callback: Callback): void; - /** - * Return the project ID used by this class. - * @returns {Promise} A promise that resolves to string containing the project ID. - */ - getProjectId(callback?: Callback): - Promise|void { - if (callback) { - this.auth.getProjectId(callback); - return; - } - return this.auth.getProjectId(); - } - - // ------------------- - // -- Service calls -- - // ------------------- - getPolicy( - request?: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|undefined, {}|undefined - ]>; - getPolicy( - request: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, - {}|null|undefined>): void; - getPolicy( - request: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, - {}|null|undefined>): void; -/** - * Gets a `Policy` on a resource. - * - * If no `Policy` is set on the resource, NOT_FOUND is returned. The - * `etag` value can be used with `UpdatePolicy()` to update a - * `Policy` during read-modify-write. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Resource name of the policy. See `Policy` for naming requirements. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example - * const [response] = await client.getPolicy(request); - */ - getPolicy( - request?: protos.google.cloud.orgpolicy.v2.IGetPolicyRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetPolicyRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'name': request.name || '', - }); - this.initialize(); - return this.innerApiCalls.getPolicy(request, options, callback); - } - getEffectivePolicy( - request?: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|undefined, {}|undefined - ]>; - getEffectivePolicy( - request: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, - {}|null|undefined>): void; - getEffectivePolicy( - request: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, - {}|null|undefined>): void; -/** - * Gets the effective `Policy` on a resource. This is the result of merging - * `Policies` in the resource hierarchy and evaluating conditions. The - * returned `Policy` will not have an `etag` or `condition` set because it is - * a computed `Policy` across multiple resources. - * Subtrees of Resource Manager resource hierarchy with 'under:' prefix will - * not be expanded. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. The effective policy to compute. See `Policy` for naming rules. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example - * const [response] = await client.getEffectivePolicy(request); - */ - getEffectivePolicy( - request?: protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IGetEffectivePolicyRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'name': request.name || '', - }); - this.initialize(); - return this.innerApiCalls.getEffectivePolicy(request, options, callback); - } - createPolicy( - request?: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|undefined, {}|undefined - ]>; - createPolicy( - request: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, - {}|null|undefined>): void; - createPolicy( - request: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, - {}|null|undefined>): void; -/** - * Creates a Policy. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint does not exist. - * Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the - * policy already exists on the given Cloud resource. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The Cloud resource that will parent the new Policy. Must be in one of the - * following forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {google.cloud.orgpolicy.v2.Policy} request.policy - * Required. `Policy` to create. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example - * const [response] = await client.createPolicy(request); - */ - createPolicy( - request?: protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.ICreatePolicyRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - this.initialize(); - return this.innerApiCalls.createPolicy(request, options, callback); - } - updatePolicy( - request?: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|undefined, {}|undefined - ]>; - updatePolicy( - request: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, - {}|null|undefined>): void; - updatePolicy( - request: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, - callback: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, - {}|null|undefined>): void; -/** - * Updates a Policy. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint or the policy do not exist. - * Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag - * supplied in the request does not match the persisted etag of the policy - * - * Note: the supplied policy will perform a full overwrite of all - * fields. - * - * @param {Object} request - * The request object that will be sent. - * @param {google.cloud.orgpolicy.v2.Policy} request.policy - * Required. `Policy` to update. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example - * const [response] = await client.updatePolicy(request); - */ - updatePolicy( - request?: protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy, - protos.google.cloud.orgpolicy.v2.IUpdatePolicyRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'policy.name': request.policy!.name || '', - }); - this.initialize(); - return this.innerApiCalls.updatePolicy(request, options, callback); - } - deletePolicy( - request?: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, - options?: CallOptions): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|undefined, {}|undefined - ]>; - deletePolicy( - request: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, - options: CallOptions, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, - {}|null|undefined>): void; - deletePolicy( - request: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, - callback: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, - {}|null|undefined>): void; -/** - * Deletes a Policy. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint or Org Policy does not exist. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.name - * Required. Name of the policy to delete. - * See `Policy` for naming rules. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [Empty]{@link google.protobuf.Empty}. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) - * for more details and examples. - * @example - * const [response] = await client.deletePolicy(request); - */ - deletePolicy( - request?: protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest, - optionsOrCallback?: CallOptions|Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, - {}|null|undefined>, - callback?: Callback< - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|null|undefined, - {}|null|undefined>): - Promise<[ - protos.google.protobuf.IEmpty, - protos.google.cloud.orgpolicy.v2.IDeletePolicyRequest|undefined, {}|undefined - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'name': request.name || '', - }); - this.initialize(); - return this.innerApiCalls.deletePolicy(request, options, callback); - } - - listConstraints( - request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IConstraint[], - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest|null, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse - ]>; - listConstraints( - request: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IConstraint>): void; - listConstraints( - request: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - callback: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IConstraint>): void; -/** - * Lists `Constraints` that could be applied on the specified resource. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The Cloud resource that parents the constraint. Must be in one of the - * following forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of [Constraint]{@link google.cloud.orgpolicy.v2.Constraint}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listConstraintsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listConstraints( - request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IConstraint>, - callback?: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IConstraint>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IConstraint[], - protos.google.cloud.orgpolicy.v2.IListConstraintsRequest|null, - protos.google.cloud.orgpolicy.v2.IListConstraintsResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - this.initialize(); - return this.innerApiCalls.listConstraints(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The Cloud resource that parents the constraint. Must be in one of the - * following forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing [Constraint]{@link google.cloud.orgpolicy.v2.Constraint} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listConstraintsAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listConstraintsStream( - request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - options?: CallOptions): - Transform{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - const callSettings = new gax.CallSettings(options); - this.initialize(); - return this.descriptors.page.listConstraints.createStream( - this.innerApiCalls.listConstraints as gax.GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listConstraints`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The Cloud resource that parents the constraint. Must be in one of the - * following forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * [Constraint]{@link google.cloud.orgpolicy.v2.Constraint}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example - * const iterable = client.listConstraintsAsync(request); - * for await (const response of iterable) { - * // process response - * } - */ - listConstraintsAsync( - request?: protos.google.cloud.orgpolicy.v2.IListConstraintsRequest, - options?: CallOptions): - AsyncIterable{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - options = options || {}; - const callSettings = new gax.CallSettings(options); - this.initialize(); - return this.descriptors.page.listConstraints.asyncIterate( - this.innerApiCalls['listConstraints'] as GaxCall, - request as unknown as RequestType, - callSettings - ) as AsyncIterable; - } - listPolicies( - request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - options?: CallOptions): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy[], - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest|null, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse - ]>; - listPolicies( - request: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - options: CallOptions, - callback: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IPolicy>): void; - listPolicies( - request: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - callback: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IPolicy>): void; -/** - * Retrieves all of the `Policies` that exist on a particular resource. - * - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The target Cloud resource that parents the set of constraints and policies - * that will be returned from this call. Must be in one of the following - * forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Promise} - The promise which resolves to an array. - * The first element of the array is Array of [Policy]{@link google.cloud.orgpolicy.v2.Policy}. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed and will merge results from all the pages into this array. - * Note that it can affect your quota. - * We recommend using `listPoliciesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listPolicies( - request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - optionsOrCallback?: CallOptions|PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IPolicy>, - callback?: PaginationCallback< - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse|null|undefined, - protos.google.cloud.orgpolicy.v2.IPolicy>): - Promise<[ - protos.google.cloud.orgpolicy.v2.IPolicy[], - protos.google.cloud.orgpolicy.v2.IListPoliciesRequest|null, - protos.google.cloud.orgpolicy.v2.IListPoliciesResponse - ]>|void { - request = request || {}; - let options: CallOptions; - if (typeof optionsOrCallback === 'function' && callback === undefined) { - callback = optionsOrCallback; - options = {}; - } - else { - options = optionsOrCallback as CallOptions; - } - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - this.initialize(); - return this.innerApiCalls.listPolicies(request, options, callback); - } - -/** - * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The target Cloud resource that parents the set of constraints and policies - * that will be returned from this call. Must be in one of the following - * forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Stream} - * An object stream which emits an object representing [Policy]{@link google.cloud.orgpolicy.v2.Policy} on 'data' event. - * The client library will perform auto-pagination by default: it will call the API as many - * times as needed. Note that it can affect your quota. - * We recommend using `listPoliciesAsync()` - * method described below for async iteration which you can stop as needed. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - */ - listPoliciesStream( - request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - options?: CallOptions): - Transform{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - const callSettings = new gax.CallSettings(options); - this.initialize(); - return this.descriptors.page.listPolicies.createStream( - this.innerApiCalls.listPolicies as gax.GaxCall, - request, - callSettings - ); - } - -/** - * Equivalent to `listPolicies`, but returns an iterable object. - * - * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand. - * @param {Object} request - * The request object that will be sent. - * @param {string} request.parent - * Required. The target Cloud resource that parents the set of constraints and policies - * that will be returned from this call. Must be in one of the following - * forms: - * * `projects/{project_number}` - * * `projects/{project_id}` - * * `folders/{folder_id}` - * * `organizations/{organization_id}` - * @param {number} request.pageSize - * Size of the pages to be returned. This is currently unsupported and will - * be ignored. The server may at any point start using this field to limit - * page size. - * @param {string} request.pageToken - * Page token used to retrieve the next page. This is currently unsupported - * and will be ignored. The server may at any point start using this field. - * @param {object} [options] - * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details. - * @returns {Object} - * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols). - * When you iterate the returned iterable, each element will be an object representing - * [Policy]{@link google.cloud.orgpolicy.v2.Policy}. The API will be called under the hood as needed, once per the page, - * so you can stop the iteration when you don't need more results. - * Please see the - * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination) - * for more details and examples. - * @example - * const iterable = client.listPoliciesAsync(request); - * for await (const response of iterable) { - * // process response - * } - */ - listPoliciesAsync( - request?: protos.google.cloud.orgpolicy.v2.IListPoliciesRequest, - options?: CallOptions): - AsyncIterable{ - request = request || {}; - options = options || {}; - options.otherArgs = options.otherArgs || {}; - options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'parent': request.parent || '', - }); - options = options || {}; - const callSettings = new gax.CallSettings(options); - this.initialize(); - return this.descriptors.page.listPolicies.asyncIterate( - this.innerApiCalls['listPolicies'] as GaxCall, - request as unknown as RequestType, - callSettings - ) as AsyncIterable; - } - // -------------------- - // -- Path templates -- - // -------------------- - - /** - * Return a fully-qualified folderConstraint resource name string. - * - * @param {string} folder - * @param {string} constraint - * @returns {string} Resource name string. - */ - folderConstraintPath(folder:string,constraint:string) { - return this.pathTemplates.folderConstraintPathTemplate.render({ - folder: folder, - constraint: constraint, - }); - } - - /** - * Parse the folder from FolderConstraint resource. - * - * @param {string} folderConstraintName - * A fully-qualified path representing folder_constraint resource. - * @returns {string} A string representing the folder. - */ - matchFolderFromFolderConstraintName(folderConstraintName: string) { - return this.pathTemplates.folderConstraintPathTemplate.match(folderConstraintName).folder; - } - - /** - * Parse the constraint from FolderConstraint resource. - * - * @param {string} folderConstraintName - * A fully-qualified path representing folder_constraint resource. - * @returns {string} A string representing the constraint. - */ - matchConstraintFromFolderConstraintName(folderConstraintName: string) { - return this.pathTemplates.folderConstraintPathTemplate.match(folderConstraintName).constraint; - } - - /** - * Return a fully-qualified folderPolicy resource name string. - * - * @param {string} folder - * @param {string} policy - * @returns {string} Resource name string. - */ - folderPolicyPath(folder:string,policy:string) { - return this.pathTemplates.folderPolicyPathTemplate.render({ - folder: folder, - policy: policy, - }); - } - - /** - * Parse the folder from FolderPolicy resource. - * - * @param {string} folderPolicyName - * A fully-qualified path representing folder_policy resource. - * @returns {string} A string representing the folder. - */ - matchFolderFromFolderPolicyName(folderPolicyName: string) { - return this.pathTemplates.folderPolicyPathTemplate.match(folderPolicyName).folder; - } - - /** - * Parse the policy from FolderPolicy resource. - * - * @param {string} folderPolicyName - * A fully-qualified path representing folder_policy resource. - * @returns {string} A string representing the policy. - */ - matchPolicyFromFolderPolicyName(folderPolicyName: string) { - return this.pathTemplates.folderPolicyPathTemplate.match(folderPolicyName).policy; - } - - /** - * Return a fully-qualified organizationConstraint resource name string. - * - * @param {string} organization - * @param {string} constraint - * @returns {string} Resource name string. - */ - organizationConstraintPath(organization:string,constraint:string) { - return this.pathTemplates.organizationConstraintPathTemplate.render({ - organization: organization, - constraint: constraint, - }); - } - - /** - * Parse the organization from OrganizationConstraint resource. - * - * @param {string} organizationConstraintName - * A fully-qualified path representing organization_constraint resource. - * @returns {string} A string representing the organization. - */ - matchOrganizationFromOrganizationConstraintName(organizationConstraintName: string) { - return this.pathTemplates.organizationConstraintPathTemplate.match(organizationConstraintName).organization; - } - - /** - * Parse the constraint from OrganizationConstraint resource. - * - * @param {string} organizationConstraintName - * A fully-qualified path representing organization_constraint resource. - * @returns {string} A string representing the constraint. - */ - matchConstraintFromOrganizationConstraintName(organizationConstraintName: string) { - return this.pathTemplates.organizationConstraintPathTemplate.match(organizationConstraintName).constraint; - } - - /** - * Return a fully-qualified organizationPolicy resource name string. - * - * @param {string} organization - * @param {string} policy - * @returns {string} Resource name string. - */ - organizationPolicyPath(organization:string,policy:string) { - return this.pathTemplates.organizationPolicyPathTemplate.render({ - organization: organization, - policy: policy, - }); - } - - /** - * Parse the organization from OrganizationPolicy resource. - * - * @param {string} organizationPolicyName - * A fully-qualified path representing organization_policy resource. - * @returns {string} A string representing the organization. - */ - matchOrganizationFromOrganizationPolicyName(organizationPolicyName: string) { - return this.pathTemplates.organizationPolicyPathTemplate.match(organizationPolicyName).organization; - } - - /** - * Parse the policy from OrganizationPolicy resource. - * - * @param {string} organizationPolicyName - * A fully-qualified path representing organization_policy resource. - * @returns {string} A string representing the policy. - */ - matchPolicyFromOrganizationPolicyName(organizationPolicyName: string) { - return this.pathTemplates.organizationPolicyPathTemplate.match(organizationPolicyName).policy; - } - - /** - * Return a fully-qualified project resource name string. - * - * @param {string} project - * @returns {string} Resource name string. - */ - projectPath(project:string) { - return this.pathTemplates.projectPathTemplate.render({ - project: project, - }); - } - - /** - * Parse the project from Project resource. - * - * @param {string} projectName - * A fully-qualified path representing Project resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectName(projectName: string) { - return this.pathTemplates.projectPathTemplate.match(projectName).project; - } - - /** - * Return a fully-qualified projectConstraint resource name string. - * - * @param {string} project - * @param {string} constraint - * @returns {string} Resource name string. - */ - projectConstraintPath(project:string,constraint:string) { - return this.pathTemplates.projectConstraintPathTemplate.render({ - project: project, - constraint: constraint, - }); - } - - /** - * Parse the project from ProjectConstraint resource. - * - * @param {string} projectConstraintName - * A fully-qualified path representing project_constraint resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectConstraintName(projectConstraintName: string) { - return this.pathTemplates.projectConstraintPathTemplate.match(projectConstraintName).project; - } - - /** - * Parse the constraint from ProjectConstraint resource. - * - * @param {string} projectConstraintName - * A fully-qualified path representing project_constraint resource. - * @returns {string} A string representing the constraint. - */ - matchConstraintFromProjectConstraintName(projectConstraintName: string) { - return this.pathTemplates.projectConstraintPathTemplate.match(projectConstraintName).constraint; - } - - /** - * Return a fully-qualified projectPolicy resource name string. - * - * @param {string} project - * @param {string} policy - * @returns {string} Resource name string. - */ - projectPolicyPath(project:string,policy:string) { - return this.pathTemplates.projectPolicyPathTemplate.render({ - project: project, - policy: policy, - }); - } - - /** - * Parse the project from ProjectPolicy resource. - * - * @param {string} projectPolicyName - * A fully-qualified path representing project_policy resource. - * @returns {string} A string representing the project. - */ - matchProjectFromProjectPolicyName(projectPolicyName: string) { - return this.pathTemplates.projectPolicyPathTemplate.match(projectPolicyName).project; - } - - /** - * Parse the policy from ProjectPolicy resource. - * - * @param {string} projectPolicyName - * A fully-qualified path representing project_policy resource. - * @returns {string} A string representing the policy. - */ - matchPolicyFromProjectPolicyName(projectPolicyName: string) { - return this.pathTemplates.projectPolicyPathTemplate.match(projectPolicyName).policy; - } - - /** - * Terminate the gRPC channel and close the client. - * - * The client will no longer be usable and all future behavior is undefined. - * @returns {Promise} A promise that resolves when the client is closed. - */ - close(): Promise { - this.initialize(); - if (!this._terminated) { - return this.orgPolicyStub!.then(stub => { - this._terminated = true; - stub.close(); - }); - } - return Promise.resolve(); - } -} diff --git a/owl-bot-staging/v2/src/v2/org_policy_client_config.json b/owl-bot-staging/v2/src/v2/org_policy_client_config.json deleted file mode 100644 index 330aa9b..0000000 --- a/owl-bot-staging/v2/src/v2/org_policy_client_config.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "interfaces": { - "google.cloud.orgpolicy.v2.OrgPolicy": { - "retry_codes": { - "non_idempotent": [], - "idempotent": [ - "DEADLINE_EXCEEDED", - "UNAVAILABLE" - ] - }, - "retry_params": { - "default": { - "initial_retry_delay_millis": 100, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 60000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - }, - "ce5b960a6ed052e690863808e4f0deff3dc7d49f": { - "initial_retry_delay_millis": 1000, - "retry_delay_multiplier": 1.3, - "max_retry_delay_millis": 10000, - "initial_rpc_timeout_millis": 60000, - "rpc_timeout_multiplier": 1, - "max_rpc_timeout_millis": 60000, - "total_timeout_millis": 600000 - } - }, - "methods": { - "ListConstraints": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "ListPolicies": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "GetPolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "GetEffectivePolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "CreatePolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "UpdatePolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - }, - "DeletePolicy": { - "timeout_millis": 60000, - "retry_codes_name": "idempotent", - "retry_params_name": "ce5b960a6ed052e690863808e4f0deff3dc7d49f" - } - } - } - } -} diff --git a/owl-bot-staging/v2/src/v2/org_policy_proto_list.json b/owl-bot-staging/v2/src/v2/org_policy_proto_list.json deleted file mode 100644 index ad104ec..0000000 --- a/owl-bot-staging/v2/src/v2/org_policy_proto_list.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "../../protos/google/cloud/orgpolicy/v2/constraint.proto", - "../../protos/google/cloud/orgpolicy/v2/orgpolicy.proto" -] diff --git a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js deleted file mode 100644 index 1afa574..0000000 --- a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - - -/* eslint-disable node/no-missing-require, no-unused-vars */ -const orgpolicy = require('@google-cloud/org-policy'); - -function main() { - const orgPolicyClient = new orgpolicy.OrgPolicyClient(); -} - -main(); diff --git a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts b/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts deleted file mode 100644 index 6e10a5a..0000000 --- a/owl-bot-staging/v2/system-test/fixtures/sample/src/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import {OrgPolicyClient} from '@google-cloud/org-policy'; - -// check that the client class type name can be used -function doStuffWithOrgPolicyClient(client: OrgPolicyClient) { - client.close(); -} - -function main() { - // check that the client instance can be created - const orgPolicyClient = new OrgPolicyClient(); - doStuffWithOrgPolicyClient(orgPolicyClient); -} - -main(); diff --git a/owl-bot-staging/v2/system-test/install.ts b/owl-bot-staging/v2/system-test/install.ts deleted file mode 100644 index 1f850b5..0000000 --- a/owl-bot-staging/v2/system-test/install.ts +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import { packNTest } from 'pack-n-play'; -import { readFileSync } from 'fs'; -import { describe, it } from 'mocha'; - -describe('📦 pack-n-play test', () => { - - it('TypeScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'TypeScript user can use the type definitions', - ts: readFileSync('./system-test/fixtures/sample/src/index.ts').toString() - } - }; - await packNTest(options); - }); - - it('JavaScript code', async function() { - this.timeout(300000); - const options = { - packageDir: process.cwd(), - sample: { - description: 'JavaScript user can use the library', - ts: readFileSync('./system-test/fixtures/sample/src/index.js').toString() - } - }; - await packNTest(options); - }); - -}); diff --git a/owl-bot-staging/v2/test/gapic_org_policy_v2.ts b/owl-bot-staging/v2/test/gapic_org_policy_v2.ts deleted file mode 100644 index 31a41c9..0000000 --- a/owl-bot-staging/v2/test/gapic_org_policy_v2.ts +++ /dev/null @@ -1,1297 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -// ** This file is automatically generated by gapic-generator-typescript. ** -// ** https://github.com/googleapis/gapic-generator-typescript ** -// ** All changes to this file may be overwritten. ** - -import * as protos from '../protos/protos'; -import * as assert from 'assert'; -import * as sinon from 'sinon'; -import {SinonStub} from 'sinon'; -import { describe, it } from 'mocha'; -import * as orgpolicyModule from '../src'; - -import {PassThrough} from 'stream'; - -import {protobuf} from 'google-gax'; - -function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message) - .toObject(instance as protobuf.Message, {defaults: true}); - return (instance.constructor as typeof protobuf.Message).fromObject(filledObject) as T; -} - -function stubSimpleCall(response?: ResponseType, error?: Error) { - return error ? sinon.stub().rejects(error) : sinon.stub().resolves([response]); -} - -function stubSimpleCallWithCallback(response?: ResponseType, error?: Error) { - return error ? sinon.stub().callsArgWith(2, error) : sinon.stub().callsArgWith(2, null, response); -} - -function stubPageStreamingCall(responses?: ResponseType[], error?: Error) { - const pagingStub = sinon.stub(); - if (responses) { - for (let i = 0; i < responses.length; ++i) { - pagingStub.onCall(i).callsArgWith(2, null, responses[i]); - } - } - const transformStub = error ? sinon.stub().callsArgWith(2, error) : pagingStub; - const mockStream = new PassThrough({ - objectMode: true, - transform: transformStub, - }); - // trigger as many responses as needed - if (responses) { - for (let i = 0; i < responses.length; ++i) { - setImmediate(() => { mockStream.write({}); }); - } - setImmediate(() => { mockStream.end(); }); - } else { - setImmediate(() => { mockStream.write({}); }); - setImmediate(() => { mockStream.end(); }); - } - return sinon.stub().returns(mockStream); -} - -function stubAsyncIterationCall(responses?: ResponseType[], error?: Error) { - let counter = 0; - const asyncIterable = { - [Symbol.asyncIterator]() { - return { - async next() { - if (error) { - return Promise.reject(error); - } - if (counter >= responses!.length) { - return Promise.resolve({done: true, value: undefined}); - } - return Promise.resolve({done: false, value: responses![counter++]}); - } - }; - } - }; - return sinon.stub().returns(asyncIterable); -} - -describe('v2.OrgPolicyClient', () => { - it('has servicePath', () => { - const servicePath = orgpolicyModule.v2.OrgPolicyClient.servicePath; - assert(servicePath); - }); - - it('has apiEndpoint', () => { - const apiEndpoint = orgpolicyModule.v2.OrgPolicyClient.apiEndpoint; - assert(apiEndpoint); - }); - - it('has port', () => { - const port = orgpolicyModule.v2.OrgPolicyClient.port; - assert(port); - assert(typeof port === 'number'); - }); - - it('should create a client with no option', () => { - const client = new orgpolicyModule.v2.OrgPolicyClient(); - assert(client); - }); - - it('should create a client with gRPC fallback', () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - fallback: true, - }); - assert(client); - }); - - it('has initialize method and supports deferred initialization', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - assert.strictEqual(client.orgPolicyStub, undefined); - await client.initialize(); - assert(client.orgPolicyStub); - }); - - it('has close method', () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.close(); - }); - - it('has getProjectId method', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().resolves(fakeProjectId); - const result = await client.getProjectId(); - assert.strictEqual(result, fakeProjectId); - assert((client.auth.getProjectId as SinonStub).calledWithExactly()); - }); - - it('has getProjectId method with callback', async () => { - const fakeProjectId = 'fake-project-id'; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.auth.getProjectId = sinon.stub().callsArgWith(0, null, fakeProjectId); - const promise = new Promise((resolve, reject) => { - client.getProjectId((err?: Error|null, projectId?: string|null) => { - if (err) { - reject(err); - } else { - resolve(projectId); - } - }); - }); - const result = await promise; - assert.strictEqual(result, fakeProjectId); - }); - - describe('getPolicy', () => { - it('invokes getPolicy without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.getPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.getPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes getPolicy without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.getPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getPolicy( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.getPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes getPolicy with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetPolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.getPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getPolicy(request), expectedError); - assert((client.innerApiCalls.getPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('getEffectivePolicy', () => { - it('invokes getEffectivePolicy without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.getEffectivePolicy = stubSimpleCall(expectedResponse); - const [response] = await client.getEffectivePolicy(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.getEffectivePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes getEffectivePolicy without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.getEffectivePolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.getEffectivePolicy( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.getEffectivePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes getEffectivePolicy with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.getEffectivePolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.getEffectivePolicy(request), expectedError); - assert((client.innerApiCalls.getEffectivePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('createPolicy', () => { - it('invokes createPolicy without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.createPolicy = stubSimpleCall(expectedResponse); - const [response] = await client.createPolicy(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.createPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes createPolicy without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.createPolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.createPolicy( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.createPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes createPolicy with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.CreatePolicyRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.createPolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.createPolicy(request), expectedError); - assert((client.innerApiCalls.createPolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('updatePolicy', () => { - it('invokes updatePolicy without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = "policy.name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.updatePolicy = stubSimpleCall(expectedResponse); - const [response] = await client.updatePolicy(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.updatePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes updatePolicy without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = "policy.name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()); - client.innerApiCalls.updatePolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.updatePolicy( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.updatePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes updatePolicy with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.UpdatePolicyRequest()); - request.policy = {}; - request.policy.name = ''; - const expectedHeaderRequestParams = "policy.name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.updatePolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.updatePolicy(request), expectedError); - assert((client.innerApiCalls.updatePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('deletePolicy', () => { - it('invokes deletePolicy without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.protobuf.Empty()); - client.innerApiCalls.deletePolicy = stubSimpleCall(expectedResponse); - const [response] = await client.deletePolicy(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.deletePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes deletePolicy without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = generateSampleMessage(new protos.google.protobuf.Empty()); - client.innerApiCalls.deletePolicy = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.deletePolicy( - request, - (err?: Error|null, result?: protos.google.protobuf.IEmpty|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.deletePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes deletePolicy with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.DeletePolicyRequest()); - request.name = ''; - const expectedHeaderRequestParams = "name="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.deletePolicy = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.deletePolicy(request), expectedError); - assert((client.innerApiCalls.deletePolicy as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - }); - - describe('listConstraints', () => { - it('invokes listConstraints without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - ]; - client.innerApiCalls.listConstraints = stubSimpleCall(expectedResponse); - const [response] = await client.listConstraints(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.listConstraints as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes listConstraints without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - ]; - client.innerApiCalls.listConstraints = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listConstraints( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IConstraint[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.listConstraints as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes listConstraints with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.listConstraints = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listConstraints(request), expectedError); - assert((client.innerApiCalls.listConstraints as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes listConstraintsStream without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - ]; - client.descriptors.page.listConstraints.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listConstraintsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.orgpolicy.v2.Constraint[] = []; - stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Constraint) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listConstraints.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listConstraints, request)); - assert.strictEqual( - (client.descriptors.page.listConstraints.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('invokes listConstraintsStream with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedError = new Error('expected'); - client.descriptors.page.listConstraints.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listConstraintsStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.orgpolicy.v2.Constraint[] = []; - stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Constraint) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listConstraints.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listConstraints, request)); - assert.strictEqual( - (client.descriptors.page.listConstraints.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('uses async iteration with listConstraints without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Constraint()), - ]; - client.descriptors.page.listConstraints.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.orgpolicy.v2.IConstraint[] = []; - const iterable = client.listConstraintsAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listConstraints.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert.strictEqual( - (client.descriptors.page.listConstraints.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('uses async iteration with listConstraints with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListConstraintsRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent=";const expectedError = new Error('expected'); - client.descriptors.page.listConstraints.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listConstraintsAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.orgpolicy.v2.IConstraint[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listConstraints.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert.strictEqual( - (client.descriptors.page.listConstraints.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - }); - - describe('listPolicies', () => { - it('invokes listPolicies without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - ]; - client.innerApiCalls.listPolicies = stubSimpleCall(expectedResponse); - const [response] = await client.listPolicies(request); - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.listPolicies as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes listPolicies without error using callback', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - ]; - client.innerApiCalls.listPolicies = stubSimpleCallWithCallback(expectedResponse); - const promise = new Promise((resolve, reject) => { - client.listPolicies( - request, - (err?: Error|null, result?: protos.google.cloud.orgpolicy.v2.IPolicy[]|null) => { - if (err) { - reject(err); - } else { - resolve(result); - } - }); - }); - const response = await promise; - assert.deepStrictEqual(response, expectedResponse); - assert((client.innerApiCalls.listPolicies as SinonStub) - .getCall(0).calledWith(request, expectedOptions /*, callback defined above */)); - }); - - it('invokes listPolicies with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedOptions = { - otherArgs: { - headers: { - 'x-goog-request-params': expectedHeaderRequestParams, - }, - }, - }; - const expectedError = new Error('expected'); - client.innerApiCalls.listPolicies = stubSimpleCall(undefined, expectedError); - await assert.rejects(client.listPolicies(request), expectedError); - assert((client.innerApiCalls.listPolicies as SinonStub) - .getCall(0).calledWith(request, expectedOptions, undefined)); - }); - - it('invokes listPoliciesStream without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - ]; - client.descriptors.page.listPolicies.createStream = stubPageStreamingCall(expectedResponse); - const stream = client.listPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.orgpolicy.v2.Policy[] = []; - stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Policy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - const responses = await promise; - assert.deepStrictEqual(responses, expectedResponse); - assert((client.descriptors.page.listPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listPolicies, request)); - assert.strictEqual( - (client.descriptors.page.listPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('invokes listPoliciesStream with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedError = new Error('expected'); - client.descriptors.page.listPolicies.createStream = stubPageStreamingCall(undefined, expectedError); - const stream = client.listPoliciesStream(request); - const promise = new Promise((resolve, reject) => { - const responses: protos.google.cloud.orgpolicy.v2.Policy[] = []; - stream.on('data', (response: protos.google.cloud.orgpolicy.v2.Policy) => { - responses.push(response); - }); - stream.on('end', () => { - resolve(responses); - }); - stream.on('error', (err: Error) => { - reject(err); - }); - }); - await assert.rejects(promise, expectedError); - assert((client.descriptors.page.listPolicies.createStream as SinonStub) - .getCall(0).calledWith(client.innerApiCalls.listPolicies, request)); - assert.strictEqual( - (client.descriptors.page.listPolicies.createStream as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('uses async iteration with listPolicies without error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent="; - const expectedResponse = [ - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - generateSampleMessage(new protos.google.cloud.orgpolicy.v2.Policy()), - ]; - client.descriptors.page.listPolicies.asyncIterate = stubAsyncIterationCall(expectedResponse); - const responses: protos.google.cloud.orgpolicy.v2.IPolicy[] = []; - const iterable = client.listPoliciesAsync(request); - for await (const resource of iterable) { - responses.push(resource!); - } - assert.deepStrictEqual(responses, expectedResponse); - assert.deepStrictEqual( - (client.descriptors.page.listPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert.strictEqual( - (client.descriptors.page.listPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - - it('uses async iteration with listPolicies with error', async () => { - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - const request = generateSampleMessage(new protos.google.cloud.orgpolicy.v2.ListPoliciesRequest()); - request.parent = ''; - const expectedHeaderRequestParams = "parent=";const expectedError = new Error('expected'); - client.descriptors.page.listPolicies.asyncIterate = stubAsyncIterationCall(undefined, expectedError); - const iterable = client.listPoliciesAsync(request); - await assert.rejects(async () => { - const responses: protos.google.cloud.orgpolicy.v2.IPolicy[] = []; - for await (const resource of iterable) { - responses.push(resource!); - } - }); - assert.deepStrictEqual( - (client.descriptors.page.listPolicies.asyncIterate as SinonStub) - .getCall(0).args[1], request); - assert.strictEqual( - (client.descriptors.page.listPolicies.asyncIterate as SinonStub) - .getCall(0).args[2].otherArgs.headers['x-goog-request-params'], - expectedHeaderRequestParams - ); - }); - }); - - describe('Path templates', () => { - - describe('folderConstraint', () => { - const fakePath = "/rendered/path/folderConstraint"; - const expectedParameters = { - folder: "folderValue", - constraint: "constraintValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.folderConstraintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderConstraintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderConstraintPath', () => { - const result = client.folderConstraintPath("folderValue", "constraintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderConstraintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderConstraintName', () => { - const result = client.matchFolderFromFolderConstraintName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConstraintFromFolderConstraintName', () => { - const result = client.matchConstraintFromFolderConstraintName(fakePath); - assert.strictEqual(result, "constraintValue"); - assert((client.pathTemplates.folderConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('folderPolicy', () => { - const fakePath = "/rendered/path/folderPolicy"; - const expectedParameters = { - folder: "folderValue", - policy: "policyValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.folderPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.folderPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('folderPolicyPath', () => { - const result = client.folderPolicyPath("folderValue", "policyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.folderPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchFolderFromFolderPolicyName', () => { - const result = client.matchFolderFromFolderPolicyName(fakePath); - assert.strictEqual(result, "folderValue"); - assert((client.pathTemplates.folderPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchPolicyFromFolderPolicyName', () => { - const result = client.matchPolicyFromFolderPolicyName(fakePath); - assert.strictEqual(result, "policyValue"); - assert((client.pathTemplates.folderPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationConstraint', () => { - const fakePath = "/rendered/path/organizationConstraint"; - const expectedParameters = { - organization: "organizationValue", - constraint: "constraintValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.organizationConstraintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationConstraintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationConstraintPath', () => { - const result = client.organizationConstraintPath("organizationValue", "constraintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationConstraintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationConstraintName', () => { - const result = client.matchOrganizationFromOrganizationConstraintName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConstraintFromOrganizationConstraintName', () => { - const result = client.matchConstraintFromOrganizationConstraintName(fakePath); - assert.strictEqual(result, "constraintValue"); - assert((client.pathTemplates.organizationConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('organizationPolicy', () => { - const fakePath = "/rendered/path/organizationPolicy"; - const expectedParameters = { - organization: "organizationValue", - policy: "policyValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.organizationPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.organizationPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('organizationPolicyPath', () => { - const result = client.organizationPolicyPath("organizationValue", "policyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.organizationPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchOrganizationFromOrganizationPolicyName', () => { - const result = client.matchOrganizationFromOrganizationPolicyName(fakePath); - assert.strictEqual(result, "organizationValue"); - assert((client.pathTemplates.organizationPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchPolicyFromOrganizationPolicyName', () => { - const result = client.matchPolicyFromOrganizationPolicyName(fakePath); - assert.strictEqual(result, "policyValue"); - assert((client.pathTemplates.organizationPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('project', () => { - const fakePath = "/rendered/path/project"; - const expectedParameters = { - project: "projectValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPath', () => { - const result = client.projectPath("projectValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectName', () => { - const result = client.matchProjectFromProjectName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectConstraint', () => { - const fakePath = "/rendered/path/projectConstraint"; - const expectedParameters = { - project: "projectValue", - constraint: "constraintValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectConstraintPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectConstraintPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectConstraintPath', () => { - const result = client.projectConstraintPath("projectValue", "constraintValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectConstraintPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectConstraintName', () => { - const result = client.matchProjectFromProjectConstraintName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchConstraintFromProjectConstraintName', () => { - const result = client.matchConstraintFromProjectConstraintName(fakePath); - assert.strictEqual(result, "constraintValue"); - assert((client.pathTemplates.projectConstraintPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - - describe('projectPolicy', () => { - const fakePath = "/rendered/path/projectPolicy"; - const expectedParameters = { - project: "projectValue", - policy: "policyValue", - }; - const client = new orgpolicyModule.v2.OrgPolicyClient({ - credentials: {client_email: 'bogus', private_key: 'bogus'}, - projectId: 'bogus', - }); - client.initialize(); - client.pathTemplates.projectPolicyPathTemplate.render = - sinon.stub().returns(fakePath); - client.pathTemplates.projectPolicyPathTemplate.match = - sinon.stub().returns(expectedParameters); - - it('projectPolicyPath', () => { - const result = client.projectPolicyPath("projectValue", "policyValue"); - assert.strictEqual(result, fakePath); - assert((client.pathTemplates.projectPolicyPathTemplate.render as SinonStub) - .getCall(-1).calledWith(expectedParameters)); - }); - - it('matchProjectFromProjectPolicyName', () => { - const result = client.matchProjectFromProjectPolicyName(fakePath); - assert.strictEqual(result, "projectValue"); - assert((client.pathTemplates.projectPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - - it('matchPolicyFromProjectPolicyName', () => { - const result = client.matchPolicyFromProjectPolicyName(fakePath); - assert.strictEqual(result, "policyValue"); - assert((client.pathTemplates.projectPolicyPathTemplate.match as SinonStub) - .getCall(-1).calledWith(fakePath)); - }); - }); - }); -}); diff --git a/owl-bot-staging/v2/tsconfig.json b/owl-bot-staging/v2/tsconfig.json deleted file mode 100644 index c78f1c8..0000000 --- a/owl-bot-staging/v2/tsconfig.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "extends": "./node_modules/gts/tsconfig-google.json", - "compilerOptions": { - "rootDir": ".", - "outDir": "build", - "resolveJsonModule": true, - "lib": [ - "es2018", - "dom" - ] - }, - "include": [ - "src/*.ts", - "src/**/*.ts", - "test/*.ts", - "test/**/*.ts", - "system-test/*.ts" - ] -} diff --git a/owl-bot-staging/v2/webpack.config.js b/owl-bot-staging/v2/webpack.config.js deleted file mode 100644 index 52ea261..0000000 --- a/owl-bot-staging/v2/webpack.config.js +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2021 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -const path = require('path'); - -module.exports = { - entry: './src/index.ts', - output: { - library: 'OrgPolicy', - filename: './org-policy.js', - }, - node: { - child_process: 'empty', - fs: 'empty', - crypto: 'empty', - }, - resolve: { - alias: { - '../../../package.json': path.resolve(__dirname, 'package.json'), - }, - extensions: ['.js', '.json', '.ts'], - }, - module: { - rules: [ - { - test: /\.tsx?$/, - use: 'ts-loader', - exclude: /node_modules/ - }, - { - test: /node_modules[\\/]@grpc[\\/]grpc-js/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]grpc/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]retry-request/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]https?-proxy-agent/, - use: 'null-loader' - }, - { - test: /node_modules[\\/]gtoken/, - use: 'null-loader' - }, - ], - }, - mode: 'production', -}; diff --git a/src/v2/org_policy_client.ts b/src/v2/org_policy_client.ts index a1f12d0..e385345 100644 --- a/src/v2/org_policy_client.ts +++ b/src/v2/org_policy_client.ts @@ -150,6 +150,12 @@ export class OrgPolicyClient { // Save the auth object to the client, for use by other methods. this.auth = this._gaxGrpc.auth as gax.GoogleAuth; + // Set useJWTAccessWithScope on the auth object. + this.auth.useJWTAccessWithScope = true; + + // Set defaultServicePath on the auth object. + this.auth.defaultServicePath = staticMembers.servicePath; + // Set the default scopes in auth client if needed. if (servicePath === staticMembers.servicePath) { this.auth.defaultScopes = staticMembers.scopes;