tlc.service.object_service#

The 3LC Object Service.

Module Contents#

Classes#

Class

Description

StarliteStateConstants

Constants for the Starlite state.

TLCObject

In-flight representation of a TLCObject.

TLCPatchRequest

In-flight representation of a patch request for a TLCObject.

DashboardManager

ObjectRoutesController

Controller for all object-related routes

ExternalDataRoutesController

Controller for all external data-related routes

TLCCustomLoggingMiddleware

Custom middleware to log object service requests and responses.

NGrokOutputAdaptor

Helper class to format output from NGrokHelper for the Object Service.

Functions#

Function

Description

internal_server_error_handler

Catch-all for application errors.

get_ip_addresses

get_running_urls

format_yaml_for_logging

open_in_chrome

startup

Setup HTTP client for connecting to 3LC Data Service

shutdown

Perform any required cleanup before terminating the application

root

Root endpoint of the service

get_last_lru_stats

status

Returns status of the service

create_starlite_app

Data#

Data

Description

last_lru_stats

API#

class tlc.service.object_service.StarliteStateConstants#

Constants for the Starlite state.

HOST_IP = HostIP#
OBJECT_SERVICE_RUNNING_URLS = ObjectServiceRunningsURLs#
NGROK_DASHBOARD_URL = NGrokDashboardURL#
NGROK_OBJECT_SERVICE_URL = NGrokObjectServiceURL#
DASHBOARD_URL = DashboardURL#
tlc.service.object_service.internal_server_error_handler(request: starlite.Request, exception: Exception) starlite.Response#

Catch-all for application errors.

class tlc.service.object_service.TLCObject#

Bases: pydantic.BaseModel

In-flight representation of a TLCObject.

type: str = None#
url: Optional[str] = None#
class Config#

Configuration.

extra = None#
orm_mode = True#
class tlc.service.object_service.TLCPatchRequest#

Bases: pydantic.BaseModel

In-flight representation of a patch request for a TLCObject.

patch_object: tlc.service.object_service.TLCObject = None#
patch_options: Dict[str, str] = None#
class Config#

Configuration.

extra = None#
orm_mode = True#
tlc.service.object_service.get_ip_addresses() list[str]#
tlc.service.object_service.get_running_urls() list[str]#
tlc.service.object_service.format_yaml_for_logging(data: dict | list, indent: int = 4) str#
tlc.service.object_service.open_in_chrome(url: str) None#
class tlc.service.object_service.DashboardManager(ngrok_helper_object_service: tlccli.subcommands.ngrok_helper.NGrokHelper | None)#
async start_dashboard(state: starlite.State) None#
wait_for_dashboard() None#
async stop_dashboard() None#
async tlc.service.object_service.startup(state: starlite.State) None#

Setup HTTP client for connecting to 3LC Data Service

async tlc.service.object_service.shutdown() None#

Perform any required cleanup before terminating the application

async tlc.service.object_service.root() starlite.Response#

Root endpoint of the service

tlc.service.object_service.last_lru_stats: dict[str, Any] | None = None#
tlc.service.object_service.get_last_lru_stats() dict[str, Any] | None#
async tlc.service.object_service.status(request: starlite.Request) dict[str, Any]#

Returns status of the service

class tlc.service.object_service.ObjectRoutesController(owner: starlite.router.Router)#

Bases: starlite.controller.Controller

Controller for all object-related routes

Initialize a controller.

Should only be called by routers as part of controller registration.

Args: owner: An instance of ‘Router’

path = /objects#
parameters = None#
async get_encoded_url(api_key: str, encoded_url: str) tlc.service.object_service.TLCObject#
async get_encoded_url_rows(api_key: str, encoded_url: str, attribute: str, request: starlite.Request) starlite.Response[bytes]#
async list_urls(api_key: str) list[str]#

Return all the objects.

Returns: List[Any]: List of the URLs of all the objects.

async new_object(api_key: str, data: tlc.service.object_service.TLCObject) starlite.Response#

Create a new object.

Parameters:

data – Object to be created

Returns:

Empty response. URL of the created object will be in the ‘Location’ field of the response headers.

async delete_object(api_key: str, encoded_url: str) None#

Delete an object.

Parameters:

encoded_url – URL of the object to be deleted.

Raises:

HTTPException if no object can be found at the URL.

async update_object(api_key: str, encoded_url: str, data: tlc.service.object_service.TLCPatchRequest) starlite.Response#

Update the attributes of an object.

Raises: HTTPException: If the object type of obj_in does not match the type of the object at object_url.

class tlc.service.object_service.ExternalDataRoutesController(owner: starlite.router.Router)#

Bases: starlite.controller.Controller

Controller for all external data-related routes

Initialize a controller.

Should only be called by routers as part of controller registration.

Args: owner: An instance of ‘Router’

path = /external_data#
parameters = None#
async get_encoded_url(api_key: str, encoded_url: str) bytes#
async get_encoded_url_binary_contents(api_key: str, encoded_url: str, format: str) starlite.Response#
class tlc.service.object_service.TLCCustomLoggingMiddleware(app: starlite.types.asgi_types.ASGIApp, config: starlite.middleware.LoggingMiddlewareConfig)#

Bases: starlite.middleware.logging.LoggingMiddleware

Custom middleware to log object service requests and responses.

Logs request and response data to loglevel.INFO, together with the time it takes to complete the request.

Initialize LoggingMiddleware.

Args: app: The next ASGI app to call. config: An instance of LoggingMiddlewareConfig.

async log_request(scope: starlite.types.asgi_types.Scope, receive: starlite.types.asgi_types.Receive) None#

Record the start time and log the request data.

log_response(scope: starlite.types.asgi_types.Scope) None#

Measure elapsed time and log the response data.

log_message(values: dict[str, Any]) None#

Log a message.

This is a copy of the superclass’ method, with special case handling of the /status endpoint, and url decoding of the path.

Parameters:

values – Extract values to log.

Returns:

None

class tlc.service.object_service.NGrokOutputAdaptor(role: str, ngrok_helper: tlccli.subcommands.ngrok_helper.NGrokHelper)#

Helper class to format output from NGrokHelper for the Object Service.

async output_public_url(state: starlite.State) None#
tlc.service.object_service.create_starlite_app(host: str, port: int, use_ngrok: bool, after_startup_handler: starlite.types.SingleOrList[starlite.types.LifeSpanHookHandler] | None = None, after_shutdown_handler: starlite.types.SingleOrList[starlite.types.LifeSpanHookHandler] | None = None) starlite.Starlite#