diff --git a/README.md b/README.md index fbf8fe8..35e63f1 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A small webhook transformation tool. ### What? -Receive webhook pushes from Docker Registries or Jira, and forward them to Discord Webhooks (with neat embeds) +Receive webhook pushes from Jira and forward them to Discord Webhooks (with neat embeds) ## Docker Compose @@ -19,12 +19,11 @@ services: environment: JIRA_TOKEN: "" # URL query field for authenticating the jira post request JIRA_URL: "" # Discord webhook URL for jira messages - DOCKER_TOKEN: "" # Bearer token for Docker Registry post request - DOCKER_URL: "" # Discord webhook URL for docker messages # In order to deliver issue type & project avatars, we have to download and redirect the images using an authorized JIRA_EMAIL: "" # account email JIRA_REST_TOKEN: "" # account rest api token HOST_URL: "" # the base url for the service + LOG_REQUESTS: "true/false" # if you want to save the received requests set it to true volumes: - /path/to/images:/app/img - /path/to/requests:/app/requests diff --git a/src/docker.rs b/src/docker.rs deleted file mode 100644 index 6c59c53..0000000 --- a/src/docker.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::env; -use std::sync::Arc; - -use actix_web::{post, web::Data, HttpResponse, Responder}; -use actix_web_httpauth::extractors::bearer::BearerAuth; -use serde_json::json; - -use crate::Clients; - -const ENV_KEY: &str = "DOCKER_BEARER"; - -#[post("/docker")] -async fn handle(auth: BearerAuth, req_body: String, clients: Data>) -> impl Responder { - let env_token = match env::var(ENV_KEY) { - Ok(v) => v, - Err(_) => return HttpResponse::InternalServerError().json(json!({"error": "Missing environment value"})), - }; - - if env_token != auth.token() { - return HttpResponse::Unauthorized().finish(); - } - - let _ = clients - .docker_client - .send(|message| { - message - .username("Docker") - .content(format!("```{}```", req_body).as_str()) - }) - .await; - - HttpResponse::Accepted().finish() -} diff --git a/src/jira.rs b/src/jira.rs index 3109c01..a60b79f 100644 --- a/src/jira.rs +++ b/src/jira.rs @@ -14,7 +14,7 @@ use serde::Deserialize; use serde_json::json; use webhook::models::{Embed, Message}; -use crate::types::JiraComment; +use crate::types::Comment; use crate::{imgstore, types::JiraData, Clients}; const ENV_KEY: &str = "JIRA_TOKEN"; @@ -172,7 +172,7 @@ fn decorate_issue_embed(e: &mut Embed, data: &JiraData, project_url: String, iss } } -fn decorate_comment_embed(e: &mut Embed, c: &JiraComment) { +fn decorate_comment_embed(e: &mut Embed, c: &Comment) { e.author( c.author.display_name.as_str(), None, diff --git a/src/main.rs b/src/main.rs index 476da45..74e0b6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,3 @@ -mod docker; mod imgstore; mod jira; mod types; @@ -15,7 +14,6 @@ use webhook::client::WebhookClient; struct Clients { jira_client: WebhookClient, - docker_client: WebhookClient, } #[actix_web::main] @@ -26,11 +24,8 @@ async fn main() -> Result<()> { let jira_url = env::var("JIRA_URL").expect("missing jira url"); - let docker_url = env::var("DOCKER_URL").expect("missing docker url"); - let data = Arc::new(Clients { jira_client: WebhookClient::new(&jira_url), - docker_client: WebhookClient::new(&docker_url), }); HttpServer::new(move || { @@ -38,7 +33,6 @@ async fn main() -> Result<()> { .app_data(bearer::Config::default()) .app_data(Data::new(data.clone())) .service(jira::handle) - .service(docker::handle) .service(imgstore::serve_image) }) .bind(("0.0.0.0", 3000))? diff --git a/src/types.rs b/src/types.rs index 1f0d9c1..f79faee 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,37 +7,37 @@ use serde::Deserialize; pub struct JiraData { pub timestamp: i64, pub webhook_event: String, - pub user: Option, - pub issue: Option, + pub user: Option, + pub issue: Option, pub issue_event_type_name: Option, - pub changelog: Option, - pub comment: Option, + pub changelog: Option, + pub comment: Option, } #[derive(Deserialize)] -pub struct JiraIssue { +pub struct Issue { #[serde(rename = "self")] pub self_url: String, pub id: String, pub key: String, - pub fields: JiraIssueFields, + pub fields: IssueFields, } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraIssueFields { - pub creator: Option, - pub project: JiraProject, +pub struct IssueFields { + pub creator: Option, + pub project: Project, pub summary: String, pub description: Option, - pub priority: JiraIssuePriority, + pub priority: IssuePriority, #[serde(rename = "issuetype")] - pub issue_type: JiraIssueType, + pub issue_type: IssueType, } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraIssuePriority { +pub struct IssuePriority { #[serde(rename = "self")] pub self_url: String, pub icon_url: String, @@ -47,7 +47,7 @@ pub struct JiraIssuePriority { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraIssueType { +pub struct IssueType { #[serde(rename = "self")] pub self_url: String, pub id: String, @@ -58,7 +58,7 @@ pub struct JiraIssueType { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraUser { +pub struct User { #[serde(rename = "self")] pub self_url: String, pub account_id: String, @@ -68,7 +68,7 @@ pub struct JiraUser { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraProject { +pub struct Project { #[serde(rename = "self")] pub self_url: String, pub id: String, @@ -78,14 +78,14 @@ pub struct JiraProject { } #[derive(Deserialize)] -pub struct JiraChangelog { +pub struct Changelog { pub id: String, - pub items: Vec, + pub items: Vec, } #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraChangelogItem { +pub struct ChangelogItem { pub field: String, pub field_id: String, pub from_string: Option, @@ -94,13 +94,13 @@ pub struct JiraChangelogItem { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] -pub struct JiraComment { +pub struct Comment { #[serde(rename = "self")] pub self_url: String, pub id: String, - pub author: JiraUser, + pub author: User, pub body: String, - pub update_author: JiraUser, + pub update_author: User, pub created: String, pub updated: String, }