diff --git a/.repo-metadata-full.json b/.repo-metadata-full.json index 49b3491111d7..cfbda3ba9c34 100644 --- a/.repo-metadata-full.json +++ b/.repo-metadata-full.json @@ -970,7 +970,7 @@ "OrgPolicy": { "language": "php", "distribution_name": "google/cloud-org-policy", - "release_level": "preview", + "release_level": "stable", "client_documentation": "https://cloud.google.com/php/docs/reference/cloud-org-policy/latest", "library_type": "GAPIC_AUTO", "api_shortname": "orgpolicy" diff --git a/OrgPolicy/README.md b/OrgPolicy/README.md index 75a350e42cc3..c5642d44ebb5 100644 --- a/OrgPolicy/README.md +++ b/OrgPolicy/README.md @@ -30,9 +30,8 @@ on authenticating your client. Once authenticated, you'll be ready to start maki ### Version -This component is considered beta. As such, it should be expected to be mostly -stable and we're working towards a release candidate. We will address issues -and requests with a higher priority. +This component is considered GA (generally available). As such, it will not introduce backwards-incompatible changes in +any minor or patch releases. We will address issues and requests with the highest priority. ### Next Steps diff --git a/OrgPolicy/owlbot.py b/OrgPolicy/owlbot.py index 4e1387f272bf..0329697d7623 100644 --- a/OrgPolicy/owlbot.py +++ b/OrgPolicy/owlbot.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google LLC +# Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,34 +32,25 @@ php.owlbot_main(src=src, dest=dest) -# Change the wording for the deprecation warning. +# remove class_alias code s.replace( - 'src/*/*_*.php', - r'will be removed in the next major release', - 'will be removed in a future release') - -### [START] protoc backwards compatibility fixes - -# roll back to private properties. -s.replace( - "src/**/V*/**/*.php", - r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$", - r"""Generated from protobuf field \1 - */ - private $""") - -# Replace "Unwrapped" with "Value" for method names. -s.replace( - "src/**/V*/**/*.php", - r"public function ([s|g]\w{3,})Unwrapped", - r"public function \1Value" -) - -### [END] protoc backwards compatibility fixes - -# fix relative cloud.google.com links -s.replace( - "src/**/V*/**/*.php", - r"(.{0,})\]\((/.{0,})\)", - r"\1](https://cloud.google.com\2)" -) + "src/V*/**/*.php", + r"^// Adding a class alias for backwards compatibility with the previous class name.$" + + "\n" + + r"^class_alias\(.*\);$" + + "\n", + '') + +# format generated clients +subprocess.run([ + 'npm', + 'exec', + '--yes', + '--package=@prettier/plugin-php@^0.16', + '--', + 'prettier', + '**/Client/*', + '--write', + '--parser=php', + '--single-quote', + '--print-width=120']) diff --git a/OrgPolicy/src/V2/AlternatePolicySpec.php b/OrgPolicy/src/V2/AlternatePolicySpec.php index 5227cb9b89c0..4d3a507f2019 100644 --- a/OrgPolicy/src/V2/AlternatePolicySpec.php +++ b/OrgPolicy/src/V2/AlternatePolicySpec.php @@ -23,13 +23,13 @@ class AlternatePolicySpec extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string launch = 1; */ - private $launch = ''; + protected $launch = ''; /** * Specify constraint for configurations of Google Cloud resources. * * Generated from protobuf field .google.cloud.orgpolicy.v2.PolicySpec spec = 2; */ - private $spec = null; + protected $spec = null; /** * Constructor. diff --git a/OrgPolicy/src/V2/Client/OrgPolicyClient.php b/OrgPolicy/src/V2/Client/OrgPolicyClient.php index deaaa4b807be..ddbf9810e36b 100644 --- a/OrgPolicy/src/V2/Client/OrgPolicyClient.php +++ b/OrgPolicy/src/V2/Client/OrgPolicyClient.php @@ -1,6 +1,6 @@ startApiCall('CreateCustomConstraint', $request, $callOptions)->wait(); } @@ -626,8 +626,10 @@ public function listConstraints(ListConstraintsRequest $request, array $callOpti * * @throws ApiException Thrown if the API call fails. */ - public function listCustomConstraints(ListCustomConstraintsRequest $request, array $callOptions = []): PagedListResponse - { + public function listCustomConstraints( + ListCustomConstraintsRequest $request, + array $callOptions = [] + ): PagedListResponse { return $this->startApiCall('ListCustomConstraints', $request, $callOptions); } @@ -684,8 +686,10 @@ public function listPolicies(ListPoliciesRequest $request, array $callOptions = * * @throws ApiException Thrown if the API call fails. */ - public function updateCustomConstraint(UpdateCustomConstraintRequest $request, array $callOptions = []): CustomConstraint - { + public function updateCustomConstraint( + UpdateCustomConstraintRequest $request, + array $callOptions = [] + ): CustomConstraint { return $this->startApiCall('UpdateCustomConstraint', $request, $callOptions)->wait(); } diff --git a/OrgPolicy/src/V2/Constraint.php b/OrgPolicy/src/V2/Constraint.php index 33b1cbd2787f..4b0d15284a17 100644 --- a/OrgPolicy/src/V2/Constraint.php +++ b/OrgPolicy/src/V2/Constraint.php @@ -37,14 +37,14 @@ class Constraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IMMUTABLE]; */ - private $name = ''; + protected $name = ''; /** * The human readable name. * Mutable. * * Generated from protobuf field string display_name = 2; */ - private $display_name = ''; + protected $display_name = ''; /** * Detailed description of what this constraint controls as well as how and * where it is enforced. @@ -52,19 +52,19 @@ class Constraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string description = 3; */ - private $description = ''; + protected $description = ''; /** * The evaluation behavior of this constraint in the absence of a policy. * * Generated from protobuf field .google.cloud.orgpolicy.v2.Constraint.ConstraintDefault constraint_default = 4; */ - private $constraint_default = 0; + protected $constraint_default = 0; /** * Shows if dry run is supported for this constraint or not. * * Generated from protobuf field bool supports_dry_run = 7; */ - private $supports_dry_run = false; + protected $supports_dry_run = false; protected $constraint_type; /** diff --git a/OrgPolicy/src/V2/Constraint/BooleanConstraint.php b/OrgPolicy/src/V2/Constraint/BooleanConstraint.php index 0302a06ca9cf..0880368ce56b 100644 --- a/OrgPolicy/src/V2/Constraint/BooleanConstraint.php +++ b/OrgPolicy/src/V2/Constraint/BooleanConstraint.php @@ -34,6 +34,4 @@ public function __construct($data = NULL) { } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(BooleanConstraint::class, \Google\Cloud\OrgPolicy\V2\Constraint_BooleanConstraint::class); diff --git a/OrgPolicy/src/V2/Constraint/ConstraintDefault.php b/OrgPolicy/src/V2/Constraint/ConstraintDefault.php index b7eaebc4f0ca..62145f84b9a4 100644 --- a/OrgPolicy/src/V2/Constraint/ConstraintDefault.php +++ b/OrgPolicy/src/V2/Constraint/ConstraintDefault.php @@ -64,6 +64,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ConstraintDefault::class, \Google\Cloud\OrgPolicy\V2\Constraint_ConstraintDefault::class); diff --git a/OrgPolicy/src/V2/Constraint/ListConstraint.php b/OrgPolicy/src/V2/Constraint/ListConstraint.php index 6dbf89baae3a..f62192e1809c 100644 --- a/OrgPolicy/src/V2/Constraint/ListConstraint.php +++ b/OrgPolicy/src/V2/Constraint/ListConstraint.php @@ -23,7 +23,7 @@ class ListConstraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool supports_in = 1; */ - private $supports_in = false; + protected $supports_in = false; /** * Indicates whether subtrees of the Resource Manager resource hierarchy * can be used in `Policy.allowed_values` and `Policy.denied_values`. For @@ -32,7 +32,7 @@ class ListConstraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool supports_under = 2; */ - private $supports_under = false; + protected $supports_under = false; /** * Constructor. @@ -120,6 +120,4 @@ public function setSupportsUnder($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ListConstraint::class, \Google\Cloud\OrgPolicy\V2\Constraint_ListConstraint::class); diff --git a/OrgPolicy/src/V2/Constraint_BooleanConstraint.php b/OrgPolicy/src/V2/Constraint_BooleanConstraint.php deleted file mode 100644 index b4579aae90e8..000000000000 --- a/OrgPolicy/src/V2/Constraint_BooleanConstraint.php +++ /dev/null @@ -1,16 +0,0 @@ -string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. Custom constraint to create. * * Generated from protobuf field .google.cloud.orgpolicy.v2.CustomConstraint custom_constraint = 2 [(.google.api.field_behavior) = REQUIRED]; */ - private $custom_constraint = null; + protected $custom_constraint = null; /** * @param string $parent Required. Must be in the following form: diff --git a/OrgPolicy/src/V2/CreatePolicyRequest.php b/OrgPolicy/src/V2/CreatePolicyRequest.php index b46cb1334ac9..adbbed633510 100644 --- a/OrgPolicy/src/V2/CreatePolicyRequest.php +++ b/OrgPolicy/src/V2/CreatePolicyRequest.php @@ -26,13 +26,13 @@ class CreatePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * Required. Policy to create. * * Generated from protobuf field .google.cloud.orgpolicy.v2.Policy policy = 3 [(.google.api.field_behavior) = REQUIRED]; */ - private $policy = null; + protected $policy = null; /** * @param string $parent Required. The Google Cloud resource that will parent the new policy. Must diff --git a/OrgPolicy/src/V2/CustomConstraint.php b/OrgPolicy/src/V2/CustomConstraint.php index 3a0f553e0255..db6db0d97896 100644 --- a/OrgPolicy/src/V2/CustomConstraint.php +++ b/OrgPolicy/src/V2/CustomConstraint.php @@ -29,7 +29,7 @@ class CustomConstraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IMMUTABLE]; */ - private $name = ''; + protected $name = ''; /** * Immutable. The resource instance type on which this policy applies. Format * will be of the form : `/` Example: @@ -52,27 +52,27 @@ class CustomConstraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string condition = 4; */ - private $condition = ''; + protected $condition = ''; /** * Allow or deny type. * * Generated from protobuf field .google.cloud.orgpolicy.v2.CustomConstraint.ActionType action_type = 5; */ - private $action_type = 0; + protected $action_type = 0; /** * One line display name for the UI. * The max length of the display_name is 200 characters. * * Generated from protobuf field string display_name = 6; */ - private $display_name = ''; + protected $display_name = ''; /** * Detailed information about this custom policy constraint. * The max length of the description is 2000 characters. * * Generated from protobuf field string description = 7; */ - private $description = ''; + protected $description = ''; /** * Output only. The last time this custom constraint was updated. This * represents the last time that the `CreateCustomConstraint` or @@ -80,7 +80,7 @@ class CustomConstraint extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp update_time = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * Constructor. diff --git a/OrgPolicy/src/V2/CustomConstraint/ActionType.php b/OrgPolicy/src/V2/CustomConstraint/ActionType.php index b86b75e0c8ae..bc8d3ec933ae 100644 --- a/OrgPolicy/src/V2/CustomConstraint/ActionType.php +++ b/OrgPolicy/src/V2/CustomConstraint/ActionType.php @@ -59,6 +59,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(ActionType::class, \Google\Cloud\OrgPolicy\V2\CustomConstraint_ActionType::class); diff --git a/OrgPolicy/src/V2/CustomConstraint/MethodType.php b/OrgPolicy/src/V2/CustomConstraint/MethodType.php index d883a15addef..6beff87de3f4 100644 --- a/OrgPolicy/src/V2/CustomConstraint/MethodType.php +++ b/OrgPolicy/src/V2/CustomConstraint/MethodType.php @@ -72,6 +72,4 @@ public static function value($name) } } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(MethodType::class, \Google\Cloud\OrgPolicy\V2\CustomConstraint_MethodType::class); diff --git a/OrgPolicy/src/V2/DeleteCustomConstraintRequest.php b/OrgPolicy/src/V2/DeleteCustomConstraintRequest.php index 07cac66d8902..76d93c9521c7 100644 --- a/OrgPolicy/src/V2/DeleteCustomConstraintRequest.php +++ b/OrgPolicy/src/V2/DeleteCustomConstraintRequest.php @@ -22,7 +22,7 @@ class DeleteCustomConstraintRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. Name of the custom constraint to delete. diff --git a/OrgPolicy/src/V2/DeletePolicyRequest.php b/OrgPolicy/src/V2/DeletePolicyRequest.php index 21935d79c91c..05b6ac45c430 100644 --- a/OrgPolicy/src/V2/DeletePolicyRequest.php +++ b/OrgPolicy/src/V2/DeletePolicyRequest.php @@ -22,7 +22,7 @@ class DeletePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * Optional. The current etag of policy. If an etag is provided and does not * match the current etag of the policy, deletion will be blocked and an @@ -30,7 +30,7 @@ class DeletePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string etag = 2 [(.google.api.field_behavior) = OPTIONAL]; */ - private $etag = ''; + protected $etag = ''; /** * @param string $name Required. Name of the policy to delete. diff --git a/OrgPolicy/src/V2/Gapic/OrgPolicyGapicClient.php b/OrgPolicy/src/V2/Gapic/OrgPolicyGapicClient.php deleted file mode 100644 index 90e2ccb01335..000000000000 --- a/OrgPolicy/src/V2/Gapic/OrgPolicyGapicClient.php +++ /dev/null @@ -1,1137 +0,0 @@ -organizationName('[ORGANIZATION]'); - * $customConstraint = new CustomConstraint(); - * $response = $orgPolicyClient->createCustomConstraint($formattedParent, $customConstraint); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * Many parameters require resource names to be formatted in a particular way. To - * assist with these names, this class includes a format method for each type of - * name, and additionally a parseName method to extract the individual identifiers - * contained within formatted names that are returned by the API. - * - * @deprecated Please use the new service client {@see \Google\Cloud\OrgPolicy\V2\Client\OrgPolicyClient}. - */ -class OrgPolicyGapicClient -{ - use GapicClientTrait; - - /** The name of the service. */ - const SERVICE_NAME = 'google.cloud.orgpolicy.v2.OrgPolicy'; - - /** - * The default address of the service. - * - * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. - */ - const SERVICE_ADDRESS = 'orgpolicy.googleapis.com'; - - /** The address template of the service. */ - private const SERVICE_ADDRESS_TEMPLATE = 'orgpolicy.UNIVERSE_DOMAIN'; - - /** The default port of the service. */ - const DEFAULT_SERVICE_PORT = 443; - - /** The name of the code generator, to be included in the agent header. */ - const CODEGEN_NAME = 'gapic'; - - /** The default scopes required by the service. */ - public static $serviceScopes = [ - 'https://www.googleapis.com/auth/cloud-platform', - ]; - - private static $customConstraintNameTemplate; - - private static $folderNameTemplate; - - private static $folderPolicyNameTemplate; - - private static $organizationNameTemplate; - - private static $organizationPolicyNameTemplate; - - private static $policyNameTemplate; - - private static $projectNameTemplate; - - private static $projectPolicyNameTemplate; - - private static $pathTemplateMap; - - private static function getClientDefaults() - { - return [ - 'serviceName' => self::SERVICE_NAME, - 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, - 'clientConfig' => __DIR__ . '/../resources/org_policy_client_config.json', - 'descriptorsConfigPath' => __DIR__ . '/../resources/org_policy_descriptor_config.php', - 'gcpApiConfigPath' => __DIR__ . '/../resources/org_policy_grpc_config.json', - 'credentialsConfig' => [ - 'defaultScopes' => self::$serviceScopes, - ], - 'transportConfig' => [ - 'rest' => [ - 'restClientConfigPath' => __DIR__ . '/../resources/org_policy_rest_client_config.php', - ], - ], - ]; - } - - private static function getCustomConstraintNameTemplate() - { - if (self::$customConstraintNameTemplate == null) { - self::$customConstraintNameTemplate = new PathTemplate('organizations/{organization}/customConstraints/{custom_constraint}'); - } - - return self::$customConstraintNameTemplate; - } - - private static function getFolderNameTemplate() - { - if (self::$folderNameTemplate == null) { - self::$folderNameTemplate = new PathTemplate('folders/{folder}'); - } - - return self::$folderNameTemplate; - } - - private static function getFolderPolicyNameTemplate() - { - if (self::$folderPolicyNameTemplate == null) { - self::$folderPolicyNameTemplate = new PathTemplate('folders/{folder}/policies/{policy}'); - } - - return self::$folderPolicyNameTemplate; - } - - private static function getOrganizationNameTemplate() - { - if (self::$organizationNameTemplate == null) { - self::$organizationNameTemplate = new PathTemplate('organizations/{organization}'); - } - - return self::$organizationNameTemplate; - } - - private static function getOrganizationPolicyNameTemplate() - { - if (self::$organizationPolicyNameTemplate == null) { - self::$organizationPolicyNameTemplate = new PathTemplate('organizations/{organization}/policies/{policy}'); - } - - return self::$organizationPolicyNameTemplate; - } - - private static function getPolicyNameTemplate() - { - if (self::$policyNameTemplate == null) { - self::$policyNameTemplate = new PathTemplate('projects/{project}/policies/{policy}'); - } - - return self::$policyNameTemplate; - } - - private static function getProjectNameTemplate() - { - if (self::$projectNameTemplate == null) { - self::$projectNameTemplate = new PathTemplate('projects/{project}'); - } - - return self::$projectNameTemplate; - } - - private static function getProjectPolicyNameTemplate() - { - if (self::$projectPolicyNameTemplate == null) { - self::$projectPolicyNameTemplate = new PathTemplate('projects/{project}/policies/{policy}'); - } - - return self::$projectPolicyNameTemplate; - } - - private static function getPathTemplateMap() - { - if (self::$pathTemplateMap == null) { - self::$pathTemplateMap = [ - 'customConstraint' => self::getCustomConstraintNameTemplate(), - 'folder' => self::getFolderNameTemplate(), - 'folderPolicy' => self::getFolderPolicyNameTemplate(), - 'organization' => self::getOrganizationNameTemplate(), - 'organizationPolicy' => self::getOrganizationPolicyNameTemplate(), - 'policy' => self::getPolicyNameTemplate(), - 'project' => self::getProjectNameTemplate(), - 'projectPolicy' => self::getProjectPolicyNameTemplate(), - ]; - } - - return self::$pathTemplateMap; - } - - /** - * Formats a string containing the fully-qualified path to represent a - * custom_constraint resource. - * - * @param string $organization - * @param string $customConstraint - * - * @return string The formatted custom_constraint resource. - */ - public static function customConstraintName($organization, $customConstraint) - { - return self::getCustomConstraintNameTemplate()->render([ - 'organization' => $organization, - 'custom_constraint' => $customConstraint, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a folder - * resource. - * - * @param string $folder - * - * @return string The formatted folder resource. - */ - public static function folderName($folder) - { - return self::getFolderNameTemplate()->render([ - 'folder' => $folder, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * folder_policy resource. - * - * @param string $folder - * @param string $policy - * - * @return string The formatted folder_policy resource. - */ - public static function folderPolicyName($folder, $policy) - { - return self::getFolderPolicyNameTemplate()->render([ - 'folder' => $folder, - 'policy' => $policy, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a organization - * resource. - * - * @param string $organization - * - * @return string The formatted organization resource. - */ - public static function organizationName($organization) - { - return self::getOrganizationNameTemplate()->render([ - 'organization' => $organization, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * organization_policy resource. - * - * @param string $organization - * @param string $policy - * - * @return string The formatted organization_policy resource. - */ - public static function organizationPolicyName($organization, $policy) - { - return self::getOrganizationPolicyNameTemplate()->render([ - 'organization' => $organization, - 'policy' => $policy, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a policy - * resource. - * - * @param string $project - * @param string $policy - * - * @return string The formatted policy resource. - */ - public static function policyName($project, $policy) - { - return self::getPolicyNameTemplate()->render([ - 'project' => $project, - 'policy' => $policy, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a project - * resource. - * - * @param string $project - * - * @return string The formatted project resource. - */ - public static function projectName($project) - { - return self::getProjectNameTemplate()->render([ - 'project' => $project, - ]); - } - - /** - * Formats a string containing the fully-qualified path to represent a - * project_policy resource. - * - * @param string $project - * @param string $policy - * - * @return string The formatted project_policy resource. - */ - public static function projectPolicyName($project, $policy) - { - return self::getProjectPolicyNameTemplate()->render([ - 'project' => $project, - 'policy' => $policy, - ]); - } - - /** - * Parses a formatted name string and returns an associative array of the components in the name. - * The following name formats are supported: - * Template: Pattern - * - customConstraint: organizations/{organization}/customConstraints/{custom_constraint} - * - folder: folders/{folder} - * - folderPolicy: folders/{folder}/policies/{policy} - * - organization: organizations/{organization} - * - organizationPolicy: organizations/{organization}/policies/{policy} - * - policy: projects/{project}/policies/{policy} - * - project: projects/{project} - * - projectPolicy: projects/{project}/policies/{policy} - * - * The optional $template argument can be supplied to specify a particular pattern, - * and must match one of the templates listed above. If no $template argument is - * provided, or if the $template argument does not match one of the templates - * listed, then parseName will check each of the supported templates, and return - * the first match. - * - * @param string $formattedName The formatted name string - * @param string $template Optional name of template to match - * - * @return array An associative array from name component IDs to component values. - * - * @throws ValidationException If $formattedName could not be matched. - */ - public static function parseName($formattedName, $template = null) - { - $templateMap = self::getPathTemplateMap(); - if ($template) { - if (!isset($templateMap[$template])) { - throw new ValidationException("Template name $template does not exist"); - } - - return $templateMap[$template]->match($formattedName); - } - - foreach ($templateMap as $templateName => $pathTemplate) { - try { - return $pathTemplate->match($formattedName); - } catch (ValidationException $ex) { - // Swallow the exception to continue trying other path templates - } - } - - throw new ValidationException("Input did not match any known format. Input: $formattedName"); - } - - /** - * Constructor. - * - * @param array $options { - * Optional. Options for configuring the service API wrapper. - * - * @type string $apiEndpoint - * The address of the API remote host. May optionally include the port, formatted - * as ":". Default 'orgpolicy.googleapis.com:443'. - * @type string|array|FetchAuthTokenInterface|CredentialsWrapper $credentials - * The credentials to be used by the client to authorize API calls. This option - * accepts either a path to a credentials file, or a decoded credentials file as a - * PHP array. - * *Advanced usage*: In addition, this option can also accept a pre-constructed - * {@see \Google\Auth\FetchAuthTokenInterface} object or - * {@see \Google\ApiCore\CredentialsWrapper} object. Note that when one of these - * objects are provided, any settings in $credentialsConfig will be ignored. - * @type array $credentialsConfig - * Options used to configure credentials, including auth token caching, for the - * client. For a full list of supporting configuration options, see - * {@see \Google\ApiCore\CredentialsWrapper::build()} . - * @type bool $disableRetries - * Determines whether or not retries defined by the client configuration should be - * disabled. Defaults to `false`. - * @type string|array $clientConfig - * Client method configuration, including retry settings. This option can be either - * a path to a JSON file, or a PHP array containing the decoded JSON data. By - * default this settings points to the default client config file, which is - * provided in the resources folder. - * @type string|TransportInterface $transport - * The transport used for executing network requests. May be either the string - * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. - * *Advanced usage*: Additionally, it is possible to pass in an already - * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note - * that when this object is provided, any settings in $transportConfig, and any - * $apiEndpoint setting, will be ignored. - * @type array $transportConfig - * Configuration options that will be used to construct the transport. Options for - * each supported transport type should be passed in a key for that transport. For - * example: - * $transportConfig = [ - * 'grpc' => [...], - * 'rest' => [...], - * ]; - * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and - * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the - * supported options. - * @type callable $clientCertSource - * A callable which returns the client cert as a string. This can be used to - * provide a certificate and private key to the transport layer for mTLS. - * } - * - * @throws ValidationException - */ - public function __construct(array $options = []) - { - $clientOptions = $this->buildClientOptions($options); - $this->setClientOptions($clientOptions); - } - - /** - * Creates a custom constraint. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * organization does not exist. - * Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the - * constraint already exists on the given organization. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedParent = $orgPolicyClient->organizationName('[ORGANIZATION]'); - * $customConstraint = new CustomConstraint(); - * $response = $orgPolicyClient->createCustomConstraint($formattedParent, $customConstraint); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $parent Required. Must be in the following form: - * - * * `organizations/{organization_id}` - * @param CustomConstraint $customConstraint Required. Custom constraint to create. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\CustomConstraint - * - * @throws ApiException if the remote call fails - */ - public function createCustomConstraint($parent, $customConstraint, array $optionalArgs = []) - { - $request = new CreateCustomConstraintRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setCustomConstraint($customConstraint); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CreateCustomConstraint', CustomConstraint::class, $optionalArgs, $request)->wait(); - } - - /** - * 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 Google Cloud resource. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedParent = $orgPolicyClient->projectName('[PROJECT]'); - * $policy = new Policy(); - * $response = $orgPolicyClient->createPolicy($formattedParent, $policy); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $parent Required. The Google 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 Policy $policy Required. Policy to create. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\Policy - * - * @throws ApiException if the remote call fails - */ - public function createPolicy($parent, $policy, array $optionalArgs = []) - { - $request = new CreatePolicyRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $request->setPolicy($policy); - $requestParamHeaders['parent'] = $parent; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('CreatePolicy', Policy::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a custom constraint. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint does not exist. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedName = $orgPolicyClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - * $orgPolicyClient->deleteCustomConstraint($formattedName); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $name Required. Name of the custom constraint to delete. - * See the custom constraint entry for naming rules. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function deleteCustomConstraint($name, array $optionalArgs = []) - { - $request = new DeleteCustomConstraintRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('DeleteCustomConstraint', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Deletes a policy. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint or organization policy does not exist. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedName = $orgPolicyClient->policyName('[PROJECT]', '[POLICY]'); - * $orgPolicyClient->deletePolicy($formattedName); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $name Required. Name of the policy to delete. - * See the policy entry for naming rules. - * @param array $optionalArgs { - * Optional. - * - * @type string $etag - * Optional. The current etag of policy. If an etag is provided and does not - * match the current etag of the policy, deletion will be blocked and an - * ABORTED error will be returned. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @throws ApiException if the remote call fails - */ - public function deletePolicy($name, array $optionalArgs = []) - { - $request = new DeletePolicyRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - if (isset($optionalArgs['etag'])) { - $request->setEtag($optionalArgs['etag']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('DeletePolicy', GPBEmpty::class, $optionalArgs, $request)->wait(); - } - - /** - * Gets a custom constraint. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * custom constraint does not exist. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedName = $orgPolicyClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - * $response = $orgPolicyClient->getCustomConstraint($formattedName); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $name Required. Resource name of the custom constraint. See the custom constraint - * entry for naming requirements. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\CustomConstraint - * - * @throws ApiException if the remote call fails - */ - public function getCustomConstraint($name, array $optionalArgs = []) - { - $request = new GetCustomConstraintRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetCustomConstraint', CustomConstraint::class, $optionalArgs, $request)->wait(); - } - - /** - * 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 - * an evaluated policy across multiple resources. - * Subtrees of Resource Manager resource hierarchy with 'under:' prefix will - * not be expanded. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedName = $orgPolicyClient->policyName('[PROJECT]', '[POLICY]'); - * $response = $orgPolicyClient->getEffectivePolicy($formattedName); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $name Required. The effective policy to compute. See - * [Policy][google.cloud.orgpolicy.v2.Policy] for naming requirements. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\Policy - * - * @throws ApiException if the remote call fails - */ - public function getEffectivePolicy($name, array $optionalArgs = []) - { - $request = new GetEffectivePolicyRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetEffectivePolicy', Policy::class, $optionalArgs, $request)->wait(); - } - - /** - * 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. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedName = $orgPolicyClient->policyName('[PROJECT]', '[POLICY]'); - * $response = $orgPolicyClient->getPolicy($formattedName); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $name Required. Resource name of the policy. See - * [Policy][google.cloud.orgpolicy.v2.Policy] for naming requirements. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\Policy - * - * @throws ApiException if the remote call fails - */ - public function getPolicy($name, array $optionalArgs = []) - { - $request = new GetPolicyRequest(); - $requestParamHeaders = []; - $request->setName($name); - $requestParamHeaders['name'] = $name; - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('GetPolicy', Policy::class, $optionalArgs, $request)->wait(); - } - - /** - * Lists constraints that could be applied on the specified resource. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedParent = $orgPolicyClient->projectName('[PROJECT]'); - * // Iterate over pages of elements - * $pagedResponse = $orgPolicyClient->listConstraints($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $orgPolicyClient->listConstraints($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $parent Required. The Google 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 array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listConstraints($parent, array $optionalArgs = []) - { - $request = new ListConstraintsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListConstraints', $optionalArgs, ListConstraintsResponse::class, $request); - } - - /** - * Retrieves all of the custom constraints that exist on a particular - * organization resource. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedParent = $orgPolicyClient->organizationName('[ORGANIZATION]'); - * // Iterate over pages of elements - * $pagedResponse = $orgPolicyClient->listCustomConstraints($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $orgPolicyClient->listCustomConstraints($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $parent Required. The target Google Cloud resource that parents the set of custom - * constraints that will be returned from this call. Must be in one of the - * following forms: - * - * * `organizations/{organization_id}` - * @param array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listCustomConstraints($parent, array $optionalArgs = []) - { - $request = new ListCustomConstraintsRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListCustomConstraints', $optionalArgs, ListCustomConstraintsResponse::class, $request); - } - - /** - * Retrieves all of the policies that exist on a particular resource. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $formattedParent = $orgPolicyClient->projectName('[PROJECT]'); - * // Iterate over pages of elements - * $pagedResponse = $orgPolicyClient->listPolicies($formattedParent); - * foreach ($pagedResponse->iteratePages() as $page) { - * foreach ($page as $element) { - * // doSomethingWith($element); - * } - * } - * // Alternatively: - * // Iterate through all elements - * $pagedResponse = $orgPolicyClient->listPolicies($formattedParent); - * foreach ($pagedResponse->iterateAllElements() as $element) { - * // doSomethingWith($element); - * } - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param string $parent Required. The target Google 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 array $optionalArgs { - * Optional. - * - * @type int $pageSize - * The maximum number of resources contained in the underlying API - * response. The API may return fewer values in a page, even if - * there are additional values to be retrieved. - * @type string $pageToken - * A page token is used to specify a page of values to be returned. - * If no page token is specified (the default), the first page - * of values will be returned. Any page token used here must have - * been generated by a previous call to the API. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\ApiCore\PagedListResponse - * - * @throws ApiException if the remote call fails - */ - public function listPolicies($parent, array $optionalArgs = []) - { - $request = new ListPoliciesRequest(); - $requestParamHeaders = []; - $request->setParent($parent); - $requestParamHeaders['parent'] = $parent; - if (isset($optionalArgs['pageSize'])) { - $request->setPageSize($optionalArgs['pageSize']); - } - - if (isset($optionalArgs['pageToken'])) { - $request->setPageToken($optionalArgs['pageToken']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->getPagedListResponse('ListPolicies', $optionalArgs, ListPoliciesResponse::class, $request); - } - - /** - * Updates a custom constraint. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint does not exist. - * - * Note: the supplied policy will perform a full overwrite of all - * fields. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $customConstraint = new CustomConstraint(); - * $response = $orgPolicyClient->updateCustomConstraint($customConstraint); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param CustomConstraint $customConstraint Required. `CustomConstraint` to update. - * @param array $optionalArgs { - * Optional. - * - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\CustomConstraint - * - * @throws ApiException if the remote call fails - */ - public function updateCustomConstraint($customConstraint, array $optionalArgs = []) - { - $request = new UpdateCustomConstraintRequest(); - $requestParamHeaders = []; - $request->setCustomConstraint($customConstraint); - $requestParamHeaders['custom_constraint.name'] = $customConstraint->getName(); - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('UpdateCustomConstraint', CustomConstraint::class, $optionalArgs, $request)->wait(); - } - - /** - * 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. - * - * Sample code: - * ``` - * $orgPolicyClient = new OrgPolicyClient(); - * try { - * $policy = new Policy(); - * $response = $orgPolicyClient->updatePolicy($policy); - * } finally { - * $orgPolicyClient->close(); - * } - * ``` - * - * @param Policy $policy Required. Policy to update. - * @param array $optionalArgs { - * Optional. - * - * @type FieldMask $updateMask - * Field mask used to specify the fields to be overwritten in the policy - * by the set. The fields specified in the update_mask are relative to the - * policy, not the full request. - * @type RetrySettings|array $retrySettings - * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an - * associative array of retry settings parameters. See the documentation on - * {@see RetrySettings} for example usage. - * } - * - * @return \Google\Cloud\OrgPolicy\V2\Policy - * - * @throws ApiException if the remote call fails - */ - public function updatePolicy($policy, array $optionalArgs = []) - { - $request = new UpdatePolicyRequest(); - $requestParamHeaders = []; - $request->setPolicy($policy); - $requestParamHeaders['policy.name'] = $policy->getName(); - if (isset($optionalArgs['updateMask'])) { - $request->setUpdateMask($optionalArgs['updateMask']); - } - - $requestParams = new RequestParamsHeaderDescriptor($requestParamHeaders); - $optionalArgs['headers'] = isset($optionalArgs['headers']) ? array_merge($requestParams->getHeader(), $optionalArgs['headers']) : $requestParams->getHeader(); - return $this->startCall('UpdatePolicy', Policy::class, $optionalArgs, $request)->wait(); - } -} diff --git a/OrgPolicy/src/V2/GetCustomConstraintRequest.php b/OrgPolicy/src/V2/GetCustomConstraintRequest.php index 0bca05fde5ee..f169a5d51f9c 100644 --- a/OrgPolicy/src/V2/GetCustomConstraintRequest.php +++ b/OrgPolicy/src/V2/GetCustomConstraintRequest.php @@ -22,7 +22,7 @@ class GetCustomConstraintRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. Resource name of the custom constraint. See the custom constraint diff --git a/OrgPolicy/src/V2/GetEffectivePolicyRequest.php b/OrgPolicy/src/V2/GetEffectivePolicyRequest.php index 21446fbad6d3..338899f8a5e9 100644 --- a/OrgPolicy/src/V2/GetEffectivePolicyRequest.php +++ b/OrgPolicy/src/V2/GetEffectivePolicyRequest.php @@ -22,7 +22,7 @@ class GetEffectivePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. The effective policy to compute. See diff --git a/OrgPolicy/src/V2/GetPolicyRequest.php b/OrgPolicy/src/V2/GetPolicyRequest.php index 8f6d1c586b14..f48f61f6804a 100644 --- a/OrgPolicy/src/V2/GetPolicyRequest.php +++ b/OrgPolicy/src/V2/GetPolicyRequest.php @@ -22,7 +22,7 @@ class GetPolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $name = ''; + protected $name = ''; /** * @param string $name Required. Resource name of the policy. See diff --git a/OrgPolicy/src/V2/ListConstraintsRequest.php b/OrgPolicy/src/V2/ListConstraintsRequest.php index 63676bb7b47e..f0f09385397f 100644 --- a/OrgPolicy/src/V2/ListConstraintsRequest.php +++ b/OrgPolicy/src/V2/ListConstraintsRequest.php @@ -26,7 +26,7 @@ class ListConstraintsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * 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 @@ -34,14 +34,14 @@ class ListConstraintsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 page_size = 2; */ - private $page_size = 0; + protected $page_size = 0; /** * 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. * * Generated from protobuf field string page_token = 3; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. The Google Cloud resource that parents the constraint. Must be in diff --git a/OrgPolicy/src/V2/ListConstraintsResponse.php b/OrgPolicy/src/V2/ListConstraintsResponse.php index 922531138951..26bd82b66fd3 100644 --- a/OrgPolicy/src/V2/ListConstraintsResponse.php +++ b/OrgPolicy/src/V2/ListConstraintsResponse.php @@ -27,7 +27,7 @@ class ListConstraintsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/OrgPolicy/src/V2/ListCustomConstraintsRequest.php b/OrgPolicy/src/V2/ListCustomConstraintsRequest.php index 21cbafbb0466..b04e17ab5b9c 100644 --- a/OrgPolicy/src/V2/ListCustomConstraintsRequest.php +++ b/OrgPolicy/src/V2/ListCustomConstraintsRequest.php @@ -24,7 +24,7 @@ class ListCustomConstraintsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * 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 @@ -32,14 +32,14 @@ class ListCustomConstraintsRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 page_size = 2; */ - private $page_size = 0; + protected $page_size = 0; /** * 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. * * Generated from protobuf field string page_token = 3; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. The target Google Cloud resource that parents the set of custom diff --git a/OrgPolicy/src/V2/ListCustomConstraintsResponse.php b/OrgPolicy/src/V2/ListCustomConstraintsResponse.php index e4e5b2d94a76..98b10425eb16 100644 --- a/OrgPolicy/src/V2/ListCustomConstraintsResponse.php +++ b/OrgPolicy/src/V2/ListCustomConstraintsResponse.php @@ -30,7 +30,7 @@ class ListCustomConstraintsResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/OrgPolicy/src/V2/ListPoliciesRequest.php b/OrgPolicy/src/V2/ListPoliciesRequest.php index cf79e64a6237..a604c24236bb 100644 --- a/OrgPolicy/src/V2/ListPoliciesRequest.php +++ b/OrgPolicy/src/V2/ListPoliciesRequest.php @@ -27,7 +27,7 @@ class ListPoliciesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { */ - private $parent = ''; + protected $parent = ''; /** * 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 @@ -35,14 +35,14 @@ class ListPoliciesRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field int32 page_size = 2; */ - private $page_size = 0; + protected $page_size = 0; /** * 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. * * Generated from protobuf field string page_token = 3; */ - private $page_token = ''; + protected $page_token = ''; /** * @param string $parent Required. The target Google Cloud resource that parents the set of diff --git a/OrgPolicy/src/V2/ListPoliciesResponse.php b/OrgPolicy/src/V2/ListPoliciesResponse.php index 7816e854e44a..d60a6f2158e1 100644 --- a/OrgPolicy/src/V2/ListPoliciesResponse.php +++ b/OrgPolicy/src/V2/ListPoliciesResponse.php @@ -30,7 +30,7 @@ class ListPoliciesResponse extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string next_page_token = 2; */ - private $next_page_token = ''; + protected $next_page_token = ''; /** * Constructor. diff --git a/OrgPolicy/src/V2/OrgPolicyClient.php b/OrgPolicy/src/V2/OrgPolicyClient.php deleted file mode 100644 index 8145ac29b639..000000000000 --- a/OrgPolicy/src/V2/OrgPolicyClient.php +++ /dev/null @@ -1,34 +0,0 @@ -_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/ListConstraints', - $argument, - ['\Google\Cloud\OrgPolicy\V2\ListConstraintsResponse', 'decode'], - $metadata, $options); - } - - /** - * Retrieves all of the `Policies` that exist on a particular resource. - * @param \Google\Cloud\OrgPolicy\V2\ListPoliciesRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function ListPolicies(\Google\Cloud\OrgPolicy\V2\ListPoliciesRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/ListPolicies', - $argument, - ['\Google\Cloud\OrgPolicy\V2\ListPoliciesResponse', 'decode'], - $metadata, $options); - } - - /** - * 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 \Google\Cloud\OrgPolicy\V2\GetPolicyRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetPolicy(\Google\Cloud\OrgPolicy\V2\GetPolicyRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/GetPolicy', - $argument, - ['\Google\Cloud\OrgPolicy\V2\Policy', 'decode'], - $metadata, $options); - } - - /** - * 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 \Google\Cloud\OrgPolicy\V2\GetEffectivePolicyRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function GetEffectivePolicy(\Google\Cloud\OrgPolicy\V2\GetEffectivePolicyRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/GetEffectivePolicy', - $argument, - ['\Google\Cloud\OrgPolicy\V2\Policy', 'decode'], - $metadata, $options); - } - - /** - * 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 \Google\Cloud\OrgPolicy\V2\CreatePolicyRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function CreatePolicy(\Google\Cloud\OrgPolicy\V2\CreatePolicyRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/CreatePolicy', - $argument, - ['\Google\Cloud\OrgPolicy\V2\Policy', 'decode'], - $metadata, $options); - } - - /** - * 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 \Google\Cloud\OrgPolicy\V2\UpdatePolicyRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function UpdatePolicy(\Google\Cloud\OrgPolicy\V2\UpdatePolicyRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/UpdatePolicy', - $argument, - ['\Google\Cloud\OrgPolicy\V2\Policy', 'decode'], - $metadata, $options); - } - - /** - * Deletes a Policy. - * - * Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the - * constraint or Org Policy does not exist. - * @param \Google\Cloud\OrgPolicy\V2\DeletePolicyRequest $argument input argument - * @param array $metadata metadata - * @param array $options call options - * @return \Grpc\UnaryCall - */ - public function DeletePolicy(\Google\Cloud\OrgPolicy\V2\DeletePolicyRequest $argument, - $metadata = [], $options = []) { - return $this->_simpleRequest('/google.cloud.orgpolicy.v2.OrgPolicy/DeletePolicy', - $argument, - ['\Google\Protobuf\GPBEmpty', 'decode'], - $metadata, $options); - } - -} diff --git a/OrgPolicy/src/V2/Policy.php b/OrgPolicy/src/V2/Policy.php index fab357ec11cc..804da4a74295 100644 --- a/OrgPolicy/src/V2/Policy.php +++ b/OrgPolicy/src/V2/Policy.php @@ -30,13 +30,13 @@ class Policy extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IMMUTABLE]; */ - private $name = ''; + protected $name = ''; /** * Basic information about the Organization Policy. * * Generated from protobuf field .google.cloud.orgpolicy.v2.PolicySpec spec = 2; */ - private $spec = null; + protected $spec = null; /** * Deprecated. * @@ -51,7 +51,7 @@ class Policy extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.orgpolicy.v2.PolicySpec dry_run_spec = 4; */ - private $dry_run_spec = null; + protected $dry_run_spec = null; /** * Optional. An opaque tag indicating the current state of the policy, used * for concurrency control. This 'etag' is computed by the server based on the @@ -60,7 +60,7 @@ class Policy extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string etag = 5 [(.google.api.field_behavior) = OPTIONAL]; */ - private $etag = ''; + protected $etag = ''; /** * Constructor. diff --git a/OrgPolicy/src/V2/PolicySpec.php b/OrgPolicy/src/V2/PolicySpec.php index 2f98ec07aba0..88ddcb36ab79 100644 --- a/OrgPolicy/src/V2/PolicySpec.php +++ b/OrgPolicy/src/V2/PolicySpec.php @@ -28,7 +28,7 @@ class PolicySpec extends \Google\Protobuf\Internal\Message * * Generated from protobuf field string etag = 1; */ - private $etag = ''; + protected $etag = ''; /** * Output only. The time stamp this was previously updated. This * represents the last time a call to `CreatePolicy` or `UpdatePolicy` was @@ -36,7 +36,7 @@ class PolicySpec extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.Timestamp update_time = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; */ - private $update_time = null; + protected $update_time = null; /** * In policies for boolean constraints, the following requirements apply: * - There must be one and only one policy rule where condition is unset. @@ -58,7 +58,7 @@ class PolicySpec extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool inherit_from_parent = 4; */ - private $inherit_from_parent = false; + protected $inherit_from_parent = false; /** * Ignores policies set above this resource and restores the * `constraint_default` enforcement behavior of the specific constraint at @@ -69,7 +69,7 @@ class PolicySpec extends \Google\Protobuf\Internal\Message * * Generated from protobuf field bool reset = 5; */ - private $reset = false; + protected $reset = false; /** * Constructor. diff --git a/OrgPolicy/src/V2/PolicySpec/PolicyRule.php b/OrgPolicy/src/V2/PolicySpec/PolicyRule.php index 0aaa59d7b13a..4d8fddc8c552 100644 --- a/OrgPolicy/src/V2/PolicySpec/PolicyRule.php +++ b/OrgPolicy/src/V2/PolicySpec/PolicyRule.php @@ -31,7 +31,7 @@ class PolicyRule extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.type.Expr condition = 5; */ - private $condition = null; + protected $condition = null; protected $kind; /** @@ -275,6 +275,4 @@ public function getKind() } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(PolicyRule::class, \Google\Cloud\OrgPolicy\V2\PolicySpec_PolicyRule::class); diff --git a/OrgPolicy/src/V2/PolicySpec/PolicyRule/StringValues.php b/OrgPolicy/src/V2/PolicySpec/PolicyRule/StringValues.php index 389de6430399..2640fcecd954 100644 --- a/OrgPolicy/src/V2/PolicySpec/PolicyRule/StringValues.php +++ b/OrgPolicy/src/V2/PolicySpec/PolicyRule/StringValues.php @@ -113,6 +113,4 @@ public function setDeniedValues($var) } -// Adding a class alias for backwards compatibility with the previous class name. -class_alias(StringValues::class, \Google\Cloud\OrgPolicy\V2\PolicySpec_PolicyRule_StringValues::class); diff --git a/OrgPolicy/src/V2/PolicySpec_PolicyRule.php b/OrgPolicy/src/V2/PolicySpec_PolicyRule.php deleted file mode 100644 index b5af57273b60..000000000000 --- a/OrgPolicy/src/V2/PolicySpec_PolicyRule.php +++ /dev/null @@ -1,16 +0,0 @@ -.google.cloud.orgpolicy.v2.CustomConstraint custom_constraint = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $custom_constraint = null; + protected $custom_constraint = null; /** * @param \Google\Cloud\OrgPolicy\V2\CustomConstraint $customConstraint Required. `CustomConstraint` to update. diff --git a/OrgPolicy/src/V2/UpdatePolicyRequest.php b/OrgPolicy/src/V2/UpdatePolicyRequest.php index 9220cb532daf..0c67e5957f80 100644 --- a/OrgPolicy/src/V2/UpdatePolicyRequest.php +++ b/OrgPolicy/src/V2/UpdatePolicyRequest.php @@ -21,7 +21,7 @@ class UpdatePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.cloud.orgpolicy.v2.Policy policy = 1 [(.google.api.field_behavior) = REQUIRED]; */ - private $policy = null; + protected $policy = null; /** * Field mask used to specify the fields to be overwritten in the policy * by the set. The fields specified in the update_mask are relative to the @@ -29,7 +29,7 @@ class UpdatePolicyRequest extends \Google\Protobuf\Internal\Message * * Generated from protobuf field .google.protobuf.FieldMask update_mask = 3; */ - private $update_mask = null; + protected $update_mask = null; /** * @param \Google\Cloud\OrgPolicy\V2\Policy $policy Required. Policy to update. diff --git a/OrgPolicy/tests/Unit/V2/Client/OrgPolicyClientTest.php b/OrgPolicy/tests/Unit/V2/Client/OrgPolicyClientTest.php index 58468aadfe0d..f65371295daf 100644 --- a/OrgPolicy/tests/Unit/V2/Client/OrgPolicyClientTest.php +++ b/OrgPolicy/tests/Unit/V2/Client/OrgPolicyClientTest.php @@ -1,6 +1,6 @@ getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); + return $this->getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); } /** @return OrgPolicyClient */ @@ -127,12 +129,15 @@ public function createCustomConstraintExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); @@ -171,9 +176,7 @@ public function createPolicyTest() // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); $policy = new Policy(); - $request = (new CreatePolicyRequest()) - ->setParent($formattedParent) - ->setPolicy($policy); + $request = (new CreatePolicyRequest())->setParent($formattedParent)->setPolicy($policy); $response = $gapicClient->createPolicy($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -199,19 +202,20 @@ public function createPolicyExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); $policy = new Policy(); - $request = (new CreatePolicyRequest()) - ->setParent($formattedParent) - ->setPolicy($policy); + $request = (new CreatePolicyRequest())->setParent($formattedParent)->setPolicy($policy); try { $gapicClient->createPolicy($request); // If the $gapicClient method call did not throw, fail the test @@ -238,8 +242,7 @@ public function deleteCustomConstraintTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $request = (new DeleteCustomConstraintRequest()) - ->setName($formattedName); + $request = (new DeleteCustomConstraintRequest())->setName($formattedName); $gapicClient->deleteCustomConstraint($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -262,17 +265,19 @@ public function deleteCustomConstraintExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $request = (new DeleteCustomConstraintRequest()) - ->setName($formattedName); + $request = (new DeleteCustomConstraintRequest())->setName($formattedName); try { $gapicClient->deleteCustomConstraint($request); // If the $gapicClient method call did not throw, fail the test @@ -299,8 +304,7 @@ public function deletePolicyTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new DeletePolicyRequest()) - ->setName($formattedName); + $request = (new DeletePolicyRequest())->setName($formattedName); $gapicClient->deletePolicy($request); $actualRequests = $transport->popReceivedCalls(); $this->assertSame(1, count($actualRequests)); @@ -323,17 +327,19 @@ public function deletePolicyExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new DeletePolicyRequest()) - ->setName($formattedName); + $request = (new DeletePolicyRequest())->setName($formattedName); try { $gapicClient->deletePolicy($request); // If the $gapicClient method call did not throw, fail the test @@ -368,8 +374,7 @@ public function getCustomConstraintTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $request = (new GetCustomConstraintRequest()) - ->setName($formattedName); + $request = (new GetCustomConstraintRequest())->setName($formattedName); $response = $gapicClient->getCustomConstraint($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -393,17 +398,19 @@ public function getCustomConstraintExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $request = (new GetCustomConstraintRequest()) - ->setName($formattedName); + $request = (new GetCustomConstraintRequest())->setName($formattedName); try { $gapicClient->getCustomConstraint($request); // If the $gapicClient method call did not throw, fail the test @@ -434,8 +441,7 @@ public function getEffectivePolicyTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new GetEffectivePolicyRequest()) - ->setName($formattedName); + $request = (new GetEffectivePolicyRequest())->setName($formattedName); $response = $gapicClient->getEffectivePolicy($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -459,17 +465,19 @@ public function getEffectivePolicyExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new GetEffectivePolicyRequest()) - ->setName($formattedName); + $request = (new GetEffectivePolicyRequest())->setName($formattedName); try { $gapicClient->getEffectivePolicy($request); // If the $gapicClient method call did not throw, fail the test @@ -500,8 +508,7 @@ public function getPolicyTest() $transport->addResponse($expectedResponse); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new GetPolicyRequest()) - ->setName($formattedName); + $request = (new GetPolicyRequest())->setName($formattedName); $response = $gapicClient->getPolicy($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -525,17 +532,19 @@ public function getPolicyExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $request = (new GetPolicyRequest()) - ->setName($formattedName); + $request = (new GetPolicyRequest())->setName($formattedName); try { $gapicClient->getPolicy($request); // If the $gapicClient method call did not throw, fail the test @@ -560,17 +569,14 @@ public function listConstraintsTest() // Mock response $nextPageToken = ''; $constraintsElement = new Constraint(); - $constraints = [ - $constraintsElement, - ]; + $constraints = [$constraintsElement]; $expectedResponse = new ListConstraintsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setConstraints($constraints); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ListConstraintsRequest()) - ->setParent($formattedParent); + $request = (new ListConstraintsRequest())->setParent($formattedParent); $response = $gapicClient->listConstraints($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -597,17 +603,19 @@ public function listConstraintsExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ListConstraintsRequest()) - ->setParent($formattedParent); + $request = (new ListConstraintsRequest())->setParent($formattedParent); try { $gapicClient->listConstraints($request); // If the $gapicClient method call did not throw, fail the test @@ -632,17 +640,14 @@ public function listCustomConstraintsTest() // Mock response $nextPageToken = ''; $customConstraintsElement = new CustomConstraint(); - $customConstraints = [ - $customConstraintsElement, - ]; + $customConstraints = [$customConstraintsElement]; $expectedResponse = new ListCustomConstraintsResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setCustomConstraints($customConstraints); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - $request = (new ListCustomConstraintsRequest()) - ->setParent($formattedParent); + $request = (new ListCustomConstraintsRequest())->setParent($formattedParent); $response = $gapicClient->listCustomConstraints($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -669,17 +674,19 @@ public function listCustomConstraintsExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - $request = (new ListCustomConstraintsRequest()) - ->setParent($formattedParent); + $request = (new ListCustomConstraintsRequest())->setParent($formattedParent); try { $gapicClient->listCustomConstraints($request); // If the $gapicClient method call did not throw, fail the test @@ -704,17 +711,14 @@ public function listPoliciesTest() // Mock response $nextPageToken = ''; $policiesElement = new Policy(); - $policies = [ - $policiesElement, - ]; + $policies = [$policiesElement]; $expectedResponse = new ListPoliciesResponse(); $expectedResponse->setNextPageToken($nextPageToken); $expectedResponse->setPolicies($policies); $transport->addResponse($expectedResponse); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ListPoliciesRequest()) - ->setParent($formattedParent); + $request = (new ListPoliciesRequest())->setParent($formattedParent); $response = $gapicClient->listPolicies($request); $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); $resources = iterator_to_array($response->iterateAllElements()); @@ -741,17 +745,19 @@ public function listPoliciesExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $formattedParent = $gapicClient->projectName('[PROJECT]'); - $request = (new ListPoliciesRequest()) - ->setParent($formattedParent); + $request = (new ListPoliciesRequest())->setParent($formattedParent); try { $gapicClient->listPolicies($request); // If the $gapicClient method call did not throw, fail the test @@ -786,8 +792,7 @@ public function updateCustomConstraintTest() $transport->addResponse($expectedResponse); // Mock request $customConstraint = new CustomConstraint(); - $request = (new UpdateCustomConstraintRequest()) - ->setCustomConstraint($customConstraint); + $request = (new UpdateCustomConstraintRequest())->setCustomConstraint($customConstraint); $response = $gapicClient->updateCustomConstraint($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -811,17 +816,19 @@ public function updateCustomConstraintExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $customConstraint = new CustomConstraint(); - $request = (new UpdateCustomConstraintRequest()) - ->setCustomConstraint($customConstraint); + $request = (new UpdateCustomConstraintRequest())->setCustomConstraint($customConstraint); try { $gapicClient->updateCustomConstraint($request); // If the $gapicClient method call did not throw, fail the test @@ -852,8 +859,7 @@ public function updatePolicyTest() $transport->addResponse($expectedResponse); // Mock request $policy = new Policy(); - $request = (new UpdatePolicyRequest()) - ->setPolicy($policy); + $request = (new UpdatePolicyRequest())->setPolicy($policy); $response = $gapicClient->updatePolicy($request); $this->assertEquals($expectedResponse, $response); $actualRequests = $transport->popReceivedCalls(); @@ -877,17 +883,19 @@ public function updatePolicyExceptionTest() $status = new stdClass(); $status->code = Code::DATA_LOSS; $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); $transport->addResponse(null, $status); // Mock request $policy = new Policy(); - $request = (new UpdatePolicyRequest()) - ->setPolicy($policy); + $request = (new UpdatePolicyRequest())->setPolicy($policy); try { $gapicClient->updatePolicy($request); // If the $gapicClient method call did not throw, fail the test diff --git a/OrgPolicy/tests/Unit/V2/OrgPolicyClientTest.php b/OrgPolicy/tests/Unit/V2/OrgPolicyClientTest.php deleted file mode 100644 index a730604e0fb7..000000000000 --- a/OrgPolicy/tests/Unit/V2/OrgPolicyClientTest.php +++ /dev/null @@ -1,839 +0,0 @@ -getMockBuilder(CredentialsWrapper::class)->disableOriginalConstructor()->getMock(); - } - - /** @return OrgPolicyClient */ - private function createClient(array $options = []) - { - $options += [ - 'credentials' => $this->createCredentials(), - ]; - return new OrgPolicyClient($options); - } - - /** @test */ - public function createCustomConstraintTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $condition = 'condition-861311717'; - $displayName = 'displayName1615086568'; - $description = 'description-1724546052'; - $expectedResponse = new CustomConstraint(); - $expectedResponse->setName($name); - $expectedResponse->setCondition($condition); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - $customConstraint = new CustomConstraint(); - $response = $gapicClient->createCustomConstraint($formattedParent, $customConstraint); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/CreateCustomConstraint', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getCustomConstraint(); - $this->assertProtobufEquals($customConstraint, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createCustomConstraintExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - $customConstraint = new CustomConstraint(); - try { - $gapicClient->createCustomConstraint($formattedParent, $customConstraint); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createPolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $etag = 'etag3123477'; - $expectedResponse = new Policy(); - $expectedResponse->setName($name); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $policy = new Policy(); - $response = $gapicClient->createPolicy($formattedParent, $policy); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/CreatePolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $actualValue = $actualRequestObject->getPolicy(); - $this->assertProtobufEquals($policy, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function createPolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $policy = new Policy(); - try { - $gapicClient->createPolicy($formattedParent, $policy); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteCustomConstraintTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $gapicClient->deleteCustomConstraint($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/DeleteCustomConstraint', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deleteCustomConstraintExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - try { - $gapicClient->deleteCustomConstraint($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deletePolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $expectedResponse = new GPBEmpty(); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $gapicClient->deletePolicy($formattedName); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/DeletePolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function deletePolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - try { - $gapicClient->deletePolicy($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getCustomConstraintTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $condition = 'condition-861311717'; - $displayName = 'displayName1615086568'; - $description = 'description-1724546052'; - $expectedResponse = new CustomConstraint(); - $expectedResponse->setName($name2); - $expectedResponse->setCondition($condition); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - $response = $gapicClient->getCustomConstraint($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/GetCustomConstraint', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getCustomConstraintExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); - try { - $gapicClient->getCustomConstraint($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getEffectivePolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $etag = 'etag3123477'; - $expectedResponse = new Policy(); - $expectedResponse->setName($name2); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $response = $gapicClient->getEffectivePolicy($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/GetEffectivePolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getEffectivePolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - try { - $gapicClient->getEffectivePolicy($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getPolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name2 = 'name2-1052831874'; - $etag = 'etag3123477'; - $expectedResponse = new Policy(); - $expectedResponse->setName($name2); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - $response = $gapicClient->getPolicy($formattedName); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/GetPolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getName(); - $this->assertProtobufEquals($formattedName, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function getPolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedName = $gapicClient->policyName('[PROJECT]', '[POLICY]'); - try { - $gapicClient->getPolicy($formattedName); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listConstraintsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $constraintsElement = new Constraint(); - $constraints = [ - $constraintsElement, - ]; - $expectedResponse = new ListConstraintsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setConstraints($constraints); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $response = $gapicClient->listConstraints($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getConstraints()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/ListConstraints', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listConstraintsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - try { - $gapicClient->listConstraints($formattedParent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listCustomConstraintsTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $customConstraintsElement = new CustomConstraint(); - $customConstraints = [ - $customConstraintsElement, - ]; - $expectedResponse = new ListCustomConstraintsResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setCustomConstraints($customConstraints); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - $response = $gapicClient->listCustomConstraints($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getCustomConstraints()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/ListCustomConstraints', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listCustomConstraintsExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->organizationName('[ORGANIZATION]'); - try { - $gapicClient->listCustomConstraints($formattedParent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listPoliciesTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $nextPageToken = ''; - $policiesElement = new Policy(); - $policies = [ - $policiesElement, - ]; - $expectedResponse = new ListPoliciesResponse(); - $expectedResponse->setNextPageToken($nextPageToken); - $expectedResponse->setPolicies($policies); - $transport->addResponse($expectedResponse); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - $response = $gapicClient->listPolicies($formattedParent); - $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); - $resources = iterator_to_array($response->iterateAllElements()); - $this->assertSame(1, count($resources)); - $this->assertEquals($expectedResponse->getPolicies()[0], $resources[0]); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/ListPolicies', $actualFuncCall); - $actualValue = $actualRequestObject->getParent(); - $this->assertProtobufEquals($formattedParent, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function listPoliciesExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $formattedParent = $gapicClient->projectName('[PROJECT]'); - try { - $gapicClient->listPolicies($formattedParent); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updateCustomConstraintTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $condition = 'condition-861311717'; - $displayName = 'displayName1615086568'; - $description = 'description-1724546052'; - $expectedResponse = new CustomConstraint(); - $expectedResponse->setName($name); - $expectedResponse->setCondition($condition); - $expectedResponse->setDisplayName($displayName); - $expectedResponse->setDescription($description); - $transport->addResponse($expectedResponse); - // Mock request - $customConstraint = new CustomConstraint(); - $response = $gapicClient->updateCustomConstraint($customConstraint); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/UpdateCustomConstraint', $actualFuncCall); - $actualValue = $actualRequestObject->getCustomConstraint(); - $this->assertProtobufEquals($customConstraint, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updateCustomConstraintExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $customConstraint = new CustomConstraint(); - try { - $gapicClient->updateCustomConstraint($customConstraint); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updatePolicyTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - // Mock response - $name = 'name3373707'; - $etag = 'etag3123477'; - $expectedResponse = new Policy(); - $expectedResponse->setName($name); - $expectedResponse->setEtag($etag); - $transport->addResponse($expectedResponse); - // Mock request - $policy = new Policy(); - $response = $gapicClient->updatePolicy($policy); - $this->assertEquals($expectedResponse, $response); - $actualRequests = $transport->popReceivedCalls(); - $this->assertSame(1, count($actualRequests)); - $actualFuncCall = $actualRequests[0]->getFuncCall(); - $actualRequestObject = $actualRequests[0]->getRequestObject(); - $this->assertSame('/google.cloud.orgpolicy.v2.OrgPolicy/UpdatePolicy', $actualFuncCall); - $actualValue = $actualRequestObject->getPolicy(); - $this->assertProtobufEquals($policy, $actualValue); - $this->assertTrue($transport->isExhausted()); - } - - /** @test */ - public function updatePolicyExceptionTest() - { - $transport = $this->createTransport(); - $gapicClient = $this->createClient([ - 'transport' => $transport, - ]); - $this->assertTrue($transport->isExhausted()); - $status = new stdClass(); - $status->code = Code::DATA_LOSS; - $status->details = 'internal error'; - $expectedExceptionMessage = json_encode([ - 'message' => 'internal error', - 'code' => Code::DATA_LOSS, - 'status' => 'DATA_LOSS', - 'details' => [], - ], JSON_PRETTY_PRINT); - $transport->addResponse(null, $status); - // Mock request - $policy = new Policy(); - try { - $gapicClient->updatePolicy($policy); - // If the $gapicClient method call did not throw, fail the test - $this->fail('Expected an ApiException, but no exception was thrown.'); - } catch (ApiException $ex) { - $this->assertEquals($status->code, $ex->getCode()); - $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); - } - // Call popReceivedCalls to ensure the stub is exhausted - $transport->popReceivedCalls(); - $this->assertTrue($transport->isExhausted()); - } -}