fix(ooniprobe): use ooniprobe-cli-unattended for unattended runs (#714)

This diff changes the software name used by unattended runs for which
we did not override the default software name (`ooniprobe-cli`).

It will become `ooniprobe-cli-unattended`. This software name is in line
with the one we use for Android, iOS, and desktop unattended runs.

While working in this diff, I introduced string constants for the run
types and a string constant for the default software name.

See https://github.com/ooni/probe/issues/2081.
This commit is contained in:
Simone Basso
2022-04-29 13:41:09 +02:00
committed by GitHub
parent 596bdf6e57
commit d3c5196474
19 changed files with 72 additions and 37 deletions
+17 -5
View File
@@ -17,10 +17,14 @@ import (
"github.com/ooni/probe-cli/v3/internal/engine"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/assetsdir"
"github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/model"
"github.com/pkg/errors"
"upper.io/db.v3/lib/sqlbuilder"
)
// DefaultSoftwareName is the default software name.
const DefaultSoftwareName = "ooniprobe-cli"
// ProbeCLI is the OONI Probe CLI context.
type ProbeCLI interface {
Config() *config.Config
@@ -28,7 +32,7 @@ type ProbeCLI interface {
IsBatch() bool
Home() string
TempDir() string
NewProbeEngine(ctx context.Context) (ProbeEngine, error)
NewProbeEngine(ctx context.Context, runType model.RunType) (ProbeEngine, error)
}
// ProbeEngine is an instance of the OONI Probe engine.
@@ -199,7 +203,7 @@ func (p *Probe) Init(softwareName, softwareVersion string) error {
// NewSession creates a new ooni/probe-engine session using the
// current configuration inside the context. The caller must close
// the session when done using it, by calling sess.Close().
func (p *Probe) NewSession(ctx context.Context) (*engine.Session, error) {
func (p *Probe) NewSession(ctx context.Context, runType model.RunType) (*engine.Session, error) {
kvstore, err := kvstore.NewFS(
utils.EngineDir(p.home),
)
@@ -209,10 +213,18 @@ func (p *Probe) NewSession(ctx context.Context) (*engine.Session, error) {
if err := os.MkdirAll(p.tunnelDir, 0700); err != nil {
return nil, errors.Wrap(err, "creating tunnel dir")
}
// When the software name is the default software name and we're running
// in unattended mode, adjust the software name accordingly.
//
// See https://github.com/ooni/probe/issues/2081.
softwareName := p.softwareName
if runType == model.RunTypeTimed && softwareName == DefaultSoftwareName {
softwareName = DefaultSoftwareName + "-unattended"
}
return engine.NewSession(ctx, engine.SessionConfig{
KVStore: kvstore,
Logger: enginex.Logger,
SoftwareName: p.softwareName,
SoftwareName: softwareName,
SoftwareVersion: p.softwareVersion,
TempDir: p.tempDir,
TunnelDir: p.tunnelDir,
@@ -220,8 +232,8 @@ func (p *Probe) NewSession(ctx context.Context) (*engine.Session, error) {
}
// NewProbeEngine creates a new ProbeEngine instance.
func (p *Probe) NewProbeEngine(ctx context.Context) (ProbeEngine, error) {
sess, err := p.NewSession(ctx)
func (p *Probe) NewProbeEngine(ctx context.Context, runType model.RunType) (ProbeEngine, error) {
sess, err := p.NewSession(ctx, runType)
if err != nil {
return nil, err
}