Skip to content

Commit facc8ef

Browse files
feat: [google-cloud-billing] added the MoveBillingAccount method, which allows changing which organization a billing account belongs to (googleapis#12088)
- [ ] Regenerate this pull request now. BEGIN_COMMIT_OVERRIDE feat: added the MoveBillingAccount method, which allows changing which organization a billing account belongs to feat: added field BillingAccount.parent END_COMMIT_OVERRIDE 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: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWJpbGxpbmcvLk93bEJvdC55YW1sIiwiaCI6IjZjZGQ3MDVjMWRhOWRhNGMzMGZlNDYxOTRhMDI3OWNlZDcyMmNjNTQifQ== --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 558ad24 commit facc8ef

16 files changed

Lines changed: 1575 additions & 21 deletions

packages/google-cloud-billing/google/cloud/billing/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
ListBillingAccountsResponse,
3636
ListProjectBillingInfoRequest,
3737
ListProjectBillingInfoResponse,
38+
MoveBillingAccountRequest,
3839
ProjectBillingInfo,
3940
UpdateBillingAccountRequest,
4041
UpdateProjectBillingInfoRequest,
@@ -66,6 +67,7 @@
6667
"ListBillingAccountsResponse",
6768
"ListProjectBillingInfoRequest",
6869
"ListProjectBillingInfoResponse",
70+
"MoveBillingAccountRequest",
6971
"ProjectBillingInfo",
7072
"UpdateBillingAccountRequest",
7173
"UpdateProjectBillingInfoRequest",

packages/google-cloud-billing/google/cloud/billing_v1/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
ListBillingAccountsResponse,
3030
ListProjectBillingInfoRequest,
3131
ListProjectBillingInfoResponse,
32+
MoveBillingAccountRequest,
3233
ProjectBillingInfo,
3334
UpdateBillingAccountRequest,
3435
UpdateProjectBillingInfoRequest,
@@ -67,6 +68,7 @@
6768
"ListServicesResponse",
6869
"ListSkusRequest",
6970
"ListSkusResponse",
71+
"MoveBillingAccountRequest",
7072
"PricingExpression",
7173
"PricingInfo",
7274
"ProjectBillingInfo",

packages/google-cloud-billing/google/cloud/billing_v1/gapic_metadata.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
"list_project_billing_info"
4141
]
4242
},
43+
"MoveBillingAccount": {
44+
"methods": [
45+
"move_billing_account"
46+
]
47+
},
4348
"SetIamPolicy": {
4449
"methods": [
4550
"set_iam_policy"
@@ -95,6 +100,11 @@
95100
"list_project_billing_info"
96101
]
97102
},
103+
"MoveBillingAccount": {
104+
"methods": [
105+
"move_billing_account"
106+
]
107+
},
98108
"SetIamPolicy": {
99109
"methods": [
100110
"set_iam_policy"
@@ -150,6 +160,11 @@
150160
"list_project_billing_info"
151161
]
152162
},
163+
"MoveBillingAccount": {
164+
"methods": [
165+
"move_billing_account"
166+
]
167+
},
153168
"SetIamPolicy": {
154169
"methods": [
155170
"set_iam_policy"

packages/google-cloud-billing/google/cloud/billing_v1/services/cloud_billing/async_client.py

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ class CloudBillingAsyncClient:
6363
DEFAULT_ENDPOINT = CloudBillingClient.DEFAULT_ENDPOINT
6464
DEFAULT_MTLS_ENDPOINT = CloudBillingClient.DEFAULT_MTLS_ENDPOINT
6565

66+
billing_account_path = staticmethod(CloudBillingClient.billing_account_path)
67+
parse_billing_account_path = staticmethod(
68+
CloudBillingClient.parse_billing_account_path
69+
)
70+
organization_path = staticmethod(CloudBillingClient.organization_path)
71+
parse_organization_path = staticmethod(CloudBillingClient.parse_organization_path)
72+
project_path = staticmethod(CloudBillingClient.project_path)
73+
parse_project_path = staticmethod(CloudBillingClient.parse_project_path)
6674
project_billing_info_path = staticmethod(
6775
CloudBillingClient.project_billing_info_path
6876
)
@@ -339,6 +347,7 @@ async def list_billing_accounts(
339347
self,
340348
request: Optional[Union[cloud_billing.ListBillingAccountsRequest, dict]] = None,
341349
*,
350+
parent: Optional[str] = None,
342351
retry: OptionalRetry = gapic_v1.method.DEFAULT,
343352
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
344353
metadata: Sequence[Tuple[str, str]] = (),
@@ -376,6 +385,18 @@ async def sample_list_billing_accounts():
376385
Args:
377386
request (Optional[Union[google.cloud.billing_v1.types.ListBillingAccountsRequest, dict]]):
378387
The request object. Request message for ``ListBillingAccounts``.
388+
parent (:class:`str`):
389+
Optional. The parent resource to list billing accounts
390+
from. Format:
391+
392+
- ``organizations/{organization_id}``, for example,
393+
``organizations/12345678``
394+
- ``billingAccounts/{billing_account_id}``, for
395+
example, ``billingAccounts/012345-567890-ABCDEF``
396+
397+
This corresponds to the ``parent`` field
398+
on the ``request`` instance; if ``request`` is provided, this
399+
should not be set.
379400
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
380401
should be retried.
381402
timeout (float): The timeout for this request.
@@ -391,8 +412,22 @@ async def sample_list_billing_accounts():
391412
392413
"""
393414
# Create or coerce a protobuf request object.
415+
# Quick check: If we got a request object, we should *not* have
416+
# gotten any keyword arguments that map to the request.
417+
has_flattened_params = any([parent])
418+
if request is not None and has_flattened_params:
419+
raise ValueError(
420+
"If the `request` argument is set, then none of "
421+
"the individual field arguments should be set."
422+
)
423+
394424
request = cloud_billing.ListBillingAccountsRequest(request)
395425

426+
# If we have keyword arguments corresponding to fields on the
427+
# request, apply these.
428+
if parent is not None:
429+
request.parent = parent
430+
396431
# Wrap the RPC method; this adds retry and timeout information,
397432
# and friendly error handling.
398433
rpc = gapic_v1.method_async.wrap_method(
@@ -569,6 +604,7 @@ async def create_billing_account(
569604
] = None,
570605
*,
571606
billing_account: Optional[cloud_billing.BillingAccount] = None,
607+
parent: Optional[str] = None,
572608
retry: OptionalRetry = gapic_v1.method.DEFAULT,
573609
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
574610
metadata: Sequence[Tuple[str, str]] = (),
@@ -627,6 +663,18 @@ async def sample_create_billing_account():
627663
This corresponds to the ``billing_account`` field
628664
on the ``request`` instance; if ``request`` is provided, this
629665
should not be set.
666+
parent (:class:`str`):
667+
Optional. The parent to create a billing account from.
668+
Format:
669+
670+
- ``organizations/{organization_id}``, for example,
671+
``organizations/12345678``
672+
- ``billingAccounts/{billing_account_id}``, for
673+
example, ``billingAccounts/012345-567890-ABCDEF``
674+
675+
This corresponds to the ``parent`` field
676+
on the ``request`` instance; if ``request`` is provided, this
677+
should not be set.
630678
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
631679
should be retried.
632680
timeout (float): The timeout for this request.
@@ -644,7 +692,7 @@ async def sample_create_billing_account():
644692
# Create or coerce a protobuf request object.
645693
# Quick check: If we got a request object, we should *not* have
646694
# gotten any keyword arguments that map to the request.
647-
has_flattened_params = any([billing_account])
695+
has_flattened_params = any([billing_account, parent])
648696
if request is not None and has_flattened_params:
649697
raise ValueError(
650698
"If the `request` argument is set, then none of "
@@ -657,6 +705,8 @@ async def sample_create_billing_account():
657705
# request, apply these.
658706
if billing_account is not None:
659707
request.billing_account = billing_account
708+
if parent is not None:
709+
request.parent = parent
660710

661711
# Wrap the RPC method; this adds retry and timeout information,
662712
# and friendly error handling.
@@ -1519,6 +1569,89 @@ async def sample_test_iam_permissions():
15191569
# Done; return the response.
15201570
return response
15211571

1572+
async def move_billing_account(
1573+
self,
1574+
request: Optional[Union[cloud_billing.MoveBillingAccountRequest, dict]] = None,
1575+
*,
1576+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
1577+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1578+
metadata: Sequence[Tuple[str, str]] = (),
1579+
) -> cloud_billing.BillingAccount:
1580+
r"""Changes which parent organization a billing account
1581+
belongs to.
1582+
1583+
.. code-block:: python
1584+
1585+
# This snippet has been automatically generated and should be regarded as a
1586+
# code template only.
1587+
# It will require modifications to work:
1588+
# - It may require correct/in-range values for request initialization.
1589+
# - It may require specifying regional endpoints when creating the service
1590+
# client as shown in:
1591+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
1592+
from google.cloud import billing_v1
1593+
1594+
async def sample_move_billing_account():
1595+
# Create a client
1596+
client = billing_v1.CloudBillingAsyncClient()
1597+
1598+
# Initialize request argument(s)
1599+
request = billing_v1.MoveBillingAccountRequest(
1600+
name="name_value",
1601+
destination_parent="destination_parent_value",
1602+
)
1603+
1604+
# Make the request
1605+
response = await client.move_billing_account(request=request)
1606+
1607+
# Handle the response
1608+
print(response)
1609+
1610+
Args:
1611+
request (Optional[Union[google.cloud.billing_v1.types.MoveBillingAccountRequest, dict]]):
1612+
The request object. Request message for ``MoveBillingAccount`` RPC.
1613+
retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any,
1614+
should be retried.
1615+
timeout (float): The timeout for this request.
1616+
metadata (Sequence[Tuple[str, str]]): Strings which should be
1617+
sent along with the request as metadata.
1618+
1619+
Returns:
1620+
google.cloud.billing_v1.types.BillingAccount:
1621+
A billing account in the
1622+
[Google Cloud
1623+
Console](\ https://console.cloud.google.com/). You
1624+
can assign a billing account to one or more projects.
1625+
1626+
"""
1627+
# Create or coerce a protobuf request object.
1628+
request = cloud_billing.MoveBillingAccountRequest(request)
1629+
1630+
# Wrap the RPC method; this adds retry and timeout information,
1631+
# and friendly error handling.
1632+
rpc = gapic_v1.method_async.wrap_method(
1633+
self._client._transport.move_billing_account,
1634+
default_timeout=None,
1635+
client_info=DEFAULT_CLIENT_INFO,
1636+
)
1637+
1638+
# Certain fields should be provided within the metadata header;
1639+
# add these here.
1640+
metadata = tuple(metadata) + (
1641+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1642+
)
1643+
1644+
# Send the request.
1645+
response = await rpc(
1646+
request,
1647+
retry=retry,
1648+
timeout=timeout,
1649+
metadata=metadata,
1650+
)
1651+
1652+
# Done; return the response.
1653+
return response
1654+
15221655
async def __aenter__(self) -> "CloudBillingAsyncClient":
15231656
return self
15241657

0 commit comments

Comments
 (0)