-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
124 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod manage; | ||
pub mod resolve; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,72 @@ | ||
use std::{collections::HashMap, error, fmt::format, result}; | ||
use serde::{Serialize, Deserialize}; | ||
|
||
use crate::util::error::EspressoError; | ||
|
||
/// Represents a resolved dependency | ||
pub struct ResolvedDependency { | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct QueryPackagesResponse { | ||
pub packages: Vec<Package> | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct Package { | ||
pub metadata: PackageMetadata, | ||
pub group_id: String, | ||
pub artifact_id: String, | ||
#[serde(rename="ref")] | ||
pub ref_: String, | ||
} | ||
|
||
/// Represents a package's metadata. | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct PackageMetadata { | ||
pub source_repository: String, | ||
pub versions: Vec<PackageVersion>, | ||
} | ||
|
||
/// Represents a specific release/version of the package. | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub struct PackageVersion { | ||
pub version: String, | ||
pub flags: Vec<Flags>, | ||
pub vulnerabilities: HashMap<String, String>, | ||
pub artifact_url: String, | ||
pub sha512sum: String, | ||
} | ||
|
||
/// Represents the supported package types. This will dictate how they're applied at compile time. | ||
#[derive(Serialize, Deserialize, Debug, Clone)] | ||
pub enum Flags { | ||
#[serde(rename = "annotation_processor")] | ||
AnnotationProcessor, | ||
} | ||
|
||
/// Query for packages from the Espresso Registry | ||
/// | ||
/// # Arguments | ||
/// * `q`: The query string | ||
/// | ||
/// # Returns | ||
/// Propagated errors, returns a `Vec` of `Package` struct(s). The `Vec` will be empty if no packages were returned in the query. | ||
pub async fn query(q: String) -> result::Result<Vec<Package>, Box<dyn error::Error>> { | ||
let client = reqwest::Client::new(); | ||
|
||
// make a request to the registry | ||
let response = client.get("https://registry.espresso.hlafaille.xyz/v1/search") | ||
.query(&[("q", q)]) | ||
.send() | ||
.await?; | ||
|
||
// handle our response from the registry | ||
let response_text = response.text().await?; | ||
let query_packages_response: QueryPackagesResponse = match serde_json::from_str(&response_text) { | ||
Ok(v) => v, | ||
Err(_) => { | ||
return Err( | ||
EspressoError::nib(format!("Failed to deserialize response: Response content was: {}", response_text).as_str()) | ||
) | ||
} | ||
}; | ||
Ok(query_packages_response.packages) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use std::{error::Error, fmt}; | ||
|
||
/// General error for use in Espresso projects | ||
#[derive(Debug)] | ||
pub struct EspressoError { | ||
msg: String | ||
} | ||
|
||
impl EspressoError { | ||
/// Creates a error | ||
/// | ||
/// # Arguments | ||
/// * `msg`: The error message | ||
pub fn new(msg: &str) -> EspressoError { | ||
EspressoError { | ||
msg: msg.to_string() | ||
} | ||
} | ||
|
||
/// Creates a new-in-box error | ||
/// | ||
/// # Arguments | ||
/// * `msg`: The error message | ||
pub fn nib(msg: &str) -> Box<EspressoError> { | ||
Box::new(Self::new(msg)) | ||
} | ||
} | ||
|
||
impl fmt::Display for EspressoError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.msg) | ||
} | ||
} | ||
|
||
impl Error for EspressoError {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod directory; | ||
pub mod pathutil; | ||
pub mod net; | ||
pub mod error; |