mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Moved the workspace to the root, Added the build scripts, ARM64 releases and the Docker image
Source/'s content is at the root now, Source/README.md merged into readme.md. Scripts at the root: build.ps1, test.ps1 (was check.ps1), release.ps1 (over release.py) and clean.ps1. Everything is LF except the .ps1 files. CI (.github/workflows/ci.yml) runs on a v* tag or by hand: the checks, then a release for Windows x64 and ARM64 and Linux x64 and ARM64, each on its own kind of runner, the archives kept as artifacts. release.py names the platform from the Rust host, make_wheel.py tags the wheel from the library's header. docker/: the server's image (built from source, the tools beside it, uid 10001), compose.yml and test.sh. CI builds amd64 and arm64 natively, checks them, and on a tag pushes them to ghcr.io with an index for <version> and latest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
//! A server on a free port, in a folder of its own with its CA and the
|
||||
//! clients' certificates.
|
||||
|
||||
use bakashrot_config::Config;
|
||||
use bakashrot_pki::{Ca, Identity, Usage};
|
||||
use bakashrot_server::Server;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const CONFIG: &str = r#"
|
||||
[server]
|
||||
listen = "127.0.0.1:0"
|
||||
ca = "ca.crt"
|
||||
certificate = "server.crt"
|
||||
key = "server.key"
|
||||
topics = ["logs", "secret"]
|
||||
|
||||
[roles.home]
|
||||
push_topics = ["logs", "secret"]
|
||||
read_topics = ["*"]
|
||||
query = true
|
||||
|
||||
[roles.lounge]
|
||||
read_topics = ["logs"]
|
||||
"#;
|
||||
|
||||
pub struct Running {
|
||||
pub folder: PathBuf,
|
||||
pub port: u16,
|
||||
ca: Ca,
|
||||
// Kept for the server's tasks to run.
|
||||
_runtime: tokio::runtime::Runtime,
|
||||
}
|
||||
|
||||
impl Running {
|
||||
pub fn start(name: &str) -> Running {
|
||||
let folder = PathBuf::from(env!("CARGO_TARGET_TMPDIR"))
|
||||
.join(format!("capi-{}-{name}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&folder);
|
||||
std::fs::create_dir_all(&folder).unwrap();
|
||||
let issued = Ca::create("Test CA", 10).unwrap();
|
||||
let ca = Ca::load(&issued.certificate, &issued.key).unwrap();
|
||||
let server = ca
|
||||
.issue(
|
||||
&Identity::new("server-1", &["peer"]).unwrap(),
|
||||
Usage::Server,
|
||||
10,
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(folder.join("ca.crt"), &issued.certificate).unwrap();
|
||||
std::fs::write(folder.join("server.crt"), &server.certificate).unwrap();
|
||||
std::fs::write(folder.join("server.key"), &server.key).unwrap();
|
||||
// `SYNC=normal` to measure without a disk flush per push.
|
||||
let sync = std::env::var("SYNC").unwrap_or_else(|_| "full".into());
|
||||
let config = CONFIG.replace(
|
||||
"[roles.home]",
|
||||
&format!(
|
||||
"synchronous = \"{sync}\"
|
||||
|
||||
[roles.home]"
|
||||
),
|
||||
);
|
||||
std::fs::write(folder.join("server.toml"), config).unwrap();
|
||||
let config = Config::load(&folder.join("server.toml")).unwrap();
|
||||
let server = Server::start(config).unwrap();
|
||||
|
||||
let runtime = tokio::runtime::Runtime::new().unwrap();
|
||||
let listener = runtime
|
||||
.block_on(tokio::net::TcpListener::bind("127.0.0.1:0"))
|
||||
.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
runtime.spawn(async move { server.serve(listener).await });
|
||||
Running {
|
||||
folder,
|
||||
port,
|
||||
ca,
|
||||
_runtime: runtime,
|
||||
}
|
||||
}
|
||||
|
||||
/// Issues a client's certificate, written as `<name>.crt` and
|
||||
/// `<name>.key`, with a `<name>.toml` to connect with.
|
||||
pub fn issue(&self, name: &str, roles: &[&str]) {
|
||||
let issued = self
|
||||
.ca
|
||||
.issue(&Identity::new(name, roles).unwrap(), Usage::Client, 10)
|
||||
.unwrap();
|
||||
std::fs::write(self.folder.join(format!("{name}.crt")), &issued.certificate).unwrap();
|
||||
std::fs::write(self.folder.join(format!("{name}.key")), &issued.key).unwrap();
|
||||
let toml = format!(
|
||||
"server = \"127.0.0.1:{}\"\nca = \"ca.crt\"\ncertificate = \"{name}.crt\"\nkey = \"{name}.key\"\n",
|
||||
self.port
|
||||
);
|
||||
std::fs::write(self.folder.join(format!("{name}.toml")), toml).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user