Exemple #1
0
def create_media_server(port, threads=8):
    media_server = grpc.server(
        futures.ThreadPoolExecutor(threads),
        interceptors=[
            TracingInterceptor(),
            get_media_auth_interceptor(
                config.config["MEDIA_SERVER_BEARER_TOKEN"])
        ],
    )
    media_server.add_insecure_port(f"[::]:{port}")
    media_pb2_grpc.add_MediaServicer_to_server(Media(), media_server)
    return media_server
Exemple #2
0
def media_session(bearer_token):
    """
    Create a fresh Media API for testing, uses the bearer token for media auth
    """
    media_auth_interceptor = get_media_auth_interceptor(bearer_token)

    with futures.ThreadPoolExecutor(1) as executor:
        server = grpc.server(executor, interceptors=[media_auth_interceptor])
        port = server.add_secure_port("localhost:0", grpc.local_server_credentials())
        servicer = Media()
        media_pb2_grpc.add_MediaServicer_to_server(servicer, server)
        server.start()

        call_creds = grpc.access_token_call_credentials(bearer_token)
        comp_creds = grpc.composite_channel_credentials(grpc.local_channel_credentials(), call_creds)

        try:
            with grpc.secure_channel(f"localhost:{port}", comp_creds) as channel:
                yield media_pb2_grpc.MediaStub(channel)
        finally:
            server.stop(None).wait()
Exemple #3
0
        Discussions(), server)
    gis_pb2_grpc.add_GISServicer_to_server(GIS(), server)
    groups_pb2_grpc.add_GroupsServicer_to_server(Groups(), server)
    pages_pb2_grpc.add_PagesServicer_to_server(Pages(), server)
    references_pb2_grpc.add_ReferencesServicer_to_server(References(), server)
    requests_pb2_grpc.add_RequestsServicer_to_server(Requests(), server)
    search_pb2_grpc.add_SearchServicer_to_server(Search(), server)
    threads_pb2_grpc.add_ThreadsServicer_to_server(Threads(), server)

    server.start()

    media_server = grpc.server(
        futures.ThreadPoolExecutor(2),
        interceptors=[
            LoggingInterceptor(),
            get_media_auth_interceptor(
                config.config["MEDIA_SERVER_BEARER_TOKEN"])
        ],
    )
    media_server.add_insecure_port("[::]:1753")
    media_pb2_grpc.add_MediaServicer_to_server(Media(), media_server)
    media_server.start()

    logger.info(
        f"Serving on 1751 (secure), 1752 (auth), 1753 (media), and 1754 (jailed)"
    )

if config.config["ROLE"] in ["scheduler", "all"]:
    scheduler = start_jobs_scheduler()

if config.config["ROLE"] in ["worker", "all"]:
    worker = start_jobs_worker()
Exemple #4
0
    interceptors=[
        LoggingInterceptor(),
        auth.get_auth_interceptor(allow_jailed=False),
        UpdateLastActiveTimeInterceptor(servicer.update_last_active_time),
    ],
)
server.add_insecure_port("[::]:1751")

account_pb2_grpc.add_AccountServicer_to_server(Account(Session), server)
api_pb2_grpc.add_APIServicer_to_server(servicer, server)
conversations_pb2_grpc.add_ConversationsServicer_to_server(Conversations(Session), server)
requests_pb2_grpc.add_RequestsServicer_to_server(Requests(Session), server)
sso_pb2_grpc.add_SSOServicer_to_server(SSO(Session), server)

server.start()

media_server = grpc.server(
    futures.ThreadPoolExecutor(2),
    interceptors=[LoggingInterceptor(), get_media_auth_interceptor(MEDIA_SERVER_BEARER_TOKEN)],
)
media_server.add_insecure_port("[::]:1753")
media_pb2_grpc.add_MediaServicer_to_server(Media(Session), media_server)
media_server.start()

logger.info(f"Serving on 1751 (secure), 1752 (auth), 1753 (media), and 1754 (jailed)")

server.wait_for_termination()
jailed_server.wait_for_termination()
auth_server.wait_for_termination()
media_server.wait_for_termination()