Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [Deploy] added support for deploy policies #7528

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Deploy/metadata/V1/CloudDeploy.php
Binary file not shown.
96 changes: 96 additions & 0 deletions Deploy/samples/V1/CloudDeployClient/create_deploy_policy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/*
* Copyright 2024 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 clouddeploy_v1_generated_CloudDeploy_CreateDeployPolicy_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Deploy\V1\Client\CloudDeployClient;
use Google\Cloud\Deploy\V1\CreateDeployPolicyRequest;
use Google\Cloud\Deploy\V1\DeployPolicy;
use Google\Cloud\Deploy\V1\DeployPolicyResourceSelector;
use Google\Cloud\Deploy\V1\PolicyRule;
use Google\Rpc\Status;

/**
* Creates a new DeployPolicy in a given project and location.
*
* @param string $formattedParent The parent collection in which the `DeployPolicy` should be
* created. Format should be
* `projects/{project_id}/locations/{location_name}`. Please see
* {@see CloudDeployClient::locationName()} for help formatting this field.
* @param string $deployPolicyId ID of the `DeployPolicy`.
*/
function create_deploy_policy_sample(string $formattedParent, string $deployPolicyId): void
{
// Create a client.
$cloudDeployClient = new CloudDeployClient();

// Prepare the request message.
$deployPolicySelectors = [new DeployPolicyResourceSelector()];
$deployPolicyRules = [new PolicyRule()];
$deployPolicy = (new DeployPolicy())
->setSelectors($deployPolicySelectors)
->setRules($deployPolicyRules);
$request = (new CreateDeployPolicyRequest())
->setParent($formattedParent)
->setDeployPolicyId($deployPolicyId)
->setDeployPolicy($deployPolicy);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudDeployClient->createDeployPolicy($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
/** @var DeployPolicy $result */
$result = $response->getResult();
printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->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 = CloudDeployClient::locationName('[PROJECT]', '[LOCATION]');
$deployPolicyId = '[DEPLOY_POLICY_ID]';

create_deploy_policy_sample($formattedParent, $deployPolicyId);
}
// [END clouddeploy_v1_generated_CloudDeploy_CreateDeployPolicy_sync]
81 changes: 81 additions & 0 deletions Deploy/samples/V1/CloudDeployClient/delete_deploy_policy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php
/*
* Copyright 2024 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 clouddeploy_v1_generated_CloudDeploy_DeleteDeployPolicy_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Deploy\V1\Client\CloudDeployClient;
use Google\Cloud\Deploy\V1\DeleteDeployPolicyRequest;
use Google\Rpc\Status;

/**
* Deletes a single DeployPolicy.
*
* @param string $formattedName The name of the `DeployPolicy` to delete. Format should be
* `projects/{project_id}/locations/{location_name}/deployPolicies/{deploy_policy_name}`. Please see
* {@see CloudDeployClient::deployPolicyName()} for help formatting this field.
*/
function delete_deploy_policy_sample(string $formattedName): void
{
// Create a client.
$cloudDeployClient = new CloudDeployClient();

// Prepare the request message.
$request = (new DeleteDeployPolicyRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $cloudDeployClient->deleteDeployPolicy($request);
$response->pollUntilComplete();

if ($response->operationSucceeded()) {
printf('Operation completed successfully.' . PHP_EOL);
} else {
/** @var Status $error */
$error = $response->getError();
printf('Operation failed with error data: %s' . PHP_EOL, $error->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 = CloudDeployClient::deployPolicyName('[PROJECT]', '[LOCATION]', '[DEPLOY_POLICY]');

delete_deploy_policy_sample($formattedName);
}
// [END clouddeploy_v1_generated_CloudDeploy_DeleteDeployPolicy_sync]
72 changes: 72 additions & 0 deletions Deploy/samples/V1/CloudDeployClient/get_deploy_policy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/*
* Copyright 2024 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 clouddeploy_v1_generated_CloudDeploy_GetDeployPolicy_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Deploy\V1\Client\CloudDeployClient;
use Google\Cloud\Deploy\V1\DeployPolicy;
use Google\Cloud\Deploy\V1\GetDeployPolicyRequest;

/**
* Gets details of a single DeployPolicy.
*
* @param string $formattedName Name of the `DeployPolicy`. Format must be
* `projects/{project_id}/locations/{location_name}/deployPolicies/{deploy_policy_name}`. Please see
* {@see CloudDeployClient::deployPolicyName()} for help formatting this field.
*/
function get_deploy_policy_sample(string $formattedName): void
{
// Create a client.
$cloudDeployClient = new CloudDeployClient();

// Prepare the request message.
$request = (new GetDeployPolicyRequest())
->setName($formattedName);

// Call the API and handle any network failures.
try {
/** @var DeployPolicy $response */
$response = $cloudDeployClient->getDeployPolicy($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 = CloudDeployClient::deployPolicyName('[PROJECT]', '[LOCATION]', '[DEPLOY_POLICY]');

get_deploy_policy_sample($formattedName);
}
// [END clouddeploy_v1_generated_CloudDeploy_GetDeployPolicy_sync]
77 changes: 77 additions & 0 deletions Deploy/samples/V1/CloudDeployClient/list_deploy_policies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/*
* Copyright 2024 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 clouddeploy_v1_generated_CloudDeploy_ListDeployPolicies_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Deploy\V1\Client\CloudDeployClient;
use Google\Cloud\Deploy\V1\DeployPolicy;
use Google\Cloud\Deploy\V1\ListDeployPoliciesRequest;

/**
* Lists DeployPolicies in a given project and location.
*
* @param string $formattedParent The parent, which owns this collection of deploy policies. Format
* must be `projects/{project_id}/locations/{location_name}`. Please see
* {@see CloudDeployClient::locationName()} for help formatting this field.
*/
function list_deploy_policies_sample(string $formattedParent): void
{
// Create a client.
$cloudDeployClient = new CloudDeployClient();

// Prepare the request message.
$request = (new ListDeployPoliciesRequest())
->setParent($formattedParent);

// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $cloudDeployClient->listDeployPolicies($request);

/** @var DeployPolicy $element */
foreach ($response as $element) {
printf('Element data: %s' . PHP_EOL, $element->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 = CloudDeployClient::locationName('[PROJECT]', '[LOCATION]');

list_deploy_policies_sample($formattedParent);
}
// [END clouddeploy_v1_generated_CloudDeploy_ListDeployPolicies_sync]
Loading
Loading