import TableStorageContext from "../context/TableStorageContext" ; import StorageErrorFactory from "../errors/StorageErrorFactory" ; import * as Models from "../generated/artifacts/models" ; import Context from "../generated/Context" ; import IServiceHandler from "../generated/handlers/IServiceHandler" ; import { parseXML } from "../generated/utils/xml" ; import { TABLE_API_VERSION } from "../utils/constants" ; import BaseHandler from "./BaseHandler" ; export default class ServiceHandler extends BaseHandler implements IServiceHandler { private memberof private readonly defaultServiceProperties = { cors : [ ] , defaultServiceVersion : TABLE_API_VERSION , hourMetrics : { enabled : false , retentionPolicy : { enabled : false } , version : "1.0" } , logging : { deleteProperty : true , read : true , retentionPolicy : { enabled : false } , version : "1.0" , write : true } , minuteMetrics : { enabled : false , retentionPolicy : { enabled : false } , version : "1.0" } } ; public async getProperties ( options , context ) { const tableCtx = new TableStorageContext ( context ) ; const accountName = tableCtx . account ! ; let properties = await this . metadataStore . getServiceProperties ( context , accountName ) ; if ( ! properties ) { properties = { ... this . defaultServiceProperties , accountName } ; } if ( properties . cors === undefined ) { properties . cors = [ ] ; } if ( properties . hourMetrics === undefined ) { properties . hourMetrics = this . defaultServiceProperties . hourMetrics ; } if ( properties . logging === undefined ) { properties . logging = this . defaultServiceProperties . logging ; } if ( properties . minuteMetrics === undefined ) { properties . minuteMetrics = this . defaultServiceProperties . minuteMetrics ; } const response = { ... properties , requestId : context . contextID , statusCode : 200 , version : TABLE_API_VERSION , clientRequestId : options . requestId } ; return response ; } public async setProperties ( tableServiceProperties , options , context ) { const tableCtx = new TableStorageContext ( context ) ; const accountName = tableCtx . account ! ; const body = tableCtx . request ! . getBody ( ) ; const parsedBody = await parseXML ( body || "" ) ; if ( ! parsedBody . hasOwnProperty ( "cors" ) && ! parsedBody . hasOwnProperty ( "Cors" ) ) { tableServiceProperties . cors = undefined ; } for ( const cors of tableServiceProperties . cors || [ ] ) { cors . allowedHeaders = cors . allowedHeaders || "" ; cors . exposedHeaders = cors . exposedHeaders || "" ; } await this . metadataStore . setServiceProperties ( context , { ... tableServiceProperties , accountName } ) ; const response = { requestId : context . contextID , statusCode : 202 , version : TABLE_API_VERSION , clientRequestId : options . requestId } ; return response ; } public async getStatistics ( options , context ) { if ( ! context . context . isSecondary ) { throw StorageErrorFactory . getInvalidQueryParameterValue ( context ) ; } const response = { statusCode : 200 , requestId : context . contextID , version : TABLE_API_VERSION , date : context . startTime , geoReplication : { status : Models . GeoReplicationStatusType . Live , lastSyncTime : context . startTime ! } , clientRequestId : options . requestId } ; return response ; } }