Ejemplo n.º 1
0
    async def call_upper_word__internal_messager(self, word: str):
        sprint_f(f"call_upper_word__internal_messager :: {word}")

        async with self.connection:
            channel = await self.connection.channel()
            rpc = await RPC.create(channel)
            upper_word = await rpc.proxy.upper_word__internal_messager(
                word=word)
        return upper_word
Ejemplo n.º 2
0
    async def call_upper_word_by_jsonrpc__internal_messager(self, json_rq):
        sprint_f(f"call_upper_word_by_jsonrpc__internal_messager :: {json_rq}")

        async with self.connection:
            channel = await self.connection.channel()
            rpc = await RPC.create(channel)
            upper_word = await rpc.proxy.internal_messager__upper_word_as_json_rpc(
                json_rq)
        return upper_word
Ejemplo n.º 3
0
    async def send_message__internal_messager(self, word: str):
        sprint_f(f"send_message__internal_messager :: {word}")

        async with self.connection:
            routing_key = "reminder24:internal__messager:test_message"
            channel = await self.connection.channel()

            await channel.default_exchange.publish(
                aio_pika.Message(body=f"Hello {word}".encode()),
                routing_key=routing_key,
            )
        return
Ejemplo n.º 4
0
    async def send_message__internal_messager_new(self, word: str):
        sprint_f(f"send_message__internal_messager :: {word}")

        async with self.connection:
            routing_key = "reminder24:internal__messager:imperial_test"
            channel = await self.connection.channel()
            d = {}
            d['host'] = word
            await channel.default_exchange.publish(
                aio_pika.Message(body=json.dumps(d).encode()),
                routing_key=routing_key,
            )

        return
Ejemplo n.º 5
0
async def telegram_send_message(request):
    # {"chat_id": "218865388", "text": "adfsdf"}

    sprint_f(f"{request}")
    API_URL = "https://api.telegram.org/bot%s/sendMessage" % TELEGRAM_API_KEY

    headers = {"Content-Type": "application/json"}

    message = {"chat_id": request["chat_id"], "text": request["text"]}  # "218865388", # 813499020 , 831499020 , 111859928

    loop = asyncio.get_event_loop()
    resp = ""
    async with aiohttp.ClientSession(loop=loop) as session:
        async with session.post(API_URL, data=json.dumps(message), headers=headers) as response:
            if response.status == 200:
                pass
    return 1
Ejemplo n.º 6
0
def groups_show():
    for group in CHANNEL_GROUPS:
        sprint_f(f"\n{group}", "green")
        for channel in CHANNEL_GROUPS.get(group, {}):
            sprint_f(channel, "cyan")
            if channel._is_expired():
                sprint_f("expired", "red")
Ejemplo n.º 7
0
    async def authenticate(self, request):

        if "Authorization" not in request.headers:
            return None

        authorization = request.headers["Authorization"]
        token = self.get_token_from_header(authorization=authorization,
                                           prefix=self.prefix)

        try:
            jwt_payload = jwt.decode(token,
                                     key=str(self.secret_key),
                                     algorithms=self.algorithm)
        except jwt.InvalidTokenError:
            if DEBUG:
                sprint_f(f"Invalid JWT token", "red")
            raise AuthenticationError("Invalid JWT token")
        except jwt.ExpiredSignatureError:
            if DEBUG:
                sprint_f(f"Expired JWT token", "red")
            raise AuthenticationError("Expired JWT token")

        if DEBUG:
            sprint_f(f"Decoded JWT payload: {jwt_payload}",
                     "green")  # debug part, do not forget to remove it

        return (
            AuthCredentials(["authenticated"]),
            JWTUser(username=jwt_payload["username"],
                    user_id=jwt_payload["user_id"],
                    email=jwt_payload["email"],
                    token=token),
        )
Ejemplo n.º 8
0
async def insert_monitor_activity(monitor_id,
                                  connection_established,
                                  response_time,
                                  test=False):
    sprint_f(
        f"monitor_id = {monitor_id} :: connection_established= {connection_established} :: response_time = {response_time}",
        "yellow")

    connection_established = str(connection_established).lower()

    response_time = round(response_time, 6)
    response_seconds, response_microseconds = str(response_time).split(".")
    if len(response_seconds) == 1:
        response_seconds = f"0{response_seconds}"
    response_time = f"00:00:{response_seconds}.{response_microseconds}"

    creation_date = datetime.datetime.now()

    conn = await asyncpg.connect(DATABASE_URI)

    insert_monitor_activity_record = f"""  
    INSERT INTO "monitoring_monitoractivity" 
    ("monitor_id", "connection_establish", "response_time", "creation_date") 
    VALUES ({monitor_id}, {connection_established}, '{response_time}'::time, '{creation_date}'::timestamptz) 
    """
    sprint_f(insert_monitor_activity_record, "cyan")
    try:
        status = await conn.execute(insert_monitor_activity_record)
        sprint_f(status, "red")
    except:
        pass
    finally:
        await conn.close()

    return 1
Ejemplo n.º 9
0
async def private(request: Request) -> JSONResponse:

    try:
        payload = await request.json()
    except JSONDecodeError:
        sprint_f("cannot_parse_request_body", "red")
        raise HTTPException(status_code=HTTP_400_BAD_REQUEST,
                            detail="cannot_parse_request_body")

    if DEBUG:
        sprint_f(request.user, "yellow")
        sprint_f(payload, "yellow")

    return JSONResponse(payload)
Ejemplo n.º 10
0
    def get_token_from_header(cls, authorization: str, prefix: str):

        if DEBUG:
            sprint_f(f"JWT token from headers: {authorization}",
                     "cyan")  # debug part, do not forget to remove it
        try:
            scheme, token = authorization.split()
        except ValueError:
            if DEBUG:
                sprint_f(f"Could not separate Authorization scheme and token",
                         "red")
            raise AuthenticationError(
                "Could not separate Authorization scheme and token")
        if scheme.lower() != prefix.lower():
            if DEBUG:
                sprint_f(f"Authorization scheme {scheme} is not supported",
                         "red")
            raise AuthenticationError(
                f"Authorization scheme {scheme} is not supported")
        return token
async def upper_word__internal_messager(*, word):
    sprint_f(word)
    return word.upper()