Skip to content

Commit

Permalink
feat: Add branch rule APIs (#7754)
Browse files Browse the repository at this point in the history
feat: Add field `psc_allowed_projects` to message `.google.cloud.securesourcemanager.v1.Instance`
docs: A comment for field `instance` in message `.google.cloud.securesourcemanager.v1.Repository` is changed
PiperOrigin-RevId: 688170540
Source-Link: googleapis/googleapis@b6a9d80
Source-Link: googleapis/googleapis-gen@d9406c5
Copy-Tag: eyJwIjoiU2VjdXJlU291cmNlTWFuYWdlci8uT3dsQm90LnlhbWwiLCJoIjoiZDk0MDZjNWU4NDBkMWU4Mjg5MjMyY2EwODk4MjdiNzFjNzYwMWMwMCJ9
  • Loading branch information
gcf-owl-bot[bot] authored Oct 24, 2024
1 parent 12921fc commit be3a11c
Show file tree
Hide file tree
Showing 22 changed files with 2,912 additions and 31 deletions.
Binary file modified SecureSourceManager/metadata/V1/SecureSourceManager.php
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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 securesourcemanager_v1_generated_SecureSourceManager_CreateBranchRule_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\SecureSourceManager\V1\BranchRule;
use Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient;
use Google\Cloud\SecureSourceManager\V1\CreateBranchRuleRequest;
use Google\Rpc\Status;

/**
* CreateBranchRule creates a branch rule in a given repository.
*
* @param string $formattedParent Please see {@see SecureSourceManagerClient::repositoryName()} for help formatting this field.
* @param string $branchRuleId
*/
function create_branch_rule_sample(string $formattedParent, string $branchRuleId): void
{
// Create a client.
$secureSourceManagerClient = new SecureSourceManagerClient();

// Prepare the request message.
$branchRule = new BranchRule();
$request = (new CreateBranchRuleRequest())
->setParent($formattedParent)
->setBranchRule($branchRule)
->setBranchRuleId($branchRuleId);

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

if ($response->operationSucceeded()) {
/** @var BranchRule $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 = SecureSourceManagerClient::repositoryName(
'[PROJECT]',
'[LOCATION]',
'[REPOSITORY]'
);
$branchRuleId = '[BRANCH_RULE_ID]';

create_branch_rule_sample($formattedParent, $branchRuleId);
}
// [END securesourcemanager_v1_generated_SecureSourceManager_CreateBranchRule_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?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 securesourcemanager_v1_generated_SecureSourceManager_DeleteBranchRule_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient;
use Google\Cloud\SecureSourceManager\V1\DeleteBranchRuleRequest;
use Google\Rpc\Status;

/**
* DeleteBranchRule deletes a branch rule.
*
* @param string $formattedName Please see {@see SecureSourceManagerClient::branchRuleName()} for help formatting this field.
*/
function delete_branch_rule_sample(string $formattedName): void
{
// Create a client.
$secureSourceManagerClient = new SecureSourceManagerClient();

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

// Call the API and handle any network failures.
try {
/** @var OperationResponse $response */
$response = $secureSourceManagerClient->deleteBranchRule($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 = SecureSourceManagerClient::branchRuleName(
'[PROJECT]',
'[LOCATION]',
'[REPOSITORY]',
'[BRANCH_RULE]'
);

delete_branch_rule_sample($formattedName);
}
// [END securesourcemanager_v1_generated_SecureSourceManager_DeleteBranchRule_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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 securesourcemanager_v1_generated_SecureSourceManager_GetBranchRule_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\SecureSourceManager\V1\BranchRule;
use Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient;
use Google\Cloud\SecureSourceManager\V1\GetBranchRuleRequest;

/**
* GetBranchRule gets a branch rule.
*
* @param string $formattedName Name of the repository to retrieve.
* The format is
* `projects/{project}/locations/{location}/repositories/{repository}/branchRules/{branch_rule}`. Please see
* {@see SecureSourceManagerClient::branchRuleName()} for help formatting this field.
*/
function get_branch_rule_sample(string $formattedName): void
{
// Create a client.
$secureSourceManagerClient = new SecureSourceManagerClient();

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

// Call the API and handle any network failures.
try {
/** @var BranchRule $response */
$response = $secureSourceManagerClient->getBranchRule($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 = SecureSourceManagerClient::branchRuleName(
'[PROJECT]',
'[LOCATION]',
'[REPOSITORY]',
'[BRANCH_RULE]'
);

get_branch_rule_sample($formattedName);
}
// [END securesourcemanager_v1_generated_SecureSourceManager_GetBranchRule_sync]
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?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 securesourcemanager_v1_generated_SecureSourceManager_ListBranchRules_sync]
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\SecureSourceManager\V1\BranchRule;
use Google\Cloud\SecureSourceManager\V1\Client\SecureSourceManagerClient;
use Google\Cloud\SecureSourceManager\V1\ListBranchRulesRequest;

/**
* ListBranchRules lists branch rules in a given repository.
*
* @param string $formattedParent Please see {@see SecureSourceManagerClient::repositoryName()} for help formatting this field.
*/
function list_branch_rules_sample(string $formattedParent): void
{
// Create a client.
$secureSourceManagerClient = new SecureSourceManagerClient();

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

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

/** @var BranchRule $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 = SecureSourceManagerClient::repositoryName(
'[PROJECT]',
'[LOCATION]',
'[REPOSITORY]'
);

list_branch_rules_sample($formattedParent);
}
// [END securesourcemanager_v1_generated_SecureSourceManager_ListBranchRules_sync]
Loading

0 comments on commit be3a11c

Please sign in to comment.