Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to created_at and updated_at #54

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

This file was deleted.

58 changes: 58 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dmtri = { version = "0.1.0", git = "https://github.com/demeter-run/specs.git" }

anyhow = "1.0.86"
async-trait = "0.1.80"
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "sqlite"] }
sqlx = { version = "0.7.4", features = ["runtime-tokio-rustls", "sqlite", "chrono"] }
tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread", "time"] }
tonic = "0.11.0"
serde = { version = "1.0.203", features = ["derive"] }
Expand All @@ -33,6 +33,7 @@ bech32 = "0.11.0"
argon2 = "0.5.3"
tower = "0.4.13"
hyper = "1.4.1"
chrono = "0.4.38"

[dev-dependencies]
mockall = "0.12.1"
Expand Down
6 changes: 6 additions & 0 deletions src/domain/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use anyhow::{bail, Result};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

macro_rules! into_event {
Expand All @@ -17,6 +18,8 @@ pub struct ProjectCreated {
pub name: String,
pub namespace: String,
pub owner: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
into_event!(ProjectCreated);

Expand All @@ -27,6 +30,8 @@ pub struct ResourceCreated {
pub project_namespace: String,
pub kind: String,
pub data: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
into_event!(ResourceCreated);

Expand All @@ -37,6 +42,7 @@ pub struct ProjectSecretCreated {
pub name: String,
pub phc: String,
pub secret: Vec<u8>,
pub created_at: DateTime<Utc>,
}
into_event!(ProjectSecretCreated);

Expand Down
18 changes: 18 additions & 0 deletions src/domain/project.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use anyhow::{bail, Error, Result};
use argon2::{password_hash::SaltString, Argon2, PasswordHash, PasswordHasher, PasswordVerifier};
use bech32::{Bech32m, Hrp};
use chrono::{DateTime, Utc};
use k8s_openapi::api::core::v1::Namespace;
use kube::{api::ObjectMeta, ResourceExt};
use rand::{
Expand Down Expand Up @@ -34,6 +35,8 @@ pub async fn create(
namespace: cmd.namespace.clone(),
name: cmd.name,
owner: user_id,
created_at: Utc::now(),
updated_at: Utc::now(),
};

event.dispatch(evt.into()).await?;
Expand Down Expand Up @@ -113,6 +116,7 @@ pub async fn create_secret(
name: cmd.name,
phc: password_hash.to_string(),
secret: secret.to_vec(),
created_at: Utc::now(),
};

event.dispatch(evt.into()).await?;
Expand Down Expand Up @@ -211,6 +215,8 @@ pub struct ProjectCache {
pub name: String,
pub namespace: String,
pub owner: String,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl From<ProjectCreated> for ProjectCache {
fn from(value: ProjectCreated) -> Self {
Expand All @@ -219,6 +225,8 @@ impl From<ProjectCreated> for ProjectCache {
namespace: value.namespace,
name: value.name,
owner: value.owner,
created_at: value.created_at,
updated_at: value.updated_at,
}
}
}
Expand Down Expand Up @@ -252,6 +260,7 @@ pub struct ProjectSecretCache {
pub name: String,
pub phc: String,
pub secret: Vec<u8>,
pub created_at: DateTime<Utc>,
}
impl From<ProjectSecretCreated> for ProjectSecretCache {
fn from(value: ProjectSecretCreated) -> Self {
Expand All @@ -261,6 +270,7 @@ impl From<ProjectSecretCreated> for ProjectSecretCache {
name: value.name,
phc: value.phc,
secret: value.secret,
created_at: value.created_at,
}
}
}
Expand All @@ -269,6 +279,7 @@ impl From<ProjectSecretCreated> for ProjectSecretCache {
pub struct ProjectUserCache {
pub user_id: String,
pub project_id: String,
pub created_at: DateTime<Utc>,
}

#[async_trait::async_trait]
Expand Down Expand Up @@ -350,6 +361,8 @@ mod tests {
name: "New Project".into(),
namespace: "sonic-vegas".into(),
owner: "user id".into(),
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}
Expand All @@ -360,6 +373,8 @@ mod tests {
name: "New Project".into(),
namespace: "sonic-vegas".into(),
owner: "user id".into(),
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}
Expand Down Expand Up @@ -389,6 +404,7 @@ mod tests {
name: "Key 1".into(),
phc: PHC.into(),
secret: SECRET.to_bytes().to_vec(),
created_at: Utc::now(),
}
}
}
Expand All @@ -400,6 +416,7 @@ mod tests {
name: "Key 1".into(),
phc: PHC.into(),
secret: SECRET.to_bytes().to_vec(),
created_at: Utc::now(),
}
}
}
Expand All @@ -409,6 +426,7 @@ mod tests {
Self {
user_id: Uuid::new_v4().to_string(),
project_id: Uuid::new_v4().to_string(),
created_at: Utc::now(),
}
}
}
Expand Down
Loading
Loading