Added support for static website service properties

This commit is contained in:
Xiaoning Liu 2018-05-09 18:15:26 +08:00
Родитель 1e024e7294
Коммит c5d88a0f4a
7 изменённых файлов: 179 добавлений и 7 удалений

Просмотреть файл

@ -3,11 +3,15 @@ be taken. This is a GA release and the changes described below indicate the chan
2018.06 Version 2.10.0
ALL
* Updated storage service version to 2018-03-28.
BLOB
* Fixed a bug that `DeleteRetentionPolicy.Days` should be `number` instead of `string` when calling `getServiceProperties`.
* Added method `getAccountProperties` on `blobService`.
* Added support for synchronous copy of block blobs and put block from URL.
* Added a method `createBlockFromURL` for `blobService`.
* Added support for static website service properties.
2018.05 Version 2.9.0-preview

Просмотреть файл

@ -319,6 +319,26 @@ exports.generateAccountSharedAccessSignature = function(storageAccountOrConnecti
* @typedef {object} AccountProperties
* @property {string} SkuName The header that specifies storage SKU, also known as account type.
* @property {string} AccountKind The header that describes the flavour of the storage account, also known as account kind.
* The properties of a blob storage service, including properties of Storage Analytics, CORS (Cross-Origin Resource Sharing) rules and Static Webiste configurations.
*/
/**
* @typedef {object} BlobServiceProperties
* @property {string} DefaultServiceVersion The default version of Storage Analytics currently in use.
* @property {LoggingProperties} Logging The Logging settings.
* @property {MetricsProperties} HourMetrics The HourMetrics settings provide a summary of request statistics grouped by API in hourly aggregates.
* @property {MetricsProperties} MinuteMetrics The HourMetrics settings provide request statistics grouped by API for each minute.
* @property {StaticWebsiteProperties} StaticWebsite The Azure Static Website settings.
* @property {object} Cors Groups all CORS rules.
* @property {CorsRule[]} Cors.CorsRules Groups settings for a `[CORS rule]{@link CorsRule}`.
*/
/**
* The Azure Static Website settings.
* @typedef {object} StaticWebsiteProperties
* @property {boolean} Enabled Whether feature of Static Website is enabled.
* @property {string} IndexDocument Indicates index document page path.
* @property {string} ErrorDocument404Path Indicates 404 document page path.
*/
/**

Просмотреть файл

@ -84,6 +84,38 @@ function serializeDeleteRetentionPolicy(doc, policy) {
}
}
function serializeStaticWebsite(doc, staticWebsite) {
if (staticWebsite !== null) {
if (typeof staticWebsite === 'undefined') {
staticWebsite = {};
}
if (typeof staticWebsite.Enabled !== 'undefined') {
doc = doc.ele(ServicePropertiesConstants.ENABLED_ELEMENT)
.txt(staticWebsite.Enabled)
.up();
} else {
doc = doc.ele(ServicePropertiesConstants.ENABLED_ELEMENT)
.txt(false)
.up();
}
if (typeof staticWebsite.IndexDocument !== 'undefined') {
doc = doc.ele(ServicePropertiesConstants.DEFAULT_INDEX_DOCUMENT_ELEMENT)
.txt(staticWebsite.IndexDocument)
.up();
}
if (typeof staticWebsite.ErrorDocument404Path !== 'undefined') {
doc = doc.ele(ServicePropertiesConstants.DEFAULT_ERROR_DOCUMENT_404_PATH_ELEMENT)
.txt(staticWebsite.ErrorDocument404Path)
.up();
}
doc = doc.up();
}
}
function serializeLogging(doc, logging) {
if (typeof logging.Version !== 'undefined') {
doc = doc.ele(ServicePropertiesConstants.VERSION_ELEMENT)
@ -257,6 +289,12 @@ exports.serialize = function (servicePropertiesJs) {
doc = doc.up();
}
if (servicePropertiesJs.StaticWebsite) {
doc = doc.ele(ServicePropertiesConstants.DEFAULT_STATIC_WEBSITE_ELEMENT);
serializeStaticWebsite(doc, servicePropertiesJs.StaticWebsite);
doc = doc.up();
}
return doc.doc().toString();
};
@ -396,6 +434,24 @@ function parseDeleteRetentionPolicy(deleteRetentionPolicyXml) {
return deleteRetentionPolicy;
}
function parseStaticWebsite(staticWebsiteXml) {
var staticWebsite = {};
if (typeof staticWebsiteXml.Enabled !== 'undefined') {
staticWebsite.Enabled = staticWebsiteXml.Enabled === 'true';
}
if (typeof staticWebsiteXml.IndexDocument !== 'undefined') {
staticWebsite.IndexDocument = staticWebsiteXml.IndexDocument;
}
if (typeof staticWebsiteXml.ErrorDocument404Path !== 'undefined') {
staticWebsite.ErrorDocument404Path = staticWebsiteXml.ErrorDocument404Path;
}
return staticWebsite;
}
exports.parse = function (servicePropertiesXml) {
var serviceProperties = {};
@ -423,5 +479,9 @@ exports.parse = function (servicePropertiesXml) {
serviceProperties.DeleteRetentionPolicy = parseDeleteRetentionPolicy(servicePropertiesXml.DeleteRetentionPolicy);
}
if (typeof servicePropertiesXml.StaticWebsite !== 'undefined') {
serviceProperties.StaticWebsite = parseStaticWebsite(servicePropertiesXml.StaticWebsite);
}
return serviceProperties;
};

Просмотреть файл

@ -470,7 +470,31 @@ var Constants = {
* @const
* @type {string}
*/
DEFAULT_DELETE_RETENTION_POLICY_ELEMENT: 'DeleteRetentionPolicy'
DEFAULT_DELETE_RETENTION_POLICY_ELEMENT: 'DeleteRetentionPolicy',
/**
* XML element for StaticWebsite.
*
* @const
* @type {string}
*/
DEFAULT_STATIC_WEBSITE_ELEMENT: 'StaticWebsite',
/**
* XML element for StaticWebsite/IndexDocument.
*
* @const
* @type {string}
*/
DEFAULT_INDEX_DOCUMENT_ELEMENT: 'IndexDocument',
/**
* XML element for StaticWebsite/ErrorDocument404Path.
*
* @const
* @type {string}
*/
DEFAULT_ERROR_DOCUMENT_404_PATH_ELEMENT: 'ErrorDocument404Path'
},
/**

Просмотреть файл

@ -210,7 +210,7 @@ BlobService.prototype.getServiceStats = function (optionsOrCallback, callback) {
* @param {string} [options.clientRequestId] A string that represents the client request ID with a 1KB character limit.
* @param {bool} [options.useNagleAlgorithm] Determines whether the Nagle algorithm is used; true to use the Nagle algorithm; otherwise, false.
* The default value is false.
* @param {errorOrResult} callback `error` will contain information if an error occurs; otherwise, `[result]{@link ServiceProperties}` will contain the properties
* @param {errorOrResult} callback `error` will contain information if an error occurs; otherwise, `[result]{@link BlobServiceProperties}` will contain the properties
* and `response` will contain information related to this operation.
*/
BlobService.prototype.getServiceProperties = function (optionsOrCallback, callback) {
@ -277,7 +277,7 @@ BlobService.prototype.getAccountProperties = function (container, blob, optionsO
* When you set blob service properties (such as enabling soft delete), it may take up to 30 seconds to take effect.
*
* @this {BlobService}
* @param {object} serviceProperties The service properties.
* @param {object} serviceProperties A `[BlobServiceProperties]{@link BlobServiceProperties}` object.
* @param {object} [options] The request options.
* @param {LocationMode} [options.locationMode] Specifies the location mode used to decide which location the request should be sent to.
* Please see StorageUtilities.LocationMode for the possible values.

Просмотреть файл

@ -2087,6 +2087,62 @@ describe('BlobService', function () {
done();
});
describe('StaticWebsite', function () {
it('should be able to enable static website', function (done) {
var prop = {
StaticWebsite: {
Enabled: true,
IndexDocument: 'index.htm',
ErrorDocument404Path: 'error/index.htm'
}
};
blobService.setServiceProperties(prop, function (err) {
assert.equal(err, null);
blobService.getServiceProperties(function (err, res) {
assert.equal(res.StaticWebsite.Enabled, true);
assert.equal(res.StaticWebsite.IndexDocument, prop.StaticWebsite.IndexDocument);
assert.equal(res.StaticWebsite.ErrorDocument404Path, prop.StaticWebsite.ErrorDocument404Path);
done();
});
});
});
it('should be able to disable static website', function (done) {
var prop = {
StaticWebsite: {
Enabled: false
}
};
blobService.setServiceProperties(prop, function (err) {
assert.equal(err, null);
blobService.getServiceProperties(function (err, res) {
assert.equal(res.StaticWebsite.Enabled, false);
assert.equal(res.StaticWebsite.IndexDocument, null);
assert.equal(res.StaticWebsite.ErrorDocument404Path, null);
done();
});
});
});
it('should return error when setting properties with static website disabled', function (done) {
var prop = {
StaticWebsite: {
IndexDocument: 'index.htm',
ErrorDocument404Path: 'error/index.htm'
}
};
blobService.setServiceProperties(prop, function (err, res) {
assert.notEqual(err, null);
done();
});
});
});
describe('getAccountProperties', function () {
it('should work without container and blob names', function (done) {
blobService.getAccountProperties(null, null, function (err, res) {

16
typings/azure-storage/azure-storage.d.ts поставляемый
Просмотреть файл

@ -159,8 +159,8 @@ declare module azurestorage {
* @param {errorOrResult} callback `error` will contain information if an error occurs; otherwise, `result` will contain the properties
* and `response` will contain information related to this operation.
*/
getServiceProperties(options: common.RequestOptions, callback?: ErrorOrResult<common.models.ServicePropertiesResult.ServiceProperties>): void;
getServiceProperties(callback?: ErrorOrResult<common.models.ServicePropertiesResult.ServiceProperties>): void;
getServiceProperties(options: common.RequestOptions, callback?: ErrorOrResult<common.models.ServicePropertiesResult.BlobServiceProperties>): void;
getServiceProperties(callback?: ErrorOrResult<common.models.ServicePropertiesResult.BlobServiceProperties>): void;
/**
* Gets the properties of a storage account.
@ -206,8 +206,8 @@ declare module azurestorage {
* if an error occurs; otherwise, `response`
* will contain information related to this operation.
*/
setServiceProperties(serviceProperties: common.models.ServicePropertiesResult.ServiceProperties, options: common.RequestOptions, callback: ErrorOrResponse): void;
setServiceProperties(serviceProperties: common.models.ServicePropertiesResult.ServiceProperties, callback: ErrorOrResponse): void;
setServiceProperties(serviceProperties: common.models.ServicePropertiesResult.BlobServiceProperties, options: common.RequestOptions, callback: ErrorOrResponse): void;
setServiceProperties(serviceProperties: common.models.ServicePropertiesResult.BlobServiceProperties, callback: ErrorOrResponse): void;
/**
* Sets the tier of a blockblob under a blob storage LRS account, or the tier of a pageblob under a premium storage account.
@ -9157,6 +9157,14 @@ declare module azurestorage {
CorsRule: CorsRule[];
};
}
export interface StaticWebsiteProperties {
Enabled: boolean;
IndexDocument?: string;
ErrorDocument404Path?: string;
}
export interface BlobServiceProperties extends ServiceProperties {
StaticWebsite?: StaticWebsiteProperties;
}
export function serialize(servicePropertiesJs: ServiceProperties): string;
export function parse(servicePropertiesXml: any): ServiceProperties;
}