prepared for publishing
This commit is contained in:
parent
7481d7a0e1
commit
3886bb19f2
21
LICENSE
Normal file
21
LICENSE
Normal 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.
|
29
pyproject.toml
Normal file
29
pyproject.toml
Normal 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"
|
@ -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)
|
|
||||||
|
|
13
setup.py
13
setup.py
@ -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' ]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
0
src/access_azure_keyvault/__init__.py
Normal file
0
src/access_azure_keyvault/__init__.py
Normal file
26
src/access_azure_keyvault/__main__.py
Normal file
26
src/access_azure_keyvault/__main__.py
Normal 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)
|
||||||
|
|
17
src/access_azure_keyvault/_aak.py
Normal file
17
src/access_azure_keyvault/_aak.py
Normal 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}>")
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user