nv-remote-cfg
v1.0.11
Published
nv-remote-cfg ============ - cli tool - create a config file server - support dynamic-modify-config through unix\_sock OR http
Downloads
6
Readme
nv-remote-cfg
- cli tool
- create a config file server
- support dynamic-modify-config through unix_sock OR http
install
- npm install nv-remote-cfg
usage
# npm install nv-remote-cfg -g
nv_rcfg_srv -H
Usage: nv_rcfg_srv [options]
Options:
-p, --port server port or unix_sock, default ./___usock___
-d, --workdir work dir, default ./
-H, --help usage
HTTP
init
# mkdir cfg-srv
# cd cfg-srv/
# nv_rcfg_srv -p 18888
//...wait install node_modules
root@dev:/home/dev/RCFG/cfg-srv# ls -l | egrep -v node_modules
total 8
-rw-r--r-- 1 root root 2 Feb 9 08:49 cfg
-rw-r--r-- 1 root root 194 Feb 9 08:49 srv
root@dev:/home/dev/RCFG/cfg-srv#
root@dev:/home/dev/RCFG/cfg-srv# cat cfg
{}
root@dev:/home/dev/RCFG/cfg-srv#
root@dev:/home/dev/RCFG/cfg-srv# cat srv
const S = require("nv-remote-cfg-srv");
const path = require("path");
module.exports = async ()=> {
await S(18888,path.join("/home/dev/RCFG/cfg-srv",'cfg'),"/home/dev/RCFG/cfg-srv");
return(S)
}
edit cfg
<> means Map
() means Set
{} means Dict
[] means Array
support comments
# vim cfg
/*
{
url: "http://api0.com"
options-set:
( js,ts,json,astml )
names: [ "bob bob", alice, jack ]
map:
<
[Radio,Multi,Const]: [radio, multi, const]
Var : var
var : Var
>
}
*/
start srv
> const S = await require("./srv")()
listen on: 18888
> S.CFG //this is a getter, for dynamic-change-from-remote
{
url: 'http://api0.com',
'options-set': Set(4) { 'js', 'ts', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
>
get config from remote
root@dev:/home/dev/RCFG/cfg-srv# nv_rcfg_client -H
Usage: nv_rcfg_client [options]
Options:
-h, --host host,default 127.0.0.1, if using unix_sock: NO effect
-a, --path path,default /cfg, if using unix_sock: NO effect
-p, --port server port or unix_sock, default ./___usock___
-S, --show show remote config
-m, --modify modify cmd,such as CFG...
-H, --help usage
root@dev:/home/dev/RCFG/cfg-srv#
root@dev:/home/dev/RCFG/cfg-srv# nv_rcfg_client -S -p 18888
{
url: 'http://api0.com',
//we will change this
'options-set': Set(4) { 'js', 'ts', 'json', 'astml' },
//we will delete ts from options-set
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
root@dev:/home/dev/RCFG/cfg-srv#
change config from remote when server running
- CFG is keywords
set prop
# nv_rcfg_client -p 18888 -m "CFG.url = 'https://API18888.net'"
before:
{
url: 'http://api0.com',
'options-set': Set(4) { 'js', 'ts', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
------------
after:
{
url: 'https://API18888.net',
'options-set': Set(4) { 'js', 'ts', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
delete set-element
# nv_rcfg_client -p 18888 -m "CFG['options-set'].delete('ts')"
before:
{
url: 'https://API18888.net',
'options-set': Set(4) { 'js', 'ts', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
------------
after:
{
url: 'https://API18888.net',
'options-set': Set(3) { 'js', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
check it on server AFTER change from client
> S.CFG
{
url: 'https://API18888.net', //===============>
'options-set': Set(3) { 'js', 'json', 'astml' }, //------------>
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
>
check the cfg file AFTER change from client
root@dev:/home/dev/RCFG/cfg-srv# cat cfg
{
"url" :
"https://API18888.net" ,
"options-set" :
(
"js" ,
"json" ,
"astml"
) ,
"names" :
[
"bob bob" ,
"alice" ,
"jack"
] ,
"map" :
<
[
"Radio" ,
"Multi" ,
"Const"
] :
[
"radio" ,
"multi" ,
"const"
] ,
"Var" :
"var" ,
"var" :
"Var"
>
}
UNIX_SOCK
- for security
server
# vim ./srv
//change the port to undefined
S(
undefined, //====>
path.join("/home/dev/RCFG/cfg-srv",'cfg'),
"/home/dev/RCFG/cfg-srv"
);
> const S = await require("./srv")()
listen on: /home/dev/RCFG/cfg-srv/___usock___
client
/*
root@dev:/home/dev/RCFG/cfg-srv# nv_rcfg_client -S
{
url: 'https://API18888.net',
'options-set': Set(3) { 'js', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
root@dev:/home/dev/RCFG/cfg-srv#
*/
# nv_rcfg_client -m "CFG.map.set('Const','const')"
before:
{
url: 'https://API18888.net',
'options-set': Set(3) { 'js', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(3) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var'
}
}
------------
after:
{
url: 'https://API18888.net',
'options-set': Set(3) { 'js', 'json', 'astml' },
names: [ 'bob bob', 'alice', 'jack' ],
map: Map(4) {
[ 'Radio', 'Multi', 'Const' ] => [ 'radio', 'multi', 'const' ],
'Var' => 'var',
'var' => 'Var',
'Const' => 'const'
}
}
LICENSE
- ISC