internal async Task <SharedAccessFilePolicies> GetPoliciesAsync(IStorageFileManagement localChannel, string shareName, string policyName)
        {
            CloudFileShare       share       = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = await localChannel.GetSharePermissionsAsync(share, null, null, null, CmdletCancellationToken);

            return(permissions.SharedAccessPolicies);
        }
Esempio n. 2
0
        private void StartCopyFromFile(IStorageFileManagement srcChannel, IStorageBlobManagement destChannel, string srcShareName, string srcFilePath, string destContainerName, string destBlobName)
        {
            NamingUtil.ValidateShareName(srcShareName, false);
            CloudFileShare share = srcChannel.GetShareReference(srcShareName);

            this.StartCopyFromFile(destChannel, share.GetRootDirectoryReference(), srcFilePath, destContainerName, destBlobName);
        }
        /// <summary>
        /// Validate the file share access policy
        /// </summary>
        /// <param name="policy">SharedAccessFilePolicy object</param>
        /// <param name="policyIdentifier">The policy identifier which need to be checked.</param>
        public static bool ValidateShareAccessPolicy(IStorageFileManagement channel, string shareName,
                                                     string policyIdentifier, bool shouldNoPermission, bool shouldNoStartTime, bool shouldNoExpiryTime)
        {
            if (string.IsNullOrEmpty(policyIdentifier))
            {
                return(true);
            }
            CloudFileShare       fileShare  = channel.GetShareReference(shareName);
            FileSharePermissions permission = fileShare.GetPermissionsAsync().Result;

            SharedAccessFilePolicy sharedAccessPolicy =
                GetExistingPolicy <SharedAccessFilePolicy>(permission.SharedAccessPolicies, policyIdentifier);

            if (shouldNoPermission && sharedAccessPolicy.Permissions != SharedAccessFilePermissions.None)
            {
                throw new InvalidOperationException(Resources.SignedPermissionsMustBeOmitted);
            }

            if (shouldNoStartTime && sharedAccessPolicy.SharedAccessStartTime.HasValue)
            {
                throw new InvalidOperationException(Resources.SignedStartTimeMustBeOmitted);
            }

            if (shouldNoExpiryTime && sharedAccessPolicy.SharedAccessExpiryTime.HasValue)
            {
                throw new InvalidOperationException(Resources.SignedExpiryTimeMustBeOmitted);
            }

            return(!sharedAccessPolicy.SharedAccessExpiryTime.HasValue);
        }
        internal string SetAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get existing permissions
            CloudFileShare share = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = localChannel.GetSharePermissions(share);

            //Set the policy with new value
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessFilePolicy policy = permissions.SharedAccessPolicies[policyName];
            AccessPolicyHelper.SetupAccessPolicy<SharedAccessFilePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            permissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to share
            localChannel.SetSharePermissions(share, permissions);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessFilePolicy>(permissions.SharedAccessPolicies, policyName));
            return policyName;
        }
        internal string SetAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            //Get existing permissions
            CloudFileShare       share       = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = localChannel.GetSharePermissions(share);

            //Set the policy with new value
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessFilePolicy policy = permissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessFilePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            permissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to share
            localChannel.SetSharePermissions(share, permissions, null, null, OperationContext);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessFilePolicy>(permissions.SharedAccessPolicies, policyName));
            return(policyName);
        }
        internal bool RemoveAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName)
        {
            bool success = false;
            string result = string.Empty;

            //Get existing permissions
            CloudFileShare share = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = localChannel.GetSharePermissions(share);

            //remove the specified policy
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            if (ShouldProcess(policyName, "Remove policy"))
            {
                permissions.SharedAccessPolicies.Remove(policyName);
                localChannel.SetSharePermissions(share, permissions);
                success = true;
            }

            return success;
        }
Esempio n. 7
0
        internal bool RemoveAzureShareStoredAccessPolicy(IStorageFileManagement localChannel, string shareName, string policyName)
        {
            bool   success = false;
            string result  = string.Empty;

            //Get existing permissions
            CloudFileShare       share       = localChannel.GetShareReference(shareName);
            FileSharePermissions permissions = localChannel.GetSharePermissions(share);

            //remove the specified policy
            if (!permissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            if (this.Force || ConfirmRemove(policyName))
            {
                permissions.SharedAccessPolicies.Remove(policyName);
                localChannel.SetSharePermissions(share, permissions);
                success = true;
            }

            return(success);
        }
 internal async Task<SharedAccessFilePolicies> GetPoliciesAsync(IStorageFileManagement localChannel, string shareName, string policyName)
 {
     CloudFileShare share = localChannel.GetShareReference(shareName);
     FileSharePermissions permissions = await localChannel.GetSharePermissionsAsync(share, null, null, null, CmdletCancellationToken);
     return permissions.SharedAccessPolicies;
 }
        private void StartCopyFromFile(IStorageFileManagement srcChannel, IStorageBlobManagement destChannel, string srcShareName, string srcFilePath, string destContainerName, string destBlobName)
        {
            NamingUtil.ValidateShareName(srcShareName, false);
            CloudFileShare share = srcChannel.GetShareReference(srcShareName);

            this.StartCopyFromFile(destChannel, share.GetRootDirectoryReference(), srcFilePath, destContainerName, destBlobName);
        }