Verified Commit 444300be authored by Sven-Hendrik Haase's avatar Sven-Hendrik Haase
Browse files

More project setup

parent 7fa0044b
image: "archlinux:base-devel"
before_script:
- pacman -Syu --needed --noconfirm rust
stages:
- lint
- test
format:
stage: lint
script:
- cargo fmt --all -- --check
clippy:
stage: lint
script:
- cargo clippy --all -- -D warnings
check:
stage: lint
script:
- cargo check --all --verbose --release
test:
stage: test
script:
- cargo test
coverage:
stage: test
script:
- cargo install cargo-tarpaulin
- cargo tarpaulin
This diff is collapsed.
......@@ -14,3 +14,13 @@ lto = true
codegen-units = 1
[dependencies]
structopt = "0.3"
keycloak = "11"
bcrypt = "0.9"
url = "2"
reqwest = { version = "0.10", features = [ "json" ] }
anyhow = "1"
actix-web = "3"
log = "0.4"
pretty_env_logger = "0.4"
serde_json = "1"
# Mail Credential Syncer
Small tool to sync mail passwords from Keycloak to Dovecot
\ No newline at end of file
Small tool to sync mail passwords from Keycloak to Dovecot
## How to run
First of all, we need to start a pre-configured Keycloak server to run our tests against:
keycloak/run-keycloak-container.sh
#!/usr/bin/env bash
docker run --rm --name keycloak \
-v $PWD/keycloak/keycloak_http_webhook_provider-jar-with-dependencies.jar:/opt/jboss/keycloak/standalone/deployments/http_webhook_provider.jar \
-v $PWD/keycloak/standalone-ha.xml:/opt/jboss/keycloak/standalone/configuration/standalone-ha.xml \
-v $PWD/keycloak/startup-script.sh:/opt/jboss/startup-scripts/startup-script.sh \
-e KEYCLOAK_USER=admin \
-e KEYCLOAK_PASSWORD=admin \
-p 8080:8080 \
--add-host host.docker.internal:$(ip addr show docker0 | grep -Po 'inet \K[\d.]+') \
"$@" \
jboss/keycloak
This diff is collapsed.
#!/usr/bin/env bash
#
# We have to do it this weird way because Keycloak runs startup scripts BEFORE
# Keycloak has started so it won't work as we'll have to use the HTTP REST API.
# So this script background itself and just polls for the API to become available.
add_http_listener() {
for i in {1..10}; do
curl --silent --head --fail http://localhost:8080/auth && \
/opt/jboss/keycloak/bin/kcadm.sh update events/config -s eventsListeners+=http \
--no-config --server http://localhost:8080/auth --user admin --password admin --realm master && \
exit 0
sleep 2
done
exit 1
}
add_http_listener &
fn main() {
println!("Hello, world!");
use actix_web::{post, web, middleware::Logger, App, HttpResponse, HttpServer, Responder};
use anyhow::{Context, Result};
use std::net::SocketAddr;
use std::path::PathBuf;
use structopt::StructOpt;
use url::Url;
#[derive(StructOpt, Debug)]
#[structopt(
name = "mail-credential-syncer",
author,
about,
global_settings = &[structopt::clap::AppSettings::ColoredHelp],
)]
struct CliConfig {
/// Local socket address to listen on
#[structopt(long)]
listen: SocketAddr,
/// Username for basic auth of HTTP endpoint
#[structopt(long, env)]
basic_auth_username: String,
/// Password for basic auth of HTTP endpoint
#[structopt(long, env)]
basic_auth_password: String,
/// Path to file containing Keycloak UUID to mail address mappings
#[structopt(long)]
mailmap: PathBuf,
/// Path to a post-sync hook executable
#[structopt(long)]
post_sync_hook: PathBuf,
/// Keycloak URL for incoming webhook validation and periodic syncs
#[structopt(long)]
keycloak_url: Url,
/// Keycloak admin username
#[structopt(long, env)]
keycloak_admin_username: String,
/// Keycloak admin password
#[structopt(long, env)]
keycloak_admin_password: String,
}
#[post("/webhook")]
async fn webhook(info: web::Json<serde_json::Value>) -> impl Responder {
println!("{:#}", info);
HttpResponse::Ok().body("Hello world!")
}
#[actix_web::main]
async fn main() -> Result<()> {
std::env::set_var("RUST_LOG", "actix_web=info");
pretty_env_logger::init();
// let args = CliConfig::from_args();
HttpServer::new(|| App::new().wrap(Logger::default()).service(webhook))
.bind("0.0.0.0:5000")?
.run()
.await
.context("Failed to run actix")
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment