feat(script): Decrypt an example GPG-encrypted file
This commit is contained in:
		
							
								
								
									
										26
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								main.py
									
									
									
									
									
								
							| @@ -2,8 +2,14 @@ | |||||||
| import atexit | import atexit | ||||||
| import json | import json | ||||||
| import logging.config | import logging.config | ||||||
|  | import os | ||||||
| import pathlib | import pathlib | ||||||
|  |  | ||||||
|  | import gnupg | ||||||
|  | from rich.traceback import install | ||||||
|  |  | ||||||
|  | install(show_locals=True) | ||||||
|  |  | ||||||
| logger = logging.getLogger("vm_management") | logger = logging.getLogger("vm_management") | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -21,19 +27,13 @@ def setup_logging(): | |||||||
|  |  | ||||||
| def main(): | def main(): | ||||||
|     setup_logging() |     setup_logging() | ||||||
|     logger.debug("Logging configured") |     gnupg_home = os.path.expanduser("~/.gnupg") | ||||||
|     logger.info("Logging configured") |     gpg = gnupg.GPG(gnupghome=gnupg_home) | ||||||
|     logger.warning("Logging configured") |     gpg.encoding = "utf-8" | ||||||
|     logger.error("Logging configured") |     vault_secret_file = os.path.expanduser("~/Downloads/hashicorp_vault_token.gpg") | ||||||
|     logger.critical("Logging configured") |     with open(vault_secret_file, "rb") as vault_secret_file: | ||||||
|  |         vault_secret = gpg.decrypt_file(vault_secret_file, passphrase="pw") | ||||||
|     # ä gnupg = gnupg.GPG() |         logger.debug("vault secret: %s", vault_secret) | ||||||
|     # logging.basicConfig(level=logging.INFO) |  | ||||||
|  |  | ||||||
|     # gpg = gnupg.GPG(gnupghome="~/.gnupg", verbose=True) |  | ||||||
|     # gpg.encoding="utf-8" |  | ||||||
|     # with open("~/Downloads/hashicorp_vault_token.gpg", "r") as file: |  | ||||||
|     #    # secret = file.read() |  | ||||||
|  |  | ||||||
|  |  | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user