コード例 #1
0
 def disconnect(self, close_code):
     if self.outpost:
         OutpostState.for_channel(self.outpost, self.channel_name).delete()
     LOGGER.debug(
         "removed outpost instance from cache",
         outpost=self.outpost,
         channel_name=self.channel_name,
     )
コード例 #2
0
 def disconnect(self, close_code):
     if self.outpost and self.last_uid:
         OutpostState.for_channel(self.outpost, self.last_uid).delete()
     LOGGER.debug(
         "removed outpost instance from cache",
         outpost=self.outpost,
         instance_uuid=self.last_uid,
     )
コード例 #3
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))
コード例 #4
0
    def receive_json(self, content: Data):
        msg = from_dict(WebsocketMessage, content)
        state = OutpostState(
            uid=self.channel_name,
            last_seen=datetime.now(),
            _outpost=self.outpost,
        )
        if msg.instruction == WebsocketMessageInstruction.HELLO:
            state.version = msg.args.get("version", None)
        elif msg.instruction == WebsocketMessageInstruction.ACK:
            return
        state.save(timeout=OUTPOST_HELLO_INTERVAL * 1.5)

        response = WebsocketMessage(
            instruction=WebsocketMessageInstruction.ACK)
        self.send_json(asdict(response))
コード例 #5
0
def _outpost_single_update(outpost: Outpost, layer=None):
    """Update outpost instances connected to a single outpost"""
    # Ensure token again, because this function is called when anything related to an
    # OutpostModel is saved, so we can be sure permissions are right
    _ = outpost.token
    if not layer:  # pragma: no cover
        layer = get_channel_layer()
    for state in OutpostState.for_outpost(outpost):
        LOGGER.debug("sending update", channel=state.uid, outpost=outpost)
        async_to_sync(layer.send)(state.uid, {"type": "event.update"})
コード例 #6
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,
     )
コード例 #7
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,
     )
コード例 #8
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,
     )
コード例 #9
0
 def connect(self):
     super().connect()
     uuid = self.scope["url_route"]["kwargs"]["pk"]
     outpost = get_objects_for_user(
         self.user, "authentik_outposts.view_outpost").filter(pk=uuid)
     if not outpost.exists():
         raise DenyConnection()
     self.accept()
     self.outpost = outpost.first()
     OutpostState(
         uid=self.channel_name,
         last_seen=datetime.now(),
         _outpost=self.outpost).save(timeout=OUTPOST_HELLO_INTERVAL * 1.5)
     LOGGER.debug(
         "added outpost instace to cache",
         outpost=self.outpost,
         channel_name=self.channel_name,
     )
コード例 #10
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))