Defender For Storage Example
To determine if a blob has been scanned or contains a virus you need to check specific tags that are deployed on the blob by Defender For Cloud. Below is some code that should demonstrate how this is done.
- Declare some constants for the tags and values that we are looking for:
static class Constants
{
public const string DefenderTag = "Malware Scanning scan result";
public const string DefenderHasVirusValue = "Malicious";
public const string DefenderIsCleanValue = "No threats found";
}
- Get a blob client for the blob
BlobClient blob = container.GetBlobClient(blob.Name);
- Get the tags for the blob:
var tags = blob.GetTags().Value.Tags;
- Check chekc each tag:
foreach (var tag in tags)
- Check the key:
if (tag.Key.ToString() == Constants.DefenderTag)
{
...
}
- Check the value:
if (tag.Value.ToString() == Constants.DefenderHasVirusValue)
{
...
}