Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e378170df |
@@ -23,13 +23,13 @@
|
|||||||
"mqtt-topic": {}
|
"mqtt-topic": {}
|
||||||
},
|
},
|
||||||
"receives": {
|
"receives": {
|
||||||
"mqtt-topic": "${dir:grants}/mesh.json"
|
"mqtt-topic": "/var/lib/mosquitto-module/grants/mesh.json"
|
||||||
},
|
},
|
||||||
"grants": {
|
"grants": {
|
||||||
"mqtt-topic": "${dir:grants}"
|
"mqtt-topic": "/var/lib/mosquitto-module/grants"
|
||||||
},
|
},
|
||||||
"own-secrets": {
|
"own-secrets": {
|
||||||
"admin": "/var/lib/mesh/mosquitto/admin",
|
"admin": "/var/lib/mosquitto-module/admin.secret",
|
||||||
"broker": "/var/lib/mesh/mosquitto/broker"
|
"broker": "/var/lib/mesh/mosquitto/broker"
|
||||||
},
|
},
|
||||||
"listens": [
|
"listens": [
|
||||||
@@ -58,24 +58,26 @@
|
|||||||
{
|
{
|
||||||
"id": "state",
|
"id": "state",
|
||||||
"type": "directory",
|
"type": "directory",
|
||||||
"mode": "0700",
|
"path": "/var/lib/mosquitto-module",
|
||||||
"place": "."
|
"mode": "0700"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "grants",
|
"id": "grants-dir",
|
||||||
"type": "directory",
|
"type": "directory",
|
||||||
|
"path": "/var/lib/mosquitto-module/grants",
|
||||||
"mode": "0700"
|
"mode": "0700"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "data",
|
"id": "data",
|
||||||
"type": "directory",
|
"type": "directory",
|
||||||
|
"path": "/services/mosquitto/data",
|
||||||
"mode": "0700",
|
"mode": "0700",
|
||||||
"owner": "1883:1883"
|
"owner": "1883:1883"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "server-conf",
|
"id": "server-conf",
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"path": "${dir:state}/mosquitto.conf",
|
"path": "/var/lib/mosquitto-module/mosquitto.conf",
|
||||||
"mode": "0600",
|
"mode": "0600",
|
||||||
"owner": "1883:1883",
|
"owner": "1883:1883",
|
||||||
"content": "persistence true\npersistence_location /mosquitto/data\n\nlog_dest stdout\nlog_type warning\nlog_type error\nlog_type notice\n\n# Every client authenticates; identities and their per-topic ACLs are managed\n# at runtime by the dynamic security plugin, whose store the plugin itself owns.\nallow_anonymous false\nplugin /usr/lib/mosquitto_dynamic_security.so\nplugin_opt_config_file /mosquitto/data/dynamic-security.json\n\n# MQTT listener\nlistener 1883\n\n# MQTT-over-WebSockets listener\nlistener 8081\nprotocol websockets\n"
|
"content": "persistence true\npersistence_location /mosquitto/data\n\nlog_dest stdout\nlog_type warning\nlog_type error\nlog_type notice\n\n# Every client authenticates; identities and their per-topic ACLs are managed\n# at runtime by the dynamic security plugin, whose store the plugin itself owns.\nallow_anonymous false\nplugin /usr/lib/mosquitto_dynamic_security.so\nplugin_opt_config_file /mosquitto/data/dynamic-security.json\n\n# MQTT listener\nlistener 1883\n\n# MQTT-over-WebSockets listener\nlistener 8081\nprotocol websockets\n"
|
||||||
@@ -91,8 +93,8 @@
|
|||||||
"name": "mosquitto-bootstrap",
|
"name": "mosquitto-bootstrap",
|
||||||
"run-once": true,
|
"run-once": true,
|
||||||
"volumes": [
|
"volumes": [
|
||||||
"${dir:data}:/mosquitto/data",
|
"/services/mosquitto/data:/mosquitto/data",
|
||||||
"/var/lib/mesh/mosquitto/admin:/run/secrets/admin:ro"
|
"/var/lib/mosquitto-module/admin.secret:/run/secrets/admin:ro"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"MESH_PROVISION_MQTT": "mosquitto:1883",
|
"MESH_PROVISION_MQTT": "mosquitto:1883",
|
||||||
@@ -110,15 +112,15 @@
|
|||||||
"id": "server",
|
"id": "server",
|
||||||
"type": "container",
|
"type": "container",
|
||||||
"name": "mosquitto",
|
"name": "mosquitto",
|
||||||
"image": "eclipse-mosquitto@sha256:38c0da4f2ef84284d47b3b3eeea1cb3bdeabe81ee10caf0cd5c5ff61ee3ea408",
|
"image": "eclipse-mosquitto@sha256:6f8d8a947c506f8a2290ec65cd4bd2bc7cb4d43fb5f6271f861cb013e2ef9797",
|
||||||
"network": "mosquitto",
|
"network": "mosquitto",
|
||||||
"ports": [
|
"ports": [
|
||||||
"1883",
|
"1883",
|
||||||
"8081"
|
"8081"
|
||||||
],
|
],
|
||||||
"volumes": [
|
"volumes": [
|
||||||
"${dir:data}:/mosquitto/data",
|
"/services/mosquitto/data:/mosquitto/data",
|
||||||
"${dir:state}/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro"
|
"/var/lib/mosquitto-module/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -128,8 +130,8 @@
|
|||||||
"network": "mosquitto",
|
"network": "mosquitto",
|
||||||
"volumes": [
|
"volumes": [
|
||||||
"/var/lib/mesh/mosquitto/broker:/run/secrets/broker:ro",
|
"/var/lib/mesh/mosquitto/broker:/run/secrets/broker:ro",
|
||||||
"${dir:grants}:/var/lib/mosquitto-module/grants:ro",
|
"/var/lib/mosquitto-module/grants:/var/lib/mosquitto-module/grants:ro",
|
||||||
"/var/lib/mesh/mosquitto/admin:/run/secrets/admin:ro"
|
"/var/lib/mosquitto-module/admin.secret:/run/secrets/admin:ro"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"MESH_BROKER_FILE": "/run/secrets/broker",
|
"MESH_BROKER_FILE": "/run/secrets/broker",
|
||||||
|
|||||||
@@ -41,6 +41,32 @@ function meshConfig(file?: string): Record<string, string> {
|
|||||||
catch { return {}; }
|
catch { return {}; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The API key Tautulli minted for itself, read from its own config.ini (mounted read-only).
|
||||||
|
*
|
||||||
|
* Tautulli owns this key: it writes it on first run and every client of its API — this runtime
|
||||||
|
* included — must present the same one. So the mesh does not mint or hold it; the one place it
|
||||||
|
* lives is the file Tautulli keeps, and a key regenerated in Tautulli's settings is simply read
|
||||||
|
* again on the next start. Undefined when there is no file or no key yet (a fresh install whose
|
||||||
|
* setup wizard has not run).
|
||||||
|
*/
|
||||||
|
function keyOfTautulli(dir?: string): string | undefined {
|
||||||
|
if (!dir) return undefined;
|
||||||
|
let ini: string;
|
||||||
|
try { ini = readFileSync(`${dir.replace(/\/$/, "")}/config.ini`, "utf8"); }
|
||||||
|
catch { return undefined; }
|
||||||
|
let section = "";
|
||||||
|
for (const raw of ini.split(/\r?\n/)) {
|
||||||
|
const line = raw.trim();
|
||||||
|
const header = /^\[(.+)\]$/.exec(line);
|
||||||
|
if (header) { section = header[1]; continue; }
|
||||||
|
if (section !== "General") continue;
|
||||||
|
const kv = /^api_key\s*=\s*"?([^"]*)"?$/.exec(line);
|
||||||
|
if (kv && kv[1]) return kv[1];
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
export class TautulliClient {
|
export class TautulliClient {
|
||||||
readonly baseUrl: string;
|
readonly baseUrl: string;
|
||||||
|
|
||||||
@@ -52,15 +78,16 @@ export class TautulliClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build from the module's resolved environment. The API key is read from MESH_TAUTULLI_APIKEY
|
* Build from the module's resolved environment. The API key is the one Tautulli minted for
|
||||||
* (Tautulli mints it in Settings → Web Interface); the base URL defaults to the local container.
|
* itself (Settings → Web Interface), read from its config.ini under MESH_TAUTULLI_CONFIG_DIR;
|
||||||
|
* MESH_TAUTULLI_APIKEY still wins where it is set. The base URL defaults to the local container.
|
||||||
* Throws when no key is configured — the module then contributes nothing rather than failing.
|
* Throws when no key is configured — the module then contributes nothing rather than failing.
|
||||||
*/
|
*/
|
||||||
static fromEnv(env: NodeJS.ProcessEnv = process.env): TautulliClient {
|
static fromEnv(env: NodeJS.ProcessEnv = process.env): TautulliClient {
|
||||||
const cfg = meshConfig(env.MESH_TAUTULLI_CONFIG_FILE);
|
const cfg = meshConfig(env.MESH_TAUTULLI_CONFIG_FILE);
|
||||||
const url = cfg.url ?? (env.MESH_TAUTULLI_URL ?? `http://127.0.0.1:${env.TAUTULLI_PORT ?? "8181"}`);
|
const url = cfg.url ?? (env.MESH_TAUTULLI_URL ?? `http://127.0.0.1:${env.TAUTULLI_PORT ?? "8181"}`);
|
||||||
const apiKey = cfg.apiKey ?? env.MESH_TAUTULLI_APIKEY;
|
const apiKey = cfg.apiKey ?? env.MESH_TAUTULLI_APIKEY ?? keyOfTautulli(env.MESH_TAUTULLI_CONFIG_DIR);
|
||||||
if (!apiKey) throw new Error("no Tautulli API key — set MESH_TAUTULLI_APIKEY");
|
if (!apiKey) throw new Error("no Tautulli API key — Tautulli's config.ini has none yet (finish its setup and enable the API)");
|
||||||
return new TautulliClient(url, apiKey);
|
return new TautulliClient(url, apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
"port": 8181,
|
"port": 8181,
|
||||||
"protocol": "tcp",
|
"protocol": "tcp",
|
||||||
"from": "mesh",
|
"from": "mesh",
|
||||||
"why": "watch statistics"
|
"why": "the watch statistics pages and API"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"resources": [
|
"resources": [
|
||||||
@@ -26,10 +26,15 @@
|
|||||||
"path": "/var/lib/mesh/tautulli",
|
"path": "/var/lib/mesh/tautulli",
|
||||||
"mode": "0700"
|
"mode": "0700"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "state",
|
||||||
|
"type": "directory",
|
||||||
|
"mode": "0700",
|
||||||
|
"place": "."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "config",
|
"id": "config",
|
||||||
"type": "directory",
|
"type": "directory",
|
||||||
"path": "/services/tautulli/config",
|
|
||||||
"mode": "0700",
|
"mode": "0700",
|
||||||
"owner": "1000:1000"
|
"owner": "1000:1000"
|
||||||
},
|
},
|
||||||
@@ -37,7 +42,7 @@
|
|||||||
"id": "server",
|
"id": "server",
|
||||||
"type": "container",
|
"type": "container",
|
||||||
"name": "tautulli",
|
"name": "tautulli",
|
||||||
"image": "lscr.io/linuxserver/tautulli@sha256:13f03ecfc61a7af89d492677389771ac29682a72153ce08a5cd4faffbc0197e8",
|
"image": "lscr.io/linuxserver/tautulli@sha256:e35570d636471f8aabfac7044057712679f954844a763ba735baa9659ea142b5",
|
||||||
"env": {
|
"env": {
|
||||||
"PUID": "1000",
|
"PUID": "1000",
|
||||||
"PGID": "1000",
|
"PGID": "1000",
|
||||||
@@ -47,7 +52,7 @@
|
|||||||
"8181"
|
"8181"
|
||||||
],
|
],
|
||||||
"volumes": [
|
"volumes": [
|
||||||
"/services/tautulli/config:/config"
|
"${dir:config}:/config"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -66,11 +71,11 @@
|
|||||||
"volumes": [
|
"volumes": [
|
||||||
"/var/lib/mesh/tautulli/broker:/run/secrets/broker:ro",
|
"/var/lib/mesh/tautulli/broker:/run/secrets/broker:ro",
|
||||||
"/var/lib/mesh/tautulli/config.json:/run/config/config.json:ro",
|
"/var/lib/mesh/tautulli/config.json:/run/config/config.json:ro",
|
||||||
"/services/tautulli/config:/var/lib/tautulli/config:ro"
|
"${dir:config}:/var/lib/tautulli/config:ro"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"MESH_BROKER_FILE": "/run/secrets/broker",
|
"MESH_BROKER_FILE": "/run/secrets/broker",
|
||||||
"MESH_TAUTULLI_URL": "http://127.0.0.1:8181",
|
"MESH_TAUTULLI_URL": "http://127.0.0.1:${port:8181}",
|
||||||
"MESH_TAUTULLI_CONFIG_FILE": "/run/config/config.json",
|
"MESH_TAUTULLI_CONFIG_FILE": "/run/config/config.json",
|
||||||
"MESH_TAUTULLI_CONFIG_DIR": "/var/lib/tautulli/config"
|
"MESH_TAUTULLI_CONFIG_DIR": "/var/lib/tautulli/config"
|
||||||
},
|
},
|
||||||
@@ -90,7 +95,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"binds": {
|
"binds": {
|
||||||
"route": "/var/lib/mesh/tautulli/route.json"
|
"route": "${dir:state}/route.json"
|
||||||
},
|
},
|
||||||
"build": {
|
"build": {
|
||||||
"on": [
|
"on": [
|
||||||
|
|||||||
Reference in New Issue
Block a user