Beispiel #1
0
#pragma warning restore AZC0002 // Client method should have cancellationToken as the last optional parameter

        /// <summary>
        /// The SetBlobsAccessTierAsync operation sets the tier on blobs.  The
        /// operation is allowed on block blobs in a blob storage or general
        /// purpose v2 account.
        /// </summary>
        /// <param name="blobUris">
        /// URIs of the blobs to set the tiers of.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blobs.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <param name="async">
        /// Whether to invoke the operation asynchronously.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate notifications
        /// that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// The <see cref="Response"/>s for the individual Set Tier operations.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure to submit the batch occurs.  Individual sub-operation
        /// failures will be wrapped in an <see cref="AggregateException"/>.
        /// </remarks>
        internal async Task <Response[]> SetBlobsAccessTierInteral(
            IEnumerable <Uri> blobUris,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority,
            bool async,
            CancellationToken cancellationToken)
        {
            blobUris = blobUris ?? throw new ArgumentNullException(nameof(blobUris));
            var responses = new List <Response>();

            // Create the batch
            BlobBatch batch = CreateBatch();

            foreach (Uri uri in blobUris)
            {
                responses.Add(batch.SetBlobAccessTier(uri, accessTier, rehydratePriority));
            }

            // Submit the batch
            await SubmitBatchInternal(
                batch,
                true,
                async,
                cancellationToken)
            .ConfigureAwait(false);

            return(responses.ToArray());
        }
Beispiel #2
0
 public SsoResponse(bool success, bool loggedIn, bool blocked, AccessTier accessTier, int status, string message) : base(success)
 {
     LoggedIn      = loggedIn;
     AccessBlocked = blocked;
     Tier          = accessTier;
     Status        = status;
     Message       = message;
 }
Beispiel #3
0
            public async Task AssertTiers(AccessTier tier, BlockBlobClient blob)
            {
                try
                {
                    BlobProperties properties = await blob.GetPropertiesAsync();

                    Assert.AreEqual(tier.ToString(), properties.AccessTier.ToString());
                }
                catch (RequestFailedException)
                {
                }
            }
Beispiel #4
0
        internal static string ToSerializedValue(this AccessTier value)
        {
            switch (value)
            {
            case AccessTier.Hot:
                return("Hot");

            case AccessTier.Cool:
                return("Cool");
            }
            return(null);
        }
Beispiel #5
0
 public virtual Response[] SetBlobsAccessTier(
     IEnumerable <Uri> blobUris,
     AccessTier accessTier,
     RehydratePriority?rehydratePriority = default,
     CancellationToken cancellationToken = default) =>
 SetBlobsAccessTierInteral(
     blobUris,
     accessTier,
     rehydratePriority,
     false,     // async
     cancellationToken)
 .EnsureCompleted();
