Beispiel #1
0
        public override void ExecuteCmdlet()
        {
            if (!UseTrack2Sdk()) // Track1
            {
                var sharedAccessPolicy = new SharedAccessAccountPolicy()
                {
                    Permissions      = SetupAccessPolicyPermission(this.Permission),
                    Services         = Service,
                    ResourceTypes    = ResourceType,
                    Protocols        = Protocol,
                    IPAddressOrRange = Util.SetupIPAddressOrRangeForSAS(this.IPAddressOrRange)
                };

                DateTimeOffset?accessStartTime;
                DateTimeOffset?accessEndTime;
                SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime,
                                                         out accessStartTime, out accessEndTime, true);
                sharedAccessPolicy.SharedAccessStartTime  = accessStartTime;
                sharedAccessPolicy.SharedAccessExpiryTime = accessEndTime;

                this.WriteObject(Channel.GetStorageAccountSASToken(sharedAccessPolicy));
            }
            else
            {
                AccountSasBuilder sasBuilder = SasTokenHelper.SetAccountSasBuilder(this.Service, this.ResourceType, Permission, this.StartTime, this.ExpiryTime, this.IPAddressOrRange, this.Protocol);
                string            sasToken   = sasBuilder.ToSasQueryParameters(new StorageSharedKeyCredential(Channel.StorageContext.StorageAccountName, Channel.StorageContext.StorageAccount.Credentials.ExportBase64EncodedKey())).ToString();
                if (sasToken[0] != '?')
                {
                    sasToken = "?" + sasToken;
                }
                this.WriteObject(sasToken);
            }
        }
        /// <summary>
        /// Update the access policy
        /// </summary>
        /// <param name="policy">Access policy object</param>
        /// <param name="shouldSetExpiryTime">Should set the default expiry time</param>
        private void SetupAccessPolicy(SharedAccessQueuePolicy policy, bool shouldSetExpiryTime)
        {
            DateTimeOffset?accessStartTime;
            DateTimeOffset?accessEndTime;

            SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime, out accessStartTime, out accessEndTime, shouldSetExpiryTime);
            policy.SharedAccessStartTime  = accessStartTime;
            policy.SharedAccessExpiryTime = accessEndTime;
            SetupAccessPolicyPermission(policy, Permission);
        }
 /// <summary>
 /// Update the access policy
 /// </summary>
 /// <param name="policy">Access policy object</param>
 /// <param name="shouldSetExpiryTime">Should set the default expiry time</param>
 private void SetupAccessPolicy(SharedAccessBlobPolicy accessPolicy, bool shouldSetExpiryTime)
 {
     AccessPolicyHelper.SetupAccessPolicyPermission(accessPolicy, Permission);
     DateTimeOffset? accessStartTime;
     DateTimeOffset? accessEndTime;
     SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime,
         out accessStartTime, out accessEndTime, shouldSetExpiryTime);
     accessPolicy.SharedAccessStartTime = accessStartTime;
     accessPolicy.SharedAccessExpiryTime = accessEndTime;
 }
        public void SetupAccessPolicyLifeTimeTest()
        {
            DateTime?      start     = DateTime.Now;
            DateTime?      end       = start.Value.AddHours(1.0);
            DateTimeOffset?testStart = null;
            DateTimeOffset?testEnd   = null;

            SasTokenHelper.SetupAccessPolicyLifeTime(start, end, out testStart, out testEnd, true);
            Assert.AreEqual(testStart.Value.UtcDateTime.ToString(), start.Value.ToUniversalTime().ToString());
            Assert.AreEqual(testEnd.Value.UtcDateTime.ToString(), end.Value.ToUniversalTime().ToString());
            AssertThrows <ArgumentException>(() => SasTokenHelper.SetupAccessPolicyLifeTime(end, start, out testStart, out testEnd, true));
        }
        public override void ExecuteCmdlet()
        {
            var sharedAccessPolicy = new SharedAccessAccountPolicy()
            {
                Permissions      = SetupAccessPolicyPermission(this.Permission),
                Services         = Service,
                ResourceTypes    = ResourceType,
                Protocols        = Protocol,
                IPAddressOrRange = Util.SetupIPAddressOrRangeForSAS(this.IPAddressOrRange)
            };

            DateTimeOffset?accessStartTime;
            DateTimeOffset?accessEndTime;

            SasTokenHelper.SetupAccessPolicyLifeTime(StartTime, ExpiryTime,
                                                     out accessStartTime, out accessEndTime, true);
            sharedAccessPolicy.SharedAccessStartTime  = accessStartTime;
            sharedAccessPolicy.SharedAccessExpiryTime = accessEndTime;

            this.WriteObject(Channel.GetStorageAccountSASToken(sharedAccessPolicy));
        }