< Summary

Class:Azure.Storage.Files.DataLake.DataLakeExtensions
Assembly:Azure.Storage.Files.DataLake
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\DataLakeExtensions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeAccountSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeFileSystemSasPermissions.cs
C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeSasPermissions.cs
Covered lines:231
Uncovered lines:63
Coverable lines:294
Total lines:702
Line coverage:78.5% (231 of 294)
Covered branches:53
Total branches:86
Branch coverage:61.6% (53 of 86)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
ToFileSystemItem(...)-100%100%
ToFileSystemProperties(...)-100%75%
ToFileDownloadDetails(...)-100%100%
ToFileDownloadInfo(...)-100%100%
ToPathProperties(...)-100%100%
ToPathInfo(...)-100%100%
ToDataLakeLease(...)-100%100%
ToBlobHttpHeaders(...)-90.91%50%
ToBlobRequestConditions(...)-100%100%
ToPathItem(...)-100%100%
ToPathContentInfo(...)-0%100%
ToMetadata(...)-0%0%
ToFileSystemAccessPolicy(...)-88.89%50%
ToDataLakeSignedIdentifiers(...)-66.67%50%
ToDataLakeSignedIdentifier(...)-85.71%50%
ToDataLakeAccessPolicy(...)-87.5%50%
ToBlobSignedIdentifiers(...)-100%100%
ToBlobSignedIdentifier(...)-85.71%50%
ToBlobAccessPolicy(...)-87.5%50%
ToBlobQueryOptions(...)-100%100%
ToBlobQueryTextConfiguration(...)-28.57%16.67%
ToBlobQueryJsonTextConfiguration(...)-0%100%
ToBlobQueryCsvTextConfiguration(...)-0%100%
ToDataLakeQueryError(...)-88.89%50%
ToPermissionsString(...)-0%0%
ToPermissionsString(...)-100%100%
ToPermissionsString(...)-100%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\DataLakeExtensions.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.Globalization;
 7using System.Linq;
 8using System.Text;
 9using Azure.Storage.Blobs.Models;
 10using Azure.Storage.Files.DataLake.Models;
 11
 12namespace Azure.Storage.Files.DataLake
 13{
 14    internal static partial class DataLakeExtensions
 15    {
 16        internal static FileSystemItem ToFileSystemItem(this BlobContainerItem containerItem) =>
 1985817            new FileSystemItem()
 1985818            {
 1985819                Name = containerItem.Name,
 1985820                Properties = containerItem.Properties.ToFileSystemProperties()
 1985821            };
 22
 23        internal static FileSystemProperties ToFileSystemProperties(this BlobContainerProperties containerProperties) =>
 1992224                new FileSystemProperties()
 1992225                {
 1992226                    LastModified = containerProperties.LastModified,
 1992227                    LeaseStatus = containerProperties.LeaseStatus.HasValue
 1992228                        ? (Models.DataLakeLeaseStatus)containerProperties.LeaseStatus : default,
 1992229                    LeaseState = containerProperties.LeaseState.HasValue
 1992230                        ? (Models.DataLakeLeaseState)containerProperties.LeaseState : default,
 1992231                    LeaseDuration = containerProperties.LeaseDuration.HasValue
 1992232                        ? (Models.DataLakeLeaseDuration)containerProperties.LeaseDuration : default,
 1992233                    PublicAccess = containerProperties.PublicAccess.HasValue
 1992234                        ? (Models.PublicAccessType)containerProperties.PublicAccess : default,
 1992235                    HasImmutabilityPolicy = containerProperties.HasImmutabilityPolicy,
 1992236                    HasLegalHold = containerProperties.HasLegalHold,
 1992237                    ETag = containerProperties.ETag,
 1992238                    Metadata = containerProperties.Metadata
 1992239                };
 40
 41        internal static FileDownloadDetails ToFileDownloadDetails(this BlobDownloadDetails blobDownloadProperties) =>
 8042            new FileDownloadDetails()
 8043            {
 8044                LastModified = blobDownloadProperties.LastModified,
 8045                Metadata = blobDownloadProperties.Metadata,
 8046                ContentRange = blobDownloadProperties.ContentRange,
 8047                ETag = blobDownloadProperties.ETag,
 8048                ContentEncoding = blobDownloadProperties.ContentEncoding,
 8049                ContentDisposition = blobDownloadProperties.ContentDisposition,
 8050                ContentLanguage = blobDownloadProperties.ContentLanguage,
 8051                CopyCompletedOn = blobDownloadProperties.CopyCompletedOn,
 8052                CopyStatusDescription = blobDownloadProperties.CopyStatusDescription,
 8053                CopyId = blobDownloadProperties.CopyId,
 8054                CopyProgress = blobDownloadProperties.CopyProgress,
 8055                CopyStatus = (Models.CopyStatus)blobDownloadProperties.CopyStatus,
 8056                LeaseDuration = (Models.DataLakeLeaseDuration)blobDownloadProperties.LeaseDuration,
 8057                LeaseState = (Models.DataLakeLeaseState)blobDownloadProperties.LeaseState,
 8058                LeaseStatus = (Models.DataLakeLeaseStatus)blobDownloadProperties.LeaseStatus,
 8059                AcceptRanges = blobDownloadProperties.AcceptRanges,
 8060                IsServerEncrypted = blobDownloadProperties.IsServerEncrypted,
 8061                EncryptionKeySha256 = blobDownloadProperties.EncryptionKeySha256,
 8062                ContentHash = blobDownloadProperties.BlobContentHash
 8063            };
 64
 65        internal static FileDownloadInfo ToFileDownloadInfo(this BlobDownloadInfo blobDownloadInfo) =>
 8066            new FileDownloadInfo()
 8067            {
 8068                ContentLength = blobDownloadInfo.ContentLength,
 8069                Content = blobDownloadInfo.Content,
 8070                ContentHash = blobDownloadInfo.ContentHash,
 8071                Properties = blobDownloadInfo.Details.ToFileDownloadDetails()
 8072            };
 73
 74        internal static PathProperties ToPathProperties(this BlobProperties blobProperties) =>
 63675            new PathProperties()
 63676            {
 63677                LastModified = blobProperties.LastModified,
 63678                CreatedOn = blobProperties.CreatedOn,
 63679                Metadata = blobProperties.Metadata,
 63680                CopyCompletedOn = blobProperties.CopyCompletedOn,
 63681                CopyStatusDescription = blobProperties.CopyStatusDescription,
 63682                CopyId = blobProperties.CopyId,
 63683                CopyProgress = blobProperties.CopyProgress,
 63684                CopySource = blobProperties.CopySource,
 63685                IsIncrementalCopy = blobProperties.IsIncrementalCopy,
 63686                LeaseDuration = (Models.DataLakeLeaseDuration)blobProperties.LeaseDuration,
 63687                LeaseStatus = (Models.DataLakeLeaseStatus)blobProperties.LeaseStatus,
 63688                LeaseState = (Models.DataLakeLeaseState)blobProperties.LeaseState,
 63689                ContentLength = blobProperties.ContentLength,
 63690                ContentType = blobProperties.ContentType,
 63691                ETag = blobProperties.ETag,
 63692                ContentHash = blobProperties.ContentHash,
 63693                ContentEncoding = blobProperties.ContentEncoding,
 63694                ContentDisposition = blobProperties.ContentDisposition,
 63695                ContentLanguage = blobProperties.ContentLanguage,
 63696                CacheControl = blobProperties.CacheControl,
 63697                AcceptRanges = blobProperties.AcceptRanges,
 63698                IsServerEncrypted = blobProperties.IsServerEncrypted,
 63699                EncryptionKeySha256 = blobProperties.EncryptionKeySha256,
 636100                AccessTier = blobProperties.AccessTier,
 636101                ArchiveStatus = blobProperties.ArchiveStatus,
 636102                AccessTierChangedOn = blobProperties.AccessTierChangedOn,
 636103                ExpiresOn = blobProperties.ExpiresOn
 636104            };
 105
 106        internal static PathInfo ToPathInfo(this BlobInfo blobInfo) =>
 112107            new PathInfo
 112108            {
 112109                ETag = blobInfo.ETag,
 112110                LastModified = blobInfo.LastModified
 112111            };
 112
 113        internal static DataLakeLease ToDataLakeLease(this BlobLease blobLease) =>
 792114            new DataLakeLease()
 792115            {
 792116                ETag = blobLease.ETag,
 792117                LastModified = blobLease.LastModified,
 792118                LeaseId = blobLease.LeaseId,
 792119                LeaseTime = blobLease.LeaseTime
 792120            };
 121
 122        internal static BlobHttpHeaders ToBlobHttpHeaders(this PathHttpHeaders pathHttpHeaders)
 123        {
 104124            if (pathHttpHeaders == null)
 125            {
 0126                return null;
 127            }
 128
 104129            return new BlobHttpHeaders()
 104130            {
 104131                ContentType = pathHttpHeaders.ContentType,
 104132                ContentHash = pathHttpHeaders.ContentHash,
 104133                ContentEncoding = pathHttpHeaders.ContentEncoding,
 104134                ContentLanguage = pathHttpHeaders.ContentLanguage,
 104135                ContentDisposition = pathHttpHeaders.ContentDisposition,
 104136                CacheControl = pathHttpHeaders.CacheControl
 104137            };
 138        }
 139
 140        internal static BlobRequestConditions ToBlobRequestConditions(this DataLakeRequestConditions dataLakeRequestCond
 141        {
 3994142            if (dataLakeRequestConditions == null)
 143            {
 3394144                return null;
 145            }
 146
 600147            return new BlobRequestConditions()
 600148            {
 600149                IfMatch = dataLakeRequestConditions.IfMatch,
 600150                IfNoneMatch = dataLakeRequestConditions.IfNoneMatch,
 600151                IfModifiedSince = dataLakeRequestConditions.IfModifiedSince,
 600152                IfUnmodifiedSince = dataLakeRequestConditions.IfUnmodifiedSince,
 600153                LeaseId = dataLakeRequestConditions.LeaseId
 600154            };
 155        }
 156
 157        internal static PathItem ToPathItem(this Dictionary<string, string> dictionary)
 158        {
 276159            dictionary.TryGetValue("name", out string name);
 276160            dictionary.TryGetValue("isDirectory", out string isDirectoryString);
 276161            dictionary.TryGetValue("lastModified", out string lastModifiedString);
 276162            dictionary.TryGetValue("etag", out string etagString);
 276163            dictionary.TryGetValue("contentLength", out string contentLengthString);
 276164            dictionary.TryGetValue("owner", out string owner);
 276165            dictionary.TryGetValue("group", out string group);
 276166            dictionary.TryGetValue("permissions", out string permissions);
 167
 276168            bool isDirectory = false;
 276169            if (isDirectoryString != null)
 170            {
 216171                isDirectory = bool.Parse(isDirectoryString);
 172            }
 173
 276174            DateTimeOffset lastModified = new DateTimeOffset();
 276175            if (lastModifiedString != null)
 176            {
 276177                lastModified = DateTimeOffset.Parse(lastModifiedString, CultureInfo.InvariantCulture);
 178            }
 179
 276180            ETag eTag = new ETag();
 276181            if (etagString != null)
 182            {
 276183                eTag = new ETag(etagString);
 184            }
 185
 276186            long contentLength = 0;
 276187            if (contentLengthString != null)
 188            {
 268189                contentLength = long.Parse(contentLengthString, CultureInfo.InvariantCulture);
 190            }
 191
 276192            PathItem pathItem = new PathItem()
 276193            {
 276194                Name = name,
 276195                IsDirectory = isDirectory,
 276196                LastModified = lastModified,
 276197                ETag = eTag,
 276198                ContentLength = contentLength,
 276199                Owner = owner,
 276200                Group = group,
 276201                Permissions = permissions
 276202            };
 276203            return pathItem;
 204        }
 205
 206        internal static PathContentInfo ToPathContentInfo(this PathUpdateResult pathUpdateResult) =>
 0207            new PathContentInfo()
 0208            {
 0209                ContentHash = pathUpdateResult.ContentMD5,
 0210                ETag = pathUpdateResult.ETag,
 0211                LastModified = pathUpdateResult.LastModified,
 0212                AcceptRanges = pathUpdateResult.AcceptRanges,
 0213                CacheControl = pathUpdateResult.CacheControl,
 0214                ContentDisposition = pathUpdateResult.ContentDisposition,
 0215                ContentEncoding = pathUpdateResult.ContentEncoding,
 0216                ContentLanguage = pathUpdateResult.ContentLanguage,
 0217                ContentLength = pathUpdateResult.ContentLength,
 0218                ContentRange = pathUpdateResult.ContentRange,
 0219                ContentType = pathUpdateResult.ContentType,
 0220                Metadata = ToMetadata(pathUpdateResult.Properties)
 0221            };
 222
 223        private static IDictionary<string, string> ToMetadata(string rawMetdata)
 224        {
 0225            if (rawMetdata == null)
 226            {
 0227                return null;
 228            }
 229
 0230            IDictionary<string, string> metadataDictionary = new Dictionary<string, string>(StringComparer.InvariantCult
 0231            string[] metadataArray = rawMetdata.Split(',');
 0232            foreach (string entry in metadataArray)
 233            {
 0234                string[] entryArray = entry.Split('=');
 0235                if (entryArray.Length == 2)
 236                {
 0237                    byte[] valueArray = Convert.FromBase64String(entryArray[1]);
 0238                    metadataDictionary.Add(entryArray[0], Encoding.UTF8.GetString(valueArray));
 239                }
 240            }
 0241            return metadataDictionary;
 242        }
 243
 244        internal static FileSystemAccessPolicy ToFileSystemAccessPolicy(this BlobContainerAccessPolicy blobContainerAcce
 245        {
 24246            if (blobContainerAccessPolicy == null)
 247            {
 0248                return null;
 249            }
 250
 24251            return new FileSystemAccessPolicy()
 24252            {
 24253                DataLakePublicAccess = (Models.PublicAccessType)blobContainerAccessPolicy.BlobPublicAccess,
 24254                ETag = blobContainerAccessPolicy.ETag,
 24255                LastModified = blobContainerAccessPolicy.LastModified,
 24256                SignedIdentifiers = blobContainerAccessPolicy.SignedIdentifiers.ToDataLakeSignedIdentifiers()
 24257            };
 258        }
 259
 260        internal static IEnumerable<DataLakeSignedIdentifier> ToDataLakeSignedIdentifiers(this IEnumerable<BlobSignedIde
 261        {
 24262            if (blobSignedIdentifiers == null)
 263            {
 0264                return null;
 265            }
 266
 56267            return blobSignedIdentifiers.ToList().Select(r => r.ToDataLakeSignedIdentifier());
 268        }
 269
 270        internal static DataLakeSignedIdentifier ToDataLakeSignedIdentifier(this BlobSignedIdentifier blobSignedIdentifi
 271        {
 32272            if (blobSignedIdentifier == null)
 273            {
 0274                return null;
 275            }
 276
 32277            return new DataLakeSignedIdentifier()
 32278            {
 32279                AccessPolicy = blobSignedIdentifier.AccessPolicy.ToDataLakeAccessPolicy(),
 32280                Id = blobSignedIdentifier.Id
 32281            };
 282        }
 283
 284        internal static DataLakeAccessPolicy ToDataLakeAccessPolicy(this BlobAccessPolicy blobAccessPolicy)
 285        {
 32286            if (blobAccessPolicy == null)
 287            {
 0288                return null;
 289            }
 290
 32291            return new DataLakeAccessPolicy()
 32292            {
 32293                PolicyStartsOn = blobAccessPolicy.PolicyStartsOn,
 32294                PolicyExpiresOn = blobAccessPolicy.PolicyExpiresOn,
 32295                Permissions = blobAccessPolicy.Permissions
 32296            };
 297        }
 298
 299        internal static IEnumerable<BlobSignedIdentifier> ToBlobSignedIdentifiers(this IEnumerable<DataLakeSignedIdentif
 300        {
 56301            if (dataLakeSignedIdentifiers == null)
 302            {
 4303                return null;
 304            }
 305
 104306            return dataLakeSignedIdentifiers.ToList().Select(r => r.ToBlobSignedIdentifier());
 307        }
 308
 309        internal static BlobSignedIdentifier ToBlobSignedIdentifier(this DataLakeSignedIdentifier dataLakeSignedIdentifi
 310        {
 52311            if (dataLakeSignedIdentifier == null)
 312            {
 0313                return null;
 314            }
 315
 52316            return new BlobSignedIdentifier()
 52317            {
 52318                AccessPolicy = dataLakeSignedIdentifier.AccessPolicy.ToBlobAccessPolicy(),
 52319                Id = dataLakeSignedIdentifier.Id
 52320            };
 321        }
 322
 323        internal static BlobAccessPolicy ToBlobAccessPolicy(this DataLakeAccessPolicy dataLakeAccessPolicy)
 324        {
 52325            if (dataLakeAccessPolicy == null)
 326            {
 0327                return null;
 328            }
 329
 52330            return new BlobAccessPolicy()
 52331            {
 52332                PolicyStartsOn = dataLakeAccessPolicy.PolicyStartsOn,
 52333                PolicyExpiresOn = dataLakeAccessPolicy.PolicyExpiresOn,
 52334                Permissions = dataLakeAccessPolicy.Permissions
 52335            };
 336        }
 337
 338        internal static BlobQueryOptions ToBlobQueryOptions(this DataLakeQueryOptions options)
 339        {
 64340            if (options == null)
 341            {
 12342                return null;
 343            }
 344
 52345            BlobQueryOptions blobQueryOptions = new BlobQueryOptions
 52346            {
 52347                InputTextConfiguration = options.InputTextConfiguration.ToBlobQueryTextConfiguration(),
 52348                OutputTextConfiguration = options.OutputTextConfiguration.ToBlobQueryTextConfiguration(),
 52349                Conditions = options.Conditions.ToBlobRequestConditions(),
 52350                ProgressHandler = options.ProgressHandler
 52351            };
 352
 52353            if (options._errorHandler != null)
 354            {
 12355                blobQueryOptions.ErrorHandler += (BlobQueryError error) => { options._errorHandler(error.ToDataLakeQuery
 356            }
 357
 52358            return blobQueryOptions;
 359        }
 360
 361        internal static IBlobQueryTextOptions ToBlobQueryTextConfiguration(this IDataLakeQueryTextOptions textConfigurat
 362        {
 104363            if (textConfiguration == null)
 364            {
 104365                return null;
 366            }
 367
 0368            if (textConfiguration.GetType() == typeof(DataLakeQueryJsonTextOptions))
 369            {
 0370                return ((DataLakeQueryJsonTextOptions)textConfiguration).ToBlobQueryJsonTextConfiguration();
 371            }
 372
 0373            if (textConfiguration.GetType() == typeof(DataLakeQueryCsvTextOptions))
 374            {
 0375                return ((DataLakeQueryCsvTextOptions)textConfiguration).ToBlobQueryCsvTextConfiguration();
 376            }
 377
 0378            throw new ArgumentException("Invalid text configuration type");
 379        }
 380
 381        internal static BlobQueryJsonTextOptions ToBlobQueryJsonTextConfiguration(this DataLakeQueryJsonTextOptions text
 0382            => new BlobQueryJsonTextOptions
 0383            {
 0384                RecordSeparator = textConfiguration.RecordSeparator
 0385            };
 386
 387        internal static BlobQueryCsvTextOptions ToBlobQueryCsvTextConfiguration(this DataLakeQueryCsvTextOptions textCon
 0388            => new BlobQueryCsvTextOptions
 0389            {
 0390                ColumnSeparator = textConfiguration.ColumnSeparator,
 0391                QuotationCharacter = textConfiguration.QuotationCharacter,
 0392                EscapeCharacter = textConfiguration.EscapeCharacter,
 0393                HasHeaders = textConfiguration.HasHeaders
 0394            };
 395
 396        internal static DataLakeQueryError ToDataLakeQueryError(this BlobQueryError error)
 397        {
 4398            if (error == null)
 399            {
 0400                return null;
 401            }
 402
 4403            return new DataLakeQueryError
 4404            {
 4405                Name = error.Name,
 4406                Description = error.Description,
 4407                IsFatal = error.IsFatal,
 4408                Position = error.Position
 4409            };
 410        }
 411    }
 412}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeAccountSasPermissions.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="DataLakeAccountSasPermissions"/> contains the list of
 12    /// permissions that can be set for a data lake account's access policy.  Use
 13    /// <see cref="DataLakeSasBuilder.SetPermissions(DataLakeAccountSasPermissions)"/>
 14    /// to set the permissions on the <see cref="DataLakeSasBuilder"/>.
 15    /// </summary>
 16    [Flags]
 17    public enum DataLakeAccountSasPermissions
 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.Files.DataLake
 57{
 58    /// <summary>
 59    /// Data Lake enum extensions
 60    /// </summary>
 61    internal static partial class DataLakeExtensions
 62    {
 63
 64        /// <summary>
 65        /// Create a permissions string to provide
 66        /// <see cref="DataLakeSasBuilder.Permissions"/>.
 67        /// </summary>
 68        /// <returns>A permissions string.</returns>
 69        internal static string ToPermissionsString(this DataLakeAccountSasPermissions permissions)
 70        {
 071            var sb = new StringBuilder();
 072            if ((permissions & DataLakeAccountSasPermissions.Read) == DataLakeAccountSasPermissions.Read)
 73            {
 074                sb.Append(Constants.Sas.Permissions.Read);
 75            }
 076            if ((permissions & DataLakeAccountSasPermissions.Add) == DataLakeAccountSasPermissions.Add)
 77            {
 078                sb.Append(Constants.Sas.Permissions.Add);
 79            }
 080            if ((permissions & DataLakeAccountSasPermissions.Create) == DataLakeAccountSasPermissions.Create)
 81            {
 082                sb.Append(Constants.Sas.Permissions.Create);
 83            }
 084            if ((permissions & DataLakeAccountSasPermissions.Write) == DataLakeAccountSasPermissions.Write)
 85            {
 086                sb.Append(Constants.Sas.Permissions.Write);
 87            }
 088            if ((permissions & DataLakeAccountSasPermissions.Delete) == DataLakeAccountSasPermissions.Delete)
 89            {
 090                sb.Append(Constants.Sas.Permissions.Delete);
 91            }
 092            if ((permissions & DataLakeAccountSasPermissions.List) == DataLakeAccountSasPermissions.List)
 93            {
 094                sb.Append(Constants.Sas.Permissions.List);
 95            }
 096            return sb.ToString();
 97        }
 98    }
 99}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeFileSystemSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.ComponentModel;
 6using System.Text;
 7using Azure.Storage;
 8using Azure.Storage.Sas;
 9
 10namespace Azure.Storage.Sas
 11{
 12    /// <summary>
 13    /// <see cref="DataLakeFileSystemSasPermissions"/> contains the list of
 14    /// permissions that can be set for a file systems's access policy.  Use
 15    /// <see cref="DataLakeSasBuilder.SetPermissions(DataLakeSasPermissions)"/>
 16    /// to set the permissions on the <see cref="DataLakeSasBuilder"/>.
 17    /// </summary>
 18    [Flags]
 19    public enum DataLakeFileSystemSasPermissions
 20    {
 21        /// <summary>
 22        /// Indicates that Read is permitted.
 23        /// </summary>
 24        Read = 1,
 25
 26        /// <summary>
 27        /// Indicates that Add is permitted.
 28        /// </summary>
 29        Add = 2,
 30
 31        /// <summary>
 32        /// Indicates that Create is permitted.
 33        /// </summary>
 34        Create = 4,
 35
 36        /// <summary>
 37        /// Indicates that Write is permitted.
 38        /// </summary>
 39        Write = 8,
 40
 41        /// <summary>
 42        /// Indicates that Delete is permitted.
 43        /// </summary>
 44        Delete = 16,
 45
 46        /// <summary>
 47        /// Indicates that List is permitted.
 48        /// </summary>
 49        List = 32,
 50
 51        /// <summary>
 52        /// Indicates that all permissions are set.
 53        /// </summary>
 54        All = ~0
 55    }
 56}
 57
 58namespace Azure.Storage.Files.DataLake
 59{
 60    /// <summary>
 61    /// Data Lake enum extensions.
 62    /// </summary>
 63    internal static partial class DataLakeExtensions
 64    {
 65        /// <summary>
 66        /// Create a permissions string to provide
 67        /// <see cref="DataLakeSasBuilder.Permissions"/>.
 68        /// </summary>
 69        /// <returns>A permissions string.</returns>
 70        internal static string ToPermissionsString(this DataLakeFileSystemSasPermissions permissions)
 71        {
 3672            var sb = new StringBuilder();
 3673            if ((permissions & DataLakeFileSystemSasPermissions.Read) == DataLakeFileSystemSasPermissions.Read)
 74            {
 3675                sb.Append(Constants.Sas.Permissions.Read);
 76            }
 3677            if ((permissions & DataLakeFileSystemSasPermissions.Add) == DataLakeFileSystemSasPermissions.Add)
 78            {
 3679                sb.Append(Constants.Sas.Permissions.Add);
 80            }
 3681            if ((permissions & DataLakeFileSystemSasPermissions.Create) == DataLakeFileSystemSasPermissions.Create)
 82            {
 3683                sb.Append(Constants.Sas.Permissions.Create);
 84            }
 3685            if ((permissions & DataLakeFileSystemSasPermissions.Write) == DataLakeFileSystemSasPermissions.Write)
 86            {
 3687                sb.Append(Constants.Sas.Permissions.Write);
 88            }
 3689            if ((permissions & DataLakeFileSystemSasPermissions.Delete) == DataLakeFileSystemSasPermissions.Delete)
 90            {
 3691                sb.Append(Constants.Sas.Permissions.Delete);
 92            }
 3693            if ((permissions & DataLakeFileSystemSasPermissions.List) == DataLakeFileSystemSasPermissions.List)
 94            {
 3695                sb.Append(Constants.Sas.Permissions.List);
 96            }
 3697            return sb.ToString();
 98        }
 99    }
 100}

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Sas\DataLakeSasPermissions.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.ComponentModel;
 6using System.Text;
 7using Azure.Storage.Sas;
 8
 9namespace Azure.Storage.Sas
 10{
 11    /// <summary>
 12    /// <see cref="DataLakeSasPermissions"/> contains the list of
 13    /// permissions that can be set for a path's access policy.  Use
 14    /// <see cref="DataLakeSasBuilder.SetPermissions(DataLakeSasPermissions)"/>
 15    /// to set the permissions on the <see cref="DataLakeSasBuilder"/>.
 16    /// </summary>
 17    [Flags]
 18    public enum DataLakeSasPermissions
 19    {
 20        /// <summary>
 21        /// Indicates that Read is permitted.
 22        /// </summary>
 23        Read = 1,
 24
 25        /// <summary>
 26        /// Indicates that Add is permitted.
 27        /// </summary>
 28        Add = 2,
 29
 30        /// <summary>
 31        /// Indicates that Create is permitted.
 32        /// </summary>
 33        Create = 4,
 34
 35        /// <summary>
 36        /// Indicates that Write is permitted.
 37        /// </summary>
 38        Write = 8,
 39
 40        /// <summary>
 41        /// Indicates that Delete is permitted.
 42        /// </summary>
 43        Delete = 16,
 44
 45        /// <summary>
 46        /// Indicates that all permissions are set.
 47        /// </summary>
 48        All = ~0
 49    }
 50}
 51
 52namespace Azure.Storage.Files.DataLake
 53{
 54    /// <summary>
 55    /// Data Lake enum extensions
 56    /// </summary>
 57    internal static partial class DataLakeExtensions
 58    {
 59
 60        /// <summary>
 61        /// Create a permissions string to provide
 62        /// <see cref="DataLakeSasBuilder.Permissions"/>.
 63        /// </summary>
 64        /// <returns>A permissions string.</returns>
 65        internal static string ToPermissionsString(this DataLakeSasPermissions permissions)
 66        {
 4467            var sb = new StringBuilder();
 4468            if ((permissions & DataLakeSasPermissions.Read) == DataLakeSasPermissions.Read)
 69            {
 4470                sb.Append(Constants.Sas.Permissions.Read);
 71            }
 4472            if ((permissions & DataLakeSasPermissions.Add) == DataLakeSasPermissions.Add)
 73            {
 4474                sb.Append(Constants.Sas.Permissions.Add);
 75            }
 4476            if ((permissions & DataLakeSasPermissions.Create) == DataLakeSasPermissions.Create)
 77            {
 4478                sb.Append(Constants.Sas.Permissions.Create);
 79            }
 4480            if ((permissions & DataLakeSasPermissions.Write) == DataLakeSasPermissions.Write)
 81            {
 4482                sb.Append(Constants.Sas.Permissions.Write);
 83            }
 4484            if ((permissions & DataLakeSasPermissions.Delete) == DataLakeSasPermissions.Delete)
 85            {
 4486                sb.Append(Constants.Sas.Permissions.Delete);
 87            }
 4488            return sb.ToString();
 89        }
 90    }
 91}