aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock102
-rw-r--r--Cargo.toml6
-rw-r--r--src/config.rs12
-rw-r--r--src/login.rs17
-rw-r--r--src/main.rs2
5 files changed, 138 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c98f596..8747145 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -104,6 +104,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
+[[package]]
name = "errno"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -119,17 +125,35 @@ version = "0.1.0"
dependencies = [
"clap",
"log",
+ "serde",
"shlex",
"systemd-journal-logger",
+ "toml",
]
[[package]]
+name = "hashbrown"
+version = "0.14.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
+
+[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]
+name = "indexmap"
+version = "2.2.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
+[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -157,6 +181,12 @@ dependencies = [
]
[[package]]
+name = "memchr"
+version = "2.7.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
+
+[[package]]
name = "proc-macro2"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -188,6 +218,35 @@ dependencies = [
]
[[package]]
+name = "serde"
+version = "1.0.204"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.204"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -221,6 +280,40 @@ dependencies = [
]
[[package]]
+name = "toml"
+version = "0.8.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac2caab0bf757388c6c0ae23b3293fdb463fee59434529014f85e3263b995c28"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "278f3d518e152219c994ce877758516bca5e118eaed6996192a774fb9fbf0788"
+dependencies = [
+ "indexmap",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "winnow",
+]
+
+[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -310,3 +403,12 @@ name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+
+[[package]]
+name = "winnow"
+version = "0.6.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1"
+dependencies = [
+ "memchr",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 1744a9d..49a71cb 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,8 +5,14 @@ edition = "2021"
[dependencies]
log = "0.4.22"
+
shlex = "1.3.0"
systemd-journal-logger = "2.1.1"
+[dependencies.toml]
+version = "0.8.15"
[dependencies.clap]
version = "4.5.9"
features = ["cargo", "derive"]
+[dependencies.serde]
+version = "1.0.204"
+features = ["derive"]
diff --git a/src/config.rs b/src/config.rs
index 5e8cc5d..9335cca 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,5 +1,7 @@
use std::path::Path;
+use serde::Deserialize;
+
pub fn ssh_user() -> &'static str {
return "git";
}
@@ -9,3 +11,13 @@ pub fn binary_path() -> &'static str {
pub fn repo_store() -> &'static Path {
return Path::new("/opt/fagit/store/");
}
+
+#[derive(Deserialize, Default)]
+pub struct RepoConfig {
+ pub access: Vec<KeyPermission>,
+}
+
+#[derive(Deserialize)]
+pub struct KeyPermission {
+ key: String,
+}
diff --git a/src/login.rs b/src/login.rs
index ca12c50..8639d35 100644
--- a/src/login.rs
+++ b/src/login.rs
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};
+use crate::config::RepoConfig;
use crate::Login;
use clap::Args;
@@ -72,6 +73,22 @@ impl RepoId {
fn repo_path(&self) -> PathBuf {
return Path::join(crate::config::repo_store(), self.0.clone());
}
+
+ fn get_config(&self) -> RepoConfig {
+ let config_process = std::process::Command::new("git")
+ .args([
+ "-C",
+ self.repo_path().to_str().unwrap(),
+ "show",
+ "HEAD:.fagit.toml",
+ ])
+ .output()
+ .unwrap();
+ if !config_process.status.success() {
+ return RepoConfig::default();
+ }
+ toml::de::from_str(&String::from_utf8(config_process.stdout).unwrap()).unwrap()
+ }
}
fn canonicalize_repo(path: &str, user: &UserToken) -> RepoId {
diff --git a/src/main.rs b/src/main.rs
index cb5a926..166f34c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -52,7 +52,7 @@ mod login;
fn find_auth_keys(auth: &Auth) {
if auth.user != config::ssh_user() {
- let authorized_keys_path = Path::new(&auth.home).join(".ssh/authorized_keys_path");
+ let authorized_keys_path = Path::new(&auth.home).join(".ssh/authorized_keys");
let mut data = std::fs::File::open(authorized_keys_path).unwrap();
let mut vec = vec![];
data.read_to_end(&mut vec).unwrap();