aboutsummaryrefslogtreecommitdiff
path: root/docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs')
-rw-r--r--docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs36
1 files changed, 32 insertions, 4 deletions
diff --git a/docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs b/docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs
index 9281cee..feac08a 100644
--- a/docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs
+++ b/docker/crupest-api/CrupestApi/CrupestApi.Secrets/SecretsService.cs
@@ -108,14 +108,42 @@ INSERT INTO secrets (Key, Secret, Description, ExpireTime, Revoked, CreateTime)
return new SecretInfo(key, secret, description, expireTime, false, now);
}
- public Task<List<SecretInfo>> GetSecretListAsync(bool includeExpired = false, bool includeRevoked = false)
+ public async Task<List<SecretInfo>> GetSecretListAsync(bool includeExpired = false, bool includeRevoked = false)
{
- throw new NotImplementedException();
+ var dbConnection = await EnsureDatabase();
+
+ var query = await dbConnection.QueryAsync<SecretInfo>(@"
+SELECT Key, Secret, Description, ExpireTime, Revoked, CreateTime FROM secrets
+WHERE @IncludeExpired OR ExpireTime IS NULL OR ExpireTime > @Now AND
+ @IncludeRevoked OR Revoked = 0;
+ ", new
+ {
+ IncludeExpired = includeExpired,
+ IncludeRevoked = includeRevoked,
+ Now = DateTime.Now.ToString("O"),
+ });
+
+ return query.ToList();
}
- public Task<List<SecretInfo>> GetSecretListByKeyAsync(string key, bool includeExpired = false, bool includeRevoked = false)
+ public async Task<List<SecretInfo>> GetSecretListByKeyAsync(string key, bool includeExpired = false, bool includeRevoked = false)
{
- throw new NotImplementedException();
+ var dbConnection = await EnsureDatabase();
+
+ var query = await dbConnection.QueryAsync<SecretInfo>(@"
+SELECT Key, Secret, Description, ExpireTime, Revoked, CreateTime FROM secrets
+WHERE Key = @Key AND
+(@IncludeExpired OR ExpireTime IS NULL OR ExpireTime > @Now) AND
+(@IncludeRevoked OR Revoked = 0);
+ ", new
+ {
+ Key = key,
+ IncludeExpired = includeExpired,
+ IncludeRevoked = includeRevoked,
+ Now = DateTime.Now.ToString("O"),
+ });
+
+ return query.ToList();
}
public Task<SecretInfo> ModifySecretAsync(string secret, SecretModifyRequest modifyRequest)