Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed extra config, forced headers to Dictionary #281

Merged
merged 2 commits into from
Nov 6, 2023
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
35 changes: 27 additions & 8 deletions src/TagzApp.Common/InMemoryProviderConfigurationRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Configuration;
using System.Text.Json;

namespace TagzApp.Common;
public class InMemoryProviderConfigurationRepository : IProviderConfigurationRepository
Expand All @@ -22,19 +23,37 @@ public async Task<ProviderConfiguration> GetConfigurationSettingsAsync(string na

foreach (var configSetting in configSettings)
{
if (configSetting.Key == "Activated")
{
providerConfig.Activated = bool.Parse(configSetting.Value ?? "false");
continue;
}

if (configSetting.Key == "Description")
switch (configSetting.Key.ToLowerInvariant())
{
providerConfig.Description = configSetting.Value ?? string.Empty;
continue;
case "activated":
providerConfig.Activated = bool.Parse(configSetting.Value ?? "false");
continue;
break;
case "description":
providerConfig.Description = configSetting.Value ?? string.Empty;
continue;
break;
case "defaultheaders":
if (configSetting.GetChildren().Count() == 0 || configSetting.Value is string)
{
providerConfig.ConfigurationSettings!.Add(configSetting.Key, configSetting.Value ?? string.Empty);
continue;
}
var headerDict = new Dictionary<string, string>();
// iterate through the children of the DefaultHeaders section and add to the dictionary
foreach (var header in configSetting.GetChildren())
{
headerDict.Add(header.Key, header.Value ?? string.Empty);
}
providerConfig.ConfigurationSettings!.Add("DefaultHeaders", JsonSerializer.Serialize(headerDict));
continue;
break;

}

providerConfig.ConfigurationSettings!.Add(configSetting.Key, configSetting.Value ?? string.Empty);

}

return providerConfig;
Expand Down
38 changes: 19 additions & 19 deletions src/TagzApp.Providers.Twitter/Configuration/TwitterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ public class TwitterConfiguration : HttpClientOptions

public bool Activated { get; set; } = false;

/// <summary>
/// Twitter issued API Key for the service
/// </summary>
public string ApiKey { get; set; } = string.Empty;

/// <summary>
/// Twitter issued API Secret Key for the service
/// </summary>
public string ApiSecretKey { get; set; } = string.Empty;

/// <summary>
/// Access token for Twitter
/// </summary>
public string AccessToken { get; set; } = string.Empty;

/// <summary>
/// Access token secret for Twitter
/// </summary>
public string AccessTokenSecret { get; set; } = string.Empty;
///// <summary>
///// Twitter issued API Key for the service
///// </summary>
//public string ApiKey { get; set; } = string.Empty;

///// <summary>
///// Twitter issued API Secret Key for the service
///// </summary>
//public string ApiSecretKey { get; set; } = string.Empty;

///// <summary>
///// Access token for Twitter
///// </summary>
//public string AccessToken { get; set; } = string.Empty;

///// <summary>
///// Access token secret for Twitter
///// </summary>
//public string AccessTokenSecret { get; set; } = string.Empty;

/// <summary>
/// Provider description
Expand Down
6 changes: 2 additions & 4 deletions src/TagzApp.Providers.Twitter/StartTwitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ protected override void MapConfigurationValues(ProviderConfiguration providerCon
{
var config = providerConfiguration.ConfigurationSettings;

var headers = config["DefaultHeaders"];

if (config != null)
{
_TwitterConfiguration = new TwitterConfiguration
Expand All @@ -38,10 +40,6 @@ protected override void MapConfigurationValues(ProviderConfiguration providerCon
BaseAddress = new Uri(config["BaseAddress"] ?? string.Empty),
Timeout = TimeSpan.Parse(config["Timeout"] ?? string.Empty),
DefaultHeaders = JsonSerializer.Deserialize<Dictionary<string, string>?>(config["DefaultHeaders"]),
ApiKey = config["ApiKey"] ?? string.Empty,
ApiSecretKey = config["ApiSecretKey"] ?? string.Empty,
AccessToken = config["AccessToken"] ?? string.Empty,
AccessTokenSecret = config["AccessTokenSecret"] ?? string.Empty,
Description = providerConfiguration.Description
};
}
Expand Down
5 changes: 4 additions & 1 deletion src/TagzApp.Storage.Postgres/PostgresMessaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ internal async Task StartProviders(IEnumerable<ISocialMediaProvider> providers,

if (provider is IHasNewestId newestIdProvider)
{

var SevenDaysAgo = DateTime.UtcNow.AddDays(-7);

var newestId = await context.Content.AsNoTracking()
.Where(c => c.Provider == provider.Id)
.Where(c => c.Provider == provider.Id && c.Timestamp > SevenDaysAgo)
.OrderByDescending(c => c.ProviderId)
.Select(c => c.ProviderId)
.FirstOrDefaultAsync();
Expand Down
124 changes: 61 additions & 63 deletions src/TagzApp.Web/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,64 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ModerationEnabled": "true",
"ConnectionStrings": {
"SecurityContextConnection": "Data Source=TagzApp.Web.db"
},
"AzureContentSafety": {
"Enabled": true
},
"providers": {
"mastodon": {
"BaseAddress": "https://mastodon.social",
"Timeout": "00:03:00",
"DefaultHeaders": "{}",
"UseHttp2": true,
"Activated": true,
"Description": "Mastodon is a decentralized social network made up of independent servers organized around specific themes, topics, or interests."
},
"youtube": {
"ApiKey": "my-random-key",
"Activated": true,
"Description": "YouTube is a free video sharing website that makes it easy to watch online videos. You can even create and upload your own videos to share with others."
},
"twitchchat": {
"ChannelName": "csharpfritz",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ModerationEnabled": "true",
"ConnectionStrings": {
"SecurityContextConnection": "Data Source=TagzApp.Web.db"
},
"AzureContentSafety": {
"Enabled": true
},
"providers": {
"mastodon": {
"BaseAddress": "https://mastodon.social",
"Timeout": "00:03:00",
"DefaultHeaders": "{}",
"UseHttp2": true,
"Activated": true,
"Description": "Mastodon is a decentralized social network made up of independent servers organized around specific themes, topics, or interests."
},
"youtube": {
"ApiKey": "my-random-key",
"Activated": true,
"Description": "YouTube is a free video sharing website that makes it easy to watch online videos. You can even create and upload your own videos to share with others."
},
"twitchchat": {
"ChannelName": "csharpfritz",
"Activated": true
},
"twitter": {
"Activated": false,
"BaseAddress": "https://api.twitter.com",
"Timeout": "00:03:00",
"DefaultHeaders": "{\"Authorization\": \"Bearer ******[Add to Local Secret Store INCLUDE BEARER prefix]*****\"}",
"ApiKey": "******[Add to Local Secret Store]******",
"ApiSecretKey": "******[Add to Local Secret Store]******",
"AccessToken": "******[Add to Local Secret Store]******",
"AccessTokenSecret": "******[Add to Local Secret Store]******",
"Description": "Twitter is a service for friends, family, and coworkers to communicate and stay connected through the exchange of quick, frequent messages"
},
"blazot": {
"BaseAddress": "https://api.blazot.com",
"Timeout": "00:03:00",
"ApiKey": "******[Add to Local Secret Store]******",
"SecretAuthKey": "******[Add to Local Secret Store]******",
"WindowSeconds": 900,
"WindowRequests": 5,
"Activated": false,
"Description": "Blazot is an all new social networking platform and your launchpad to the social universe!"
}
},
"HttpPolicies": {
"HttpCircuitBreaker": {
"DurationOfBreak": "00:01:00",
"ExceptionsAllowedBeforeBreaking": 20
},
"HttpRetry": {
"BackoffPower": 2,
"Count": 3
}
},
"AllowedHosts": "*"
},
"twitter": {
"Activated": false,
"BaseAddress": "https://api.twitter.com",
"Timeout": "00:03:00",
"DefaultHeaders": {
"Authorization": "Bearer ******[Add to Local Secret Store INCLUDE BEARER prefix]*****"
},
"Description": "Twitter is a service for friends, family, and coworkers to communicate and stay connected through the exchange of quick, frequent messages"
},
"blazot": {
"BaseAddress": "https://api.blazot.com",
"Timeout": "00:03:00",
"ApiKey": "******[Add to Local Secret Store]******",
"SecretAuthKey": "******[Add to Local Secret Store]******",
"WindowSeconds": 900,
"WindowRequests": 5,
"Activated": false,
"Description": "Blazot is an all new social networking platform and your launchpad to the social universe!"
}
},
"HttpPolicies": {
"HttpCircuitBreaker": {
"DurationOfBreak": "00:01:00",
"ExceptionsAllowedBeforeBreaking": 20
},
"HttpRetry": {
"BackoffPower": 2,
"Count": 3
}
},
"AllowedHosts": "*"
}