Use more general ooni/probe-engine API (#67)
No functional change, just importing less stuff and meddling much less with the internals of ooni/probe-engine.
This commit is contained in:
+9
-12
@@ -1,7 +1,6 @@
|
||||
package run
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/alecthomas/kingpin"
|
||||
@@ -97,19 +96,17 @@ func init() {
|
||||
if ctx.Config.Advanced.BouncerURL != "" {
|
||||
ctx.Session.AddAvailableHTTPSBouncer(ctx.Config.Advanced.BouncerURL)
|
||||
}
|
||||
if err := ctx.Session.MaybeLookupBackends(context.Background()); err != nil {
|
||||
log.WithError(err).Warn("Failed to discover available test helpers")
|
||||
// Rationale for falling through: some tests may be able to complete
|
||||
// with no test helpers, so stopping may be excessive here.
|
||||
if ctx.Config.Sharing.UploadResults && ctx.Config.Advanced.CollectorURL != "" {
|
||||
ctx.Session.AddAvailableHTTPSCollector(ctx.Config.Advanced.CollectorURL)
|
||||
}
|
||||
if ctx.Config.Sharing.UploadResults {
|
||||
if ctx.Config.Advanced.CollectorURL != "" {
|
||||
ctx.Session.AddAvailableHTTPSCollector(ctx.Config.Advanced.CollectorURL)
|
||||
} else if err := ctx.Session.MaybeLookupCollectors(context.Background()); err != nil {
|
||||
log.WithError(err).Error("Failed to discover available collectors")
|
||||
return err
|
||||
}
|
||||
if err := ctx.Session.MaybeLookupBackends(); err != nil {
|
||||
log.WithError(err).Warn("Failed to discover OONI backends")
|
||||
return err
|
||||
}
|
||||
// Make sure we share what the user wants us to share.
|
||||
ctx.Session.SetIncludeProbeIP(ctx.Config.Sharing.IncludeIP)
|
||||
ctx.Session.SetIncludeProbeASN(ctx.Config.Sharing.IncludeASN)
|
||||
ctx.Session.SetIncludeProbeCC(ctx.Config.Sharing.IncludeCountry)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
package enginex
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-engine/model"
|
||||
)
|
||||
|
||||
// Logger is the logger used by the engine.
|
||||
@@ -13,30 +10,6 @@ var Logger = log.WithFields(log.Fields{
|
||||
"type": "engine",
|
||||
})
|
||||
|
||||
// MakeGenericTestKeys casts the m.TestKeys to a map[string]interface{}.
|
||||
//
|
||||
// Ideally, all tests should have a clear Go structure, well defined, that
|
||||
// will be stored in m.TestKeys as an interface. This is not already the
|
||||
// case and it's just valid for tests written in Go. Until all tests will
|
||||
// be written in Go, we'll keep this glue here to make sure we convert from
|
||||
// the engine format to the cli format.
|
||||
//
|
||||
// This function will first attempt to cast directly to map[string]interface{},
|
||||
// which is possible for MK tests, and then use JSON serialization and
|
||||
// de-serialization only if that's required.
|
||||
func MakeGenericTestKeys(m model.Measurement) (map[string]interface{}, error) {
|
||||
if result, ok := m.TestKeys.(map[string]interface{}); ok {
|
||||
return result, nil
|
||||
}
|
||||
data, err := json.Marshal(m.TestKeys)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result map[string]interface{}
|
||||
err = json.Unmarshal(data, &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// LocationProvider is an interface that returns the current location. The
|
||||
// github.com/ooni/probe-engine/session.Session implements it.
|
||||
type LocationProvider interface {
|
||||
|
||||
Reference in New Issue
Block a user