Commit 1ecf0c3d authored by June's avatar June
Browse files

Also rotate GitLab token

parent 0901969a
namespace MomentaryMeeting.Services
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using MomentaryMeeting.Models;
......@@ -25,18 +26,19 @@
{
private readonly IDeserializer _deserializer;
private readonly ILogger<DefaultDatabaseApi> _logger;
private readonly IConfiguration _configuration;
private Database _currentDatabase;
public DefaultDatabaseApi(ILogger<DefaultDatabaseApi> logger)
public DefaultDatabaseApi(ILogger<DefaultDatabaseApi> logger, IConfiguration configuration)
{
_deserializer = new DeserializerBuilder()
.WithNamingConvention(UnderscoredNamingConvention.Instance)
.IgnoreUnmatchedProperties()
.Build();
_logger = logger;
_configuration = configuration;
_currentDatabase = Load(filename =>
_currentDatabase = Load(filename =>
{
using var stream = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream($"MomentaryMeeting.Data.{filename}"));
return stream.ReadToEnd();
......@@ -45,7 +47,7 @@
_logger.LogInformation("Database was loaded from disk.");
}
public Database Load(Func<string,string> getFileContents)
public Database Load(Func<string, string> getFileContents)
{
var newdb = new Database
{
......@@ -94,10 +96,17 @@
public async Task Refresh()
{
var accessToken = _configuration.GetValue<string>("GitLab:PrivateToken");
if (!string.IsNullOrWhiteSpace(accessToken))
{
_logger.LogWarning("Unable to refresh database from GitLab, because the GitLab:PrivateToken configuration value isn't set.");
return;
}
var files = Assembly.GetExecutingAssembly().GetManifestResourceNames().Where(n => n.EndsWith(".yaml")).Select(n => n[22..]);
var contents = new Dictionary<string, string>();
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", "7u_65smg_d5AXPX9HMVN");
client.DefaultRequestHeaders.Add("PRIVATE-TOKEN", accessToken);
foreach (var file in files)
{
contents[file] = await client.GetStringAsync($"https://a-momentary-meeting:53q25YXsaa7nkKaykgcE@gitlab.com/api/v4/projects/23987727/repository/files/{file}/raw?ref=main");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment