implement secret creating and deleting

This commit is contained in:
beckerinj
2022-12-02 02:40:44 -05:00
parent 4e518d90ad
commit 00a89ccb48
9 changed files with 185 additions and 20 deletions
+10
View File
@@ -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
+2 -1
View File
@@ -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"
+9
View File
@@ -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()
}
-2
View File
@@ -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,