-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom constraints CRUD APIs, proper etag support in Org Po…
…licy Update/Delete API (#6893) docs: updated comments PiperOrigin-RevId: 591301652 Source-Link: googleapis/googleapis@db5ce67 Source-Link: googleapis/googleapis-gen@3c13326 Copy-Tag: eyJwIjoiT3JnUG9saWN5Ly5Pd2xCb3QueWFtbCIsImgiOiIzYzEzMzI2NmVkYWFmODFiMTRjMmRkOGZkNDcwNTEyN2RjYmNlMDZiIn0=
- Loading branch information
1 parent
eae8dec
commit 9691ed5
Showing
48 changed files
with
3,391 additions
and
323 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
80 changes: 80 additions & 0 deletions
80
OrgPolicy/samples/V2/OrgPolicyClient/create_custom_constraint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START orgpolicy_v2_generated_OrgPolicy_CreateCustomConstraint_sync] | ||
use Google\ApiCore\ApiException; | ||
use Google\Cloud\OrgPolicy\V2\Client\OrgPolicyClient; | ||
use Google\Cloud\OrgPolicy\V2\CreateCustomConstraintRequest; | ||
use Google\Cloud\OrgPolicy\V2\CustomConstraint; | ||
|
||
/** | ||
* 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. | ||
* | ||
* @param string $formattedParent Must be in the following form: | ||
* | ||
* * `organizations/{organization_id}` | ||
* Please see {@see OrgPolicyClient::organizationName()} for help formatting this field. | ||
*/ | ||
function create_custom_constraint_sample(string $formattedParent): void | ||
{ | ||
// Create a client. | ||
$orgPolicyClient = new OrgPolicyClient(); | ||
|
||
// Prepare the request message. | ||
$customConstraint = new CustomConstraint(); | ||
$request = (new CreateCustomConstraintRequest()) | ||
->setParent($formattedParent) | ||
->setCustomConstraint($customConstraint); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var CustomConstraint $response */ | ||
$response = $orgPolicyClient->createCustomConstraint($request); | ||
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$formattedParent = OrgPolicyClient::organizationName('[ORGANIZATION]'); | ||
|
||
create_custom_constraint_sample($formattedParent); | ||
} | ||
// [END orgpolicy_v2_generated_OrgPolicy_CreateCustomConstraint_sync] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
OrgPolicy/samples/V2/OrgPolicyClient/delete_custom_constraint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START orgpolicy_v2_generated_OrgPolicy_DeleteCustomConstraint_sync] | ||
use Google\ApiCore\ApiException; | ||
use Google\Cloud\OrgPolicy\V2\Client\OrgPolicyClient; | ||
use Google\Cloud\OrgPolicy\V2\DeleteCustomConstraintRequest; | ||
|
||
/** | ||
* Deletes a custom constraint. | ||
* | ||
* Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the | ||
* constraint does not exist. | ||
* | ||
* @param string $formattedName Name of the custom constraint to delete. | ||
* See the custom constraint entry for naming rules. Please see | ||
* {@see OrgPolicyClient::customConstraintName()} for help formatting this field. | ||
*/ | ||
function delete_custom_constraint_sample(string $formattedName): void | ||
{ | ||
// Create a client. | ||
$orgPolicyClient = new OrgPolicyClient(); | ||
|
||
// Prepare the request message. | ||
$request = (new DeleteCustomConstraintRequest()) | ||
->setName($formattedName); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
$orgPolicyClient->deleteCustomConstraint($request); | ||
printf('Call completed successfully.' . PHP_EOL); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$formattedName = OrgPolicyClient::customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); | ||
|
||
delete_custom_constraint_sample($formattedName); | ||
} | ||
// [END orgpolicy_v2_generated_OrgPolicy_DeleteCustomConstraint_sync] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
OrgPolicy/samples/V2/OrgPolicyClient/get_custom_constraint.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/* | ||
* GENERATED CODE WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START orgpolicy_v2_generated_OrgPolicy_GetCustomConstraint_sync] | ||
use Google\ApiCore\ApiException; | ||
use Google\Cloud\OrgPolicy\V2\Client\OrgPolicyClient; | ||
use Google\Cloud\OrgPolicy\V2\CustomConstraint; | ||
use Google\Cloud\OrgPolicy\V2\GetCustomConstraintRequest; | ||
|
||
/** | ||
* Gets a custom constraint. | ||
* | ||
* Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the | ||
* custom constraint does not exist. | ||
* | ||
* @param string $formattedName Resource name of the custom constraint. See the custom constraint | ||
* entry for naming requirements. Please see | ||
* {@see OrgPolicyClient::customConstraintName()} for help formatting this field. | ||
*/ | ||
function get_custom_constraint_sample(string $formattedName): void | ||
{ | ||
// Create a client. | ||
$orgPolicyClient = new OrgPolicyClient(); | ||
|
||
// Prepare the request message. | ||
$request = (new GetCustomConstraintRequest()) | ||
->setName($formattedName); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var CustomConstraint $response */ | ||
$response = $orgPolicyClient->getCustomConstraint($request); | ||
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$formattedName = OrgPolicyClient::customConstraintName('[ORGANIZATION]', '[CUSTOM_CONSTRAINT]'); | ||
|
||
get_custom_constraint_sample($formattedName); | ||
} | ||
// [END orgpolicy_v2_generated_OrgPolicy_GetCustomConstraint_sync] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.