public EnableStorageAnalyticsCommand(StorageServiceType type, AnalyticsMetricsType analytics) { if(type == StorageServiceType) throw new FluentManagementException("unable to complete request need another storage type", "EnableStorageAnalyticsCommand"); _type = type; _analytics = analytics; Version = "2013-08-15"; }
internal void ToBlobPath_IfValidBlobOperationEntry_ReturnsBlobPath(StorageServiceOperationType operationType, StorageServiceType serviceType, string requestedObjectKey, string expectedContainerName, string expectedBlobName) { StorageAnalyticsLogEntry entry = CreateEntry("2014-09-08T18:44:18.9681025Z", operationType, serviceType, requestedObjectKey); BlobPath blobPath = entry.ToBlobPath(); Assert.NotNull(blobPath); Assert.Equal(expectedContainerName, blobPath.ContainerName); Assert.Equal(expectedBlobName, blobPath.BlobName); }
public override void ExecuteCmdlet() { StorageServiceType serviceType = StorageServiceType.Blob; if (ShouldProcess(serviceType.ToString(), "Enable Static Website")) { ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(serviceType, GetRequestOptions(serviceType), OperationContext); EnableStaticWebsiteProperties(serviceProperties); Channel.SetStorageServiceProperties(serviceType, serviceProperties, GetRequestOptions(serviceType), OperationContext); if (PassThru) { WriteObject(PSStaticWebsiteProperties.ParsePSStaticWebsiteProperties(serviceProperties.StaticWebsite)); } } }
public override void ExecuteCmdlet() { StorageServiceType serviceType = StorageServiceType.Blob; if (ShouldProcess(serviceType.ToString(), "Enable Delete Retention Policy")) { ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(serviceType, GetRequestOptions(serviceType), OperationContext); DisableDeleteRetentionProperties(serviceProperties); Channel.SetStorageServiceProperties(serviceType, serviceProperties, GetRequestOptions(serviceType), OperationContext); if (PassThru) { WriteObject(PSDeleteRetentionPolicy.ParsePSDeleteRetentionPolicy(serviceProperties.DeleteRetentionPolicy)); } } }
/// <summary> /// Get the service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> /// <returns>The service properties of the specified service type</returns> public ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, OperationContext operationContext) { CloudStorageAccount account = StorageContext.StorageAccount; switch (type) { case StorageServiceType.Blob: return(account.CreateCloudBlobClient().GetServiceProperties((BlobRequestOptions)options, operationContext)); case StorageServiceType.Queue: return(account.CreateCloudQueueClient().GetServiceProperties((QueueRequestOptions)options, operationContext)); case StorageServiceType.Table: return(account.CreateCloudTableClient().GetServiceProperties((TableRequestOptions)options, operationContext)); default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { CloudStorageAccount account = StorageContext.StorageAccount; try { switch (type) { case StorageServiceType.Blob: Task.Run(() => account.CreateCloudBlobClient().SetServicePropertiesAsync(properties, (BlobRequestOptions)options, operationContext)).Wait(); break; case StorageServiceType.Queue: Task.Run(() => account.CreateCloudQueueClient().SetServicePropertiesAsync(properties, (QueueRequestOptions)options, operationContext)).Wait(); break; case StorageServiceType.Table: Task.Run(() => account.CreateCloudTableClient().SetServicePropertiesAsync(properties, (TableRequestOptions)options, operationContext)).Wait(); break; case StorageServiceType.File: if (null != properties.Logging) { throw new InvalidOperationException(Resources.FileNotSupportLogging); } FileServiceProperties fileServiceProperties = new FileServiceProperties(); fileServiceProperties.Cors = properties.Cors; fileServiceProperties.HourMetrics = properties.HourMetrics; fileServiceProperties.MinuteMetrics = properties.MinuteMetrics; Task.Run(() => account.CreateCloudFileClient().SetServicePropertiesAsync(fileServiceProperties, (FileRequestOptions)options, operationContext)).Wait(); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } } catch (AggregateException e) when(e.InnerException is StorageException) { throw e.InnerException; } }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(CloudStorageAccount account, StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { switch (type) { case StorageServiceType.Blob: account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext); break; case StorageServiceType.Queue: account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext); break; case StorageServiceType.Table: account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
private bool ValidateStorageServiceEndpoint(string storageAccountName, StorageServiceType storageServiceType, string storageServiceEndpoint) { Uri storageServiceEndpointUri; if (!Uri.TryCreate(storageServiceEndpoint, UriKind.Absolute, out storageServiceEndpointUri)) { return(false); } // Custom domain name for storage services is not supported. string storageServiceEndpointPublicAzure = string.Format(CultureInfo.InvariantCulture, "https://{0}.{1}.{2}/", storageAccountName, storageServiceType, "core.windows.net"); string storageServiceEndpointMooncake = string.Format(CultureInfo.InvariantCulture, "https://{0}.{1}.{2}/", storageAccountName, storageServiceType, "core.chinacloudapi.cn"); if (string.Compare(storageServiceEndpoint.TrimEnd('/'), storageServiceEndpointPublicAzure.TrimEnd('/'), StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(storageServiceEndpoint.TrimEnd('/'), storageServiceEndpointMooncake.TrimEnd('/'), StringComparison.OrdinalIgnoreCase) != 0) { return(false); } return(true); }
/// <summary> /// Get a request options /// </summary> /// <param name="type">Service type</param> /// <returns>Request options</returns> public IRequestOptions GetRequestOptions(StorageServiceType type) { if (ServerTimeoutPerRequest == null) { return(null); } IRequestOptions options = default(IRequestOptions); switch (type) { case StorageServiceType.Blob: options = new BlobRequestOptions(); break; case StorageServiceType.Queue: options = new QueueRequestOptions(); break; case StorageServiceType.Table: options = new TableRequestOptions(); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } if (ServerTimeoutPerRequest != null) { options.ServerTimeout = TimeSpan.FromSeconds((double)ServerTimeoutPerRequest); } if (ClientTimeoutPerRequest != null) { options.MaximumExecutionTime = TimeSpan.FromSeconds((double)ClientTimeoutPerRequest); } return(options); }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { CloudStorageAccount account = StorageContext.StorageAccount; switch (type) { case StorageServiceType.Blob: account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext); break; case StorageServiceType.Queue: account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext); break; case StorageServiceType.Table: account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext); break; case StorageServiceType.File: if (null != properties.Logging) { throw new InvalidOperationException(Resources.FileNotSupportLogging); } if (null != properties.HourMetrics || null != properties.MinuteMetrics) { throw new InvalidOperationException(Resources.FileNotSupportMetrics); } FileServiceProperties fileServiceProperties = new FileServiceProperties(); fileServiceProperties.Cors = properties.Cors; account.CreateCloudFileClient().SetServiceProperties(fileServiceProperties, (FileRequestOptions)options, operationContext); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
/// <summary> /// Get a request options /// </summary> /// <param name="type">Service type</param> /// <returns>Request options</returns> public IRequestOptions GetRequestOptions(StorageServiceType type) { IRequestOptions options; switch (type) { case StorageServiceType.Blob: options = new BlobRequestOptions(); break; case StorageServiceType.Queue: options = new QueueRequestOptions(); break; case StorageServiceType.Table: options = new TableRequestOptions(); break; case StorageServiceType.File: options = new FileRequestOptions(); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } if (this.ServerTimeoutPerRequest.HasValue) { options.ServerTimeout = ConvertToTimeSpan(this.ServerTimeoutPerRequest.Value); } if (this.ClientTimeoutPerRequest.HasValue) { options.MaximumExecutionTime = ConvertToTimeSpan(this.ClientTimeoutPerRequest.Value); } return(options); }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(StorageServiceType type, WindowsAzure.Storage.Shared.Protocol.ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { throw new NotImplementedException("No need to cover this in unit test since there are no additional logics on this api"); }
/// <summary> /// Get the service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> /// <returns>The service properties of the specified service type</returns> public ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, OperationContext operationContext) { throw new NotImplementedException("No need to cover this in unit test since the logic is quite simple. For more details, please read GetAzureStorageServiceLogging.cs"); }
/// <summary> /// Get the resource metric values, based on the resource and service (for example: if the resource is a storage account, possible services are BLOB, Queue, Table and File) /// </summary> /// <param name="resource">The Azure resource for which we want to fetch metrics</param> /// <param name="storageServiceType">The Azure storage service type</param> /// <param name="queryParameters">Query properties to be used when fetching metric data. All fields are optional</param> /// <param name="cancellationToken">Cancellation Token for the async operation</param> /// <returns>A <see cref="Task{TResult}"/> object that represents the asynchronous operation, returning the list metrics</returns> public async Task <IEnumerable <MetricQueryResult> > GetResourceMetricsAsync(ResourceIdentifier resource, StorageServiceType storageServiceType, QueryParameters queryParameters, CancellationToken cancellationToken = default(CancellationToken)) { string resourceId = resource.ToResourceId(storageServiceType); return(await this.GetResourceMetricsAsync(resourceId, queryParameters, cancellationToken)); }
/// <summary> /// Get the resource metric definitions, based on the resource and service (for example: if the resource is a storage account, possible services are BLOB, Queue, Table and File) /// </summary> /// <param name="resource">The Azure resource for which we want to fetch metric definitions</param> /// <param name="storageServiceType">The Azure storage service type</param> /// <param name="cancellationToken">Cancellation Token for the async operation</param> /// <returns>A <see cref="Task{TResult}"/> object that represents the asynchronous operation, returning the list of metric definitions</returns> public async Task <IEnumerable <MetricDefinition> > GetResourceMetricDefinitionsAsync(ResourceIdentifier resource, StorageServiceType storageServiceType, CancellationToken cancellationToken) { string resourceId = resource.ToResourceId(storageServiceType); return(await this.GetResourceMetricDefinitionsAsync(resourceId, cancellationToken)); }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(CloudStorageAccount account, StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { throw new NotImplementedException("No need to cover this in unit test since there are no additional logics on this api"); }
private static StorageAnalyticsLogEntry CreateEntry(string requestStartTime, StorageServiceOperationType operationType, StorageServiceType serviceType, string requestedObjectKey) { StorageAnalyticsLogEntry entry = new StorageAnalyticsLogEntry(); entry.RequestStartTime = DateTime.Parse(requestStartTime, CultureInfo.InvariantCulture); entry.OperationType = operationType; entry.ServiceType = serviceType; entry.RequestedObjectKey = requestedObjectKey; return entry; }
private static StorageAnalyticsLogEntry CreateEntry(string requestStartTime, StorageServiceOperationType operationType, StorageServiceType serviceType, string requestedObjectKey) { StorageAnalyticsLogEntry entry = new StorageAnalyticsLogEntry(); entry.RequestStartTime = DateTime.Parse(requestStartTime, CultureInfo.InvariantCulture); entry.OperationType = operationType; entry.ServiceType = serviceType; entry.RequestedObjectKey = requestedObjectKey; return(entry); }
public RequestWithErrorPayload(StorageAccountSettings settings, string uri, string httpMethod, StorageServiceType serviceType) : base(settings) { TestRequestUri = uri; TestHttpMethod = httpMethod; _serviceType = serviceType; // use a faster retry policy with the same strategy as the real one RetryPolicy = new RetryPolicy <ExceptionRetryStrategy>(3, TimeSpan.FromMilliseconds(1)); }
/// <summary> /// Get the service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> /// <returns>The service properties of the specified service type</returns> public ServiceProperties GetStorageServiceProperties(StorageServiceType type, IRequestOptions options, OperationContext operationContext) { CloudStorageAccount account = StorageContext.StorageAccount; switch (type) { case StorageServiceType.Blob: return account.CreateCloudBlobClient().GetServiceProperties((BlobRequestOptions) options, operationContext); case StorageServiceType.Queue: return account.CreateCloudQueueClient().GetServiceProperties((QueueRequestOptions) options, operationContext); case StorageServiceType.Table: return account.CreateCloudTableClient().GetServiceProperties((TableRequestOptions) options, operationContext); case StorageServiceType.File: FileServiceProperties fileServiceProperties = account.CreateCloudFileClient().GetServiceProperties((FileRequestOptions)options, operationContext); ServiceProperties sp = new ServiceProperties(); sp.Clean(); sp.Cors = fileServiceProperties.Cors; return sp; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
/// <summary> /// Set service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="properties">Service properties</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> public void SetStorageServiceProperties(StorageServiceType type, ServiceProperties properties, IRequestOptions options, OperationContext operationContext) { CloudStorageAccount account = StorageContext.StorageAccount; switch (type) { case StorageServiceType.Blob: account.CreateCloudBlobClient().SetServiceProperties(properties, (BlobRequestOptions)options, operationContext); break; case StorageServiceType.Queue: account.CreateCloudQueueClient().SetServiceProperties(properties, (QueueRequestOptions)options, operationContext); break; case StorageServiceType.Table: account.CreateCloudTableClient().SetServiceProperties(properties, (TableRequestOptions)options, operationContext); break; default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
/// <summary> /// Get the service properties /// </summary> /// <param name="account">Cloud storage account</param> /// <param name="type">Service type</param> /// <param name="options">Request options</param> /// <param name="operationContext">Operation context</param> /// <returns>The service properties of the specified service type</returns> public ServiceProperties GetStorageServiceProperties(CloudStorageAccount account, StorageServiceType type, IRequestOptions options, OperationContext operationContext) { switch (type) { case StorageServiceType.Blob: return account.CreateCloudBlobClient().GetServiceProperties((BlobRequestOptions)options, operationContext); case StorageServiceType.Queue: return account.CreateCloudQueueClient().GetServiceProperties((QueueRequestOptions)options, operationContext); case StorageServiceType.Table: return account.CreateCloudTableClient().GetServiceProperties((TableRequestOptions)options, operationContext); default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } }
/// <summary> /// Gets the resource ID for the specified resource, including the specified storage service type, if provided. /// The resource ID is a string in the ARM resource ID format, for example: /// <example> /// /subscriptions/7904b7bd-5e6b-4415-99a8-355657b7da19/resourceGroups/MyResourceGroupName/providers/Microsoft.Storage/storageAccounts/MyStorage/blobServices/default /// </example> /// </summary> /// <exception cref="ArgumentException">A specific storage service type was specified, but the specified resource is not of type <see cref="ResourceType.AzureStorage"/></exception> /// <param name="resourceIdentifier">The resource identifier</param> /// <param name="storageServiceType">The storage service type</param> /// <returns>The resource ID</returns> public static string ToResourceId(this ResourceIdentifier resourceIdentifier, StorageServiceType storageServiceType) { // Get the resource ID string resourceId = resourceIdentifier.ToResourceId(); // Add a suffix that matches the storage service type if (storageServiceType != StorageServiceType.None) { // Verify that this is a storage resource if (resourceIdentifier.ResourceType != ResourceType.AzureStorage) { throw new ArgumentException($"Unexpected resource type {resourceIdentifier.ResourceType}, expected type {ResourceType.AzureStorage}"); } resourceId += "/" + MapStorageServiceTypeToString[storageServiceType]; } return(resourceId); }