Beispiel #6
0
 public virtual async Task <Response[]> SetBlobsAccessTierAsync(
     IEnumerable <Uri> blobUris,
     AccessTier accessTier,
     RehydratePriority?rehydratePriority = default,
     CancellationToken cancellationToken = default) =>
 await SetBlobsAccessTierInteral(
     blobUris,
     accessTier,
     rehydratePriority,
     true,     // async
     cancellationToken)
 .ConfigureAwait(false);
        /// <summary>
        /// The <see cref="SetBlobAccessTier(Uri, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
        /// operation sets the tier on a blob.  The operation is allowed on
        /// block blobs in a blob storage or general purpose v2 account.
        ///
        /// A block blob's tier determines Hot/Cool/Archive storage type.  This
        /// operation does not update the blob's ETag.  For detailed
        /// information about block blob level tiering
        /// <see href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers">
        /// Blob Storage Tiers</see>.
        ///
        /// </summary>
        /// <param name="blobUri">
        /// The blob's primary <see cref="Uri"/> endpoint.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blob.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <param name="leaseAccessConditions">
        /// Optional <see cref="BlobRequestConditions"/> to add conditions on
        /// setting the access tier.
        /// </param>
        /// <returns>
        /// A <see cref="Response"/> on successfully deleting.  The response
        /// cannot be used until the batch has been submitted with
        /// <see cref="BlobBatchClient.SubmitBatchAsync"/>.
        /// </returns>
        public virtual Response SetBlobAccessTier(
            Uri blobUri,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority         = default,
            BlobRequestConditions leaseAccessConditions = default)
        {
            BlobUriBuilder uriBuilder = new BlobUriBuilder(blobUri);

            return(SetBlobAccessTier(
                       blobContainerName: uriBuilder.BlobContainerName,
                       blobName: uriBuilder.BlobName,
                       accessTier: accessTier,
                       rehydratePriority: rehydratePriority,
                       leaseAccessConditions: leaseAccessConditions));
        }
 ///GENMHASH:F3C7D5F595E480B52B33BC7ACD704928:6B5BD9106155829D3669430155DCDD3B
 public StorageAccountImpl WithAccessTier(AccessTier accessTier)
 {
     if (IsInCreateMode)
     {
         createParameters.AccessTier = accessTier;
     }
     else
     {
         if (this.Inner.Kind != Models.Kind.BlobStorage)
         {
             throw new NotSupportedException($"Access tier can changed only for blob storage account type 'BlobStorage', the account type of this account is '{this.Inner.Kind}'");
         }
         updateParameters.AccessTier = accessTier;
     }
     return(this);
 }
Beispiel #9
0
        /// <summary>
        /// The <see cref="SetBlobAccessTier(Uri, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
        /// operation sets the tier on a blob.  The operation is allowed on
        /// block blobs in a blob storage or general purpose v2 account.
        ///
        /// A block blob's tier determines Hot/Cool/Archive storage type.  This
        /// operation does not update the blob's ETag.  For detailed
        /// information about block blob level tiering
        /// <see href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers">
        /// Blob Storage Tiers</see>.
        ///
        /// </summary>
        /// <param name="blobUri">
        /// The blob's primary <see cref="Uri"/> endpoint.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blob.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <param name="leaseAccessConditions">
        /// Optional <see cref="BlobRequestConditions"/> to add conditions on
        /// setting the access tier.
        /// </param>
        /// <returns>
        /// A <see cref="Response"/> on successfully deleting.  The response
        /// cannot be used until the batch has been submitted with
        /// <see cref="BlobBatchClient.SubmitBatchAsync"/>.
        /// </returns>
        public virtual Response SetBlobAccessTier(
            Uri blobUri,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority         = default,
            BlobRequestConditions leaseAccessConditions = default)
        {
            SetBatchOperationType(BlobBatchOperationType.SetAccessTier);
            HttpMessage message = BatchRestClient.Blob.SetAccessTierAsync_CreateMessage(
                pipeline: _client.BatchOperationPipeline,
                resourceUri: blobUri,
                tier: accessTier,
                version: _client.Version.ToVersionString(),
                rehydratePriority: rehydratePriority,
                leaseId: leaseAccessConditions?.LeaseId);

            _messages.Add(message);
            return(new DelayedResponse(message, response => BatchRestClient.Blob.SetAccessTierAsync_CreateResponse(_client.ClientDiagnostics, response)));
        }
