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

Add: support dns (lookup) command #6

Merged
merged 10 commits into from
Mar 20, 2022
Merged

Add: support dns (lookup) command #6

merged 10 commits into from
Mar 20, 2022

Conversation

patrykcieszkowski
Copy link
Contributor

@patrykcieszkowski patrykcieszkowski commented Mar 18, 2022

resolve #2

There's not many actively maintained libraries around, since node's official package resolves DNS pretty well (https://nodejs.org/api/dns.html).

It doesn't however seem to support protocol selection, so that won't work for us.

My initial commit implemented domain-info package, but I decided to ditch it since it doesn't seem to be actively maintained either, its last build failed. It supports multi dns type queries, which is interesting. The package @zarianec (node-dig-dns) has proposed on the other hand, doesn't include types so they had to be included manually.

No tests, since theres nothing to test. Parsing is handled by the library.

@patrykcieszkowski
Copy link
Contributor Author

@zarianec I don't think this DeepSource linter is configured in accordance with our project eslint.

@jimaek
Copy link
Member

jimaek commented Mar 18, 2022

@zarianec I don't think this DeepSource linter is configured in accordance with our project eslint.

You're admin of deepsource. Can you please configure it as you see fit?

@zarianec
Copy link
Contributor

yep, we just enabled it so it may require rules tweaking to make it work as expected. It's not necessary DeepSource checks to always pass. The main goal is to provide additional information and insights.
If you see that some errors could be ignored or they are false positives - ignore them. Or even better - disable them in the dashboard. But be careful there and try to not disable some correct rules.

@zarianec
Copy link
Contributor

and some rules in DeepSource are really stupid I must say 🤯

type: Joi.string().valid('dns'),
target: Joi.string(),
query: Joi.object({
type: Joi.string().valid(...allowedTypes).optional(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not provide default value here? You can make the property required in the DnsOptions type then and avoid non-null assertions later.

target: Joi.string(),
query: Joi.object({
type: Joi.string().valid(...allowedTypes).optional(),
address: Joi.string().optional(),
Copy link
Contributor

Choose a reason for hiding this comment

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

resolver or nameServer should be a better name.


const args = [
options.target,
`@${options.query.address ?? getDnsServers().pop()!}`,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an optimistic approach 🙂 . Dns servers returned by dns.getServers() may include addresses with a port as well as ipv6 addresses. Why not just avoid the @servername option if no options.query.address provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. That's a leftover from the previous library - it wouldn't find its own defaults.

Copy link
Member

Choose a reason for hiding this comment

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

We should let dig use the system defaults for now, so dont provide anything manually

options.target,
`@${options.query.address ?? getDnsServers().pop()!}`,
['-t', options.query.type ?? 'A'],
['-p', options.query.port ?? '53'],
Copy link
Contributor

Choose a reason for hiding this comment

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

-4 +time=1 +tries=2 params missing. They must be hardcoded.

@zarianec
Copy link
Contributor

I guess it's not possible with node-dig-dns to get the command progress? We may want to add +trace later for tracing the resolution and it will require real-time updates.

@patrykcieszkowski
Copy link
Contributor Author

I guess it's not possible with node-dig-dns to get the command progress? We may want to add +trace later for tracing the resolution and it will require real-time updates.

It doesn't, it outputs a promise resolution after completed query. If we want the progress event to be outputted, we'll have to build our own library (or just copy the codebase of node-dig-dns and adapt for our needs)

@zarianec
Copy link
Contributor

@patrykcieszkowski tests missing for this new command.

@patrykcieszkowski
Copy link
Contributor Author

@patrykcieszkowski tests missing for this new command.

read the top message

@zarianec
Copy link
Contributor

No tests, since theres nothing to test. Parsing is handled by the library.

Not true. Yes, parsing is done by a 3rd-party library but we send this output to the API using websockets and we must be sure that this output won't change after we update the library, change the code, etc.
What's important in commands - is the messages they send to the API. Parsing is just a part of it.

@zarianec
Copy link
Contributor

My goal is eventually to have 100% code coverage.

@zarianec
Copy link
Contributor

Following the discussion in private channels, it's not much to test there since we use an external library and don't have a mechanism of mocking/testing calls for 3rd-party system components (ping, dig, etc.).
I'm going to merge this PR and we will figure out how to properly test it in a separate one.

@zarianec zarianec merged commit 8fe9d83 into master Mar 20, 2022
@zarianec zarianec deleted the 2-dns-support branch March 20, 2022 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DNS command - Real time update
3 participants