Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Renamed EnvironmentUtil.GetVariable -> EnvironmentUtil.GetRequiredVariable.

nzbdav-dev4711100d164b
diff --git a/backend/Api/Controllers/BaseApiController.cs b/backend/Api/Controllers/BaseApiController.cs
index 37963c34..dde14bad 100644
--- a/backend/Api/Controllers/BaseApiController.cs
+++ b/backend/Api/Controllers/BaseApiController.cs
@@ -21,7 +21,7 @@ public abstract class BaseApiController : ControllerBase
var apiKey = HttpContext.GetRequestApiKey();
if (apiKey == null)
throw new UnauthorizedAccessException("API Key Required");
- if (apiKey != EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY"))
+ if (apiKey != EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY"))
throw new UnauthorizedAccessException("API Key Incorrect");
}
diff --git a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs
index f4639363..1c1699af 100644
--- a/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs
+++ b/backend/Api/Controllers/GetWebdavItem/GetWebdavItemRequest.cs
@@ -46,7 +46,7 @@ public class GetWebdavItemRequest
return true;
}
- var apiKey = EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");
+ var apiKey = EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");
return downloadKey == GenerateDownloadKey(apiKey, path);
}
diff --git a/backend/Api/SabControllers/SabApiController.cs b/backend/Api/SabControllers/SabApiController.cs
index 6816ca7b..950be13e 100644
--- a/backend/Api/SabControllers/SabApiController.cs
+++ b/backend/Api/SabControllers/SabApiController.cs
@@ -110,7 +110,7 @@ public class SabApiController(
var apiKey = httpContext.GetRequestApiKey();
var isValidKey = apiKey?.IsAny(
configManager.GetApiKey(),
- EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY")
+ EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY")
);
if (!isValidKey.HasValue)
throw new UnauthorizedAccessException("API Key Required");
diff --git a/backend/Config/ConfigManager.cs b/backend/Config/ConfigManager.cs
index ff0c4b93..66155d7a 100644
--- a/backend/Config/ConfigManager.cs
+++ b/backend/Config/ConfigManager.cs
@@ -66,7 +66,7 @@ public class ConfigManager
public string GetApiKey()
{
return StringUtil.EmptyToNull(GetConfigValue("api.key"))
- ?? EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");
+ ?? EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");
}
public string GetStrmKey()
diff --git a/backend/Utils/EnvironmentUtil.cs b/backend/Utils/EnvironmentUtil.cs
index 4aee2032..0fc7239e 100644
--- a/backend/Utils/EnvironmentUtil.cs
+++ b/backend/Utils/EnvironmentUtil.cs
@@ -2,7 +2,7 @@
public static class EnvironmentUtil
{
- public static string GetVariable(string envVariable)
+ public static string GetRequiredVariable(string envVariable)
{
return Environment.GetEnvironmentVariable(envVariable) ??
throw new Exception($"The environment variable `{envVariable}` must be set.");
diff --git a/backend/Websocket/WebsocketManager.cs b/backend/Websocket/WebsocketManager.cs
index 86322c09..d4a72c19 100644
--- a/backend/Websocket/WebsocketManager.cs
+++ b/backend/Websocket/WebsocketManager.cs
@@ -69,7 +69,7 @@ public class WebsocketManager
private static async Task<bool> Authenticate(WebSocket socket)
{
var apiKey = await ReceiveAuthToken(socket).ConfigureAwait(false);
- return apiKey == EnvironmentUtil.GetVariable("FRONTEND_BACKEND_API_KEY");
+ return apiKey == EnvironmentUtil.GetRequiredVariable("FRONTEND_BACKEND_API_KEY");
}
/// <summary>