feat(miniooni): run local oonirun v2 descriptor (#966)
We introduce the -f, --input-file FILE option with which we are able to run an OONI Run v2 descriptor stored locally. In this running mode, there are no checks related to whether the descriptor has changed, since we're dealing with a local file. Closes https://github.com/ooni/probe/issues/2328
This commit is contained in:
@@ -196,6 +196,13 @@ func registerOONIRun(rootCmd *cobra.Command, globalOptions *Options) {
|
||||
[]string{},
|
||||
"URL of the OONI Run v2 descriptor to run (may be specified multiple times)",
|
||||
)
|
||||
flags.StringSliceVarP(
|
||||
&globalOptions.InputFilePaths,
|
||||
"input-file",
|
||||
"f",
|
||||
[]string{},
|
||||
"Path to the OONI Run v2 descriptor to run (may be specified multiple times)",
|
||||
)
|
||||
}
|
||||
|
||||
// registerAllExperiments registers a subcommand for each experiment
|
||||
|
||||
@@ -6,25 +6,18 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine"
|
||||
"github.com/ooni/probe-cli/v3/internal/oonirun"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
|
||||
// ooniRunMain runs the experiments described by the given OONI Run URLs. This
|
||||
// function works with both v1 and v2 OONI Run URLs.
|
||||
func ooniRunMain(ctx context.Context,
|
||||
sess *engine.Session, currentOptions *Options, annotations map[string]string) {
|
||||
runtimex.PanicIfTrue(
|
||||
len(currentOptions.Inputs) <= 0,
|
||||
"in oonirun mode you need to specify at least one URL using `-i URL`",
|
||||
)
|
||||
runtimex.PanicIfTrue(
|
||||
len(currentOptions.InputFilePaths) > 0,
|
||||
"in oonirun mode you cannot specify any `-f FILE` file",
|
||||
)
|
||||
logger := sess.Logger()
|
||||
cfg := &oonirun.LinkConfig{
|
||||
AcceptChanges: currentOptions.Yes,
|
||||
@@ -49,4 +42,20 @@ func ooniRunMain(ctx context.Context,
|
||||
continue
|
||||
}
|
||||
}
|
||||
for _, filename := range currentOptions.InputFilePaths {
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
logger.Warnf("oonirun: reading OONI Run v2 descriptor failed: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
var descr oonirun.V2Descriptor
|
||||
if err := json.Unmarshal(data, &descr); err != nil {
|
||||
logger.Warnf("oonirun: parsing OONI Run v2 descriptor failed: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
if err := oonirun.V2MeasureDescriptor(ctx, cfg, &descr); err != nil {
|
||||
logger.Warnf("oonirun: running link failed: %s", err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user