API
API Implemenation for the Customizer to start and control the payload processing.
lifespan(app)
async
Lifespan function for FASTAPI to handle the startup and shutdown process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
FastAPI
|
The FastAPI application. |
required |
Source code in packages/pyxecm/src/pyxecm_api/app.py
run_api()
Start the FastAPI Webserver.
Source code in packages/pyxecm/src/pyxecm_api/app.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
|
Utility library to handle the authentication with OTDS.
login(form_data)
async
Login using OTDS and return a token.
Source code in packages/pyxecm/src/pyxecm_api/auth/router.py
read_users_me(current_user)
async
Get the current user.
current_user (User): The current user.
Source code in packages/pyxecm/src/pyxecm_api/auth/router.py
Models for FastAPI.
User
Bases: BaseModel
Model for users authenticated by OTDS.
Source code in packages/pyxecm/src/pyxecm_api/auth/models.py
Utility library to handle the authentication with OTDS.
get_authorized_user(current_user)
async
Check if the user is authorized (member of the Group otadmin@otds.admin).
Source code in packages/pyxecm/src/pyxecm_api/auth/functions.py
get_current_user(token, api_key)
async
Get the current user from OTDS and verify it.
Source code in packages/pyxecm/src/pyxecm_api/auth/functions.py
get_groups(response, token)
Get the groups of the user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
response
|
dict
|
description |
required |
token
|
str
|
description |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
description |
Source code in packages/pyxecm/src/pyxecm_api/auth/functions.py
get_otcsticket(otcsticket)
async
Check if the user is authorized (member of the Group otadmin@otds.admin).
API Implemenation for the Customizer to start and control the payload processing.
get_browser_automation_file(user, file)
Download the logfile for a specific payload.
Source code in packages/pyxecm/src/pyxecm_api/common/router.py
get_status()
async
Get the status of the Customizer.
Source code in packages/pyxecm/src/pyxecm_api/common/router.py
list_browser_automation_files(user)
List all browser automation files.
Source code in packages/pyxecm/src/pyxecm_api/common/router.py
redirect_to_api(request)
async
Redirect from / to /api.
Returns:
Type | Description |
---|---|
RedirectResponse
|
None |
shutdown(user)
Endpoint to end the application.
Source code in packages/pyxecm/src/pyxecm_api/common/router.py
Metics for payload logs.
payload_logs_by_payload(payload_list)
Metrics for payload logs by payload.
Source code in packages/pyxecm/src/pyxecm_api/common/metrics.py
payload_logs_total(payload_list)
Metrics for total payload logs messages.
Source code in packages/pyxecm/src/pyxecm_api/common/metrics.py
Define common functions.
build_graph()
Build the knowledge Graph. And keep it updated every hour.
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
get_k8s_object()
get_knowledgegraph_object()
Get the Knowledge Graph object.
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
get_ontology()
Get the ontology for the knowledge graph.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The ontology as a dictionary. |
get_otca_object(otcs_object=None)
Get the Content Aviator (OTCA) object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
otcs_object
|
OTCS | None
|
The Content Server (OTCS) object. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
OTCA |
OTCA
|
The new Content Aviator object. |
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
get_otcs_logs_lock()
Get the Logs LOCK dict.
Returns:
Type | Description |
---|---|
dict
|
The dict with all LOCKS for the logs |
get_otcs_object()
Get an instance of a Content Server (OTCS) object.
Returns:
Name | Type | Description |
---|---|---|
OTCS |
OTCS
|
Return a new OTCS object. |
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
get_otcs_object_from_otcsticket(otcs_ticket)
Get an instance of a Content Server (OTCS) object.
Returns:
Name | Type | Description |
---|---|---|
OTCS |
OTCS
|
Return an OTCS object. |
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
get_settings()
Get the API Settings object.
Returns:
Name | Type | Description |
---|---|---|
CustomizerPISettings |
CustomizerAPISettings
|
Returns the API Settings. |
list_files_in_directory(directory)
Recursively list files in a directory and return a nested JSON structure with URLs.
Source code in packages/pyxecm/src/pyxecm_api/common/functions.py
Define router for v1_maintenance.
embed_metadata(user, otcs_object, body)
Embed the Metadata of the given objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Annotated[User, Depends
|
User required for authentication. |
required |
otcs_object
|
Annotated[OTCS, Depends(get_otcs_object)]
|
The OTCS object to interact with OTCM (Content Server). |
required |
body
|
Annotated[CSAIEmbedMetadata, Body
|
The request body. |
required |
Returns:
Name | Type | Description |
---|---|---|
JSONResponse |
JSONResponse
|
JSONResponse with success=true/false |
Source code in packages/pyxecm/src/pyxecm_api/v1_csai/router.py
get_csai_config_data(user, k8s_object, settings)
Get the csai config data.
Source code in packages/pyxecm/src/pyxecm_api/v1_csai/router.py
get_csai_graph(name)
Display the graph of the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the CSAI graph. |
required |
Returns:
Name | Type | Description |
---|---|---|
HTMLResponse |
HTMLResponse
|
Visualization of the CSAI graph |
Source code in packages/pyxecm/src/pyxecm_api/v1_csai/router.py
set_csai_config_data(user, settings, k8s_object, config)
Set the CSAI config data.
Source code in packages/pyxecm/src/pyxecm_api/v1_csai/router.py
Define router for v1_maintenance.
set_maintenance_mode_options(user, k8s_object, config)
async
Configure the Maintenance Mode and set options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
User
|
Added to enforce authentication requirement |
required |
k8s_object
|
K8s
|
K8s object instance of pyxecm K8s class |
required |
config
|
MaintenanceModel
|
instance of the Maintenance Model |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
MaintenanceModel
|
description |
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/router.py
status(user, k8s_object)
async
Return status of maintenance mode.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
User
|
Added to enforce authentication requirement |
required |
k8s_object
|
K8s
|
K8s object instance of pyxecm K8s class |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
MaintenanceModel
|
Details of maintenance mode. |
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/router.py
Define Models for the Maintenance Page Config.
MaintenanceModel
Bases: BaseModel
Status object of the Maintenance Page.
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/models.py
Define functions for v1_maintenance.
get_cshost(k8s_object)
Get the cs_hostname from the environment Variable OTCS_PUBLIC_HOST otherwise read it from the otcs-frontend-configmap.
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/functions.py
get_maintenance_mode_status(k8s_object)
Get status of maintenance mode.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
Details of maintenance mode. |
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/functions.py
set_maintenance_mode_via_ingress(enabled, k8s_object)
Set maintenance mode.
Source code in packages/pyxecm/src/pyxecm_api/v1_maintenance/functions.py
Define router for v1_otcs.
delete_otcs_log_file(user, settings, file_name)
async
Delete single OTCS log archive.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
delete_otcs_log_files(user, settings)
async
Delete all otcs log files.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
get_otcs_log_file(user, settings, file_name)
async
Download OTCS log archive.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
get_otcs_log_files(user, settings, k8s_object, otcs_logs_lock)
async
List all otcs logs that can be downloaded.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
post_otcs_log_file(file, settings, key='')
async
Upload a file to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Annotated[UploadFile, File(...)]
|
File to be uploaded. |
required |
settings
|
Annotated[CustomizerAPISettings, Depends(get_settings)]
|
CustomizerAPISettings. |
required |
key
|
str
|
Key to validate the upload. |
''
|
Returns:
Name | Type | Description |
---|---|---|
JSONResponse |
JSONResponse
|
Status of the upload |
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
put_otcs_logs(user, k8s_object, settings, otcs_logs_lock, hosts)
async
Collect the logs from the given OTCS instances.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/router.py
Define functions for v1_otcs.
collect_otcs_logs(host, k8s_object, logs_lock, settings)
Collect the logs for the given OTCS instance.
Source code in packages/pyxecm/src/pyxecm_api/v1_otcs/functions.py
Define router for v1_payload.
create_payload_item(user, settings, upload_file, name='', dependencies=None, enabled=True, loglevel='INFO')
Upload a new payload item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
User
|
The user who is uploading the payload. Defaults to None. |
required |
settings
|
CustomizerAPISettings
|
The settings object. |
required |
upload_file
|
UploadFile
|
The file to upload. Defaults to File(...). |
required |
name
|
str
|
The name of the payload (if not provided we will use the file name). |
''
|
dependencies
|
list of integers
|
List of other payload items this item depends on. |
None
|
enabled
|
bool
|
Flag indicating if the payload is enabled or not. |
True
|
loglevel
|
str
|
The loglevel for the payload processing. Defaults to "INFO". |
'INFO'
|
Raises:
Type | Description |
---|---|
HTTPException
|
Raised, if payload list is not initialized. |
Returns:
Name | Type | Description |
---|---|---|
dict |
PayloadListItem
|
The HTTP response. |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
delete_payload_item(user, payload_id)
async
Delete an existing payload item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Optional[User]
|
User performing the update. |
required |
payload_id
|
int
|
The ID of the payload to update. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
JSONResponse
|
response or None |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
download_payload_content(user, payload_id)
Download the payload for a specific payload item.
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
download_payload_logfile(user, payload_id)
Download the logfile for a specific payload.
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
get_payload_content(user, payload_id)
async
Get a payload item based on its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Annotated[User, Depends(get_authorized_user)]
|
Annotated[User, Depends(get_authorized_user)] |
required |
payload_id
|
int
|
The payload item ID. |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
A payload item with the given ID couldn't be found. |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict | None
|
HTTP response. |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
get_payload_item(user, payload_id)
async
Get a payload item based on its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Annotated[User, Depends(get_authorized_user)]
|
Annotated[User, Depends(get_authorized_user)] |
required |
payload_id
|
int
|
payload item ID |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
a payload item with the given ID couldn't be found |
Returns:
Name | Type | Description |
---|---|---|
dict |
PayloadListItem
|
HTTP response. |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
get_payload_items(user)
async
Get all Payload items.
Raises:
Type | Description |
---|---|
HTTPException
|
payload list not initialized |
HTTPException
|
payload list is empty |
Returns:
Name | Type | Description |
---|---|---|
dict |
PayloadListItems
|
HTTP response with the result data |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
move_payload_item_down(user, payload_id)
async
Move a payload item down in the list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Annotated[User, Depends(get_authorized_user)]
|
Annotated[User, Depends(get_authorized_user)] |
required |
payload_id
|
int
|
The payload item ID. |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
a payload item with the given ID couldn't be found |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
HTTP response |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
move_payload_item_up(user, payload_id)
async
Move a payload item up in the list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Annotated[User, Depends(get_authorized_user)]
|
Annotated[User, Depends(get_authorized_user)] |
required |
payload_id
|
int
|
payload item ID |
required |
Raises:
Type | Description |
---|---|
HTTPException
|
a payload item with the given ID couldn't be found |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
HTTP response |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
stream_logfile(user, payload_id)
async
Stream the logfile and follow changes.
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
update_payload_item(user, payload_id, name=None, dependencies=None, enabled=None, status=None, loglevel=None, customizer_settings=None)
async
Update an existing payload item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user
|
Optional[User]
|
User performing the update. |
required |
payload_id
|
int
|
ID of the payload to update. |
required |
upload_file
|
UploadFile
|
replace the file name |
required |
name
|
Optional[str]
|
Updated name. |
None
|
dependencies
|
Optional[List[int]]
|
Updated list of dependencies. |
None
|
enabled
|
Optional[bool]
|
Updated enabled status. |
None
|
loglevel
|
Optional[str]
|
Updated loglevel. |
None
|
status
|
Optional[str]
|
Updated status. |
None
|
customizer_settings
|
Optional[str]
|
Updated customizer settings. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
UpdatedPayloadListItem
|
HTTP response with the updated payload details. |
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/router.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
Define Models for Payload.
PayloadListItem
Bases: BaseModel
Defines PayloadListItem Model.
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/models.py
PayloadListItems
PayloadStats
UpdatedPayloadListItem
API Implemenation for the Customizer to start and control the payload processing.
import_payload(payload=None, payload_dir=None, enabled=None, dependencies=None)
Automatically load payload items from disk of a given directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
payload
|
str
|
The name of the payload. |
None
|
payload_dir
|
str
|
The local path. |
None
|
enabled
|
bool
|
Automatically start the processing (True), or only define items (False). Defaults to False. |
None
|
dependencies
|
bool
|
Automatically add dependency on the last payload in the queue |
None
|
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/functions.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
prepare_dependencies(dependencies)
Convert the dependencies string to a list of integers.
Source code in packages/pyxecm/src/pyxecm_api/v1_payload/functions.py
tail_log(file_path)
async
Asynchronously follow the log file like tail -f
.