Skip to content

Commit 9995dc5

Browse files
author
Rebecca Shaw
committed
add request metadata for grpc routing
1 parent aaa8360 commit 9995dc5

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

servicedirectory/snippets.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@ def create_namespace(project_id, location_id, namespace_id):
2929
response = client.create_namespace(
3030
parent='projects/{0}/locations/{1}'.format(project_id, location_id),
3131
namespace=namespace,
32-
namespace_id=namespace_id)
32+
namespace_id=namespace_id,
33+
metadata=[[
34+
'x-goog-request-params',
35+
'name=projects/{0}/locations/{1}/namespaces/{2}'.format(
36+
project_id, location_id, namespace_id)
37+
]])
3338

3439
print('Created namespace {0}.'.format(response.name))
3540

@@ -44,7 +49,13 @@ def delete_namespace(project_id, location_id, namespace_id):
4449
namespace_name = 'projects/{0}/locations/{1}/namespaces/{2}'.format(
4550
project_id, location_id, namespace_id)
4651

47-
client.delete_namespace(name=namespace_name)
52+
client.delete_namespace(
53+
name=namespace_name,
54+
metadata=[[
55+
'x-goog-request-params',
56+
'name=projects/{0}/locations/{1}/namespaces/{2}'.format(
57+
project_id, location_id, namespace_id)
58+
]])
4859

4960
print('Deleted namespace {0}.'.format(namespace_name))
5061

@@ -62,7 +73,12 @@ def create_service(project_id, location_id, namespace_id, service_id):
6273
parent='projects/{0}/locations/{1}/namespaces/{2}'.format(
6374
project_id, location_id, namespace_id),
6475
service=service,
65-
service_id=service_id)
76+
service_id=service_id,
77+
metadata=[[
78+
'x-goog-request-params',
79+
'name=projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
80+
project_id, location_id, namespace_id, service_id)
81+
]])
6682

6783
print('Created service {0}.'.format(response.name))
6884

@@ -77,7 +93,13 @@ def delete_service(project_id, location_id, namespace_id, service_id):
7793
service_name = 'projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
7894
project_id, location_id, namespace_id, service_id)
7995

80-
client.delete_service(name=service_name)
96+
client.delete_service(
97+
name=service_name,
98+
metadata=[[
99+
'x-goog-request-params',
100+
'name=projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
101+
project_id, location_id, namespace_id, service_id)
102+
]])
81103

82104
print('Deleted service {0}.'.format(service_name))
83105

@@ -91,7 +113,13 @@ def resolve_service(project_id, location_id, namespace_id, service_id):
91113
name='projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
92114
project_id, location_id, namespace_id, service_id))
93115

94-
response = client.resolve_service(request=request)
116+
response = client.resolve_service(
117+
request=request,
118+
metadata=[[
119+
'x-goog-request-params',
120+
'name=projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
121+
project_id, location_id, namespace_id, service_id)
122+
]])
95123

96124
print('Endpoints found:')
97125
for endpoint in response.service.endpoints:
@@ -117,7 +145,13 @@ def create_endpoint(project_id, location_id, namespace_id, service_id,
117145
parent='projects/{0}/locations/{1}/namespaces/{2}/services/{3}'.format(
118146
project_id, location_id, namespace_id, service_id),
119147
endpoint=endpoint,
120-
endpoint_id=endpoint_id)
148+
endpoint_id=endpoint_id,
149+
metadata=[[
150+
'x-goog-request-params',
151+
'name=projects/{0}/locations/{1}/namespaces/{2}/services/{3}/endpoints/{4}'
152+
.format(project_id, location_id, namespace_id, service_id,
153+
endpoint_id)
154+
]])
121155

122156
print('Created endpoint {0}.'.format(response.name))
123157

@@ -133,6 +167,13 @@ def delete_endpoint(project_id, location_id, namespace_id, service_id,
133167
endpoint_name = 'projects/{0}/locations/{1}/namespaces/{2}/services/{3}/endpoints/{4}'.format(
134168
project_id, location_id, namespace_id, service_id, endpoint_id)
135169

136-
client.delete_endpoint(name=endpoint_name)
170+
client.delete_endpoint(
171+
name=endpoint_name,
172+
metadata=[[
173+
'x-goog-request-params',
174+
'name=projects/{0}/locations/{1}/namespaces/{2}/services/{3}/endpoints/{4}'
175+
.format(project_id, location_id, namespace_id, service_id,
176+
endpoint_id)
177+
]])
137178

138179
print('Deleted endpoint {0}.'.format(endpoint_name))

servicedirectory/snippets_test.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from google.cloud import servicedirectory_v1beta1
2121

2222
PROJECT_ID = environ['GCLOUD_PROJECT']
23-
LOCATION_ID = 'us-east1'
24-
NAMESPACE_ID = 'a-namespace'
25-
SERVICE_ID = 'a-service'
26-
ENDPOINT_ID = 'a-endpoint'
23+
LOCATION_ID = environ['GCLOUD_LOCATION']
24+
NAMESPACE_ID = 'test-namespace'
25+
SERVICE_ID = 'test-service'
26+
ENDPOINT_ID = 'test-endpoint'
2727
ADDRESS = '1.2.3.4'
2828
PORT = 443
2929

@@ -33,7 +33,13 @@ def teardown_module(module):
3333
response = client.list_namespaces(
3434
parent='projects/{0}/locations/{1}'.format(PROJECT_ID, LOCATION_ID))
3535
for namespace in response.namespaces:
36-
client.delete_namespace(name=namespace.name)
36+
client.delete_namespace(
37+
name=namespace.name,
38+
metadata=[[
39+
'x-goog-request-params',
40+
'name=projects/{0}/locations/{1}/namespaces/{2}'.format(
41+
PROJECT_ID, LOCATION_ID, namespace.name)
42+
]])
3743

3844

3945
def test_create_namespace():

0 commit comments

Comments
 (0)