Skip to content

Commit c6bcac7

Browse files
committed
chore: test example
1 parent 54f7ec7 commit c6bcac7

File tree

23 files changed

+433
-154
lines changed

23 files changed

+433
-154
lines changed

.dockerignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.idea
2+
.DS_Store
3+
/data
4+
.trustify
5+
/target
6+
/.dockerignore
7+
/Containerfile

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ http = "1"
7676
human-date-parser = "0.3"
7777
humantime = "2"
7878
humantime-serde = "1"
79+
indicatif = "0.18.0"
7980
itertools = "0.14"
8081
jsn = "0.14"
8182
json-merge-patch = "0.0.1"

Containerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM registry.access.redhat.com/ubi9/ubi:latest AS builder
2+
3+
RUN dnf install --setop install_weak_deps=false --nodocs -y git python gcc g++ cmake rust cargo ninja-build openssl-devel xz
4+
5+
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
6+
ENV PATH="/root/.cargo/bin:${PATH}"
7+
8+
RUN mkdir /build
9+
10+
COPY . /build
11+
12+
WORKDIR /build
13+
14+
RUN ls
15+
16+
RUN cargo build --release
17+
18+
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
19+
20+
COPY --from=builder /build/target/release/trustd /usr/local/bin/

common/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ deepsize = { workspace = true }
1717
hex = { workspace = true }
1818
hide = { workspace = true }
1919
human-date-parser = { workspace = true }
20+
humantime = { workspace = true }
2021
itertools = { workspace = true }
2122
lenient_semver = { workspace = true }
2223
log = { workspace = true }
@@ -32,6 +33,7 @@ sea-orm = { workspace = true, features = ["sea-query-binder", "sqlx-postgres", "
3233
sea-orm-migration = { workspace = true }
3334
sea-query = { workspace = true }
3435
serde = { workspace = true, features = ["derive"] }
36+
serde-cyclonedx = { workspace = true }
3537
serde_json = { workspace = true }
3638
spdx-expression = { workspace = true }
3739
spdx-rs = { workspace = true }
@@ -45,7 +47,6 @@ urlencoding = { workspace = true }
4547
utoipa = { workspace = true, features = ["url"] }
4648
uuid = { workspace = true, features = ["v5", "serde"] }
4749
walker-common = { workspace = true, features = ["bzip2", "liblzma", "flate2"] }
48-
humantime = { workspace = true }
4950

5051
[dev-dependencies]
5152
chrono = { workspace = true }

common/src/advisory/cyclonedx.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use serde_cyclonedx::cyclonedx::v_1_6::CycloneDx;
2+
use std::collections::HashMap;
3+
4+
/// extract CycloneDX SBOM general purpose properties
5+
pub fn extract_properties(sbom: &CycloneDx) -> HashMap<String, Option<String>> {
6+
sbom.properties
7+
.iter()
8+
.flatten()
9+
.map(|e| (e.name.clone(), e.value.clone()))
10+
.collect()
11+
}
12+
13+
/// extract CycloneDX SBOM general purpose properties, convert into [`serde_json::Value`]
14+
pub fn extract_properties_json(sbom: &CycloneDx) -> serde_json::Value {
15+
serde_json::Value::Object(
16+
extract_properties(sbom)
17+
.into_iter()
18+
.map(|(k, v)| {
19+
(
20+
k,
21+
v.map(serde_json::Value::String)
22+
.unwrap_or(serde_json::Value::Null),
23+
)
24+
})
25+
.collect(),
26+
)
27+
}

common/src/advisory/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub mod cyclonedx;
2+
13
use serde::{Deserialize, Serialize};
24
use std::collections::HashMap;
35
use utoipa::ToSchema;

data-migration.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
kind: Job
2+
apiVersion: batch/v1
3+
metadata:
4+
name: data-migration-test
5+
spec:
6+
completions: 4
7+
completionMode: Indexed
8+
parallelism: 4 # same as completions
9+
template:
10+
spec:
11+
restartPolicy: OnFailure
12+
affinity:
13+
nodeAffinity:
14+
requiredDuringSchedulingIgnoredDuringExecution:
15+
nodeSelectorTerms:
16+
- matchExpressions:
17+
- key: "kubernetes.io/arch"
18+
operator: In
19+
values: ["amd64"]
20+
containers:
21+
- name: run
22+
image: quay.io/ctrontesting/trustd:latest
23+
imagePullPolicy: Always
24+
command:
25+
- /usr/local/bin/trustd
26+
- db
27+
- data
28+
- m0002000_example_data_migration # name of the migration
29+
env:
30+
- name: MIGRATION_DATA_CONCURRENT
31+
value: "5" # in-process parallelism
32+
- name: MIGRATION_DATA_TOTAL_RUNNER
33+
value: "4" # same as completions
34+
- name: MIGRATION_DATA_CURRENT_RUNNER
35+
valueFrom:
36+
fieldRef:
37+
fieldPath: metadata.annotations['batch.kubernetes.io/job-completion-index']
38+
39+
- name: TRUSTD_STORAGE_STRATEGY
40+
value: s3
41+
- name: TRUSTD_S3_ACCESS_KEY
42+
valueFrom:
43+
secretKeyRef:
44+
name: storage-credentials
45+
key: aws_access_key_id
46+
- name: TRUSTD_S3_SECRET_KEY
47+
valueFrom:
48+
secretKeyRef:
49+
name: storage-credentials
50+
key: aws_secret_access_key
51+
- name: TRUSTD_S3_REGION
52+
valueFrom:
53+
configMapKeyRef:
54+
name: aws-storage
55+
key: region
56+
- name: TRUSTD_S3_BUCKET
57+
value: trustify-default
58+
59+
- name: TRUSTD_DB_URL
60+
value: postgresql://postgres:yhEA9G7kzw1lrsxlSezCQlPqN3JYRH1W@jreimann-test.cf4uparthbgf.eu-west-1.rds.amazonaws.com:5432/trustify_default?sslmode=require
61+
62+
- name: RUST_LOG
63+
value: info
64+
---
65+
kind: Secret
66+
apiVersion: v1
67+
metadata:
68+
name: storage-credentials
69+
data:
70+
aws_access_key_id: QUtJQVcyVFAzUU1PSllCWFhPQ0c=
71+
aws_secret_access_key: WXQvZDhBNktLVHhETGYzamV4K3kzVC91bEZmYjdPTUhnRTJSZlpCeQ==
72+
type: Opaque
73+
---
74+
kind: ConfigMap
75+
apiVersion: v1
76+
metadata:
77+
name: aws-storage
78+
data:
79+
region: "eu-west-1"

entity/src/sbom.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ pub struct Model {
2626
graphql(derived(owned, into = "HashMap<String,String>", with = "Labels::from"))
2727
)]
2828
pub labels: Labels,
29+
30+
/// properties from the SBOM document
31+
pub properties: serde_json::Value,
2932
}
3033

3134
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

migration/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bytes = { workspace = true }
1919
clap = { workspace = true, features = ["derive", "env"] }
2020
futures = { workspace = true }
2121
futures-util = { workspace = true }
22+
indicatif = { workspace = true, features = ["tokio", "futures"] }
2223
sea-orm = { workspace = true }
2324
sea-orm-migration = { workspace = true, features = ["runtime-tokio-rustls", "sqlx-postgres", "with-uuid"] }
2425
serde-cyclonedx = { workspace = true }
@@ -28,6 +29,7 @@ tokio = { workspace = true, features = ["full"] }
2829
tracing = { workspace = true }
2930
tracing-subscriber = { workspace = true }
3031
uuid = { workspace = true, features = ["v5"] }
32+
humantime = { workspace = true }
3133

3234
[dev-dependencies]
3335
trustify-common = { workspace = true }

0 commit comments

Comments
 (0)