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
19 changes: 19 additions & 0 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.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ hex = "0.4.3"
http = "0.2.9"
humantime = "2.1.0"
hyper = "0.14"
hyper-rustls = { version = "0.25", features = ["http1", "http2", "ring", "rustls-native-certs"] }
insta = { version = "1.39", features = ["json", "redactions", "yaml"] }
indexmap = { version = "2.2.6" }
itertools = "0.13.0"
Expand All @@ -109,6 +110,7 @@ pyo3 = { version = "0.24.1", features = ["experimental-async"]}
rand = "0.8.5"
regex = "1.11.1"
reqwest = { version = "0.11.27", default-features = false, features = ["rustls-tls", "stream", "json"] }
rustls-pemfile = "2.2.0"
secrecy = "0.8.0"
serde = { version = "1.0", features = ["derive"] }
# serde_json is set to 1.0.127 to prevent a conflict with core, if that gets updated upstream, this
Expand Down
45 changes: 39 additions & 6 deletions influxdb3/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use secrecy::ExposeSecret;
use secrecy::Secret;
use std::error::Error;
use std::num::NonZeroUsize;
use std::path::PathBuf;
use std::str;
use token::AdminTokenConfig;
use token::TokenCommands;
Expand All @@ -27,13 +28,15 @@ pub struct Config {

impl Config {
fn get_client(&self) -> Result<Client, Box<dyn Error>> {
let (host_url, auth_token) = match &self.cmd {
let (host_url, auth_token, ca_cert) = match &self.cmd {
SubCommand::Database(DatabaseConfig {
host_url,
auth_token,
ca_cert,
..
})
| SubCommand::LastCache(LastCacheConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -43,6 +46,7 @@ impl Config {
..
})
| SubCommand::DistinctCache(DistinctCacheConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -52,6 +56,7 @@ impl Config {
..
})
| SubCommand::Table(TableConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -61,27 +66,29 @@ impl Config {
..
})
| SubCommand::Trigger(TriggerConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
auth_token,
..
},
..
}) => (host_url, auth_token),
}) => (host_url, auth_token, ca_cert),
SubCommand::Token(token_commands) => {
let (host_url, auth_token) = match &token_commands.commands {
let (host_url, auth_token, ca_cert) = match &token_commands.commands {
token::TokenSubCommand::Admin(AdminTokenConfig {
host_url,
auth_token,
ca_cert,
..
}) => (host_url, auth_token),
}) => (host_url, auth_token, ca_cert),
};
(host_url, auth_token)
(host_url, auth_token, ca_cert)
}
};

