Configure Lints, containerize tests, add structure, minor test changes, add routes of token auth

This commit is contained in:
Laurenz 2024-04-11 17:52:09 +02:00
parent 065cae6f26
commit cdae3c2fd3
15 changed files with 133 additions and 112 deletions

98
Cargo.lock generated
View file

@ -82,7 +82,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
"syn",
]
[[package]]
@ -259,12 +259,6 @@ dependencies = [
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "fnv"
version = "1.0.7"
@ -338,12 +332,6 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "hermit-abi"
version = "0.3.9"
@ -437,17 +425,6 @@ dependencies = [
"tokio",
]
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -619,7 +596,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
"syn",
]
[[package]]
@ -634,30 +611,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn 1.0.109",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "1.0.79"
@ -764,7 +717,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
"syn",
]
[[package]]
@ -806,8 +759,8 @@ version = "0.1.0"
dependencies = [
"axum",
"env_logger",
"log",
"tokio",
"utoipa",
]
[[package]]
@ -859,16 +812,6 @@ dependencies = [
"sled",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.58"
@ -919,7 +862,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.58",
"syn",
]
[[package]]
@ -982,37 +925,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "utoipa"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "272ebdfbc99111033031d2f10e018836056e4d2c8e2acda76450ec7974269fa7"
dependencies = [
"indexmap",
"serde",
"serde_json",
"utoipa-gen",
]
[[package]]
name = "utoipa-gen"
version = "4.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3c9f4d08338c1bfa70dde39412a040a884c6f318b3d09aaaf3437a1e52027fc"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"regex",
"syn 2.0.58",
]
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"

View file

@ -1,6 +1,6 @@
[workspace]
workspace.resolver = "2"
resolver = "2"
members = ["crates/*"]
default-members = ["crates/server"]
@ -9,3 +9,11 @@ log = "0.4.21"
env_logger = "0.11.3"
tokio = "1.37.0"
axum = "0.7.5"
[workspace.lints.clippy]
uninlined_format_args = "warn"
correctness = "warn"
suspicious = "warn"
complexity = "warn"
perf = "warn"
style = "warn"

View file

@ -3,6 +3,7 @@ name = "auth-token"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true
[dependencies]

View file

@ -3,7 +3,8 @@ name = "backend-kv"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true
[dependencies]
base = { path = "../base" }

View file

@ -3,6 +3,7 @@ name = "base"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true
[dependencies]

View file

@ -3,10 +3,14 @@ name = "server"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
# [target.x86_64-unknown-linux-gnu]
# rustflags = ["-C", "linker=clang", "-C", "link-arg=-fuse-ld=lld"]
[lints]
workspace = true
[dependencies]
log = { workspace = true }
env_logger = { workspace = true }
tokio = { workspace = true, features=["full"] }
axum = { workspace = true }
utoipa = { version = "4", features = ["axum_extras"] }
tokio = { workspace = true, features = ["full"] }
axum = { workspace = true, features = ["json"] }

10
crates/server/src/auth.rs Normal file
View file

@ -0,0 +1,10 @@
use axum::Router;
use self::token::token_auth_router;
// route prefix: `/auth/token/`
mod token;
pub fn auth_router() -> Router {
Router::new().nest("/token", token_auth_router())
}

View file

@ -0,0 +1,45 @@
use axum::Router;
pub fn token_auth_router() -> Router {
Router::new()
}
async fn get_accessors() {}
async fn post_create() {}
async fn post_create_orphan() {}
async fn post_create_role() {}
async fn get_lookup() {}
async fn post_lookup() {}
async fn get_lookup_self() {}
async fn post_lookup_self() {}
async fn post_renew() {}
async fn post_renew_accessor() {}
async fn post_renew_self() {}
async fn post_revoke() {}
async fn post_revoke_accessor() {}
async fn post_revoke_orphan() {}
async fn post_revoke_self() {}
async fn get_roles() {}
async fn get_role_by_name() {}
async fn post_role_by_name() {}
async fn delete_role_by_name() {}
async fn post_tidy() {}

View file

@ -0,0 +1 @@

View file

@ -1,19 +1,38 @@
use axum::{routing::get, Router};
use axum::{
http::{StatusCode, Uri},
routing::get,
Router,
};
use log::warn;
use tokio::net::TcpListener;
mod auth;
mod identity;
mod secrets;
mod sys;
#[tokio::main]
async fn main() {
env_logger::init();
// build our application with a route
let app = Router::new()
.route("/", get(root));
.route("/", get(root))
.nest("/v1/auth", auth::auth_router())
.fallback(fallback_route_unknown);
// run our app with hyper, listening globally on port 8200
let listener = tokio::net::TcpListener::bind("[::]:8200").await.unwrap();
let listener = TcpListener::bind("[::]:8200").await.unwrap();
warn!("Listening on: {}", listener.local_addr().unwrap());
axum::serve(listener, app).await.unwrap();
}
async fn fallback_route_unknown(uri: Uri, body: String) -> (StatusCode, &'static str) {
log::error!("Route not found: {}, payload {}", uri, body);
(StatusCode::NOT_FOUND, "Route not implemented")
}
// basic handler that responds with a static string
async fn root() -> &'static str {
log::info!("Hello world");
"Hello, World!"
}

View file

@ -0,0 +1 @@

1
crates/server/src/sys.rs Normal file
View file

@ -0,0 +1 @@

View file

@ -3,7 +3,8 @@ name = "storage-sled"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints]
workspace = true
[dependencies]
base = { path = "../base" }

14
go_client/Containerfile Normal file
View file

@ -0,0 +1,14 @@
FROM docker.io/library/golang:1.22-alpine3.19 AS builder
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
RUN go build -o /app
FROM docker.io/library/alpine:3.19
COPY --from=builder /app /app
CMD ["/app"]

View file

@ -16,7 +16,7 @@ func main() {
// prepare a client with the given base address
client, err := vault.New(
vault.WithAddress("http://127.0.0.1:8200"),
vault.WithAddress("http://localhost:8200"),
vault.WithRequestTimeout(30*time.Second),
)
if err != nil {
@ -36,17 +36,19 @@ func main() {
"password1": "abc123",
"password2": "correct horse battery staple",
}},
vault.WithMountPath("secret"),
vault.WithMountPath("kw_mount_path"),
)
if err != nil {
log.Fatal(err)
log.Fatal("kv2: Failed to write secret:\n\t", err)
} else {
log.Println("kv2: Secret written (apparently)")
}
log.Println("secret written successfully")
// read the secret
s, err := client.Secrets.KvV2Read(ctx, "foo", vault.WithMountPath("secret"))
if err != nil {
log.Fatal(err)
}
} else {
log.Println("secret retrieved:", s.Data.Data)
}
}