-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy path__init__.py
47 lines (35 loc) · 1.33 KB
/
__init__.py
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
import os
import os.path
from typing import List, Literal, Optional, Pattern, Union
from pydantic import BaseModel, ConfigDict, Field, PrivateAttr
from holmes.utils.pydantic_utils import RobustaBaseConfig, load_model_from_file
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
class IssueMatcher (RobustaBaseConfig):
issue_id: Optional[Pattern] = None # unique id
issue_name: Optional[Pattern] = None # not necessary unique
source: Optional[Pattern] = None
class RunbookContext(RobustaBaseConfig):
type: "URL"
class Runbook(RobustaBaseConfig):
match: IssueMatcher
instructions: str
_path = PrivateAttr()
def set_path(self, path: str):
self._path = path
def get_path(self) -> str:
return self._path
class ListOfRunbooks(BaseModel):
runbooks: List[Runbook]
def load_runbooks_from_file(path: str) -> List[Runbook]:
data: ListOfRunbooks = load_model_from_file(ListOfRunbooks, file_path=path)
for runbook in data.runbooks:
runbook.set_path(path)
return data.runbooks
def load_builtin_runbooks() -> List[Runbook]:
all_runbooks = []
for filename in os.listdir(THIS_DIR):
if not filename.endswith(".yaml"):
continue
path = os.path.join(THIS_DIR, filename)
all_runbooks.extend(load_runbooks_from_file(path))
return all_runbooks