Skip to content

Commit 139b893

Browse files
Merge branch 'master' into kms-flaky-fix
2 parents 48f645e + efe5e78 commit 139b893

File tree

23 files changed

+529
-425
lines changed

23 files changed

+529
-425
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/container_registry/ @DanSanche @GoogleCloudPlatform/python-samples-owners
2424
/datacatalog/ @shollyman @GoogleCloudPlatform/python-samples-owners
2525
/dataflow/ @davidcavazos @GoogleCloudPlatform/python-samples-owners
26-
/datalabeling/ @czahedi @GoogleCloudPlatform/python-samples-owners
26+
/datalabeling/ @sgreenberg @GoogleCloudPlatform/python-samples-owners
2727
/dataproc/ @bradmiro @GoogleCloudPlatform/python-samples-owners
2828
/datastore/ @andrewsg @GoogleCloudPlatform/python-samples-owners
2929
/dialogflow/ @nnegrey @telpirion @sirtorry @GoogleCloudPlatform/python-samples-owners

AUTHORING_GUIDE.md

Lines changed: 274 additions & 365 deletions
Large diffs are not rendered by default.

appengine/flexible/pubsub/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
# Global list to storage messages received by this instance.
3636
MESSAGES = []
3737

38+
# Initialize the publisher client once to avoid memory leak
39+
# and reduce publish latency.
40+
publisher = pubsub_v1.PublisherClient()
3841

3942
# [START gae_flex_pubsub_index]
4043
@app.route('/', methods=['GET', 'POST'])
@@ -44,9 +47,7 @@ def index():
4447

4548
data = request.form.get('payload', 'Example payload').encode('utf-8')
4649

47-
# Consider initialzing the publisher client outside this function
48-
# for low latency publish.
49-
publisher = pubsub_v1.PublisherClient()
50+
# publisher = pubsub_v1.PublisherClient()
5051
topic_path = publisher.topic_path(
5152
current_app.config['PROJECT'],
5253
current_app.config['PUBSUB_TOPIC'])
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
grpcio==1.27.2
2-
grpcio-tools==1.27.2
2+
grpcio-tools==1.28.1
33
google-auth==1.11.2
44
six==1.14.0
55
googleapis-common-protos==1.51.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
grpcio==1.27.2
2-
grpcio-tools==1.27.2
2+
grpcio-tools==1.28.1
33
google-auth==1.11.2
44
six==1.14.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
grpcio==1.27.2
2-
grpcio-tools==1.27.2
2+
grpcio-tools==1.28.1

functions/billing/main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
# [START functions_billing_limit_appengine]
2727
# [START functions_billing_stop]
2828
from googleapiclient import discovery
29-
from oauth2client.client import GoogleCredentials
3029
# [END functions_billing_stop]
3130
# [END functions_billing_limit]
3231
# [END functions_billing_limit_appengine]
@@ -80,7 +79,6 @@ def stop_billing(data, context):
8079
'cloudbilling',
8180
'v1',
8281
cache_discovery=False,
83-
credentials=GoogleCredentials.get_application_default()
8482
)
8583

8684
projects = billing.projects()
@@ -130,7 +128,6 @@ def limit_use(data, context):
130128
'compute',
131129
'v1',
132130
cache_discovery=False,
133-
credentials=GoogleCredentials.get_application_default()
134131
)
135132
instances = compute.instances()
136133

@@ -190,8 +187,7 @@ def limit_use_appengine(data, context):
190187
appengine = discovery.build(
191188
'appengine',
192189
'v1',
193-
cache_discovery=False,
194-
credentials=GoogleCredentials.get_application_default()
190+
cache_discovery=False
195191
)
196192
apps = appengine.apps()
197193

functions/billing/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
slackclient==2.5.0
22
# [START functions_billing_limit_appengine_deps]
3-
oauth2client==4.1.3
43
google-api-python-client==1.7.11
54
# [START functions_billing_limit_appengine_deps]

