mxcubecore.ipc.whitelist

Whitelist of HardwareObject methods callable over IPC.

See IPC_FORMAT.md, section 4, for the eligibility rules.

Functions

build_request_model(func)

Build a pydantic request model from the parameters of func.

build_whitelist(beamline, allowed_methods)

Build the whitelist from the configured "role.method" entries.

describe(registry)

Implementation of the _describe reserved IPC method.

dispatch(beamline, registry, method_path, params)

Validate params, call a whitelisted method and return a JSON-safe result.

ipc_method([request_model, response_model])

Mark a method as IPC-eligible with explicit request/response models.

validate_params(request_model, params)

Validate params and return them as keyword arguments.

Classes

WhitelistEntry(method_path, role, ...)

A resolved and validated whitelist entry.

Exceptions

IPCWhitelistError

Invalid whitelist configuration or call to a non-whitelisted method.

exception mxcubecore.ipc.whitelist.IPCWhitelistError[source]

Bases: Exception

Invalid whitelist configuration or call to a non-whitelisted method.

class mxcubecore.ipc.whitelist.WhitelistEntry(method_path: str, role: str, method_name: str, request_model: Type[BaseModel], response_type: Any)[source]

Bases: object

A resolved and validated whitelist entry.

Parameters:
  • method_path (str)

  • role (str)

  • method_name (str)

  • request_model (Type[BaseModel])

  • response_type (Any)

mxcubecore.ipc.whitelist.build_request_model(func: Callable) → Type[BaseModel][source]

Build a pydantic request model from the parameters of func.

Raises:

IPCWhitelistError – when a parameter is untyped, is *args/**kwargs, or has a type pydantic can’t handle.

Parameters:

func (Callable)

Return type:

Type[BaseModel]

mxcubecore.ipc.whitelist.build_whitelist(beamline: Any, allowed_methods: List[str]) → Dict[str, WhitelistEntry][source]

Build the whitelist from the configured “role.method” entries.

Raises:

IPCWhitelistError – when a role or method could not be resolved, or a method is not IPC-eligible.

Parameters:
Return type:

Dict[str, WhitelistEntry]

mxcubecore.ipc.whitelist.describe(registry: Dict[str, WhitelistEntry]) → Dict[str, Dict[str, Any]][source]

Implementation of the _describe reserved IPC method.

Returns request and response schemas for each whitelisted method.

Parameters:

registry (Dict[str, WhitelistEntry])

Return type:

Dict[str, Dict[str, Any]]

mxcubecore.ipc.whitelist.dispatch(beamline: Any, registry: Dict[str, WhitelistEntry], method_path: str, params: Dict[str, Any]) → Any[source]

Validate params, call a whitelisted method and return a JSON-safe result.

Raises:
  • IPCWhitelistError – when method_path is not whitelisted.

  • pydantic.ValidationError – when params don’t validate.

  • TypeError – when the method returns something other than its declared pydantic response model.

Parameters:
Return type:

Any

mxcubecore.ipc.whitelist.ipc_method(request_model: Type[BaseModel] | None = None, response_model: Type[BaseModel] | None = None) → Callable[[Callable], Callable][source]

Mark a method as IPC-eligible with explicit request/response models.

Only needed when the models can’t be inferred from the method signature.

Parameters:
  • request_model (Type[BaseModel] | None)

  • response_model (Type[BaseModel] | None)

Return type:

Callable[[Callable], Callable]

mxcubecore.ipc.whitelist.validate_params(request_model: Type[BaseModel], params: Dict[str, Any]) → Dict[str, Any][source]

Validate params and return them as keyword arguments.

Nested models stay model instances (unlike with model_dump()).

Raises:

pydantic.ValidationError – when params don’t validate.

Parameters:
Return type:

Dict[str, Any]