Skip to content

Commit 7d80651

Browse files
committed
Update examples to use key and TLS
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
1 parent ed4a9ca commit 7d80651

File tree

1 file changed

+36
-10
lines changed

1 file changed

+36
-10
lines changed

src/frequenz/dispatch/_dispatcher.py

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ class Dispatcher:
6262
async def run():
6363
host = os.getenv("DISPATCH_API_HOST", "localhost")
6464
port = os.getenv("DISPATCH_API_PORT", "50051")
65+
key = os.getenv("DISPATCH_API_KEY", "some-key")
6566
6667
service_address = f"{host}:{port}"
67-
grpc_channel = grpc.aio.insecure_channel(service_address)
68-
microgrid_id = 1
69-
dispatcher = Dispatcher(microgrid_id, grpc_channel, service_address)
68+
grpc_channel = grpc.aio.secure_channel(
69+
service_address,
70+
credentials=grpc.ssl_channel_credentials()
71+
)
72+
dispatcher = Dispatcher(
73+
microgrid_id=1,
74+
grpc_channel=grpc_channel,
75+
svc_addr=service_address,
76+
key=key
77+
)
7078
await dispatcher.start()
7179
7280
actor = MagicMock() # replace with your actor
@@ -110,12 +118,20 @@ async def run():
110118
async def run():
111119
host = os.getenv("DISPATCH_API_HOST", "localhost")
112120
port = os.getenv("DISPATCH_API_PORT", "50051")
121+
key = os.getenv("DISPATCH_API_KEY", "some-key")
113122
114123
service_address = f"{host}:{port}"
115-
grpc_channel = grpc.aio.insecure_channel(service_address)
116-
microgrid_id = 1
117-
dispatcher = Dispatcher(microgrid_id, grpc_channel, service_address)
118-
dispatcher.start() # this will start the actor
124+
grpc_channel = grpc.aio.secure_channel(
125+
service_address,
126+
credentials=grpc.ssl_channel_credentials()
127+
)
128+
dispatcher = Dispatcher(
129+
microgrid_id=1,
130+
grpc_channel=grpc_channel,
131+
svc_addr=service_address,
132+
key=key
133+
)
134+
await dispatcher.start() # this will start the actor
119135
120136
events_receiver = dispatcher.lifecycle_events.new_receiver()
121137
@@ -146,11 +162,21 @@ async def run():
146162
async def run():
147163
host = os.getenv("DISPATCH_API_HOST", "localhost")
148164
port = os.getenv("DISPATCH_API_PORT", "50051")
165+
key = os.getenv("DISPATCH_API_KEY", "some-key")
149166
150-
service_address = f"{host}:{port}"
151-
grpc_channel = grpc.aio.insecure_channel(service_address)
152167
microgrid_id = 1
153-
dispatcher = Dispatcher(microgrid_id, grpc_channel, service_address)
168+
169+
service_address = f"{host}:{port}"
170+
grpc_channel = grpc.aio.secure_channel(
171+
service_address,
172+
credentials=grpc.ssl_channel_credentials()
173+
)
174+
dispatcher = Dispatcher(
175+
microgrid_id=microgrid_id,
176+
grpc_channel=grpc_channel,
177+
svc_addr=service_address,
178+
key=key
179+
)
154180
await dispatcher.start() # this will start the actor
155181
156182
# Create a new dispatch

0 commit comments

Comments
 (0)