Compare commits

...

25 Commits
v0.4.0 ... main

Author SHA1 Message Date
Antoine Martin 24c0156b97 lohr: v0.4.5 2023-12-12 15:46:33 +01:00
Antoine Martin 298e895a0b cargo: bump lock again 2023-12-12 15:44:51 +01:00
Antoine Martin b6445e6707 lohr: v0.4.4 2023-12-12 15:39:39 +01:00
Antoine Martin 926f48f979 switch to new rust-toolchain format 2023-12-12 15:37:36 +01:00
Antoine Martin b04748a804 cargo: bump rocket to v0.5 2023-12-12 15:36:56 +01:00
Antoine Martin 77e5214561 lohr: v0.4.3 2023-12-12 15:24:22 +01:00
Antoine Martin 689c57a140 ci: make them runnable manually 2023-12-12 15:18:32 +01:00
Antoine Martin 66d965beee ci: update rust actions 2023-12-12 15:15:56 +01:00
Antoine Martin 708c350c9a ci: bump cachix workflow actions 2023-12-12 15:11:49 +01:00
Antoine Martin 075ca9a23c fix clippy lints 2023-12-12 15:06:59 +01:00
Antoine Martin 25eba69b16 cargo: bump dependencies 2023-12-12 15:01:58 +01:00
Antoine Martin 88609b24fe flake: add rust-analyzer to devshell 2023-12-12 14:57:37 +01:00
Antoine Martin 26eefe2ebe flake.lock: Update
Flake lock file updates:

• Updated input 'flake-compat':
    'github:edolstra/flake-compat/12c64ca55c1014cdc1b16ed5a804aa8576601ff2' (2021-08-02)
  → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Updated input 'flake-utils':
    'github:numtide/flake-utils/997f7efcb746a9c140ce1f13c72263189225f482' (2021-08-20)
  → 'github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725' (2023-12-04)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/08ef0f28e3a41424b92ba1d203de64257a9fca6a' (2021-08-28)
  → 'github:NixOS/nixpkgs/e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d' (2023-12-11)
2023-12-12 14:51:44 +01:00
Antoine Martin 58503cc8b9 flake.lock: Update
Flake input changes:

* Updated 'flake-compat': 'github:edolstra/flake-compat/99f1c2157fba4bfe6211a321fd0ee43199025dbf' -> 'github:edolstra/flake-compat/12c64ca55c1014cdc1b16ed5a804aa8576601ff2'
* Updated 'flake-utils': 'github:numtide/flake-utils/5466c5bbece17adaab2d82fae80b46e807611bf3' -> 'github:numtide/flake-utils/997f7efcb746a9c140ce1f13c72263189225f482'
* Updated 'nixpkgs': 'github:NixOS/nixpkgs/7db379d016a9bad7b7da9b81103ab7454faa3344' -> 'github:NixOS/nixpkgs/08ef0f28e3a41424b92ba1d203de64257a9fca6a'
2021-09-04 18:18:31 +02:00
Antoine Martin a48e59bedc github: fix cachix ci 2021-09-04 18:18:31 +02:00
Antoine Martin c37a390f6c lohr: fix clippy lint 2021-09-04 18:16:38 +02:00
Antoine Martin cd85ace566 github: trigger cachix build on flake change
This also covers version bumps because the version is in the flake
2021-09-04 18:14:14 +02:00
Antoine Martin 964975bada lohr: v0.4.2 2021-06-10 05:40:15 +02:00
Antoine Martin b78c486a0e lohr: upgrade to Rocket v0.5.0-rc.1 2021-06-10 05:36:39 +02:00
Antoine Martin 7fad5a6a87 github: only trigger cachix build on tag 2021-06-04 17:48:39 +02:00
Antoine Martin 5f7d140b61 lohr: v0.4.1 2021-06-04 17:38:37 +02:00
Antoine Martin 1f6fe74d03 lohr: upgrade to latest Rocket master 2021-06-04 17:31:00 +02:00
Antoine Martin fd50523f11 flake.lock: Update
Flake input changes:

