-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrpc_sample.py
More file actions
30 lines (21 loc) · 812 Bytes
/
grpc_sample.py
File metadata and controls
30 lines (21 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from google.auth.transport import mtls
import google.oauth2.credentials
from google.pubsub import PublisherClient
import google.api_core.client_options as ClientOptions
def call():
project_id = "sijun-mtls-demo"
cred = google.oauth2.credentials.UserAccessTokenCredentials()
if mtls.has_default_client_cert_source():
print("= has default client cert source=")
callback = mtls.default_client_cert_source()
else:
callback = None
client_options = ClientOptions.ClientOptions(
client_cert_source=callback
)
client = PublisherClient(credentials=cred, client_options=client_options)
project = "projects/{}".format(project_id)
list_topics_iter = client.list_topics(project=project)
topics = list(list_topics_iter)
print(topics)
call()