-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy path__init__.py
81 lines (68 loc) · 2.69 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
import repokid.hooks as hooks
from repokid.role import Role
from repokid.types import RepokidHookInput
from repokid.types import RepokidHookOutput
LOGGER = logging.getLogger("repokid")
@hooks.implements_hook("BEFORE_REPO_ROLES", 1)
def log_before_repo_roles(input_dict: RepokidHookInput) -> RepokidHookOutput:
LOGGER.debug("Calling DURING_REPOABLE_CALCULATION hooks")
if not all(required in input_dict for required in ["account_number", "roles"]):
raise hooks.MissingHookParameter(
"Did not get all required parameters for BEFORE_REPO_ROLES hook"
)
return input_dict
@hooks.implements_hook("DURING_REPOABLE_CALCULATION", 1)
def log_during_repoable_calculation_hooks(
input_dict: RepokidHookInput,
) -> RepokidHookOutput:
LOGGER.debug("Calling DURING_REPOABLE_CALCULATION hooks")
if not all(
required in input_dict
for required in [
"account_number",
"role_name",
"potentially_repoable_permissions",
"minimum_age",
]
):
raise hooks.MissingHookParameter(
"Did not get all required parameters for DURING_REPOABLE_CALCULATION hook"
)
return input_dict
@hooks.implements_hook("DURING_REPOABLE_CALCULATION_BATCH", 1)
def log_during_repoable_calculation_batch_hooks(
input_dict: RepokidHookInput,
) -> RepokidHookOutput:
LOGGER.debug("Calling DURING_REPOABLE_CALCULATION_BATCH hooks")
if not all(
required in input_dict
for required in [
"role_batch",
"potentially_repoable_permissions",
"minimum_age",
]
):
raise hooks.MissingHookParameter(
"Did not get all required parameters for DURING_REPOABLE_CALCULATION_BATCH hook"
)
for role in input_dict["role_batch"]:
if not isinstance(role, Role):
raise hooks.MissingHookParameter(
"Role_batch needs to be a series of Role objects in DURING_REPOABLE_CALCULATION_BATCH hook"
)
return input_dict
@hooks.implements_hook("AFTER_SCHEDULE_REPO", 1)
def log_after_schedule_repo_hooks(input_dict: RepokidHookInput) -> RepokidHookOutput:
LOGGER.debug("Calling AFTER_SCHEDULE_REPO hooks")
if "roles" not in input_dict:
raise hooks.MissingHookParameter(
"Required key 'roles' not passed to AFTER_SCHEDULE_REPO"
)
return input_dict
@hooks.implements_hook("AFTER_REPO", 1)
def log_after_repo_hooks(input_dict: RepokidHookInput) -> RepokidHookOutput:
LOGGER.debug("Calling AFTER_REPO hooks")
if "role" not in input_dict:
raise hooks.MissingHookParameter("Required key 'role' not passed to AFTER_REPO")
return input_dict