-
Notifications
You must be signed in to change notification settings - Fork 28
⭐ Add provider ipinfo #6176
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
base: main
Are you sure you want to change the base?
⭐ Add provider ipinfo #6176
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
chris-rock
left a comment
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.
Great first version @Bajusz15 I added some feedback
providers/ipinfo/config/config.go
Outdated
| var Config = plugin.Provider{ | ||
| Name: "ipinfo", | ||
| ID: "go.mondoo.com/cnquery/v12/providers/ipinfo", | ||
| Version: "10.0.0", |
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.
should be version 12
providers/ipinfo/config/config.go
Outdated
| Connectors: []plugin.Connector{ | ||
| { | ||
| Name: "ipinfo", | ||
| Use: "ipinfo", |
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.
proper description required
providers/ipinfo/go.mod
Outdated
|
|
||
| go 1.25.1 | ||
|
|
||
| require go.mondoo.com/cnquery/v12 v12.9.0 |
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.
should be a relative import similar to the other providers
| url = "https://ipinfo.io" | ||
| } else { | ||
| // Query for specific IP | ||
| url = fmt.Sprintf("https://ipinfo.io/%s", queryIP.String()) |
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.
any reason why we are not using https://github.com/ipinfo/go? This would also help us to implement the token support.
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 was not working without a real token when I was testing it locally. I removed it in this commit, but this is still an early draft and needs lot of rework. If I can find a way to use the sdk without a real token I will change it back.
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.
Empty token works without any problem:
const token = ""
// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
client := ipinfo.NewClient(nil, nil, token)
const ip_address = "8.8.8.8"
info, err := client.GetIPInfo(net.ParseIP(ip_address))
if err != nil {
panic(err)
}
fmt.Println(info)
providers/ipinfo/resources/ipinfo.go
Outdated
| ) | ||
|
|
||
| // getIPInfoToken returns the IPINFO_TOKEN from environment variable, cached after first read | ||
| func getIPInfoToken() string { |
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.
This should be done when we start the connection, then we also do not need to use locks https://github.com/mondoohq/cnquery/pull/6176/files#diff-59130fb879bd3dcc44bb675d913b5a3f8019f8cc4f814d53bcc0f4ea39b0ab5aR18-R28
providers/ipinfo/README.md
Outdated
|
|
||
| This provider makes public IP address information accessible from ipinfo.io. | ||
|
|
||
| It provides a connector for querying IP information via the ipinfo.io API. |
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.
We should add examples here how to use it and also include sample MQL. https://github.com/mondoohq/cnquery/tree/main/providers/shodan is a good example
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.
I specifically would also love to see some examples that use the cross provider connection eg. with local interface.
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.
Updated readme now
| ^\.github/workflows/.*\.yaml | ||
| _release_template_file.md | ||
| ignore$ | ||
| ipinfo |
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.
This PR should merge into main, not another branch
| url = "https://ipinfo.io" | ||
| } else { | ||
| // Query for specific IP | ||
| url = fmt.Sprintf("https://ipinfo.io/%s", queryIP.String()) |
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.
Empty token works without any problem:
const token = ""
// params: httpClient, cache, token. `http.DefaultClient` and no cache will be used in case of `nil`.
client := ipinfo.NewClient(nil, nil, token)
const ip_address = "8.8.8.8"
info, err := client.GetIPInfo(net.ParseIP(ip_address))
if err != nil {
panic(err)
}
fmt.Println(info)338d9e3 to
4fe5b09
Compare
Adds ipinfo provider. Initially I added functionality to route the request through an interface, but after alignment we decided to keep it simple, ipinfo can be used to query ipinfo.io for any ip.
If the envrionment variable
IPINFO_TOKENis set we can use the paid sdk version, otherwise we fall back to the free deprecated API (simply calling ipinfo.io/).To get public IP of the machine we are running ipinfo from, we need to call ipinfo with an empty address.
Usage: