Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
invoke_without_command=True, context_settings={"auto_envvar_prefix": "BLUEAPI"}
)
@click.version_option(version=__version__, prog_name="blueapi")
@click.option("-H", "--host", type=str)
@click.option(
"-c", "--config", type=Path, help="Path to configuration YAML file", multiple=True
)
@click.pass_context
def main(ctx: click.Context, config: tuple[Path, ...]) -> None:
def main(ctx: click.Context, config: tuple[Path, ...], host: str | None):
# if no command is supplied, run with the options passed

# Set umask to DLS standard
Expand All @@ -64,6 +65,8 @@ def main(ctx: click.Context, config: tuple[Path, ...]) -> None:
config_loader.use_values_from_yaml(*config)
except FileNotFoundError as fnfe:
raise ClickException(f"Config file not found: {fnfe.filename}") from fnfe
if host:
config_loader.use_values({"api": {"url": host}})

loaded_config: ApplicationConfig = config_loader.load()

Expand Down
13 changes: 7 additions & 6 deletions src/blueapi/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ def from_config(cls, config: ApplicationConfig) -> "BlueapiClient":
except Exception:
... # Swallow exceptions
rest = BlueapiRestClient(config.api, session_manager=session_manager)
if config.stomp.enabled:
assert config.stomp.url.host is not None, "Stomp URL missing host"
assert config.stomp.url.port is not None, "Stomp URL missing port"
stomp_config = config.stomp if config.stomp.enabled else rest.get_stomp_config()
if stomp_config and stomp_config.enabled:
assert stomp_config.url.host is not None, "Stomp URL missing host"
assert stomp_config.url.port is not None, "Stomp URL missing port"
client = StompClient.for_broker(
broker=Broker(
host=config.stomp.url.host,
port=config.stomp.url.port,
auth=config.stomp.auth,
host=stomp_config.url.host,
port=stomp_config.url.port,
auth=stomp_config.auth,
)
)
events = EventBusClient(client)
Expand Down
5 changes: 4 additions & 1 deletion src/blueapi/client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
)
from pydantic import BaseModel, TypeAdapter, ValidationError

from blueapi.config import RestConfig
from blueapi.config import RestConfig, StompConfig
from blueapi.service.authentication import JWTAuth, SessionManager
from blueapi.service.model import (
DeviceModel,
Expand Down Expand Up @@ -230,6 +230,9 @@ def get_oidc_config(self) -> OIDCConfig | None:
# Server is not using authentication
return None

def get_stomp_config(self) -> StompConfig | None:
return self._request_and_deserialize("/config/stomp", StompConfig)

def get_python_environment(
self, name: str | None = None, source: SourceInfo | None = None
) -> PythonEnvironmentResponse:
Expand Down
4 changes: 4 additions & 0 deletions src/blueapi/service/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def get_oidc_config() -> OIDCConfig | None:
return config().oidc


def get_stomp_config() -> StompConfig | None:
return config().stomp


def get_python_env(
name: str | None = None, source: SourceInfo | None = None
) -> PythonEnvironmentResponse:
Expand Down
18 changes: 17 additions & 1 deletion src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from starlette.responses import JSONResponse
from super_state_machine.errors import TransitionError

from blueapi.config import ApplicationConfig, OIDCConfig, Tag
from blueapi.config import ApplicationConfig, OIDCConfig, StompConfig, Tag
from blueapi.service import interface
from blueapi.worker import TrackableTask, WorkerState
from blueapi.worker.event import TaskStatusEnum
Expand Down Expand Up @@ -224,6 +224,22 @@ def get_oidc_config(
return config


@open_router.get(
"/config/stomp",
tags=[Tag.META],
responses={status.HTTP_204_NO_CONTENT: {"description": "No Stomp configured"}},
)
@start_as_current_span(TRACER)
def get_stomp_config(
runner: Annotated[WorkerDispatcher, Depends(_runner)],
) -> StompConfig:
"""Retrieve the stomp configuration for the server."""
config = runner.run(interface.get_stomp_config)
if config is None:
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT)
return config


@secure_router.get("/plans", tags=[Tag.PLAN])
@start_as_current_span(TRACER)
def get_plans(runner: Annotated[WorkerDispatcher, Depends(_runner)]) -> PlanResponse:
Expand Down
Loading