diff --git a/Cargo.lock b/Cargo.lock index 55995c0..2c050ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,6 +56,17 @@ dependencies = [ "trust-dns-resolver 0.18.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "actix-cors" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "actix-service 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.99.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "actix-http" version = "1.0.1" @@ -71,7 +82,7 @@ dependencies = [ "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "brotli2 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "copyless 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.99.9 (registry+https://github.com/rust-lang/crates.io-index)", "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -398,7 +409,7 @@ name = "brotli-sys" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -444,7 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.56" +version = "1.0.57" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -454,7 +465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "chrono" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", @@ -550,9 +561,10 @@ name = "dumnati" version = "0.0.1-dev" dependencies = [ "actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "actix-web 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "cbloom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "envsubst 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -774,7 +786,7 @@ name = "generator" version = "0.6.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1201,7 +1213,7 @@ version = "0.9.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.71 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2061,6 +2073,7 @@ dependencies = [ "checksum actix 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4af87564ff659dee8f9981540cac9418c45e910c8072fdedd643a262a38fcaf" "checksum actix-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09e55f0a5c2ca15795035d90c46bd0e73a5123b72f68f12596d6ba5282051380" "checksum actix-connect 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c95cc9569221e9802bf4c377f6c18b90ef10227d787611decf79fd47d2a8e76c" +"checksum actix-cors 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a6206917d5c0fdd79d81cec9ef02d3e802df4abf276d96241e1f595d971e002" "checksum actix-http 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c16664cc4fdea8030837ad5a845eb231fb93fc3c5c171edfefb52fad92ce9019" "checksum actix-macros 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a60f9ba7c4e6df97f3aacb14bb5c0cd7d98a49dcbaed0d7f292912ad9a6a3ed2" "checksum actix-router 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d7a10ca4d94e8c8e7a87c5173aba1b97ba9a6563ca02b0e1cd23531093d3ec8" @@ -2095,9 +2108,9 @@ dependencies = [ "checksum bytes 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "118cf036fbb97d0816e3c34b2d7a1e8cfc60f68fcf63d550ddbe9bd5f59c213b" "checksum bytestring 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fc7c05fa5172da78a62d9949d662d2ac89d4cc7355d7b49adee5163f1fb3f363" "checksum cbloom 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0dae93c94b6b0538bc02c6844855d31bd362804da80c3cc4b455a00b9851caff" -"checksum cc 1.0.56 (registry+https://github.com/rust-lang/crates.io-index)" = "77c1f1d60091c1b73e2b1f4560ab419204b178e625fa945ded7b660becd2bd46" +"checksum cc 1.0.57 (registry+https://github.com/rust-lang/crates.io-index)" = "0fde55d2a2bfaa4c9668bbc63f531fbdeee3ffe188f4662511ce2c22b3eedebe" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -"checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +"checksum chrono 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "f0fee792e164f78f5fe0c296cc2eb3688a2ca2b70cdff33040922d298203f0c4" "checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum copyless 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536" diff --git a/dumnati/Cargo.toml b/dumnati/Cargo.toml index 920fbb3..78481cc 100644 --- a/dumnati/Cargo.toml +++ b/dumnati/Cargo.toml @@ -9,6 +9,7 @@ publish = false [dependencies] actix = "^0.9.0" +actix-cors = "^0.2" actix-web = "^2.0.0" cbloom = "^0.1.3" chrono = "^0.4.7" diff --git a/dumnati/src/main.rs b/dumnati/src/main.rs index 8e04833..51f1e8b 100644 --- a/dumnati/src/main.rs +++ b/dumnati/src/main.rs @@ -10,6 +10,7 @@ mod policy; mod scraper; use actix::prelude::*; +use actix_cors::CorsFactory; use actix_web::{web, App, HttpResponse}; use failure::{Error, Fallible}; use prometheus::{Histogram, IntCounter, IntCounterVec, IntGauge, IntGaugeVec}; @@ -74,6 +75,8 @@ fn main() -> Fallible<()> { let sys = actix::System::new("dumnati"); // TODO(lucab): figure out all configuration params. + let gb_allowed_origins = vec!["https://builds.coreos.fedoraproject.org"]; + let pe_allowed_origins = vec!["https://builds.coreos.fedoraproject.org"]; let streams_cfg = maplit::btreeset!["next", "stable", "testing"]; let mut scrapers = HashMap::with_capacity(streams_cfg.len()); for stream in streams_cfg { @@ -94,6 +97,7 @@ fn main() -> Fallible<()> { let gb_service = service_state.clone(); actix_web::HttpServer::new(move || { App::new() + .wrap(build_cors_middleware(&gb_allowed_origins)) .data(gb_service.clone()) .route("/v1/graph", web::get().to(gb_serve_graph)) }) @@ -114,6 +118,7 @@ fn main() -> Fallible<()> { let pe_service = service_state.clone(); actix_web::HttpServer::new(move || { App::new() + .wrap(build_cors_middleware(&pe_allowed_origins)) .data(pe_service.clone()) .route("/v1/graph", web::get().to(pe_serve_graph)) }) @@ -266,6 +271,15 @@ pub(crate) fn pe_record_metrics(data: &AppState, query: &GraphQuery) { } } +/// Provide a CORS middleware allowing given origins. +pub(crate) fn build_cors_middleware(allowed_origins: &[&str]) -> CorsFactory { + let mut builder = actix_cors::Cors::new(); + for origin in allowed_origins { + builder = builder.allowed_origin(origin); + } + builder.finish() +} + #[derive(Debug, StructOpt)] pub(crate) struct CliOptions { /// Path to configuration file.