aboutsummaryrefslogtreecommitdiff
path: root/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-02-19 02:05:39 +0800
committerYuqian Yang <crupest@crupest.life>2025-02-19 02:42:42 +0800
commit4c5df72057fe02257e243de37930a47425a84722 (patch)
treef782d0e85c4a784b659e0da29f0bbf4fc25fc827 /dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets
parent89e31c19bb8fca91c54a73ff7a7f4e837d1dbf93 (diff)
downloadcrupest-4c5df72057fe02257e243de37930a47425a84722.tar.gz
crupest-4c5df72057fe02257e243de37930a47425a84722.tar.bz2
crupest-4c5df72057fe02257e243de37930a47425a84722.zip
chore(docker): remove crupest-api, forgejo and move dropped.
Diffstat (limited to 'dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets')
-rw-r--r--dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/ISecretService.cs8
-rw-r--r--dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretInfo.cs48
-rw-r--r--dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs48
-rw-r--r--dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretServiceCollectionExtensions.cs12
-rw-r--r--dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretsConstants.cs6
5 files changed, 0 insertions, 122 deletions
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/ISecretService.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/ISecretService.cs
deleted file mode 100644
index 83025f8..0000000
--- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/ISecretService.cs
+++ /dev/null
@@ -1,8 +0,0 @@
-namespace CrupestApi.Commons.Secrets;
-
-public interface ISecretService
-{
- void CreateTestSecret(string key, string secret);
-
- List<string> GetPermissions(string secret);
-}
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretInfo.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretInfo.cs
deleted file mode 100644
index c3a4de0..0000000
--- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretInfo.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using System.Security.Cryptography;
-using System.Text;
-using CrupestApi.Commons.Crud;
-
-namespace CrupestApi.Commons.Secrets;
-
-public class SecretInfo
-{
- [Column(NotNull = true)]
- public string Key { get; set; } = default!;
- [Column(NotNull = true, NoUpdate = true, ActAsKey = true)]
- public string Secret { get; set; } = default!;
- [Column(DefaultEmptyForString = true)]
- public string Description { get; set; } = default!;
- [Column(NotNull = false)]
- public DateTime? ExpireTime { get; set; }
- [Column(NotNull = true, DefaultValue = false)]
- public bool Revoked { get; set; }
- [Column(NotNull = true)]
- public DateTime CreateTime { get; set; }
-
- private static RandomNumberGenerator RandomNumberGenerator = RandomNumberGenerator.Create();
-
- private static string GenerateRandomKey(int length)
- {
- const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- var result = new StringBuilder(length);
- lock (RandomNumberGenerator)
- {
- for (int i = 0; i < length; i++)
- {
- result.Append(chars[RandomNumberGenerator.GetInt32(chars.Length)]);
- }
- }
- return result.ToString();
- }
-
-
- public static string SecretDefaultValueGenerator()
- {
- return GenerateRandomKey(16);
- }
-
- public static DateTime CreateTimeDefaultValueGenerator()
- {
- return DateTime.UtcNow;
- }
-}
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs
deleted file mode 100644
index c693d8d..0000000
--- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretService.cs
+++ /dev/null
@@ -1,48 +0,0 @@
-using System.Data;
-using CrupestApi.Commons.Crud;
-using CrupestApi.Commons.Crud.Migrations;
-
-namespace CrupestApi.Commons.Secrets;
-
-public class SecretService : CrudService<SecretInfo>, ISecretService
-{
- private readonly ILogger<SecretService> _logger;
-
- public SecretService(ITableInfoFactory tableInfoFactory, IDbConnectionFactory dbConnectionFactory, IDatabaseMigrator migrator, ILoggerFactory loggerFactory)
- : base(tableInfoFactory, dbConnectionFactory, migrator, loggerFactory)
- {
- _logger = loggerFactory.CreateLogger<SecretService>();
- }
-
- protected override void AfterMigrate(IDbConnection connection, TableInfo table)
- {
- if (table.SelectCount(connection) == 0)
- {
- _logger.LogInformation("No secrets found, insert default secrets.");
- using var transaction = connection.BeginTransaction();
- var insertClause = InsertClause.Create()
- .Add(nameof(SecretInfo.Key), SecretsConstants.SecretManagementKey)
- .Add(nameof(SecretInfo.Secret), "crupest")
- .Add(nameof(SecretInfo.Description), "This is the init key. Please revoke it immediately after creating a new one.");
- _table.Insert(connection, insertClause, out var _);
- transaction.Commit();
- }
- }
-
- public void CreateTestSecret(string key, string secret)
- {
- var connection = _dbConnection;
- var insertClause = InsertClause.Create()
- .Add(nameof(SecretInfo.Key), key)
- .Add(nameof(SecretInfo.Secret), secret)
- .Add(nameof(SecretInfo.Description), "Test secret.");
- _table.Insert(connection, insertClause, out var _);
- }
-
- public List<string> GetPermissions(string secret)
- {
- var list = _table.Select<SecretInfo>(_dbConnection,
- where: WhereClause.Create().Eq(nameof(SecretInfo.Secret), secret));
- return list.Select(x => x.Key).ToList();
- }
-}
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretServiceCollectionExtensions.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretServiceCollectionExtensions.cs
deleted file mode 100644
index a9c0e5f..0000000
--- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretServiceCollectionExtensions.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Microsoft.Extensions.DependencyInjection.Extensions;
-
-namespace CrupestApi.Commons.Secrets;
-
-public static class SecretServiceCollectionExtensions
-{
- public static IServiceCollection AddSecrets(this IServiceCollection services)
- {
- services.TryAddScoped<ISecretService, SecretService>();
- return services;
- }
-}
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretsConstants.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretsConstants.cs
deleted file mode 100644
index 207cc45..0000000
--- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Secrets/SecretsConstants.cs
+++ /dev/null
@@ -1,6 +0,0 @@
-namespace CrupestApi.Commons.Secrets;
-
-public static class SecretsConstants
-{
- public const string SecretManagementKey = "crupest.secrets.management";
-}