|
4 | 4 | import hashlib |
5 | 5 | import weakref |
6 | 6 | from abc import ABC, abstractmethod |
| 7 | +from collections import defaultdict |
7 | 8 | from copy import deepcopy |
8 | | -from datetime import datetime, timezone, timedelta |
| 9 | +from datetime import datetime, timedelta |
9 | 10 | from enum import Enum, StrEnum, unique |
10 | 11 | from functools import wraps, cached_property |
11 | 12 | from typing import Dict, Iterator, List, ClassVar, Optional, TypedDict, Any, TypeVar, Type, Callable, Set, Tuple |
12 | | -from collections import defaultdict |
13 | 13 |
|
14 | 14 | from attr import resolve_types |
15 | 15 | from attrs import define, field, Factory, frozen, evolve |
16 | 16 | from prometheus_client import Counter, Summary |
17 | 17 |
|
| 18 | +from fixlib.basecategories import Category |
18 | 19 | from fixlib.json import from_json as _from_json, to_json as _to_json, to_json_str |
19 | 20 | from fixlib.logger import log |
20 | 21 | from fixlib.types import Json |
21 | 22 | from fixlib.utils import make_valid_timestamp, utc_str, utc |
22 | | -from fixlib.basecategories import Category |
23 | | - |
24 | 23 |
|
25 | 24 | metrics_resource_pre_cleanup_exceptions = Counter( |
26 | 25 | "resource_pre_cleanup_exceptions_total", |
@@ -246,6 +245,32 @@ def __str__(self) -> str: |
246 | 245 | MetricNameWithUnit = str |
247 | 246 |
|
248 | 247 |
|
| 248 | +class Severity(StrEnum): |
| 249 | + info = "info" |
| 250 | + low = "low" |
| 251 | + medium = "medium" |
| 252 | + high = "high" |
| 253 | + critical = "critical" |
| 254 | + |
| 255 | + |
| 256 | +@define(slots=True) |
| 257 | +class Finding: |
| 258 | + title: str |
| 259 | + severity: Severity = Severity.medium |
| 260 | + description: Optional[str] = None |
| 261 | + remediation: Optional[str] = None |
| 262 | + created_at: Optional[datetime] = None |
| 263 | + details: Optional[Json] = None |
| 264 | + |
| 265 | + |
| 266 | +@define(slots=True) |
| 267 | +class Assessment: |
| 268 | + # The provider of the security assessment |
| 269 | + provider: str |
| 270 | + # All findings of the security provider to this resource |
| 271 | + findings: List[Finding] = field(factory=list) |
| 272 | + |
| 273 | + |
249 | 274 | @define(eq=False, slots=False, kw_only=True) |
250 | 275 | class BaseResource(ABC): |
251 | 276 | """ |
@@ -305,6 +330,8 @@ class BaseResource(ABC): |
305 | 330 | _resource_usage: Dict[MetricNameWithUnit, Dict[str, float]] = field(factory=lambda: defaultdict(dict)) |
306 | 331 | # Deep link into the cloud provider's console |
307 | 332 | _provider_link: Optional[str] = None |
| 333 | + # Assessment details for this resource: multiple providers can append their findings |
| 334 | + _assessments: List[Assessment] = field(factory=list) |
308 | 335 |
|
309 | 336 | ctime: Optional[datetime] = field( |
310 | 337 | default=None, |
|
0 commit comments