Compare commits

..

No commits in common. "main" and "v0.1.3" have entirely different histories.
main ... v0.1.3

10 changed files with 262 additions and 425 deletions

View File

@ -9,7 +9,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: self-hosted
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: docker build . -t raspberrypi99/request-mirror - run: docker build . -t raspberrypi99/request-mirror

View File

@ -8,7 +8,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: self-hosted
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: docker build . -t raspberrypi99/request-mirror - run: docker build . -t raspberrypi99/request-mirror

View File

@ -11,7 +11,9 @@ env:
jobs: jobs:
build: build:
runs-on: ubuntu-latest
runs-on: self-hosted
steps: steps:
- name: Checkout sources - name: Checkout sources
uses: actions/checkout@v4 uses: actions/checkout@v4

581
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,22 +6,21 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
chrono = "0.4.39" chrono = "0.4.34"
diesel = { version = "2.2.6", features = ["postgres", "chrono"] } diesel = { version = "2.1.4", features = ["postgres", "chrono"] }
dotenvy = "0.15.7" dotenvy = "0.15.7"
regex = "1.11.1" regex = "1.10.5"
rocket = { version = "0.5.1", features = ["tls"] } rocket = { version = "0.5.1", features = ["tls"] }
serde = { version = "1.0.217", features = ["derive"] } serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.137" serde_json = "1.0.114"
tokio = { version = "1.43.0", features = ["full"] } tokio = { version = "1.36.0", features = ["full"] }
time = "0.3.37"
[dependencies.rocket_dyn_templates] [dependencies.rocket_dyn_templates]
version = "0.2.0" version = "0.2.0"
features = ["handlebars"] features = ["handlebars"]
[dependencies.uuid] [dependencies.uuid]
version = "1.12.1" version = "1.7.0"
features = [ features = [
"v4", # Lets you generate random UUIDs "v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG "fast-rng", # Use a faster (but still sufficiently random) RNG

View File

@ -1,14 +1,14 @@
FROM rustlang/rust:nightly AS builder FROM rustlang/rust:nightly as builder
WORKDIR /app WORKDIR /app
COPY src ./src COPY src ./src
COPY Cargo.toml . COPY Cargo.toml .
COPY Cargo.lock . COPY Cargo.lock .
RUN cargo install --path . RUN cargo install --path .
FROM rustlang/rust:nightly AS runner FROM rustlang/rust:nightly as runner
COPY migrations /migrations COPY migrations /migrations
RUN cargo install diesel_cli --no-default-features --features postgres RUN cargo install diesel_cli --no-default-features --features postgres
RUN apt update && apt upgrade -y && apt install -y libpq-dev libc6 RUN apt update && apt install -y libpq-dev libc6
COPY --from=builder /usr/local/cargo/bin/request-mirror /usr/local/bin/request-mirror COPY --from=builder /usr/local/cargo/bin/request-mirror /usr/local/bin/request-mirror
COPY ./templates /templates COPY ./templates /templates
COPY .env.docker /.env COPY .env.docker /.env

View File

@ -117,37 +117,4 @@ Next, you can run the project using the following command. This can be run even
```bash ```bash
docker compose up -d docker compose up -d
```
## Ansible Playbook
You can get access to an ansible playbook and associated files by checking out the following repository
[https://github.com/RaspberryProgramming/CamsAnsibleLibrary/](https://github.com/RaspberryProgramming/CamsAnsibleLibrary)
You can clone the repository
```bash
git clone https://github.com/RaspberryProgramming/CamsAnsibleLibrary
cd CamsAnsibleLibrary/Request\ Mirror/
```
Next, you can create your "inventory" file
```
[request-mirror-host]
10.1.2.3
```
If you haven't already, setup an ssh key so you can automatically log into your remote host as root. If you decide to use a user with sudo privileges you may need to modify the playbook on your own.
```bash
ansible-playbook request_mirror_deployment.yml -i inventory
```
If you need to enter a root password, you can add the -K argument
```bash
ansible-playbook request_mirror_deployment.yml -i inventory -K
``` ```

View File

@ -17,8 +17,6 @@ services:
- 80:80 - 80:80
environment: environment:
- DATABASE_URL=postgres://postgres:Password123@postgres/request_mirror_db - DATABASE_URL=postgres://postgres:Password123@postgres/request_mirror_db
# Set COOKIE_EXPIRATION in weeks
# - COOKIE_EXPIRATION=52
depends_on: depends_on:
postgres: postgres:
condition: service_healthy condition: service_healthy

View File

@ -47,38 +47,6 @@ pub fn establish_connection() -> PgConnection {
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url)) .unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
} }
/// returns default cookie expiration in weeks
///
/// This value can be set by modifying an environment variable or setting in the .env file.
///
/// Example:
///
/// ```rust,ignore
/// use request_mirror::establish_connection;
///
/// let connection = establish_connection();
/// ```
pub fn cookie_expiration() -> i64 {
let key: &str = "COOKIE_EXPIRATION";
let expiration: i64;
match env::var(key) {
Ok(val) => {
match val.parse::<i64>() {
Ok(v) => expiration = v,
Err(e) => expiration = 52
}
},
Err(_e) => {
dotenv().ok();
expiration = 52;
}
}
expiration
}
/// Used to create a new client in the database. You need to pass a connection, the ip and client_id /// Used to create a new client in the database. You need to pass a connection, the ip and client_id
/// ///
/// Example: /// Example:

View File

@ -9,7 +9,6 @@ use rocket::outcome::Outcome;
use rocket_dyn_templates::Template; use rocket_dyn_templates::Template;
use serde::Serialize; use serde::Serialize;
use rocket::http::{Cookie, CookieJar, Status}; use rocket::http::{Cookie, CookieJar, Status};
use time::{Duration, OffsetDateTime};
use uuid::Uuid; use uuid::Uuid;
use request_mirror::models::*; use request_mirror::models::*;
use diesel::prelude::*; use diesel::prelude::*;
@ -62,14 +61,7 @@ impl<'r> FromRequest<'r> for RequestInfo {
let new_uuid = Uuid::new_v4().to_string(); let new_uuid = Uuid::new_v4().to_string();
println!("Creating new cookie"); println!("Creating new cookie");
let mut cookie = Cookie::new("mirror-id", new_uuid.clone()); req_cookies.add(Cookie::new("mirror-id", new_uuid.clone()));
let mut now = OffsetDateTime::now_utc();
now += Duration::weeks(cookie_expiration()); // Default expiration is 52 weeks
cookie.set_expires(now);
req_cookies.add(cookie);
let address = if req.client_ip().is_some() { let address = if req.client_ip().is_some() {
req.client_ip().unwrap().to_string() req.client_ip().unwrap().to_string()