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

Commit af189a0

Browse files
feat: add available_cpu field (#255)
* feat: add `available_cpu ` field feat: add `kms_key_name` field to ServiceConfig (the CMEK use case) feat: add `max_instance_request_concurrency` field feat: add `security_level` field PiperOrigin-RevId: 516979219 Source-Link: googleapis/googleapis@650f7cd Source-Link: https://github.com/googleapis/googleapis-gen/commit/3c4d23fd766eddb2c726b40d23ef012974a3251f Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiM2M0ZDIzZmQ3NjZlZGRiMmM3MjZiNDBkMjNlZjAxMjk3NGEzMjUxZiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 18152f1 commit af189a0

File tree

5 files changed

+285
-56
lines changed

5 files changed

+285
-56
lines changed

google/cloud/functions_v2/services/function_service/async_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class FunctionServiceAsyncClient:
8080
parse_channel_path = staticmethod(FunctionServiceClient.parse_channel_path)
8181
connector_path = staticmethod(FunctionServiceClient.connector_path)
8282
parse_connector_path = staticmethod(FunctionServiceClient.parse_connector_path)
83+
crypto_key_path = staticmethod(FunctionServiceClient.crypto_key_path)
84+
parse_crypto_key_path = staticmethod(FunctionServiceClient.parse_crypto_key_path)
8385
function_path = staticmethod(FunctionServiceClient.function_path)
8486
parse_function_path = staticmethod(FunctionServiceClient.parse_function_path)
8587
repository_path = staticmethod(FunctionServiceClient.repository_path)

google/cloud/functions_v2/services/function_service/client.py

+24
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,30 @@ def parse_connector_path(path: str) -> Dict[str, str]:
259259
)
260260
return m.groupdict() if m else {}
261261