let mut client = Client::new(host_url.clone())?;
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
if let Some(token) = &auth_token {
client = client.with_auth_token(token.expose_secret());
}
Expand Down Expand Up @@ -126,6 +133,10 @@ pub struct DatabaseConfig {
/// alphanumeric with - and _ allowed and starts with a letter or number
#[clap(env = "INFLUXDB3_DATABASE_NAME", required = true)]
pub database_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand Down Expand Up @@ -164,6 +175,10 @@ pub struct LastCacheConfig {
/// Give a name for the cache.
#[clap(required = false)]
cache_name: Option<String>,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand Down Expand Up @@ -197,6 +212,10 @@ pub struct DistinctCacheConfig {
/// This will be automatically generated if not provided
#[clap(required = false)]
cache_name: Option<String>,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand All @@ -216,6 +235,10 @@ pub struct TableConfig {
#[clap(required = true)]
/// The name of the table to be created
table_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Parser)]
Expand Down Expand Up @@ -246,6 +269,10 @@ pub struct TriggerConfig {
error_behavior: ErrorBehavior,
/// Name for the new trigger
trigger_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
Expand All @@ -264,6 +291,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
value_columns,
count,
ttl,
..
}) => {
let mut b = client.api_v3_configure_last_cache_create(database_name, table);

Expand Down Expand Up @@ -301,6 +329,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
columns,
max_cardinality,
max_age,
..
}) => {
let mut b =
client.api_v3_configure_distinct_cache_create(database_name, table, columns);
Expand Down Expand Up @@ -330,6 +359,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
table_name,
tags,
fields,
..
}) => {
client
.api_v3_configure_table_create(&database_name, &table_name, tags, fields)
Expand Down Expand Up @@ -371,6 +401,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
disabled,
run_asynchronous,
error_behavior,
..
}) => {
let trigger_arguments: Option<HashMap<String, String>> = trigger_arguments.map(|a| {
a.into_iter()
Expand Down Expand Up @@ -441,6 +472,7 @@ mod tests {
count,
ttl,
influxdb3_config: crate::commands::common::InfluxDb3Config { database_name, .. },
..
}) = args.cmd
else {
panic!("Did not parse args correctly: {args:#?}")
Expand Down Expand Up @@ -478,6 +510,7 @@ mod tests {
run_asynchronous,
error_behavior,
influxdb3_config: crate::commands::common::InfluxDb3Config { database_name, .. },
..
}) = args.cmd
else {
panic!("Did not parse args correctly: {args:#?}")
Expand Down
6 changes: 5 additions & 1 deletion influxdb3/src/commands/create/token.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::error::Error;
use std::{error::Error, path::PathBuf};

use clap::Parser;
use influxdb3_client::Client;
Expand Down Expand Up @@ -36,6 +36,10 @@ pub struct AdminTokenConfig {
/// The token for authentication with the InfluxDB 3 Enterprise server
#[clap(long = "token", env = "INFLUXDB3_AUTH_TOKEN")]
pub auth_token: Option<Secret<String>>,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
pub ca_cert: Option<PathBuf>,
}

pub(crate) async fn handle_token_creation(
Expand Down
32 changes: 31 additions & 1 deletion influxdb3/src/commands/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use secrecy::ExposeSecret;
use secrecy::Secret;
use std::error::Error;
use std::io;
use std::path::PathBuf;
use url::Url;

#[derive(Debug, clap::Parser)]
Expand All @@ -18,9 +19,11 @@ impl Config {
SubCommand::Database(DatabaseConfig {
host_url,
auth_token,
ca_cert,
..
})
| SubCommand::LastCache(LastCacheConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -30,6 +33,7 @@ impl Config {
..
})
| SubCommand::DistinctCache(DistinctCacheConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -39,6 +43,7 @@ impl Config {
..
})
| SubCommand::Table(TableConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -48,6 +53,7 @@ impl Config {
..
})
| SubCommand::Trigger(TriggerConfig {
ca_cert,
influxdb3_config:
InfluxDb3Config {
host_url,
Expand All @@ -56,7 +62,7 @@ impl Config {
},
..
}) => {
let mut client = Client::new(host_url.clone())?;
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
if let Some(token) = &auth_token {
client = client.with_auth_token(token.expose_secret());
}
Expand Down Expand Up @@ -100,6 +106,10 @@ pub struct DatabaseConfig {
/// The name of the database to be deleted
#[clap(env = "INFLUXDB3_DATABASE_NAME", required = true)]
pub database_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand All @@ -114,6 +124,10 @@ pub struct LastCacheConfig {
/// The name of the cache being deleted
#[clap(required = true)]
cache_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand All @@ -128,6 +142,10 @@ pub struct DistinctCacheConfig {
/// The name of the cache being deleted
#[clap(required = true)]
cache_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
Expand All @@ -137,6 +155,10 @@ pub struct TableConfig {
#[clap(required = true)]
/// The name of the table to be deleted
table_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

#[derive(Debug, clap::Parser)]
Expand All @@ -151,6 +173,10 @@ pub struct TriggerConfig {
/// Name of trigger to delete
#[clap(required = true)]
trigger_name: String,

/// An optional arg to use a custom ca for useful for testing with self signed certs
#[clap(long = "tls-ca")]
ca_cert: Option<PathBuf>,
}

pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
Expand All @@ -175,6 +201,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
influxdb3_config: InfluxDb3Config { database_name, .. },
table,
cache_name,
..
}) => {
client
.api_v3_configure_last_cache_delete(database_name, table, cache_name)
Expand All @@ -186,6 +213,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
influxdb3_config: InfluxDb3Config { database_name, .. },
table,
cache_name,
..
}) => {
client
.api_v3_configure_distinct_cache_delete(database_name, table, cache_name)
Expand All @@ -196,6 +224,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
SubCommand::Table(TableConfig {
influxdb3_config: InfluxDb3Config { database_name, .. },
table_name,
..
}) => {
println!(
"Are you sure you want to delete {:?}.{:?}? Enter 'yes' to confirm",
Expand All @@ -220,6 +249,7 @@ pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {
influxdb3_config: InfluxDb3Config { database_name, .. },
trigger_name,
force,
..
}) => {
client
.api_v3_configure_processing_engine_trigger_delete(
Expand Down
Loading