Created
July 11, 2024 22:00
-
-
Save dotku/6b43b6ae32ee085aefd95ae26d56ffd0 to your computer and use it in GitHub Desktop.
Revisions
-
dotku created this gist
Jul 11, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ import subprocess import os from pprint import pprint def load_azd_env_values(env_name=None): command = ["azd", "env", "get-values"] if env_name: command.extend(["--environment", env_name]) try: result = subprocess.run(command, capture_output=True, text=True, check=True) # Print the result to debug # print("Command output:", result.stdout) if not result.stdout.strip(): raise ValueError("The command returned no output.") env_values = {} for line in result.stdout.strip().split('\n'): if '=' in line: key, value = line.split('=', 1) env_values[key] = value.strip('"') else: raise ValueError(f"Invalid line in output: {line}") for key, value in env_values.items(): os.environ[key] = value return env_values except subprocess.CalledProcessError as e: print(f"An error occurred while running azd env get-values: {e}") return None # Example usage: env_values = load_azd_env_values() print("\nCurrent environment variables:") current_env_values = {key: os.environ.get(key) for key in env_values} pprint(current_env_values)