cleanup(geolocate): remove IP lookuppers blocked by sanctions (#747)

Closes https://github.com/ooni/probe/issues/2104
This commit is contained in:
Simone Basso 2022-05-20 12:43:56 +02:00 committed by GitHub
parent e5d59e834e
commit 6713fc6bc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 0 additions and 187 deletions

View File

@ -1,32 +0,0 @@
package geolocate
import (
"context"
"net/http"
"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/model"
)
type avastResponse struct {
IP string `json:"ip"`
}
func avastIPLookup(
ctx context.Context,
httpClient *http.Client,
logger model.Logger,
userAgent string,
) (string, error) {
var v avastResponse
err := (&httpx.APIClientTemplate{
BaseURL: "https://ip-info.ff.avast.com",
HTTPClient: httpClient,
Logger: logger,
UserAgent: userAgent,
}).WithBodyLogging().Build().GetJSON(ctx, "/v1/info", &v)
if err != nil {
return DefaultProbeIP, err
}
return v.IP, nil
}

View File

@ -1,26 +0,0 @@
package geolocate
import (
"context"
"net"
"net/http"
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
)
func TestIPLookupWorksUsingAvast(t *testing.T) {
ip, err := avastIPLookup(
context.Background(),
http.DefaultClient,
log.Log,
httpheader.UserAgent(),
)
if err != nil {
t.Fatal(err)
}
if net.ParseIP(ip) == nil {
t.Fatalf("not an IP address: '%s'", ip)
}
}

View File

@ -1,31 +0,0 @@
package geolocate
import (
"context"
"net/http"
"strings"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/model"
)
func ipConfigIPLookup(
ctx context.Context,
httpClient *http.Client,
logger model.Logger,
userAgent string,
) (string, error) {
data, err := (&httpx.APIClientTemplate{
BaseURL: "https://ipconfig.io",
HTTPClient: httpClient,
Logger: logger,
UserAgent: httpheader.CLIUserAgent(),
}).WithBodyLogging().Build().FetchResource(ctx, "/")
if err != nil {
return DefaultProbeIP, err
}
ip := strings.Trim(string(data), "\r\n\t ")
logger.Debugf("ipconfig: body: %s", ip)
return ip, nil
}

View File

@ -1,26 +0,0 @@
package geolocate
import (
"context"
"net"
"net/http"
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
)
func TestIPLookupWorksUsingIPConfig(t *testing.T) {
ip, err := ipConfigIPLookup(
context.Background(),
http.DefaultClient,
log.Log,
httpheader.UserAgent(),
)
if err != nil {
t.Fatal(err)
}
if net.ParseIP(ip) == nil {
t.Fatalf("not an IP address: '%s'", ip)
}
}

View File

@ -1,34 +0,0 @@
package geolocate
import (
"context"
"net/http"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
"github.com/ooni/probe-cli/v3/internal/httpx"
"github.com/ooni/probe-cli/v3/internal/model"
)
type ipInfoResponse struct {
IP string `json:"ip"`
}
func ipInfoIPLookup(
ctx context.Context,
httpClient *http.Client,
logger model.Logger,
userAgent string,
) (string, error) {
var v ipInfoResponse
err := (&httpx.APIClientTemplate{
Accept: "application/json",
BaseURL: "https://ipinfo.io",
HTTPClient: httpClient,
Logger: logger,
UserAgent: httpheader.CLIUserAgent(), // we must be a CLI client
}).WithBodyLogging().Build().GetJSON(ctx, "/", &v)
if err != nil {
return DefaultProbeIP, err
}
return v.IP, nil
}

View File

@ -1,26 +0,0 @@
package geolocate
import (
"context"
"net"
"net/http"
"testing"
"github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
)
func TestIPLookupWorksUsingIPInfo(t *testing.T) {
ip, err := ipInfoIPLookup(
context.Background(),
http.DefaultClient,
log.Log,
httpheader.UserAgent(),
)
if err != nil {
t.Fatal(err)
}
if net.ParseIP(ip) == nil {
t.Fatalf("not an IP address: '%s'", ip)
}
}

View File

@ -36,22 +36,10 @@ type method struct {
var ( var (
methods = []method{ methods = []method{
{
name: "avast",
fn: avastIPLookup,
},
{ {
name: "cloudflare", name: "cloudflare",
fn: cloudflareIPLookup, fn: cloudflareIPLookup,
}, },
{
name: "ipconfig",
fn: ipConfigIPLookup,
},
{
name: "ipinfo",
fn: ipInfoIPLookup,
},
{ {
name: "stun_ekiga", name: "stun_ekiga",
fn: stunEkigaIPLookup, fn: stunEkigaIPLookup,