Skip to content

Commit 5feb6ce

Browse files
authored
Merge pull request #8 from Veridise/sas-1567-digest
SAS-1567: Add api_send_digest
2 parents e0c3758 + 2095373 commit 5feb6ce

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

audithub_client/api/send_digest.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
from dataclasses import dataclass
3+
from datetime import datetime, timedelta, timezone
4+
from typing import Optional
5+
6+
from ..library.auth import authentication_retry
7+
from ..library.context import AuditHubContext
8+
from ..library.http import GET
9+
from ..library.net_utils import ensure_success, response_json
10+
11+
12+
@dataclass
13+
class SendDigestNotificationsArgs:
14+
user_id: Optional[str]
15+
days_to_include: Optional[int]
16+
17+
18+
def get_query_timestamp(days_to_include: int):
19+
return (datetime.now(timezone.utc) - timedelta(days=days_to_include)).isoformat()
20+
21+
22+
def api_send_digest_notifications(
23+
context: AuditHubContext, input: SendDigestNotificationsArgs
24+
):
25+
26+
query_params = {}
27+
if input.user_id:
28+
query_params["user_id"] = input.user_id
29+
if input.days_to_include:
30+
query_params["from_created_at"] = get_query_timestamp(input.days_to_include)
31+
32+
response = authentication_retry(
33+
context, GET, url=f"{context.base_url}/admin/digest", params=query_params
34+
)
35+
ensure_success(response)
36+
ret = response_json(response)
37+
return ret

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "audithub-client"
3-
version = "1.1.3"
3+
version = "1.1.4"
44
description = "A Python client that can access Veridise AuditHub via its REST API, providing CLI access"
55
authors = ["Nikos Chondros <nikos@veridise.com>"]
66
license = "AGPLv3"

0 commit comments

Comments
 (0)