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

Commit fa7d695

Browse files
feat: added support for CMEK (#188)
- [ ] Regenerate this pull request now. docs: clarified wording around quota usage Clients can now specify the docker registry to use for storing function Docker images and KMS crypto keys for function source code objects. PiperOrigin-RevId: 453234231 Source-Link: googleapis/googleapis@d180952 Source-Link: https://github.com/googleapis/googleapis-gen/commit/836ff24b7e881ef46acd17836c46ed1a9832b195 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODM2ZmYyNGI3ZTg4MWVmNDZhY2QxNzgzNmM0NmVkMWE5ODMyYjE5NSJ9
1 parent ecd0fff commit fa7d695

File tree

5 files changed

+68
-16
lines changed

5 files changed

+68
-16
lines changed

google/cloud/functions_v1/services/cloud_functions_service/async_client.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ async def sample_get_function():
375375
contains user computation executed in
376376
response to an event. It encapsulate
377377
function and triggers configurations.
378-
Next tag: 36
379378
380379
"""
381380
# Create or coerce a protobuf request object.
@@ -500,7 +499,7 @@ async def sample_create_function():
500499
501500
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
502501
response to an event. It encapsulate function and
503-
triggers configurations. Next tag: 36
502+
triggers configurations.
504503
505504
"""
506505
# Create or coerce a protobuf request object.
@@ -615,7 +614,7 @@ async def sample_update_function():
615614
616615
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
617616
response to an event. It encapsulate function and
618-
triggers configurations. Next tag: 36
617+
triggers configurations.
619618
620619
"""
621620
# Create or coerce a protobuf request object.

google/cloud/functions_v1/services/cloud_functions_service/client.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ def sample_get_function():
625625
contains user computation executed in
626626
response to an event. It encapsulate
627627
function and triggers configurations.
628-
Next tag: 36
629628
630629
"""
631630
# Create or coerce a protobuf request object.
@@ -740,7 +739,7 @@ def sample_create_function():
740739
741740
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
742741
response to an event. It encapsulate function and
743-
triggers configurations. Next tag: 36
742+
triggers configurations.
744743
745744
"""
746745
# Create or coerce a protobuf request object.
@@ -855,7 +854,7 @@ def sample_update_function():
855854
856855
The result type for the operation will be :class:`google.cloud.functions_v1.types.CloudFunction` Describes a Cloud Function that contains user computation executed in
857856
response to an event. It encapsulate function and
858-
triggers configurations. Next tag: 36
857+
triggers configurations.
859858
860859
"""
861860
# Create or coerce a protobuf request object.

google/cloud/functions_v1/types/functions.py

+53-9
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CloudFunctionStatus(proto.Enum):
5858
class CloudFunction(proto.Message):
5959
r"""Describes a Cloud Function that contains user computation
6060
executed in response to an event. It encapsulate function and
61-
triggers configurations. Next tag: 36
61+
triggers configurations.
6262
6363
This message has `oneof`_ fields (mutually exclusive fields).
6464
For each oneof, at most one member field can be set at the same time.
@@ -212,8 +212,10 @@ class CloudFunction(proto.Message):
212212
repository using the ``docker_repository`` field that was
213213
created with the same KMS crypto key.
214214
215-
The following service accounts need to be granted Cloud KMS
216-
crypto key encrypter/decrypter roles on the key.
215+
The following service accounts need to be granted the role
216+
'Cloud KMS CryptoKey Encrypter/Decrypter
217+
(roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the
218+
Key/KeyRing/Project/Organization (least access preferred).
217219
218220
1. Google Cloud Functions service account
219221
(service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com)
@@ -275,6 +277,14 @@ class CloudFunction(proto.Message):
275277
Cross-project repositories are not supported. Cross-location
276278
repositories are not supported. Repository format must be
277279
'DOCKER'.
280+
docker_registry (google.cloud.functions_v1.types.CloudFunction.DockerRegistry):
281+
Docker Registry to use for this deployment.
282+
283+
If ``docker_repository`` field is specified, this field will
284+
be automatically set as ``ARTIFACT_REGISTRY``. If
285+
unspecified, it currently defaults to
286+
``CONTAINER_REGISTRY``. This field may be overridden by the
287+
backend for eligible deployments.
278288
"""
279289

280290
class VpcConnectorEgressSettings(proto.Enum):
@@ -299,6 +309,12 @@ class IngressSettings(proto.Enum):
299309
ALLOW_INTERNAL_ONLY = 2
300310
ALLOW_INTERNAL_AND_GCLB = 3
301311

312+
class DockerRegistry(proto.Enum):
313+
r"""Docker Registry to use for storing function Docker images."""
314+
DOCKER_REGISTRY_UNSPECIFIED = 0
315+
CONTAINER_REGISTRY = 1
316+
ARTIFACT_REGISTRY = 2
317+
302318
name = proto.Field(
303319
proto.STRING,
304320
number=1,
@@ -445,6 +461,11 @@ class IngressSettings(proto.Enum):
445461
proto.STRING,
446462
number=34,
447463
)
464+
docker_registry = proto.Field(
465+
proto.ENUM,
466+
number=35,
467+
enum=DockerRegistry,
468+
)
448469

449470

450471
class SourceRepository(proto.Message):
@@ -626,9 +647,7 @@ class Retry(proto.Message):
626647
class SecretEnvVar(proto.Message):
627648
r"""Configuration for a secret environment variable. It has the
628649
information necessary to fetch the secret value from secret
629-
manager and expose it as an environment variable. Secret value
630-
is not a part of the configuration. Secret values are only
631-
fetched when a new clone starts.
650+
manager and expose it as an environment variable.
632651
633652
Attributes:
634653
key (str):
@@ -648,7 +667,7 @@ class SecretEnvVar(proto.Message):
648667
string 'latest'). It is recommended to use a
649668
numeric version for secret environment variables
650669
as any updates to the secret value is not
651-
reflected until new clones start.
670+
reflected until new instances start.
652671
"""
653672

654673
key = proto.Field(
@@ -779,8 +798,8 @@ class UpdateFunctionRequest(proto.Message):
779798
function (google.cloud.functions_v1.types.CloudFunction):
780799
Required. New version of the function.
781800
update_mask (google.protobuf.field_mask_pb2.FieldMask):
782-
Required list of fields to be updated in this
783-
request.
801+
Required. The list of fields in ``CloudFunction`` that have
802+
to be updated.
784803
"""
785804

786805
function = proto.Field(
@@ -956,12 +975,37 @@ class GenerateUploadUrlRequest(proto.Message):
956975
The project and location in which the Google Cloud Storage
957976
signed URL should be generated, specified in the format
958977
``projects/*/locations/*``.
978+
kms_key_name (str):
979+
Resource name of a KMS crypto key (managed by the user) used
980+
to encrypt/decrypt function source code objects in staging
981+
Cloud Storage buckets. When you generate an upload url and
982+
upload your source code, it gets copied to a staging Cloud
983+
Storage bucket in an internal regional project. The source
984+
code is then copied to a versioned directory in the sources
985+
bucket in the consumer project during the function
986+
deployment.
987+
988+
It must match the pattern
989+
``projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}``.
990+
991+
The Google Cloud Functions service account
992+
(service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com)
993+
must be granted the role 'Cloud KMS CryptoKey
994+
Encrypter/Decrypter
995+
(roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the
996+
Key/KeyRing/Project/Organization (least access preferred).
997+
GCF will delegate access to the Google Storage service
998+
account in the internal project.
959999
"""
9601000

9611001
parent = proto.Field(
9621002
proto.STRING,
9631003
number=1,
9641004
)
1005+
kms_key_name = proto.Field(
1006+
proto.STRING,
1007+
number=2,
1008+
)
9651009

9661010

9671011
class GenerateUploadUrlResponse(proto.Message):

scripts/fixup_functions_v1_keywords.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class functionsCallTransformer(cst.CSTTransformer):
4343
'create_function': ('location', 'function', ),
4444
'delete_function': ('name', ),
4545
'generate_download_url': ('name', 'version_id', ),
46-
'generate_upload_url': ('parent', ),
46+
'generate_upload_url': ('parent', 'kms_key_name', ),
4747
'get_function': ('name', ),
4848
'get_iam_policy': ('resource', 'options', ),
4949
'list_functions': ('parent', 'page_size', 'page_token', ),

tests/unit/gapic/functions_v1/test_cloud_functions_service.py

+10
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@ def test_get_function(request_type, transport: str = "grpc"):
10731073
build_name="build_name_value",
10741074
source_token="source_token_value",
10751075
docker_repository="docker_repository_value",
1076+
docker_registry=functions.CloudFunction.DockerRegistry.CONTAINER_REGISTRY,
10761077
source_archive_url="source_archive_url_value",
10771078
https_trigger=functions.HttpsTrigger(url="url_value"),
10781079
)
@@ -1110,6 +1111,10 @@ def test_get_function(request_type, transport: str = "grpc"):
11101111
assert response.build_name == "build_name_value"
11111112
assert response.source_token == "source_token_value"
11121113
assert response.docker_repository == "docker_repository_value"
1114+
assert (
1115+
response.docker_registry
1116+
== functions.CloudFunction.DockerRegistry.CONTAINER_REGISTRY
1117+
)
11131118

11141119

11151120
def test_get_function_empty_call():
@@ -1166,6 +1171,7 @@ async def test_get_function_async(
11661171
build_name="build_name_value",
11671172
source_token="source_token_value",
11681173
docker_repository="docker_repository_value",
1174+
docker_registry=functions.CloudFunction.DockerRegistry.CONTAINER_REGISTRY,
11691175
)
11701176
)
11711177
response = await client.get_function(request)
@@ -1202,6 +1208,10 @@ async def test_get_function_async(
12021208
assert response.build_name == "build_name_value"
12031209
assert response.source_token == "source_token_value"
12041210
assert response.docker_repository == "docker_repository_value"
1211+
assert (
1212+
response.docker_registry
1213+
== functions.CloudFunction.DockerRegistry.CONTAINER_REGISTRY
1214+
)
12051215

12061216

12071217
@pytest.mark.asyncio

0 commit comments

Comments
 (0)