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.

  1. 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";
}
  1. Get a blob client for the blob
BlobClient blob = container.GetBlobClient(blob.Name);
  1. Get the tags for the blob:
var tags = blob.GetTags().Value.Tags;
  1. Check chekc each tag:
foreach (var tag in tags)
  1. Check the key:
if (tag.Key.ToString() == Constants.DefenderTag)
{
    ...
}
  1. Check the value:
if (tag.Value.ToString() == Constants.DefenderHasVirusValue)
{
    ...
}