diff --git a/src/ASSIGNMENT-02/__init__.py b/src/ASSIGNMENT-02/__init__.py index 2a01653..b8d88de 100644 --- a/src/ASSIGNMENT-02/__init__.py +++ b/src/ASSIGNMENT-02/__init__.py @@ -1,7 +1,12 @@ import logging -import azure.functions as func +# Code based on VSCode template for Python Azure Function Apps and +# https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-python?tabs=azure-cli#create-the-sample-code +import os +import azure.functions as func +from azure.keyvault.secrets import SecretClient +from azure.identity import DefaultAzureCredential def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') @@ -16,7 +21,21 @@ def main(req: func.HttpRequest) -> func.HttpResponse: name = req_body.get('name') if name: - return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.") + keyVaultName = name + KVUri = f"https://{keyVaultName}.vault.azure.net" + + credential = DefaultAzureCredential() + client = SecretClient(vault_url=KVUri, credential=credential) + + secretName = "VaronisAssignmentSecret" + + print(f"Retrieving your secret from {keyVaultName}.") + + retrieved_secret = client.get_secret(secretName) + + print(f"Your secret is '{retrieved_secret.value}'.") + + return func.HttpResponse(f"{retrieved_secret.value}") else: return func.HttpResponse( "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.", diff --git a/src/ASSIGNMENT-02/requirements.txt b/src/ASSIGNMENT-02/requirements.txt new file mode 100644 index 0000000..ff4c7ba --- /dev/null +++ b/src/ASSIGNMENT-02/requirements.txt @@ -0,0 +1,20 @@ +azure-common==1.1.28 +azure-core==1.28.0 +azure-functions==1.15.0 +azure-identity==1.13.0 +azure-keyvault-secrets==4.7.0 +certifi==2023.7.22 +cffi==1.15.1 +charset-normalizer==3.2.0 +cryptography==41.0.2 +idna==3.4 +isodate==0.6.1 +msal==1.23.0 +msal-extensions==1.0.0 +portalocker==2.7.0 +pycparser==2.21 +PyJWT==2.8.0 +requests==2.31.0 +six==1.16.0 +typing_extensions==4.7.1 +urllib3==2.0.4