Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,22 @@ To turn it off, set any of these in the environment the game runs in:
- `TRACE_USAGE_REPORTING=off` (also `false`, `0`, `no`) — turns off every program that reports to trace
- `DO_NOT_TRACK=1` (also `true`, `yes`) — the [console DNT convention](https://consoledonottrack.com), honoured the same way

Every switch fails closed, so an opt-out is never read as "on": `FISHE_USAGE_REPORTING_ENABLED`, once set, keeps reporting on only for `true`, `on`, `yes` or `1` (any case) and turns it off for anything else, an empty value or a typo included; `TRACE_USAGE_REPORTING` set to anything but blank or one of those values turns it off; `DO_NOT_TRACK` set to anything but blank, `0`, `false`, `off` or `no` turns it off.

```bash
FISHE_USAGE_REPORTING_ENABLED=false python3 src/fishE.py
```

| Variable | Default | What it does |
|---|---|---|
| `FISHE_USAGE_REPORTING_ENABLED` | `true` | `false`, `0`, `no` or `off` turns reporting off. |
| `FISHE_USAGE_REPORTING_ENABLED` | `true` | `false`, `0`, `no` or `off` turns reporting off — so does any value but `true`, `on`, `yes` or `1`, empty included. |
| `FISHE_USAGE_REPORTING_ENDPOINT` | `https://trace.danielstephenson.dev` | Where events are sent — a self-hosted trace, or a local stub. |
| `FISHE_USAGE_REPORTING_KEY` | the key issued to FishE | The program key sent with each event. |
| `TRACE_USAGE_REPORTING` | unset | `off`, `false`, `0` or `no` turns reporting off, for FishE and every other trace client. |
| `DO_NOT_TRACK` | unset | `1`, `true` or `yes` turns reporting off the same way. |
| `TRACE_USAGE_REPORTING` | unset | `off`, `false`, `0` or `no` (any value but blank, `true`, `on`, `yes` or `1`) turns reporting off, for FishE and every other trace client. |
| `DO_NOT_TRACK` | unset | `1`, `true` or `yes` (any value but blank, `0`, `false`, `off` or `no`) turns reporting off the same way. |
| `TRACE_INSTALL_ID` | unset | Sent as the installation ID instead of the one in `trace-install-id`, which is then left alone — to pin one for a container or service. |

The test suite switches reporting off for every test (`tests/conftest.py`), and the tests that exercise it point at a loopback stub server, so running the tests never reports anything either. The client is `src/trace_client.py`, vendored as one standard-library file from [trace-client-python](https://github.com/Stephenson-Software/trace-client-python) (0.4.1); the wiring is `src/usageReporting.py`.
The test suite switches reporting off for every test (`tests/conftest.py`), and the tests that exercise it point at a loopback stub server, so running the tests never reports anything either. The client is `src/trace_client.py`, vendored as one standard-library file from [trace-client-python](https://github.com/Stephenson-Software/trace-client-python) (0.5.0); the wiring is `src/usageReporting.py`.

Details: https://danielstephenson.dev/usage-reporting

Expand Down
30 changes: 16 additions & 14 deletions src/config/config.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import os

from trace_client import allows_reporting

# Usage reporting (see src/usageReporting.py). The key is the program key the
# trace service issued to FishE; it identifies the program, not the player,
# and is bundled so an install that never sets FISHE_USAGE_REPORTING_KEY still
# reports.
USAGE_REPORTING_ENDPOINT_DEFAULT = "https://trace.danielstephenson.dev"
USAGE_REPORTING_KEY_DEFAULT = "_zbWO4qi0bhg9RoKxYXCCy93D36R5dF0Sa5xCiR180E"

# Values that switch a FISHE_* boolean off. Anything else - including unset
# and empty - leaves the default in place, matching FISHE_SAVE_DIR above.
_FALSE_VALUES = ("0", "false", "no", "off")


def _environmentFlag(name, default):
"""Read a boolean FISHE_* variable, falling back to default when it is
unset or empty so a compose file with `NAME=` doesn't flip the switch."""
value = os.environ.get(name, "").strip().lower()
if not value:
return default
return value not in _FALSE_VALUES
def _usageReportingEnabled(name):
"""Read FishE's own usage-reporting switch. Unset means the default, on.
Once set, it fails closed: it is read through the trace client's
allows_reporting, so only true, on, yes or 1 (any case) keeps reporting
on, and anything else - false, off, no, 0, empty, a typo - turns it off.
An opt-out is never read as on."""
value = os.environ.get(name)
if value is None:
return True
return allows_reporting(value)


# @author Daniel McCoy Stephenson
Expand All @@ -41,11 +42,12 @@ def __init__(self):

# Usage reporting: one startup event (and one when a save is opened)
# to the trace service, program name and version only. On by default;
# FISHE_USAGE_REPORTING_ENABLED=false is the opt-out. The endpoint and
# FISHE_USAGE_REPORTING_ENABLED=false is the opt-out, and anything but
# true/on/yes/1 counts as one (see _usageReportingEnabled). The endpoint and
# key overrides exist so a self-hosted trace can be pointed at, and so
# tests can aim the client at a loopback stub instead of production.
self.usageReportingEnabled = _environmentFlag(
"FISHE_USAGE_REPORTING_ENABLED", True
self.usageReportingEnabled = _usageReportingEnabled(
"FISHE_USAGE_REPORTING_ENABLED"
)
self.usageReportingEndpoint = (
os.environ.get("FISHE_USAGE_REPORTING_ENDPOINT", "").strip()
Expand Down
Loading
Loading