Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
feat: add provisioned_resources_parent and kms_settings; add …
…common resource path helper methods
  • Loading branch information
yoshi-automation committed Nov 17, 2020
1 parent c1542b2 commit daaff1f
Show file tree
Hide file tree
Showing 9 changed files with 484 additions and 129 deletions.
1 change: 1 addition & 0 deletions docs/assuredworkloads_v1beta1/types.rst
Expand Up @@ -3,3 +3,4 @@ Types for Google Cloud Assuredworkloads v1beta1 API

.. automodule:: google.cloud.assuredworkloads_v1beta1.types
:members:
:show-inheritance:
Expand Up @@ -28,8 +28,8 @@
from google.auth import credentials # type: ignore
from google.oauth2 import service_account # type: ignore

from google.api_core import operation
from google.api_core import operation_async
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service import (
pagers,
)
Expand All @@ -55,9 +55,51 @@ class AssuredWorkloadsServiceAsyncClient:
AssuredWorkloadsServiceClient.parse_workload_path
)

common_billing_account_path = staticmethod(
AssuredWorkloadsServiceClient.common_billing_account_path
)
parse_common_billing_account_path = staticmethod(
AssuredWorkloadsServiceClient.parse_common_billing_account_path
)

common_folder_path = staticmethod(AssuredWorkloadsServiceClient.common_folder_path)
parse_common_folder_path = staticmethod(
AssuredWorkloadsServiceClient.parse_common_folder_path
)

common_organization_path = staticmethod(
AssuredWorkloadsServiceClient.common_organization_path
)
parse_common_organization_path = staticmethod(
AssuredWorkloadsServiceClient.parse_common_organization_path
)

common_project_path = staticmethod(
AssuredWorkloadsServiceClient.common_project_path
)
parse_common_project_path = staticmethod(
AssuredWorkloadsServiceClient.parse_common_project_path
)

common_location_path = staticmethod(
AssuredWorkloadsServiceClient.common_location_path
)
parse_common_location_path = staticmethod(
AssuredWorkloadsServiceClient.parse_common_location_path
)

from_service_account_file = AssuredWorkloadsServiceClient.from_service_account_file
from_service_account_json = from_service_account_file

@property
def transport(self) -> AssuredWorkloadsServiceTransport:
"""Return the transport used by the client instance.
Returns:
AssuredWorkloadsServiceTransport: The transport used by the client instance.
"""
return self._client.transport

