-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Rework jobs and projects response types. #48
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,61 @@ | ||
//! This module contains types involved with handling phylum processing jobs. | ||
|
||
use chrono::{DateTime, Utc}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::common::*; | ||
use super::project::*; | ||
use crate::types::package::{PackageDescriptor, PackageStatus, PackageStatusExtended, PackageType}; | ||
use crate::types::package::{PackageDescriptor, PackageStatusExtended, PackageType}; | ||
|
||
/// Data shared between the full [`JobResponse`] type and the abbreviated [`JobDescriptor`] type. | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct JobEssentials { | ||
pub id: JobId, | ||
pub created_at: DateTime<Utc>, | ||
pub updated_at: DateTime<Utc>, | ||
pub label: Option<String>, | ||
pub ecosystem: PackageType, | ||
pub project: JobProject, | ||
pub score: JobScore, | ||
pub num_incomplete: u32, | ||
} | ||
|
||
/// Response type for the API /jobs/<job id> endpoint. | ||
#[derive(Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct JobResponse { | ||
#[serde(flatten)] | ||
pub essentials: JobEssentials, | ||
pub status: Status, | ||
pub package_statuses: Vec<PackageStatusExtended>, | ||
pub action: Action, | ||
pub thresholds: ProjectThresholds, | ||
} | ||
|
||
/// Metadata about a job. | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct JobDescriptor { | ||
#[serde(flatten)] | ||
pub essentials: JobEssentials, | ||
pub package_descriptors: Vec<PackageDescriptor>, | ||
} | ||
|
||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct JobProject { | ||
pub id: ProjectId, | ||
pub name: String, | ||
} | ||
Comment on lines
+47
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To support group-owned projects, this probably also needs an optional group name. |
||
|
||
#[derive(Debug, PartialEq, PartialOrd, Clone, Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct JobScore { | ||
pub value: f64, | ||
Comment on lines
+54
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be really helpful to have the per-axis scores for the job included along side the overall job score. |
||
pub pass: bool, | ||
pub message: String, | ||
} | ||
|
||
/// When a job is completed, and some requirement is not met ( such as quality | ||
/// level ), what action should be taken? | ||
|
@@ -21,23 +71,6 @@ pub enum Action { | |
Break, | ||
} | ||
|
||
/// Metadata about a job | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct JobDescriptor { | ||
pub job_id: JobId, | ||
pub project: String, | ||
pub label: String, | ||
pub num_dependencies: u32, | ||
pub score: f64, | ||
pub packages: Vec<PackageDescriptor>, | ||
pub pass: bool, | ||
pub msg: String, | ||
pub date: String, | ||
pub ecosystem: String, | ||
#[serde(default)] | ||
pub num_incomplete: u32, | ||
} | ||
|
||
/// Submit Package for analysis | ||
#[derive( | ||
PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Serialize, Deserialize, JsonSchema, | ||
|
@@ -71,21 +104,24 @@ pub struct SubmitPackageResponse { | |
/// Represents a response that summarizes the output of all current jobs | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct AllJobsStatusResponse { | ||
/// A description of the latest jobs | ||
/// A description of the latest jobs. | ||
pub jobs: Vec<JobDescriptor>, | ||
/// Total jobs run | ||
/// Total jobs run. | ||
pub total_jobs: u32, | ||
pub count: u32, | ||
} | ||
|
||
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
#[serde(untagged)] | ||
pub enum JobStatusResponseVariant { | ||
// Serde returns the one that deserializes successfully first, so most complicated goes first | ||
Extended(JobStatusResponse<PackageStatusExtended>), | ||
Basic(JobStatusResponse<PackageStatus>), | ||
/// Response from canceling a job | ||
#[derive( | ||
PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
pub struct CancelJobResponse { | ||
pub msg: String, | ||
} | ||
|
||
// -------------------------------------------------------------- | ||
// V V | ||
// V -------- EVERYTHING BELOW THIS LINE IS DEPRECATED -------- V | ||
|
||
/// Data returned when querying the job status endpoint | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct JobStatusResponse<T> { | ||
|
@@ -126,11 +162,3 @@ pub struct JobStatusResponse<T> { | |
/// The packages that are a part of this job | ||
pub packages: Vec<T>, | ||
} | ||
|
||
/// Response from canceling a job | ||
#[derive( | ||
PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
pub struct CancelJobResponse { | ||
pub msg: String, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,38 @@ | ||
//! This module contains types for working with project data | ||
//! This module contains types for working with project data. | ||
|
||
use std::collections::HashMap; | ||
|
||
use chrono::{DateTime, Utc}; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use uuid::Uuid; | ||
|
||
use super::common::ProjectId; | ||
use super::job::*; | ||
use super::job::{JobDescriptor, JobResponse}; | ||
use super::package::PackageType; | ||
|
||
/// Rick cut off thresholds for a project | ||
#[derive(PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct ProjectThresholds { | ||
pub author: f32, | ||
pub engineering: f32, | ||
pub license: f32, | ||
pub malicious: f32, | ||
pub total: f32, | ||
pub vulnerability: f32, | ||
// Response type for the API /projects/<project id> endpoint. | ||
#[derive(Serialize, Deserialize, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ProjectResponse { | ||
pub id: Uuid, | ||
pub name: String, | ||
pub created_at: DateTime<Utc>, | ||
pub updated_at: DateTime<Utc>, | ||
pub thresholds: ProjectThresholds, | ||
pub stats: ProjectStats, | ||
pub latest_job: Option<JobResponse>, | ||
} | ||
|
||
/// Summary response for a project | ||
#[derive( | ||
PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
pub struct ProjectSummaryResponse { | ||
/// The project name | ||
pub name: String, | ||
/// The project id | ||
pub id: ProjectId, | ||
/// The project name | ||
pub name: String, | ||
/// When the project was updated | ||
pub updated_at: DateTime<Utc>, | ||
/// When the project was created | ||
|
@@ -40,19 +46,74 @@ pub struct ProjectSummaryResponse { | |
/// A more detailed project response | ||
#[derive(PartialEq, PartialOrd, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct ProjectDetailsResponse { | ||
/// The project id | ||
pub id: ProjectId, | ||
/// The project name | ||
pub name: String, | ||
/// The project id | ||
pub id: String, | ||
/// The project ecosystem / package type | ||
pub ecosystem: String, | ||
pub ecosystem: Option<PackageType>, | ||
/// The configured risk cutoff thresholds for the project | ||
pub thresholds: ProjectThresholds, | ||
/// Most recent analysis job runs | ||
pub jobs: Vec<JobDescriptor>, | ||
} | ||
|
||
/// Rquest to create a project | ||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct LicensesStats { | ||
pub counts: HashMap<String, u32>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct IssueStatusCounts { | ||
pub untagged: u32, | ||
pub will_fix: u32, | ||
pub accept: u32, | ||
pub not_relevant: u32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct IssueStatusStats { | ||
pub counts: IssueStatusCounts, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct DependenciesCounts { | ||
pub total: u32, | ||
pub num_incomplete: u32, | ||
pub above_threshold: u32, | ||
pub below_threshold: u32, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct DependenciesStats { | ||
pub counts: DependenciesCounts, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Default, JsonSchema)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ProjectStats { | ||
pub licenses: LicensesStats, | ||
pub issue_status: IssueStatusStats, | ||
pub dependencies: DependenciesStats, | ||
} | ||
Comment on lines
+97
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These seem to be related to a job and not a project. Should this be |
||
|
||
/// Risk cut off thresholds for a project. | ||
#[derive(PartialEq, PartialOrd, Copy, Clone, Debug, Serialize, Deserialize, JsonSchema)] | ||
pub struct ProjectThresholds { | ||
pub author: f32, | ||
pub engineering: f32, | ||
pub license: f32, | ||
pub malicious: f32, | ||
pub total: f32, | ||
pub vulnerability: f32, | ||
} | ||
|
||
/// Request to create a project. | ||
#[derive( | ||
PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, Serialize, Deserialize, JsonSchema, | ||
)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A list of issues would be a good addition here