CorsRule Class

CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. Web browsers implement a security restriction known as same-origin policy that prevents a web page from calling APIs in a different domain; CORS provides a secure way to allow one domain (the origin domain) to call APIs in another domain.

All required parameters must be populated in order to send to Azure.

Constructor

CorsRule(allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any)

Parameters

Name Description
allowed_origins
Required

A list of origin domains that will be allowed via CORS, or "*" to allow all domains. The list must contain at least one entry. Limited to 64 origin domains. Each allowed origin can have up to 256 characters.

allowed_methods
Required

A list of HTTP methods that are allowed to be executed by the origin. The list must contain at least one entry. For Azure Storage, permitted methods are DELETE, GET, HEAD, MERGE, POST, OPTIONS or PUT.

Keyword-Only Parameters

Name Description
max_age_in_seconds
int

The number of seconds that the client/browser should cache a pre-flight response.

exposed_headers

Defaults to an empty list. A list of response headers to expose to CORS clients. Limited to 64 defined headers and two prefixed headers. Each header can be up to 256 characters.

allowed_headers

Defaults to an empty list. A list of headers allowed to be part of the cross-origin request. Limited to 64 defined headers and 2 prefixed headers. Each header can be up to 256 characters.

Methods

as_dict

Return a dict that can be serialized using json.dump.

deserialize

Deserialize this model from a dictionary.

enable_additional_properties_sending

Add additional_properties to the attribute map so they are sent to the service.

from_dict

Parse a dict using a given key extractor and return a model.

is_xml_model

Whether this model is serialized as XML.

serialize

Serialize this model to a dictionary.

as_dict

Return a dict that can be serialized using json.dump.

as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, dict[str, typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) -> MutableMapping[str, Any]

Parameters

Name Description
keep_readonly

If you want to serialize the readonly attributes.

Default value: True
key_transformer

A function that takes an attribute name, the attribute map, and the value, and returns the key to use in the output dict.

Returns

Type Description
<xref:JSON>

A dict JSON compatible object.

deserialize

Deserialize this model from a dictionary.

deserialize(data: Any, content_type: str | None = None) -> Self

Parameters

Name Description
data
Required
str

A str using RestAPI structure. JSON by default.

content_type
str

JSON by default, set application/xml if XML.

Default value: None

Returns

Type Description

An instance of this model.

enable_additional_properties_sending

Add additional_properties to the attribute map so they are sent to the service.

enable_additional_properties_sending() -> None

Returns

Type Description

None

from_dict

Parse a dict using a given key extractor and return a model.

from_dict(data: Any, key_extractors: Callable[[str, dict[str, Any], Any], Any] | None = None, content_type: str | None = None) -> Self

Parameters

Name Description
data
Required

A dict using RestAPI structure.

key_extractors

A key extractor function.

Default value: None
content_type
str

JSON by default, set application/xml if XML.

Default value: None

Returns

Type Description

An instance of this model.

is_xml_model

Whether this model is serialized as XML.

is_xml_model() -> bool

Returns

Type Description

True if this model is serialized as XML, otherwise False.

serialize

Serialize this model to a dictionary.

serialize(keep_readonly: bool = False, **kwargs: Any) -> MutableMapping[str, Any]

Parameters

Name Description
keep_readonly

If you want to serialize the readonly attributes.

Default value: False

Returns

Type Description
<xref:JSON>

A dict JSON compatible object.

Attributes

allowed_headers

The comma-delimited string representation of the list of headers allowed to be part of the cross-origin request.

allowed_headers: str

allowed_methods

The comma-delimited string representation of the list of HTTP methods that are allowed to be executed by the origin.

allowed_methods: str

allowed_origins

The comma-delimited string representation of the list of origin domains that will be allowed via CORS, or "*" to allow all domains.

allowed_origins: str

exposed_headers

The comma-delimited string representation of the list of response headers to expose to CORS clients.

exposed_headers: str

max_age_in_seconds

The number of seconds that the client/browser should cache a pre-flight response.

max_age_in_seconds: int