public override void ExecuteCmdlet()
        {
            if (String.IsNullOrEmpty(ShareName))
            {
                return;
            }
            CloudFileShare         fileShare    = Channel.GetShareReference(this.ShareName);
            SharedAccessFilePolicy accessPolicy = new SharedAccessFilePolicy();

            bool shouldSetExpiryTime = SasTokenHelper.ValidateShareAccessPolicy(
                Channel,
                this.ShareName,
                accessPolicyIdentifier,
                !string.IsNullOrEmpty(this.Permission),
                this.StartTime.HasValue,
                this.ExpiryTime.HasValue);

            SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);
            string sasToken = fileShare.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier, Protocol, Util.SetupIPAddressOrRangeForSAS(IPAddressOrRange));

            if (FullUri)
            {
                string fullUri = SasTokenHelper.GetFullUriWithSASToken(fileShare.SnapshotQualifiedUri.AbsoluteUri.ToString(), sasToken);

                WriteObject(fullUri);
            }
            else
            {
                WriteObject(sasToken);
            }
        }
Example #2
0
        public override void ExecuteCmdlet()
        {
            if (String.IsNullOrEmpty(ShareName))
            {
                return;
            }

            CloudFileShare fileShare = null;
            CloudFile      file      = null;

            if (null != this.File)
            {
                file      = this.File;
                fileShare = this.File.Share;
            }
            else
            {
                string[] path = NamingUtil.ValidatePath(this.Path, true);
                fileShare = Channel.GetShareReference(this.ShareName);
                file      = fileShare.GetRootDirectoryReference().GetFileReferenceByPath(path);
            }

            SharedAccessFilePolicy accessPolicy = new SharedAccessFilePolicy();

            bool shouldSetExpiryTime = SasTokenHelper.ValidateShareAccessPolicy(
                Channel,
                fileShare.Name,
                accessPolicyIdentifier,
                !string.IsNullOrEmpty(this.Permission),
                this.StartTime.HasValue,
                this.ExpiryTime.HasValue);

            SetupAccessPolicy(accessPolicy, shouldSetExpiryTime);

            string sasToken = file.GetSharedAccessSignature(accessPolicy, accessPolicyIdentifier);

            if (FullUri)
            {
                string fullUri = SasTokenHelper.GetFullUriWithSASToken(file.Uri.AbsoluteUri.ToString(), sasToken);

                WriteObject(fullUri);
            }
            else
            {
                WriteObject(sasToken);
            }
        }