File size: 730 Bytes
99d2629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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