| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/provisioner/lib/ |
Upload File : |
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const nami_wrapper_1 = require("./nami_wrapper");
/**
* Class for handling single element that is stored ; a single element maps to single file on disk
* and is written in an atomic way using `save` function;
* currently all data is stored as ~/.provisioner/{{name}}.json`
*/
class StorageData {
/**
* Constructor
* @param manager Instance of StorageManager creating this object
* @param name Unique name for storage ; used for filename for storing the data
* @param dataType Format to use for storing ; currently only `json` is supported
*/
constructor(manager, name, dataType) {
this.manager = manager;
this.name = name;
this.dataType = dataType;
this.dataType = this.dataType || "json";
this._fileName = nami_wrapper_1.file.join([manager.prefix, `${this.name}.${this.dataType}`]);
this.data = {};
}
/**
* Load data from disk, overwriting any locally stored data
*/
load() {
if (nami_wrapper_1.file.exists(this._fileName)) {
if (this.dataType === "json") {
this.data = JSON.parse(nami_wrapper_1.file.read(this._fileName));
}
else {
this.data = nami_wrapper_1.file.read(this._fileName);
}
}
}
/**
* Save data to disk, overwriting any previous data in the storage
*/
save() {
// TODO: backup old data ?
if (this.dataType === "json") {
nami_wrapper_1.file.write(this._fileName, JSON.stringify(this.data));
}
else {
nami_wrapper_1.file.write(this._fileName, this.data);
}
}
}
exports.StorageData = StorageData;
/**
* Class for handling storage for all provisioner based logic;
* the class is mainly used to get instances of `StorageData` objects and makes sure only one
* instance of `StorageData` object with same name is created - creating the same object when
* first needed and then returning it
*/
class StorageManager {
/**
* Constructor
* @param provisioner Instance of provisioner that this object will be used with
* @param prefix Directory where data is stored; defaults to `~/.provisioner`
*/
constructor(provisioner, prefix) {
this.provisioner = provisioner;
this.prefix = prefix;
this._items = {};
this.prefix = nami_wrapper_1.file.normalize(this.prefix || "~/.provisioner");
}
/**
* Get an instance of `StorageData` based on the name; makes sure only one
* instance of `StorageData` object with same name is created - creating the same object when
* first needed and then returning it
*/
getItem(name, dataType) {
if (!this._items[name]) {
nami_wrapper_1.file.mkdir(this.prefix);
this._items[name] = new StorageData(this, name, dataType);
this._items[name].load();
}
return this._items[name];
}
}
exports.StorageManager = StorageManager;