/
index.js
120 lines (119 loc) · 3.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
var fs = require('fs'),
spawn = require('child_process').spawn,
backend = require('./backend'),
replace = require('./replace'),
search = require('./search');
module.exports = function(params){
backend = backend(params);
var rust = {
setHostName:function(host, callback){
var ops = {
regex:/http, (.+)"/,
value:'http, [ {"' + host + '"',
file:params.config
};
replace(ops, callback);
},
getHostName:function(callback){
search({
regex:/http, (.+)"/,
cleaner: [
{clean: '[', cleanee: ''},
{clean: '{', cleanee: ''},
{clean: '"', cleanee: ''}
],
trim: true,
file:params.config
}, callback);
},
setHTTPPort:function(port, callback){
rust.getHostName(function(hostname){
var ops = {
regex:/http, (.+) }/,
value:'http, [ {"' + hostname + '", ' + port + ' }',
file:params.config
};
replace(ops, callback);
});
},
setHandoffPort:function(port, callback){
var ops = {
regex:/handoff_port,(.+)}/,
value:'handoff_port, ' + port + ' }',
file:params.config
};
replace(ops, callback);
},
setPBIP:function(host, callback){
replace({
regex:/pb_ip,(.+)}/,
value:'pb_ip, "' + host + '" }',
file:params.config
}, callback);
},
setPBPort:function(port, callback){
replace({
regex:/pb_port,(.+)}/,
value:'pb_port, ' + port + ' }',
file:params.config
}, callback);
},
disablePB:function(callback){
replace({
regex:/{pb_ip/,
value:'%% {pb_ip',
file:params.config
}, callback);
},
backend:backend,
getSearch:function(callback){
fs.readFile(params.config, function(err, blob){
blob.toString().replace(/riak_search,\s+\[\s.+\n\s+{enabled,(.+)}/, function(r, search){
if (typeof(search) === 'string'){
search = search.trim() === 'true' ? true : false;
}
callback(null, search);
});
});
},
setSearch:function(enabled, callback){
fs.readFile(params.config, function(err, blob){
blob.toString().replace(/riak_search,(\s+\[\s.+\n\s+){enabled,(.+)}/, function(r, c, s){
var buildString = r.replace(s.trim(), enabled);
fs.writeFile(params.config, blob.toString().replace(r, buildString), function(err){
callback(err);
});
});
});
},
getNodeName:function(callback){
fs.readFile(params.args, function(err, blob){
blob.toString().replace(/-name(.+)/, function(r, name){
callback(null, name.trim());
});
});
},
setNodeName:function(name, callback){
replace({
regex:/-name(.+)/,
value:"-name " + name,
file:params.args
}, callback);
},
getCookieName:function(callback){
fs.readFile(params.args, function(err, blob){
blob.toString().replace(/-setcookie(.+)/, function(r, name){
callback(null, name.trim());
});
});
},
setCookieName:function(name, callback){
replace({
regex:/-setcookie(.+)/,
value:"-setcookie " + name,
file:params.args
}, callback);
}
};
return rust;
};