prepared for publishing

This commit is contained in:
Wolfgang Hottgenroth 2022-09-16 12:08:23 +02:00
parent 7481d7a0e1
commit 3886bb19f2
Signed by: wn
GPG Key ID: 836E9E1192A6B132
8 changed files with 93 additions and 45 deletions

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Wolfgang Hottgenroth
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

0
README.md Normal file
View File

29
pyproject.toml Normal file
View File

@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
[project]
name = "access_azure_keyvault"
version = "0.0.3"
authors = [
{ name="Wolfgang Hottgenroth", email="wolfgang.hottgenroth@icloud.com" },
]
description = "Simple tool to access secrets in Azure keyvaults"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"azure.keyvault>=4.2.0",
"azure.identity>=1.10.0",
"azure.core>=1.25.1",
"loguru>=0.6.0"
]
[project.urls]
"Homepage" = "https://home.hottis.de/gitlab/wolutator/access-azure-keyvault"
"Bug Tracker" = "https://home.hottis.de/gitlab/wolutator/access-azure-keyvault/-/issues"

View File

@ -1,32 +0,0 @@
import argparse
import sys
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import AzureError
parser = argparse.ArgumentParser(description="access-key-vault.py")
parser.add_argument('--keyvault', '-v',
help="Name of Azure Key Vault",
required=True)
parser.add_argument('--secretname', '-s',
help='Name of secret to query',
required=True)
args = parser.parse_args()
keyVaultName = args.keyvault
secretName = args.secretname
KVUri = f"https://{keyVaultName}.vault.azure.net"
try:
credential = DefaultAzureCredential()
client = SecretClient(vault_url=KVUri, credential=credential)
retrieved_secret = client.get_secret(secretName)
print(f"{retrieved_secret.value}")
except AzureError as e:
print(f"AzureError: <{e.__class__.__name__}> <{e}>", file=sys.stderr)
sys.exit(1)
except Exception as e:
print(f"Error: <{e.__class__.__name__}> <{e}>", file=sys.stderr)
sys.exit(1)

View File

@ -1,13 +0,0 @@
from setuptools import setup
setup(
name = 'access-azure-keyvault',
version = '0.1',
author = 'Wolfgang Hottgenroth',
author_email = 'wolfgang.hottgenroth@icloud.com',
description = 'Tool to retrieve secrets from an Azure keyvault',
license = 'MIT',
scripts = [ 'scripts/access-azure-keyvault.py' ]
)

View File

View File

@ -0,0 +1,26 @@
import argparse
import sys
from . import _aak
from loguru import logger
parser = argparse.ArgumentParser(description="access_azure_keyvault")
parser.add_argument('--keyvault', '-v',
help="Name of Azure Key Vault",
required=True)
parser.add_argument('--secretname', '-s',
help='Name of secret to query',
required=True)
args = parser.parse_args()
keyVaultName = args.keyvault
secretName = args.secretname
logger.debug(f"Trying to retrieve secret {secretName} from keyvault {keyVaultName}")
try:
secretValue = _aak.getSecret(keyVaultName, secretName)
logger.debug(f"Retrieved {secretValue}")
print(secretValue)
except Exception as e:
logger.error(f"Error: <{e.__class__.__name__}> <{e}>")
sys.exit(1)

View File

@ -0,0 +1,17 @@
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import AzureError
class LocalException (Exception): pass
def getSecret(keyVaultName, secretName):
KVUri = f"https://{keyVaultName}.vault.azure.net"
try:
credential = DefaultAzureCredential()
client = SecretClient(vault_url=KVUri, credential=credential)
retrieved_secret = client.get_secret(secretName)
return retrieved_secret
except AzureError as e:
raise LocalException(f"AzureError: <{e.__class__.__name__}> <{e}>")