Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
80 changes: 60 additions & 20 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "o2_report_generator"
version = "0.1.0"
version = "0.11.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -13,6 +13,13 @@ chromiumoxide = { git = "https://github.com/mattsse/chromiumoxide", features = [
"_fetcher-rusttls-tokio",
], default-features = false, rev = "6f2392f78ae851e2acf33df8e9764cc299d837db" }
chrono = { version = "0.4", default-features = false, features = ["clock"] }
clap = { version = "4.5", default-features = false, features = [
"std",
"help",
"usage",
"suggestions",
"cargo",
] }
dotenv_config = "0.1"
dotenvy = "0.15"
env_logger = "0.10"
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ FROM public.ecr.aws/debian/debian:bookworm-slim as runtime
RUN apt-get update -y && apt-get install -y --no-install-recommends ca-certificates chromium && \
update-ca-certificates
COPY ./bin/report-generator /
RUN ["/report-generator", "init-dir", "-p", "/data/"]
CMD ["/report-generator"]
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-07-07"
channel = "nightly-2025-03-02"
components = ["rustfmt", "clippy", "llvm-tools"]
52 changes: 52 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2025 OpenObserve Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

mod utils;

pub async fn cli() -> Result<bool, anyhow::Error> {
let app = clap::Command::new("report-generator")
.version(crate::config::VERSION)
.about(clap::crate_description!())
.subcommands(&[clap::Command::new("init-dir")
.about("init report-generator data dir")
.arg(
clap::Arg::new("path")
.short('p')
.long("path")
.help("init this path as data root dir"),
)])
.get_matches();

if app.subcommand().is_none() {
return Ok(false);
}

let (name, command) = app.subcommand().unwrap();
if name == "init-dir" {
match command.get_one::<String>("path") {
Some(path) => {
utils::set_permission(path, 0o777)?;
println!("init dir {} successfully", path);
}
None => {
return Err(anyhow::anyhow!("please set data path"));
}
}
return Ok(true);
}

println!("command {name} execute successfully");
Ok(true)
}
29 changes: 29 additions & 0 deletions src/cli/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2025 OpenObserve Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

#[cfg(unix)]
pub fn set_permission<P: AsRef<std::path::Path>>(path: P, mode: u32) -> Result<(), std::io::Error> {
use std::os::unix::fs::PermissionsExt;
std::fs::create_dir_all(path.as_ref())?;
std::fs::set_permissions(path.as_ref(), std::fs::Permissions::from_mode(mode))
}

#[cfg(not(unix))]
pub fn set_permission<P: AsRef<std::path::Path>>(
path: P,
_mode: u32,
) -> Result<(), std::io::Error> {
std::fs::create_dir_all(path.as_ref())
}
Loading
Loading