refactor(miniooni): divide et impera (#912)
This diff splits miniooni's implementation in smaller and more easily tractable blocks ahead of future refactoring. I'm trying to make `miniooni oonirun -i URL` as possible as `miniooni -i URL oonirun`, because users typically expect this kind of flexibity from modern Unix commands. Part of https://github.com/ooni/probe/issues/2184
This commit is contained in:
parent
196ac55493
commit
7daa686c68
9 changed files with 351 additions and 247 deletions
53
internal/cmd/miniooni/consent.go
Normal file
53
internal/cmd/miniooni/consent.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package main
|
||||
|
||||
//
|
||||
// Acquiring user's consent
|
||||
//
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
|
||||
// acquireUserConsent ensures the user is okay with using miniooni. This function
|
||||
// panics if we do not have acquired the user consent.
|
||||
func acquireUserConsent(miniooniDir string, currentOptions Options) {
|
||||
consentFile := path.Join(miniooniDir, "informed")
|
||||
err := maybeWriteConsentFile(currentOptions.Yes, consentFile)
|
||||
runtimex.PanicOnError(err, "cannot write informed consent file")
|
||||
runtimex.PanicIfFalse(regularFileExists(consentFile), riskOfRunningOONI)
|
||||
}
|
||||
|
||||
// maybeWriteConsentFile writes the consent file iff the yes argument is true
|
||||
func maybeWriteConsentFile(yes bool, filepath string) (err error) {
|
||||
if yes {
|
||||
err = os.WriteFile(filepath, []byte("\n"), 0644)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// riskOfRunningOONI is miniooni's informed consent text.
|
||||
const riskOfRunningOONI = `
|
||||
Do you consent to OONI Probe data collection?
|
||||
|
||||
OONI Probe collects evidence of internet censorship and measures
|
||||
network performance:
|
||||
|
||||
- OONI Probe will likely test objectionable sites and services;
|
||||
|
||||
- Anyone monitoring your internet activity (such as a government
|
||||
or Internet provider) may be able to tell that you are using OONI Probe;
|
||||
|
||||
- The network data you collect will be published automatically
|
||||
unless you use miniooni's -n command line flag.
|
||||
|
||||
To learn more, see https://ooni.org/about/risks/.
|
||||
|
||||
If you're onboard, re-run the same command and add the --yes flag, to
|
||||
indicate that you understand the risks. This will create an empty file
|
||||
named 'consent' in $HOME/.miniooni, meaning that we know you opted in
|
||||
and we will not ask you this question again.
|
||||
|
||||
`
|
||||
Loading…
Reference in a new issue