ConfigurationManager

ConfigurationManager

Manager class for configuration items

Constructor

new ConfigurationManager(configDirectoryopt, encryptionKeyopt)

Source:
Parameters:
Name Type Attributes Default Description
configDirectory string <optional>
"./../data/" Base folder containing the config files
encryptionKey string | Buffer <optional>
Encryption key used (if applicable)

Methods

delete(config)

Deletes a config and removes it from the cache
Source:
Parameters:
Name Type Description
config ConfigItem

destroy(saveConfigs)

Destroys the configuration manager and closes all open (cached) items
Source:
Parameters:
Name Type Description
saveConfigs boolean Save the config files when closed

loadConfig(configName, isPath, configClass) → {ConfigItem|NeptuneConfig|ClientConfig}

Load a configuration from disk
Source:
Parameters:
Name Type Description
configName string The name of the configuration file (or path if isPath is set to true)
isPath boolean Indicates that configName is in fact the path to the config file. ONLY set this to true IF you are reading a known good file.
configClass ConfigItem | NeptuneConfig | ClientConfig Which class to initialize. This is the class type that will be returned

readFileContents(path) → {Promise.<JSONObject>}

Returns the JSON contents of a file, decrypting/encrypting if need-be.
Source:
Parameters:
Name Type Description
path string Path to the file you wish to read
Returns:
Type:
Promise.<JSONObject>
The config contents

readFileContentsSync(path) → {object}

Returns the JSON contents of a file, decrypting/encrypting if need-be.
Source:
Parameters:
Name Type Description
path string Path to the file you wish to read
Returns:
Type:
object
The config contents

rekey(newKeyopt)

Changes the encryption key on all configuration files. Essentially re-encrypts (or decrypts) all files.\ Use this to enable / disable encryption. Saves the new key to the key chain.
Source:
Parameters:
Name Type Attributes Description
newKey string | boolean <optional>
The new encryption key. If true we'll generate one, if empty or undefined we will disable encryption.

removeConfigItemFromCache(configItem) → {boolean}

Source:
Parameters:
Name Type Description
configItem ConfigItem Which item to remove from the cache
Returns:
Type:
boolean
ConfigItem was removed from our cache

rename(config, fileName, isPath)

Renames the config file
Source:
Parameters:
Name Type Description
config ConfigItem
fileName string New file name
isPath string Provided fileName is actual the real path

setEncryptionKey(newKey)

Sets the internal encryption key. If you set the key to something that is not the key, bad things may happen.\ This is not intended to be used to change the encryption key! Use `ConfigurationManager.rekey(newkey)` instead.
Source:
Parameters:
Name Type Description
newKey string New (actual) encryption key

writeFileContents(data, path) → {Promise.<boolean>}

Writes a string to a file, decrypting/encrypting if need-be.
Source:
Parameters:
Name Type Description
data string | object Data you wish to write to the file. Will be converted to JSON string if not already a string.
path string Path of the file you wish to write
Returns:
Type:
Promise.<boolean>
The config was saved

writeFileContentsSync(data, path) → {Promise.<boolean>}

Writes a string to a file, decrypting/encrypting if need-be.
Source:
Parameters:
Name Type Description
data string | object Data you wish to write to the file. Will be converted to JSON string if not already a string.
path string Path of the file you wish to write
Returns:
Type:
Promise.<boolean>
The config was saved