UNPKG

azurite

Version:

An open source Azure Storage API compatible server

100 lines 3.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setExtentMemoryLimit = exports.CertOptions = void 0; const tslib_1 = require("tslib"); const fs = tslib_1.__importStar(require("fs")); const models_1 = require("./models"); const MemoryExtentStore_1 = require("./persistence/MemoryExtentStore"); const os_1 = require("os"); const Logger_1 = tslib_1.__importDefault(require("./Logger")); var CertOptions; (function (CertOptions) { CertOptions[CertOptions["Default"] = 0] = "Default"; CertOptions[CertOptions["PEM"] = 1] = "PEM"; CertOptions[CertOptions["PFX"] = 2] = "PFX"; })(CertOptions || (exports.CertOptions = CertOptions = {})); function setExtentMemoryLimit(env, logToConsole) { if (env.inMemoryPersistence()) { let mb = env.extentMemoryLimit(); if (mb === undefined || typeof mb !== 'number') { mb = MemoryExtentStore_1.DEFAULT_EXTENT_MEMORY_LIMIT / (1024 * 1024); } if (mb < 0) { throw new Error(`A negative value of '${mb}' is not allowed for the extent memory limit.`); } if (mb >= 0) { const bytes = Math.round(mb * 1024 * 1024); const totalPct = Math.round(100 * bytes / (0, os_1.totalmem)()); const message = `In-memory extent storage is enabled with a limit of ${mb.toFixed(2)} MB (${bytes} bytes, ${totalPct}% of total memory).`; if (logToConsole) { console.log(message); } Logger_1.default.info(message); MemoryExtentStore_1.SharedChunkStore.setSizeLimit(bytes); } else { const message = `In-memory extent storage is enabled with no limit on memory used.`; if (logToConsole) { console.log(message); } Logger_1.default.info(message); MemoryExtentStore_1.SharedChunkStore.setSizeLimit(); } } } exports.setExtentMemoryLimit = setExtentMemoryLimit; class ConfigurationBase { constructor(host, port, enableAccessLog = false, accessLogWriteStream, enableDebugLog = false, debugLogFilePath, loose = false, skipApiVersionCheck = false, cert = "", key = "", pwd = "", oauth, disableProductStyleUrl = false) { this.host = host; this.port = port; this.enableAccessLog = enableAccessLog; this.accessLogWriteStream = accessLogWriteStream; this.enableDebugLog = enableDebugLog; this.debugLogFilePath = debugLogFilePath; this.loose = loose; this.skipApiVersionCheck = skipApiVersionCheck; this.cert = cert; this.key = key; this.pwd = pwd; this.oauth = oauth; this.disableProductStyleUrl = disableProductStyleUrl; } hasCert() { if (this.cert.length > 0 && this.key.length > 0) { return CertOptions.PEM; } if (this.cert.length > 0 && this.pwd.toString().length > 0) { return CertOptions.PFX; } return CertOptions.Default; } getCert(option) { switch (option) { case CertOptions.PEM: return { cert: fs.readFileSync(this.cert), key: fs.readFileSync(this.key) }; case CertOptions.PFX: return { pfx: fs.readFileSync(this.cert), passphrase: this.pwd.toString() }; default: return null; } } getOAuthLevel() { if (this.oauth) { if (this.oauth.toLowerCase() === "basic") { return models_1.OAuthLevel.BASIC; } } return; } getHttpServerAddress() { return `http${this.hasCert() === CertOptions.Default ? "" : "s"}://${this.host}:${this.port}`; } } exports.default = ConfigurationBase; //# sourceMappingURL=ConfigurationBase.js.map