-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Admin APIs and tools for node params (without refreshing) #1051
Conversation
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); | ||
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); | ||
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); | ||
console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for fixing these~ 👍
// ain_validateAppName | ||
INVALID_APP_NAME_FOR_STATE_LABEL: 30701, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make sure to run the unit & integration tests? I think they would need some updates from this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for denoting this! I couldn't think these codes were directly used in the tests. Fixed now!
AIN_GET_EVENT_HANDLER_CHANNEL_INFO: 'ain_getEventHandlerChannelInfo', | ||
AIN_GET_EVENT_HANDLER_FILTER_INFO: 'ain_getEventHandlerFilterInfo', | ||
AIN_GET_LAST_BLOCK: 'ain_getLastBlock', | ||
AIN_GET_LAST_BLOCK_NUMBER: 'ain_getLastBlockNumber', | ||
AIN_GET_NODE_PARAM: 'ain_getNodeParam', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add tool scripts for the new apis?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New tools added!
json_rpc/admin.js
Outdated
verified) { | ||
done(null, | ||
JsonRpcUtil.addProtocolVersion({ result: NodeConfigs.DEV_CLIENT_API_IP_WHITELIST })); | ||
trafficStatsManager.addEvent(TrafficEventTypes.ACCESS_CONTROL_SET, latency); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/ACCESS_CONTROL_SET/ACCESS_CONTROL_GET/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't notice it! Fixed now, thanks!
json_rpc/admin.js
Outdated
if (_.get(args.message, 'method') !== JSON_RPC_METHODS.AIN_GET_NODE_PARAM || !verified) { | ||
const latency = Date.now() - beginTime; | ||
trafficStatsManager.addEvent(TrafficEventTypes.ACCESS_CONTROL_SET, latency); | ||
done({ code: 403, message: 'Forbidden' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it looks a little bit out of the scope but could you define a result code in JsonRpcApiResultCode for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
json_rpc/admin.js
Outdated
const beginTime = Date.now(); | ||
const verified = node.verifyNodeAccountSignature(args.message, args.signature); | ||
if (_.get(args.message, 'method') !== JSON_RPC_METHODS.AIN_ADD_TO_DEV_CLIENT_API_IP_WHITELIST || | ||
!verified) { | ||
if (_.get(args.message, 'method') !== JSON_RPC_METHODS.AIN_SET_NODE_PARAM || !verified) { | ||
const latency = Date.now() - beginTime; | ||
trafficStatsManager.addEvent(TrafficEventTypes.ACCESS_CONTROL_SET, latency); | ||
done({ code: 403, message: 'Forbidden' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
if (_.get(args.message, 'method') !== JSON_RPC_METHODS.AIN_ADD_TO_WHITELIST_NODE_PARAM || !verified) { | ||
const latency = Date.now() - beginTime; | ||
trafficStatsManager.addEvent(TrafficEventTypes.ACCESS_CONTROL_SET, latency); | ||
done({ code: 403, message: 'Forbidden' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
done(null, JsonRpcUtil.addProtocolVersion({ | ||
result: { | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not exist.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is/does/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.SUCCESS, | ||
message: `Added IP (${args.message.ip}) to whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is not exists/does not exist/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.IP_ALREADY_IN_WHITELIST, | ||
message: `IP (${args.message.ip}) already in whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.SUCCESS, | ||
message: `Removed IP (${args.message.ip}) from whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
done(null, JsonRpcUtil.addProtocolVersion({ | ||
result: { | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not whitelist` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/not whitelist/not a whitelist/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
common/result-code.js
Outdated
// ain_removeFromDevClientApiIpWhitelist | ||
IP_NOT_IN_WHITELIST: 30601, | ||
// Admin APIs | ||
PARAM_INVALID: 30501, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion) what about adding prefix 'ADMIN_' for these admin API code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.IP_NOT_IN_WHITELIST, | ||
message: `IP (${args.message.ip}) not in whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.PARAM_INVALID, | ||
message: `Param [${param}] is not whitelist` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); | ||
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); | ||
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); | ||
console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for fixing this!
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); | ||
console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); | ||
console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); | ||
console.log('node tools/api-access/removeFromDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor) what about adding an example with wildcard ('*')?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
console.log('node tools/api-access/getDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); | ||
console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 private_key 127.0.0.1'); | ||
console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 mnemonic 127.0.0.1'); | ||
console.log('node tools/api-access/addToDevClientApiIpWhitelist.js http://localhost:8081 0 keystore /path/to/keystore/file 127.0.0.1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor) what about adding an example with wildcard('*')?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added!
I addressed all reviews and made some changes in API, please take a look! |
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.SUCCESS, | ||
message: `Added IP (${args.message.ip}) to whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.ADMIN_PARAM_INVALID, | ||
message: `Param [${param}] does not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor) s/exists/exist/?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, fixed!
json_rpc/admin.js
Outdated
code: JsonRpcApiResultCode.IP_ALREADY_IN_WHITELIST, | ||
message: `IP (${args.message.ip}) already in whitelist: ${JSON.stringify(NodeConfigs.DEV_CLIENT_API_IP_WHITELIST)}` | ||
code: JsonRpcApiResultCode.ADMIN_PARAM_INVALID, | ||
message: `Param [${param}] does not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
json_rpc/admin.js
Outdated
done(null, JsonRpcUtil.addProtocolVersion({ | ||
result: { | ||
code: JsonRpcApiResultCode.ADMIN_PARAM_INVALID, | ||
message: `Param [${param}] does not exists.` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with some minor comments.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!!
Now merged! Thanks for the reviews! |
Changes
TODO
Related Issue