|
@@ -7,6 +7,7 @@ const logger = require('./logger')
|
7
|
7
|
const crypto = require('cobox-crypto')
|
8
|
8
|
|
9
|
9
|
const CONFIG_FILE = 'config.yml'
|
|
10
|
+const IDENTITY_SUBKEY_ID = 0
|
10
|
11
|
|
11
|
12
|
module.exports = (storage, opts) => new CoBoxConfig(storage, opts)
|
12
|
13
|
|
|
@@ -20,7 +21,6 @@ const defaultOptions = () => ({
|
20
|
21
|
const defaultConfig = () => ({
|
21
|
22
|
options: defaultOptions(),
|
22
|
23
|
groups: { byKey: {}, byName: {} },
|
23
|
|
- identities: { byKey: {}, byName: {} }
|
24
|
24
|
})
|
25
|
25
|
|
26
|
26
|
// filename-safe date (probably there is a better way to do this)
|
|
@@ -38,7 +38,6 @@ class CoBoxConfig {
|
38
|
38
|
if (!fs.existsSync(this.storage)) {
|
39
|
39
|
fs.writeFileSync(this.storage, yaml.safeDump(defaultConfig(), { sortKeys: true }))
|
40
|
40
|
this._groups = config.groups
|
41
|
|
- this._identities = config.identities
|
42
|
41
|
this._options = config.options
|
43
|
42
|
} else {
|
44
|
43
|
this.load()
|
|
@@ -52,11 +51,10 @@ class CoBoxConfig {
|
52
|
51
|
this.masterKey = fs.readFileSync(masterKeyPath)
|
53
|
52
|
}
|
54
|
53
|
|
|
54
|
+ this.identity = crypto.keyPair(this.masterKey, IDENTITY_SUBKEY_ID)
|
55
|
55
|
this.logger = logger(path.join(this.root, 'logs', logfile))
|
56
|
56
|
this.log = this.logger('cobox-config')
|
57
|
|
-
|
58
|
57
|
this.groups = KeyHandler(this._groups)
|
59
|
|
- this.identities = KeyHandler(this._identities)
|
60
|
58
|
this.options = MapHandler(this._options)
|
61
|
59
|
}
|
62
|
60
|
|
|
@@ -64,7 +62,6 @@ class CoBoxConfig {
|
64
|
62
|
try {
|
65
|
63
|
var config = defaultConfig()
|
66
|
64
|
config.groups = this._groups
|
67
|
|
- config.identities = this._identities
|
68
|
65
|
config.options = this._options
|
69
|
66
|
|
70
|
67
|
fs.writeFileSync(this.storage, yaml.safeDump(config, { sortKeys: true }))
|
|
@@ -79,7 +76,6 @@ class CoBoxConfig {
|
79
|
76
|
try {
|
80
|
77
|
const config = yaml.safeLoad(fs.readFileSync(this.storage, 'utf8'))
|
81
|
78
|
this._groups = config.groups
|
82
|
|
- this._identities = config.identities
|
83
|
79
|
this._options = config.options || defaultOptions()
|
84
|
80
|
return true
|
85
|
81
|
} catch (err) {
|