Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
CORS support
Browse files Browse the repository at this point in the history
  • Loading branch information
katmsft committed Apr 1, 2017
1 parent d674f3e commit 58af25f
Show file tree
Hide file tree
Showing 19 changed files with 741 additions and 114 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ ALL
- `MicrosoftAzure\Storage\Common\Internal\IMiddleware` was moved to `MicrosoftAzure\Storage\Common\Middlewares\IMiddleware`
- `MicrosoftAzure\Storage\Common\Internal\Middlewares\MiddlewareBase` was moved to `MicrosoftAzure\Storage\Common\Middlewares\MiddlewareBase`
- `MicrosoftAzure\Storage\Common\Internal\RetryMiddlewareFactory` was moved to `MicrosoftAzure\Storage\Common\Middlewares\RetryMiddlewareFactory`
* Added Cross-Origin Resource Sharing (CORS) support. Now setting service properties can set CORS rules at the same time.

Blob
* Added API `createPageBlobFromContent` to support creating page blob directly from contents which includes local file, stream, etc...
Expand Down
189 changes: 100 additions & 89 deletions src/Common/Internal/Resources.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Resources
const BATCH_ENTITY_DEL_MSG = 'The entity was deleted successfully.';
const INVALID_PROP_VAL_MSG = "'%s' property value must satisfy %s.";
const INVALID_PARAM_MSG = "The provided variable '%s' should be of type '%s'";
const INVALID_VALUE_MSG = "The provided variable '%s' has unexpected value. Reason: '%s'";
const INVALID_STRING_LENGTH = "The provided variable '%s' should be of %s characters long";
const INVALID_BTE_MSG = "The blob block type must exist in %s";
const INVALID_BLOB_PAT_MSG = 'The provided access type is invalid.';
Expand Down Expand Up @@ -130,7 +131,8 @@ class Resources
const ERROR_TOO_MANY_SIGNED_IDENTIFIERS = 'There can be at most 5 signed identifiers at the same time.';
const INVALID_PERMISSION_PROVIDED = 'Invalid permission provided, the permission of resource type \'%s\' can only be of \'%s\'';
const INVALID_RESOURCE_TYPE = 'Provided resource type is invalid.';

const ERROR_KEY_NOT_EXIST = "The key '%s' does not exist in the given array.";

// HTTP Headers
const X_MS_HEADER_PREFIX = 'x-ms-';
const X_MS_META_HEADER_PREFIX = 'x-ms-meta-';
Expand Down Expand Up @@ -313,97 +315,106 @@ class Resources
const MULTIPART_MIXED_TYPE = 'multipart/mixed';

