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

Commit ea38aad

Browse files
feat: ListFunctions now include metadata which indicates whether a function is a GEN_1 or GEN_2 function (#263)
* feat: ListFunctions now include metadata which indicates whether a function is a `GEN_1` or `GEN_2` function PiperOrigin-RevId: 535193873 Source-Link: googleapis/googleapis@d6b7eb5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/822ccd09cc1e9f8a4ab0125cc93effe26ab882c1 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODIyY2NkMDljYzFlOWY4YTRhYjAxMjVjYzkzZWZmZTI2YWI4ODJjMSJ9 * 🦉 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 17b7a5b commit ea38aad

File tree

4 files changed

+67
-49
lines changed

4 files changed

+67
-49
lines changed

‎google/cloud/functions_v2/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
ListFunctionsResponse,
3737
ListRuntimesRequest,
3838
ListRuntimesResponse,
39+
LocationMetadata,
3940
OperationMetadata,
4041
RepoSource,
4142
SecretEnvVar,
@@ -68,6 +69,7 @@
6869
"ListFunctionsResponse",
6970
"ListRuntimesRequest",
7071
"ListRuntimesResponse",
72+
"LocationMetadata",
7173
"OperationMetadata",
7274
"RepoSource",
7375
"SecretEnvVar",

‎google/cloud/functions_v2/types/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
ListFunctionsResponse,
3131
ListRuntimesRequest,
3232
ListRuntimesResponse,
33+
LocationMetadata,
3334
OperationMetadata,
3435
RepoSource,
3536
SecretEnvVar,
@@ -59,6 +60,7 @@
5960
"ListFunctionsResponse",
6061
"ListRuntimesRequest",
6162
"ListRuntimesResponse",
63+
"LocationMetadata",
6264
"OperationMetadata",
6365
"RepoSource",
6466
"SecretEnvVar",

‎google/cloud/functions_v2/types/functions.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"ListRuntimesRequest",
5252
"ListRuntimesResponse",
5353
"OperationMetadata",
54+
"LocationMetadata",
5455
"Stage",
5556
},
5657
)
@@ -82,9 +83,6 @@ class Function(proto.Message):
8283
A user-defined name of the function. Function names must be
8384
unique globally and match pattern
8485
``projects/*/locations/*/functions/*``
85-
environment (google.cloud.functions_v2.types.Environment):
86-
Describe whether the function is 1st Gen or
87-
2nd Gen.
8886
description (str):
8987
User-provided description of a function.
9088
build_config (google.cloud.functions_v2.types.BuildConfig):
@@ -108,15 +106,18 @@ class Function(proto.Message):
108106
state_messages (MutableSequence[google.cloud.functions_v2.types.StateMessage]):
109107
Output only. State Messages for this Cloud
110108
Function.
109+
environment (google.cloud.functions_v2.types.Environment):
110+
Describe whether the function is 1st Gen or
111+
2nd Gen.
112+
url (str):
113+
Output only. The deployed url for the
114+
function.
111115
kms_key_name (str):
112-
Resource name of a KMS crypto key (managed by the user) used
113-
to encrypt/decrypt function resources.
116+
[Preview] Resource name of a KMS crypto key (managed by the
117+
user) used to encrypt/decrypt function resources.
114118
115119
It must match the pattern
116120
``projects/{project}/locations/{location}/keyRings/{key_ring}/cryptoKeys/{crypto_key}``.
117-
url (str):
118-
Output only. The deployed url for the
119-
function.
120121
"""
121122

122123
class State(proto.Enum):
@@ -152,11 +153,6 @@ class State(proto.Enum):
152153
proto.STRING,
153154
number=1,
154155
)
155-
environment: "Environment" = proto.Field(
156-
proto.ENUM,
157-
number=10,
158-
enum="Environment",
159-
)
160156
description: str = proto.Field(
161157
proto.STRING,
162158
number=2,
@@ -196,14 +192,19 @@ class State(proto.Enum):
196192
number=9,
197193
message="StateMessage",
198194
)
199-
kms_key_name: str = proto.Field(
200-
proto.STRING,
201-
number=25,
195+
environment: "Environment" = proto.Field(
196+
proto.ENUM,
197+
number=10,
198+
enum="Environment",
202199
)
203200
url: str = proto.Field(
204201
proto.STRING,
205202
number=14,
206203
)
204+
kms_key_name: str = proto.Field(
205+
proto.STRING,
206+
number=25,
207+
)
207208

208209

209210
class StateMessage(proto.Message):
@@ -473,7 +474,7 @@ class BuildConfig(proto.Message):
473474
User-provided build-time environment
474475
variables for the function
475476
docker_registry (google.cloud.functions_v2.types.BuildConfig.DockerRegistry):
476-
Optional. Docker Registry to use for this deployment. This
477+
Docker Registry to use for this deployment. This
477478
configuration is only applicable to 1st Gen functions, 2nd
478479
Gen functions can only use Artifact Registry.
479480
@@ -564,7 +565,6 @@ class DockerRegistry(proto.Enum):
564565
class ServiceConfig(proto.Message):
565566
r"""Describes the Service being deployed.
566567
Currently Supported : Cloud Run (fully managed).
567-
Next tag: 23
568568
569569
Attributes:
570570
service (str):
@@ -585,10 +585,9 @@ class ServiceConfig(proto.Message):
585585
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery/pkg/api/resource/quantity.go
586586
a full description.
587587
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
588+
[Preview] The number of CPUs used in a single container
589+
instance. Default value is calculated from available memory.
590+
Supports the same values as Cloud Run, see
592591
https://cloud.google.com/run/docs/reference/rest/v1/Container#resourcerequirements
593592
Example: "1" indicates 1 vCPU
594593
environment_variables (MutableMapping[str, str]):
@@ -652,9 +651,8 @@ class ServiceConfig(proto.Message):
652651
revision (str):
653652
Output only. The name of service revision.
654653
max_instance_request_concurrency (int):
655-
Sets the maximum number of concurrent
656-
requests that each instance can receive.
657-
Defaults to 1.
654+
[Preview] Sets the maximum number of concurrent requests
655+
that each instance can receive. Defaults to 1.
658656
security_level (google.cloud.functions_v2.types.ServiceConfig.SecurityLevel):
659657
Security level configure whether the function
660658
only accepts https. This configuration is only
@@ -713,7 +711,7 @@ class SecurityLevel(proto.Enum):
713711
714712
This enforces security protocol on function URL.
715713
716-
Security level is only ocnfigurable for 1st Gen functions, If
714+
Security level is only configurable for 1st Gen functions, If
717715
unspecified, SECURE_OPTIONAL will be used. 2nd Gen functions are
718716
SECURE_ALWAYS ONLY.
719717
@@ -1251,9 +1249,9 @@ class GenerateUploadUrlRequest(proto.Message):
12511249
Storage signed URL should be generated, specified in the
12521250
format ``projects/*/locations/*``.
12531251
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
1252+
[Preview] Resource name of a KMS crypto key (managed by the
1253+
user) used to encrypt/decrypt function source code objects
1254+
in intermediate Cloud Storage buckets. When you generate an
12571255
upload url and upload your source code, it gets copied to an
12581256
intermediate Cloud Storage bucket. The source code is then
12591257
copied to a versioned directory in the sources bucket in the
@@ -1528,6 +1526,22 @@ class OperationMetadata(proto.Message):
15281526
)
15291527

15301528

1529+
class LocationMetadata(proto.Message):
1530+
r"""Extra GCF specific location information.
1531+
1532+
Attributes:
1533+
environments (MutableSequence[google.cloud.functions_v2.types.Environment]):
1534+
The Cloud Function environments this location
1535+
supports.
1536+
"""
1537+
1538+
environments: MutableSequence["Environment"] = proto.RepeatedField(
1539+
proto.ENUM,
1540+
number=1,
1541+
enum="Environment",
1542+
)
1543+
1544+
15311545
class Stage(proto.Message):
15321546
r"""Each Stage of the deployment process
15331547

‎tests/unit/gapic/functions_v2/test_function_service.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,11 @@ def test_get_function(request_type, transport: str = "grpc"):
765765
# Designate an appropriate return value for the call.
766766
call.return_value = functions.Function(
767767
name="name_value",
768-
environment=functions.Environment.GEN_1,
769768
description="description_value",
770769
state=functions.Function.State.ACTIVE,
771-
kms_key_name="kms_key_name_value",
770+
environment=functions.Environment.GEN_1,
772771
url="url_value",
772+
kms_key_name="kms_key_name_value",
773773
)
774774
response = client.get_function(request)
775775

@@ -781,11 +781,11 @@ def test_get_function(request_type, transport: str = "grpc"):
781781
# Establish that the response is the type that we expect.
782782
assert isinstance(response, functions.Function)
783783
assert response.name == "name_value"
784-
assert response.environment == functions.Environment.GEN_1
785784
assert response.description == "description_value"
786785
assert response.state == functions.Function.State.ACTIVE
787-
assert response.kms_key_name == "kms_key_name_value"
786+
assert response.environment == functions.Environment.GEN_1
788787
assert response.url == "url_value"
788+
assert response.kms_key_name == "kms_key_name_value"
789789

790790

791791
def test_get_function_empty_call():
@@ -823,11 +823,11 @@ async def test_get_function_async(
823823
call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(
824824
functions.Function(
825825
name="name_value",
826-
environment=functions.Environment.GEN_1,
827826
description="description_value",
828827
state=functions.Function.State.ACTIVE,
829-
kms_key_name="kms_key_name_value",
828+
environment=functions.Environment.GEN_1,
830829
url="url_value",
830+
kms_key_name="kms_key_name_value",
831831
)
832832
)
833833
response = await client.get_function(request)
@@ -840,11 +840,11 @@ async def test_get_function_async(
840840
# Establish that the response is the type that we expect.
841841
assert isinstance(response, functions.Function)
842842
assert response.name == "name_value"
843-
assert response.environment == functions.Environment.GEN_1
844843
assert response.description == "description_value"
845844
assert response.state == functions.Function.State.ACTIVE
846-
assert response.kms_key_name == "kms_key_name_value"
845+
assert response.environment == functions.Environment.GEN_1
847846
assert response.url == "url_value"
847+
assert response.kms_key_name == "kms_key_name_value"
848848

849849

850850
@pytest.mark.asyncio
@@ -2691,11 +2691,11 @@ def test_get_function_rest(request_type):
26912691
# Designate an appropriate value for the returned response.
26922692
return_value = functions.Function(
26932693
name="name_value",
2694-
environment=functions.Environment.GEN_1,
26952694
description="description_value",
26962695
state=functions.Function.State.ACTIVE,
2697-
kms_key_name="kms_key_name_value",
2696+
environment=functions.Environment.GEN_1,
26982697
url="url_value",
2698+
kms_key_name="kms_key_name_value",
26992699
)
27002700

27012701
# Wrap the value into a proper Response obj
@@ -2711,11 +2711,11 @@ def test_get_function_rest(request_type):
27112711
# Establish that the response is the type that we expect.
27122712
assert isinstance(response, functions.Function)
27132713
assert response.name == "name_value"
2714-
assert response.environment == functions.Environment.GEN_1
27152714
assert response.description == "description_value"
27162715
assert response.state == functions.Function.State.ACTIVE
2717-
assert response.kms_key_name == "kms_key_name_value"
2716+
assert response.environment == functions.Environment.GEN_1
27182717
assert response.url == "url_value"
2718+
assert response.kms_key_name == "kms_key_name_value"
27192719

27202720

27212721
def test_get_function_rest_required_fields(request_type=functions.GetFunctionRequest):
@@ -3300,7 +3300,6 @@ def test_create_function_rest(request_type):
33003300
request_init = {"parent": "projects/sample1/locations/sample2"}
33013301
request_init["function"] = {
33023302
"name": "name_value",
3303-
"environment": 1,
33043303
"description": "description_value",
33053304
"build_config": {
33063305
"build": "build_value",
@@ -3387,8 +3386,9 @@ def test_create_function_rest(request_type):
33873386
"state_messages": [
33883387
{"severity": 1, "type_": "type__value", "message": "message_value"}
33893388
],
3390-
"kms_key_name": "kms_key_name_value",
3389+
"environment": 1,
33913390
"url": "url_value",
3391+
"kms_key_name": "kms_key_name_value",
33923392
}
33933393
request = request_type(**request_init)
33943394

@@ -3576,7 +3576,6 @@ def test_create_function_rest_bad_request(
35763576
request_init = {"parent": "projects/sample1/locations/sample2"}
35773577
request_init["function"] = {
35783578
"name": "name_value",
3579-
"environment": 1,
35803579
"description": "description_value",
35813580
"build_config": {
35823581
"build": "build_value",
@@ -3663,8 +3662,9 @@ def test_create_function_rest_bad_request(
36633662
"state_messages": [
36643663
{"severity": 1, "type_": "type__value", "message": "message_value"}
36653664
],
3666-
"kms_key_name": "kms_key_name_value",
3665+
"environment": 1,
36673666
"url": "url_value",
3667+
"kms_key_name": "kms_key_name_value",
36683668
}
36693669
request = request_type(**request_init)
36703670

@@ -3763,7 +3763,6 @@ def test_update_function_rest(request_type):
37633763
}
37643764
request_init["function"] = {
37653765
"name": "projects/sample1/locations/sample2/functions/sample3",
3766-
"environment": 1,
37673766
"description": "description_value",
37683767
"build_config": {
37693768
"build": "build_value",
@@ -3850,8 +3849,9 @@ def test_update_function_rest(request_type):
38503849
"state_messages": [
38513850
{"severity": 1, "type_": "type__value", "message": "message_value"}
38523851
],
3853-
"kms_key_name": "kms_key_name_value",
3852+
"environment": 1,
38543853
"url": "url_value",
3854+
"kms_key_name": "kms_key_name_value",
38553855
}
38563856
request = request_type(**request_init)
38573857

@@ -4028,7 +4028,6 @@ def test_update_function_rest_bad_request(
40284028
}
40294029
request_init["function"] = {
40304030
"name": "projects/sample1/locations/sample2/functions/sample3",
4031-
"environment": 1,
40324031
"description": "description_value",
40334032
"build_config": {
40344033
"build": "build_value",
@@ -4115,8 +4114,9 @@ def test_update_function_rest_bad_request(
41154114
"state_messages": [
41164115
{"severity": 1, "type_": "type__value", "message": "message_value"}
41174116
],
4118-
"kms_key_name": "kms_key_name_value",
4117+
"environment": 1,
41194118
"url": "url_value",
4119+
"kms_key_name": "kms_key_name_value",
41204120
}
41214121
request = request_type(**request_init)
41224122

0 commit comments

Comments
��(0)