Compare commits
7 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
2030d2ad1e | |
|
|
e3a2e9d632 | |
|
|
a408e753a8 | |
|
|
0394851e97 | |
|
|
5eda5d0604 | |
|
|
e646772844 | |
|
|
e358f8b3a7 |
|
|
@ -9,7 +9,7 @@ on:
|
|||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: self-hosted
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: docker build . -t raspberrypi99/request-mirror
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ on:
|
|||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: self-hosted
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: docker build . -t raspberrypi99/request-mirror
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ env:
|
|||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: self-hosted
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v4
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
15
Cargo.toml
15
Cargo.toml
|
|
@ -6,21 +6,22 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4.34"
|
||||
diesel = { version = "2.1.4", features = ["postgres", "chrono"] }
|
||||
chrono = "0.4.39"
|
||||
diesel = { version = "2.2.6", features = ["postgres", "chrono"] }
|
||||
dotenvy = "0.15.7"
|
||||
regex = "1.10.5"
|
||||
regex = "1.11.1"
|
||||
rocket = { version = "0.5.1", features = ["tls"] }
|
||||
serde = { version = "1.0.197", features = ["derive"] }
|
||||
serde_json = "1.0.114"
|
||||
tokio = { version = "1.36.0", features = ["full"] }
|
||||
serde = { version = "1.0.217", features = ["derive"] }
|
||||
serde_json = "1.0.137"
|
||||
tokio = { version = "1.43.0", features = ["full"] }
|
||||
time = "0.3.37"
|
||||
|
||||
[dependencies.rocket_dyn_templates]
|
||||
version = "0.2.0"
|
||||
features = ["handlebars"]
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "1.7.0"
|
||||
version = "1.12.1"
|
||||
features = [
|
||||
"v4", # Lets you generate random UUIDs
|
||||
"fast-rng", # Use a faster (but still sufficiently random) RNG
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
FROM rustlang/rust:nightly as builder
|
||||
FROM rustlang/rust:nightly AS builder
|
||||
WORKDIR /app
|
||||
COPY src ./src
|
||||
COPY Cargo.toml .
|
||||
COPY Cargo.lock .
|
||||
RUN cargo install --path .
|
||||
|
||||
FROM rustlang/rust:nightly as runner
|
||||
FROM rustlang/rust:nightly AS runner
|
||||
COPY migrations /migrations
|
||||
RUN cargo install diesel_cli --no-default-features --features postgres
|
||||
RUN apt update && apt install -y libpq-dev libc6
|
||||
RUN apt update && apt upgrade -y && apt install -y libpq-dev libc6
|
||||
COPY --from=builder /usr/local/cargo/bin/request-mirror /usr/local/bin/request-mirror
|
||||
COPY ./templates /templates
|
||||
COPY .env.docker /.env
|
||||
|
|
|
|||
33
README.md
33
README.md
|
|
@ -117,4 +117,37 @@ Next, you can run the project using the following command. This can be run even
|
|||
|
||||
```bash
|
||||
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
|
||||
```
|
||||
|
|
@ -17,6 +17,8 @@ services:
|
|||
- 80:80
|
||||
environment:
|
||||
- DATABASE_URL=postgres://postgres:Password123@postgres/request_mirror_db
|
||||
# Set COOKIE_EXPIRATION in weeks
|
||||
# - COOKIE_EXPIRATION=52
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
|
|
|
|||
32
src/lib.rs
32
src/lib.rs
|
|
@ -47,6 +47,38 @@ pub fn establish_connection() -> PgConnection {
|
|||
.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
|
||||
///
|
||||
/// Example:
|
||||
|
|
|
|||
10
src/main.rs
10
src/main.rs
|
|
@ -9,6 +9,7 @@ use rocket::outcome::Outcome;
|
|||
use rocket_dyn_templates::Template;
|
||||
use serde::Serialize;
|
||||
use rocket::http::{Cookie, CookieJar, Status};
|
||||
use time::{Duration, OffsetDateTime};
|
||||
use uuid::Uuid;
|
||||
use request_mirror::models::*;
|
||||
use diesel::prelude::*;
|
||||
|
|
@ -61,7 +62,14 @@ impl<'r> FromRequest<'r> for RequestInfo {
|
|||
let new_uuid = Uuid::new_v4().to_string();
|
||||
println!("Creating new cookie");
|
||||
|
||||
req_cookies.add(Cookie::new("mirror-id", new_uuid.clone()));
|
||||
let mut cookie = 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() {
|
||||
req.client_ip().unwrap().to_string()
|
||||
|
|
|
|||
Loading…
Reference in New Issue