functions/slack/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
google-api-python-client==1.7.11
22
flask==1.1.1
3-
oauth2client==4.1.3
43
slackeventsapi==2.1.0

healthcare/api-client/fhir/fhir_resources_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
service_account_json = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
3030

3131
bundle = os.path.join(os.path.dirname(__file__), "resources/execute_bundle.json")
32-
dataset_id = "test_dataset_{}".format(str(uuid.uuid4()))
33-
fhir_store_id = "test_fhir_store-{}".format(str(uuid.uuid4()))
32+
dataset_id = "test_dataset_{}".format(uuid.uuid4())
33+
fhir_store_id = "test_fhir_store-{}".format(uuid.uuid4())
3434
resource_type = "Patient"
3535

3636

healthcare/api-client/fhir/fhir_stores_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pytest
1717
import sys
1818
import time
19+
import uuid
1920

2021
from google.cloud import exceptions, storage
2122

@@ -28,8 +29,8 @@
2829
project_id = os.environ["GOOGLE_CLOUD_PROJECT"]
2930
service_account_json = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
3031

31-
dataset_id = "test_dataset_{}".format(int(time.time()))
32-
fhir_store_id = "test_fhir_store-{}".format(int(time.time()))
32+
dataset_id = "test_dataset_{}".format(uuid.uuid4())
33+
fhir_store_id = "test_fhir_store-{}".format(uuid.uuid4())
3334

3435
gcs_uri = os.environ["CLOUD_STORAGE_BUCKET"]
3536
RESOURCES = os.path.join(os.path.dirname(__file__), "resources")

healthcare/api-client/hl7v2/hl7v2_messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def list_hl7v2_messages(
190190
hl7v2_messages_parent, hl7v2_store_id)
191191

192192
hl7v2_messages = client.projects().locations().datasets().hl7V2Stores(
193-
).messages().list(parent=hl7v2_message_path).execute().get('messages', [])
193+
).messages().list(parent=hl7v2_message_path).execute().get('hl7V2Messages', [])
194194

195195
for hl7v2_message in hl7v2_messages:
196196
print(hl7v2_message)

healthcare/api-client/hl7v2/hl7v2_messages_test.py

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
import os
1616
import pytest
17-
import re
1817
import sys
19-
import time
18+
import uuid
19+
20+
from gcp_devrel.testing import eventually_consistent
2021

2122
# Add datasets for bootstrapping datasets for testing
2223
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
@@ -28,8 +29,8 @@
2829
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
2930
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
3031

31-
dataset_id = 'test_dataset_{}'.format(int(time.time()))
32-
hl7v2_store_id = 'test_hl7v2_store-{}'.format(int(time.time()))
32+
dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
33+
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())
3334
hl7v2_message_file = 'resources/hl7-sample-ingest.json'
3435
label_key = 'PROCESSED'
3536
label_value = 'TRUE'
@@ -81,15 +82,20 @@ def test_CRUD_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
8182
hl7v2_store_id,
8283
hl7v2_message_file)
8384

84-
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
85-
service_account_json,
86-
project_id,
87-
cloud_region,
88-
dataset_id,
89-
hl7v2_store_id)
90-
91-
hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
92-
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
85+
hl7v2_message_id = ""
86+
@eventually_consistent.call
87+
def _():
88+
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
89+
service_account_json,
90+
project_id,
91+
cloud_region,
92+
dataset_id,
93+
hl7v2_store_id)
94+
95+
assert len(hl7v2_messages_list) > 0
96+
hl7v2_message_name = hl7v2_messages_list[0].get('name')
97+
nonlocal hl7v2_message_id
98+
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
9399

94100
hl7v2_messages.get_hl7v2_message(
95101
service_account_json,
@@ -124,15 +130,20 @@ def test_ingest_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
124130
hl7v2_store_id,
125131
hl7v2_message_file)
126132

