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

Small updates #71

Merged
merged 5 commits into from
Jul 5, 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
2 changes: 0 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
DATABASE_URL="mysql://iam:secret@localhost:3306/iam"

REDIS_URL=redis://127.0.0.1

JWT_RSA_PRIVATE='-----BEGIN RSA PRIVATE KEY-----MIIJJgIBAAKCAgBdptOAsZZBpF7P0+79iKssZuYKq6UMVUYVHYFv2ClXAJmIMU+QXcued9oZA077BXhv5e7Lu8RXqylMNUd3hEEJjisXce3e33bcDrJZmGEljv/I3YCrNWK1LFpqd5YzossJpT+65TPxmeVipqJ65ZUpBCO3V82r3dDMx8d2CGMqOOygI1afeFxoZDVm/H1flR+uDusbB9EvYlKsiCfEGlQz/lnHiHI/bEmdeIzhpCLmRhtWxyyl6wqe07f718JdGpnPo6Aql8UtSMQRjtKcRW2G67hNXGgB7uS5y8qW8fj/fIcyePZGm8TUv3vL+wMUb6+05RN7i9BXt6Eurgok2NQGYvwforJHlCsj3aIzjTcfH3s6jkdZSj9Yho2BgtJi50qWxiWYxTTAmtVSDihjIty2h2NkzlXePWDF+iQW0bkbuYQQKzM6dLGNF0+z8t7ddlvKeqG8CI1+kZ3QR+XsKWSIhhGx+yncbxWUAzqMoLUUK9WlmQttoC8VenFSunNof2QxT+1BbYJt9ZFI5ZltTICR6K9kmRNQQ7qrdQacBsKi2SD+JVK7ESAARj9FZNvf0X78LM+H1NZACe4pT4tlObH4OwkHpl77oCmghNe49Q1CNv7d5QKesOS19kBoQYMYb+jKjKc/uj7iObwTuywX8I1d19gJeHD2XkZS9VV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bVIRLWVNrteA/P48WSSC/dJ18k/qWDPGkG0+sSdlQVFX7oAgvsp4aQPzqnxdwM33Q9BT8PodhrZzQM53iqhQnIM4si8mj6AhF1FwowUMgVxzD0y5f5Vr0tdj7f9Nzr+19964jEH+54WiV+2EisPeXbqXUooNR/ijU+Xgg0scH+taDat/mlk8wk5L8BSYZRBUpZETSjQyBiZCScW0t400ufQkoAW51Rf7PUgRfETsHlC3MfiSLJF6qs0kl6SwB+MxfDvWXPnCb+UhLllenaAPn63q7e7HMXHAHwyGF-----END RSA PRIVATE KEY-----'
JWT_RSA_PUBLIC='-----BEGIN PUBLIC KEY-----MIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgBdptOAsZZBpF7P0+79iKssZuYKq6UMVUYVHYFv2ClXAJmIMU+QXcued9oZA077BXhv5e7Lu8RXqylMNUd3hEEJjisXce3e33bcDrJZmGEljv/I3YCrNWK1LFpqd5YzossJpT+65TPxmeVipqJ65ZUpBCO3V82r3dDMx8d2CGMqOOygI1afeFxoZDVm/H1flR+uDusbB9EvYlKsiCfEGlQz/lnHiHI/bEmdeIzhpCLmRhtWxyyl6wqe07f718JdGpnPo6Aql8UtSMQRjtKcRW2G67hNXGgB7uS5y8qW8fj/fIcyePZGm8TUv3vL+wMUb6+05RN7i9BXt6Eurgok2NQGYvwforJHlCsj3aIzjTcfH3s6jkdZSj9Yho2BgtJi50qWxiWYxTTAmtVSDihjIty2h2NkzlXePWDF+iQW0bkbuYQQKzM6dLGNF0+z8t7ddlvKeqG8CI1+kZ3QR+XsKWSIhhGx+yncbxWUAzqMoLUUK9WlmQttoC8VenFSunNof2QxT+1BbYJt9ZFI5ZltTICR6K9kmRNQQ7qrdQacBsKi2SD+JVK7ESAARj9FZNvf0X78LM+H1NZACe4pT4tlObH4OwkHpl77oCmghNe49Q1CNv7d5QKesOS19kBoQYMYb+jKjKc/uj7iObwTuywX8I1d19gJeHD2XkZS9VVcHbYLUQIDAQAB-----END PUBLIC KEY-----'
49 changes: 0 additions & 49 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ default-members = [
"iam-migration",
"cmds",
]
resolver = "2"

[workspace.package]
license-file = "./LICENSE"
2 changes: 1 addition & 1 deletion cmds/src/create_iam_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ async fn main() {

let (id, secret) = create_app(&database, &name).await;

println!("id: {}", id.to_string());
println!("id: {}", id);
println!("secret: {}", secret);
}
9 changes: 2 additions & 7 deletions deny.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
[advisories]
vulnerability = "deny"
unmaintained = "warn"
notice = "deny"
version = 2