get_transport_class = functools.partial(
type(AssuredWorkloadsServiceClient).get_transport_class,
type(AssuredWorkloadsServiceClient),
Expand Down Expand Up @@ -158,7 +200,8 @@ async def create_workload(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent, workload]):
has_flattened_params = any([parent, workload])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -251,7 +294,8 @@ async def update_workload(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([workload, update_mask]):
has_flattened_params = any([workload, update_mask])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -322,7 +366,8 @@ async def delete_workload(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -402,7 +447,8 @@ async def get_workload(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([name]):
has_flattened_params = any([name])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down Expand Up @@ -482,7 +528,8 @@ async def list_workloads(
# Create or coerce a protobuf request object.
# Sanity check: If we got a request object, we should *not* have
# gotten any keyword arguments that map to the request.
if request is not None and any([parent]):
has_flattened_params = any([parent])
if request is not None and has_flattened_params:
raise ValueError(
"If the `request` argument is set, then none of "
"the individual field arguments should be set."
Expand Down
Expand Up @@ -19,10 +19,10 @@
from distutils import util
import os
import re
from typing import Callable, Dict, Sequence, Tuple, Type, Union
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core import client_options as client_options_lib # type: ignore
from google.api_core import exceptions # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import retry as retries # type: ignore
Expand All @@ -32,8 +32,8 @@
from google.auth.exceptions import MutualTLSChannelError # type: ignore
from google.oauth2 import service_account # type: ignore

from google.api_core import operation
from google.api_core import operation_async
from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.assuredworkloads_v1beta1.services.assured_workloads_service import (
pagers,
)
Expand Down Expand Up @@ -138,6 +138,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):

from_service_account_json = from_service_account_file

@property
def transport(self) -> AssuredWorkloadsServiceTransport:
"""Return the transport used by the client instance.
Returns:
AssuredWorkloadsServiceTransport: The transport used by the client instance.
"""
return self._transport

@staticmethod
def workload_path(organization: str, location: str, workload: str,) -> str:
"""Return a fully-qualified workload string."""
Expand All @@ -154,12 +163,71 @@ def parse_workload_path(path: str) -> Dict[str, str]:
)
return m.groupdict() if m else {}

@staticmethod
def common_billing_account_path(billing_account: str,) -> str:
"""Return a fully-qualified billing_account string."""
return "billingAccounts/{billing_account}".format(
billing_account=billing_account,
)

@staticmethod
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
"""Parse a billing_account path into its component segments."""
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_folder_path(folder: str,) -> str:
"""Return a fully-qualified folder string."""
return "folders/{folder}".format(folder=folder,)

@staticmethod
def parse_common_folder_path(path: str) -> Dict[str, str]:
"""Parse a folder path into its component segments."""
m = re.match(r"^folders/(?P<folder>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_organization_path(organization: str,) -> str:
"""Return a fully-qualified organization string."""
return "organizations/{organization}".format(organization=organization,)

@staticmethod
def parse_common_organization_path(path: str) -> Dict[str, str]:
"""Parse a organization path into its component segments."""
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_project_path(project: str,) -> str:
"""Return a fully-qualified project string."""
return "projects/{project}".format(project=project,)

@staticmethod
def parse_common_project_path(path: str) -> Dict[str, str]:
"""Parse a project path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)$", path)
return m.groupdict() if m else {}

@staticmethod
def common_location_path(project: str, location: str,) -> str:
"""Return a fully-qualified location string."""
return "projects/{project}/locations/{location}".format(
project=project, location=location,
)

@staticmethod
def parse_common_location_path(path: str) -> Dict[str, str]:
"""Parse a location path into its component segments."""
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
return m.groupdict() if m else {}

def __init__(
self,
*,
credentials: credentials.Credentials = None,
transport: Union[str, AssuredWorkloadsServiceTransport] = None,
client_options: ClientOptions = None,
credentials: Optional[credentials.Credentials] = None,
transport: Union[str, AssuredWorkloadsServiceTransport, None] = None,
client_options: Optional[client_options_lib.ClientOptions] = None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the assured workloads service client.
Expand All @@ -173,8 +241,8 @@ def __init__(
transport (Union[str, ~.AssuredWorkloadsServiceTransport]): The
transport to use. If set to None, a transport is chosen
automatically.
client_options (ClientOptions): Custom options for the client. It
won't take effect if a ``transport`` instance is provided.
client_options (client_options_lib.ClientOptions): Custom options for the
client. It won't take effect if a ``transport`` instance is provided.
(1) The ``api_endpoint`` property can be used to override the
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
environment variable can also be used to override the endpoint:
Expand All @@ -189,20 +257,20 @@ def __init__(
not provided, the default SSL client certificate will be used if
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
set, no client certificate will be used.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
creation failed for any reason.
"""
if isinstance(client_options, dict):
client_options = ClientOptions.from_dict(client_options)
client_options = client_options_lib.from_dict(client_options)
if client_options is None:
client_options = ClientOptions.ClientOptions()
client_options = client_options_lib.ClientOptions()

# Create SSL credentials for mutual TLS if needed.
use_client_cert = bool(
Expand Down
Expand Up @@ -92,10 +92,10 @@ def __init__(
for grpc channel. It is ignored if ``channel`` is provided.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
Expand All @@ -104,13 +104,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -147,6 +150,7 @@ def __init__(
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand Down Expand Up @@ -224,12 +228,8 @@ def create_channel(

@property
def grpc_channel(self) -> grpc.Channel:
"""Create the channel designed to connect to this service.
This property caches on the instance; repeated calls return
the same channel.
"""Return the channel designed to connect to this service.
"""
# Return the channel from cache.
return self._grpc_channel

@property
Expand Down
Expand Up @@ -149,13 +149,16 @@ def __init__(
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._ssl_channel_credentials = ssl_channel_credentials

if channel:
# Sanity check: Ensure that channel and credentials are not both
# provided.
credentials = False

# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
elif api_mtls_endpoint:
warnings.warn(
"api_mtls_endpoint and client_cert_source are deprecated",
Expand Down Expand Up @@ -192,6 +195,7 @@ def __init__(
scopes=scopes or self.AUTH_SCOPES,
quota_project_id=quota_project_id,
)
self._ssl_channel_credentials = ssl_credentials
else:
host = host if ":" in host else host + ":443"

Expand Down
Expand Up @@ -180,8 +180,8 @@ class Workload(proto.Message):
the Workload. When present it must be between 4
to 30 characters. Allowed characters are:
lowercase and uppercase letters, numbers,
hyphen, single-quote, double-quote, space, and
exclamation point.
hyphen, and spaces.
Example: My Workload
resources (Sequence[~.assuredworkloads_v1beta1.Workload.ResourceInfo]):
Output only. The resources associated with
Expand Down Expand Up @@ -224,6 +224,18 @@ class Workload(proto.Message):
operations.
labels (Sequence[~.assuredworkloads_v1beta1.Workload.LabelsEntry]):
Optional. Labels applied to the workload.
provisioned_resources_parent (str):
Input only. The parent resource for the resources managed by
this Assured Workload. May be either an organization or a
folder. Must be the same or a child of the Workload parent.
If not specified all resources are created under the
Workload parent. Formats: folders/{folder_id}
organizations/{organization_id}
kms_settings (~.assuredworkloads_v1beta1.Workload.KMSSettings):
Input only. Settings used to create a CMEK
crypto key. When set a project with a KMS CMEK
key is provisioned. This field is mandatory for
a subset of Compliance Regimes.
"""

class ComplianceRegime(proto.Enum):
Expand Down Expand Up @@ -377,6 +389,10 @@ class FedrampModerateSettings(proto.Message):

labels = proto.MapField(proto.STRING, proto.STRING, number=10)

provisioned_resources_parent = proto.Field(proto.STRING, number=13)

kms_settings = proto.Field(proto.MESSAGE, number=14, message=KMSSettings,)


class CreateWorkloadOperationMetadata(proto.Message):
r"""Operation metadata to give request details of CreateWorkload.
Expand All @@ -402,7 +418,7 @@ class CreateWorkloadOperationMetadata(proto.Message):
parent = proto.Field(proto.STRING, number=3)

compliance_regime = proto.Field(
proto.ENUM, number=4, enum=Workload.ComplianceRegime,
proto.ENUM, number=4, enum="Workload.ComplianceRegime",
)


Expand Down

0 comments on commit daaff1f

Please sign in to comment.