public void MaximumRulesAllowed() { Assert.Throws <InvalidOperationException>(() => { var list = new CorsRules(); for (int i = 0; i < CorsRules.MaximumRulesAllowed + 1; i++) { list.Add(new CorsRule( Guid.NewGuid().ToString(), new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); } }); }
internal FileServiceData(ResourceIdentifier id, string name, ResourceType type, Models.Sku sku, CorsRules cors, DeleteRetentionPolicy shareDeleteRetentionPolicy, ProtocolSettings protocolSettings) : base(id, name, type) { Sku = sku; Cors = cors; ShareDeleteRetentionPolicy = shareDeleteRetentionPolicy; ProtocolSettings = protocolSettings; }
public void UniqueRuleName() { Assert.Throws <InvalidOperationException>(() => { var list = new CorsRules(); for (int i = 0; i < 2 + 1; i++) { list.Add(new CorsRule( "123456", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); } }); }
public void RuleNameReservedUse() { Assert.Throws <ArgumentException>(() => { var list = new CorsRules(); list.Add(new CorsRule( "b2-123456", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); }); }
internal FileServiceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, StorageSku sku, CorsRules cors, DeleteRetentionPolicy shareDeleteRetentionPolicy, ProtocolSettings protocolSettings) : base(id, name, resourceType, systemData) { Sku = sku; Cors = cors; ShareDeleteRetentionPolicy = shareDeleteRetentionPolicy; ProtocolSettings = protocolSettings; }
internal static QueueServiceData DeserializeQueueServiceData(JsonElement element) { ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; Optional <CorsRules> cors = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("cors")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cors = CorsRules.DeserializeCorsRules(property0.Value); continue; } } continue; } } return(new QueueServiceData(id, name, type, systemData, cors.Value)); }
internal BlobServiceProperties(string id, string name, string type, Sku sku, CorsRules cors, string defaultServiceVersion, DeleteRetentionPolicy deleteRetentionPolicy, bool?isVersioningEnabled, bool?automaticSnapshotPolicyEnabled, ChangeFeed changeFeed, RestorePolicyProperties restorePolicy, DeleteRetentionPolicy containerDeleteRetentionPolicy) : base(id, name, type) { Sku = sku; Cors = cors; DefaultServiceVersion = defaultServiceVersion; DeleteRetentionPolicy = deleteRetentionPolicy; IsVersioningEnabled = isVersioningEnabled; AutomaticSnapshotPolicyEnabled = automaticSnapshotPolicyEnabled; ChangeFeed = changeFeed; RestorePolicy = restorePolicy; ContainerDeleteRetentionPolicy = containerDeleteRetentionPolicy; }
internal BlobServiceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, StorageSku sku, CorsRules cors, string defaultServiceVersion, DeleteRetentionPolicy deleteRetentionPolicy, bool?isVersioningEnabled, bool?automaticSnapshotPolicyEnabled, ChangeFeed changeFeed, RestorePolicyProperties restorePolicy, DeleteRetentionPolicy containerDeleteRetentionPolicy, LastAccessTimeTrackingPolicy lastAccessTimeTrackingPolicy) : base(id, name, resourceType, systemData) { Sku = sku; Cors = cors; DefaultServiceVersion = defaultServiceVersion; DeleteRetentionPolicy = deleteRetentionPolicy; IsVersioningEnabled = isVersioningEnabled; AutomaticSnapshotPolicyEnabled = automaticSnapshotPolicyEnabled; ChangeFeed = changeFeed; RestorePolicy = restorePolicy; ContainerDeleteRetentionPolicy = containerDeleteRetentionPolicy; LastAccessTimeTrackingPolicy = lastAccessTimeTrackingPolicy; }
public void RuleNameLength() { Assert.Throws <ArgumentOutOfRangeException>(() => { var list = new CorsRules(); list.Add(new CorsRule( "12345", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); }); Assert.Throws <ArgumentOutOfRangeException>(() => { var list = new CorsRules(); list.Add(new CorsRule( "012345678901234567890123456789012345678901234567890", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); }); }
public void MaxAgeLength() { Assert.Throws <ArgumentOutOfRangeException>(() => { var list = new CorsRules(); list.Add(new CorsRule( "123456", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, CorsRule.MinimumAgeSeconds - 1) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); }); Assert.Throws <ArgumentOutOfRangeException>(() => { var list = new CorsRules(); list.Add(new CorsRule( "123456", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, CorsRule.MaximumAgeSeconds + 1) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } ); }); }
public PSCorsRules(CorsRules rules) { if (rules.CorsRulesProperty is null) { CorsRulesProperty = null; } else { List <PSCorsRule> ruleList = new List <PSCorsRule>(); foreach (CorsRule rule in rules.CorsRulesProperty) { ruleList.Add(new PSCorsRule(rule)); } this.CorsRulesProperty = ruleList.ToArray(); } }
public BlobServicePropertiesImpl WithCORSRule(CorsRule corsRule) { CorsRules corsRules = this.Inner.Cors; if (corsRules == null) { List <CorsRule> firstCorsRule = new List <CorsRule>(); firstCorsRule.Add(corsRule); this.Inner.Cors = new CorsRules(firstCorsRule); } else { List <CorsRule> currentCorsRules = corsRules.CorsRulesProperty as List <CorsRule>; currentCorsRules.Add(corsRule); this.Inner.Cors = new CorsRules(currentCorsRules); } return(this); }
public async Task UpdateTableService() { //update cors CorsRules cors = new CorsRules(); cors.CorsRulesValue.Add(new CorsRule( allowedHeaders: new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" }, allowedMethods: new CorsRuleAllowedMethodsItem[] { "GET", "HEAD", "POST", "OPTIONS", "MERGE", "PUT" }, allowedOrigins: new string[] { "http://www.contoso.com", "http://www.fabrikam.com" }, exposedHeaders: new string[] { "x-ms-meta-*" }, maxAgeInSeconds: 100)); TableServiceData parameter = new TableServiceData() { Cors = cors, }; _tableService = (await _tableService.CreateOrUpdateAsync(parameter)).Value; //validate Assert.AreEqual(_tableService.Data.Cors.CorsRulesValue.Count, 1); }
public CorsRules ParseCorsRules() { if (this.CorsRulesProperty is null) { return(new CorsRules { CorsRulesProperty = null }); } else { CorsRules returnValue = new CorsRules { CorsRulesProperty = new List <CorsRule>() }; foreach (PSCorsRule rule in this.CorsRulesProperty) { returnValue.CorsRulesProperty.Add(rule.ParseCorsRule()); } return(returnValue); } }
/// <summary> /// Sets the properties of a storage account’s Table service, including /// properties for Storage Analytics and CORS (Cross-Origin Resource Sharing) /// rules. /// </summary> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. The name is /// case insensitive. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and use /// numbers and lower-case letters only. /// </param> /// <param name='cors'> /// Specifies CORS rules for the Table service. You can include up to five /// CorsRule elements in the request. If no CorsRule elements are included in /// the request body, all CORS rules will be deleted, and CORS will be disabled /// for the Table service. /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="CloudException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <AzureOperationResponse <TableServiceProperties> > SetServicePropertiesWithHttpMessagesAsync(string resourceGroupName, string accountName, CorsRules cors = default(CorsRules), Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (resourceGroupName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName"); } if (resourceGroupName != null) { if (resourceGroupName.Length > 90) { throw new ValidationException(ValidationRules.MaxLength, "resourceGroupName", 90); } if (resourceGroupName.Length < 1) { throw new ValidationException(ValidationRules.MinLength, "resourceGroupName", 1); } if (!System.Text.RegularExpressions.Regex.IsMatch(resourceGroupName, "^[-\\w\\._\\(\\)]+$")) { throw new ValidationException(ValidationRules.Pattern, "resourceGroupName", "^[-\\w\\._\\(\\)]+$"); } } if (accountName == null) { throw new ValidationException(ValidationRules.CannotBeNull, "accountName"); } if (accountName != null) { if (accountName.Length > 24) { throw new ValidationException(ValidationRules.MaxLength, "accountName", 24); } if (accountName.Length < 3) { throw new ValidationException(ValidationRules.MinLength, "accountName", 3); } } if (Client.ApiVersion == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.ApiVersion"); } if (Client.ApiVersion != null) { if (Client.ApiVersion.Length < 1) { throw new ValidationException(ValidationRules.MinLength, "Client.ApiVersion", 1); } } if (Client.SubscriptionId == null) { throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.SubscriptionId"); } if (Client.SubscriptionId != null) { if (Client.SubscriptionId.Length < 1) { throw new ValidationException(ValidationRules.MinLength, "Client.SubscriptionId", 1); } } string tableServiceName = "default"; TableServiceProperties parameters = new TableServiceProperties(); if (cors != null) { parameters.Cors = cors; } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("resourceGroupName", resourceGroupName); tracingParameters.Add("accountName", accountName); tracingParameters.Add("tableServiceName", tableServiceName); tracingParameters.Add("parameters", parameters); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "SetServiceProperties", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/tableServices/{tableServiceName}").ToString(); _url = _url.Replace("{resourceGroupName}", System.Uri.EscapeDataString(resourceGroupName)); _url = _url.Replace("{accountName}", System.Uri.EscapeDataString(accountName)); _url = _url.Replace("{subscriptionId}", System.Uri.EscapeDataString(Client.SubscriptionId)); _url = _url.Replace("{tableServiceName}", System.Uri.EscapeDataString(tableServiceName)); List <string> _queryParameters = new List <string>(); if (Client.ApiVersion != null) { _queryParameters.Add(string.Format("api-version={0}", System.Uri.EscapeDataString(Client.ApiVersion))); } if (_queryParameters.Count > 0) { _url += (_url.Contains("?") ? "&" : "?") + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (Client.GenerateClientRequestId != null && Client.GenerateClientRequestId.Value) { _httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", System.Guid.NewGuid().ToString()); } if (Client.AcceptLanguage != null) { if (_httpRequest.Headers.Contains("accept-language")) { _httpRequest.Headers.Remove("accept-language"); } _httpRequest.Headers.TryAddWithoutValidation("accept-language", Client.AcceptLanguage); } if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (parameters != null) { _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(parameters, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Set Credentials if (Client.Credentials != null) { cancellationToken.ThrowIfCancellationRequested(); await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new CloudException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); try { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); CloudError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject <CloudError>(_responseContent, Client.DeserializationSettings); if (_errorBody != null) { ex = new CloudException(_errorBody.Message); ex.Body = _errorBody; } } catch (JsonException) { // Ignore the exception } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_httpResponse.Headers.Contains("x-ms-request-id")) { ex.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new AzureOperationResponse <TableServiceProperties>(); _result.Request = _httpRequest; _result.Response = _httpResponse; if (_httpResponse.Headers.Contains("x-ms-request-id")) { _result.RequestId = _httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault(); } // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject <TableServiceProperties>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public void FileServiceCorsTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(context, handler); var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler); // Create resource group var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient); // Create storage account string accountName = TestUtilities.GenerateName("sto"); var parameters = StorageManagementTestUtilities.GetDefaultStorageAccountParameters(); var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters); StorageManagementTestUtilities.VerifyAccountProperties(account, true); // implement case try { FileServiceProperties properties1 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName); Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count); CorsRules cors = new CorsRules(); cors.CorsRulesProperty = new List <CorsRule>(); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" }, AllowedMethods = new string[] { "GET", "HEAD", "POST", "OPTIONS", "MERGE", "PUT" }, AllowedOrigins = new string[] { "http://www.contoso.com", "http://www.fabrikam.com" }, ExposedHeaders = new string[] { "x-ms-meta-*" }, MaxAgeInSeconds = 100 }); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "*" }, AllowedMethods = new string[] { "GET" }, AllowedOrigins = new string[] { "*" }, ExposedHeaders = new string[] { "*" }, MaxAgeInSeconds = 2 }); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "x-ms-meta-12345675754564*" }, AllowedMethods = new string[] { "GET", "PUT", "CONNECT" }, AllowedOrigins = new string[] { "http://www.abc23.com", "https://www.fabrikam.com/*" }, ExposedHeaders = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x -ms-meta-target*" }, MaxAgeInSeconds = 2000 }); FileServiceProperties properties3 = storageMgmtClient.FileServices.SetServiceProperties(rgName, accountName, new FileServiceProperties(cors: cors)); //Validate CORS Rules Assert.Equal(cors.CorsRulesProperty.Count, properties3.Cors.CorsRulesProperty.Count); for (int i = 0; i < cors.CorsRulesProperty.Count; i++) { CorsRule putRule = cors.CorsRulesProperty[i]; CorsRule getRule = properties3.Cors.CorsRulesProperty[i]; Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders); Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods); Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins); Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders); Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds); } FileServiceProperties properties4 = storageMgmtClient.FileServices.GetServiceProperties(rgName, accountName); //Validate CORS Rules Assert.Equal(cors.CorsRulesProperty.Count, properties4.Cors.CorsRulesProperty.Count); for (int i = 0; i < cors.CorsRulesProperty.Count; i++) { CorsRule putRule = cors.CorsRulesProperty[i]; CorsRule getRule = properties4.Cors.CorsRulesProperty[i]; Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders); Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods); Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins); Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders); Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds); } } finally { // clean up storageMgmtClient.StorageAccounts.Delete(rgName, accountName); resourcesClient.ResourceGroups.Delete(rgName); } } }
internal QueueServiceData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, CorsRules cors) : base(id, name, type, systemData) { Cors = cors; }
internal static FileServiceData DeserializeFileServiceData(JsonElement element) { Optional <Sku> sku = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; Optional <CorsRules> cors = default; Optional <DeleteRetentionPolicy> shareDeleteRetentionPolicy = default; Optional <ProtocolSettings> protocolSettings = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("sku")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sku = Sku.DeserializeSku(property.Value); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("cors")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cors = CorsRules.DeserializeCorsRules(property0.Value); continue; } if (property0.NameEquals("shareDeleteRetentionPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } shareDeleteRetentionPolicy = DeleteRetentionPolicy.DeserializeDeleteRetentionPolicy(property0.Value); continue; } if (property0.NameEquals("protocolSettings")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } protocolSettings = ProtocolSettings.DeserializeProtocolSettings(property0.Value); continue; } } continue; } } return(new FileServiceData(id, name, type, sku.Value, cors.Value, shareDeleteRetentionPolicy.Value, protocolSettings.Value)); }
internal FileServiceProperties(string id, string name, string type, Sku sku, CorsRules cors, DeleteRetentionPolicy shareDeleteRetentionPolicy) : base(id, name, type) { Sku = sku; Cors = cors; ShareDeleteRetentionPolicy = shareDeleteRetentionPolicy; }
/// <summary> /// Sets the properties of file services in storage accounts, including CORS /// (Cross-Origin Resource Sharing) rules. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. The name is /// case insensitive. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and use /// numbers and lower-case letters only. /// </param> /// <param name='cors'> /// Specifies CORS rules for the File service. You can include up to five /// CorsRule elements in the request. If no CorsRule elements are included in /// the request body, all CORS rules will be deleted, and CORS will be disabled /// for the File service. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <FileServiceProperties> SetServicePropertiesAsync(this IFileServicesOperations operations, string resourceGroupName, string accountName, CorsRules cors = default(CorsRules), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.SetServicePropertiesWithHttpMessagesAsync(resourceGroupName, accountName, cors, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Sets the properties of file services in storage accounts, including CORS /// (Cross-Origin Resource Sharing) rules. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group within the user's subscription. The name is /// case insensitive. /// </param> /// <param name='accountName'> /// The name of the storage account within the specified resource group. /// Storage account names must be between 3 and 24 characters in length and use /// numbers and lower-case letters only. /// </param> /// <param name='cors'> /// Specifies CORS rules for the File service. You can include up to five /// CorsRule elements in the request. If no CorsRule elements are included in /// the request body, all CORS rules will be deleted, and CORS will be disabled /// for the File service. /// </param> public static FileServiceProperties SetServiceProperties(this IFileServicesOperations operations, string resourceGroupName, string accountName, CorsRules cors = default(CorsRules)) { return(operations.SetServicePropertiesAsync(resourceGroupName, accountName, cors).GetAwaiter().GetResult()); }
public void CorsRuleEquatable() { var rule1 = new CorsRule( "downloadFromAnyOrigin", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, }; var rule2 = new CorsRule( "downloadFromAnyOrigin", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, }; Assert.True(rule1.Equals(rule2)); Assert.Equal(rule1.GetHashCode(), rule2.GetHashCode()); Assert.True(rule1 == rule2); Assert.False(rule1 != rule2); var rule3 = new CorsRules { new CorsRule( "downloadFromAnyOrigin", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3600) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } }; var rule4 = new CorsRules { new CorsRule( "downloadFromAnyOrigin", new List <string> { "https" }, new List <string> { "b2_download_file_by_id", "b2_download_file_by_name" }, 3601) { AllowedHeaders = new List <string> { "range" }, ExposeHeaders = new List <string> { "x-bz-content-sha1" }, } }; Assert.False(rule3.Equals(rule4)); Assert.NotEqual(rule3.GetHashCode(), rule4.GetHashCode()); }
internal static BlobServiceData DeserializeBlobServiceData(JsonElement element) { Optional <Sku> sku = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; Optional <CorsRules> cors = default; Optional <string> defaultServiceVersion = default; Optional <DeleteRetentionPolicy> deleteRetentionPolicy = default; Optional <bool> isVersioningEnabled = default; Optional <bool> automaticSnapshotPolicyEnabled = default; Optional <ChangeFeed> changeFeed = default; Optional <RestorePolicyProperties> restorePolicy = default; Optional <DeleteRetentionPolicy> containerDeleteRetentionPolicy = default; Optional <LastAccessTimeTrackingPolicy> lastAccessTimeTrackingPolicy = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("sku")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sku = Sku.DeserializeSku(property.Value); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = property.Value.GetString(); continue; } if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } foreach (var property0 in property.Value.EnumerateObject()) { if (property0.NameEquals("cors")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } cors = CorsRules.DeserializeCorsRules(property0.Value); continue; } if (property0.NameEquals("defaultServiceVersion")) { defaultServiceVersion = property0.Value.GetString(); continue; } if (property0.NameEquals("deleteRetentionPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } deleteRetentionPolicy = DeleteRetentionPolicy.DeserializeDeleteRetentionPolicy(property0.Value); continue; } if (property0.NameEquals("isVersioningEnabled")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } isVersioningEnabled = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("automaticSnapshotPolicyEnabled")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } automaticSnapshotPolicyEnabled = property0.Value.GetBoolean(); continue; } if (property0.NameEquals("changeFeed")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } changeFeed = ChangeFeed.DeserializeChangeFeed(property0.Value); continue; } if (property0.NameEquals("restorePolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } restorePolicy = RestorePolicyProperties.DeserializeRestorePolicyProperties(property0.Value); continue; } if (property0.NameEquals("containerDeleteRetentionPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } containerDeleteRetentionPolicy = DeleteRetentionPolicy.DeserializeDeleteRetentionPolicy(property0.Value); continue; } if (property0.NameEquals("lastAccessTimeTrackingPolicy")) { if (property0.Value.ValueKind == JsonValueKind.Null) { property0.ThrowNonNullablePropertyIsNull(); continue; } lastAccessTimeTrackingPolicy = LastAccessTimeTrackingPolicy.DeserializeLastAccessTimeTrackingPolicy(property0.Value); continue; } } continue; } } return(new BlobServiceData(id, name, type, sku.Value, cors.Value, defaultServiceVersion.Value, deleteRetentionPolicy.Value, Optional.ToNullable(isVersioningEnabled), Optional.ToNullable(automaticSnapshotPolicyEnabled), changeFeed.Value, restorePolicy.Value, containerDeleteRetentionPolicy.Value, lastAccessTimeTrackingPolicy.Value)); }
internal TableServiceProperties(string id, string name, string type, CorsRules cors) : base(id, name, type) { Cors = cors; }
internal TableServiceData(ResourceIdentifier id, string name, ResourceType type, CorsRules cors) : base(id, name, type) { Cors = cors; }
public void TableServiceCorsTest() { var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK }; using (MockContext context = MockContext.Start(this.GetType().FullName)) { var resourcesClient = StorageManagementTestUtilities.GetResourceManagementClient(context, handler); var storageMgmtClient = StorageManagementTestUtilities.GetStorageManagementClient(context, handler); // Create resource group var rgName = StorageManagementTestUtilities.CreateResourceGroup(resourcesClient); // Create storage account string accountName = TestUtilities.GenerateName("sto"); var parameters = new StorageAccountCreateParameters { Location = "eastus2euap", Kind = Kind.StorageV2, Sku = new Sku { Name = SkuName.StandardLRS } }; var account = storageMgmtClient.StorageAccounts.Create(rgName, accountName, parameters); // implement case try { TableServiceProperties properties1 = storageMgmtClient.TableServices.GetServiceProperties(rgName, accountName); Assert.Equal(0, properties1.Cors.CorsRulesProperty.Count); CorsRules cors = new CorsRules(); cors.CorsRulesProperty = new List <CorsRule>(); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x-ms-meta-target*" }, AllowedMethods = new string[] { "GET", "HEAD", "POST", "OPTIONS", "MERGE", "PUT" }, AllowedOrigins = new string[] { "http://www.contoso.com", "http://www.fabrikam.com" }, ExposedHeaders = new string[] { "x-ms-meta-*" }, MaxAgeInSeconds = 100 }); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "*" }, AllowedMethods = new string[] { "GET" }, AllowedOrigins = new string[] { "*" }, ExposedHeaders = new string[] { "*" }, MaxAgeInSeconds = 2 }); cors.CorsRulesProperty.Add(new CorsRule() { AllowedHeaders = new string[] { "x-ms-meta-12345675754564*" }, AllowedMethods = new string[] { "GET", "PUT", "CONNECT" }, AllowedOrigins = new string[] { "http://www.abc23.com", "https://www.fabrikam.com/*" }, ExposedHeaders = new string[] { "x-ms-meta-abc", "x-ms-meta-data*", "x -ms-meta-target*" }, MaxAgeInSeconds = 2000 }); TableServiceProperties properties3 = storageMgmtClient.TableServices.SetServiceProperties(rgName, accountName, cors); //Validate CORS Rules if (HttpMockServer.Mode == HttpRecorderMode.Record) { // Need wait for cors rules setting take effect when record case System.Threading.Thread.Sleep(30000); } Assert.Equal(cors.CorsRulesProperty.Count, properties3.Cors.CorsRulesProperty.Count); for (int i = 0; i < cors.CorsRulesProperty.Count; i++) { CorsRule putRule = cors.CorsRulesProperty[i]; CorsRule getRule = properties3.Cors.CorsRulesProperty[i]; Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders); Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods); Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins); Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders); Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds); } TableServiceProperties properties4 = storageMgmtClient.TableServices.GetServiceProperties(rgName, accountName); //Validate CORS Rules Assert.Equal(cors.CorsRulesProperty.Count, properties4.Cors.CorsRulesProperty.Count); for (int i = 0; i < cors.CorsRulesProperty.Count; i++) { CorsRule putRule = cors.CorsRulesProperty[i]; CorsRule getRule = properties4.Cors.CorsRulesProperty[i]; Assert.Equal(putRule.AllowedHeaders, getRule.AllowedHeaders); Assert.Equal(putRule.AllowedMethods, getRule.AllowedMethods); Assert.Equal(putRule.AllowedOrigins, getRule.AllowedOrigins); Assert.Equal(putRule.ExposedHeaders, getRule.ExposedHeaders); Assert.Equal(putRule.MaxAgeInSeconds, getRule.MaxAgeInSeconds); } } finally { // clean up storageMgmtClient.StorageAccounts.Delete(rgName, accountName); resourcesClient.ResourceGroups.Delete(rgName); } } }
public virtual async Task <Response <FileServiceProperties> > SetServicePropertiesAsync(string resourceGroupName, string accountName, CorsRules cors = null, DeleteRetentionPolicy shareDeleteRetentionPolicy = null, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("FileServicesClient.SetServiceProperties"); scope.Start(); try { return(await RestClient.SetServicePropertiesAsync(resourceGroupName, accountName, cors, shareDeleteRetentionPolicy, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }