cli: add support for passing proxy command line parameter (#981)
This implements the bare minimum needed to have circumvention proxy support in OONI Probe CLI. The reference issue is https://github.com/ooni/probe/issues/1955. (Most of that issue is implemented, save for the fact that currently we do not have support for `http` and `https` proxies.) While there, add to `Makefile` a rule for correctly building `ooniprobe` and `miniooni` for "this system" (i.e., the default `GOOS` and `GOARCH` on a system), because we needed this for testing this patch and we needed to figure out the commands instead.
This commit is contained in:
@@ -44,6 +44,9 @@ func init() {
|
||||
softwareVersion := Cmd.Flag(
|
||||
"software-version", "Override the application version",
|
||||
).Default(version.Version).String()
|
||||
proxy := Cmd.Flag(
|
||||
"proxy", "specify a proxy address for speaking to the OONI Probe backend (use: --proxy=psiphon:/// for psiphon)",
|
||||
).String()
|
||||
|
||||
Cmd.PreAction(func(ctx *kingpin.ParseContext) error {
|
||||
// TODO(bassosimone): we need to properly deprecate --batch
|
||||
@@ -78,7 +81,7 @@ func init() {
|
||||
}
|
||||
|
||||
probe := ooni.NewProbe(*configPath, homePath)
|
||||
err = probe.Init(*softwareName, *softwareVersion)
|
||||
err = probe.Init(*softwareName, *softwareVersion, *proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func newOONIProbe(t *testing.T) *ooni.Probe {
|
||||
probe := ooni.NewProbe(configPath, homePath)
|
||||
swName := "ooniprobe-cli-tests"
|
||||
swVersion := "3.0.0-alpha"
|
||||
err = probe.Init(swName, swVersion)
|
||||
err = probe.Init(swName, swVersion, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
_ "embed" // because we embed a file
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
@@ -62,6 +63,7 @@ type Probe struct {
|
||||
|
||||
softwareName string
|
||||
softwareVersion string
|
||||
proxyURL *url.URL
|
||||
}
|
||||
|
||||
// SetIsBatch sets the value of isBatch.
|
||||
@@ -124,7 +126,7 @@ func (p *Probe) ListenForSignals() {
|
||||
// MaybeListenForStdinClosed will treat any error on stdin just
|
||||
// like SIGTERM if and only if
|
||||
//
|
||||
// os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") == "true"
|
||||
// os.Getenv("OONI_STDIN_EOF_IMPLIES_SIGTERM") == "true"
|
||||
//
|
||||
// When this feature is enabled, a collateral effect is that we swallow
|
||||
// whatever is passed to us on the standard input.
|
||||
@@ -151,7 +153,7 @@ func (p *Probe) MaybeListenForStdinClosed() {
|
||||
}
|
||||
|
||||
// Init the OONI manager
|
||||
func (p *Probe) Init(softwareName, softwareVersion string) error {
|
||||
func (p *Probe) Init(softwareName, softwareVersion, proxy string) error {
|
||||
var err error
|
||||
|
||||
if err = MaybeInitializeHome(p.home); err != nil {
|
||||
@@ -197,6 +199,12 @@ func (p *Probe) Init(softwareName, softwareVersion string) error {
|
||||
|
||||
p.softwareName = softwareName
|
||||
p.softwareVersion = softwareVersion
|
||||
if proxy != "" {
|
||||
p.proxyURL, err = url.Parse(proxy)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid proxy URL")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -228,6 +236,7 @@ func (p *Probe) NewSession(ctx context.Context, runType model.RunType) (*engine.
|
||||
SoftwareVersion: p.softwareVersion,
|
||||
TempDir: p.tempDir,
|
||||
TunnelDir: p.tunnelDir,
|
||||
ProxyURL: p.proxyURL,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestInit(t *testing.T) {
|
||||
probe := NewProbe("", ooniHome)
|
||||
swName := "ooniprobe-cli-tests"
|
||||
swVersion := "3.0.0-alpha"
|
||||
if err := probe.Init(swName, swVersion); err != nil {
|
||||
if err := probe.Init(swName, swVersion, ""); err != nil {
|
||||
t.Error(err)
|
||||
t.Fatal("failed to init the context")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user