Skip to content

Commit

Permalink
feat: adding configs same as trustify
Browse files Browse the repository at this point in the history
  • Loading branch information
helio-frota committed May 29, 2024
1 parent 790e308 commit aec4f89
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow-unwrap-in-tests = true
allow-expect-in-tests = true
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ci

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Format
run: cargo fmt --check
- name: Check
run: cargo check
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# scale-testing

Utility for testing trustification at scale.

This tool is to help replicating existing SBOMs (SPDX or CycloneDX) file in order to augment an existing data set by multipling the number SBOMs files.
This tool is to help replicating existing SBOMs (SPDX or CycloneDX) file in order to augment an existing data set by multiplying the number SBOMs files.

For instance let's say we have a total of 1000 SBMS (500 SPDX and 500) and we'd like to obtain a total of 10K SBOMs files for our scale test, so we can run the tool using a replication size of 10.
For instance let's say we have a total of 1000 SBMS (500 SPDX and 500) and we'd like to obtain a total of 10K SBOMs files for our scale test, so we can run the tool using a replication size of 10.

The tool replicates existing SBOMs, by copying each file content and change its file name and its key records.

## Usage

## Usage ##
After installing trustification/scale-testing repo,

We can run the tool, by providing the size of the replication, the source directory and the destination directory :
Expand All @@ -19,8 +20,7 @@ The latter will replicate 10 times each SBOM file available in /SBOMs/.

Each replicated SBOM file will be created under its corresponding batch directory under `/data-set`.


## Example ##
> Example
```sh
$ cargo run -- 2 ./SBOMs ./data-set
Expand Down Expand Up @@ -61,23 +61,21 @@ data-set/
5 directories, 6 files
```

## scale test example

### Using bombastic_walker
## Using bombastic_walker

#### Prepare initial SBOMs data set
### Prepare initial SBOMs data set

Provide initial set of SBOMs files to be replicated, i.e `/SBOMs/`.
Use only SPDX files, for now, because the CycloneDX files tested were rejected with following error: `JSON: Unsupported CycloneDX version: 1.4`

#### Replicate SBOMs
### Replicate SBOMs

Run the replication tool to multiply your existing SBOM files set

`cargo run -- 10 /SBOMs /data-set`

#### Use the replicated SBOMs
### Use the replicated SBOMs

The bombastic_walker could exploit each replicated SBOMs batch, for example in devmode :
The bombastic_walker could exploit each replicated SBOMs batch, for example in devmode :

`RUST_LOG=info cargo run -p trust bombastic walker --sink http://localhost:8082 --source /data-set/batch1/ --devmode -3`
9 changes: 2 additions & 7 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
> [!NOTE]
> This is a working in progress.
## trustify

In this directory we are using [PM-mode](https://github.com/trustification/trustify/?tab=readme-ov-file#quick-start) + [Hyperfoil](https://hyperfoil.io/) (in-vm) to experiment the tool and create some basic scenarios.

## trustification

TBD
* [trustify](./trustify/README.md)
* [trustification](./trustification/README.md)
3 changes: 3 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[toolchain]
channel = "1.78.0"
components = [ "rustfmt", "clippy" ]
22 changes: 13 additions & 9 deletions src/replicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Replication {
// In the dst dir. create as many batch directories as replicator value.
// In each batch directory, add a metadata subdirectory containting metadata.json file.
// This is necessary for the bombastic-walker to parse the files.
for i in 1..self.config.replicator.parse::<u32>().unwrap() + 1 {
for i in 1..self.config.replicator.parse::<u32>().unwrap_or_default() + 1 {
let batch_path = format!("batch{}", i);
fs::create_dir_all(
Path::new(&self.config.dst)
Expand Down Expand Up @@ -49,7 +49,7 @@ impl Replication {
file,
&self.config.src.clone(),
&self.config.dst.clone(),
self.config.replicator.parse::<u32>().unwrap(),
self.config.replicator.parse::<u32>().unwrap_or_default(),
),
Err(e) => println!("Error: {}", e),
}
Expand All @@ -60,7 +60,7 @@ impl Replication {
}

fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) {
let file_name_base: String = file.file_name().into_string().unwrap();
let file_name_base: String = file.file_name().into_string().unwrap_or_default();

for i in 1..times + 1 {
let dst_file_name =
Expand All @@ -78,7 +78,7 @@ fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) {
};

let contents = fs::read_to_string(Path::new(src).join(file_name_base.as_str()))
.unwrap()
.unwrap_or_default()
.lines()
.map(|line| {
// SPDX
Expand Down Expand Up @@ -109,14 +109,17 @@ fn replicate_file(file: fs::DirEntry, src: &str, dst: &str, times: u32) {
/// Insert provided string after the file base name and before the extensions
/// Example with string being "blah": "ubi9-minimal-9.3-830.json" becomes "ubi9-minimal-9.blah.3-830.json"
fn replicate_file_name(file_name: &str, str: &str) -> String {
let mut file_name_with_extensions = file_name.split(".");
let base_file_name: String = file_name_with_extensions.next().unwrap().to_string();
let mut file_name_with_extensions = file_name.split('.');
let base_file_name: String = file_name_with_extensions
.next()
.unwrap_or_default()
.to_string();

let mut dst_file_name = base_file_name.clone();
dst_file_name.push_str(str);

for extension in file_name_with_extensions {
dst_file_name.push_str(".");
dst_file_name.push('.');
dst_file_name.push_str(extension);
}

Expand All @@ -127,10 +130,11 @@ fn replace(line: &str, key: &str, value: &str, index: u32) -> String {
println!("Amending {}: {}", key, line);
let mut document_key = line.split(": ");
document_key.next();
let remainder = document_key.next().unwrap();
let remainder = document_key.next().unwrap_or_default().to_string();

let new_remainder = remainder.replace("\",", format!("-{}{}\",", value, index).as_str());
let new_remainder_str = new_remainder.as_str();

line.replace(remainder, new_remainder_str).to_string()
line.replace(remainder.as_str(), new_remainder_str)
.to_string()
}

0 comments on commit aec4f89

Please sign in to comment.