Skip to content
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

feature audit #42

Merged
merged 25 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
10272e2
uwu println!
uncomfyhalomacro Sep 19, 2023
4324472
chore: move out modules since no further splitting happened
uncomfyhalomacro Sep 19, 2023
eae3f05
boilerplate: initial rendition of audit
uncomfyhalomacro Sep 19, 2023
8719460
remove clippy lints
uncomfyhalomacro Sep 19, 2023
1c37197
misc: import AuditOpts
uncomfyhalomacro Sep 19, 2023
06fe33a
more boilerplate
uncomfyhalomacro Sep 22, 2023
db05761
boilerplate: initial implementation for reading service files
uncomfyhalomacro Sep 22, 2023
9ee0c3e
add clippy lints again
uncomfyhalomacro Sep 22, 2023
38b3040
add serde and quick-xml for services.rs
uncomfyhalomacro Sep 22, 2023
f826532
update lockfile
uncomfyhalomacro Sep 22, 2023
60417ea
improve services xml parsing
uncomfyhalomacro Sep 23, 2023
83f6e6c
boilerplate: finalize logic of how audit could work
uncomfyhalomacro Sep 23, 2023
5058694
misc: methods for sources
uncomfyhalomacro Sep 23, 2023
9200c49
boilerplate: more spaghetti to create a vec of Opts.
uncomfyhalomacro Sep 23, 2023
4f85263
minor fixes
uncomfyhalomacro Sep 23, 2023
381fac1
boilerplate: add more methods for audit trait
uncomfyhalomacro Sep 25, 2023
f00575f
improvement: use conversions to AsRef(erence) :) for args options
uncomfyhalomacro Sep 25, 2023
66479af
add: constants for EXCLUDED_RUSTSECS and AUDIT_PATH_PREFIX
uncomfyhalomacro Sep 25, 2023
3dadd31
cargo_audit: binary getting there 👀
uncomfyhalomacro Sep 25, 2023
7e25f86
refactor: other_options should be just a ref. ignore to --ignore
uncomfyhalomacro Sep 26, 2023
d9a1d34
Tweak some error messages
Firstyear Sep 26, 2023
b86392e
limit rust version to stable
uncomfyhalomacro Sep 30, 2023
21b0049
update lockfile
uncomfyhalomacro Oct 6, 2023
861b1e5
initial cargo-audit implementation done
uncomfyhalomacro Oct 6, 2023
c14f05e
Improve handling of reports and how we execute them
Firstyear Oct 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ license.workspace = true

[dependencies]
clap = { workspace = true, features = ["derive"] }
quick-xml = { workspace = true, features = ["serialize"] }
serde = { workspace = true, features = ["derive"] }
glob.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
Expand Down
53 changes: 53 additions & 0 deletions cargo/src/audit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: MPL-2.0

// Copyright (C) 2023 Soc Virnyl Estela

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

// use std::error::Error;
// use std::fmt;
use std::io;
use std::path::PathBuf;
// use std::process;

use clap::Parser;

#[derive(Parser, Debug)]
#[command(
author,
name = "cargo_vendor",
version,
about = "OBS Source Service to vendor all crates.io and dependencies for Rust project locally",
after_long_help = "Set verbosity and tracing through `RUST_LOG` environmental variable e.g. `RUST_LOG=trace`

Bugs can be reported on GitHub: https://github.com/uncomfyhalomacro/obs-service-cargo_vendor-rs/issues",
max_term_width = 120
)]
pub struct AuditOpts {
#[clap(flatten)]
src: AuditSrc,
#[arg(long, help = "Where to find other lockfiles for auditing.")]
lockfiles: Option<Vec<PathBuf>>,
}

#[derive(clap::Args, Debug, Clone)]
pub struct AuditSrc {
#[arg(
long,
visible_aliases = ["srctar", "srcdir"],
help = "Where to find sources. Source is either a directory or a source tarball AND cannot be both."
)]
// NOTE If `None`, check `_service`
src: Option<PathBuf>,
}

// TODO: Replace some of the return types with a Custom Error
pub trait Audit {
// RATIONALE: Running this command should be have two states
// 1. With src option
// 2. Without src option
// If 2, read the `_service` file.
fn run_audit(&self, opts: &AuditOpts) -> io::Result<()>;
}
32 changes: 32 additions & 0 deletions cargo/src/bin/cargo_audit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: MPL-2.0

// Copyright (C) 2023 Soc Virnyl Estela

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#![deny(warnings)]
#![warn(unused_extern_crates)]
// Enable some groups of clippy lints.
#![deny(clippy::suspicious)]
#![deny(clippy::perf)]
// Specific lints to enforce.
#![warn(clippy::todo)]
#![deny(clippy::unimplemented)]
#![deny(clippy::unwrap_used)]
#![deny(clippy::expect_used)]
#![deny(clippy::panic)]
#![deny(clippy::await_holding_lock)]
#![deny(clippy::needless_pass_by_value)]
#![deny(clippy::trivially_copy_pass_by_ref)]
#![deny(clippy::disallowed_types)]
#![deny(clippy::manual_let_else)]
#![allow(clippy::unreachable)]

use clap::Parser;
use obs_service_cargo::audit::AuditOpts;

fn main() {
let _my_args = AuditOpts::parse();
}
File renamed without changes.
2 changes: 2 additions & 0 deletions cargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#![deny(clippy::manual_let_else)]
#![allow(clippy::unreachable)]

pub mod audit;
pub mod cli;
pub mod consts;
pub mod services;
pub mod utils;
pub mod vendor;
56 changes: 56 additions & 0 deletions cargo/src/services.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use std::path::Path;

use quick_xml as xml;
use serde::Deserialize;
use serde::Serialize;
#[allow(unused_imports)]
use tracing::{debug, error, info, trace, warn, Level};
use xml::de::from_str;

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Services {
#[serde(rename = "service")]
service: Service,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Service {
#[serde(rename = "@name")]
name: Option<String>,
#[serde(rename = "@mode")]
mode: Option<String>,
#[serde(rename = "param")]
param: Option<Vec<Param>>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
pub struct Param {
#[serde(rename = "@name")]
name: String,
#[serde(rename = "$text")]
text: Option<String>,
}

impl Services {
pub fn from_file<P: AsRef<Path>>(p: P) -> std::io::Result<Self> {
match std::fs::read_to_string(p).map(|content| from_str::<Services>(&content)) {
Ok(c) => match c {
Ok(ay) => Ok(ay),
Err(err) => {
error!(?err, "Failed to deserialize xml string");
Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Failed to deserialize xml string",
))
}
},
Err(err) => {
error!(?err, "Failed to read file to string");
Err(err)
}
}
}
}
File renamed without changes.