Initial commit for statistics feature
This commit is contained in:
@@ -1,40 +1,47 @@
|
||||
from typing import Dict, List
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
def pull_policy_exec_histories(
|
||||
self, type: List[str], checkpoint: str, policy: List[str]
|
||||
api,
|
||||
type: str,
|
||||
days: int,
|
||||
policy_name: Optional[str] = None,
|
||||
) -> str:
|
||||
"""Retrieve execution history logs."""
|
||||
|
||||
def api(AirlockAPIWrapper):
|
||||
"""
|
||||
An implementation of the python AirlockAPIWrapper class to pass Python data into Rust
|
||||
Pull execution history for policies.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
base_url : str
|
||||
(Required) Base URL of the Airlock API, this should be in your .env file.
|
||||
api_key : str
|
||||
(Required) API Key for your profile in airlock, this should be in your credential manager.
|
||||
headers : {"X-APIKey": self.api_key}
|
||||
api : AirlockAPIWrapper
|
||||
The API wrapper instance
|
||||
policy_name : Optional[str]
|
||||
Name of the policy to query. If None, returns history for all policies.
|
||||
type : str
|
||||
JSON-style string list of execution types, e.g., "[1,2,3]"
|
||||
days : int
|
||||
Number of days to look back
|
||||
|
||||
```def __init__(self, base_url: str, api_key: str):
|
||||
self.base_url = base_ur.rstrip("/")
|
||||
self.api_key = api_key
|
||||
self.headers = {"X-APIKey": self.api_key}
|
||||
```
|
||||
Returns
|
||||
-------
|
||||
str
|
||||
JSON string containing execution history response with structure:
|
||||
{"response": {"exechistories": [...]}}
|
||||
"""
|
||||
...
|
||||
|
||||
def history_logging(
|
||||
api,
|
||||
exec_types: str,
|
||||
checkpoint_number: str,
|
||||
policy_names: str,
|
||||
policy_names: Optional[str] = None,
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
Query execution history logs from the Airlock API.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
api : AirlockAPIWrapper
|
||||
The API wrapper instance
|
||||
|
||||
exec_types : str
|
||||
A JSON-style string list of execution types to retrieve.
|
||||
Example: "[3,5,8]"
|
||||
@@ -42,17 +49,30 @@ def history_logging(
|
||||
- 1 = Blocked Execution
|
||||
- 2 = Untrusted Execution [Audit]
|
||||
- 3 = Untrusted Execution [OTP]
|
||||
- 4 = Trusted Path Execution
|
||||
- 5 = Trusted Publisher Execution
|
||||
- 6 = Blocklist Execution
|
||||
- 7 = Blocklist Execution [Audit]
|
||||
- 8 = Trusted Process Execution
|
||||
(etc.)
|
||||
- 9 = Constrained Execution
|
||||
- 10 = Trusted Metadata Execution
|
||||
- 11 = Trusted Browser Execution
|
||||
- 12 = Blocked Browser Execution
|
||||
- 13 = Untrusted Browser Execution [Audit]
|
||||
- 14 = Untrusted Browser Execution [OTP]
|
||||
- 15 = Blocklist Browser Execution [Audit]
|
||||
- 16 = Blocklist Browser Execution
|
||||
- 17 = Trusted Installer Execution
|
||||
- 18 = Trusted Browser Metadata Execution
|
||||
|
||||
checkpoint_number : str
|
||||
The checkpoint ID. Used to fetch results after a certain event.
|
||||
Example: "601d275487bacb01e3470713"
|
||||
|
||||
policy_names : str
|
||||
policy_names : Optional[str], default None
|
||||
A comma-separated or JSON-style list of policy group names.
|
||||
Example: "Apple Mac" or "["Apple Mac", "Servers London"]"
|
||||
If None or not provided, retrieves execution history for ALL policies.
|
||||
Example: "Apple Mac" or '["Apple Mac", "Servers London"]'
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -76,14 +96,29 @@ def history_logging(
|
||||
- datetime: str
|
||||
- ip: str
|
||||
- localip: str
|
||||
|
||||
Raises
|
||||
------
|
||||
RuntimeError
|
||||
If the request fails or the response cannot be parsed.
|
||||
|
||||
Example
|
||||
-------
|
||||
>>> histories = await airlock_libs.history_logging("[3,5,8]", "601d275487bacb01e3470713", "Apple Mac")
|
||||
Examples
|
||||
--------
|
||||
>>> # Get execution history for ALL policies
|
||||
>>> histories = airlock_libs.history_logging(
|
||||
... api,
|
||||
... "[1,2,3]",
|
||||
... "601d275487bacb01e3470713",
|
||||
... None # or omit this parameter
|
||||
... )
|
||||
>>>
|
||||
>>> # Get execution history for a specific policy
|
||||
>>> histories = airlock_libs.history_logging(
|
||||
... api,
|
||||
... "[3,5,8]",
|
||||
... "601d275487bacb01e3470713",
|
||||
... "Apple Mac"
|
||||
... )
|
||||
>>> print(histories[0]["filename"])
|
||||
'chrome.exe'
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user