262+
@staticmethod
263+
def crypto_key_path(
264+
project: str,
265+
location: str,
266+
key_ring: str,
267+
crypto_key: str,
268+
) -> str:
269+
"""Returns a fully-qualified crypto_key string."""
270+
return "projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}".format(
271+
project=project,
272+
location=location,
273+
key_ring=key_ring,
274+
crypto_key=crypto_key,
275+
)
276+
277+
@staticmethod
278+
def parse_crypto_key_path(path: str) -> Dict[str, str]:
279+
"""Parses a crypto_key path into its component segments."""
280+
m = re.match(
281+
r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)/keyRings/(?P<key_ring>.+?)/cryptoKeys/(?P<crypto_key>.+?)$",
282+
path,
283+
)
284+
return m.groupdict() if m else {}
285+
262286
@staticmethod
263287
def function_path(
264288
project: str,

google/cloud/functions_v2/types/functions.py

+146-10
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ class Function(proto.Message):
8383
unique globally and match pattern
8484
``projects/*/locations/*/functions/*``
8585
environment (google.cloud.functions_v2.types.Environment):
86-
Describe whether the function is gen1 or
87-
gen2.
86+
Describe whether the function is 1st Gen or
87+
2nd Gen.
8888
description (str):
8989
User-provided description of a function.
9090
build_config (google.cloud.functions_v2.types.BuildConfig):
@@ -108,6 +108,15 @@ class Function(proto.Message):
108108
state_messages (MutableSequence[google.cloud.functions_v2.types.StateMessage]):
109109
Output only. State Messages for this Cloud
110110
Function.
111+
kms_key_name (str):
112+
Resource name of a KMS crypto key (managed by the user) used
113+
to encrypt/decrypt function resources.
114+
115+
It must match the pattern
116+
``projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}``.
117+
url (str):
118+
Output only. The deployed url for the
119+
function.
111120
"""
112121

113122
class State(proto.Enum):
@@ -187,6 +196,14 @@ class State(proto.Enum):
187196
number=9,
188197
message="StateMessage",
189198
)
199+
kms_key_name: str = proto.Field(
200+
proto.STRING,
201+
number=25,
202+
)
203+
url: str = proto.Field(
204+
proto.STRING,
205+
number=14,
206+
)
190207

191208

192209
class StateMessage(proto.Message):
@@ -455,13 +472,23 @@ class BuildConfig(proto.Message):
455472
environment_variables (MutableMapping[str, str]):
456473
User-provided build-time environment
457474
variables for the function
475+
docker_registry (google.cloud.functions_v2.types.BuildConfig.DockerRegistry):
476+
Optional. Docker Registry to use for this deployment. This
477+
configuration is only applicable to 1st Gen functions, 2nd
478+
Gen functions can only use Artifact Registry.
479+
480+
If ``docker_repository`` field is specified, this field will
481+
be automatically set as ``ARTIFACT_REGISTRY``. If
482+
unspecified, it currently defaults to
483+
``CONTAINER_REGISTRY``. This field may be overridden by the
484+
backend for eligible deployments.
458485
docker_repository (str):
459-
Optional. User managed repository created in Artifact
460-
Registry optionally with a customer managed encryption key.
461-
This is the repository to which the function docker image
462-
will be pushed after it is built by Cloud Build. If
463-
unspecified, GCF will create and use a repository named
464-
'gcf-artifacts' for every deployed region.
486+
User managed repository created in Artifact Registry
487+
optionally with a customer managed encryption key. This is
488+
the repository to which the function docker image will be
489+
pushed after it is built by Cloud Build. If unspecified, GCF
490+
will create and use a repository named 'gcf-artifacts' for
491+
every deployed region.
465492
466493
It must match the pattern
467494
``projects/{project}/locations/{location}/repositories/{repository}``.
@@ -471,6 +498,27 @@ class BuildConfig(proto.Message):
471498
'DOCKER'.
472499
"""
473500

501+
class DockerRegistry(proto.Enum):
502+
r"""Docker Registry to use for storing function Docker images.
503+
504+
Values:
505+
DOCKER_REGISTRY_UNSPECIFIED (0):
506+
Unspecified.
507+
CONTAINER_REGISTRY (1):
508+
Docker images will be stored in multi-regional Container
509+
Registry repositories named ``gcf``.
510+
ARTIFACT_REGISTRY (2):
511+
Docker images will be stored in regional Artifact Registry
512+
repositories. By default, GCF will create and use
513+
repositories named ``gcf-artifacts`` in every region in
514+
which a function is deployed. But the repository to use can
515+
also be specified by the user using the
516+
``docker_repository`` field.
517+
"""
518+
DOCKER_REGISTRY_UNSPECIFIED = 0
519+
CONTAINER_REGISTRY = 1
520+
ARTIFACT_REGISTRY = 2
521+
474522
build: str = proto.Field(
475523
proto.STRING,
476524
number=1,
@@ -502,6 +550,11 @@ class BuildConfig(proto.Message):
502550
proto.STRING,
503551
number=6,
504552
)
553+
docker_registry: DockerRegistry = proto.Field(
554+
proto.ENUM,
555+
number=10,
556+
enum=DockerRegistry,
557+
)
505558
docker_repository: str = proto.Field(
506559
proto.STRING,
507560
number=7,
@@ -511,6 +564,7 @@ class BuildConfig(proto.Message):
511564
class ServiceConfig(proto.Message):
512565
r"""Describes the Service being deployed.
513566
Currently Supported : Cloud Run (fully managed).
567+
Next tag: 23
514568
515569
Attributes:
516570
service (str):
@@ -530,6 +584,13 @@ class ServiceConfig(proto.Message):
530584
See
531585
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go
532586
a full description.
587+
available_cpu (str):
588+
The number of CPUs used in a single container
589+
instance. Default value is calculated from
590+
available memory. Supports the same values as
591+
Cloud Run, see
592+
https://cloud.google.com/run/docs/reference/rest/v1/Container#resourcerequirements
593+
Example: "1" indicates 1 vCPU
533594
environment_variables (MutableMapping[str, str]):
534595
Environment variables that shall be available
535596
during function execution.
@@ -590,6 +651,16 @@ class ServiceConfig(proto.Message):
590651
Secret volumes configuration.
591652
revision (str):
592653
Output only. The name of service revision.
654+
max_instance_request_concurrency (int):
655+
Sets the maximum number of concurrent
656+
requests that each instance can receive.
657+
Defaults to 1.
658+
security_level (google.cloud.functions_v2.types.ServiceConfig.SecurityLevel):
659+
Security level configure whether the function
660+
only accepts https. This configuration is only
661+
applicable to 1st Gen functions with Http
662+
trigger. By default https is optional for 1st
663+
Gen functions; 2nd Gen functions are https ONLY.
593664
"""
594665

595666
class VpcConnectorEgressSettings(proto.Enum):
@@ -637,6 +708,33 @@ class IngressSettings(proto.Enum):
637708
ALLOW_INTERNAL_ONLY = 2
638709
ALLOW_INTERNAL_AND_GCLB = 3
639710

711+
class SecurityLevel(proto.Enum):
712+
r"""Available security level settings.
713+
714+
This enforces security protocol on function URL.
715+
716+
Security level is only ocnfigurable for 1st Gen functions, If
717+
unspecified, SECURE_OPTIONAL will be used. 2nd Gen functions are
718+
SECURE_ALWAYS ONLY.
719+
720+
Values:
721+
SECURITY_LEVEL_UNSPECIFIED (0):
722+
Unspecified.
723+
SECURE_ALWAYS (1):
724+
Requests for a URL that match this handler
725+
that do not use HTTPS are automatically
726+
redirected to the HTTPS URL with the same path.
727+
Query parameters are reserved for the redirect.
728+
SECURE_OPTIONAL (2):
729+
Both HTTP and HTTPS requests with URLs that
730+
match the handler succeed without redirects. The
731+
application can examine the request to determine
732+
which protocol was used and respond accordingly.
733+
"""
734+
SECURITY_LEVEL_UNSPECIFIED = 0
735+
SECURE_ALWAYS = 1
736+
SECURE_OPTIONAL = 2
737+
640738
service: str = proto.Field(
641739
proto.STRING,
642740
number=1,
@@ -649,6 +747,10 @@ class IngressSettings(proto.Enum):
649747
proto.STRING,
650748
number=13,
651749
)
750+
available_cpu: str = proto.Field(
751+
proto.STRING,
752+
number=22,
753+
)
652754
environment_variables: MutableMapping[str, str] = proto.MapField(
653755
proto.STRING,
654756
proto.STRING,
@@ -702,6 +804,15 @@ class IngressSettings(proto.Enum):
702804
proto.STRING,
703805
number=18,
704806
)
807+
max_instance_request_concurrency: int = proto.Field(
808+
proto.INT32,
809+
number=20,
810+
)
811+
security_level: SecurityLevel = proto.Field(
812+
proto.ENUM,
813+
number=21,
814+
enum=SecurityLevel,
815+
)
705816

706817

707818
class SecretEnvVar(proto.Message):
@@ -981,8 +1092,11 @@ class ListFunctionsRequest(proto.Message):
9811092
reachable locations along with the names of any unreachable
9821093
locations.
9831094
page_size (int):
984-
Maximum number of functions to return per
985-
call.
1095+
Maximum number of functions to return per call. The largest
1096+
allowed page_size is 1,000, if the page_size is omitted or
1097+
specified as greater than 1,000 then it will be replaced as
1098+
1,000. The size of the list response can be less than
1099+
specified when used with filters.
9861100
page_token (str):
9871101
The value returned by the last ``ListFunctionsResponse``;
9881102
indicates that this is a continuation of a prior
@@ -1136,12 +1250,34 @@ class GenerateUploadUrlRequest(proto.Message):
11361250
Required. The project and location in which the Google Cloud
11371251
Storage signed URL should be generated, specified in the
11381252
format ``projects/*/locations/*``.
1253+
kms_key_name (str):
1254+
Resource name of a KMS crypto key (managed by the user) used
1255+
to encrypt/decrypt function source code objects in
1256+
intermediate Cloud Storage buckets. When you generate an
1257+
upload url and upload your source code, it gets copied to an
1258+
intermediate Cloud Storage bucket. The source code is then
1259+
copied to a versioned directory in the sources bucket in the
1260+
consumer project during the function deployment.
1261+
1262+
It must match the pattern
1263+
``projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}``.
1264+
1265+
The Google Cloud Functions service account
1266+
(service-{project_number}@gcf-admin-robot.iam.gserviceaccount.com)
1267+
must be granted the role 'Cloud KMS CryptoKey
1268+
Encrypter/Decrypter
1269+
(roles/cloudkms.cryptoKeyEncrypterDecrypter)' on the
1270+
Key/KeyRing/Project/Organization (least access preferred).
11391271
"""
11401272

11411273
parent: str = proto.Field(
11421274
proto.STRING,
11431275
number=1,
11441276
)
1277+
kms_key_name: str = proto.Field(
1278+
proto.STRING,
1279+
number=2,
1280+
)
11451281

11461282

11471283
class GenerateUploadUrlResponse(proto.Message):

scripts/fixup_functions_v2_keywords.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class functionsCallTransformer(cst.CSTTransformer):
4242
'create_function': ('parent', 'function', 'function_id', ),
4343
'delete_function': ('name', ),
4444
'generate_download_url': ('name', ),
45-
'generate_upload_url': ('parent', ),
45+
'generate_upload_url': ('parent', 'kms_key_name', ),
4646
'get_function': ('name', ),
4747
'list_functions': ('parent', 'page_size', 'page_token', 'filter', 'order_by', ),
4848
'list_runtimes': ('parent', 'filter', ),

0 commit comments

Comments
 (0)