Load API credentials from environment variables and fetch an access token. Returns: str: The access token. Raises: SystemExit: If API key or Secret key are not set.
()
| 72 | |
| 73 | |
| 74 | def get_access_token() -> str: |
| 75 | """ |
| 76 | Load API credentials from environment variables and fetch an access token. |
| 77 | |
| 78 | Returns: |
| 79 | str: The access token. |
| 80 | |
| 81 | Raises: |
| 82 | SystemExit: If API key or Secret key are not set. |
| 83 | """ |
| 84 | load_dotenv() |
| 85 | |
| 86 | # Attempt to retrieve API key and Secret key from environment variables |
| 87 | HUME_API_KEY = os.getenv("HUME_API_KEY") |
| 88 | HUME_SECRET_KEY = os.getenv("HUME_SECRET_KEY") |
| 89 | |
| 90 | # Ensure API key and Secret key are set |
| 91 | if HUME_API_KEY is None or HUME_SECRET_KEY is None: |
| 92 | print( |
| 93 | "Error: HUME_API_KEY and HUME_SECRET_KEY must be set either in a .env file or as environment variables." |
| 94 | ) |
| 95 | exit() |
| 96 | |
| 97 | # Create an instance of Authenticator with the API key and Secret key |
| 98 | authenticator = Authenticator(HUME_API_KEY, HUME_SECRET_KEY) |
| 99 | |
| 100 | # Fetch the access token |
| 101 | access_token = authenticator.fetch_access_token() |
| 102 | return access_token |
| 103 | |
| 104 | |
| 105 | if __name__ == "__main__": |
no test coverage detected