Coverage for src/couchers/server.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from concurrent import futures
3import grpc
5from couchers import config
6from couchers.constants import SERVER_THREADS
7from couchers.interceptors import AuthValidatorInterceptor, ErrorSanitizationInterceptor, TracingInterceptor
8from couchers.servicers.account import Account
9from couchers.servicers.admin import Admin
10from couchers.servicers.api import API
11from couchers.servicers.auth import Auth
12from couchers.servicers.blocking import Blocking
13from couchers.servicers.bugs import Bugs
14from couchers.servicers.communities import Communities
15from couchers.servicers.conversations import Conversations
16from couchers.servicers.discussions import Discussions
17from couchers.servicers.donations import Donations, Stripe
18from couchers.servicers.events import Events
19from couchers.servicers.gis import GIS
20from couchers.servicers.groups import Groups
21from couchers.servicers.jail import Jail
22from couchers.servicers.media import Media, get_media_auth_interceptor
23from couchers.servicers.notifications import Notifications
24from couchers.servicers.pages import Pages
25from couchers.servicers.references import References
26from couchers.servicers.reporting import Reporting
27from couchers.servicers.requests import Requests
28from couchers.servicers.resources import Resources
29from couchers.servicers.search import Search
30from couchers.servicers.threads import Threads
31from proto import (
32 account_pb2_grpc,
33 admin_pb2_grpc,
34 api_pb2_grpc,
35 auth_pb2_grpc,
36 blocking_pb2_grpc,
37 bugs_pb2_grpc,
38 communities_pb2_grpc,
39 conversations_pb2_grpc,
40 discussions_pb2_grpc,
41 donations_pb2_grpc,
42 events_pb2_grpc,
43 gis_pb2_grpc,
44 groups_pb2_grpc,
45 jail_pb2_grpc,
46 media_pb2_grpc,
47 notifications_pb2_grpc,
48 pages_pb2_grpc,
49 references_pb2_grpc,
50 reporting_pb2_grpc,
51 requests_pb2_grpc,
52 resources_pb2_grpc,
53 search_pb2_grpc,
54 stripe_pb2_grpc,
55 threads_pb2_grpc,
56)
59def create_main_server(port):
60 server = grpc.server(
61 futures.ThreadPoolExecutor(SERVER_THREADS),
62 interceptors=[
63 ErrorSanitizationInterceptor(),
64 TracingInterceptor(),
65 AuthValidatorInterceptor(),
66 ],
67 )
68 server.add_insecure_port(f"[::]:{port}")
70 account_pb2_grpc.add_AccountServicer_to_server(Account(), server)
71 admin_pb2_grpc.add_AdminServicer_to_server(Admin(), server)
72 api_pb2_grpc.add_APIServicer_to_server(API(), server)
73 auth_pb2_grpc.add_AuthServicer_to_server(Auth(), server)
74 blocking_pb2_grpc.add_BlockingServicer_to_server(Blocking(), server)
75 bugs_pb2_grpc.add_BugsServicer_to_server(Bugs(), server)
76 communities_pb2_grpc.add_CommunitiesServicer_to_server(Communities(), server)
77 conversations_pb2_grpc.add_ConversationsServicer_to_server(Conversations(), server)
78 discussions_pb2_grpc.add_DiscussionsServicer_to_server(Discussions(), server)
79 donations_pb2_grpc.add_DonationsServicer_to_server(Donations(), server)
80 events_pb2_grpc.add_EventsServicer_to_server(Events(), server)
81 gis_pb2_grpc.add_GISServicer_to_server(GIS(), server)
82 groups_pb2_grpc.add_GroupsServicer_to_server(Groups(), server)
83 jail_pb2_grpc.add_JailServicer_to_server(Jail(), server)
84 notifications_pb2_grpc.add_NotificationsServicer_to_server(Notifications(), server)
85 pages_pb2_grpc.add_PagesServicer_to_server(Pages(), server)
86 references_pb2_grpc.add_ReferencesServicer_to_server(References(), server)
87 reporting_pb2_grpc.add_ReportingServicer_to_server(Reporting(), server)
88 requests_pb2_grpc.add_RequestsServicer_to_server(Requests(), server)
89 resources_pb2_grpc.add_ResourcesServicer_to_server(Resources(), server)
90 search_pb2_grpc.add_SearchServicer_to_server(Search(), server)
91 stripe_pb2_grpc.add_StripeServicer_to_server(Stripe(), server)
92 threads_pb2_grpc.add_ThreadsServicer_to_server(Threads(), server)
93 return server
96def create_media_server(port, threads=8):
97 media_server = grpc.server(
98 futures.ThreadPoolExecutor(threads),
99 interceptors=[TracingInterceptor(), get_media_auth_interceptor(config.config["MEDIA_SERVER_BEARER_TOKEN"])],
100 )
101 media_server.add_insecure_port(f"[::]:{port}")
102 media_pb2_grpc.add_MediaServicer_to_server(Media(), media_server)
103 return media_server