Terarea  2
The automation project
Loading...
Searching...
No Matches
secrets.py
Go to the documentation of this file.
1"""_summary_
2 File in charge of tracking secrets for a given check
3"""
4
5from typing import Dict, Any
6from datetime import datetime, timezone
7from .variables import Variables
8
9
10class Secrets:
11 """_summary_
12 This class is in charge of storing the secrets for the server.
13 """
14
15 def __init__(self, success: int = 0, error: int = 84, debug: bool = False) -> None:
16 """_summary_
17 Class in charge of managing the secrets for the server runtime trigger and consequences.
18
19 Args:
20 success (int, optional): _description_. Defaults to 0.
21 error (int, optional): _description_. Defaults to 84.
22 debug (bool, optional): _description_. Defaults to False.
23 """
24 self.debug: bool = debug
25 self.success: int = success
26 self.error: int = error
27 self.scope: str = "secrets"
28
29 self.vars: Variables = Variables(
30 success=self.success,
31 error=self.error,
32 debug=self.debug
33 )
34
35 def get_secret(self, secret_name: str) -> Dict[str, Any]:
36 """_summary_
37 Get the secret from the server.
38
39 Args:
40 secret_name (str): _description_
41
42 Returns:
43 Dict[str, Any]: _description_
44 """
45 return self.vars.get_variable(secret_name, self.scope)
46
47 def set_token(self, token: str) -> None:
48 """_summary_
49 Set the token for the server.
50
51 Args:
52 token (str): _description_
53 """
54 self.vars.insert_or_update("token", token, type(token), self.scope)
55 bearer = f"Bearer {token}"
56 self.vars.insert_or_update("bearer", bearer, type(bearer), self.scope)
57
58 def get_token(self) -> str:
59 """_summary_
60 Get the token for the server.
61
62 Returns:
63 str: _description_
64 """
65 return self.vars.get_variable("token", self.scope)
66
67 def get_bearer(self) -> str:
68 """_summary_
69 Get the bearer for the server.
70
71 Returns:
72 str: _description_
73 """
74 return self.vars.get_variable("bearer", self.scope)
75
76 @staticmethod
77 def now() -> str:
78 """_summary_
79 Get the current time.
80 """
81 return datetime.now().isoformat()
82
83 @staticmethod
84 def current_date() -> str:
85 """_summary_
86 $ref{secrets.current_date}: Returns the current date without the time in the server's local timezone
87
88 Returns:
89 _type_: _description_
90 """
91 return datetime.now().date().isoformat()
92
93 @staticmethod
94 def current_time() -> str:
95 """_summary_
96 $ref{secrets.current_time}: Returns the current time (hours:minutes:seconds) in the server's local timezone
97
98 Returns:
99 _type_: _description_
100 """
101 return datetime.now().time().replace(microsecond=0).isoformat()
102
103 @staticmethod
104 def now_utc() -> str:
105 """_summary_
106 $ref{secrets.now_utc}: Returns the current datetime in UTC with timezone info
107
108 Returns:
109 _type_: _description_
110 """
111 return datetime.now(timezone.utc).isoformat()
112
113 @staticmethod
114 def current_date_utc() -> str:
115 """_summary_
116 $ref{secrets.current_date_utc}: Returns the current date without the time in UTC
117
118 Returns:
119 _type_: _description_
120 """
121 return datetime.now(timezone.utc).date().isoformat()
122
123 @staticmethod
124 def current_time_utc() -> str:
125 """_summary_
126 $ref{secrets.current_time_utc}: Returns the current time (hours:minutes:seconds) in UTC
127
128 Returns:
129 _type_: _description_
130 """
131 return datetime.now(timezone.utc).time().replace(microsecond=0).isoformat()
132
133 @staticmethod
134 def now_server() -> str:
135 """_summary_
136 $ref{secrets.now_server}: Returns the current datetime with timezone info in the server's local timezone
137
138 Returns:
139 _type_: _description_
140 """
141 return datetime.now().astimezone().isoformat()
142
143 @staticmethod
145 """_summary_
146 $ref{secrets.current_date_server}: Returns the current date without the time in the server's local timezone
147
148 Returns:
149 _type_: _description_
150 """
151 return datetime.now().astimezone().date().isoformat()
152
153 @staticmethod
155 """_summary_
156 $ref{secrets.current_time_server}: Returns the current time (hours:minutes:seconds) in the server's local timezone
157
158 Returns:
159 _type_: _description_
160 """
161 return datetime.now().astimezone().time().replace(microsecond=0).isoformat()
None __init__(self, int success=0, int error=84, bool debug=False)
Definition secrets.py:15
Dict[str, Any] get_secret(self, str secret_name)
Definition secrets.py:35
None set_token(self, str token)
Definition secrets.py:47