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()
        {
            if (ShouldProcess("ServiceProperties", VerbsCommon.Set))
            {
                if (ServiceType != StorageServiceType.Table)
                {
                    StorageClient.ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);

                    serviceProperties.DefaultServiceVersion = this.DefaultServiceVersion;

                    Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
                                                        GetRequestOptions(ServiceType), OperationContext);

                    if (PassThru)
                    {
                        WriteObject(new PSSeriviceProperties(serviceProperties));
                    }
                }
                else //Table use old XSCL
                {
                    StorageTableManagement tableChannel = new StorageTableManagement(Channel.StorageContext);

                    if (!tableChannel.IsTokenCredential)
                    {
                        XTable.ServiceProperties serviceProperties = tableChannel.GetStorageTableServiceProperties(GetTableRequestOptions(), TableOperationContext);

                        if (!string.IsNullOrEmpty(DefaultServiceVersion))
                        {
                            serviceProperties.DefaultServiceVersion = this.DefaultServiceVersion;
                        }

                        tableChannel.SetStorageTableServiceProperties(serviceProperties,
                                                                      GetTableRequestOptions(), TableOperationContext);

                        if (PassThru)
                        {
                            WriteObject(new PSSeriviceProperties(serviceProperties));
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Updating default service version is not supported while using OAuth.");
                    }
                }
            }
        }
示例#3
0
        public override void ExecuteCmdlet()
        {
            if (ShouldProcess("ServiceProperties", VerbsCommon.Set))
            {
                if (ServiceType != StorageServiceType.Table)
                {
                    StorageClient.ServiceProperties serviceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);

                    serviceProperties.DefaultServiceVersion = this.DefaultServiceVersion;

                    Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
                                                        GetRequestOptions(ServiceType), OperationContext);

                    if (PassThru)
                    {
                        WriteObject(new PSSeriviceProperties(serviceProperties));
                    }
                }
                else //Table use old XSCL
                {
                    StorageTableManagement   tableChannel      = new StorageTableManagement(Channel.StorageContext);
                    XTable.ServiceProperties serviceProperties = tableChannel.GetStorageTableServiceProperties(GetTableRequestOptions(), TableOperationContext);

                    if (!string.IsNullOrEmpty(DefaultServiceVersion))
                    {
                        serviceProperties.DefaultServiceVersion = this.DefaultServiceVersion;
                    }

                    tableChannel.SetStorageTableServiceProperties(serviceProperties,
                                                                  GetTableRequestOptions(), TableOperationContext);

                    if (PassThru)
                    {
                        WriteObject(new PSSeriviceProperties(serviceProperties));
                    }
                }
            }
        }
        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 (StorageServiceType.File == ServiceType)
            {
                throw new PSInvalidOperationException(Resources.FileNotSupportLogging);
            }

            if (ServiceType != StorageServiceType.Table)
            {
                StorageClient.ServiceProperties currentServiceProperties = Channel.GetStorageServiceProperties(ServiceType, GetRequestOptions(ServiceType), OperationContext);

                // Premium Account not support classic metrics and logging
                if (currentServiceProperties.Logging == null)
                {
                    AccountProperties accountProperties = Channel.GetAccountProperties();
                    if (accountProperties.SkuName.Contains("Premium"))
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "This Storage account doesn't support Classic Logging, since it’s a Premium Storage account: {0}", Channel.StorageContext.StorageAccountName));
                    }
                }

                StorageClient.ServiceProperties serviceProperties = new StorageClient.ServiceProperties();
                serviceProperties.Clean();
                serviceProperties.Logging = currentServiceProperties.Logging;

                UpdateServiceProperties(serviceProperties.Logging);

                Channel.SetStorageServiceProperties(ServiceType, serviceProperties,
                                                    GetRequestOptions(ServiceType), OperationContext);

                if (PassThru)
                {
                    WriteObject(serviceProperties.Logging);
                }
            }
            else //Table use old XSCL
            {
                StorageTableManagement   tableChannel             = new StorageTableManagement(Channel.StorageContext);
                XTable.ServiceProperties currentServiceProperties = tableChannel.GetStorageTableServiceProperties(GetTableRequestOptions(), TableOperationContext);

                // Premium Account not support classic metrics and logging
                if (currentServiceProperties.Logging == null)
                {
                    AccountProperties accountProperties = Channel.GetAccountProperties();
                    if (accountProperties.SkuName.Contains("Premium"))
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "This Storage account doesn't support Classic Logging, since it’s a Premium Storage account: {0}", Channel.StorageContext.StorageAccountName));
                    }
                }

                XTable.ServiceProperties serviceProperties = new XTable.ServiceProperties();
                serviceProperties.Clean();
                serviceProperties.Logging = currentServiceProperties.Logging;

                UpdateTableServiceProperties(serviceProperties.Logging);

                tableChannel.SetStorageTableServiceProperties(serviceProperties,
                                                              GetTableRequestOptions(), TableOperationContext);

                if (PassThru)
                {
                    WriteObject(serviceProperties.Logging);
                }
            }
        }
        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);
            }
        }