arr-init: fix bazarr API endpoint and update test
This commit is contained in:
@@ -366,26 +366,28 @@ let
|
|||||||
|
|
||||||
enabledInstances = lib.filterAttrs (_: inst: inst.enable) cfg;
|
enabledInstances = lib.filterAttrs (_: inst: inst.enable) cfg;
|
||||||
|
|
||||||
mkBazarrProviderSection = type: provider: ''
|
mkBazarrProviderSection = type: provider:
|
||||||
|
let
|
||||||
|
ltype = lib.toLower type;
|
||||||
|
in ''
|
||||||
# ${type} provider
|
# ${type} provider
|
||||||
echo "Checking ${type} provider..."
|
echo "Checking ${type} provider..."
|
||||||
PROVIDER_API_KEY=$(${grep} -oP '(?<=<ApiKey>)[^<]+' ${lib.escapeShellArg "${provider.dataDir}/config.xml"})
|
PROVIDER_API_KEY=$(${grep} -oP '(?<=<ApiKey>)[^<]+' ${lib.escapeShellArg "${provider.dataDir}/config.xml"})
|
||||||
EXISTING=$(${curl} -sf "$BASE_URL/api/${lib.toLower type}" -H "X-API-KEY: $API_KEY")
|
EXISTING=$(${curl} -sf "$BASE_URL/api/system/settings" -H "X-API-KEY: $API_KEY")
|
||||||
if echo "$EXISTING" | ${jq} -e '. | length > 0' > /dev/null 2>&1; then
|
USE_FLAG=$(echo "$EXISTING" | ${jq} -r '.general.use_${ltype}')
|
||||||
|
EXISTING_KEY=$(echo "$EXISTING" | ${jq} -r '.${ltype}.apikey // ""')
|
||||||
|
if [ "$USE_FLAG" = "true" ] && [ -n "$EXISTING_KEY" ]; then
|
||||||
echo "${type} provider already configured, skipping"
|
echo "${type} provider already configured, skipping"
|
||||||
else
|
else
|
||||||
echo "Adding ${type} provider..."
|
echo "Adding ${type} provider..."
|
||||||
PAYLOAD=$(${jq} -n \
|
${curl} -sf -X POST "$BASE_URL/api/system/settings" \
|
||||||
--arg ip "localhost" \
|
|
||||||
--argjson port ${builtins.toString provider.port} \
|
|
||||||
--arg apikey "$PROVIDER_API_KEY" \
|
|
||||||
--argjson ssl false \
|
|
||||||
--arg base_url "/" \
|
|
||||||
'{ip: $ip, port: $port, apikey: $apikey, ssl: $ssl, base_url: $base_url}')
|
|
||||||
${curl} -sf -X POST "$BASE_URL/api/${lib.toLower type}" \
|
|
||||||
-H "X-API-KEY: $API_KEY" \
|
-H "X-API-KEY: $API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-d "settings-general-use_${ltype}=true" \
|
||||||
-d "$PAYLOAD"
|
-d "settings-${ltype}-ip=localhost" \
|
||||||
|
-d "settings-${ltype}-port=${builtins.toString provider.port}" \
|
||||||
|
-d "settings-${ltype}-apikey=$PROVIDER_API_KEY" \
|
||||||
|
-d "settings-${ltype}-ssl=false" \
|
||||||
|
-d "settings-${ltype}-base_url=/"
|
||||||
echo "${type} provider added"
|
echo "${type} provider added"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -124,6 +124,11 @@ testPkgs.testers.runNixOSTest {
|
|||||||
enable = true;
|
enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.bazarr = {
|
||||||
|
enable = true;
|
||||||
|
listenPort = 6767;
|
||||||
|
};
|
||||||
|
|
||||||
services.arrInit.sonarr = {
|
services.arrInit.sonarr = {
|
||||||
enable = true;
|
enable = true;
|
||||||
serviceName = "sonarr";
|
serviceName = "sonarr";
|
||||||
@@ -217,6 +222,24 @@ testPkgs.testers.runNixOSTest {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
services.bazarrInit = {
|
||||||
|
enable = true;
|
||||||
|
dataDir = "/var/lib/bazarr";
|
||||||
|
port = 6767;
|
||||||
|
sonarr = {
|
||||||
|
enable = true;
|
||||||
|
dataDir = "/var/lib/sonarr/.config/NzbDrone";
|
||||||
|
port = 8989;
|
||||||
|
serviceName = "sonarr";
|
||||||
|
};
|
||||||
|
radarr = {
|
||||||
|
enable = true;
|
||||||
|
dataDir = "/var/lib/radarr/.config/Radarr";
|
||||||
|
port = 7878;
|
||||||
|
serviceName = "radarr";
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
@@ -228,6 +251,7 @@ testPkgs.testers.runNixOSTest {
|
|||||||
machine.wait_for_unit("sonarr.service")
|
machine.wait_for_unit("sonarr.service")
|
||||||
machine.wait_for_unit("radarr.service")
|
machine.wait_for_unit("radarr.service")
|
||||||
machine.wait_for_unit("prowlarr.service")
|
machine.wait_for_unit("prowlarr.service")
|
||||||
|
machine.wait_for_unit("bazarr.service")
|
||||||
|
|
||||||
# Wait for Sonarr API to be ready (config.xml is auto-generated on first start)
|
# Wait for Sonarr API to be ready (config.xml is auto-generated on first start)
|
||||||
machine.wait_until_succeeds(
|
machine.wait_until_succeeds(
|
||||||
@@ -350,5 +374,46 @@ testPkgs.testers.runNixOSTest {
|
|||||||
"jq '. | length'"
|
"jq '. | length'"
|
||||||
).strip()
|
).strip()
|
||||||
assert result == "2", f"Expected 2 Prowlarr synced apps, got {result}"
|
assert result == "2", f"Expected 2 Prowlarr synced apps, got {result}"
|
||||||
|
|
||||||
|
# Wait for Bazarr to generate config.yaml
|
||||||
|
machine.wait_until_succeeds(
|
||||||
|
"test -f /var/lib/bazarr/config/config.yaml",
|
||||||
|
timeout=120,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Wait for Bazarr API to be ready
|
||||||
|
machine.wait_until_succeeds(
|
||||||
|
"API_KEY=$(awk '/^auth:/{f=1} f && /apikey:/{gsub(/.*apikey: /, \"\"); print; exit}' /var/lib/bazarr/config/config.yaml) && "
|
||||||
|
"curl -sf http://localhost:6767/api/system/status -H \"X-API-KEY: $API_KEY\"",
|
||||||
|
timeout=120,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Restart bazarr-init now that config.yaml exists
|
||||||
|
machine.succeed("systemctl restart bazarr-init.service")
|
||||||
|
machine.wait_for_unit("bazarr-init.service")
|
||||||
|
|
||||||
|
# Verify Sonarr provider configured in Bazarr
|
||||||
|
machine.succeed(
|
||||||
|
"API_KEY=$(awk '/^auth:/{f=1} f && /apikey:/{gsub(/.*apikey: /, \"\"); print; exit}' /var/lib/bazarr/config/config.yaml) && "
|
||||||
|
"curl -sf http://localhost:6767/api/system/settings -H \"X-API-KEY: $API_KEY\" | "
|
||||||
|
"jq -e '.general.use_sonarr == true and (.sonarr.apikey // \"\") != \"\"'"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Verify Radarr provider configured in Bazarr
|
||||||
|
machine.succeed(
|
||||||
|
"API_KEY=$(awk '/^auth:/{f=1} f && /apikey:/{gsub(/.*apikey: /, \"\"); print; exit}' /var/lib/bazarr/config/config.yaml) && "
|
||||||
|
"curl -sf http://localhost:6767/api/system/settings -H \"X-API-KEY: $API_KEY\" | "
|
||||||
|
"jq -e '.general.use_radarr == true and (.radarr.apikey // \"\") != \"\"'"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Idempotency: restart bazarr-init and verify no duplicate config
|
||||||
|
machine.succeed("systemctl restart bazarr-init.service")
|
||||||
|
machine.wait_for_unit("bazarr-init.service")
|
||||||
|
|
||||||
|
machine.succeed(
|
||||||
|
"API_KEY=$(awk '/^auth:/{f=1} f && /apikey:/{gsub(/.*apikey: /, \"\"); print; exit}' /var/lib/bazarr/config/config.yaml) && "
|
||||||
|
"curl -sf http://localhost:6767/api/system/settings -H \"X-API-KEY: $API_KEY\" | "
|
||||||
|
"jq -e '.general.use_sonarr == true and (.sonarr.apikey // \"\") != \"\"'"
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user