Skip to content
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

Merged
merged 11 commits into from
Jun 3, 2022

Conversation

kriii
Copy link
Contributor

@kriii kriii commented May 27, 2022

Changes

  • Generalize exist APIs
  • Fix tools due to API changes
  • Fix some typos

TODO

  • Make the collection of callbacks for some parameters that need a refresh.

Related Issue

@kriii kriii changed the base branch from master to develop May 27, 2022 05:51
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');
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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',
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New tools added!

verified) {
done(null,
JsonRpcUtil.addProtocolVersion({ result: NodeConfigs.DEV_CLIENT_API_IP_WHITELIST }));
trafficStatsManager.addEvent(TrafficEventTypes.ACCESS_CONTROL_SET, latency);
Copy link
Member

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/?

Copy link
Contributor Author

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!

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' });
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

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' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

done(null, JsonRpcUtil.addProtocolVersion({
result: {
code: JsonRpcApiResultCode.PARAM_INVALID,
message: `Param [${param}] is not exist.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/is/does/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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.`
Copy link
Member

@platfowner platfowner May 29, 2022

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/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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.`
Copy link
Member

@platfowner platfowner May 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

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.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

done(null, JsonRpcUtil.addProtocolVersion({
result: {
code: JsonRpcApiResultCode.PARAM_INVALID,
message: `Param [${param}] is not whitelist`
Copy link
Member

@platfowner platfowner May 29, 2022

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/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

// ain_removeFromDevClientApiIpWhitelist
IP_NOT_IN_WHITELIST: 30601,
// Admin APIs
PARAM_INVALID: 30501,
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

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`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto?

Copy link
Contributor Author

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');
Copy link
Member

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');
Copy link
Member

@platfowner platfowner May 29, 2022

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 ('*')?

Copy link
Contributor Author

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');
Copy link
Member

@platfowner platfowner May 29, 2022

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('*')?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

@kriii
Copy link
Contributor Author

kriii commented May 30, 2022

I addressed all reviews and made some changes in API, please take a look!

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.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor) s/exists/exist/?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, fixed!

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.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

done(null, JsonRpcUtil.addProtocolVersion({
result: {
code: JsonRpcApiResultCode.ADMIN_PARAM_INVALID,
message: `Param [${param}] does not exists.`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

Copy link
Member

@platfowner platfowner left a 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!

@kriii kriii added the enhancement New feature or request label May 31, 2022
@kriii kriii changed the title Admin APIs for node params (without refreshing) Admin APIs and tools for node params (without refreshing) May 31, 2022
Copy link
Contributor

@liayoo liayoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!!

@kriii kriii merged commit 6b63787 into develop Jun 3, 2022
@kriii kriii deleted the feature/kriii/node_param_api branch June 3, 2022 01:16
@kriii
Copy link
Contributor Author

kriii commented Jun 3, 2022

Now merged! Thanks for the reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants