-
-
Save TimothyODonnell/22eb0e615148fb264a12f47c44cfe172 to your computer and use it in GitHub Desktop.
// ##### RUN AV ON FILE ##### | |
log.LogInformation("Download completed. Connecting to AV server {ClamAVServerUrl}:{ClamAVServerPort}... ", ClamAVServerUrl, ClamAVServerPort); | |
var clam = new ClamClient(ClamAVServerUrl, ClamAVServerPort); | |
bool isConnected = await clam.PingAsync(); | |
var version = await clam.GetVersionAsync(); | |
if (!isConnected) throw new Exception("AV server connection could not be established."); | |
log.LogInformation("Connection ok: {IsConnected}. AV server reports version: {ServerVersion}", isConnected, version); | |
var scanResult = await clam.SendAndScanFileAsync(ms.ToArray()); | |
switch (scanResult.Result) | |
{ | |
case ClamScanResults.Clean: | |
log.LogInformation("The file is clean!"); | |
// Continue | |
break; | |
case ClamScanResults.VirusDetected: | |
log.LogCritical("Virus found. Deleting file."); | |
await blobClient.DeleteIfExistsAsync(Azure.Storage.Blobs.Models.DeleteSnapshotsOption.IncludeSnapshots); | |
// Do other steps | |
break; | |
case ClamScanResults.Error: | |
default: | |
log.LogInformation("File scan error occurred. {ScanResult}", scanResult.RawResult); | |
break; | |
} |
Good catch. Fixed it on the main gist. The configuration is acquired from the function app settings in the very idiomatic and standard way. I typically want to omit all of the boilerplate to discourage direct copypasting - especially when it comes to code like this.
We used terraform to set these values directly into the azure function app on deployment.
string response = ConfigurationManager.AppSettings["appsettingkey"].ToString();
The call about the port being non obvious is true. Let me improve that bit.
As for the final storage location and what you wish to do with the file after it has been scanned - that I leave entirely up to the users to figure out. You can take any steps you like, but I'm also hesitant to include that code because it will lead to mindless copypasting.
Thanks for the heads up :)
I have linked this discussion in my post to the part where these settings were discussed and improved that bit slightly. Thanks @TimothyODonnell
I've added the missing first letter which I assume must have been a cut and paste error. Additionally, there is no mention of how to add the configuration into the function app. I assume that this was manually added into the function app via the portal. The port information was obtained from this url which is probably worth linking as people might struggle to add an appropriate value into this setting. Is this tutorial also missing the creation of a file container into which the files will be placed?
https://hub.docker.com/r/mkodockx/docker-clamav/