-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathmod.rs
More file actions
185 lines (163 loc) · 5.01 KB
/
mod.rs
File metadata and controls
185 lines (163 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
use std::collections::HashMap;
use crate::{Error, purl::model::details::versioned_purl::VersionedPurlStatus};
use sea_orm::prelude::Uuid;
use serde::{Deserialize, Serialize};
use trustify_common::purl::Purl;
use trustify_entity::{base_purl, qualified_purl, versioned_purl};
use utoipa::ToSchema;
pub mod details;
pub mod summary;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct BasePurlHead {
/// The ID of the base PURL
pub uuid: Uuid,
/// The actual base PURL
pub purl: Purl,
}
impl BasePurlHead {
pub fn from_entity(entity: &base_purl::Model) -> Self {
BasePurlHead {
uuid: entity.id,
purl: Purl {
ty: entity.r#type.clone(),
namespace: entity.namespace.clone(),
name: entity.name.clone(),
version: None,
qualifiers: Default::default(),
},
}
}
pub async fn from_package_entities(
entities: &Vec<base_purl::Model>,
) -> Result<Vec<Self>, Error> {
let mut heads = Vec::new();
for entity in entities {
heads.push(Self::from_entity(entity))
}
Ok(heads)
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct VersionedPurlHead {
/// The ID of the versioned PURL
pub uuid: Uuid,
/// The actual, versioned PURL
pub purl: Purl,
/// The version from the PURL
pub version: String,
}
impl VersionedPurlHead {
pub fn from_entity(
package: &base_purl::Model,
package_version: &versioned_purl::Model,
) -> Self {
Self {
uuid: package_version.id,
purl: Purl {
ty: package.r#type.clone(),
namespace: package.namespace.clone(),
name: package.name.clone(),
version: Some(package_version.version.clone()),
qualifiers: Default::default(),
},
version: package_version.version.clone(),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema, Hash)]
pub struct PurlHead {
/// The ID of the qualified PURL
pub uuid: Uuid,
/// The actual qualified PURL
pub purl: Purl,
}
impl PurlHead {
pub fn from_entity(
package: &base_purl::Model,
package_version: &versioned_purl::Model,
qualified_package: &qualified_purl::Model,
) -> Self {
Self {
uuid: qualified_package.id,
purl: Purl {
ty: package.r#type.clone(),
namespace: package.namespace.clone(),
name: package.name.clone(),
version: Some(package_version.version.clone()),
qualifiers: qualified_package.qualifiers.0.clone(),
},
}
}
pub fn from_entities(
package: &base_purl::Model,
package_version: &versioned_purl::Model,
qualified_packages: &Vec<qualified_purl::Model>,
) -> Vec<Self> {
let mut heads = Vec::new();
for qualified_package in qualified_packages {
heads.push(Self::from_entity(
&package.clone(),
&package_version.clone(),
qualified_package,
))
}
heads
}
}
#[derive(Serialize, Deserialize, Debug, ToSchema)]
pub struct TypeHead {
pub name: String,
}
#[derive(Serialize, Deserialize, Debug, ToSchema)]
pub struct RecommendRequest {
pub purls: Vec<Purl>,
}
#[derive(Serialize, Deserialize, Default, ToSchema)]
pub struct RecommendResponse {
pub recommendations: HashMap<String, Vec<RecommendEntry>>,
}
#[derive(Serialize, Deserialize, Default, ToSchema)]
pub struct RecommendEntry {
pub package: String,
pub vulnerabilities: Vec<VulnerabilityStatus>,
}
#[derive(Serialize, Deserialize, ToSchema)]
pub struct VulnerabilityStatus {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<VexStatus>,
#[serde(skip_serializing_if = "Option::is_none")]
pub justification: Option<VexJustification>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, ToSchema)]
pub enum VexStatus {
Affected,
Fixed,
NotAffected,
UnderInvestigation,
Recommended,
#[serde(untagged)]
Other(String),
}
impl From<&VersionedPurlStatus> for VexStatus {
fn from(value: &VersionedPurlStatus) -> Self {
match value.status.as_str() {
"fixed" => Self::Fixed,
"not_affected" => Self::NotAffected,
"affected" => Self::Affected,
"under_investigation" => Self::UnderInvestigation,
"recommended" => Self::Recommended,
_ => Self::Other(value.status.clone()),
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub enum VexJustification {
ComponentNotPresent,
VulnerableCodeNotPresent,
VulnerableCodeNotInExecutePath,
VulnerableCodeCannotBeControlledByAdversary,
InlineMitigationsAlreadyExist,
NotProvided,
Other(String),
}