-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
'use strict' | ||
|
||
const Conf = require('conf') | ||
|
||
const config = new Conf({ | ||
// data is stored on the local file system | ||
// assuming this is secure enough for all practical purposes | ||
encryptionKey: 'encryption key does not need to be secret', | ||
}) | ||
const log = require('./log') | ||
|
||
const ENCRYPTION_KEY = 'ENCRYPTION_KEY' | ||
const TOKEN = 'TOKEN' | ||
|
||
module.exports = { | ||
get encryptionKey() { | ||
return config.has(ENCRYPTION_KEY) | ||
? Buffer.from(config.get(ENCRYPTION_KEY), 'hex') | ||
: null | ||
}, | ||
set encryptionKey(buffer) { | ||
config.set(ENCRYPTION_KEY, buffer.toString('hex')) | ||
}, | ||
get token() { | ||
return config.get(TOKEN) | ||
}, | ||
set token(value) { | ||
config.set(TOKEN, value) | ||
}, | ||
function createConfig(repository) { | ||
log.verbose(`Initializing config for repository ${repository}`) | ||
|
||
const userConfig = new Conf({ | ||
configName: 'user', | ||
// data is stored on the local file system | ||
// assuming this is secure enough for all practical purposes | ||
encryptionKey: `user encryption key`, | ||
}) | ||
|
||
const repositoryConfig = new Conf({ | ||
configName: repository, | ||
encryptionKey: `repository ${repository} encryption key`, | ||
}) | ||
|
||
return { | ||
get encryptionKey() { | ||
return repositoryConfig.has(ENCRYPTION_KEY) | ||
? Buffer.from(repositoryConfig.get(ENCRYPTION_KEY), 'hex') | ||
: null | ||
}, | ||
set encryptionKey(buffer) { | ||
repositoryConfig.set(ENCRYPTION_KEY, buffer.toString('hex')) | ||
}, | ||
get token() { | ||
return userConfig.get(TOKEN) | ||
}, | ||
set token(value) { | ||
userConfig.set(TOKEN, value) | ||
}, | ||
} | ||
} | ||
|
||
module.exports = createConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
'use strict' | ||
|
||
const log = require('../log') | ||
const createConfig = require('../config') | ||
const { setup } = require('./setup') | ||
|
||
function setupLogging(argv) { | ||
log.setLevel(argv.verbose) | ||
function setupLogging(yargs) { | ||
log.setLevel(yargs.verbose) | ||
} | ||
|
||
function setupConfig({ repository }) { | ||
return { | ||
config: createConfig(repository), | ||
} | ||
} | ||
|
||
module.exports = { | ||
setup, | ||
setupLogging, | ||
setupConfig, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.