127-
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
128-
service_account_json,
129-
project_id,
130-
cloud_region,
131-
dataset_id,
132-
hl7v2_store_id)
133-
134-
hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
135-
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
133+
hl7v2_message_id = ""
134+
@eventually_consistent.call
135+
def _():
136+
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
137+
service_account_json,
138+
project_id,
139+
cloud_region,
140+
dataset_id,
141+
hl7v2_store_id)
142+
143+
assert len(hl7v2_messages_list) > 0
144+
hl7v2_message_name = hl7v2_messages_list[0].get('name')
145+
nonlocal hl7v2_message_id
146+
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
136147

137148
hl7v2_messages.get_hl7v2_message(
138149
service_account_json,
@@ -167,15 +178,20 @@ def test_patch_hl7v2_message(test_dataset, test_hl7v2_store, capsys):
167178
hl7v2_store_id,
168179
hl7v2_message_file)
169180

170-
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
171-
service_account_json,
172-
project_id,
173-
cloud_region,
174-
dataset_id,
175-
hl7v2_store_id)
176-
177-
hl7v2_messages_list_to_str = str(hl7v2_messages_list).split('/', 9)[9]
178-
hl7v2_message_id = re.sub('\']', '', hl7v2_messages_list_to_str)
181+
hl7v2_message_id = ""
182+
@eventually_consistent.call
183+
def _():
184+
hl7v2_messages_list = hl7v2_messages.list_hl7v2_messages(
185+
service_account_json,
186+
project_id,
187+
cloud_region,
188+
dataset_id,
189+
hl7v2_store_id)
190+
191+
assert len(hl7v2_messages_list) > 0
192+
hl7v2_message_name = hl7v2_messages_list[0].get('name')
193+
nonlocal hl7v2_message_id
194+
hl7v2_message_id = hl7v2_message_name.split('/', 9)[9]
179195

180196
hl7v2_messages.patch_hl7v2_message(
181197
service_account_json,

healthcare/api-client/hl7v2/hl7v2_stores_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616
import pytest
1717
import sys
18-
import time
18+
import uuid
1919

2020
# Add datasets for bootstrapping datasets for testing
2121
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'datasets')) # noqa
@@ -26,8 +26,8 @@
2626
project_id = os.environ['GOOGLE_CLOUD_PROJECT']
2727
service_account_json = os.environ['GOOGLE_APPLICATION_CREDENTIALS']
2828

29-
dataset_id = 'test_dataset_{}'.format(int(time.time()))
30-
hl7v2_store_id = 'test_hl7v2_store-{}'.format(int(time.time()))
29+
dataset_id = 'test_dataset_{}'.format(uuid.uuid4())
30+
hl7v2_store_id = 'test_hl7v2_store-{}'.format(uuid.uuid4())
3131

3232

3333
@pytest.fixture(scope='module')
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
pytest==5.3.2
2+
gcp-devrel-py-tools==0.0.15
3+
google-cloud-core

iot/api-client/end_to_end_example/cloudiot_pubsub_example_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from google.cloud import pubsub
4646
from googleapiclient import discovery
4747
from googleapiclient.errors import HttpError
48-
from oauth2client.service_account import ServiceAccountCredentials
48+
from google.oauth2 import service_account
4949

5050

5151
API_SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
@@ -58,8 +58,8 @@ class Server(object):
5858
"""Represents the state of the server."""
5959

6060
def __init__(self, service_account_json):
61-
credentials = ServiceAccountCredentials.from_json_keyfile_name(
62-
service_account_json, API_SCOPES)
61+
credentials = service_account.Credentials.from_service_account_file(
62+
service_account_json).with_scopes(API_SCOPES)
6363
if not credentials:
6464
sys.exit('Could not load service account credential '
6565
'from {}'.format(service_account_json))

iot/api-client/end_to_end_example/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ google-api-python-client==1.7.11
33
google-auth-httplib2==0.0.3
44
google-auth==1.11.2
55
google-cloud-pubsub==1.1.0
6-
oauth2client==4.1.3
76
pyjwt==1.7.1
87
paho-mqtt==1.5.0

0 commit comments

Comments
 (0)