mirror of
https://github.com/moghtech/komodo.git
synced 2026-07-27 21:46:17 -05:00
implement secret creating and deleting
This commit is contained in:
@@ -51,6 +51,16 @@ impl DbClient {
|
||||
Extension(Arc::new(client))
|
||||
}
|
||||
|
||||
pub async fn get_user(&self, user_id: &str) -> anyhow::Result<User> {
|
||||
let user = self
|
||||
.users
|
||||
.find_one_by_id(user_id)
|
||||
.await
|
||||
.context(format!("failed at mongo query for user {user_id}"))?
|
||||
.ok_or(anyhow!("user at {user_id} doesn't exist"))?;
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub async fn get_deployment(&self, deployment_id: &str) -> anyhow::Result<Deployment> {
|
||||
let deployment = self
|
||||
.deployments
|
||||
|
||||
@@ -15,4 +15,5 @@ serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
serde_json = "1.0"
|
||||
toml = "0.5"
|
||||
run_command = { version = "0.0.5", features = ["async_tokio"] }
|
||||
run_command = { version = "0.0.5", features = ["async_tokio"] }
|
||||
rand = "0.8"
|
||||
@@ -3,6 +3,7 @@ use std::{fs::File, io::Read, net::SocketAddr, str::FromStr};
|
||||
use anyhow::Context;
|
||||
use async_timing_util::unix_timestamp_ms;
|
||||
use axum::http::StatusCode;
|
||||
use rand::{distributions::Alphanumeric, Rng};
|
||||
use run_command::{async_run_command, CommandOutput};
|
||||
use serde::de::DeserializeOwned;
|
||||
use types::Log;
|
||||
@@ -58,3 +59,11 @@ pub fn handle_anyhow_error(err: anyhow::Error) -> (StatusCode, String) {
|
||||
format!("Internal Error: {err:#?}"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn generate_secret(length: usize) -> String {
|
||||
rand::thread_rng()
|
||||
.sample_iter(&Alphanumeric)
|
||||
.take(length)
|
||||
.map(char::from)
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ pub struct User {
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
|
||||
pub struct ApiSecret {
|
||||
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
|
||||
pub id: Option<ObjectId>,
|
||||
pub name: String,
|
||||
pub hash: String,
|
||||
pub created_at: i64,
|
||||
|
||||
Reference in New Issue
Block a user