eli02's picture
update: Check pushing to hugginface git.
99d2629
raw
history blame
730 Bytes
import os
def retrieve_secrets(
file_path: str | os.PathLike,
secret_from: str,
access_type: str="default"
) -> 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