Spaces:
Sleeping
Sleeping
update: Check pushing to hugginface git.
Browse files- utility.py +22 -0
utility.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
def retrieve_secrets(
|
4 |
+
file_path: str | os.PathLike,
|
5 |
+
secret_from: str,
|
6 |
+
access_type: str="default"
|
7 |
+
) -> str:
|
8 |
+
with open(file_path, 'r') as file:
|
9 |
+
lines = file.read().split('\n\n')
|
10 |
+
|
11 |
+
for block in lines:
|
12 |
+
if secret_from in block:
|
13 |
+
tokens = block.split('\n')
|
14 |
+
for token in tokens:
|
15 |
+
if token.startswith('#'):
|
16 |
+
continue
|
17 |
+
token_parts = token.split('#')
|
18 |
+
token_value = token_parts[0].strip()
|
19 |
+
token_type = token_parts[1].strip() if len(token_parts) > 1 else 'default'
|
20 |
+
if token_type == access_type:
|
21 |
+
return token_value
|
22 |
+
return None
|