[licenses]
unlicensed = "deny"
copyleft = "warn"
allow-osi-fsf-free = "neither"
default = "deny"
version = 2
confidence-threshold = 1.0
allow = [
"MIT",
Expand Down
1 change: 0 additions & 1 deletion iam-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ chrono = { version = "0.4.23", features = ["clock"], default-features = false }
uuid = { version = "1.2.2", features = ["v1", "rng"] }
sea-orm = { version = "0.10.6", default-features = false, features = ["runtime-actix-rustls", "sqlx-mysql"] }
tracing = { version = "0.1.37", default-features = false }
redis = { version = "0.22.1", features = ["aio", "tokio-comp", "connection-manager"] }
rand = { version = "0.8.5", default-features = false, features = ["std", "std_rng"] }
rust-argon2 = { version = "1.0.0", default-features = false }
bcrypt = "0.13.0"
Expand Down
2 changes: 1 addition & 1 deletion iam-common/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ where

apps::Entity::insert(app).exec(db).await?;

let secret = BASE64_STANDARD_NO_PAD.encode(format!("{}:{}", id.to_string(), password));
let secret = BASE64_STANDARD_NO_PAD.encode(format!("{}:{}", id, password));
Ok((id, secret))
}
9 changes: 5 additions & 4 deletions iam-common/src/id.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Display};
use uuid::{
v1::{Context, Timestamp},
Uuid,
Expand Down Expand Up @@ -81,10 +82,10 @@ impl Id {
}
}

impl ToString for Id {
#[inline]
fn to_string(&self) -> String {
format!(
impl Display for Id {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}-{}",
self.get_prefix(),
self.uuid
Expand Down
2 changes: 1 addition & 1 deletion iam-migration/src/m20220822_190837_remove_invite_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl MigrationTrait for Migration {
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
todo!();
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion iam/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn audit_filter(metadata: &tracing::Metadata<'_>) -> bool {
if metadata.is_event() {
return metadata.target().starts_with("audit");
}
return metadata.name().starts_with("audit");
metadata.name().starts_with("audit")
}

#[tokio::main]
Expand Down
23 changes: 0 additions & 23 deletions iam/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
use iam_common::{database, token::Jwt};
use rand::{rngs::StdRng, SeedableRng};
use sea_orm::DbConn;
use std::sync::Arc;

pub trait SharedTrait: Clone + Send + Sync + 'static {
type Db: sea_orm::ConnectionTrait + sea_orm::TransactionTrait;
type Jwt: iam_common::token::JwtTrait;
type Rng: rand::Rng + Clone;

fn db(&self) -> &Self::Db;
fn jwt(&self) -> &Self::Jwt;
fn rng(&self) -> &Self::Rng;
}

pub struct SharedInner {
pub db: DbConn,
pub jwt: Jwt,
pub rng: StdRng,
}

#[derive(Clone)]
Expand All @@ -27,7 +23,6 @@ pub struct Shared {
impl SharedTrait for Shared {
type Db = DbConn;
type Jwt = Jwt;
type Rng = StdRng;

fn db(&self) -> &DbConn {
&self.inner.db
Expand All @@ -36,18 +31,13 @@ impl SharedTrait for Shared {
fn jwt(&self) -> &Jwt {
&self.inner.jwt
}

fn rng(&self) -> &StdRng {
&self.inner.rng
}
}

pub async fn create_shared() -> Shared {
Shared {
inner: Arc::new(SharedInner {
db: database::connect().await,
jwt: Jwt::from_env(),
rng: StdRng::from_entropy(),
}),
}
}
Expand All @@ -57,13 +47,11 @@ pub mod mock {
#![allow(unused)]

use super::*;
use rand::rngs::mock::StepRng;
use sea_orm::MockDatabase;

pub struct MockSharedInner {
db: Option<DbConn>,
jwt: Option<Jwt>,
rng: Option<StepRng>,
}

#[derive(Clone)]
Expand All @@ -76,7 +64,6 @@ pub mod mock {
MockSharedInner {
db: None,
jwt: None,
rng: None,
}
}

Expand All @@ -96,11 +83,6 @@ pub mod mock {
self
}

pub fn rng(mut self, rng: StepRng) -> Self {
self.rng = Some(rng);
self
}

pub fn build(mut self) -> MockShared {
MockShared {
inner: Arc::new(self),
Expand All @@ -111,7 +93,6 @@ pub mod mock {
impl SharedTrait for MockShared {
type Db = DbConn;
type Jwt = Jwt;
type Rng = StepRng;

fn db(&self) -> &DbConn {
self.inner.db.as_ref().expect("database not set")
Expand All @@ -120,9 +101,5 @@ pub mod mock {
fn jwt(&self) -> &Jwt {
self.inner.jwt.as_ref().expect("jwt not set")
}

fn rng(&self) -> &StepRng {
self.inner.rng.as_ref().expect("rng not set")
}
}
}
Loading