/// <summary> /// Converts the permissions specified for the shared access policy to a string. /// </summary> /// <param name="permissions">The shared access permissions.</param> /// <returns>The shared access permissions in string format.</returns> public static string PermissionsToString(SharedAccessPermissions permissions) { // The service supports a fixed order => rwdl StringBuilder builder = new StringBuilder(); if ((permissions & SharedAccessPermissions.Read) == SharedAccessPermissions.Read) { builder.Append("r"); } if ((permissions & SharedAccessPermissions.Write) == SharedAccessPermissions.Write) { builder.Append("w"); } if ((permissions & SharedAccessPermissions.Delete) == SharedAccessPermissions.Delete) { builder.Append("d"); } if ((permissions & SharedAccessPermissions.List) == SharedAccessPermissions.List) { builder.Append("l"); } return(builder.ToString()); }
/// <summary> /// Converts the permissions specified for the shared access policy to a string. /// </summary> /// <param name="permissions">The shared access permissions.</param> /// <returns>The shared access permissions in string format.</returns> public static string PermissionsToString(SharedAccessPermissions permissions) { // The service supports a fixed order => rwdl StringBuilder builder = new StringBuilder(); if ((permissions & SharedAccessPermissions.Read) == SharedAccessPermissions.Read) { builder.Append("r"); } if ((permissions & SharedAccessPermissions.Write) == SharedAccessPermissions.Write) { builder.Append("w"); } if ((permissions & SharedAccessPermissions.Delete) == SharedAccessPermissions.Delete) { builder.Append("d"); } if ((permissions & SharedAccessPermissions.List) == SharedAccessPermissions.List) { builder.Append("l"); } return builder.ToString(); }
public override string GenerateSAS(SharedAccessPermissions sap, int validatePeriod, string policySignedIdentifier = null) { if (null == policySignedIdentifier) { if (this.SourceOrDest == SourceOrDest.Dest) { this.fileHelper.CreateShare(this.shareName); } return(this.fileHelper.GetSASofShare(this.shareName, sap.ToFilePermissions(), validatePeriod, false)); } else { this.fileHelper.CreateShare(this.shareName); return(this.fileHelper.GetSASofShare(this.shareName, sap.ToFilePermissions(), validatePeriod, true, policySignedIdentifier)); } }
/// <summary> /// Constructs a <see cref="SharedAccessPermissions"/> object from a permissions string. /// </summary> /// <param name="value">The shared access permissions in string format.</param> /// <returns>A set of shared access permissions.</returns> public static SharedAccessPermissions PermissionsFromString(string value) { char[] chars = value.ToCharArray(); SharedAccessPermissions permissions = 0; foreach (char c in chars) { switch (c) { case 'r': permissions |= SharedAccessPermissions.Read; break; case 'w': permissions |= SharedAccessPermissions.Write; break; case 'd': permissions |= SharedAccessPermissions.Delete; break; case 'l': permissions |= SharedAccessPermissions.List; break; default: CommonUtils.ArgumentOutOfRange("value", value); break; } } // Incase we ever change none to be something other than 0 if (permissions == 0) { permissions |= SharedAccessPermissions.None; } return(permissions); }
internal static SharedAccessBlobPermissions FromGenericToAzure(SharedAccessPermissions permissions) { var result = SharedAccessBlobPermissions.None; if (permissions.HasFlag(SharedAccessPermissions.Add)) { result |= SharedAccessBlobPermissions.Add; } if (permissions.HasFlag(SharedAccessPermissions.Create)) { result |= SharedAccessBlobPermissions.Create; } if (permissions.HasFlag(SharedAccessPermissions.Delete)) { result |= SharedAccessBlobPermissions.Delete; } if (permissions.HasFlag(SharedAccessPermissions.List)) { result |= SharedAccessBlobPermissions.List; } if (permissions.HasFlag(SharedAccessPermissions.Read)) { result |= SharedAccessBlobPermissions.Read; } if (permissions.HasFlag(SharedAccessPermissions.Write)) { result |= SharedAccessBlobPermissions.Write; } return(result); }
/// <summary> /// Creates a shared access signature for a specific blob /// </summary> public String CreateSharedSignature(String resource, SharedAccessPermissions permissions) { var blob = container.GetBlobReference(resource); return blob.GetSharedAccessSignature(new SharedAccessPolicy() { SharedAccessStartTime = DateTime.Now, SharedAccessExpiryTime = DateTime.Now.AddMinutes(30), Permissions = permissions }); }
/// <summary> /// Creates a shared access signature for the files container /// </summary> public String CreateSharedSignature(SharedAccessPermissions permissions) { return container.GetSharedAccessSignature(new SharedAccessPolicy() { SharedAccessStartTime = DateTime.Now, SharedAccessExpiryTime = DateTime.Now.AddMinutes(30), Permissions = permissions }); }
public abstract string GenerateSAS(SharedAccessPermissions sap, int validatePeriod, string policySignedIdentifier = null);
public override string GenerateSAS(SharedAccessPermissions sap, int validatePeriod, string policySignedIdentifier = null) { throw new NotSupportedException("GenerateSAS is not supported in LocalDataAdaptorBase."); }
public static SharedAccessFilePermissions ToFilePermissions(this SharedAccessPermissions sap) { return((SharedAccessFilePermissions)Enum.Parse(typeof(SharedAccessFilePermissions), sap.ToString())); }
public string GenerateSharedAccessSignature(string containerName, string blobName, bool read, bool write, bool delete, bool list, DateTime startTime, DateTime endTime) { CloudBlobClient client = CloudStorageAccount.CreateCloudBlobClient(); client.RetryPolicy = RetryPolicies.Retry(20, TimeSpan.Zero); CloudBlobContainer container = client.GetContainerReference(containerName); string path; if (string.IsNullOrEmpty(blobName)) { path = container.Attributes.Uri.AbsoluteUri; } else { CloudBlob blob = container.GetBlobReference(blobName); path = blob.Attributes.Uri.AbsoluteUri; } SharedAccessPermissions permissions = new SharedAccessPermissions(); if (read) permissions |= SharedAccessPermissions.Read; if (write) permissions |= SharedAccessPermissions.Write; if (delete) permissions |= SharedAccessPermissions.Delete; if (list) permissions |= SharedAccessPermissions.List; SharedAccessPolicy policy = new SharedAccessPolicy() { Permissions = permissions, SharedAccessStartTime = startTime, SharedAccessExpiryTime = endTime }; string queryString = container.GetSharedAccessSignature(policy); return path + queryString; }