Debug endpoint

This commit is contained in:
Valentin Brandl 2019-07-28 17:07:15 +02:00
parent f59470d89f
commit e75a341241
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
2 changed files with 29 additions and 10 deletions

View File

@ -2,7 +2,7 @@ use crate::{
service::Service,
statics::{self, CF_ZONE_IDENT},
};
use actix_web::{http::header, Error};
use actix_web::{http::header, Error, HttpResponse};
use awc::Client;
use futures::Future;
@ -13,6 +13,24 @@ impl Cloudflare {
&CF_ZONE_IDENT
}
pub(crate) fn dbg<T: Service>(
client: &Client,
file: &str,
) -> impl Future<Item = HttpResponse, Error = Error> {
client
.post(format!(
"https://api.cloudflare.com/client/v4/zones/{}/purge_cache",
Self::identifier()
))
.header(header::USER_AGENT, statics::USER_AGENT.as_str())
.header("X-Auth-Email", Self::auth_email())
.header("X-Auth-Key", Self::auth_key())
.content_type("application/json")
.send_json(&CfPurgeRequest::singleton::<T>(file))
.from_err()
.and_then(|response| HttpResponse::build(response.status()).streaming(response))
}
pub(crate) fn purge_cache<T: Service>(
client: &Client,
file: &str,

View File

@ -104,6 +104,13 @@ fn purge_cache<T: Service>(
.map(|success| HttpResponse::Ok().body(success.to_string()))
}
fn dbg<T: Service>(
client: web::Data<Client>,
file: web::Path<String>,
) -> impl Future<Item = HttpResponse, Error = Error> {
Cloudflare::dbg::<T>(&client, &file)
}
fn main() -> Result<()> {
std::env::set_var("RUST_LOG", "actix_server=info,actix_web=trace");
pretty_env_logger::init();
@ -118,26 +125,20 @@ fn main() -> Result<()> {
"/github/{user}/{repo}/{commit}/{file:.*}",
web::get().to_async(handle_request::<Github>),
)
.route(
"/github/{file:.*}",
web::delete().to_async(purge_cache::<Github>),
)
.route("/github/{file:.*}", web::delete().to_async(dbg::<Github>))
.route(
"/bitbucket/{user}/{repo}/{commit}/{file:.*}",
web::get().to_async(handle_request::<Bitbucket>),
)
.route(
"/bitbucket//{file:.*}",
web::delete().to_async(purge_cache::<Bitbucket>),
web::delete().to_async(dbg::<Bitbucket>),
)
.route(
"/gitlab/{user}/{repo}/{commit}/{file:.*}",
web::get().to_async(handle_request::<GitLab>),
)
.route(
"/gitlab/{file:.*}",
web::delete().to_async(purge_cache::<GitLab>),
)
.route("/gitlab/{file:.*}", web::delete().to_async(dbg::<GitLab>))
.service(actix_files::Files::new("/", "public").index_file("index.html"))
})
.workers(OPT.workers)