// Common used XML tags
const XTAG_ATTRIBUTES = '@attributes';
const XTAG_NAMESPACE = '@namespace';
const XTAG_LABEL = 'Label';
const XTAG_NAME = 'Name';
const XTAG_DESCRIPTION = 'Description';
const XTAG_LOCATION = 'Location';
const XTAG_AFFINITY_GROUP = 'AffinityGroup';
const XTAG_HOSTED_SERVICES = 'HostedServices';
const XTAG_STORAGE_SERVICES = 'StorageServices';
const XTAG_STORAGE_SERVICE = 'StorageService';
const XTAG_DISPLAY_NAME = 'DisplayName';
const XTAG_SERVICE_NAME = 'ServiceName';
const XTAG_URL = 'Url';
const XTAG_ID = 'ID';
const XTAG_STATUS = 'Status';
const XTAG_HTTP_STATUS_CODE = 'HttpStatusCode';
const XTAG_CODE = 'Code';
const XTAG_MESSAGE = 'Message';
const XTAG_STORAGE_SERVICE_PROPERTIES = 'StorageServiceProperties';
const XTAG_SERVICE_ENDPOINT = 'ServiceEndpoint';
const XTAG_ENDPOINT = 'Endpoint';
const XTAG_ENDPOINTS = 'Endpoints';
const XTAG_PRIMARY = 'Primary';
const XTAG_SECONDARY = 'Secondary';
const XTAG_KEY_TYPE = 'KeyType';
const XTAG_STORAGE_SERVICE_KEYS = 'StorageServiceKeys';
const XTAG_ERROR = 'Error';
const XTAG_HOSTED_SERVICE = 'HostedService';
const XTAG_HOSTED_SERVICE_PROPERTIES = 'HostedServiceProperties';
const XTAG_CREATE_HOSTED_SERVICE = 'CreateHostedService';
const XTAG_ATTRIBUTES = '@attributes';
const XTAG_NAMESPACE = '@namespace';
const XTAG_LABEL = 'Label';
const XTAG_NAME = 'Name';
const XTAG_DESCRIPTION = 'Description';
const XTAG_LOCATION = 'Location';
const XTAG_AFFINITY_GROUP = 'AffinityGroup';
const XTAG_HOSTED_SERVICES = 'HostedServices';
const XTAG_STORAGE_SERVICES = 'StorageServices';
const XTAG_STORAGE_SERVICE = 'StorageService';
const XTAG_DISPLAY_NAME = 'DisplayName';
const XTAG_SERVICE_NAME = 'ServiceName';
const XTAG_URL = 'Url';
const XTAG_ID = 'ID';
const XTAG_STATUS = 'Status';
const XTAG_HTTP_STATUS_CODE = 'HttpStatusCode';
const XTAG_CODE = 'Code';
const XTAG_MESSAGE = 'Message';
const XTAG_STORAGE_SERVICE_PROPERTIES = 'StorageServiceProperties';
const XTAG_SERVICE_ENDPOINT = 'ServiceEndpoint';
const XTAG_ENDPOINT = 'Endpoint';
const XTAG_ENDPOINTS = 'Endpoints';
const XTAG_PRIMARY = 'Primary';
const XTAG_SECONDARY = 'Secondary';
const XTAG_KEY_TYPE = 'KeyType';
const XTAG_STORAGE_SERVICE_KEYS = 'StorageServiceKeys';
const XTAG_ERROR = 'Error';
const XTAG_HOSTED_SERVICE = 'HostedService';
const XTAG_HOSTED_SERVICE_PROPERTIES = 'HostedServiceProperties';
const XTAG_CREATE_HOSTED_SERVICE = 'CreateHostedService';
const XTAG_CREATE_STORAGE_SERVICE_INPUT = 'CreateStorageServiceInput';
const XTAG_UPDATE_STORAGE_SERVICE_INPUT = 'UpdateStorageServiceInput';
const XTAG_CREATE_AFFINITY_GROUP = 'CreateAffinityGroup';
const XTAG_UPDATE_AFFINITY_GROUP = 'UpdateAffinityGroup';
const XTAG_UPDATE_HOSTED_SERVICE = 'UpdateHostedService';
const XTAG_PACKAGE_URL = 'PackageUrl';
const XTAG_CONFIGURATION = 'Configuration';
const XTAG_START_DEPLOYMENT = 'StartDeployment';
const XTAG_TREAT_WARNINGS_AS_ERROR = 'TreatWarningsAsError';
const XTAG_CREATE_DEPLOYMENT = 'CreateDeployment';
const XTAG_DEPLOYMENT_SLOT = 'DeploymentSlot';
const XTAG_PRIVATE_ID = 'PrivateID';
const XTAG_ROLE_INSTANCE_LIST = 'RoleInstanceList';
const XTAG_UPGRADE_DOMAIN_COUNT = 'UpgradeDomainCount';
const XTAG_ROLE_LIST = 'RoleList';
const XTAG_SDK_VERSION = 'SdkVersion';
const XTAG_INPUT_ENDPOINT_LIST = 'InputEndpointList';
const XTAG_LOCKED = 'Locked';
const XTAG_ROLLBACK_ALLOWED = 'RollbackAllowed';
const XTAG_UPGRADE_STATUS = 'UpgradeStatus';
const XTAG_UPGRADE_TYPE = 'UpgradeType';
const XTAG_CREATE_AFFINITY_GROUP = 'CreateAffinityGroup';
const XTAG_UPDATE_AFFINITY_GROUP = 'UpdateAffinityGroup';
const XTAG_UPDATE_HOSTED_SERVICE = 'UpdateHostedService';
const XTAG_PACKAGE_URL = 'PackageUrl';
const XTAG_CONFIGURATION = 'Configuration';
const XTAG_START_DEPLOYMENT = 'StartDeployment';
const XTAG_TREAT_WARNINGS_AS_ERROR = 'TreatWarningsAsError';
const XTAG_CREATE_DEPLOYMENT = 'CreateDeployment';
const XTAG_DEPLOYMENT_SLOT = 'DeploymentSlot';
const XTAG_PRIVATE_ID = 'PrivateID';
const XTAG_ROLE_INSTANCE_LIST = 'RoleInstanceList';
const XTAG_UPGRADE_DOMAIN_COUNT = 'UpgradeDomainCount';
const XTAG_ROLE_LIST = 'RoleList';
const XTAG_SDK_VERSION = 'SdkVersion';
const XTAG_INPUT_ENDPOINT_LIST = 'InputEndpointList';
const XTAG_LOCKED = 'Locked';
const XTAG_ROLLBACK_ALLOWED = 'RollbackAllowed';
const XTAG_UPGRADE_STATUS = 'UpgradeStatus';
const XTAG_UPGRADE_TYPE = 'UpgradeType';
const XTAG_CURRENT_UPGRADE_DOMAIN_STATE = 'CurrentUpgradeDomainState';
const XTAG_CURRENT_UPGRADE_DOMAIN = 'CurrentUpgradeDomain';
const XTAG_ROLE_NAME = 'RoleName';
const XTAG_INSTANCE_NAME = 'InstanceName';
const XTAG_INSTANCE_STATUS = 'InstanceStatus';
const XTAG_INSTANCE_UPGRADE_DOMAIN = 'InstanceUpgradeDomain';
const XTAG_INSTANCE_FAULT_DOMAIN = 'InstanceFaultDomain';
const XTAG_INSTANCE_SIZE = 'InstanceSize';
const XTAG_INSTANCE_STATE_DETAILS = 'InstanceStateDetails';
const XTAG_INSTANCE_ERROR_CODE = 'InstanceErrorCode';
const XTAG_OS_VERSION = 'OsVersion';
const XTAG_ROLE_INSTANCE = 'RoleInstance';
const XTAG_ROLE = 'Role';
const XTAG_INPUT_ENDPOINT = 'InputEndpoint';
const XTAG_VIP = 'Vip';
const XTAG_PORT = 'Port';
const XTAG_DEPLOYMENT = 'Deployment';
const XTAG_DEPLOYMENTS = 'Deployments';
const XTAG_REGENERATE_KEYS = 'RegenerateKeys';
const XTAG_SWAP = 'Swap';
const XTAG_PRODUCTION = 'Production';
const XTAG_SOURCE_DEPLOYMENT = 'SourceDeployment';
const XTAG_CHANGE_CONFIGURATION = 'ChangeConfiguration';
const XTAG_MODE = 'Mode';
const XTAG_UPDATE_DEPLOYMENT_STATUS = 'UpdateDeploymentStatus';
const XTAG_ROLE_TO_UPGRADE = 'RoleToUpgrade';
const XTAG_FORCE = 'Force';
const XTAG_UPGRADE_DEPLOYMENT = 'UpgradeDeployment';
const XTAG_UPGRADE_DOMAIN = 'UpgradeDomain';
const XTAG_WALK_UPGRADE_DOMAIN = 'WalkUpgradeDomain';
const XTAG_ROLLBACK_UPDATE_OR_UPGRADE = 'RollbackUpdateOrUpgrade';
const XTAG_CONTAINER_NAME = 'ContainerName';
const XTAG_ACCOUNT_NAME = 'AccountName';
const XTAG_SIGNED_IDENTIFIERS = 'SignedIdentifiers';
const XTAG_SIGNED_IDENTIFIER = 'SignedIdentifier';
const XTAG_ACCESS_POLICY = 'AccessPolicy';
const XTAG_SIGNED_START = 'Start';
const XTAG_SIGNED_EXPIRY = 'Expiry';
const XTAG_SIGNED_PERMISSION = 'Permission';
const XTAG_SIGNED_ID = 'Id';
const XTAG_CURRENT_UPGRADE_DOMAIN = 'CurrentUpgradeDomain';
const XTAG_ROLE_NAME = 'RoleName';
const XTAG_INSTANCE_NAME = 'InstanceName';
const XTAG_INSTANCE_STATUS = 'InstanceStatus';
const XTAG_INSTANCE_UPGRADE_DOMAIN = 'InstanceUpgradeDomain';
const XTAG_INSTANCE_FAULT_DOMAIN = 'InstanceFaultDomain';
const XTAG_INSTANCE_SIZE = 'InstanceSize';
const XTAG_INSTANCE_STATE_DETAILS = 'InstanceStateDetails';
const XTAG_INSTANCE_ERROR_CODE = 'InstanceErrorCode';
const XTAG_OS_VERSION = 'OsVersion';
const XTAG_ROLE_INSTANCE = 'RoleInstance';
const XTAG_ROLE = 'Role';
const XTAG_INPUT_ENDPOINT = 'InputEndpoint';
const XTAG_VIP = 'Vip';
const XTAG_PORT = 'Port';
const XTAG_DEPLOYMENT = 'Deployment';
const XTAG_DEPLOYMENTS = 'Deployments';
const XTAG_REGENERATE_KEYS = 'RegenerateKeys';
const XTAG_SWAP = 'Swap';
const XTAG_PRODUCTION = 'Production';
const XTAG_SOURCE_DEPLOYMENT = 'SourceDeployment';
const XTAG_CHANGE_CONFIGURATION = 'ChangeConfiguration';
const XTAG_MODE = 'Mode';
const XTAG_UPDATE_DEPLOYMENT_STATUS = 'UpdateDeploymentStatus';
const XTAG_ROLE_TO_UPGRADE = 'RoleToUpgrade';
const XTAG_FORCE = 'Force';
const XTAG_UPGRADE_DEPLOYMENT = 'UpgradeDeployment';
const XTAG_UPGRADE_DOMAIN = 'UpgradeDomain';
const XTAG_WALK_UPGRADE_DOMAIN = 'WalkUpgradeDomain';
const XTAG_ROLLBACK_UPDATE_OR_UPGRADE = 'RollbackUpdateOrUpgrade';
const XTAG_CONTAINER_NAME = 'ContainerName';
const XTAG_ACCOUNT_NAME = 'AccountName';
const XTAG_LOGGING = 'Logging';
const XTAG_HOUR_METRICS = 'HourMetrics';
const XTAG_CORS = 'Cors';
const XTAG_CORS_RULE = 'CorsRule';
const XTAG_ALLOWED_ORIGINS = 'AllowedOrigins';
const XTAG_ALLOWED_METHODS = 'AllowedMethods';
const XTAG_ALLOWED_HEADERS = 'AllowedHeaders';
const XTAG_EXPOSED_HEADERS = 'ExposedHeaders';
const XTAG_MAX_AGE_IN_SECONDS = 'MaxAgeInSeconds';
const XTAG_SIGNED_IDENTIFIERS = 'SignedIdentifiers';
const XTAG_SIGNED_IDENTIFIER = 'SignedIdentifier';
const XTAG_ACCESS_POLICY = 'AccessPolicy';
const XTAG_SIGNED_START = 'Start';
const XTAG_SIGNED_EXPIRY = 'Expiry';
const XTAG_SIGNED_PERMISSION = 'Permission';
const XTAG_SIGNED_ID = 'Id';

