feat(miniooni): add the --censor flag (#571)

This flag is similar to the previous --self-censor-spec and tells
miniooni what censorship to implement for itself.

This concludes the design at https://github.com/ooni/probe/issues/1803#issuecomment-957323297
This commit is contained in:
Simone Basso 2021-11-03 14:23:47 +01:00 committed by GitHub
parent 100cc559a2
commit 6f90d29bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,9 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/humanize"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/netxlite"
"github.com/ooni/probe-cli/v3/internal/netxlite/filtering"
"github.com/ooni/probe-cli/v3/internal/runtimex"
"github.com/ooni/probe-cli/v3/internal/version"
"github.com/pborman/getopt/v2"
)
@ -27,6 +30,7 @@ import (
// Options contains the options you can set from the CLI.
type Options struct {
Annotations []string
Censor string
ExtraOptions []string
HomeDir string
Inputs []string
@ -61,6 +65,10 @@ func init() {
getopt.FlagLong(
&globalOptions.Annotations, "annotation", 'A', "Add annotaton", "KEY=VALUE",
)
getopt.FlagLong(
&globalOptions.Censor, "censor", 0,
"Specifies censorship rules to apply for QA purposes", "FILE",
)
getopt.FlagLong(
&globalOptions.ExtraOptions, "option", 'O',
"Pass an option to the experiment", "KEY=VALUE",
@ -307,6 +315,17 @@ func MainWithConfiguration(experimentName string, currentOptions Options) {
}
log.Log = logger
if currentOptions.Censor != "" {
config, err := filtering.NewTProxyConfig(currentOptions.Censor)
runtimex.PanicOnError(err, "cannot parse --censor file as JSON")
tproxy, err := filtering.NewTProxy(config, log.Log)
runtimex.PanicOnError(err, "cannot create tproxy instance")
defer tproxy.Close()
netxlite.TProxy = tproxy
log.Infof("miniooni: disabling submission with --censor to avoid pulluting OONI data")
currentOptions.NoCollector = true
}
//Mon Jan 2 15:04:05 -0700 MST 2006
log.Infof("Current time: %s", time.Now().Format("2006-01-02 15:04:05 MST"))