Spaces:
Sleeping
Sleeping
File size: 1,432 Bytes
c2d68b9 99d2629 c2d68b9 99d2629 1d4e0ad 99d2629 c2d68b9 dd010bf 1d4e0ad c2d68b9 |
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 |
#!/usr/bin/env python3
import os
import argparse
def retrieve_secrets(
file_path: str | os.PathLike,
secret_from: str,
access_type: str
) -> str:
with open(file_path, 'r') as file:
lines = file.read().split('\n\n')
for block in lines:
if secret_from in block:
tokens = block.split('\n')
for token in tokens:
if token.startswith('#'):
continue
token_parts = token.split('#')
token_value = token_parts[0].strip()
token_type = token_parts[1].strip() if len(token_parts) > 1 else 'default'
if token_type == access_type:
return token_value
return None
def main():
parser = argparse.ArgumentParser(description='Retrieve secrets from a file.')
parser.add_argument('--file-path', type=str, default="/home/el02/.ssh/lab_access.txt", help='Path to the secrets file')
parser.add_argument('--secret-from', type=str, default="Hugging Face Authentication", help='Source of the secret')
parser.add_argument('--access-type', type=str, default="write", help='Type of access')
args = parser.parse_args()
secret = retrieve_secrets(args.file_path, args.secret_from, args.access_type)
if secret:
print(secret)
else:
print("Secret not found.")
if __name__ == "__main__":
main() |