Bulk ASN#159
Conversation
BE-2184 CLI ASN Bulk
Related to issue : #56 Right now we don't support looking up ASNs in bulk, but it's a useful feature to have. In the process, we should actually support mixing together IPs & ASNs in one bulk lookup, by default. And as a further improvement to the API, we should deprecate the Here's a specific checklist of things to consider:
|
UmanShahzad
left a comment
There was a problem hiding this comment.
@Harisabdullah I'll review this when we develop the generic solution for reading inputs from any place.
Restructure the codebase to enhance input handling from various sources
UmanShahzad
left a comment
There was a problem hiding this comment.
We require essentially 'passing down' the op func to make it work in a 'streaming' way - without buffering inputs at lower levels and bringing them up higher, because otherwise it won't scale.
|
|
||
| // save token to file. | ||
| gConfig.Token = tok | ||
| gConfig.Token = newtoken |
| INPUT_TYPE_IP INPUT_TYPE = "IP" | ||
| INPUT_TYPE_IP_RANGE INPUT_TYPE = "IPRange" | ||
| INPUT_TYPE_CIDR INPUT_TYPE = "CIDR" | ||
| INPUT_TYPE_FILE INPUT_TYPE = "File" |
There was a problem hiding this comment.
Files are a source, not an input type: the generic functionality, if told to read from files by the user, should do so by opening them and parsing their inputs for ips/ranges/cidrs/asns/etc. The same way it transparently 'opens' the 'stdin file' and reads from it when requested.
| } | ||
|
|
||
| if isPiped || isTyping || stat.Size() > 0 { | ||
| inputs = append(inputs, ReadStringsFromStdin()...) |
There was a problem hiding this comment.
This should actually be doing an op per string coming from stdin on the fly, instead of having it be returned. Otherwise for operations like prips this won't scale, because it'll store the whole thing in memory before proceeding and in some inputs that won't be even possible (huge IP ranges/cidrs).
| } | ||
|
|
||
| // readStringsFromFile reads strings from a file, one per line. | ||
| func readStringsFromFile(filename string) ([]string, error) { |
There was a problem hiding this comment.
We need to ensure all of our actions are not buffering inputs into an arbitrarily large array - this will make certain use cases not scale. We need to perform the op per input in the file if we're told to open files.
| } | ||
|
|
||
| // ReadStringsFromStdin reads strings from stdin until an empty line is entered. | ||
| func ReadStringsFromStdin() []string { |
UmanShahzad
left a comment
There was a problem hiding this comment.
Nice, let's try this out in main
Flow of Control is as follows
->
ipinfo as500->cmd_asn_single->
ipinfo asn->cmd_asn->
ipinfo asn bulk->cmd_asn_bulkHence the refactor of files
Implements #56