Logic implemented

This commit is contained in:
Gal Szkolnik 2023-07-23 05:25:51 -04:00
parent edbdf0e57b
commit 4c30299958
2 changed files with 41 additions and 2 deletions

View File

@ -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.",

View File

@ -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