Пример #1
0
            self.logger.add(ZipkinAdapter(cfg.log_zipkin))

    @property
    def lock(self) -> Lock:
        cmp: Optional[Lock] = self.get('lock')  # type: ignore
        if cmp is None:
            raise AttributeError
        return cmp


if __name__ == "__main__":
    """
    Usage:

    APP_LOG_ZIPKIN_ENABLED=1 \
    APP_LOG_ZIPKIN_ADDR=http://127.0.0.1:9002/api/v2/spans \
    APP_LOG_ZIPKIN_NAME=server \
    APP_LOCK_URL=redis://127.0.0.1:9008/0 \
    python -m examples.lock

    APP_LOG_ZIPKIN_ENABLED=1 \
    APP_LOG_ZIPKIN_ADDR=http://127.0.0.1:9002/api/v2/spans \
    APP_LOG_ZIPKIN_NAME=server \
    APP_LOCK_URL=postgres://ipapp:[email protected]:9001/ipapp \
    python -m examples.lock

    curl http://localhost:8080/1 & curl http://localhost:8080/2 & curl http://localhost:8080/2 &
    """
    logging.basicConfig(level=logging.INFO)
    main(sys.argv, '0', App, Config)
Пример #2
0

class App(BaseApplication):
    def __init__(self, cfg: Config) -> None:
        super().__init__(cfg)

        if cfg.log_prometheus.enabled:
            self.logger.add(PrometheusAdapter(cfg.log_prometheus))
        if cfg.log_zipkin.enabled:
            self.logger.add(ZipkinAdapter(cfg.log_zipkin))
        if cfg.log_sentry.enabled:
            self.logger.add(SentryAdapter(cfg.log_sentry))
        if cfg.log_requests.enabled:
            self.logger.add(RequestsAdapter(cfg.log_requests))

        self.add('srv', Uvicorn(cfg.asgi, fapp))


if __name__ == "__main__":
    """
    Usage:

APP_LOG_ZIPKIN_ENABLED=1 \
APP_LOG_ZIPKIN_ADDR=http://127.0.0.1:9002/api/v2/spans \
APP_LOG_ZIPKIN_NAME=client \
python -m examples.fastapi --log-level CRITICAL
    """

    logging.basicConfig(level=logging.INFO)
    main(sys.argv, '0.0.1', App, Config)
Пример #3
0
    description="Идентификатор пользователя",
)) -> User:
    return User(id=id, name="User%d" % id)


class App(BaseApplication):
    def __init__(self, cfg: Config) -> None:
        super().__init__(cfg)
        self.add("srv",
                 Server(cfg.rpc, RestRpcHttpHandler(api, cfg.rpc_handler)))
        if cfg.log_prometheus.enabled:
            self.logger.add(PrometheusAdapter(cfg.log_prometheus))
        if cfg.log_zipkin.enabled:
            self.logger.add(ZipkinAdapter(cfg.log_zipkin))
        if cfg.log_sentry.enabled:
            self.logger.add(SentryAdapter(cfg.log_sentry))
        if cfg.log_requests.enabled:
            self.logger.add(RequestsAdapter(cfg.log_requests))


if __name__ == "__main__":
    """
    APP_LOG_ZIPKIN_ENABLED=1 \
    APP_LOG_ZIPKIN_ADDR=http://127.0.0.1:9411/api/v2/spans \
    APP_LOG_ZIPKIN_NAME=rpc-server \
    python3 -m examples.http_restrpc_server

    """
    logging.basicConfig(level=logging.INFO)
    main(sys.argv, "0.0.1", App, Config)
Пример #4
0
    async def pdf_handler(self, request: Request) -> Response:
        obj = await self.app.s3.get_object('file.pdf')
        return Response(body=obj.body, content_type=obj.content_type)

    async def png_handler(self, request: Request) -> Response:
        async with self.app.s3 as s3:
            obj = await s3.get_object('file.png')
            return Response(body=obj.body, content_type=obj.content_type)

    async def jpg_handler(self, request: Request) -> Response:
        async with self.app.s3.create_client() as client:
            bucket = self.app.s3.bucket_name
            obj = await client.get_object(Key='file.jpg', Bucket=bucket)
            async with obj['Body'] as f:
                body = await f.read()
                return Response(body=body, content_type=obj['ContentType'])


if __name__ == '__main__':
    """
    Usage:

    APP_S3_ENDPOINT_URL=http://localhost:9000 \
    APP_S3_AWS_ACCESS_KEY_ID=EXAMPLEACCESSKEY \
    APP_S3_AWS_SECRET_ACCESS_KEY=EXAMPLESECRETKEY \
    python -m examples.s3
    """

    logging.basicConfig(level=logging.INFO)
    main(sys.argv, '1.0.0', App, Config)
Пример #5
0
        gender: Optional[Gender] = Field(None, description="Gender"),
        passport: Optional[Passport] = Field(None, description="Passport"),
        is_active: bool = Field(False, deprecated=True),
    ) -> UpdateCustomerResponse:
        if customer_id == UUID("435ff4ec-ac73-413c-ad4d-270020a354de"):
            raise CustomerNotFound
        return UpdateCustomerResponse(customer_id=customer_id,
                                      username=username)

    @method(deprecated=True)
    async def delete_customer(self, customer_id: UUID) -> UUID:
        return customer_id

    @method(
        request_ref="/api.json#/components/schemas/Request",  # type: ignore
        response_ref="/api.json#/components/schemas/Response",
    )
    async def find_customer(self, **kwargs) -> None:
        pass


class App(BaseApplication):
    def __init__(self, cfg: Config) -> None:
        super().__init__(cfg)
        self.add("srv", Server(cfg.http, RpcHandler(Api(), cfg.handler)))


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    main(sys.argv, VERSION, App, Config)