-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
50 lines (38 loc) · 1.52 KB
/
client.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import print_function
import logging
import grpc
import relationships_pb2
import relationships_pb2_grpc
relation_api_gRPC_server = "localhost:9000"
def run():
with grpc.insecure_channel(relation_api_gRPC_server) as channel:
stub = relationships_pb2_grpc.RelationshipsStub(channel)
request = relationships_pb2.CreateRelationshipsRequest(
touch=True,
relationships=[
relationships_pb2.Relationship(
object=relationships_pb2.ObjectReference(type="group", id="bob_club"),
relation="member",
subject=relationships_pb2.SubjectReference(
object=relationships_pb2.ObjectReference(type="user", id="bob")
)
)
]
)
response = stub.CreateRelationships(request)
print(response.SerializeToString())
print("End of CreateRelationshipsRequest")
print("Start of ReadRelationshipsRequest")
with grpc.insecure_channel(relation_api_gRPC_server) as channel:
stub = relationships_pb2_grpc.RelationshipsStub(channel)
request = relationships_pb2.ReadRelationshipsRequest(filter=relationships_pb2.RelationshipFilter(
object_type="group",
object_id="bob_club",
relation="member"
))
response = stub.ReadRelationships(request)
print(response)
print("End of ReadRelationshipsRequest")
if __name__ == "__main__":
logging.basicConfig()
run()