Skip to content

Commit

Permalink
Fixes #19790: Use gumdrop instead of structopt
Browse files Browse the repository at this point in the history
  • Loading branch information
amousset authored and Jenkins CI committed Aug 17, 2021
1 parent 63e9b3a commit 1e8dc42
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 126 deletions.
132 changes: 43 additions & 89 deletions relay/sources/relayd/Cargo.lock

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

2 changes: 1 addition & 1 deletion relay/sources/relayd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ diesel = { version = "1", default-features = false, features = ["postgres", "chr
# Uses rust implementation by default
flate2 = "1"
futures = "0.3"
gumdrop = "0.8"
hex = "0.4"
humantime = "2"
hyper = { version = "0.14", default-features = false }
Expand All @@ -41,7 +42,6 @@ reqwest = { version = "0.11.1", default-features = false, features = ["stream",
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha2 = "0.9"
structopt = { version = "0.3", default-features = false }
thiserror = "1"
tokio = { version = "1", default-features = false, features = [ "rt-multi-thread", "process", "macros", "signal", "fs"] }
tokio-stream = { version = "0.1", default-features = false, features = ["io-util"] }
Expand Down
7 changes: 3 additions & 4 deletions relay/sources/relayd/src/api/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ use crate::{
api::{ApiResponse, ApiResult},
check_configuration,
output::database::ping,
Error, JobConfig,
Error, JobConfig, CRATE_VERSION,
};
use serde::Serialize;
use std::sync::Arc;
use structopt::clap::crate_version;
use warp::{filters::method, path, Filter, Reply};

pub fn routes_1(
Expand Down Expand Up @@ -71,7 +70,7 @@ impl Info {
env!("CARGO_PKG_VERSION_MAJOR"),
env!("CARGO_PKG_VERSION_MINOR")
),
full_version: crate_version!().to_string(),
full_version: CRATE_VERSION.to_string(),
}
}
}
Expand Down Expand Up @@ -112,7 +111,7 @@ impl Status {
.pool
.clone()
.map(|p| ping(&p).map_err(|e| e).into()),
configuration: check_configuration(&job_config.cli_cfg.configuration_dir)
configuration: check_configuration(&job_config.cli_cfg.config)
.map_err(|e| e)
.into(),
}
Expand Down
35 changes: 18 additions & 17 deletions relay/sources/relayd/src/configuration/cli.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2019-2020 Normation SAS

use gumdrop::Options;
use std::path::{Path, PathBuf};

#[derive(StructOpt, Debug)]
#[structopt(name = "rudder-relayd")]
#[structopt(author, about)]
#[derive(Debug, Options)]
// version and description are taken from Cargo.toml
// struct fields comments are used as option description in help
pub struct CliConfiguration {
/// Sets a custom config directory
#[structopt(
short = "c",
long = "config",
default_value = "/opt/rudder/etc/relayd/",
parse(from_os_str)
#[options(
help = "set a custom config directory",
default = "/opt/rudder/etc/relayd/"
)]
pub configuration_dir: PathBuf,

/// Checks the syntax of the configuration file and exit
#[structopt(short = "t", long = "test")]
pub check_configuration: bool,
pub config: PathBuf,
#[options(help = "check the syntax of the configuration file and exit")]
pub test: bool,
/// Automatically used for help flag
#[options(help = "print help message")]
help: bool,
#[options(help = "print version", short = "V")]
pub version: bool,
}

impl CliConfiguration {
/// Used to generate configurations in tests
pub fn new<P: AsRef<Path>>(path: P, check_configuration: bool) -> Self {
pub fn new<P: AsRef<Path>>(path: P, test: bool) -> Self {
Self {
configuration_dir: path.as_ref().to_path_buf(),
check_configuration,
config: path.as_ref().to_path_buf(),
test,
help: false,
version: false,
}
}
}
4 changes: 2 additions & 2 deletions relay/sources/relayd/src/http_client.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2019-2020 Normation SAS

use crate::{CRATE_NAME, CRATE_VERSION};
use anyhow::Error;
use lazy_static::lazy_static;
use reqwest::{Certificate, Client};
use structopt::clap::{crate_name, crate_version};
use tracing::debug;

lazy_static! {
/// User-Agent used in our HTTP requests
/// "rudder-relayd/7.0.0"
static ref USER_AGENT: String = format!("{}/{}", crate_name!(), crate_version!());
static ref USER_AGENT: String = format!("{}/{}", CRATE_NAME, CRATE_VERSION);
}

type PemCertificate = Vec<u8>;
Expand Down
Loading

0 comments on commit 1e8dc42

Please sign in to comment.