-
-
Save TimothyODonnell/22eb0e615148fb264a12f47c44cfe172 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ##### 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; | |
} |
I have linked this discussion in my post to the part where these settings were discussed and improved that bit slightly. Thanks @TimothyODonnell
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 :)