< Summary

Class:Azure.Storage.Files.DataLake.Models.PathAccessControlItem
Assembly:Azure.Storage.Files.DataLake
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Files.DataLake\src\Models\PathAccessControlItem.cs
Covered lines:52
Uncovered lines:1
Coverable lines:53
Total lines:151
Line coverage:98.1% (52 of 53)
Covered branches:29
Total branches:30
Branch coverage:96.6% (29 of 30)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_DefaultScope()-100%100%
get_AccessControlType()-100%100%
get_EntityId()-100%100%
get_Permissions()-100%100%
.ctor()-100%100%
.ctor(...)-100%100%
ToString()-100%100%
Parse(...)-100%100%
ParseAccesControlType(...)-88.89%87.5%

File(s)

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

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System;
 5using System.Text;
 6
 7namespace Azure.Storage.Files.DataLake.Models
 8{
 9    /// <summary>
 10    /// Represents an access control in a file access control list.
 11    /// </summary>
 12    public class PathAccessControlItem
 13    {
 14        /// <summary>
 15        /// Indicates whether this is the default entry for the ACL.
 16        /// </summary>
 45017        public bool DefaultScope { get; set; }
 18
 19        /// <summary>
 20        /// Specifies which role this entry targets.
 21        /// </summary>
 119622        public AccessControlType AccessControlType { get; set; }
 23
 24        /// <summary>
 25        /// Specifies the entity for which this entry applies.
 26        /// Must be omitted for types mask or other.  It must also be omitted when the user or group is the owner.
 27        /// </summary>
 44628        public string EntityId { get; set; }
 29
 30        /// <summary>
 31        /// Specifies the permissions granted to this entry.
 32        /// </summary>
 119633        public RolePermissions Permissions { get; set; }
 34
 35        /// <summary>
 36        /// Empty constructor.
 37        /// </summary>
 152438        public PathAccessControlItem() { }
 39
 40        /// <summary>
 41        /// Constructor.
 42        /// </summary>
 43        /// <param name="accessControlType">Specifies which role this entry targets.</param>
 44        /// <param name="permissions">Specifies the permissions granted to this entry.</param>
 45        /// <param name="defaultScope">Indicates whether this is the default entry for the ACL.</param>
 46        /// <param name="entityId">Optional entity ID to which this entry applies.</param>
 2247        public PathAccessControlItem(
 2248            AccessControlType accessControlType,
 2249            RolePermissions permissions,
 2250            bool defaultScope = false,
 2251            string entityId = default)
 52        {
 2253            if (entityId != null
 2254                && !(accessControlType == AccessControlType.User || accessControlType == AccessControlType.Group))
 55            {
 256                throw DataLakeErrors.EntityIdAndInvalidAccessControlType(accessControlType.ToString());
 57            }
 58
 2059            DefaultScope = defaultScope;
 2060            AccessControlType = accessControlType;
 2061            EntityId = entityId;
 2062            Permissions = permissions;
 2063        }
 64
 65        /// <summary>
 66        /// Override of ToString().
 67        /// </summary>
 68        /// <returns></returns>
 69        public override string ToString()
 70        {
 39671            StringBuilder stringBuilder = new StringBuilder();
 72
 39673            if (DefaultScope)
 74            {
 875                stringBuilder.Append("default:");
 76            }
 39677            stringBuilder.Append(AccessControlType.ToString().ToLowerInvariant());
 39678            stringBuilder.Append(":");
 39679            stringBuilder.Append(EntityId ?? "");
 39680            stringBuilder.Append(":");
 39681            stringBuilder.Append(Permissions.ToSymbolicRolePermissions());
 82
 39683            return stringBuilder.ToString();
 84        }
 85
 86        /// <summary>
 87        /// Parses the provided string into a <see cref="PathAccessControlItem"/>
 88        /// </summary>
 89        /// <param name="s">The string representation of the access control list.</param>
 90        /// <returns>A <see cref="PathAccessControlItem"/>.</returns>
 91        public static PathAccessControlItem Parse(string s)
 92        {
 76493            if (s == null)
 94            {
 295                return null;
 96            }
 97
 76298            PathAccessControlItem entry = new PathAccessControlItem();
 76299            string[] parts = s.Split(':');
 762100            int indexOffset = 0;
 101
 762102            if (parts.Length < 3 || parts.Length > 4)
 103            {
 4104                throw DataLakeErrors.PathAccessControlItemStringInvalidLength(s);
 105            }
 106
 758107            if (parts.Length == 4)
 108            {
 12109                if (!parts[0].Equals("default", StringComparison.OrdinalIgnoreCase))
 110                {
 2111                    throw DataLakeErrors.PathAccessControlItemStringInvalidPrefix(s);
 112                }
 10113                entry.DefaultScope = true;
 10114                indexOffset = 1;
 115            }
 756116            entry.AccessControlType = ParseAccesControlType(parts[indexOffset]);
 117
 756118            if (!string.IsNullOrEmpty(parts[1 + indexOffset]))
 119            {
 6120                entry.EntityId = parts[1 + indexOffset];
 121            }
 122
 756123            entry.Permissions = PathAccessControlExtensions.ParseSymbolicRolePermissions(parts[2 + indexOffset], false);
 756124            return entry;
 125        }
 126
 127        internal static AccessControlType ParseAccesControlType(string s)
 128        {
 756129            if ("user".Equals(s, StringComparison.OrdinalIgnoreCase))
 130            {
 226131                return AccessControlType.User;
 132            }
 530133            else if ("group".Equals(s, StringComparison.OrdinalIgnoreCase))
 134            {
 220135                return AccessControlType.Group;
 136            }
 310137            else if ("mask".Equals(s, StringComparison.OrdinalIgnoreCase))
 138            {
 90139                return AccessControlType.Mask;
 140            }
 220141            else if ("other".Equals(s, StringComparison.OrdinalIgnoreCase))
 142            {
 220143                return AccessControlType.Other;
 144            }
 145            else
 146            {
 0147                throw Errors.InvalidArgument(nameof(s));
 148            }
 149        }
 150    }
 151}