authentik.providers.rac.consumer_outpost
RAC consumer
1"""RAC consumer""" 2 3from channels.exceptions import ChannelFull 4from channels.generic.websocket import AsyncWebsocketConsumer 5 6from authentik.providers.rac.consumer_client import build_rac_client_group 7 8 9class RACOutpostConsumer(AsyncWebsocketConsumer): 10 """Consumer the outpost connects to, to send specific data back to a client connection""" 11 12 dest_channel_id: str 13 14 async def connect(self): 15 self.dest_channel_id = self.scope["url_route"]["kwargs"]["channel"] 16 await self.accept() 17 await self.channel_layer.group_send( 18 build_rac_client_group(), 19 { 20 "type": "event.outpost.connected", 21 "outpost_channel": self.channel_name, 22 "client_channel": self.dest_channel_id, 23 }, 24 ) 25 26 async def receive(self, text_data=None, bytes_data=None): 27 """Mirror data received from guacd running in the outpost 28 to the dest_channel_id which is the channel talking to the browser""" 29 try: 30 await self.channel_layer.send( 31 self.dest_channel_id, 32 { 33 "type": "event.send", 34 "text_data": text_data, 35 "bytes_data": bytes_data, 36 }, 37 ) 38 except ChannelFull: 39 pass 40 41 async def event_send(self, event: dict): 42 """Handler called by client websocket that sends data to this specific 43 outpost connection""" 44 await self.send(text_data=event.get("text_data"), bytes_data=event.get("bytes_data")) 45 46 async def event_disconnect(self, event: dict): 47 """Tell outpost we're about to disconnect""" 48 await self.send(text_data="0.authentik.disconnect") 49 await self.close()
class
RACOutpostConsumer(channels.generic.websocket.AsyncWebsocketConsumer):
10class RACOutpostConsumer(AsyncWebsocketConsumer): 11 """Consumer the outpost connects to, to send specific data back to a client connection""" 12 13 dest_channel_id: str 14 15 async def connect(self): 16 self.dest_channel_id = self.scope["url_route"]["kwargs"]["channel"] 17 await self.accept() 18 await self.channel_layer.group_send( 19 build_rac_client_group(), 20 { 21 "type": "event.outpost.connected", 22 "outpost_channel": self.channel_name, 23 "client_channel": self.dest_channel_id, 24 }, 25 ) 26 27 async def receive(self, text_data=None, bytes_data=None): 28 """Mirror data received from guacd running in the outpost 29 to the dest_channel_id which is the channel talking to the browser""" 30 try: 31 await self.channel_layer.send( 32 self.dest_channel_id, 33 { 34 "type": "event.send", 35 "text_data": text_data, 36 "bytes_data": bytes_data, 37 }, 38 ) 39 except ChannelFull: 40 pass 41 42 async def event_send(self, event: dict): 43 """Handler called by client websocket that sends data to this specific 44 outpost connection""" 45 await self.send(text_data=event.get("text_data"), bytes_data=event.get("bytes_data")) 46 47 async def event_disconnect(self, event: dict): 48 """Tell outpost we're about to disconnect""" 49 await self.send(text_data="0.authentik.disconnect") 50 await self.close()
Consumer the outpost connects to, to send specific data back to a client connection
async def
connect(self):
15 async def connect(self): 16 self.dest_channel_id = self.scope["url_route"]["kwargs"]["channel"] 17 await self.accept() 18 await self.channel_layer.group_send( 19 build_rac_client_group(), 20 { 21 "type": "event.outpost.connected", 22 "outpost_channel": self.channel_name, 23 "client_channel": self.dest_channel_id, 24 }, 25 )
async def
receive(self, text_data=None, bytes_data=None):
27 async def receive(self, text_data=None, bytes_data=None): 28 """Mirror data received from guacd running in the outpost 29 to the dest_channel_id which is the channel talking to the browser""" 30 try: 31 await self.channel_layer.send( 32 self.dest_channel_id, 33 { 34 "type": "event.send", 35 "text_data": text_data, 36 "bytes_data": bytes_data, 37 }, 38 ) 39 except ChannelFull: 40 pass
Mirror data received from guacd running in the outpost to the dest_channel_id which is the channel talking to the browser
async def
event_send(self, event: dict):
42 async def event_send(self, event: dict): 43 """Handler called by client websocket that sends data to this specific 44 outpost connection""" 45 await self.send(text_data=event.get("text_data"), bytes_data=event.get("bytes_data"))
Handler called by client websocket that sends data to this specific outpost connection