< Summary

Class:Azure.Storage.Blobs.BlobExtensions
Assembly:Azure.Storage.Blobs
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\BlobExtensions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\BlockList.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\BlockListTypes.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\GetBlobContainersAsyncCollection.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\GetBlobsAsyncCollection.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\Lease.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobAccountSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobContainerSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobVersionSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\SnapshotSasPermissions.cs
Covered lines:235
Uncovered lines:26
Coverable lines:261
Total lines:1134
Line coverage:90% (235 of 261)
Covered branches:108
Total branches:126
Branch coverage:85.7% (108 of 126)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ToTagDictionary(...)-100%100%
ToBlobTags(...)-100%100%
ToBlobItem(...)-94.44%70%
ToBlobItems(...)-83.33%75%
ToTagsString(...)-83.33%75%
ToBlobProperties(...)-100%75%
ParseObjectReplicationIds(...)-77.78%75%
ParseObjectReplicationMetadata(...)-75%83.33%
ToBlobTagItem(...)-85.71%50%
ToBlobTagItems(...)-83.33%75%
ToRehydratePriority(...)-0%0%
ToBlockList(...)-87.5%50%
ToBlockListType(...)-100%100%
AsIncludeItems(...)-100%100%
AsIncludeItems(...)-100%100%
ToLease(...)-100%100%
ToPermissionsString(...)-78.57%75%
ToPermissionsString(...)-100%100%
ToPermissionsString(...)-100%100%
ToPermissionsString(...)-100%100%
ToPermissionsString(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\BlobExtensions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Net;
 7using System.Linq;
 8using System.Text;
 9using Azure.Storage.Blobs.Models;
 10using Tags = System.Collections.Generic.IDictionary<string, string>;
 11
 12namespace Azure.Storage.Blobs
 13{
 14    internal static partial class BlobExtensions
 15    {
 16        internal static IDictionary<string, string> ToTagDictionary(this BlobTags blobTags)
 17        {
 1068018            if (blobTags?.BlobTagSet == null)
 19            {
 1059620                return null;
 21            }
 8422            Dictionary<string, string> tags = new Dictionary<string, string>();
 50423            foreach (BlobTag blobTag in blobTags.BlobTagSet)
 24            {
 16825                tags[blobTag.Key] = blobTag.Value;
 26            }
 27
 8428            return tags;
 29        }
 30
 31        internal static BlobTags ToBlobTags(this Tags tags)
 32        {
 20033            BlobTags blobTags = new BlobTags();
 94434            foreach (KeyValuePair<string, string> tag in tags)
 35            {
 27236                blobTags.BlobTagSet.Add(new BlobTag
 27237                {
 27238                    Key = tag.Key,
 27239                    Value = tag.Value
 27240                });
 41            }
 20042            return blobTags;
 43        }
 44
 45        internal static BlobItem ToBlobItem(this BlobItemInternal blobItemInternal)
 46        {
 1060847            if (blobItemInternal == null)
 48            {
 049                return null;
 50            }
 51
 1060852            return new BlobItem
 1060853            {
 1060854                Name = blobItemInternal.Name,
 1060855                Deleted = blobItemInternal.Deleted,
 1060856                Snapshot = blobItemInternal.Snapshot,
 1060857                Properties = blobItemInternal.Properties,
 1060858                VersionId = blobItemInternal.VersionId,
 1060859                IsLatestVersion = blobItemInternal.IsCurrentVersion,
 1060860                Metadata = blobItemInternal.Metadata?.Count > 0
 1060861                    ? blobItemInternal.Metadata
 1060862                    : null,
 1060863                Tags = blobItemInternal.BlobTags.ToTagDictionary(),
 1060864                ObjectReplicationSourceProperties = blobItemInternal.ObjectReplicationMetadata?.Count > 0
 1060865                    ? ParseObjectReplicationMetadata(blobItemInternal.ObjectReplicationMetadata)
 1060866                    : null
 1060867            };
 68        }
 69
 70        internal static IEnumerable<BlobItem> ToBlobItems(this IEnumerable<BlobItemInternal> blobItemInternals)
 71        {
 28072            if (blobItemInternals == null)
 73            {
 074                return null;
 75            }
 76
 28077            List<BlobItem> blobItems = new List<BlobItem>();
 138478            foreach (BlobItemInternal blobItemInternal in blobItemInternals)
 79            {
 41280                blobItems.Add(blobItemInternal.ToBlobItem());
 81            }
 28082            return blobItems;
 83        }
 84
 85        internal static string ToTagsString(this Tags tags)
 86        {
 5687            if (tags == null)
 88            {
 089                return null;
 90            }
 91
 5692            List<string> encodedTags = new List<string>();
 31293            foreach (KeyValuePair<string, string> tag in tags)
 94            {
 10095                encodedTags.Add($"{WebUtility.UrlEncode(tag.Key)}={WebUtility.UrlEncode(tag.Value)}");
 96            }
 5697            return string.Join("&", encodedTags);
 98        }
 99
 100        /// <summary>
 101        /// Creates a new BlobProperties object backed by BlobPropertiesInternal.
 102        /// </summary>
 103        /// <param name="properties">
 104        /// The BlobPropertiesInternal returned with the request.
 105        /// </param>
 106        internal static BlobProperties ToBlobProperties(this BlobPropertiesInternal properties) =>
 1372107            new BlobProperties()
 1372108            {
 1372109                LastModified = properties.LastModified,
 1372110                CreatedOn = properties.CreatedOn,
 1372111                Metadata = properties.Metadata,
 1372112                ObjectReplicationDestinationPolicyId = properties.ObjectReplicationPolicyId,
 1372113                ObjectReplicationSourceProperties =
 1372114                    properties.ObjectReplicationRules?.Count > 0
 1372115                    ? BlobExtensions.ParseObjectReplicationIds(properties.ObjectReplicationRules)
 1372116                    : null,
 1372117                BlobType = properties.BlobType,
 1372118                CopyCompletedOn = properties.CopyCompletedOn,
 1372119                CopyStatusDescription = properties.CopyStatusDescription,
 1372120                CopyId = properties.CopyId,
 1372121                CopyProgress = properties.CopyProgress,
 1372122                CopySource = properties.CopySource,
 1372123                CopyStatus = properties.CopyStatus,
 1372124                IsIncrementalCopy = properties.IsIncrementalCopy,
 1372125                DestinationSnapshot = properties.DestinationSnapshot,
 1372126                LeaseDuration = properties.LeaseDuration,
 1372127                LeaseState = properties.LeaseState,
 1372128                LeaseStatus = properties.LeaseStatus,
 1372129                ContentLength = properties.ContentLength,
 1372130                ContentType = properties.ContentType,
 1372131                ETag = properties.ETag,
 1372132                ContentHash = properties.ContentHash,
 1372133                ContentEncoding = properties.ContentEncoding,
 1372134                ContentDisposition = properties.ContentDisposition,
 1372135                ContentLanguage = properties.ContentLanguage,
 1372136                CacheControl = properties.CacheControl,
 1372137                BlobSequenceNumber = properties.BlobSequenceNumber,
 1372138                AcceptRanges = properties.AcceptRanges,
 1372139                BlobCommittedBlockCount = properties.BlobCommittedBlockCount,
 1372140                IsServerEncrypted = properties.IsServerEncrypted,
 1372141                EncryptionKeySha256 = properties.EncryptionKeySha256,
 1372142                EncryptionScope = properties.EncryptionScope,
 1372143                AccessTier = properties.AccessTier,
 1372144                AccessTierInferred = properties.AccessTierInferred,
 1372145                ArchiveStatus = properties.ArchiveStatus,
 1372146                AccessTierChangedOn = properties.AccessTierChangedOn,
 1372147                VersionId = properties.VersionId,
 1372148                IsLatestVersion = properties.IsCurrentVersion,
 1372149                TagCount = properties.TagCount,
 1372150                ExpiresOn = properties.ExpiresOn,
 1372151                IsSealed = properties.IsSealed,
 1372152                RehydratePriority = properties.RehydratePriority
 1372153            };
 154
 155        /// <summary>
 156        /// Internal. Parses Object Replication Policy ID from Rule ID and sets the Policy ID for source blobs.
 157        /// </summary>
 158        /// <param name="OrIds">
 159        /// Unparsed Object Replication headers.
 160        /// For source blobs, the dictionary will contain keys that contain the policy id and rule id separated
 161        /// by a underscore (e.g. policyId_ruleId). The value of these keys will be the replication status (e.g. Complet
 162        /// For destination blobs, the dictionary will contain one entry where the key will be "policy-id"
 163        /// and the value will be the destination policy id. No parsing will be required for this.
 164        /// </param>
 165        /// <returns>
 166        /// If the blob has object replication policy(s) applied and is the source blob, this method will return a
 167        /// List of <see cref="ObjectReplicationPolicy"/>, which contains the Policy ID and the respective
 168        /// rule(s) and replication status(s) for each policy.
 169        /// If the blob has object replication policy applied and is the destination blob,
 170        /// this method will return default as the policy id should be set in ObjectReplicationDestinationPolicyId
 171        /// (e.g. <see cref="BlobProperties.ObjectReplicationDestinationPolicyId"/>,<see cref="BlobDownloadDetails.Objec
 172        /// </returns>
 173        internal static IList<ObjectReplicationPolicy> ParseObjectReplicationIds(this IDictionary<string, string> OrIds)
 174        {
 175            try
 176            {
 177                // If the dictionary contains a key with policy id, we are not required to do any parsing since
 178                // the policy id should already be stored in the ObjectReplicationDestinationPolicyId.
 32179                KeyValuePair<string, string> destPolicy = OrIds.Single(id => (id.Key == "policy-id"));
 8180                return default;
 181            }
 8182            catch (Exception)
 183            {
 184                // If an exception is thrown by Single then we have confirmed that there's not a policy id already
 185                // stored in the ObjectReplicationDestinationPolicyId and that we have the unparsed
 186                // Object Replication headers from the source blob.
 8187            }
 8188            List<ObjectReplicationPolicy> OrProperties = new List<ObjectReplicationPolicy>();
 32189            foreach (KeyValuePair<string, string> status in OrIds)
 190            {
 8191                string[] parsedIds = status.Key.Split('_');
 0192                int policyIndex = OrProperties.FindIndex(policy => policy.PolicyId == parsedIds[0]);
 8193                if (policyIndex > -1)
 194                {
 0195                    OrProperties[policyIndex].Rules.Add(new ObjectReplicationRule()
 0196                    {
 0197                        RuleId = parsedIds[1],
 0198                        ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), status.
 0199                    });
 200                }
 201                else
 202                {
 8203                    IList<ObjectReplicationRule> NewRuleStatus = new List<ObjectReplicationRule>();
 8204                    NewRuleStatus.Add(new ObjectReplicationRule()
 8205                    {
 8206                        RuleId = parsedIds[1],
 8207                        ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), status.
 8208                    });
 8209                    OrProperties.Add(new ObjectReplicationPolicy()
 8210                    {
 8211                        PolicyId = parsedIds[0],
 8212                        Rules = NewRuleStatus
 8213                    });
 214                }
 215            }
 8216            return OrProperties;
 8217        }
 218
 219        /// <summary>
 220        /// Internal. Parses Object Replication Policy ID from Rule ID and sets the Policy ID for source blobs.
 221        /// </summary>
 222        /// <param name="OrMetadata">
 223        /// Unparsed Object Replication headers.
 224        /// For source blobs, the dictionary will contain keys that are prefixed with "or-" and followed by the
 225        /// policy id and rule id separated by a underscore (e.g. or-policyId_ruleId).
 226        /// The value of this metadata key will be the replication status (e.g. Complete, Failed).
 227        /// </param>
 228        /// <returns>
 229        /// If the blob has object replication policy(s) applied and is the source blob, this method will return a
 230        /// List of <see cref="ObjectReplicationPolicy"/>, which contains the Policy ID and the respective
 231        /// rule(s) and replication status(s) for each policy.
 232        /// </returns>
 233        internal static IList<ObjectReplicationPolicy> ParseObjectReplicationMetadata(this IDictionary<string, string> O
 234        {
 84235            List<ObjectReplicationPolicy> OrProperties = new List<ObjectReplicationPolicy>();
 336236            foreach (KeyValuePair<string, string> status in OrMetadata)
 237            {
 84238                string[] parsedIds = status.Key.Split('_');
 84239                if (parsedIds[0].StartsWith("or-", System.StringComparison.InvariantCulture))
 240                {
 84241                    parsedIds[0] = parsedIds[0].Substring("or-".Length);
 242                }
 0243                int policyIndex = OrProperties.FindIndex(policy => policy.PolicyId == parsedIds[0]);
 84244                if (policyIndex > -1)
 245                {
 0246                    OrProperties[policyIndex].Rules.Add(new ObjectReplicationRule()
 0247                    {
 0248                        RuleId = parsedIds[1],
 0249                        ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), status.
 0250                    });
 251                }
 252                else
 253                {
 84254                    IList<ObjectReplicationRule> NewRuleStatus = new List<ObjectReplicationRule>();
 84255                    NewRuleStatus.Add(new ObjectReplicationRule()
 84256                    {
 84257                        RuleId = parsedIds[1],
 84258                        ReplicationStatus = (ObjectReplicationStatus)Enum.Parse(typeof(ObjectReplicationStatus), status.
 84259                    });
 84260                    OrProperties.Add(new ObjectReplicationPolicy()
 84261                    {
 84262                        PolicyId = parsedIds[0],
 84263                        Rules = NewRuleStatus
 84264                    });
 265                }
 266            }
 84267            return OrProperties;
 268        }
 269
 270        internal static TaggedBlobItem ToBlobTagItem(this FilterBlobItem filterBlobItem)
 271        {
 42272            if (filterBlobItem == null)
 273            {
 0274                return null;
 275            }
 276
 42277            return new TaggedBlobItem
 42278            {
 42279                BlobName = filterBlobItem.BlobName,
 42280                BlobContainerName = filterBlobItem.BlobContainerName
 42281            };
 282        }
 283
 284        internal static List<TaggedBlobItem> ToBlobTagItems(this IEnumerable<FilterBlobItem> filterBlobItems)
 285        {
 12286            if (filterBlobItems == null)
 287            {
 0288                return null;
 289            }
 290
 12291            List<TaggedBlobItem> list = new List<TaggedBlobItem>();
 292
 108293            foreach (FilterBlobItem filterBlobItem in filterBlobItems)
 294            {
 42295                list.Add(filterBlobItem.ToBlobTagItem());
 296            }
 297
 12298            return list;
 299        }
 300
 301        internal static RehydratePriority? ToRehydratePriority(this string rehydratePriority)
 302        {
 0303            if (rehydratePriority == null)
 304            {
 0305                return null;
 306            }
 307
 0308            if (rehydratePriority == RehydratePriority.High.ToString())
 309            {
 0310                return RehydratePriority.High;
 311            }
 312            else
 313            {
 0314                return RehydratePriority.Standard;
 315            }
 316        }
 317    }
 318}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\BlockList.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Storage.Blobs.Models;
 6
 7#pragma warning disable SA1402  // File may only contain a single type
 8
 9namespace Azure.Storage.Blobs.Models
 10{
 11    /// <summary>
 12    /// A block blob's <see cref="BlockList"/> returned from
 13    /// <see cref="Azure.Storage.Blobs.Specialized.BlockBlobClient.GetBlockListAsync"/>.
 14    /// </summary>
 15    public partial class BlockList
 16    {
 17        /// <summary>
 18        /// Gets the date and time the container was last modified.  Any
 19        /// operation that modifies the blob, including an update of the
 20        /// blob's metadata or properties, changes the last-modified time of
 21        /// the blob.
 22        /// </summary>
 23        public DateTimeOffset LastModified { get; internal set; }
 24
 25        /// <summary>
 26        /// The <see cref="Azure.ETag"/> contains a value that you can use to
 27        /// perform operations conditionally. If the request version is
 28        /// 2011-08-18 or newer, the  ETag value will be in quotes.
 29        /// </summary>
 30        public ETag ETag { get; internal set; }
 31
 32        /// <summary>
 33        /// The media type of the body of the response. For the
 34        /// <see cref=" Specialized.BlockBlobClient.GetBlockListAsync"/>
 35        /// operation this is 'application/xml'.
 36        /// </summary>
 37        public string ContentType { get; internal set; }
 38
 39        /// <summary>
 40        /// The size of the blob, in bytes.
 41        /// </summary>
 42        public long BlobContentLength { get; internal set; }
 43    }
 44}
 45
 46namespace Azure.Storage.Blobs
 47{
 48    /// <summary>
 49    /// BlobRestClient response extensions
 50    /// </summary>
 51    internal static partial class BlobExtensions
 52    {
 53        /// <summary>
 54        /// Convert the internal GetBlockListOperation response into a BlockList.
 55        /// </summary>
 56        /// <param name="response">The original response.</param>
 57        /// <returns>The BlockList response.</returns>
 58        internal static Response<BlockList> ToBlockList(this Response<GetBlockListOperation> response)
 59        {
 60            // Return an exploding Response on 304
 5661            if (response.IsUnavailable())
 62            {
 063                return response.GetRawResponse().AsNoBodyResponse<BlockList>();
 64            }
 65
 5666            BlockList blocks = response.Value.Body;
 5667            blocks.LastModified = response.Value.LastModified;
 5668            blocks.ETag = response.Value.ETag;
 5669            blocks.ContentType = response.Value.ContentType;
 5670            blocks.BlobContentLength = response.Value.BlobContentLength;
 5671            return Response.FromValue(blocks, response.GetRawResponse());
 72        }
 73    }
 74}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\BlockListTypes.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure.Storage.Blobs.Models;
 6
 7namespace Azure.Storage.Blobs.Models
 8{
 9    /// <summary>
 10    /// Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together
 11    /// </summary>
 12    [Flags]
 13    public enum BlockListTypes
 14    {
 15        /// <summary>
 16        /// Flag to specify returning both committed and uncommitted blocks.
 17        /// </summary>
 18        All = Committed | Uncommitted,
 19
 20        /// <summary>
 21        /// Flag to specify returning the list of committed blocks.
 22        /// </summary>
 23        Committed = 1,
 24
 25        /// <summary>
 26        /// Flag to specify returning the list of uncommitted blocks.
 27        /// </summary>
 28        Uncommitted = 2
 29    }
 30}
 31
 32namespace Azure.Storage.Blobs
 33{
 34    /// <summary>
 35    /// BlockListTypes extensions
 36    /// </summary>
 37    internal static partial class BlobExtensions
 38    {
 39        /// <summary>
 40        /// Convert the BlockListTypes into a BlockListType.
 41        /// </summary>
 42        /// <param name="options"></param>
 43        /// <returns>The BlockList response.</returns>
 44        internal static BlockListType ToBlockListType(this BlockListTypes options) =>
 6845            options switch
 6846            {
 7247                BlockListTypes.Committed => BlockListType.Committed,
 7248                BlockListTypes.Uncommitted => BlockListType.Uncommitted,
 12849                _ => BlockListType.All,
 6850            };
 51    }
 52}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\GetBlobContainersAsyncCollection.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4#pragma warning disable SA1402  // File may only contain a single type
 5
 6using System.Collections.Generic;
 7using System.Diagnostics;
 8using System.Linq;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Azure.Core.Pipeline;
 12using Azure.Storage.Blobs.Models;
 13
 14namespace Azure.Storage.Blobs.Models
 15{
 16    internal class GetBlobContainersAsyncCollection : StorageCollectionEnumerator<BlobContainerItem>
 17    {
 18        private readonly BlobServiceClient _client;
 19        private readonly BlobContainerTraits _traits;
 20        private readonly BlobContainerStates _states;
 21        private readonly string _prefix;
 22
 23        public GetBlobContainersAsyncCollection(
 24            BlobServiceClient client,
 25            BlobContainerTraits traits,
 26            BlobContainerStates states,
 27            string prefix = default)
 28        {
 29            _client = client;
 30            _traits = traits;
 31            _states = states;
 32            _prefix = prefix;
 33        }
 34
 35        public override async ValueTask<Page<BlobContainerItem>> GetNextPageAsync(
 36            string continuationToken,
 37            int? pageSizeHint,
 38            bool async,
 39            CancellationToken cancellationToken)
 40        {
 41
 42            Response<BlobContainersSegment> response = await _client.GetBlobContainersInternal(
 43                    continuationToken,
 44                    _traits,
 45                    _states,
 46                    _prefix,
 47                    pageSizeHint,
 48                    async,
 49                    cancellationToken).ConfigureAwait(false);
 50
 51            return Page<BlobContainerItem>.FromValues(
 52                response.Value.BlobContainerItems.ToArray(),
 53                response.Value.NextMarker,
 54                response.GetRawResponse());
 55        }
 56    }
 57}
 58
 59namespace Azure.Storage.Blobs
 60{
 61    /// <summary>
 62    /// BlobContainerTraits/BlobContianerStates enum methods.
 63    /// </summary>
 64    internal static partial class BlobExtensions
 65    {
 66        /// <summary>
 67        /// Convert the details into ListContainersIncludeType values.
 68        /// </summary>
 69        /// <returns>ListContainersIncludeType values</returns>
 70        internal static IEnumerable<ListContainersIncludeType> AsIncludeItems(BlobContainerTraits traits, BlobContainerS
 71        {
 72            // Remove this line
 73            Debug.Assert(states == BlobContainerStates.None);
 6874            var items = new List<ListContainersIncludeType>();
 75            // Uncomment when feature is re-enabled.
 76            //if ((states & BlobContainerStates.Deleted) == BlobContainerStates.Deleted)
 77            //{
 78            //    items.Add(ListContainersIncludeType.Deleted);
 79            //}
 6880            if ((traits & BlobContainerTraits.Metadata) == BlobContainerTraits.Metadata)
 81            {
 882                items.Add(ListContainersIncludeType.Metadata);
 83            }
 84
 6885            return items.Count > 0 ? items : null;
 86        }
 87    }
 88}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\GetBlobsAsyncCollection.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4#pragma warning disable SA1402  // File may only contain a single type
 5
 6using System.Collections.Generic;
 7using System.Linq;
 8using System.Threading;
 9using System.Threading.Tasks;
 10using Azure.Core.Pipeline;
 11using Azure.Storage.Blobs.Models;
 12
 13namespace Azure.Storage.Blobs.Models
 14{
 15    internal class GetBlobsAsyncCollection : StorageCollectionEnumerator<BlobItem>
 16    {
 17        private readonly BlobContainerClient _client;
 18        private readonly BlobTraits _traits;
 19        private readonly BlobStates _states;
 20        private readonly string _prefix;
 21
 22        public GetBlobsAsyncCollection(
 23            BlobContainerClient client,
 24            BlobTraits traits,
 25            BlobStates states,
 26            string prefix)
 27        {
 28            _client = client;
 29            _traits = traits;
 30            _states = states;
 31            _prefix = prefix;
 32        }
 33
 34        public override async ValueTask<Page<BlobItem>> GetNextPageAsync(
 35            string continuationToken,
 36            int? pageSizeHint,
 37            bool async,
 38            CancellationToken cancellationToken)
 39        {
 40            Response<BlobsFlatSegment> response = await _client.GetBlobsInternal(
 41                continuationToken,
 42                _traits,
 43                _states,
 44                _prefix,
 45                pageSizeHint,
 46                async,
 47                cancellationToken).ConfigureAwait(false);
 48
 49            return Page<BlobItem>.FromValues(
 50                response.Value.BlobItems.ToBlobItems().ToArray(),
 51                response.Value.NextMarker,
 52                response.GetRawResponse());
 53        }
 54    }
 55}
 56
 57namespace Azure.Storage.Blobs
 58{
 59    /// <summary>
 60    /// BlobTraits/BlobStates enum methods
 61    /// </summary>
 62    internal static partial class BlobExtensions
 63    {
 64        /// <summary>
 65        /// Convert the details into ListBlobsIncludeItem values.
 66        /// </summary>
 67        /// <returns>ListBlobsIncludeItem values</returns>
 68        internal static IEnumerable<ListBlobsIncludeItem> AsIncludeItems(BlobTraits traits, BlobStates states)
 69        {
 70            // NOTE: Multiple strings MUST be appended in alphabetic order or signing the string for authentication fail
 71            // TODO: Remove this requirement by pushing it closer to header generation.
 58272            var items = new List<ListBlobsIncludeItem>();
 58273            if ((traits & BlobTraits.CopyStatus) == BlobTraits.CopyStatus)
 74            {
 475                items.Add(ListBlobsIncludeItem.Copy);
 76            }
 58277            if ((states & BlobStates.Deleted) == BlobStates.Deleted)
 78            {
 1679                items.Add(ListBlobsIncludeItem.Deleted);
 80            }
 58281            if ((traits & BlobTraits.Metadata) == BlobTraits.Metadata)
 82            {
 1883                items.Add(ListBlobsIncludeItem.Metadata);
 84            }
 58285            if ((states & BlobStates.Snapshots) == BlobStates.Snapshots)
 86            {
 1487                items.Add(ListBlobsIncludeItem.Snapshots);
 88            }
 58289            if ((traits & BlobTraits.Tags) == BlobTraits.Tags)
 90            {
 891                items.Add(ListBlobsIncludeItem.Tags);
 92            }
 58293            if ((states & BlobStates.Uncommitted) == BlobStates.Uncommitted)
 94            {
 1295                items.Add(ListBlobsIncludeItem.Uncommittedblobs);
 96            }
 58297            if ((states & BlobStates.Version) == BlobStates.Version)
 98            {
 899                items.Add(ListBlobsIncludeItem.Versions);
 100            }
 582101            return items.Count > 0 ? items : null;
 102        }
 103    }
 104}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Models\Lease.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using Azure;
 6using Azure.Storage.Blobs.Models;
 7
 8#pragma warning disable SA1402  // File may only contain a single type
 9
 10namespace Azure.Storage.Blobs.Models
 11{
 12    /// <summary>
 13    /// Lease
 14    /// </summary>
 15    public partial class BlobLease
 16    {
 17        /// <summary>
 18        /// Gets the approximate time remaining in the lease period, in
 19        /// seconds.  This is only provided when breaking a lease.
 20        /// </summary>
 21        public int? LeaseTime { get; internal set; }
 22    }
 23}
 24
 25namespace Azure.Storage.Blobs
 26{
 27    /// <summary>
 28    /// BlobRestClient response extensions
 29    /// </summary>
 30    internal static partial class BlobExtensions
 31    {
 32        /// <summary>
 33        /// Convert the internal BrokenLease response into a Lease.  The
 34        /// LeaseId will be empty.
 35        /// </summary>
 36        /// <param name="response">The original response.</param>
 37        /// <returns>The Lease response.</returns>
 38        internal static Response<BlobLease> ToLease(this Response<BrokenLease> response)
 11239            => Response.FromValue(
 11240                new BlobLease
 11241                {
 11242                    ETag = response.Value.ETag,
 11243                    LastModified = response.Value.LastModified,
 11244                    LeaseTime = response.Value.LeaseTime
 11245                }, response.GetRawResponse());
 46    }
 47}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobAccountSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6using Azure.Storage.Sas;
 7
 8namespace Azure.Storage.Sas
 9{
 10    /// <summary>
 11    /// <see cref="BlobAccountSasPermissions"/> contains the list of
 12    /// permissions that can be set for a blob account's access policy.  Use
 13    /// <see cref="BlobSasBuilder.SetPermissions(BlobAccountSasPermissions)"/>
 14    /// to set the permissions on the <see cref="BlobSasBuilder"/>.
 15    /// </summary>
 16    [Flags]
 17    public enum BlobAccountSasPermissions
 18    {
 19        /// <summary>
 20        /// Indicates that Read is permitted.
 21        /// </summary>
 22        Read = 1,
 23
 24        /// <summary>
 25        /// Indicates that Add is permitted.
 26        /// </summary>
 27        Add = 2,
 28
 29        /// <summary>
 30        /// Indicates that Create is permitted.
 31        /// </summary>
 32        Create = 4,
 33
 34        /// <summary>
 35        /// Indicates that Write is permitted.
 36        /// </summary>
 37        Write = 8,
 38
 39        /// <summary>
 40        /// Indicates that Delete is permitted.
 41        /// </summary>
 42        Delete = 16,
 43
 44        /// <summary>
 45        /// Indicates that List is permitted.
 46        /// </summary>
 47        List = 32,
 48
 49        /// <summary>
 50        /// Indicates that all permissions are set.
 51        /// </summary>
 52        All = ~0
 53    }
 54}
 55
 56namespace Azure.Storage.Blobs
 57{
 58    /// <summary>
 59    /// Blob enum extensions
 60    /// </summary>
 61    internal static partial class BlobExtensions
 62    {
 63
 64        /// <summary>
 65        /// Create a permissions string to provide
 66        /// <see cref="BlobSasBuilder.Permissions"/>.
 67        /// </summary>
 68        /// <returns>A permissions string.</returns>
 69        internal static string ToPermissionsString(this BlobAccountSasPermissions permissions)
 70        {
 2871            var sb = new StringBuilder();
 2872            if ((permissions & BlobAccountSasPermissions.Read) == BlobAccountSasPermissions.Read)
 73            {
 2874                sb.Append(Constants.Sas.Permissions.Read);
 75            }
 2876            if ((permissions & BlobAccountSasPermissions.Add) == BlobAccountSasPermissions.Add)
 77            {
 078                sb.Append(Constants.Sas.Permissions.Add);
 79            }
 2880            if ((permissions & BlobAccountSasPermissions.Create) == BlobAccountSasPermissions.Create)
 81            {
 082                sb.Append(Constants.Sas.Permissions.Create);
 83            }
 2884            if ((permissions & BlobAccountSasPermissions.Write) == BlobAccountSasPermissions.Write)
 85            {
 2886                sb.Append(Constants.Sas.Permissions.Write);
 87            }
 2888            if ((permissions & BlobAccountSasPermissions.Delete) == BlobAccountSasPermissions.Delete)
 89            {
 2890                sb.Append(Constants.Sas.Permissions.Delete);
 91            }
 2892            if ((permissions & BlobAccountSasPermissions.List) == BlobAccountSasPermissions.List)
 93            {
 094                sb.Append(Constants.Sas.Permissions.List);
 95            }
 2896            return sb.ToString();
 97        }
 98    }
 99}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobContainerSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6using Azure.Storage.Sas;
 7
 8namespace Azure.Storage.Sas
 9{
 10    /// <summary>
 11    /// <see cref="BlobContainerSasPermissions"/> contains the list of
 12    /// permissions that can be set for a blob's access policy.  Use
 13    /// <see cref="BlobSasBuilder.SetPermissions(BlobContainerSasPermissions)"/>
 14    /// to set the permissions on the <see cref="BlobSasBuilder"/>.
 15    /// </summary>
 16    [Flags]
 17    public enum BlobContainerSasPermissions
 18    {
 19        /// <summary>
 20        /// Indicates that Read is permitted.
 21        /// </summary>
 22        Read = 1,
 23
 24        /// <summary>
 25        /// Indicates that Add is permitted.
 26        /// </summary>
 27        Add = 2,
 28
 29        /// <summary>
 30        /// Indicates that Create is permitted.
 31        /// </summary>
 32        Create = 4,
 33
 34        /// <summary>
 35        /// Indicates that Write is permitted.
 36        /// </summary>
 37        Write = 8,
 38
 39        /// <summary>
 40        /// Indicates that Delete is permitted.
 41        /// </summary>
 42        Delete = 16,
 43
 44        /// <summary>
 45        /// Indicates that List is permitted.
 46        /// </summary>
 47        List = 32,
 48
 49        /// <summary>
 50        /// Indicates that reading and writing Tags are permitted.
 51        /// </summary>
 52        Tag = 64,
 53
 54        /// <summary>
 55        /// Indicates that deleting a Blob Version is permitted.
 56        /// </summary>
 57        DeleteBlobVersion = 128,
 58
 59        /// <summary>
 60        /// Indicates that all permissions are set.
 61        /// </summary>
 62        All = ~0
 63    }
 64}
 65
 66namespace Azure.Storage.Blobs
 67{
 68    /// <summary>
 69    /// Blob enum extensions.
 70    /// </summary>
 71    internal static partial class BlobExtensions
 72    {
 73
 74        /// <summary>
 75        /// Create a permissions string to provide
 76        /// <see cref="BlobSasBuilder.Permissions"/>.
 77        /// </summary>
 78        /// <returns>A permissions string.</returns>
 79        internal static string ToPermissionsString(this BlobContainerSasPermissions permissions)
 80        {
 5281            var sb = new StringBuilder();
 5282            if ((permissions & BlobContainerSasPermissions.Read) == BlobContainerSasPermissions.Read)
 83            {
 3684                sb.Append(Constants.Sas.Permissions.Read);
 85            }
 5286            if ((permissions & BlobContainerSasPermissions.Add) == BlobContainerSasPermissions.Add)
 87            {
 2088                sb.Append(Constants.Sas.Permissions.Add);
 89            }
 5290            if ((permissions & BlobContainerSasPermissions.Create) == BlobContainerSasPermissions.Create)
 91            {
 2092                sb.Append(Constants.Sas.Permissions.Create);
 93            }
 5294            if ((permissions & BlobContainerSasPermissions.Write) == BlobContainerSasPermissions.Write)
 95            {
 2096                sb.Append(Constants.Sas.Permissions.Write);
 97            }
 5298            if ((permissions & BlobContainerSasPermissions.Delete) == BlobContainerSasPermissions.Delete)
 99            {
 20100                sb.Append(Constants.Sas.Permissions.Delete);
 101            }
 52102            if ((permissions & BlobContainerSasPermissions.DeleteBlobVersion) == BlobContainerSasPermissions.DeleteBlobV
 103            {
 24104                sb.Append(Constants.Sas.Permissions.DeleteBlobVersion);
 105            }
 52106            if ((permissions & BlobContainerSasPermissions.List) == BlobContainerSasPermissions.List)
 107            {
 20108                sb.Append(Constants.Sas.Permissions.List);
 109            }
 52110            if ((permissions & BlobContainerSasPermissions.Tag) == BlobContainerSasPermissions.Tag)
 111            {
 24112                sb.Append(Constants.Sas.Permissions.Tag);
 113            }
 52114            return sb.ToString();
 115        }
 116    }
 117}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6using Azure.Storage.Sas;
 7
 8namespace Azure.Storage.Sas
 9{
 10    /// <summary>
 11    /// <see cref="BlobSasPermissions"/> contains the list of
 12    /// permissions that can be set for a blob's access policy.  Use
 13    /// <see cref="BlobSasBuilder.SetPermissions(BlobSasPermissions)"/>
 14    /// to set the permissions on the <see cref="BlobSasBuilder"/>.
 15    /// </summary>
 16    [Flags]
 17    public enum BlobSasPermissions
 18    {
 19        /// <summary>
 20        /// Indicates that Read is permitted.
 21        /// </summary>
 22        Read = 1,
 23
 24        /// <summary>
 25        /// Indicates that Add is permitted.
 26        /// </summary>
 27        Add = 2,
 28
 29        /// <summary>
 30        /// Indicates that Create is permitted.
 31        /// </summary>
 32        Create = 4,
 33
 34        /// <summary>
 35        /// Indicates that Write is permitted.
 36        /// </summary>
 37        Write = 8,
 38
 39        /// <summary>
 40        /// Indicates that Delete is permitted.
 41        /// </summary>
 42        Delete = 16,
 43
 44        /// <summary>
 45        /// Indicates that reading and writing Tags are permitted.
 46        /// </summary>
 47        Tag = 32,
 48
 49        /// <summary>
 50        /// Indicates that deleting a Blob Version is permitted.
 51        /// </summary>
 52        DeleteBlobVersion = 64,
 53
 54        /// <summary>
 55        /// Indicates that all permissions are set.
 56        /// </summary>
 57        All = ~0
 58    }
 59}
 60
 61namespace Azure.Storage.Blobs
 62{
 63    /// <summary>
 64    /// Blob enum extensions
 65    /// </summary>
 66    internal static partial class BlobExtensions
 67    {
 68
 69        /// <summary>
 70        /// Create a permissions string to provide
 71        /// <see cref="BlobSasBuilder.Permissions"/>.
 72        /// </summary>
 73        /// <returns>A permissions string.</returns>
 74        internal static string ToPermissionsString(this BlobSasPermissions permissions)
 75        {
 7676            var sb = new StringBuilder();
 7677            if ((permissions & BlobSasPermissions.Read) == BlobSasPermissions.Read)
 78            {
 6079                sb.Append(Constants.Sas.Permissions.Read);
 80            }
 7681            if ((permissions & BlobSasPermissions.Add) == BlobSasPermissions.Add)
 82            {
 4083                sb.Append(Constants.Sas.Permissions.Add);
 84            }
 7685            if ((permissions & BlobSasPermissions.Create) == BlobSasPermissions.Create)
 86            {
 4087                sb.Append(Constants.Sas.Permissions.Create);
 88            }
 7689            if ((permissions & BlobSasPermissions.Write) == BlobSasPermissions.Write)
 90            {
 4091                sb.Append(Constants.Sas.Permissions.Write);
 92            }
 7693            if ((permissions & BlobSasPermissions.Delete) == BlobSasPermissions.Delete)
 94            {
 4095                sb.Append(Constants.Sas.Permissions.Delete);
 96            }
 7697            if ((permissions & BlobSasPermissions.DeleteBlobVersion) == BlobSasPermissions.DeleteBlobVersion)
 98            {
 2099                sb.Append(Constants.Sas.Permissions.DeleteBlobVersion);
 100            }
 76101            if ((permissions & BlobSasPermissions.Tag) == BlobSasPermissions.Tag)
 102            {
 20103                sb.Append(Constants.Sas.Permissions.Tag);
 104            }
 76105            return sb.ToString();
 106        }
 107    }
 108}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\BlobVersionSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Text;
 7using Azure.Storage.Sas;
 8
 9namespace Azure.Storage.Sas
 10{
 11    /// <summary>
 12    /// <see cref="BlobVersionSasPermissions"/> contains the list of
 13    /// permissions that can be set for a blob bersion.  Use
 14    /// <see cref="BlobSasBuilder.SetPermissions(BlobVersionSasPermissions)"/>
 15    /// to set the permissions on the <see cref="BlobSasBuilder"/>.
 16    /// </summary>
 17    [Flags]
 18    public enum BlobVersionSasPermissions
 19    {
 20        /// <summary>
 21        /// Indicates that Delete is permitted.
 22        /// </summary>
 23        Delete = 1,
 24
 25        /// <summary>
 26        /// Indicates that all permissions are set.
 27        /// </summary>
 28        All = ~0
 29    }
 30}
 31
 32namespace Azure.Storage.Blobs
 33{
 34    /// <summary>
 35    /// Blob enum extensions.
 36    /// </summary>
 37    internal static partial class BlobExtensions
 38    {
 39
 40        /// <summary>
 41        /// Create a permissions string to provide
 42        /// <see cref="BlobSasBuilder.Permissions"/>.
 43        /// </summary>
 44        /// <returns>A permissions string.</returns>
 45        internal static string ToPermissionsString(this BlobVersionSasPermissions permissions)
 46        {
 847            var sb = new StringBuilder();
 848            if ((permissions & BlobVersionSasPermissions.Delete) == BlobVersionSasPermissions.Delete)
 49            {
 850                sb.Append(Constants.Sas.Permissions.DeleteBlobVersion);
 51            }
 852            return sb.ToString();
 53        }
 54    }
 55}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs\src\Sas\SnapshotSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6using Azure.Storage.Sas;
 7
 8namespace Azure.Storage.Sas
 9{
 10    /// <summary>
 11    /// <see cref="SnapshotSasPermissions"/> contains the list of
 12    /// permissions that can be set for a blob's access policy.  Use
 13    /// <see cref="BlobSasBuilder.SetPermissions(SnapshotSasPermissions)"/>
 14    /// to set the permissions on the <see cref="BlobSasBuilder"/>.
 15    /// </summary>
 16    [Flags]
 17    public enum SnapshotSasPermissions
 18    {
 19        /// <summary>
 20        /// Indicates that Read is permitted.
 21        /// </summary>
 22        Read = 1,
 23
 24        /// <summary>
 25        /// Indicates that Write is permitted.
 26        /// </summary>
 27        Write = 2,
 28
 29        /// <summary>
 30        /// Indicates that Delete is permitted.
 31        /// </summary>
 32        Delete = 4,
 33
 34        /// <summary>
 35        /// Indicates that all permissions are set.
 36        /// </summary>
 37        All = ~0
 38    }
 39}
 40
 41namespace Azure.Storage.Blobs
 42{
 43    /// <summary>
 44    /// Blob enum extensions.
 45    /// </summary>
 46    internal static partial class BlobExtensions
 47    {
 48
 49        /// <summary>
 50        /// Create a permissions string to provide
 51        /// <see cref="BlobSasBuilder.Permissions"/>.
 52        /// </summary>
 53        /// <returns>A permissions string.</returns>
 54        internal static string ToPermissionsString(this SnapshotSasPermissions permissions)
 55        {
 1256            var sb = new StringBuilder();
 1257            if ((permissions & SnapshotSasPermissions.Read) == SnapshotSasPermissions.Read)
 58            {
 1259                sb.Append(Constants.Sas.Permissions.Read);
 60            }
 1261            if ((permissions & SnapshotSasPermissions.Write) == SnapshotSasPermissions.Write)
 62            {
 863                sb.Append(Constants.Sas.Permissions.Write);
 64            }
 1265            if ((permissions & SnapshotSasPermissions.Delete) == SnapshotSasPermissions.Delete)
 66            {
 867                sb.Append(Constants.Sas.Permissions.Delete);
 68            }
 1269            return sb.ToString();
 70        }
 71    }
 72}