forked from ooni/probe-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oonirun.go
64 lines (60 loc) · 2.05 KB
/
oonirun.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
//
// OONI Run
//
import (
"context"
"encoding/json"
"errors"
"os"
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/oonirun"
)
// 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) {
logger := sess.Logger()
cfg := &oonirun.LinkConfig{
AcceptChanges: currentOptions.Yes,
AuthFile: currentOptions.AuthFile,
Annotations: annotations,
KVStore: sess.KeyValueStore(),
MaxRuntime: currentOptions.MaxRuntime,
NoCollector: currentOptions.NoCollector,
NoJSON: currentOptions.NoJSON,
Random: currentOptions.Random,
ReportFile: currentOptions.ReportFile,
Session: sess,
}
for _, URL := range currentOptions.Inputs {
r := oonirun.NewLinkRunner(cfg, URL)
if err := r.Run(ctx); err != nil {
if errors.Is(err, oonirun.ErrNeedToAcceptChanges) {
logger.Warnf("oonirun: to accept these changes, rerun adding `-y` to the command line")
logger.Warnf("oonirun: we'll show this error every time the upstream link changes")
panic("oonirun: need to accept changes using `-y`")
}
logger.Warnf("oonirun: running link failed: %s", err.Error())
continue
}
}
for _, filename := range currentOptions.InputFilePaths {
data, err := os.ReadFile(filename) // #nosec G304 - this is working as intended
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
}
logger.Infof("oonirun: running '%s'", descr.Name)
logger.Infof("oonirun: link authored by '%s'", descr.Author)
if err := oonirun.V2MeasureDescriptor(ctx, cfg, &descr); err != nil {
logger.Warnf("oonirun: running link failed: %s", err.Error())
continue
}
}
}