Skip to content

Commit

Permalink
feat: added the MoveBillingAccount method, which allows changing whic…
Browse files Browse the repository at this point in the history
…h organization a billing account belongs to (googleapis#6845)

feat: added field BillingAccount.parent
build: do not use common_resources.proto for Billing v1 API

The change to BUILD.bazel should not affect any library users.
We will define Project and Organization resources in the Billing proto
instead of the common proto file.
PiperOrigin-RevId: 588132546
Source-Link: googleapis/googleapis@3ab9a05
Source-Link: https://github.com/googleapis/googleapis-gen/commit/6cdd705c1da9da4c30fe46194a0279ced722cc54
Copy-Tag: eyJwIjoiQmlsbGluZy8uT3dsQm90LnlhbWwiLCJoIjoiNmNkZDcwNWMxZGE5ZGE0YzMwZmU0NjE5NGEwMjc5Y2VkNzIyY2M1NCJ9
  • Loading branch information
gcf-owl-bot[bot] authored Dec 7, 2023
1 parent 67eb6c7 commit 73ea346
Show file tree
Hide file tree
Showing 15 changed files with 918 additions and 8 deletions.
Binary file modified Billing/metadata/V1/CloudBilling.php
Binary file not shown.
76 changes: 76 additions & 0 deletions Billing/samples/V1/CloudBillingClient/move_billing_account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?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 cloudbilling_v1_generated_CloudBilling_MoveBillingAccount_sync]
use Google\ApiCore\ApiException;
use Google\Cloud\Billing\V1\BillingAccount;
use Google\Cloud\Billing\V1\CloudBillingClient;

/**
* Changes which parent organization a billing account belongs to.
*
* @param string $formattedName The resource name of the billing account to move.
* Must be of the form `billingAccounts/{billing_account_id}`.
* The specified billing account cannot be a subaccount, since a subaccount
* always belongs to the same organization as its parent account. Please see
* {@see CloudBillingClient::billingAccountName()} for help formatting this field.
* @param string $formattedDestinationParent The resource name of the Organization to reparent
* the billing account under.
* Must be of the form `organizations/{organization_id}`. Please see
* {@see CloudBillingClient::organizationName()} for help formatting this field.
*/
function move_billing_account_sample(
string $formattedName,
string $formattedDestinationParent
): void {
// Create a client.
$cloudBillingClient = new CloudBillingClient();

// Call the API and handle any network failures.
try {
/** @var BillingAccount $response */
$response = $cloudBillingClient->moveBillingAccount($formattedName, $formattedDestinationParent);
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 = CloudBillingClient::billingAccountName('[BILLING_ACCOUNT]');
$formattedDestinationParent = CloudBillingClient::organizationName('[ORGANIZATION]');

move_billing_account_sample($formattedName, $formattedDestinationParent);
}
// [END cloudbilling_v1_generated_CloudBilling_MoveBillingAccount_sync]
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
* account, even if the charge occurred before the new billing account was
* assigned to the project.
*
* The current authenticated user must have ownership privileges for both the
* The current authenticated user must have ownership privileges for both
* the
* [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo
* ) and the [billing
* account](https://cloud.google.com/billing/docs/how-to/billing-access).
Expand Down
62 changes: 62 additions & 0 deletions Billing/src/V1/BillingAccount.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 62 additions & 1 deletion Billing/src/V1/Client/CloudBillingClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Google\Cloud\Billing\V1\GetProjectBillingInfoRequest;
use Google\Cloud\Billing\V1\ListBillingAccountsRequest;
use Google\Cloud\Billing\V1\ListProjectBillingInfoRequest;
use Google\Cloud\Billing\V1\MoveBillingAccountRequest;
use Google\Cloud\Billing\V1\ProjectBillingInfo;
use Google\Cloud\Billing\V1\UpdateBillingAccountRequest;
use Google\Cloud\Billing\V1\UpdateProjectBillingInfoRequest;
Expand Down Expand Up @@ -72,6 +73,7 @@
* @method PromiseInterface getProjectBillingInfoAsync(GetProjectBillingInfoRequest $request, array $optionalArgs = [])
* @method PromiseInterface listBillingAccountsAsync(ListBillingAccountsRequest $request, array $optionalArgs = [])
* @method PromiseInterface listProjectBillingInfoAsync(ListProjectBillingInfoRequest $request, array $optionalArgs = [])
* @method PromiseInterface moveBillingAccountAsync(MoveBillingAccountRequest $request, array $optionalArgs = [])
* @method PromiseInterface setIamPolicyAsync(SetIamPolicyRequest $request, array $optionalArgs = [])
* @method PromiseInterface testIamPermissionsAsync(TestIamPermissionsRequest $request, array $optionalArgs = [])
* @method PromiseInterface updateBillingAccountAsync(UpdateBillingAccountRequest $request, array $optionalArgs = [])
Expand Down Expand Up @@ -135,6 +137,38 @@ public static function billingAccountName(string $billingAccount): string
]);
}

/**
* 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(string $organization): string
{
return self::getPathTemplate('organization')->render([
'organization' => $organization,
]);
}

/**
* Formats a string containing the fully-qualified path to represent a
* organization_billing_account resource.
*
* @param string $organization
* @param string $billingAccount
*
* @return string The formatted organization_billing_account resource.
*/
public static function organizationBillingAccountName(string $organization, string $billingAccount): string
{
return self::getPathTemplate('organizationBillingAccount')->render([
'organization' => $organization,
'billing_account' => $billingAccount,
]);
}

/**
* Formats a string containing the fully-qualified path to represent a project
* resource.
Expand Down Expand Up @@ -170,6 +204,8 @@ public static function projectBillingInfoName(string $project): string
* The following name formats are supported:
* Template: Pattern
* - billingAccount: billingAccounts/{billing_account}
* - organization: organizations/{organization}
* - organizationBillingAccount: organizations/{organization}/billingAccounts/{billing_account}
* - project: projects/{project}
* - projectBillingInfo: projects/{project}/billingInfo
*
Expand Down Expand Up @@ -434,6 +470,30 @@ public function listProjectBillingInfo(ListProjectBillingInfoRequest $request, a
return $this->startApiCall('ListProjectBillingInfo', $request, $callOptions);
}

/**
* Changes which parent organization a billing account belongs to.
*
* The async variant is {@see CloudBillingClient::moveBillingAccountAsync()} .
*
* @param MoveBillingAccountRequest $request A request to house fields associated with the call.
* @param array $callOptions {
* 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 BillingAccount
*
* @throws ApiException Thrown if the API call fails.
*/
public function moveBillingAccount(MoveBillingAccountRequest $request, array $callOptions = []): BillingAccount
{
return $this->startApiCall('MoveBillingAccount', $request, $callOptions)->wait();
}

/**
* Sets the access control policy for a billing account. Replaces any existing
* policy.
Expand Down Expand Up @@ -531,7 +591,8 @@ public function updateBillingAccount(UpdateBillingAccountRequest $request, array
* account, even if the charge occurred before the new billing account was
* assigned to the project.
*
* The current authenticated user must have ownership privileges for both the
* The current authenticated user must have ownership privileges for both
* the
* [project](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo
* ) and the [billing
* account](https://cloud.google.com/billing/docs/how-to/billing-access).
Expand Down
77 changes: 77 additions & 0 deletions Billing/src/V1/CreateBillingAccountRequest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73ea346

Please sign in to comment.