refactor(internal/ooni): Context => Probe (#170)
Closes https://github.com/ooni/probe/issues/939
This commit is contained in:
parent
163922e001
commit
9e238c27dd
8 changed files with 90 additions and 90 deletions
|
|
@ -137,12 +137,12 @@ func Onboarding(config *config.Config) error {
|
|||
|
||||
// MaybeOnboarding will run the onboarding process only if the informed consent
|
||||
// config option is set to false
|
||||
func MaybeOnboarding(c *ooni.Context) error {
|
||||
if c.Config.InformedConsent == false {
|
||||
if c.IsBatch == true {
|
||||
func MaybeOnboarding(probe *ooni.Probe) error {
|
||||
if probe.Config.InformedConsent == false {
|
||||
if probe.IsBatch == true {
|
||||
return errors.New("cannot run onboarding in batch mode")
|
||||
}
|
||||
if err := Onboarding(c.Config); err != nil {
|
||||
if err := Onboarding(probe.Config); err != nil {
|
||||
return errors.Wrap(err, "onboarding")
|
||||
}
|
||||
}
|
||||
|
|
@ -155,26 +155,26 @@ func init() {
|
|||
yes := cmd.Flag("yes", "Answer yes to all the onboarding questions.").Bool()
|
||||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
ctx, err := root.Init()
|
||||
probe, err := root.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if *yes == true {
|
||||
ctx.Config.Lock()
|
||||
ctx.Config.InformedConsent = true
|
||||
ctx.Config.Unlock()
|
||||
probe.Config.Lock()
|
||||
probe.Config.InformedConsent = true
|
||||
probe.Config.Unlock()
|
||||
|
||||
if err := ctx.Config.Write(); err != nil {
|
||||
if err := probe.Config.Write(); err != nil {
|
||||
log.WithError(err).Error("failed to write config file")
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if ctx.IsBatch == true {
|
||||
if probe.IsBatch == true {
|
||||
return errors.New("cannot do onboarding in batch mode")
|
||||
}
|
||||
|
||||
return Onboarding(ctx.Config)
|
||||
return Onboarding(probe.Config)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ var Cmd = kingpin.New("ooniprobe", "")
|
|||
var Command = Cmd.Command
|
||||
|
||||
// Init should be called by all subcommand that care to have a ooni.Context instance
|
||||
var Init func() (*ooni.Context, error)
|
||||
var Init func() (*ooni.Probe, error)
|
||||
|
||||
func init() {
|
||||
configPath := Cmd.Flag("config", "Set a custom config file path").Short('c').String()
|
||||
|
|
@ -43,7 +43,7 @@ func init() {
|
|||
log.Debugf("ooni version %s", version.Version)
|
||||
}
|
||||
|
||||
Init = func() (*ooni.Context, error) {
|
||||
Init = func() (*ooni.Probe, error) {
|
||||
var err error
|
||||
|
||||
homePath, err := utils.GetOONIHome()
|
||||
|
|
@ -51,16 +51,16 @@ func init() {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
ctx := ooni.NewContext(*configPath, homePath)
|
||||
err = ctx.Init(*softwareName, *softwareVersion)
|
||||
probe := ooni.NewProbe(*configPath, homePath)
|
||||
err = probe.Init(*softwareName, *softwareVersion)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if *isBatch {
|
||||
ctx.IsBatch = true
|
||||
probe.IsBatch = true
|
||||
}
|
||||
|
||||
return ctx, nil
|
||||
return probe, nil
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/ooni/probe-cli/internal/ooni"
|
||||
)
|
||||
|
||||
func runNettestGroup(tg string, ctx *ooni.Context, network *database.Network) error {
|
||||
func runNettestGroup(tg string, ctx *ooni.Probe, network *database.Network) error {
|
||||
if ctx.IsTerminated() == true {
|
||||
log.Debugf("context is terminated, stopping runNettestGroup early")
|
||||
return nil
|
||||
|
|
@ -79,7 +79,7 @@ func init() {
|
|||
cmd := root.Command("run", "Run a test group or OONI Run link")
|
||||
|
||||
var nettestGroupNamesBlue []string
|
||||
var ctx *ooni.Context
|
||||
var probe *ooni.Probe
|
||||
var network *database.Network
|
||||
|
||||
for name := range nettests.NettestGroups {
|
||||
|
|
@ -90,48 +90,48 @@ func init() {
|
|||
|
||||
cmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
var err error
|
||||
ctx, err = root.Init()
|
||||
probe, err = root.Init()
|
||||
if err != nil {
|
||||
log.Errorf("%s", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = onboard.MaybeOnboarding(ctx); err != nil {
|
||||
if err = onboard.MaybeOnboarding(probe); err != nil {
|
||||
log.WithError(err).Error("failed to perform onboarding")
|
||||
return err
|
||||
}
|
||||
|
||||
if *noCollector == true {
|
||||
ctx.Config.Sharing.UploadResults = false
|
||||
probe.Config.Sharing.UploadResults = false
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
websitesCmd := cmd.Command("websites", "")
|
||||
websitesCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return runNettestGroup("websites", ctx, network)
|
||||
return runNettestGroup("websites", probe, network)
|
||||
})
|
||||
imCmd := cmd.Command("im", "")
|
||||
imCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return runNettestGroup("im", ctx, network)
|
||||
return runNettestGroup("im", probe, network)
|
||||
})
|
||||
performanceCmd := cmd.Command("performance", "")
|
||||
performanceCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return runNettestGroup("performance", ctx, network)
|
||||
return runNettestGroup("performance", probe, network)
|
||||
})
|
||||
middleboxCmd := cmd.Command("middlebox", "")
|
||||
middleboxCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return runNettestGroup("middlebox", ctx, network)
|
||||
return runNettestGroup("middlebox", probe, network)
|
||||
})
|
||||
circumventionCmd := cmd.Command("circumvention", "")
|
||||
circumventionCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
return runNettestGroup("circumvention", ctx, network)
|
||||
return runNettestGroup("circumvention", probe, network)
|
||||
})
|
||||
allCmd := cmd.Command("all", "").Default()
|
||||
allCmd.Action(func(_ *kingpin.ParseContext) error {
|
||||
log.Infof("Running %s tests", color.BlueString("all"))
|
||||
for tg := range nettests.NettestGroups {
|
||||
if err := runNettestGroup(tg, ctx, network); err != nil {
|
||||
if err := runNettestGroup(tg, probe, network); err != nil {
|
||||
log.WithError(err).Errorf("failed to run %s", tg)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue