Skip to content

Commit

Permalink
auth: auth-server: Define key management API
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Oct 22, 2024
1 parent e23f495 commit 2186e9d
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 42 deletions.
82 changes: 67 additions & 15 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
@@ -1,13 +1,14 @@
[workspace]
members = [
"auth/auth-server",
"auth/auth-server-api",
"compliance/compliance-server",
"compliance/compliance-api",
"dealer/renegade-dealer",
"dealer/renegade-dealer-api",
"funds-manager/funds-manager-api",
"funds-manager/funds-manager-server",
"price-reporter",
"auth-server",
]

[profile.bench]
Expand Down
8 changes: 8 additions & 0 deletions auth/auth-server-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "auth-server-api"
version = "0.1.0"
edition = "2021"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
uuid = "1.0"
36 changes: 36 additions & 0 deletions auth/auth-server-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! API types for the auth server

#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
#![deny(unsafe_code)]
#![deny(clippy::needless_pass_by_ref_mut)]
#![feature(trivial_bounds)]

use serde::Deserialize;
use uuid::Uuid;

// ----------------------
// | API Key Management |
// ----------------------

/// The path to create a new API key
///
/// POST /api-keys
pub const API_KEYS_PATH: &str = "api-keys";
/// The path to mark an API key as inactive
///
/// POST /api-keys/{id}/deactivate
pub const DEACTIVATE_API_KEY_PATH: &str = "deactivate";

/// A request to create a new API key
#[derive(Debug, Deserialize)]
pub struct CreateApiKeyRequest {
/// The API key id
pub id: Uuid,
/// The API key secret
///
/// Expected as a base64 encoded string
pub secret: String,
/// The name of the API key
pub name: String,
}
13 changes: 12 additions & 1 deletion auth-server/Cargo.toml → auth/auth-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,27 @@ warp = "0.3"

# === Database === #
bb8 = "0.8"
diesel = { version = "2", features = ["postgres"] }
diesel = { version = "2", features = ["postgres", "chrono", "uuid"] }
diesel-async = { version = "0.4", features = ["postgres", "bb8"] }
tokio-postgres = "0.7"
postgres-native-tls = "0.5"
native-tls = "0.2"

# === Cryptography === #
aes-gcm = "0.10.1"
rand = "0.8.5"

# === Renegade Dependencies === #
auth-server-api = { path = "../auth-server-api" }
renegade-utils = { package = "util", git = "https://github.com/renegade-fi/renegade" }

# === Misc Dependencies === #
base64 = "0.22.1"
bytes = "1.0"
chrono = { version = "0.4", features = ["serde"] }
futures-util = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
tracing = "0.1"
uuid = { version = "1.0", features = ["serde", "v4"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions auth/auth-server/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Error types for the auth server

use thiserror::Error;

/// Custom error type for server errors
#[derive(Error, Debug)]
pub enum AuthServerError {
/// Database connection error
#[error("Database connection error: {0}")]
DatabaseConnection(String),

/// Encryption error
#[error("Encryption error: {0}")]
Encryption(String),

/// Decryption error
#[error("Decryption error: {0}")]
Decryption(String),
}

impl AuthServerError {
/// Create a new database connection error
pub fn db<T: ToString>(msg: T) -> Self {

Check failure on line 23 in auth/auth-server/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument is passed by value, but not consumed in the function body

error: this argument is passed by value, but not consumed in the function body --> auth/auth-server/src/error.rs:23:33 | 23 | pub fn db<T: ToString>(msg: T) -> Self { | ^ help: consider taking a reference instead: `&T` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value = note: requested on the command line with `-D clippy::needless-pass-by-value`
Self::DatabaseConnection(msg.to_string())
}

/// Create a new encryption error
pub fn encryption<T: ToString>(msg: T) -> Self {

Check failure on line 28 in auth/auth-server/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument is passed by value, but not consumed in the function body

error: this argument is passed by value, but not consumed in the function body --> auth/auth-server/src/error.rs:28:41 | 28 | pub fn encryption<T: ToString>(msg: T) -> Self { | ^ help: consider taking a reference instead: `&T` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
Self::Encryption(msg.to_string())
}

/// Create a new decryption error
pub fn decryption<T: ToString>(msg: T) -> Self {

Check failure on line 33 in auth/auth-server/src/error.rs

View workflow job for this annotation

GitHub Actions / clippy

this argument is passed by value, but not consumed in the function body

error: this argument is passed by value, but not consumed in the function body --> auth/auth-server/src/error.rs:33:41 | 33 | pub fn decryption<T: ToString>(msg: T) -> Self { | ^ help: consider taking a reference instead: `&T` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
Self::Decryption(msg.to_string())
}
}

impl warp::reject::Reject for AuthServerError {}
Loading

0 comments on commit 2186e9d

Please sign in to comment.