// PHP URL Keys
const PHP_URL_SCHEME = 'scheme';
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Internal/RestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(Serialization\ISerializer $dataSerializer = null, $u
$this->dataSerializer = $dataSerializer;
$this->_uri = $uri;
//For logging the request and responses.
//$this->middlewares[] = new HistoryMiddleware('.\\messages.log');
// $this->middlewares[] = new HistoryMiddleware('.\\messages.log');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Common/Internal/ServiceRestProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getAccountName()
}

/**
* Static helper function to create a usable client for the proxy.
* Helper function to create a usable client for the proxy.
* The requestOptions can contain the following keys that will affect
* the way retry handler is created and applied.
* handler: HandlerStack, if set, this function will not
Expand All @@ -113,6 +113,7 @@ protected function createClient(array $requestOptions)

return (new \GuzzleHttp\Client(
array_merge(
$requestOptions,
$this->_options['http'],
array(
"defaults" => array(
Expand All @@ -124,8 +125,7 @@ protected function createClient(array $requestOptions)
'verify' => true,
// For testing with Fiddler
//'proxy' => "localhost:8888",
),
$requestOptions
)
)
));
}
Expand Down
1 change: 1 addition & 0 deletions src/Common/Internal/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ public static function validateMetadata(array $metadata = null)
* Append the content to file.
* @param string $path The file to append to.
* @param string $content The content to append.
*
* @return void
*/
public static function appendToFile($path, $content)
Expand Down
29 changes: 29 additions & 0 deletions src/Common/Internal/Validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,33 @@ public static function isDateString($value, $name)
);
}
}

/**
* Validate if the provided array has key, throw exception otherwise.
*
* @param string $key The key to be searched.
* @param string $name The name of the array.
* @param array $array The array to be validated.
*
* @throws \UnexpectedValueException
* @throws \InvalidArgumentException
*
* @return boolean
*/
public static function hasKey($key, $name, array $array)
{
Validate::isArray($array, $name);

if (!array_key_exists($key, $array)) {
throw new \UnexpectedValueException(
sprintf(
Resources::INVALID_VALUE_MSG,
$name,
sprintf(Resources::ERROR_KEY_NOT_EXIST, $key)
)
);
}

return true;
}
}
Loading

0 comments on commit 58af25f

Please sign in to comment.