Transport
REST transport layer — HTTP abstraction over requests.
All REST calls go through RestTransport. This is the single point of change when migrating the way we do the REST communication.
- Classes:
ServerInfo: Parsed capabilities from GET /api/v1/info. FileAccessConfig: Parsed response from GET /api/v1/config/file-access. RestTransport: Thin HTTP client with auth, timeout, and transfer mode support. RestResponse: Lightweight response wrapper (not leaked to users).
- exception mitk_workbench_remote.transport.InsecureTransportWarning
Bases:
UserWarningAn API token is being sent over an unencrypted connection.
Emitted when a token is configured for a plain
http://URL whose host is not loopback: theAuthorization: Bearerheader then travels in cleartext and can be intercepted in transit. Preferhttpsfor remote hosts. Silence withwarnings.filterwarnings("ignore", category=InsecureTransportWarning)when the connection runs over a trusted network.
- class mitk_workbench_remote.transport.TransferMode(*values)
-
Transfer modes supported by the MITK REST server.
- DIRECT = 'direct'
- FILE_REFERENCE = 'file-reference'
- class mitk_workbench_remote.transport.FileAccessMode(*values)
-
File-access restriction modes reported by GET /api/v1/config/file-access.
- UNRESTRICTED = 'unrestricted'
- ALLOWED_DIRECTORIES = 'allowed-directories'
- class mitk_workbench_remote.transport.ServerInfo(name, api_version, mitk_version, transfer_modes=<factory>)
Bases:
objectParsed response from GET /api/v1/info.
- Parameters:
name (
str) – Human-readable server name.api_version (
str) – API version string (e.g."v1").mitk_version (
str) – Underlying MITK version string.transfer_modes (
tuple[str,...] (default:<factory>)) – Transfer modes advertised by the server. Kept as plain strings (notTransferModeenum) so that unknown modes from future server versions are preserved rather than causing aValueErrorat parse time.
- class mitk_workbench_remote.transport.FileAccessConfig(mode, restrictions_active, max_active_temp_dirs_per_ip, allowed_paths=<factory>)
Bases:
objectParsed response from GET /api/v1/config/file-access.
- Parameters:
mode (
FileAccessMode) – Access mode —FileAccessMode.UNRESTRICTEDorFileAccessMode.ALLOWED_DIRECTORIES.restrictions_active (
bool) – Whether path restrictions are enforced.max_active_temp_dirs_per_ip (
int) – Server-side limit on concurrent temp directories per client IP. Used by file-reference transfer logic to avoid unexpected server-side eviction.allowed_paths (
tuple[str,...] (default:<factory>)) – Allowed base paths whenrestrictions_activeis True.
- mode: FileAccessMode
- class mitk_workbench_remote.transport.RestResponse(response)
Bases:
objectThin wrapper around requests.Response. Never returned to users directly.
- Parameters:
response (
Response) – The underlying requests Response object.
- class mitk_workbench_remote.transport.RestTransport(base_url, *, token=None, timeout=30.0, transfer_mode=None, trust_env=None)
Bases:
objectHTTP client with auth, timeout, and transfer-mode support.
All REST calls made by the library go through this class. Nothing outside this module imports the underlying used dependency directly.
- Parameters:
base_url (
str) – Base URL of the MITK Workbench REST server (e.g."http://localhost:8080"). Trailing slash is stripped.token (
str|None(default:None)) – Optional API token sent as theAuthorization: Bearer <token>header. Sending a token to a non-localhttp://host emits anInsecureTransportWarning, since the header travels in cleartext.timeout (
float(default:30.0)) – Request timeout in seconds. Defaults to 30.transfer_mode (
TransferMode|str|None(default:None)) – Override transfer mode (TransferMode.DIRECTorTransferMode.FILE_REFERENCE). WhenNone(default) the mode is auto-detected on first access via server capabilities. A plain string is accepted for convenience; an unrecognised value raisesValueErrorimmediately.trust_env (
bool|None(default:None)) – Whether to honor environment proxy settings (HTTP_PROXY/HTTPS_PROXY/NO_PROXY), the env CA bundle, and.netrc. WhenNone(default) this is decided automatically:Falsefor loopback targets (a forward/corporate proxy cannot route to the caller’s own machine, so honoring it would send the request to the proxy, which typically rejects it with a 403),Truefor remote hosts. PassTrueto always honor env proxies orFalseto never.
- property server_info: ServerInfo
Server capabilities, fetched once from GET /api/v1/info and cached.
- property file_access_config: FileAccessConfig
File-reference configuration, fetched once from GET /config/file-access and cached.
- property transfer_mode: TransferMode
Preferred transfer mode for data requests.
Resolution order:
Explicit value set in the constructor.
TransferMode.FILE_REFERENCEif the server advertises it inGET /api/v1/infocapabilities AND the server is on localhost (filesystem access required).TransferMode.DIRECTotherwise.
Cached after first resolution.
- get(path, **kwargs)
Send a GET request.
- Return type:
- post(path, **kwargs)
Send a POST request.
- Return type:
- put(path, **kwargs)
Send a PUT request.
- Return type:
- patch(path, **kwargs)
Send a PATCH request.
- Return type:
- delete(path, **kwargs)
Send a DELETE request.
- Return type:
- get_binary(path, **kwargs)
Send a GET request for binary data, advertising the preferred transfer mode.
- Return type:
- put_binary(path, data, **kwargs)
Send a PUT request with raw bytes as the body.
- Return type:
- put_file_reference(path, *, file_path, **kwargs)
Send a PUT with file-reference transfer mode (JSON body with file path).
- Return type: