This is now the third and last blog post about Content Hub Antivirus. If you have missed the previous post. Please read Part 1 and Part 2 of this series. In the third and final chapter of the series, I will explain the Solution I've posted on Github.
Before we dive into the Visual Studio solution, let us first take a look at what we're supposed to be building. On the right-hand side is the Azure part. This is where the Azure functions are living. If you look closely at the image you can find the three functions:
- Receive scan request
- Process scan request
- Process scan result
These functions will be part of the solution as well. So let us continue and open the solution is Visual Studio. One of the first thins you will see in the Solution Explorer are the projects below the solution.
- QueueConnectionstring -> Azure storage connection string with read / write permission to queues
- Cloudmersive-ApiKey -> API key that can be created on the Cloudmersive website.
Within the AntivirusFunctions.cs file you will find the three functions declared. This is the starting point for all interactions with the Function. The ReceiveScanRequest function will get a POST message with a payload from Content Hub. This payload is serialized and validated before being used. After that, it will create a message on the queue for later execution. This way we can quickly send back to Content Hub that we've successfully processed their request. Now that the first action has completed we can move on to the next step.
The second step is to actually execute the antivirus scan request. That is where the ProcessScanRequest function kicks in. This function responds to the queue where the scan requests are being sent in the previous step. The service takes in the request and when all file sources have been checked with the Cloudmersive scan service. If a virus was found by the Cloudmersive scan service, the process is immediately stopped and the result is then stored in the response queue. When all sources are viruses free the result is of course stored in the same queue, with a different payload. Once the result has been stored we can move to the final phase of the solution.
In this final phase, we report back to the Content Hub on the callback URL we received in the request. In the ProcessScanResult function, we will process the result of the previous step. The callback URL requires a specific payload in order to function properly. In order for easy reporting, I've created the helper class AntivirusResultHelper, this has two methods: CreateOkResult and CreateVirusFoundResult. This will generate the following JSON:
{ "value": "Ok" }
OR
{ "value": "Malicious" }
The JSON will be sent as a payload to the Content Hub callback URL. The Content Hub will process the status and update the entity on its side.
And there we have it. A complete Antivirus process with Content Hub. I hope you've enjoyed the serie.
Until next time!