/// <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> /// 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; try { switch (type) { case StorageServiceType.Blob: return(account.CreateCloudBlobClient().GetServicePropertiesAsync((BlobRequestOptions)options, operationContext).Result); case StorageServiceType.Queue: return(account.CreateCloudQueueClient().GetServicePropertiesAsync((QueueRequestOptions)options, operationContext).Result); case StorageServiceType.Table: return(account.CreateCloudTableClient().GetServicePropertiesAsync((TableRequestOptions)options, operationContext).Result); case StorageServiceType.File: FileServiceProperties fileServiceProperties = account.CreateCloudFileClient().GetServicePropertiesAsync((FileRequestOptions)options, operationContext).Result; ServiceProperties sp = new ServiceProperties(); sp.Clean(); sp.Cors = fileServiceProperties.Cors; sp.HourMetrics = fileServiceProperties.HourMetrics; sp.MinuteMetrics = fileServiceProperties.MinuteMetrics; return(sp); default: throw new ArgumentException(Resources.InvalidStorageServiceType, "type"); } } catch (AggregateException e) when(e.InnerException is StorageException) { throw e.InnerException; } }
public override void ExecuteCmdlet() { if (ServiceType != StorageServiceType.Table) { ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = currentServiceProperties.Cors; serviceProperties.Cors.CorsRules.Clear(); Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); } else //Table use old XSCL { StorageTableManagement tableChannel = new StorageTableManagement(Channel.StorageContext); XTable.ServiceProperties currentServiceProperties = tableChannel.GetStorageTableServiceProperties(GetTableRequestOptions(), TableOperationContext); XTable.ServiceProperties serviceProperties = new XTable.ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = currentServiceProperties.Cors; serviceProperties.Cors.CorsRules.Clear(); tableChannel.SetStorageTableServiceProperties(serviceProperties, GetTableRequestOptions(), TableOperationContext); } }
public override void ExecuteCmdlet() { ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = currentServiceProperties.Cors; serviceProperties.Cors.CorsRules.Clear(); Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); }
public override void ExecuteCmdlet() { ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); // Premium Account not support classic metrics and logging if ((MetricsType == ServiceMetricsType.Hour && currentServiceProperties.HourMetrics == null) || (MetricsType == ServiceMetricsType.Minute && currentServiceProperties.MinuteMetrics == null)) { AccountProperties accountProperties = Channel.GetAccountProperties(); if (accountProperties.SkuName.Contains("Premium")) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "This Storage account doesn't support Classic Metrics, since it’s a Premium Storage account: {0}", Channel.StorageContext.StorageAccountName)); } } ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); bool isHourMetrics = false; switch (MetricsType) { case ServiceMetricsType.Hour: serviceProperties.HourMetrics = currentServiceProperties.HourMetrics; UpdateServiceProperties(serviceProperties.HourMetrics); isHourMetrics = true; break; case ServiceMetricsType.Minute: serviceProperties.MinuteMetrics = currentServiceProperties.MinuteMetrics; UpdateServiceProperties(serviceProperties.MinuteMetrics); isHourMetrics = false; break; } Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); if (PassThru) { if (isHourMetrics) { WriteObject(serviceProperties.HourMetrics); } else { WriteObject(serviceProperties.MinuteMetrics); } } }
public override void ExecuteCmdlet() { ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); serviceProperties.Logging = currentServiceProperties.Logging; UpdateServiceProperties(serviceProperties.Logging); Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); if (PassThru) { WriteObject(serviceProperties.Logging); } }
public override void ExecuteCmdlet() { ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = new CorsProperties(); foreach (var corsRuleObject in this.CorsRules) { CorsRule corsRule = new CorsRule(); corsRule.AllowedHeaders = corsRuleObject.AllowedHeaders; corsRule.AllowedOrigins = corsRuleObject.AllowedOrigins; corsRule.ExposedHeaders = corsRuleObject.ExposedHeaders; corsRule.MaxAgeInSeconds = corsRuleObject.MaxAgeInSeconds; this.SetAllowedMethods(corsRule, corsRuleObject.AllowedMethods); serviceProperties.Cors.CorsRules.Add(corsRule); } try { Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); } catch (StorageException se) { if ((null != se.RequestInformation) && ((int)HttpStatusCode.BadRequest == se.RequestInformation.HttpStatusCode) && (null != se.RequestInformation.ExtendedErrorInformation) && (string.Equals(InvalidXMLNodeValueError, se.RequestInformation.ExtendedErrorInformation.ErrorCode, StringComparison.OrdinalIgnoreCase) || string.Equals(InvalidXMLDocError, se.RequestInformation.ExtendedErrorInformation.ErrorCode, StringComparison.OrdinalIgnoreCase))) { throw new InvalidOperationException(Resources.CORSRuleError); } else { throw; } } if (PassThru) { WriteObject(this.CorsRules); } }
public override void ExecuteCmdlet() { if (StorageServiceType.File == ServiceType) { throw new PSInvalidOperationException(Resources.FileNotSupportMetrics); } ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); bool isHourMetrics = false; switch (MetricsType) { case ServiceMetricsType.Hour: serviceProperties.HourMetrics = currentServiceProperties.HourMetrics; UpdateServiceProperties(serviceProperties.HourMetrics); isHourMetrics = true; break; case ServiceMetricsType.Minute: serviceProperties.MinuteMetrics = currentServiceProperties.MinuteMetrics; UpdateServiceProperties(serviceProperties.MinuteMetrics); isHourMetrics = false; break; } Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); if (PassThru) { if (isHourMetrics) { WriteObject(serviceProperties.HourMetrics); } else { WriteObject(serviceProperties.MinuteMetrics); } } }
public override void ExecuteCmdlet() { CloudStorageAccount account = GetCloudStorageAccount(); ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(account, ServiceType, GetRequestOptions(ServiceType), OperationContext); ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); bool isHourMetrics = false; switch (MetricsType) { case ServiceMetricsType.Hour: serviceProperties.HourMetrics = currentServiceProperties.HourMetrics; UpdateServiceProperties(serviceProperties.HourMetrics); isHourMetrics = true; break; case ServiceMetricsType.Minute: serviceProperties.MinuteMetrics = currentServiceProperties.MinuteMetrics; UpdateServiceProperties(serviceProperties.MinuteMetrics); isHourMetrics = false; break; } Channel.SetStorageServiceProperties(account, ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); if (PassThru) { if (isHourMetrics) { WriteObject(serviceProperties.HourMetrics); } else { WriteObject(serviceProperties.MinuteMetrics); } } }
public override void ExecuteCmdlet() { if (ServiceType != StorageServiceType.Table) { ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext); // Premium Account not support classic metrics and logging if ((MetricsType == ServiceMetricsType.Hour && currentServiceProperties.HourMetrics == null) || (MetricsType == ServiceMetricsType.Minute && currentServiceProperties.MinuteMetrics == null)) { AccountProperties accountProperties = Channel.GetAccountProperties(); if (accountProperties.SkuName.Contains("Premium")) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "This Storage account doesn't support Classic Metrics, since it’s a Premium Storage account: {0}", Channel.StorageContext.StorageAccountName)); } } ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); bool isHourMetrics = false; switch (MetricsType) { case ServiceMetricsType.Hour: serviceProperties.HourMetrics = currentServiceProperties.HourMetrics; UpdateServiceProperties(serviceProperties.HourMetrics); isHourMetrics = true; break; case ServiceMetricsType.Minute: serviceProperties.MinuteMetrics = currentServiceProperties.MinuteMetrics; UpdateServiceProperties(serviceProperties.MinuteMetrics); isHourMetrics = false; break; } Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); if (PassThru) { if (isHourMetrics) { WriteObject(serviceProperties.HourMetrics); } else { WriteObject(serviceProperties.MinuteMetrics); } } } else //Table use old XSCL { StorageTableManagement tableChannel = new StorageTableManagement(Channel.StorageContext); if (!tableChannel.IsTokenCredential) { XTable.ServiceProperties currentServiceProperties = tableChannel.GetStorageTableServiceProperties(GetTableRequestOptions(), TableOperationContext); // Premium Account not support classic metrics and logging if ((MetricsType == ServiceMetricsType.Hour && currentServiceProperties.HourMetrics == null) || (MetricsType == ServiceMetricsType.Minute && currentServiceProperties.MinuteMetrics == null)) { AccountProperties accountProperties = Channel.GetAccountProperties(); if (accountProperties.SkuName.Contains("Premium")) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "This Storage account doesn't support Classic Metrics, since it’s a Premium Storage account: {0}", Channel.StorageContext.StorageAccountName)); } } XTable.ServiceProperties serviceProperties = new XTable.ServiceProperties(); serviceProperties.Clean(); bool isHourMetrics = false; switch (MetricsType) { case ServiceMetricsType.Hour: serviceProperties.HourMetrics = currentServiceProperties.HourMetrics; UpdateServiceProperties(serviceProperties.HourMetrics); isHourMetrics = true; break; case ServiceMetricsType.Minute: serviceProperties.MinuteMetrics = currentServiceProperties.MinuteMetrics; UpdateServiceProperties(serviceProperties.MinuteMetrics); isHourMetrics = false; break; } tableChannel.SetStorageTableServiceProperties(serviceProperties, GetTableRequestOptions(), TableOperationContext); if (PassThru) { if (isHourMetrics) { WriteObject(serviceProperties.HourMetrics); } else { WriteObject(serviceProperties.MinuteMetrics); } } } else { TableServiceProperties serviceProperties = tableChannel.GetProperties(this.CmdletCancellationToken); // Premium Account not support classic metrics and logging if ((MetricsType == ServiceMetricsType.Hour && serviceProperties.HourMetrics == null) || (MetricsType == ServiceMetricsType.Minute && serviceProperties.MinuteMetrics == null)) { this.ThrowIfPremium("This Storage account doesn't support Classic Metrics, since it’s a Premium Storage account: {0}"); } switch (MetricsType) { case ServiceMetricsType.Hour: UpdateServiceProperties(serviceProperties.HourMetrics); break; case ServiceMetricsType.Minute: UpdateServiceProperties(serviceProperties.MinuteMetrics); break; default: throw new ArgumentException($"Unsupported metrics type {MetricsType}"); } tableChannel.SetProperties(serviceProperties, this.CmdletCancellationToken); if (PassThru) { WriteObject(PSSeriviceProperties.ConvertMetricsProperties(MetricsType == ServiceMetricsType.Hour ? serviceProperties.HourMetrics : serviceProperties.MinuteMetrics)); } } } }
public override void ExecuteCmdlet() { if (ServiceType != StorageServiceType.Table) { ServiceProperties serviceProperties = new ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = new CorsProperties(); foreach (var corsRuleObject in this.CorsRules) { CorsRule corsRule = new CorsRule(); corsRule.AllowedHeaders = corsRuleObject.AllowedHeaders; corsRule.AllowedOrigins = corsRuleObject.AllowedOrigins; corsRule.ExposedHeaders = corsRuleObject.ExposedHeaders; corsRule.MaxAgeInSeconds = corsRuleObject.MaxAgeInSeconds; this.SetAllowedMethods(corsRule, corsRuleObject.AllowedMethods); serviceProperties.Cors.CorsRules.Add(corsRule); } try { Channel.SetStorageServiceProperties(ServiceType, serviceProperties, GetRequestOptions(ServiceType), OperationContext); } catch (StorageException se) { if ((null != se.RequestInformation) && ((int)HttpStatusCode.BadRequest == se.RequestInformation.HttpStatusCode) && (null != se.RequestInformation.ExtendedErrorInformation) && (string.Equals(InvalidXMLNodeValueError, se.RequestInformation.ErrorCode, StringComparison.OrdinalIgnoreCase) || string.Equals(InvalidXMLDocError, se.RequestInformation.ErrorCode, StringComparison.OrdinalIgnoreCase))) { throw new InvalidOperationException(Resources.CORSRuleError); } else { throw; } } } else //Table use old XSCL { StorageTableManagement tableChannel = new StorageTableManagement(Channel.StorageContext); if (!tableChannel.IsTokenCredential) { XTable.ServiceProperties serviceProperties = new XTable.ServiceProperties(); serviceProperties.Clean(); serviceProperties.Cors = new XTable.CorsProperties(); foreach (var corsRuleObject in this.CorsRules) { XTable.CorsRule corsRule = new XTable.CorsRule(); corsRule.AllowedHeaders = corsRuleObject.AllowedHeaders; corsRule.AllowedOrigins = corsRuleObject.AllowedOrigins; corsRule.ExposedHeaders = corsRuleObject.ExposedHeaders; corsRule.MaxAgeInSeconds = corsRuleObject.MaxAgeInSeconds; this.SetAllowedMethods(corsRule, corsRuleObject.AllowedMethods); serviceProperties.Cors.CorsRules.Add(corsRule); } try { tableChannel.SetStorageTableServiceProperties(serviceProperties, GetTableRequestOptions(), TableOperationContext); } catch (XTable.StorageException se) { if ((null != se.RequestInformation) && ((int)HttpStatusCode.BadRequest == se.RequestInformation.HttpStatusCode) && (null != se.RequestInformation.ExtendedErrorInformation) && (string.Equals(InvalidXMLNodeValueError, se.RequestInformation.ErrorCode, StringComparison.OrdinalIgnoreCase) || string.Equals(InvalidXMLDocError, se.RequestInformation.ErrorCode, StringComparison.OrdinalIgnoreCase))) { throw new InvalidOperationException(Resources.CORSRuleError); } else { throw; } } } else { TableServiceProperties serviceProperties = tableChannel.GetProperties(this.CmdletCancellationToken); serviceProperties.Cors.Clear(); foreach (PSCorsRule corsRule in this.CorsRules) { serviceProperties.Cors.Add(new TableCorsRule( corsRule.AllowedOrigins == null ? string.Empty : string.Join(",", corsRule.AllowedOrigins), this.CheckAndJoinAllowedMethods(corsRule.AllowedMethods), corsRule.AllowedHeaders == null ? string.Empty : string.Join(",", corsRule.AllowedHeaders), corsRule.ExposedHeaders == null ? string.Empty : string.Join(",", corsRule.ExposedHeaders), corsRule.MaxAgeInSeconds)); } try { tableChannel.SetProperties(serviceProperties, this.CmdletCancellationToken); } catch (RequestFailedException ex) { this.WriteExceptionError(ex); throw new InvalidOperationException(Resources.CORSRuleError); } } } if (PassThru) { WriteObject(this.CorsRules); } }