@@ -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
@@ -175,20 +201,26 @@ async def run():
175201 """
176202
177203 def __init__ (
178- self , microgrid_id : int , grpc_channel : grpc .aio .Channel , svc_addr : str
204+ self ,
205+ * ,
206+ microgrid_id : int ,
207+ grpc_channel : grpc .aio .Channel ,
208+ svc_addr : str ,
209+ key : str ,
179210 ):
180211 """Initialize the dispatcher.
181212
182213 Args:
183214 microgrid_id: The microgrid id.
184215 grpc_channel: The gRPC channel.
185216 svc_addr: The service address.
217+ key: The key to access the service.
186218 """
187219 self ._running_state_channel = Broadcast [Dispatch ](name = "running_state_change" )
188220 self ._lifecycle_events_channel = Broadcast [DispatchEvent ](
189221 name = "lifecycle_events"
190222 )
191- self ._client = Client (grpc_channel , svc_addr )
223+ self ._client = Client (grpc_channel = grpc_channel , svc_addr = svc_addr , key = key )
192224 self ._actor = DispatchingActor (
193225 microgrid_id ,
194226 self ._client ,
0 commit comments