I have inherited the following code in Azure Functions and I want to ensure if this correct and find out the correct way to call this utilizing Python Azure Functions v2 programming model.
import os
import gnupg
import azure.functions as func
gpg = gnupg.GPG(gnupghome='/tmp')
class PGPDecryption:
def __init__(self, prikey):
self.fullkey = prikey
def decrypt(self, blob_data):
key_data = self.fullkey.strip()
gpg.import_keys(key_data)
decrypted_data = gpg.decrypt(blob_data)
return str(decrypted_data)
# Blob Trigger for input and Blob Output binding for decrypted file
@func.blob_input(name='inputBlob', path='input-container/{name}',
connection='AzureWebJobsStorage')
@func.blob_output(name='outputBlob', path='output-container/{name}.decrypted',
connection='AzureWebJobsStorage')
def main(inputBlob: func.InputStream, outputBlob: func.Out[func.InputStream], context:
func.Context):
prikey = '<Your PGP Private Key>' # Replace with your PGP private key
decryptor = PGPDecryption(prikey)
decrypted_data = decryptor.decrypt(inputBlob.read())
# Writing decrypted data to output binding
outputBlob.set(decrypted_data)
The objective is for the code to get a file from Azure Blob and decrpyt it and put it back to another Azure Blob location. Does the code actually achieve this and how can I debug this?
To debug you can use logging and to test the code(taken a sample code, you can use yours):
Here, this azure blob trigger gets triggered when a new blob is added and then it created a new file in destination like below:
You need to check if a new blob is created or not.