コード例 #1
0
    def receive_json(self, content: Data):
        msg = from_dict(WebsocketMessage, content)
        uid = msg.args.get("uuid", self.channel_name)
        self.last_uid = uid

        if not self.outpost:
            raise DenyConnection()

        state = OutpostState.for_instance_uid(self.outpost, uid)
        if self.channel_name not in state.channel_ids:
            state.channel_ids.append(self.channel_name)
        state.last_seen = datetime.now()

        if not self.first_msg:
            GAUGE_OUTPOSTS_CONNECTED.labels(
                outpost=self.outpost.name,
                uid=self.last_uid,
            ).inc()
            self.first_msg = True

        if msg.instruction == WebsocketMessageInstruction.HELLO:
            state.version = msg.args.get("version", None)
            state.build_hash = msg.args.get("buildHash", "")
        elif msg.instruction == WebsocketMessageInstruction.ACK:
            return
        GAUGE_OUTPOSTS_LAST_UPDATE.labels(
            outpost=self.outpost.name,
            uid=self.last_uid or "",
            version=state.version or "",
        ).set_to_current_time()
        state.save(timeout=OUTPOST_HELLO_INTERVAL * 1.5)

        response = WebsocketMessage(
            instruction=WebsocketMessageInstruction.ACK)
        self.send_json(asdict(response))
コード例 #2
0
ファイル: channels.py プロジェクト: toboshii/authentik
 def disconnect(self, close_code):
     if self.outpost and self.last_uid:
         state = OutpostState.for_instance_uid(self.outpost, self.last_uid)
         if self.channel_name in state.channel_ids:
             state.channel_ids.remove(self.channel_name)
             state.save()
     LOGGER.debug(
         "removed outpost instance from cache",
         outpost=self.outpost,
         instance_uuid=self.last_uid,
     )
コード例 #3
0
 def disconnect(self, close_code):
     if self.outpost and self.last_uid:
         state = OutpostState.for_instance_uid(self.outpost, self.last_uid)
         if self.channel_name in state.channel_ids:
             state.channel_ids.remove(self.channel_name)
             state.save()
     GAUGE_OUTPOSTS_CONNECTED.labels(
         outpost=self.outpost.name,
         uid=self.last_uid,
     ).dec()
     LOGGER.debug(
         "removed outpost instance from cache",
         outpost=self.outpost,
         instance_uuid=self.last_uid,
     )
コード例 #4
0
 def disconnect(self, code):
     if self.outpost and self.last_uid:
         state = OutpostState.for_instance_uid(self.outpost, self.last_uid)
         if self.channel_name in state.channel_ids:
             state.channel_ids.remove(self.channel_name)
             state.save()
         GAUGE_OUTPOSTS_CONNECTED.labels(
             outpost=self.outpost.name,
             uid=self.last_uid,
             expected=self.outpost.config.kubernetes_replicas,
         ).dec()
     self.logger.debug(
         "removed outpost instance from cache",
         instance_uuid=self.last_uid,
     )
コード例 #5
0
ファイル: channels.py プロジェクト: toboshii/authentik
    def receive_json(self, content: Data):
        msg = from_dict(WebsocketMessage, content)
        uid = msg.args.get("uuid", self.channel_name)
        self.last_uid = uid
        state = OutpostState.for_instance_uid(self.outpost, uid)
        if self.channel_name not in state.channel_ids:
            state.channel_ids.append(self.channel_name)
        state.last_seen = datetime.now()
        if msg.instruction == WebsocketMessageInstruction.HELLO:
            state.version = msg.args.get("version", None)
            state.build_hash = msg.args.get("buildHash", "")
        elif msg.instruction == WebsocketMessageInstruction.ACK:
            return
        state.save(timeout=OUTPOST_HELLO_INTERVAL * 1.5)

        response = WebsocketMessage(
            instruction=WebsocketMessageInstruction.ACK)
        self.send_json(asdict(response))