Complete client configuration endpoints

This commit is contained in:
Simon Bihel
2022-02-14 22:29:12 +00:00
parent 27e36e2aa6
commit e0241feb9a
7 changed files with 180 additions and 19 deletions

View File

@@ -115,6 +115,7 @@ impl DBClient for CFClient {
.map_err(|e| anyhow!("Failed to put KV: {}", e))?;
Ok(())
}
async fn get_client(&self, client_id: String) -> Result<Option<ClientEntry>> {
Ok(self
.ctx
@@ -125,6 +126,17 @@ impl DBClient for CFClient {
.await
.map_err(|e| anyhow!("Failed to get KV: {}", e))?)
}
async fn delete_client(&self, client_id: String) -> Result<()> {
Ok(self
.ctx
.kv(KV_NAMESPACE)
.map_err(|e| anyhow!("Failed to get KV store: {}", e))?
.delete(&format!("{}/{}", KV_CLIENT_PREFIX, client_id))
.await
.map_err(|e| anyhow!("Failed to get KV: {}", e))?)
}
async fn set_code(&self, code: String, code_entry: CodeEntry) -> Result<()> {
let namespace = self
.ctx

View File

@@ -2,7 +2,7 @@ use anyhow::Result;
use async_trait::async_trait;
use chrono::{offset::Utc, DateTime};
use ethers_core::types::H160;
use openidconnect::{core::CoreClientMetadata, Nonce};
use openidconnect::{core::CoreClientMetadata, Nonce, RegistrationAccessToken};
use serde::{Deserialize, Serialize};
#[cfg(not(target_arch = "wasm32"))]
@@ -30,6 +30,7 @@ pub struct CodeEntry {
pub struct ClientEntry {
pub secret: String,
pub metadata: CoreClientMetadata,
pub access_token: Option<RegistrationAccessToken>,
}
// Using a trait to easily pass async functions with async_trait
@@ -38,6 +39,7 @@ pub struct ClientEntry {
pub trait DBClient {
async fn set_client(&self, client_id: String, client_entry: ClientEntry) -> Result<()>;
async fn get_client(&self, client_id: String) -> Result<Option<ClientEntry>>;
async fn delete_client(&self, client_id: String) -> Result<()>;
async fn set_code(&self, code: String, code_entry: CodeEntry) -> Result<()>;
async fn get_code(&self, code: String) -> Result<Option<CodeEntry>>;
}

View File

@@ -47,6 +47,18 @@ impl DBClient for RedisClient {
}
}
async fn delete_client(&self, client_id: String) -> Result<()> {
let mut conn = self
.pool
.get()
.await
.map_err(|e| anyhow!("Failed to get connection to database: {}", e))?;
conn.del(format!("{}/{}", KV_CLIENT_PREFIX, client_id))
.await
.map_err(|e| anyhow!("Failed to get kv: {}", e))?;
Ok(())
}
async fn set_code(&self, code: String, code_entry: CodeEntry) -> Result<()> {
let mut conn = self
.pool