Skip to content

Commit

Permalink
feat(rpc): add UBO_GRPC_LISTEN_HOST and UBO_GRPC_LISTEN_PORT envi…
Browse files Browse the repository at this point in the history
…ronment variables
  • Loading branch information
sassanh committed Sep 28, 2024
1 parent c453747 commit b59cabc
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- feat(rpc): add reflection to rpc server, limited to root service, but good enough for health checking purposes
- refactor(rpc): preserve the order of fields of `oneof` declarations generated for `Union` types
- refactor(audio): convert `AudioPlayChimeEvent`s to `AudioPlayAudioEvent`s instead of directly playing the chime
- feat(rpc): add `UBO_GRPC_LISTEN_HOST` and `UBO_GRPC_LISTEN_PORT` environment variables

## Version 0.17.0

Expand Down
2 changes: 2 additions & 0 deletions ubo_app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
ENABLED_SERVICES = ENABLED_SERVICES.split(',') if ENABLED_SERVICES else []

DISABLE_GRPC = str_to_bool(os.environ.get('UBO_DISABLE_GRPC', 'False')) == 1
GRPC_LISTEN_HOST = os.environ.get('UBO_GRPC_LISTEN_HOST', '127.0.0.1')
GRPC_LISTEN_PORT = int(os.environ.get('UBO_GRPC_LISTEN_PORT', '50051'))

UPDATE_ASSETS_PATH = Path(f'{INSTALLATION_PATH}/_update/')
UPDATE_LOCK_PATH = UPDATE_ASSETS_PATH / 'update_is_ready.lock'
Expand Down
13 changes: 6 additions & 7 deletions ubo_app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@ def main() -> None:

start_event_loop_thread(asyncio.get_event_loop())

from ubo_app.constants import DISABLE_GRPC, HEIGHT, WIDTH

if not DISABLE_GRPC:
from ubo_app.rpc.server import serve as grpc_serve

worker_thread.run_task(grpc_serve())

import headless_kivy.config

from ubo_app.constants import DISABLE_GRPC, HEIGHT, WIDTH
from ubo_app.display import render_on_display

headless_kivy.config.setup_headless_kivy(
Expand All @@ -67,6 +61,11 @@ def main() -> None:

logger.info('----------------------Starting the app----------------------')

if not DISABLE_GRPC:
from ubo_app.rpc.server import serve as grpc_serve

worker_thread.run_task(grpc_serve())

load_services()
app = MenuApp()

Expand Down
8 changes: 3 additions & 5 deletions ubo_app/rpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from grpclib.reflection.service import ServerReflection
from grpclib.server import Server

from ubo_app.constants import GRPC_LISTEN_HOST, GRPC_LISTEN_PORT
from ubo_app.logging import logger
from ubo_app.rpc.service import StoreService

LISTEN_HOST = '127.0.0.1'
LISTEN_PORT = 50051


async def serve() -> None:
"""Serve the gRPC server."""
Expand All @@ -22,8 +20,8 @@ async def serve() -> None:

logger.error(
'Starting gRPC server',
extra={'host': LISTEN_HOST, 'port': LISTEN_PORT},
extra={'host': GRPC_LISTEN_HOST, 'port': GRPC_LISTEN_PORT},
)
await server.start(LISTEN_HOST, LISTEN_PORT)
await server.start(GRPC_LISTEN_HOST, GRPC_LISTEN_PORT)

await server.wait_closed()
12 changes: 2 additions & 10 deletions ubo_app/services/050-users/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ async def reset_password(event: UsersResetPasswordEvent) -> None:
@store.autorun(lambda state: state.users)
def users_menu(state: UsersState) -> Menu:
"""Get the SSH menu items."""
logger.info(state.users)
if state.users is None:
return HeadedMenu(
title='󰡉Users',
Expand Down Expand Up @@ -307,13 +306,6 @@ async def init_service() -> None:

async def get_users() -> list[UserState]:
paths = await accounts_service.list_cached_users()
logger.info(paths)
q = await _UserInterface.new_proxy(
bus=bus,
service_name='org.freedesktop.Accounts',
object_path=paths[0],
).user_name
logger.info(q)
return [
UserState(
id=(
Expand All @@ -332,12 +324,12 @@ async def get_users() -> list[UserState]:

async def monitor_user_added() -> None:
async for path in accounts_service.user_added:
logger.info('Users added', extra={'path': path})
logger.info('User added', extra={'path': path})
store.dispatch(UsersSetUsersAction(users=await get_users()))

async def monitor_user_deleted() -> None:
async for path in accounts_service.user_deleted:
logger.info('Users deleted', extra={'path': path})
logger.info('User deleted', extra={'path': path})
store.dispatch(UsersSetUsersAction(users=await get_users()))

create_task(monitor_user_added())
Expand Down

0 comments on commit b59cabc

Please sign in to comment.