-
Notifications
You must be signed in to change notification settings - Fork 164
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
5 changed files
with
150 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
config.json |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
var Consul = require('consul-node'); | ||
var consul = new Consul(); | ||
|
||
/** | ||
* Grab the meta config to bootstrap git2consul. | ||
*/ | ||
module.exports = function(cb) { | ||
consul.kv.get('/git2consul/?recurse', function(err, items) { | ||
if (err) return cb(err); | ||
|
||
var config = {}; | ||
items.forEach(function(item) { | ||
config[item.key.substring(11)] = item.value.indexOf(',') === -1 ? item.value : item.value.split(','); | ||
}); | ||
|
||
cb(null, config); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var fs = require('fs'); | ||
|
||
var Consul = require('consul-node'); | ||
|
||
var consul = new Consul(); | ||
|
||
/** | ||
* This utility adds keys from the top level of a .json config file to the /git2consul/ path of | ||
* Consul. We use this to seed Consul's KV with the bootstrapping information used by git2consul. | ||
*/ | ||
|
||
if (process.argv.length !== 3) { | ||
console.error('usage: node utils/seed.js config.js'); | ||
process.exit(1); | ||
} | ||
|
||
var add_entry = function(key, value, cb) { | ||
console.log('Adding config %s : %s', key, value); | ||
consul.kv.put(key, value, cb); | ||
}; | ||
|
||
var config_file = process.argv[2]; | ||
|
||
console.log('Adding keys from config file %s to local consul cluster', config_file); | ||
|
||
var file = fs.readFileSync(config_file, {'encoding':'utf8'}); | ||
var obj = JSON.parse(file); | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
if (typeof value === 'string') { | ||
add_entry('git2consul/' + key, value, function(err) { | ||
if (err) return console.error(err); | ||
}); | ||
} else if (value.hasOwnProperty('length')) { | ||
value = value.join(); | ||
add_entry('git2consul/' + key, value, function(err) { | ||
if (err) return console.error(err); | ||
}); | ||
} | ||
} |