Skip to content

Commit

Permalink
feat: Add custom constraints CRUD APIs, proper etag support in Org Po…
Browse files Browse the repository at this point in the history
…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
gcf-owl-bot[bot] authored Dec 15, 2023
1 parent eae8dec commit 9691ed5
Show file tree
Hide file tree
Showing 48 changed files with 3,391 additions and 323 deletions.
Binary file modified OrgPolicy/metadata/V2/Constraint.php
Binary file not shown.
Binary file modified OrgPolicy/metadata/V2/Orgpolicy.php
Binary file not shown.
80 changes: 80 additions & 0 deletions OrgPolicy/samples/V2/OrgPolicyClient/create_custom_constraint.php
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]
9 changes: 5 additions & 4 deletions OrgPolicy/samples/V2/OrgPolicyClient/create_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
use Google\Cloud\OrgPolicy\V2\Policy;

/**
* Creates a Policy.
* 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.
* policy already exists on the given Google Cloud resource.
*
* @param string $formattedParent The Google Cloud resource that will parent the new policy. Must
* be in one of the following forms:
*
* @param string $formattedParent The Cloud resource that will parent the new Policy. Must be in
* one of the following forms:
* * `projects/{project_number}`
* * `projects/{project_id}`
* * `folders/{folder_id}`
Expand Down
73 changes: 73 additions & 0 deletions OrgPolicy/samples/V2/OrgPolicyClient/delete_custom_constraint.php
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]
6 changes: 3 additions & 3 deletions OrgPolicy/samples/V2/OrgPolicyClient/delete_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
use Google\Cloud\OrgPolicy\V2\DeletePolicyRequest;

/**
* Deletes a Policy.
* Deletes a policy.
*
* Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the
* constraint or Org Policy does not exist.
* constraint or organization policy does not exist.
*
* @param string $formattedName Name of the policy to delete.
* See `Policy` for naming rules. Please see
* See the policy entry for naming rules. Please see
* {@see OrgPolicyClient::policyName()} for help formatting this field.
*/
function delete_policy_sample(string $formattedName): void
Expand Down
75 changes: 75 additions & 0 deletions OrgPolicy/samples/V2/OrgPolicyClient/get_custom_constraint.php
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]
11 changes: 6 additions & 5 deletions OrgPolicy/samples/V2/OrgPolicyClient/get_effective_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
use Google\Cloud\OrgPolicy\V2\Policy;

/**
* 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.
* 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.
*
* @param string $formattedName The effective policy to compute. See `Policy` for naming rules. Please see
* @param string $formattedName The effective policy to compute. See
* [Policy][google.cloud.orgpolicy.v2.Policy] for naming requirements. Please see
* {@see OrgPolicyClient::policyName()} for help formatting this field.
*/
function get_effective_policy_sample(string $formattedName): void
Expand Down
10 changes: 5 additions & 5 deletions OrgPolicy/samples/V2/OrgPolicyClient/get_policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
use Google\Cloud\OrgPolicy\V2\Policy;

/**
* Gets a `Policy` on a resource.
* Gets a policy on a resource.
*
* If no `Policy` is set on the resource, NOT_FOUND is returned. The
* 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.
* policy during read-modify-write.
*
* @param string $formattedName Resource name of the policy. See `Policy` for naming
* requirements. Please see
* @param string $formattedName Resource name of the policy. See
* [Policy][google.cloud.orgpolicy.v2.Policy] for naming requirements. Please see
* {@see OrgPolicyClient::policyName()} for help formatting this field.
*/
function get_policy_sample(string $formattedName): void
Expand Down
7 changes: 4 additions & 3 deletions OrgPolicy/samples/V2/OrgPolicyClient/list_constraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
use Google\Cloud\OrgPolicy\V2\ListConstraintsRequest;

/**
* Lists `Constraints` that could be applied on the specified resource.
* Lists constraints that could be applied on the specified resource.
*
* @param string $formattedParent The Google Cloud resource that parents the constraint. Must be in
* one of the following forms:
*
* @param string $formattedParent The Cloud resource that parents the constraint. Must be in one of
* the following forms:
* * `projects/{project_number}`
* * `projects/{project_id}`
* * `folders/{folder_id}`
Expand Down
Loading

0 comments on commit 9691ed5

Please sign in to comment.