* Updated 'nixpkgs': 'github:NixOS/nixpkgs/c0e881852006b132236cbf0301bd1939bb50867e' -> 'github:NixOS/nixpkgs/7db379d016a9bad7b7da9b81103ab7454faa3344'
2021-06-04 15:58:00 +02:00
Antoine Martin d942dc1098 ci: setup cachix build 2021-04-08 04:24:48 +02:00
Antoine Martin bc32f8a565 README: add note about missing versions on crates.io 2021-04-08 02:49:19 +02:00
12 changed files with 870 additions and 684 deletions

20
.github/workflows/cachix.yaml vendored Normal file
View File

@ -0,0 +1,20 @@
name: "Cachix build"
on:
workflow_dispatch:
push:
paths:
- 'flake.nix'
- 'flake.lock'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v24
- uses: cachix/cachix-action@v12
with:
name: alarsyo
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
- run: |
nix build --verbose

View File

@ -1,4 +1,4 @@
on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]
name: CI
@ -8,62 +8,34 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
uses: dtolnay/rust-toolchain@stable
- name: Run cargo check
uses: actions-rs/cargo@v1
with:
command: check
- run: cargo check
test:
name: Test Suite
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
uses: dtolnay/rust-toolchain@stable
- name: Run cargo test
uses: actions-rs/cargo@v1
with:
command: test
- run: cargo test
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
uses: dtolnay/rust-toolchain@stable
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- name: Run cargo clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features -- -D warnings
- run: cargo fmt --all -- --check
- run: cargo clippy --all-features -- -D warnings

1395
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,13 @@
[package]
name = "lohr"
version = "0.4.0"
version = "0.4.5"
authors = ["Antoine Martin <antoine@alarsyo.net>"]
edition = "2018"
license = "Apache-2.0 OR MIT"
description = "A Git mirroring daemon"
homepage = "https://github.com/alarsyo/lohr"
repository = "https://github.com/alarsyo/lohr"
resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -23,7 +24,7 @@ serde_yaml = "0.8.17"
sha2 = "0.9.3"
[dependencies.rocket]
version = "0.5.0-dev"
version = "0.5.0"
# don't need private-cookies
default-features = false
@ -31,6 +32,3 @@ default-features = false
version = "2.33.3"
# no need for suggestions or color with only one argument
default-features = false
[patch.crates-io]
rocket = { git = "https://github.com/SergioBenitez/Rocket", rev = "8d4d01106e2e10b08100805d40bfa19a7357e900" }

View File

@ -28,6 +28,10 @@ install it with `cargo install`:
$ cargo install lohr
Note: currently this method won't get you the latest version of `lohr`, as it
depends on Rocket v0.5.0, which isn't released yet. Updated versions of `lohr`
will be published on crates.io as soon as Rocket v0.5.0 releases.
## Setup
### Quickstart

