Skip to content

Commit

Permalink
Added support for custom privacy policy link
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkendk committed Apr 26, 2024
1 parent a04a903 commit 42ec829
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
14 changes: 10 additions & 4 deletions ConfigurationLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static class ConfigurationLoader
/// </summary>
private const string StorageStringEnvKey = "STORAGE";

/// <summary>
/// URL for the privacy policy, if not using the default
/// </summary>
private const string PrivacyPolicyEnvKey = "PRIVACY_POLICY_URL";

/// <summary>
/// The environment key for the Seq logging Url
/// </summary>
Expand Down Expand Up @@ -250,6 +255,7 @@ public static ApplicationConfiguration LoadApplicationConfiguration()
Environment.GetEnvironmentVariable(SecretsPassphraseKey) ?? string.Empty,
ExpandEnvPath(Environment.GetEnvironmentVariable(ConfigFileEnvKey)) ?? string.Empty,
Environment.GetEnvironmentVariable(StorageStringEnvKey) ?? string.Empty,
Environment.GetEnvironmentVariable(PrivacyPolicyEnvKey) ?? string.Empty,

Environment.GetEnvironmentVariable(SeqUrlEnvKey) ?? string.Empty,
Environment.GetEnvironmentVariable(SeqApiKeyEnvKey) ?? string.Empty
Expand Down Expand Up @@ -324,8 +330,8 @@ public static IEnumerable<ServiceConfiguration> LoadServices(ApplicationConfigur
else
{
if (!File.Exists(configuration.SecretsFilePath))
throw new InvalidDataException($"Secrets file specified, but not found: {Path.GetFullPath(configuration.SecretsFilePath)}");
throw new InvalidDataException($"Secrets file specified, but not found: {Path.GetFullPath(configuration.SecretsFilePath)}");

name = configuration.SecretsFilePath;
using var fs = File.OpenRead(configuration.SecretsFilePath);
fs.CopyTo(secretsData);
Expand All @@ -339,7 +345,7 @@ public static IEnumerable<ServiceConfiguration> LoadServices(ApplicationConfigur
{
SharpAESCrypt.SharpAESCrypt.Decrypt(configuration.SecretsPassphrase, secretsData, ms);
ms.Position = 0;
decryptedStream = ms;
decryptedStream = ms;
}

var secrets = DeserializeStream<Dictionary<string, string>>(decryptedStream, name);
Expand All @@ -362,7 +368,7 @@ public static IEnumerable<ServiceConfiguration> LoadServices(ApplicationConfigur
{
if (!File.Exists(configuration.ConfigFilePath))
throw new InvalidDataException($"Config file specified, but not found: {Path.GetFullPath(configuration.ConfigFilePath)}");

name = configuration.ConfigFilePath;
using var fs = File.OpenRead(configuration.ConfigFilePath);
fs.CopyTo(configData);
Expand Down
2 changes: 2 additions & 0 deletions Datamodel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ string Result
/// <param name="SecretsPassphrase">Passhrase for decypting the OAuth secrets</param>
/// <param name="ConfigFilePath">Path to service config overrides</param>
/// <param name="StorageString">Path to a storage destination for v1 tokens</param>
/// <param name="CustomPrivacyPolicyUrl">Url for a custom privacy policy</param>
/// <param name="SeqLogUrl">Url for Seq log destination</param>
/// <param name="SeqLogApiKey">Optional API key for logging to Seq</param>
public sealed record ApplicationConfiguration(
Expand All @@ -125,6 +126,7 @@ public sealed record ApplicationConfiguration(
string SecretsPassphrase,
string ConfigFilePath,
string StorageString,
string CustomPrivacyPolicyUrl,
string SeqLogUrl,
string SeqLogApiKey
);
Expand Down
18 changes: 13 additions & 5 deletions Handler/PrivacyPolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ public static class PrivacyPolicy
/// <returns>The awaitable token</returns>
public static Task Handle(HttpContext context, ApplicationContext appContext)
{
context.Response.ContentType = "text/html";
context.Response.StatusCode = (int)HttpStatusCode.OK;
return context.Response.WriteAsync(
appContext.Render.PrivacyPolicy
);
if (string.IsNullOrWhiteSpace(appContext.Configuration.CustomPrivacyPolicyUrl))
{
context.Response.ContentType = "text/html";
context.Response.StatusCode = (int)HttpStatusCode.OK;
return context.Response.WriteAsync(
appContext.Render.PrivacyPolicy
);
}
else
{
context.Response.Redirect(appContext.Configuration.CustomPrivacyPolicyUrl);
return Task.CompletedTask;
}
}
}

0 comments on commit 42ec829

Please sign in to comment.