Skip to content
Merged
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
17 changes: 9 additions & 8 deletions src/murfey/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from threading import Thread
from typing import Any, Dict, List, NamedTuple, Tuple

import graypy
import mrcfile
import numpy as np
import uvicorn
import workflows
import zocalo.configuration
from backports.entry_points_selectable import entry_points
from fastapi import Request
from fastapi.templating import Jinja2Templates
Expand Down Expand Up @@ -273,17 +273,19 @@ def run():
default=0,
)

security_config = get_security_config()
# setup logging
zc = zocalo.configuration.from_file()
zc.activate()
if security_config.graylog_host:
handler = graypy.GELFUDPHandler(
security_config.graylog_host, security_config.graylog_port, level_names=True
)
root_logger = logging.getLogger()
root_logger.addHandler(handler)

# Install a log filter to all existing handlers.
# At this stage this will exclude console loggers, but will cover
# any Graylog logging set up by the environment activation
LogFilter.install()

zc.add_command_line_options(parser)
workflows.transport.add_command_line_options(parser, transport_argument=True)
workflows.transport.load_configuration_file(security_config.rabbitmq_credentials)

args = parser.parse_args()

Expand All @@ -296,7 +298,6 @@ def run():
# Set up logging now that the desired verbosity is known
_set_up_logging(quiet=args.quiet, verbosity=args.verbose)

security_config = get_security_config()
if not args.temporary and _transport_object:
_transport_object.feedback_queue = security_config.feedback_queue
rabbit_thread = Thread(
Expand Down
14 changes: 13 additions & 1 deletion src/murfey/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import yaml
from backports.entry_points_selectable import entry_points
from pydantic import BaseModel, BaseSettings, Extra
from pydantic import BaseModel, BaseSettings, Extra, validator


class MachineConfig(BaseModel, extra=Extra.allow): # type: ignore
Expand Down Expand Up @@ -82,6 +82,7 @@ def from_file(config_file_path: Path, instrument: str = "") -> Dict[str, Machine


class Security(BaseModel):
rabbitmq_credentials: str
murfey_db_credentials: str
crypto_key: str
auth_key: str = ""
Expand All @@ -93,6 +94,16 @@ class Security(BaseModel):
auth_type: Literal["password", "cookie"] = "password"
cookie_key: str = ""
feedback_queue: str = "murfey_feedback"
graylog_host: str = ""
graylog_port: Optional[int] = None

@validator("graylog_port")
def check_port_present_if_host_is(
cls, v: Optional[int], values: dict, **kwargs
) -> Optional[int]:
if values["graylog_host"] and v is None:
raise ValueError("The Graylog port must be set if the Graylog host is")
return v


def security_from_file(config_file_path: Path) -> Security:
Expand Down Expand Up @@ -133,6 +144,7 @@ def get_security_config() -> Security:
if machine_config.security_configuration_path:
return security_from_file(machine_config.security_configuration_path)
return Security(
rabbitmq_credentials="",
session_validation="",
murfey_db_credentials="",
crypto_key="",
Expand Down
Loading