Beispiel #10
0
        /// <summary>
        /// The SetBlobsAccessTierAsync operation sets the tier on blobs.  The
        /// operation is allowed on block blobs in a blob storage or general
        /// purpose v2 account.
        /// </summary>
        /// <param name="blobUris">
        /// URIs of the blobs to set the tiers of.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blobs.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <param name="async">
        /// Whether to invoke the operation asynchronously.
        /// </param>
        /// <param name="cancellationToken">
        /// Optional <see cref="CancellationToken"/> to propagate notifications
        /// that the operation should be cancelled.
        /// </param>
        /// <returns>
        /// The <see cref="Response"/>s for the individual Set Tier operations.
        /// </returns>
        /// <remarks>
        /// A <see cref="RequestFailedException"/> will be thrown if
        /// a failure to submit the batch occurs.  Individual sub-operation
        /// failures will be wrapped in an <see cref="AggregateException"/>.
        /// </remarks>
        internal async Task <Response[]> SetBlobsAccessTierInteral(
            IEnumerable <Uri> blobUris,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority,
            bool async,
            CancellationToken cancellationToken)
        {
            DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(BlobBatchClient)}.{nameof(SetBlobsAccessTier)}");

            try
            {
                scope.Start();

                blobUris = blobUris ?? throw new ArgumentNullException(nameof(blobUris));
                var responses = new List <Response>();

                // Create the batch
                BlobBatch batch = CreateBatch();
                foreach (Uri uri in blobUris)
                {
                    responses.Add(batch.SetBlobAccessTier(uri, accessTier, rehydratePriority));
                }

                // Submit the batch
                await SubmitBatchInternal(
                    batch,
                    true,
                    async,
                    cancellationToken)
                .ConfigureAwait(false);

                return(responses.ToArray());
            }
            catch (Exception ex)
            {
                scope.Failed(ex);
                throw;
            }
            finally
            {
                scope.Dispose();
            }
        }
Beispiel #11
0
        /// <summary>
        /// The <see cref="SetBlobAccessTier(string, string, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
        /// operation sets the tier on a blob.  The operation is allowed on
        /// block blobs in a blob storage or general purpose v2 account.
        ///
        /// A block blob's tier determines Hot/Cool/Archive storage type.  This
        /// operation does not update the blob's ETag.  For detailed
        /// information about block blob level tiering see
        /// <see href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers">
        /// Blob Storage Tiers</see>.
        /// </summary>
        /// <param name="blobContainerName">
        /// The name of the container containing the blob to set the tier of.
        /// </param>
        /// <param name="blobName">
        /// The name of the blob to set the tier of.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blob.
        /// </param>
        /// <param name="leaseAccessConditions">
        /// Optional <see cref="BlobRequestConditions"/> to add conditions on
        /// setting the access tier.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <returns>
        /// A <see cref="Response"/> on successfully deleting.  The response
        /// cannot be used until the batch has been submitted with
        /// <see cref="BlobBatchClient.SubmitBatchAsync"/>.
        /// </returns>
        public virtual Response SetBlobAccessTier(
            string blobContainerName,
            string blobName,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority         = default,
            BlobRequestConditions leaseAccessConditions = default)
        {
            var blobUri = new BlobUriBuilder(_client.Uri)
            {
                BlobContainerName = blobContainerName,
                BlobName          = blobName
            };

            return(SetBlobAccessTier(
                       blobUri.ToUri(),
                       accessTier,
                       rehydratePriority,
                       leaseAccessConditions));
        }
