-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
DataLakeFileSystemSasPermissions.cs
136 lines (123 loc) · 4.5 KB
/
DataLakeFileSystemSasPermissions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.ComponentModel;
using System.Text;
using Azure.Storage;
using Azure.Storage.Sas;
namespace Azure.Storage.Sas
{
/// <summary>
/// <see cref="DataLakeFileSystemSasPermissions"/> contains the list of
/// permissions that can be set for a file systems's access policy. Use
/// <see cref="DataLakeSasBuilder.SetPermissions(DataLakeSasPermissions)"/>
/// to set the permissions on the <see cref="DataLakeSasBuilder"/>.
/// </summary>
[Flags]
public enum DataLakeFileSystemSasPermissions
{
/// <summary>
/// Indicates that Read is permitted.
/// </summary>
Read = 1,
/// <summary>
/// Indicates that Add is permitted.
/// </summary>
Add = 2,
/// <summary>
/// Indicates that Create is permitted.
/// </summary>
Create = 4,
/// <summary>
/// Indicates that Write is permitted.
/// </summary>
Write = 8,
/// <summary>
/// Indicates that Delete is permitted.
/// </summary>
Delete = 16,
/// <summary>
/// Indicates that List is permitted.
/// </summary>
List = 32,
/// <summary>
/// Indicates that Move is permitted.
/// </summary>
Move = 64,
/// <summary>
/// Indicates that Execute is permitted.
/// </summary>
Execute = 128,
/// <summary>
/// Indicates that Ownership is permitted.
/// </summary>
ManageOwnership = 256,
/// <summary>
/// Indicates that Permissions is permitted.
/// </summary>
ManageAccessControl = 512,
/// <summary>
/// Indicates that all permissions are set.
/// </summary>
All = ~0
}
}
namespace Azure.Storage.Files.DataLake
{
/// <summary>
/// Data Lake enum extensions.
/// </summary>
internal static partial class DataLakeExtensions
{
/// <summary>
/// Create a permissions string to provide
/// <see cref="DataLakeSasBuilder.Permissions"/>.
/// </summary>
/// <returns>A permissions string.</returns>
internal static string ToPermissionsString(this DataLakeFileSystemSasPermissions permissions)
{
var sb = new StringBuilder();
if ((permissions & DataLakeFileSystemSasPermissions.Read) == DataLakeFileSystemSasPermissions.Read)
{
sb.Append(Constants.Sas.Permissions.Read);
}
if ((permissions & DataLakeFileSystemSasPermissions.Add) == DataLakeFileSystemSasPermissions.Add)
{
sb.Append(Constants.Sas.Permissions.Add);
}
if ((permissions & DataLakeFileSystemSasPermissions.Create) == DataLakeFileSystemSasPermissions.Create)
{
sb.Append(Constants.Sas.Permissions.Create);
}
if ((permissions & DataLakeFileSystemSasPermissions.Write) == DataLakeFileSystemSasPermissions.Write)
{
sb.Append(Constants.Sas.Permissions.Write);
}
if ((permissions & DataLakeFileSystemSasPermissions.Delete) == DataLakeFileSystemSasPermissions.Delete)
{
sb.Append(Constants.Sas.Permissions.Delete);
}
if ((permissions & DataLakeFileSystemSasPermissions.List) == DataLakeFileSystemSasPermissions.List)
{
sb.Append(Constants.Sas.Permissions.List);
}
if ((permissions & DataLakeFileSystemSasPermissions.Move) == DataLakeFileSystemSasPermissions.Move)
{
sb.Append(Constants.Sas.Permissions.Move);
}
if ((permissions & DataLakeFileSystemSasPermissions.Execute) == DataLakeFileSystemSasPermissions.Execute)
{
sb.Append(Constants.Sas.Permissions.Execute);
}
if ((permissions & DataLakeFileSystemSasPermissions.ManageOwnership) == DataLakeFileSystemSasPermissions.ManageOwnership)
{
sb.Append(Constants.Sas.Permissions.ManageOwnership);
}
if ((permissions & DataLakeFileSystemSasPermissions.ManageAccessControl) == DataLakeFileSystemSasPermissions.ManageAccessControl)
{
sb.Append(Constants.Sas.Permissions.ManageAccessControl);
}
return sb.ToString();
}
}
}