コード例 #1
0
    async def __aenter__(self):
        message_decrypter = BeekeeperBotMessageDecrypter(
            base64.b64decode(self._pubnub_channel_key))
        message_listener = BeekeeperBotMessageListener(
            bot=self, decrypter=message_decrypter)

        pubnub_config = PNConfiguration()
        pubnub_config.subscribe_key = self._pubnub_key
        pubnub_config.reconnect_policy = PNReconnectionPolicy.LINEAR
        pubnub_config.connect_timeout = 30

        self._pubnub = PubNubAsyncio(config=pubnub_config)
        self._pubnub.add_listener(message_listener)
        self._pubnub.subscribe().channels([self._pubnub_channel_name
                                           ]).execute()

        return self
コード例 #2
0
ファイル: initPubNub.py プロジェクト: Saverio976/Chat-App-TUI
def initPubNub(stdscr):
    """
    Ask for a pseudo if not in the path and init the pubnub.PubNub object.

    Parameters
    ----------
        stdscr: :class:curses._CursesWindow
            the screen initialised in main.py

    Returns
    -------
    :class:pubnub.PubNub
        with configuration
    """
    pseudo = os.getenv("PSEUDO")
    if pseudo == None:
        pseudo = ""
        while len(pseudo) < 2:
            stdscr.addstr(0, 0, "pseudo :")
            stdscr.refresh()
            editwin = curses.newwin(1, min(16, curses.COLS - 1), 1, 1)  # pylint: disable=no-member
            editwin.keypad(True)
            box = Textbox(editwin)
            box.edit()
            pseudo = " ".join(box.gather().split())
        alphabet = string.ascii_letters + string.digits
        pseudo += ''.join(secrets.choice(alphabet) for i in range(10))
        with open("assets/data/.env", "a") as file:
            file.write(f"\nPSEUDO=\"{pseudo}\"")
        editwin.erase()

    pnconfig = PNConfiguration()
    pnconfig.subscribe_key = os.getenv("SUB_KEY")
    pnconfig.publish_key = os.getenv("PUB_KEY")
    pnconfig.ssl = True
    pnconfig.cipher_key = os.getenv("CYPHER_KEY")
    pnconfig.uuid = pseudo
    pnconfig.reconnect_policy = PNReconnectionPolicy.EXPONENTIAL
    pnconfig.connect_timeout = 30

    return PubNub(pnconfig)
コード例 #3
0
    def __init__(self, host, user, password, database):
        print("GatewayAuth: Starting gateway database..")
        self.gd = gateway_database.GatewayDatabase(host, user, password,
                                                   database)

        pnconfig = PNConfiguration()
        pnconfig.subscribe_key = self.gd.sub_key()
        pnconfig.publish_key = self.gd.pub_key()
        pnconfig.secret_key = self.gd.sec_key()
        pnconfig.subscribe_timeout = 9 ^ 99
        pnconfig.connect_timeout = 9 ^ 99
        pnconfig.non_subscribe_timeout = 9 ^ 99
        pnconfig.ssl = True
        pnconfig.reconnect_policy = PNReconnectionPolicy.LINEAR
        pnconfig.uuid = 'GA'
        pnconfig.auth_key = idgen.id_generator(size=42)

        self.pubnub = PubNub(pnconfig)
        self.pubnub.add_listener(self)
        self.pubnub.unsubscribe_all()

        self.admin_channel = idgen.id_generator(size=255)
        self.pubnub.grant().channels(self.admin_channel).auth_keys(
            [self.gd.receivers_key(),
             pnconfig.auth_key]).read(True).write(True).manage(True).sync()

        print("GatewayAuth: Starting the receiver..")
        self.gr = gateway_receiver.Receiver(self.gd, self.admin_channel)
        self.gateway_uuids = [pnconfig.uuid, self.gr.uuid]
        self.gateway_channels = ["gateway_auth", "gateway_global"]

        self.pubnub.grant().channels(
            self.gateway_channels).read(True).write(True).manage(True).sync()
        print(
            "GatewayAuth: Connecting to gateway channel and gateway global feed.."
        )
        self.pubnub.subscribe().channels(
            self.gateway_channels +
            [self.admin_channel]).with_presence().execute()

        self.receiver_auth_key = self.gd.receivers_key()