Beispiel #12
0
 internal BlobChangeFeedEventData(Dictionary <string, object> record)
 {
     BlobOperationName = new BlobOperationName((string)record[Constants.ChangeFeed.EventData.Api]);
     ClientRequestId   = (string)record[Constants.ChangeFeed.EventData.ClientRequestId];
     RequestId         = Guid.Parse((string)record[Constants.ChangeFeed.EventData.RequestId]);
     ETag          = new ETag((string)record[Constants.ChangeFeed.EventData.Etag]);
     ContentType   = (string)record[Constants.ChangeFeed.EventData.ContentType];
     ContentLength = (long)record[Constants.ChangeFeed.EventData.ContentLength];
     BlobType      = ((string)record[Constants.ChangeFeed.EventData.BlobType]) switch
     {
         Constants.ChangeFeed.EventData.BlockBlob => BlobType.Block,
         Constants.ChangeFeed.EventData.PageBlob => BlobType.Page,
         Constants.ChangeFeed.EventData.AppendBlob => BlobType.Append,
         _ => default
     };
     record.TryGetValue(Constants.ChangeFeed.EventData.BlobVersionLower, out object blobVersionObject);
     BlobVersion = (string)blobVersionObject;
     record.TryGetValue(Constants.ChangeFeed.EventData.ContainerVersion, out object containerVersionObject);
     ContainerVersion = (string)containerVersionObject;
     record.TryGetValue(Constants.ChangeFeed.EventData.BlobTier, out object blobTierObject);
     if (blobTierObject != null)
     {
         BlobAccessTier = new AccessTier((string)blobTierObject);
     }
     record.TryGetValue(Constants.ChangeFeed.EventData.ContentOffset, out object contentOffset);
     ContentOffset = (long?)contentOffset;
     record.TryGetValue(Constants.ChangeFeed.EventData.DestinationUrl, out object destinationUrl);
     DestinationUri = !string.IsNullOrEmpty((string)destinationUrl) ? new Uri((string)destinationUrl) : null;
     record.TryGetValue(Constants.ChangeFeed.EventData.SourceUrl, out object sourceUrl);
     SourceUri = !string.IsNullOrEmpty((string)sourceUrl) ? new Uri((string)sourceUrl) : null;
     record.TryGetValue(Constants.ChangeFeed.EventData.Url, out object url);
     Uri = !string.IsNullOrEmpty((string)url) ? new Uri((string)url) : null;
     record.TryGetValue(Constants.ChangeFeed.EventData.Recursive, out object recursive);
     Recursive = (bool?)recursive;
     Sequencer = (string)record[Constants.ChangeFeed.EventData.Sequencer];
     record.TryGetValue(Constants.ChangeFeed.EventData.PreviousInfo, out object previousInfoObject);
     PreviousInfo = ExtractPreviousInfo(record);
     record.TryGetValue(Constants.ChangeFeed.EventData.Snapshot, out object snapshotObject);
     Snapshot = (string)snapshotObject;
     UpdatedBlobProperties = ExtractBlobProperties(record);
     AsyncOperationInfo    = ExtractAsyncOperationInfo(record);
     UpdatedBlobTags       = ExtractUpdatedBlobTags(record);
 }
        /// <summary>
        /// The <see cref="SetBlobAccessTier(string, string, AccessTier, RehydratePriority?, BlobRequestConditions)"/>
        /// operation sets the tier on a blob.  The operation is allowed on
        /// block blobs in a blob storage or general purpose v2 account.
        ///
        /// A block blob's tier determines Hot/Cool/Archive storage type.  This
        /// operation does not update the blob's ETag.  For detailed
        /// information about block blob level tiering see
        /// <see href="https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers">
        /// Blob Storage Tiers</see>.
        /// </summary>
        /// <param name="blobContainerName">
        /// The name of the container containing the blob to set the tier of.
        /// </param>
        /// <param name="blobName">
        /// The name of the blob to set the tier of.
        /// </param>
        /// <param name="accessTier">
        /// Indicates the tier to be set on the blob.
        /// </param>
        /// <param name="leaseAccessConditions">
        /// Optional <see cref="BlobRequestConditions"/> to add conditions on
        /// setting the access tier.
        /// </param>
        /// <param name="rehydratePriority">
        /// Optional <see cref="RehydratePriority"/>
        /// Indicates the priority with which to rehydrate an archived blob.
        /// </param>
        /// <returns>
        /// A <see cref="Response"/> on successfully deleting.  The response
        /// cannot be used until the batch has been submitted with
        /// <see cref="BlobBatchClient.SubmitBatchAsync"/>.
        /// </returns>
        public virtual Response SetBlobAccessTier(
            string blobContainerName,
            string blobName,
            AccessTier accessTier,
            RehydratePriority?rehydratePriority         = default,
            BlobRequestConditions leaseAccessConditions = default)
        {
            SetBatchOperationType(BlobBatchOperationType.SetAccessTier);

            HttpMessage message = BlobRestClient.CreateSetAccessTierRequest(
                containerName: blobContainerName,
                blob: blobName.EscapePath(),
                accessTier.ToBatchAccessTier(),
                timeout: null,
                rehydratePriority: rehydratePriority.ToBatchRehydratePriority(),
                leaseId: leaseAccessConditions?.LeaseId,
                ifTags: leaseAccessConditions?.TagConditions);

            _messages.Add(message);

            return(new DelayedResponse(
                       message,
                       async response =>
            {
                switch (response.Status)
                {
                case 200:
                case 202:
                    BlobSetAccessTierHeaders blobSetAccessTierHeaders = new BlobSetAccessTierHeaders(response);
                    return ResponseWithHeaders.FromValue(blobSetAccessTierHeaders, response);

                default:
                    throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(response).ConfigureAwait(false);
                }
            }));
        }
 /// <summary>
 /// Specifies the access tier used for billing.
 /// Access tier cannot be changed more than once every 7 days (168 hours).
 /// Access tier cannot be set for StandardLRS, StandardGRS, StandardRAGRS,
 /// or PremiumLRS account types.
 /// </summary>
 /// <param name="accessTier">The access tier value.</param>
 /// <return>The next stage of storage account definition.</return>
 StorageAccount.Definition.IWithCreate StorageAccount.Definition.IWithCreateAndAccessTier.WithAccessTier(AccessTier accessTier)
 {
     return(this.WithAccessTier(accessTier));
 }
 public IAzureBlobContainerConfigurator AccessTier(AccessTier accessTier)
 {
     _accessTierBuilder = _ => accessTier;
     return(this);
 }
        private Task ChangeTier(string fileName, AccessTier tier)
        {
            BlobClient blob = _blobContainer.GetBlobClient(fileName);

            return(blob.SetAccessTierAsync(tier));
        }
        /// <summary>
        /// Changes the access tier of a block blob in a blob container.
        /// </summary>
        /// <param name="containerName">Name of the blob container.</param>
        /// <param name="blobName">Name of the blob.</param>
        /// <param name="targetTier"><see cref="AccessTier"/> which indicates the new access tier for the blob.</param>
        /// <returns>True or false.</returns>
        public static async Task <bool> ChangeAccessTier(string containerName, string blobName, AccessTier targetTier)
        {
            try
            {
                BlobClient blob = s_blobServiceClient.GetBlobContainerClient(containerName).GetBlobClient(blobName);
                await blob.SetAccessTierAsync(targetTier);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #18
0
        public Worker(ILogger <Worker> logger,
                      IHostApplicationLifetime hostApplicationLifetime,
                      TelemetryClient telemetryClient,
                      Config config)
        {
            _logger = logger;
            _hostApplicationLifetime = hostApplicationLifetime;
            _telemetryClient         = telemetryClient;
            _config = config;
            _todo   = new ConcurrentBag <Task>();

            using (var op = _telemetryClient.StartOperation <DependencyTelemetry>("Setup"))
            {
                _logger.LogInformation($"Run = {_config.Run}");
                op.Telemetry.Properties.Add("Run", _config.Run);

                _logger.LogInformation($"Container = {_config.Container}");
                op.Telemetry.Properties.Add("Container", _config.Container);

                var blobServiceClient = new BlobServiceClient(_config.StorageConnectionString);
                _logger.LogInformation($"StorageAccountName = {blobServiceClient.AccountName}");
                op.Telemetry.Properties.Add("StorageAccountName", blobServiceClient.AccountName);

                //Default the delimiter to a slash if not provided
                if (string.IsNullOrEmpty(_config.Delimiter))
                {
                    _config.Delimiter = "/";
                }
                _logger.LogInformation($"Delimiter = {_config.Delimiter}");
                op.Telemetry.Properties.Add("Delimiter", _config.Delimiter);

                //Set the starting point to the root if not provided
                if (string.IsNullOrEmpty(_config.Prefix))
                {
                    _config.Prefix = string.Empty;
                }
                //If starting point is provided, ensure that it has the delimiter at the end
                else if (!_config.Prefix.EndsWith(_config.Delimiter))
                {
                    _config.Prefix = _config.Prefix + _config.Delimiter;
                }
                _logger.LogInformation($"Prefix = {_config.Prefix}");
                op.Telemetry.Properties.Add("Prefix", _config.Prefix);

                //Set the default thread count if one was not set
                if (_config.ThreadCount < 1)
                {
                    _config.ThreadCount = Environment.ProcessorCount * 8;
                }
                _logger.LogInformation($"ThreadCount = {_config.ThreadCount}");
                op.Telemetry.Properties.Add("ThreadCount", _config.ThreadCount.ToString());

                //The Semaphore ensures how many scans can happen at the same time
                _slim = new SemaphoreSlim(_config.ThreadCount);

                _logger.LogInformation($"WhatIf = {_config.WhatIf}");
                op.Telemetry.Properties.Add("WhatIf", _config.WhatIf.ToString());

                _logger.LogInformation($"TargetAccessTier = {_config.TargetAccessTier}");
                op.Telemetry.Properties.Add("TargetAccessTier", _config.TargetAccessTier);

                if (_config.TargetAccessTier.Equals("Hot", StringComparison.InvariantCultureIgnoreCase))
                {
                    _targetAccessTier = AccessTier.Hot;
                }
                else if (_config.TargetAccessTier.Equals("Cool", StringComparison.InvariantCultureIgnoreCase))
                {
                    _targetAccessTier = AccessTier.Cool;
                }
                else if (_config.TargetAccessTier.Equals("Archive", StringComparison.InvariantCultureIgnoreCase))
                {
                    _targetAccessTier = AccessTier.Archive;
                }
                else
                {
                    _logger.LogError($"Invalid Target Access Tier of {_config.TargetAccessTier} must be either Hot, Cool or Archive.");
                    _configValid = false;
                }

                _logger.LogInformation($"SourceAccessTier = {_config.SourceAccessTier}");
                op.Telemetry.Properties.Add("SourceAccessTier", _config.SourceAccessTier);

                if (_config.SourceAccessTier.Equals("Hot", StringComparison.InvariantCultureIgnoreCase))
                {
                    _sourceAccessTier = AccessTier.Hot;
                }
                else if (_config.SourceAccessTier.Equals("Cool", StringComparison.InvariantCultureIgnoreCase))
                {
                    _sourceAccessTier = AccessTier.Cool;
                }
                else if (_config.SourceAccessTier.Equals("Archive", StringComparison.InvariantCultureIgnoreCase))
                {
                    _sourceAccessTier = AccessTier.Archive;
                }
                else
                {
                    _logger.LogError($"Invalid Source Access Tier of {_config.SourceAccessTier} must be either Hot, Cool or Archive.");
                    _configValid = false;
                }

                if (_sourceAccessTier.Equals(_targetAccessTier))
                {
                    _logger.LogError($"Invalid Source/Target Access Tier they cannot be the same.");
                    _configValid = false;
                }

                if (string.IsNullOrEmpty(config.Container))
                {
                    _logger.LogError($"No Storage Container Name Provided.");
                    _configValid = false;
                }
            }
        }
 /// <summary>
 /// Convert an AccessTier into an AccessTierRequired value.
 /// </summary>
 /// <param name="tier">The AccessTier.</param>
 /// <returns>An AccessTierRequired value.</returns>
 internal static AccessTierRequired ToAccessTierRequired(this AccessTier tier) =>
 (AccessTierRequired)tier.ToString();
Beispiel #20
0
 public Task AssertTiers(AccessTier tier, BlockBlobClient[] blobs) =>
 Task.WhenAll(blobs.Select(b => AssertTiers(tier, b)));
Beispiel #21
0
 public static bool IsLowerTierThan(this AccessTier currentAccess, AccessTier accessTier)
 {
     return(currentAccess > accessTier);
 }
 /// <summary>
 /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider"
 /// /> and <see cref="ignoreCase" />
 /// </summary>
 /// <param name="sourceValue">the <see cref="System.Object"/> to convert from</param>
 /// <param name="destinationType">the <see cref="System.Type" /> to convert to</param>
 /// <param name="formatProvider">not used by this TypeConverter.</param>
 /// <param name="ignoreCase">when set to <c>true</c>, will ignore the case when converting.</param>
 /// <returns>
 /// an instance of <see cref="AccessTier" />, or <c>null</c> if there is no suitable conversion.
 /// </returns>
 public override object ConvertFrom(object sourceValue, global::System.Type destinationType, global::System.IFormatProvider formatProvider, bool ignoreCase) => AccessTier.CreateFrom(sourceValue);
Beispiel #23
0
 public static bool IsHigherTierThan(this AccessTier currentAccess, AccessTier accessTier)
 {
     return(currentAccess < accessTier);
 }
Beispiel #24
0
 public static string ToSerialString(this AccessTier value) => value switch
 {
Beispiel #25
0
        public SsoResponse ValidateAuthenticationStatus(
            AccessTier accessTier,
            bool loggedIn,
            string serviceName,
            string serviceUri,
            string userName,
            bool failuresHaveOccurred = false
            )
        {
            if (string.IsNullOrWhiteSpace(serviceName) ||
                string.IsNullOrWhiteSpace(serviceUri) ||
                string.IsNullOrWhiteSpace(userName))
            {
                _logger.LogWarning("Some properties which should not be null/empty were null/empty.\n" +
                                   "Did you forget to add a header in your reverse proxy?\n" +
                                   $"\tserviceName = {serviceName}\n" +
                                   $"\tserviceUri = {serviceUri}\n" +
                                   $"\tuserName = {userName}");
            }

            var rules = _configurationService.GetAccessControls(serviceName)
                        .Where(rule => rule.Path == null || serviceUri.StartsWith(rule.Path));

            var numRules = 0;

            foreach (var rule in rules)
            {
                var block = rule.ControlType == ControlType.Allow ?
                            accessTier.IsHigherTierThan(rule.MinimumAccessTier ?? AccessTier.Failure) :
                            accessTier.IsLowerTierThan(rule.MinimumAccessTier ?? AccessTier.NoAccess);

                if (rule.Exempt.Contains(userName))
                {
                    block = !block;
                }

                if (block)
                {
                    return(new SsoResponse(
                               !failuresHaveOccurred,
                               loggedIn,
                               true,
                               AccessTier.NoAccess,
                               403,
                               string.IsNullOrWhiteSpace(rule.BlockMessage) ? _configurationService.GetConfig().DefaultAccessDeniedMessage : rule.BlockMessage
                               ));
                }

                numRules++;
            }

            var globalBlocked = numRules == 0 ? accessTier == AccessTier.NoAccess : false;
            var message       = "";
            var status        = 200;

            if (globalBlocked)
            {
                if (failuresHaveOccurred)
                {
                    status  = 400;
                    message = "An error occurred";
                }
                else if (loggedIn)
                {
                    status  = 403;
                    message = _configurationService.GetConfig().DefaultAccessDeniedMessage;
                }
                else
                {
                    status  = 401;
                    message = "Login Required";
                }
            }

            return(new SsoResponse(
                       !failuresHaveOccurred,
                       loggedIn,
                       globalBlocked,
                       accessTier,
                       status,
                       message
                       ));
        }
 /// <summary>
 /// Specifies the access tier used for billing.
 /// Access tier cannot be changed more than once every 7 days (168 hours).
 /// Access tier cannot be set for StandardLRS, StandardGRS, StandardRAGRS,
 /// or PremiumLRS account types.
 /// </summary>
 /// <param name="accessTier">The access tier value.</param>
 /// <return>The next stage of storage account update.</return>
 StorageAccount.Update.IUpdate StorageAccount.Update.IWithAccessTier.WithAccessTier(AccessTier accessTier)
 {
     return(this.WithAccessTier(accessTier));
 }
Beispiel #27
0
 public static BatchAccessTier ToBatchAccessTier(this AccessTier accessTier)
 => new BatchAccessTier(accessTier.ToString());