Complete client configuration endpoints
This commit is contained in:
12
src/db/cf.rs
12
src/db/cf.rs
@@ -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
|
||||
|
||||
@@ -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>>;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user