View File

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1606424373,
"narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=",
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
@ -17,12 +17,15 @@
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1614513358,
"narHash": "sha256-LakhOx3S1dRjnh0b5Dg3mbZyH0ToC9I8Y2wKSkBaTzU=",
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5466c5bbece17adaab2d82fae80b46e807611bf3",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
@ -33,11 +36,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1616670887,
"narHash": "sha256-wn+l9qJfR5sj5Gq4DheJHAcBDfOs9K2p9seW2f35xzs=",
"lastModified": 1702272962,
"narHash": "sha256-D+zHwkwPc6oYQ4G3A1HuadopqRwUY/JkMwHz1YF7j4Q=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "c0e881852006b132236cbf0301bd1939bb50867e",
"rev": "e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d",
"type": "github"
},
"original": {
@ -53,6 +56,21 @@
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -16,11 +16,11 @@
{
defaultPackage = pkgs.rustPlatform.buildRustPackage {
pname = "lohr";
version = "0.4.0";
version = "0.4.5";
src = ./.;
cargoSha256 = "sha256-5a2mK+E6LlR5RHDAhHDvnfPNG+0JdvpnL4kuTiz7vVg=";
cargoHash = "sha256-hext0S0o9D9pN9epzXtD5dwAYMPCLpBBOBT4FX0mTMk=";
meta = with pkgs.lib; {
description = "A Git mirroring tool";
@ -43,6 +43,7 @@
rustPackages.clippy
rustc
rustfmt
rust-analyzer
];
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;

View File

@ -1 +0,0 @@
stable

2
rust-toolchain.toml Normal file
View File

@ -0,0 +1,2 @@
[toolchain]
channel = "stable"

View File

@ -2,7 +2,6 @@ use serde::Deserialize;
#[derive(Clone, Deserialize)]
pub(crate) struct Repository {
pub(crate) name: String,
pub(crate) full_name: String,
pub(crate) ssh_url: String,
}

View File

@ -30,8 +30,8 @@ struct Secret(String);
#[post("/", data = "<payload>")]
fn gitea_webhook(
payload: SignedJson<GiteaWebHook>,
sender: State<JobSender>,
config: State<GlobalSettings>,
sender: &State<JobSender>,
config: &State<GlobalSettings>,
) -> Status {
if config
.blacklist
@ -121,7 +121,7 @@ async fn main() -> anyhow::Result<()> {
repo_updater(receiver, homedir, config);
});
rocket::ignite()
rocket::build()
.mount("/", routes![gitea_webhook])
.manage(JobSender(Mutex::new(sender)))
.manage(Secret(secret))

View File

@ -8,7 +8,7 @@ use rocket::{
http::ContentType,
State,
};
use rocket::{http::Status, local_cache};
use rocket::{http::Status, request::local_cache};
use rocket::{Data, Request};
use anyhow::{anyhow, Context};
@ -72,15 +72,15 @@ where
{
type Error = anyhow::Error;
async fn from_data(request: &'r Request<'_>, data: Data) -> Outcome<Self, Self::Error> {
async fn from_data(request: &'r Request<'_>, data: Data<'r>) -> Outcome<'r, Self> {
let json_ct = ContentType::new("application", "json");
if request.content_type() != Some(&json_ct) {
return Outcome::Failure((Status::BadRequest, anyhow!("wrong content type")));
return Outcome::Error((Status::BadRequest, anyhow!("wrong content type")));
}
let signatures = request.headers().get(X_GITEA_SIGNATURE).collect::<Vec<_>>();
if signatures.len() != 1 {
return Outcome::Failure((
return Outcome::Error((
Status::BadRequest,
anyhow!("request header needs exactly one signature"),
));
@ -91,26 +91,24 @@ where
Ok(s) if s.is_complete() => s.into_inner(),
Ok(_) => {
let eof = io::ErrorKind::UnexpectedEof;
return Outcome::Failure((
return Outcome::Error((
Status::PayloadTooLarge,
io::Error::new(eof, "data limit exceeded").into(),
));
}
Err(e) => return Outcome::Failure((Status::BadRequest, e.into())),
Err(e) => return Outcome::Error((Status::BadRequest, e.into())),
};
let signature = signatures[0];
let secret = request.guard::<State<Secret>>().await.unwrap();
let secret = request.guard::<&State<Secret>>().await.unwrap();
if !validate_signature(&secret.0, &signature, &content) {
return Outcome::Failure((Status::BadRequest, anyhow!("couldn't verify signature")));
if !validate_signature(&secret.0, signature, &content) {
return Outcome::Error((Status::BadRequest, anyhow!("couldn't verify signature")));
}
let content = match Self::from_str(local_cache!(request, content)) {
match Self::from_str(local_cache!(request, content)) {
Ok(content) => Outcome::Success(content),
Err(e) => Outcome::Failure((Status::BadRequest, e)),
};
content
Err(e) => Outcome::Error((Status::BadRequest, e)),
}
}
}