-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlogs_archives.py
More file actions
64 lines (48 loc) · 2.46 KB
/
logs_archives.py
File metadata and controls
64 lines (48 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# Unless explicitly stated otherwise all files in this repository are licensed
# under the 3-clause BSD style license (see LICENSE).
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019 Datadog, Inc.
from __future__ import annotations
from typing import TYPE_CHECKING, Optional, List, Dict, Tuple, cast
from datadog_sync.utils.base_resource import BaseResource, ResourceConfig
if TYPE_CHECKING:
from datadog_sync.utils.custom_client import CustomClient
class LogsArchives(BaseResource):
resource_type = "logs_archives"
resource_config = ResourceConfig(
base_path="/api/v2/logs/config/archives",
excluded_attributes=["id", "attributes.state"],
)
# Additional LogsArchives specific attributes
async def get_resources(self, client: CustomClient) -> List[Dict]:
resp = await client.get(self.resource_config.base_path)
return resp["data"]
async def import_resource(self, _id: Optional[str] = None, resource: Optional[Dict] = None) -> Tuple[str, Dict]:
if _id:
source_client = self.config.source_client
resource = (await source_client.get(self.resource_config.base_path + f"/{_id}"))["data"]
resource = cast(dict, resource)
return resource["id"], resource
async def pre_resource_action_hook(self, _id, resource: Dict) -> None:
pass
async def pre_apply_hook(self) -> None:
pass
async def create_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
destination_client = self.config.destination_client
payload = {"data": resource}
resp = await destination_client.post(self.resource_config.base_path, payload)
return _id, resp["data"]
async def update_resource(self, _id: str, resource: Dict) -> Tuple[str, Dict]:
destination_client = self.config.destination_client
payload = {"data": resource}
resp = await destination_client.put(
self.resource_config.base_path + f"/{self.config.state.destination[self.resource_type][_id]['id']}",
payload,
)
self.config.state.destination[self.resource_type][_id] = resp["data"]
return _id, resp["data"]
async def delete_resource(self, _id: str) -> None:
destination_client = self.config.destination_client
await destination_client.delete(
self.resource_config.base_path + f"/{self.config.state.destination[self.resource_type][_id]['id']}"
)