From 90b9d53bf883a68c877555830b6acaceda1744cc Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Wed, 4 Nov 2020 11:03:04 -0500 Subject: [PATCH] cleanups --- backend/Rocket.example.toml | 2 -- backend/src/main.rs | 12 ++++++------ backend/src/web/discord_webhook.rs | 4 +++- backend/src/web/mastodon.rs | 7 +------ 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/backend/Rocket.example.toml b/backend/Rocket.example.toml index 47c3426..bbd5327 100644 --- a/backend/Rocket.example.toml +++ b/backend/Rocket.example.toml @@ -29,8 +29,6 @@ api_secret = "..." # the API. [global.mastodon] instance = "..." -app_id = "..." -app_secret = "..." token = "..." account = "..." diff --git a/backend/src/main.rs b/backend/src/main.rs index 917aa37..3cf532b 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -9,7 +9,7 @@ use color_eyre::eyre::Result; use rocket_contrib::helmet::SpaceHelmet; use rocket_prometheus::PrometheusMetrics; -use ::mi::{api, paseto, web, MainDatabase, APPLICATION_NAME}; +use ::mi::{api, paseto, web::*, MainDatabase, APPLICATION_NAME}; #[get("/.within/botinfo")] fn botinfo() -> &'static str { @@ -43,11 +43,11 @@ fn main() -> Result<()> { .attach(MainDatabase::fairing()) .attach(SpaceHelmet::default()) .attach(paseto::ed25519_keypair()) - .attach(web::discord_webhook::Client::fairing()) - .attach(web::mastodon::Client::fairing()) - .attach(web::pluralkit::Client::fairing()) - .attach(web::switchcounter::Client::fairing()) - .attach(web::twitter::Client::fairing()) + .attach(discord_webhook::Client::fairing()) + .attach(mastodon::Client::fairing()) + .attach(pluralkit::Client::fairing()) + .attach(switchcounter::Client::fairing()) + .attach(twitter::Client::fairing()) .mount("/metrics", prometheus) .mount("/", routes![botinfo]) .mount( diff --git a/backend/src/web/discord_webhook.rs b/backend/src/web/discord_webhook.rs index 007b55c..a6e1972 100644 --- a/backend/src/web/discord_webhook.rs +++ b/backend/src/web/discord_webhook.rs @@ -44,7 +44,9 @@ impl Client { } pub fn send(&self, body: String) -> Result<()> { - let resp = ureq::post(&self.webhook_url).send_json(serde_json::to_value(Body::new(body))?); + let resp = ureq::post(&self.webhook_url) + .set("User-Agent", crate::APPLICATION_NAME) + .send_json(serde_json::to_value(Body::new(body))?); if resp.ok() { Ok(()) diff --git a/backend/src/web/mastodon.rs b/backend/src/web/mastodon.rs index 13ba277..3c1fe15 100644 --- a/backend/src/web/mastodon.rs +++ b/backend/src/web/mastodon.rs @@ -3,8 +3,6 @@ use rocket::fairing::AdHoc; pub struct Client { instance_url: String, - app_id: String, - app_secret: String, token: String, account_name: String, } @@ -15,15 +13,11 @@ impl Client { let cfg = rocket.config(); let table = cfg.get_table("mastodon").unwrap(); let instance_url = table["instance"].as_str().unwrap().to_string(); - let app_id = table["app_id"].as_str().unwrap().to_string(); - let app_secret = table["app_secret"].as_str().unwrap().to_string(); let token = table["token"].as_str().unwrap().to_string(); let account_name = table["account"].as_str().unwrap().to_string(); let cli = Client { instance_url: instance_url, - app_id: app_id, - app_secret: app_secret, token: token, account_name: account_name, }; @@ -41,6 +35,7 @@ impl Client { let resp = ureq::post(url) .set("Authorization", &format!("bearer {}", self.token)) + .set("User-Agent", crate::APPLICATION_NAME) .send_form(&[("status", body.as_str())]); if resp.ok() {