Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 47 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ resolver = "2"
[workspace.dependencies]
anyhow = "1.0.97"
tokio = { version = "1.41.1", features = ["rt-multi-thread", "macros"] }
futures = "0.3.31"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
8 changes: 4 additions & 4 deletions veno-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
tokio = { workspace = true }
futures = { workspace = true }
serde = { workspace = true }
serde_derive = { workspace = true }
serde_json = { workspace = true }

config = "0.15"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
reqwest = { version = "0.12", features = ["json"] }
once_cell = "1.20"
lettre = "0.11"
regex = "1.11.1"
mockito = "1.6.1"
futures = "0.3.31"
34 changes: 1 addition & 33 deletions veno-core/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{Context, Result};
use futures::future::join_all;
use serde::{Deserialize, Serialize};
use serde::Deserialize;

use crate::{
artifact::Artifact,
Expand Down Expand Up @@ -41,31 +41,6 @@ impl AppState {
notifier.sink.send(&notification).await;
}
}

// This function will check all artifacts if they are behind the latest version
pub async fn check_all_artifacts(&self) -> Result<String> {
let mut new_versions = Vec::new();

let check_futures = self
.artifacts
.iter()
.map(|artifact| async move { (artifact, artifact.is_version_behind().await) });

let checked_artifacts = join_all(check_futures).await;

for (artifact, result) in checked_artifacts {
if let Ok(Some(latest_version)) = result {
new_versions.push(CheckedArtifact {
name: artifact.name.clone(),
current_version: artifact.current_version.clone(),
latest_version,
});
}
}
let new_versions =
serde_json::to_string(&new_versions).context("Failed to serialize new versions")?;
Ok(new_versions)
}
}

async fn generate_notification(artifacts: &Vec<(&Artifact, Result<Option<String>>)>) -> String {
Expand All @@ -90,10 +65,3 @@ async fn generate_notification(artifacts: &Vec<(&Artifact, Result<Option<String>

messages.join("\n")
}

#[derive(Debug, Serialize)]
struct CheckedArtifact {
name: String,
current_version: String,
latest_version: String,
}
2 changes: 1 addition & 1 deletion veno-core/src/artifact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Artifact {
}

impl Artifact {
pub(super) async fn is_version_behind(&self) -> Result<Option<String>> {
pub async fn is_version_behind(&self) -> Result<Option<String>> {
self.source.is_version_behind(&self.current_version).await
}
}
20 changes: 15 additions & 5 deletions veno-core/src/artifact/source/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ impl SourceChecker for GitHubSource {
return Err(anyhow!("Request failed: {:?}", response));
}

// Parse the JSON response
let release: Release = response
.json()
.await
.context("Failed to parse JSON response")?;
// // Parse the JSON response
// let release: Release = match response.json().await {
// Ok(json) => json,
// Err(err) => {
// let error_message = format!("Failed to parse JSON response: {}", err);
// println!("{}", error_message);
// return Err(anyhow!(error_message));
// }
// };

//TODO make error responses more robust
let release: Release = response.json().await.map_err(|err| {
println!("added context: {}", err);
err
})?;

// Extract and compare the version
// TODO: change this logic to be used with the version checker but we first need to
Expand Down
9 changes: 2 additions & 7 deletions veno-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ use anyhow::Result;
use once_cell::sync::Lazy;
use reqwest::{Client, ClientBuilder, Response};

pub static CLIENT: Lazy<Client> = Lazy::new(|| {
static CLIENT: Lazy<Client> = Lazy::new(|| {
ClientBuilder::new()
.user_agent("veno")
.build()
.expect("Could not create reqwest client")
});

pub async fn get(url: &str) -> Result<Response, reqwest::Error> {
async fn get(url: &str) -> Result<Response, reqwest::Error> {
CLIENT
.get(url)
.timeout(Duration::from_secs(10))
.send()
.await
}

pub fn pretty_json(body: &str) -> Result<String, serde_json::Error> {
let json: serde_json::Value = serde_json::from_str(body)?;
serde_json::to_string_pretty(&json)
}
1 change: 1 addition & 0 deletions veno-core/src/notifier/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl SinkSender for WebhookSink {
}
}

// TODO this needs to bubble so we can return an error to the user
pub async fn call(webhook: &str, payload: &Value) {
match CLIENT
.post(webhook)
Expand Down
7 changes: 5 additions & 2 deletions veno-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ edition = "2021"
[dependencies]
anyhow = { workspace = true }
tokio = { workspace = true }

futures = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
veno-core = { path = "../veno-core" }
clap = { version = "4.0", features = ["derive"] }
axum = "0.8.3"
serde = { version = "1.0", features = ["derive"] }
utoipa = { version = "5.3.1", features = ["axum_extras"] }
utoipa-redoc = { version = "6.0.0", features = ["axum"] }
72 changes: 0 additions & 72 deletions veno-web/src/endpoints.rs

This file was deleted.

10 changes: 6 additions & 4 deletions veno-web/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::sync::Arc;

use anyhow::Result;
use resources::serve_api;
use veno_core::app::AppState;

use clap::Parser;
use endpoints::routes;

mod endpoints;
mod resources;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand All @@ -16,7 +18,7 @@ struct Cli {
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let config = AppState::init(&cli.config)?;
routes(config.clone()).await;
let app = Arc::new(AppState::init(&cli.config)?);
serve_api(app).await;
Ok(())
}
15 changes: 15 additions & 0 deletions veno-web/src/resources/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use serde::Serialize;

#[derive(Serialize, Debug, Clone)]
pub struct PathParamError {
pub error_code: String,
pub resource: String,
pub param: String,
pub message: String,
}

#[derive(Serialize, Debug, Clone)]
pub struct InternalServerError {
pub error_code: String,
pub message: String,
}
Loading