Skip to content

Commit 8aa043e

Browse files
committed
feat: add --tls-no-verify option to CLI subcommands (#2096) (#27102)
* feat: add --tls-no-verify option to non-serve subcommands * test: validate --tls-no-verify flag
1 parent 20fa509 commit 8aa043e

File tree

19 files changed

+623
-73
lines changed

19 files changed

+623
-73
lines changed

influxdb3/src/commands/create.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ pub struct Config {
3131

3232
impl Config {
3333
fn get_client(&self) -> Result<Client, Box<dyn Error>> {
34-
let (host_url, auth_token, ca_cert) = match &self.cmd {
34+
let (host_url, auth_token, ca_cert, tls_no_verify) = match &self.cmd {
3535
SubCommand::Database(DatabaseConfig {
3636
host_url,
3737
auth_token,
3838
ca_cert,
39+
tls_no_verify,
3940
..
4041
})
4142
| SubCommand::LastCache(LastCacheConfig {
4243
ca_cert,
44+
tls_no_verify,
4345
influxdb3_config:
4446
InfluxDb3Config {
4547
host_url,
@@ -50,6 +52,7 @@ impl Config {
5052
})
5153
| SubCommand::DistinctCache(DistinctCacheConfig {
5254
ca_cert,
55+
tls_no_verify,
5356
influxdb3_config:
5457
InfluxDb3Config {
5558
host_url,
@@ -60,6 +63,7 @@ impl Config {
6063
})
6164
| SubCommand::Table(TableConfig {
6265
ca_cert,
66+
tls_no_verify,
6367
influxdb3_config:
6468
InfluxDb3Config {
6569
host_url,
@@ -70,21 +74,23 @@ impl Config {
7074
})
7175
| SubCommand::Trigger(TriggerConfig {
7276
ca_cert,
77+
tls_no_verify,
7378
influxdb3_config:
7479
InfluxDb3Config {
7580
host_url,
7681
auth_token,
7782
..
7883
},
7984
..
80-
}) => (host_url, auth_token, ca_cert),
85+
}) => (host_url, auth_token, ca_cert, tls_no_verify),
8186
SubCommand::Token(create_token_config) => {
8287
let host_settings = create_token_config.get_connection_settings()?;
8388
// We need to return references, so we'll handle this differently
8489
return Ok({
8590
let mut client = Client::new(
8691
host_settings.host_url.clone(),
8792
host_settings.ca_cert.clone(),
93+
host_settings.tls_no_verify,
8894
)?;
8995
if let Some(token) = &host_settings.auth_token {
9096
client = client.with_auth_token(token.expose_secret());
@@ -94,7 +100,7 @@ impl Config {
94100
}
95101
};
96102

97-
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
103+
let mut client = Client::new(host_url.clone(), ca_cert.clone(), *tls_no_verify)?;
98104
if let Some(token) = &auth_token {
99105
client = client.with_auth_token(token.expose_secret());
100106
}
@@ -147,6 +153,10 @@ pub struct DatabaseConfig {
147153
/// An optional arg to use a custom ca for useful for testing with self signed certs
148154
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
149155
ca_cert: Option<PathBuf>,
156+
157+
/// Disable TLS certificate verification
158+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
159+
tls_no_verify: bool,
150160
}
151161

152162
#[derive(Debug, clap::Args)]
@@ -190,6 +200,10 @@ pub struct LastCacheConfig {
190200
/// An optional arg to use a custom ca for useful for testing with self signed certs
191201
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
192202
ca_cert: Option<PathBuf>,
203+
204+
/// Disable TLS certificate verification
205+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
206+
tls_no_verify: bool,
193207
}
194208

195209
#[derive(Debug, clap::Args)]
@@ -227,6 +241,10 @@ pub struct DistinctCacheConfig {
227241
/// An optional arg to use a custom ca for useful for testing with self signed certs
228242
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
229243
ca_cert: Option<PathBuf>,
244+
245+
/// Disable TLS certificate verification
246+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
247+
tls_no_verify: bool,
230248
}
231249

232250
#[derive(Debug, clap::Args)]
@@ -250,6 +268,10 @@ pub struct TableConfig {
250268
/// An optional arg to use a custom ca for useful for testing with self signed certs
251269
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
252270
ca_cert: Option<PathBuf>,
271+
272+
/// Disable TLS certificate verification
273+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
274+
tls_no_verify: bool,
253275
}
254276

255277
#[derive(Debug, clap::Parser)]
@@ -291,6 +313,10 @@ pub struct TriggerConfig {
291313
/// An optional arg to use a custom ca for useful for testing with self signed certs
292314
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
293315
ca_cert: Option<PathBuf>,
316+
317+
/// Disable TLS certificate verification
318+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
319+
tls_no_verify: bool,
294320
}
295321

296322
pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {

influxdb3/src/commands/create/token.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,14 @@ pub struct InfluxDb3ServerConfig {
201201
/// An optional arg to use a custom ca for useful for testing with self signed certs
202202
#[clap(name = "tls-ca", long = "tls-ca")]
203203
pub ca_cert: Option<PathBuf>,
204+
205+
/// Disable TLS certificate verification
206+
#[clap(
207+
name = "tls-no-verify",
208+
long = "tls-no-verify",
209+
env = "INFLUXDB3_TLS_NO_VERIFY"
210+
)]
211+
pub tls_no_verify: bool,
204212
}
205213

206214
#[derive(Parser, Debug)]

influxdb3/src/commands/delete.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ pub struct Config {
1616

1717
impl Config {
1818
fn get_client(&self) -> Result<Client, Box<dyn Error>> {
19-
match &self.cmd {
19+
let (host_url, auth_token, ca_cert, tls_no_verify) = match &self.cmd {
2020
SubCommand::Database(DatabaseConfig {
2121
host_url,
2222
auth_token,
2323
ca_cert,
24+
tls_no_verify,
2425
..
2526
})
2627
| SubCommand::LastCache(LastCacheConfig {
2728
ca_cert,
29+
tls_no_verify,
2830
influxdb3_config:
2931
InfluxDb3Config {
3032
host_url,
@@ -35,6 +37,7 @@ impl Config {
3537
})
3638
| SubCommand::DistinctCache(DistinctCacheConfig {
3739
ca_cert,
40+
tls_no_verify,
3841
influxdb3_config:
3942
InfluxDb3Config {
4043
host_url,
@@ -45,6 +48,7 @@ impl Config {
4548
})
4649
| SubCommand::Table(TableConfig {
4750
ca_cert,
51+
tls_no_verify,
4852
influxdb3_config:
4953
InfluxDb3Config {
5054
host_url,
@@ -55,6 +59,7 @@ impl Config {
5559
})
5660
| SubCommand::Trigger(TriggerConfig {
5761
ca_cert,
62+
tls_no_verify,
5863
influxdb3_config:
5964
InfluxDb3Config {
6065
host_url,
@@ -65,17 +70,17 @@ impl Config {
6570
})
6671
| SubCommand::Token(TokenConfig {
6772
ca_cert,
73+
tls_no_verify,
6874
host_url,
6975
auth_token,
7076
..
71-
}) => {
72-
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
73-
if let Some(token) = &auth_token {
74-
client = client.with_auth_token(token.expose_secret());
75-
}
76-
Ok(client)
77-
}
77+
}) => (host_url, auth_token, ca_cert, tls_no_verify),
78+
};
79+
let mut client = Client::new(host_url.clone(), ca_cert.clone(), *tls_no_verify)?;
80+
if let Some(token) = &auth_token {
81+
client = client.with_auth_token(token.expose_secret());
7882
}
83+
Ok(client)
7984
}
8085
}
8186

@@ -124,6 +129,10 @@ pub struct DatabaseConfig {
124129
/// An optional arg to use a custom ca for useful for testing with self signed certs
125130
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
126131
ca_cert: Option<PathBuf>,
132+
133+
/// Disable TLS certificate verification
134+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
135+
tls_no_verify: bool,
127136
}
128137

129138
#[derive(Debug, clap::Args)]
@@ -142,6 +151,10 @@ pub struct LastCacheConfig {
142151
/// An optional arg to use a custom ca for useful for testing with self signed certs
143152
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
144153
ca_cert: Option<PathBuf>,
154+
155+
/// Disable TLS certificate verification
156+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
157+
tls_no_verify: bool,
145158
}
146159

147160
#[derive(Debug, clap::Args)]
@@ -160,6 +173,10 @@ pub struct DistinctCacheConfig {
160173
/// An optional arg to use a custom ca for useful for testing with self signed certs
161174
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
162175
ca_cert: Option<PathBuf>,
176+
177+
/// Disable TLS certificate verification
178+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
179+
tls_no_verify: bool,
163180
}
164181

165182
#[derive(Debug, clap::Args)]
@@ -178,6 +195,10 @@ pub struct TableConfig {
178195
/// An optional arg to use a custom ca for useful for testing with self signed certs
179196
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
180197
ca_cert: Option<PathBuf>,
198+
199+
/// Disable TLS certificate verification
200+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
201+
tls_no_verify: bool,
181202
}
182203

183204
#[derive(Debug, clap::Parser)]
@@ -196,6 +217,10 @@ pub struct TriggerConfig {
196217
/// An optional arg to use a custom ca for useful for testing with self signed certs
197218
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
198219
ca_cert: Option<PathBuf>,
220+
221+
/// Disable TLS certificate verification
222+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
223+
tls_no_verify: bool,
199224
}
200225

201226
#[derive(Debug, clap::Args)]
@@ -220,6 +245,10 @@ pub struct TokenConfig {
220245
/// An optional arg to use a custom ca for useful for testing with self signed certs
221246
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
222247
ca_cert: Option<PathBuf>,
248+
249+
/// Disable TLS certificate verification
250+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
251+
tls_no_verify: bool,
223252
}
224253

225254
fn parse_hard_delete_time(value: Option<String>) -> Option<HardDeletionTime> {

influxdb3/src/commands/disable.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ pub struct Config {
1111

1212
impl Config {
1313
fn get_client(&self) -> Result<Client, Box<dyn Error>> {
14-
let (host_url, auth_token, ca_cert) = match &self.cmd {
14+
let (host_url, auth_token, ca_cert, tls_no_verify) = match &self.cmd {
1515
SubCommand::Trigger(TriggerConfig {
1616
ca_cert,
17+
tls_no_verify,
1718
influxdb3_config:
1819
InfluxDb3Config {
1920
host_url,
2021
auth_token,
2122
..
2223
},
2324
..
24-
}) => (host_url, auth_token, ca_cert),
25+
}) => (host_url, auth_token, ca_cert, tls_no_verify),
2526
};
26-
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
27+
let mut client = Client::new(host_url.clone(), ca_cert.clone(), *tls_no_verify)?;
2728
if let Some(token) = &auth_token {
2829
client = client.with_auth_token(token.expose_secret());
2930
}
@@ -49,6 +50,10 @@ struct TriggerConfig {
4950
/// An optional arg to use a custom ca for useful for testing with self signed certs
5051
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
5152
pub ca_cert: Option<PathBuf>,
53+
54+
/// Disable TLS certificate verification
55+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
56+
pub tls_no_verify: bool,
5257
}
5358

5459
pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {

influxdb3/src/commands/enable.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ pub struct Config {
1111

1212
impl Config {
1313
fn get_client(&self) -> Result<Client, Box<dyn Error>> {
14-
let (host_url, auth_token, ca_cert) = match &self.cmd {
14+
let (host_url, auth_token, ca_cert, tls_no_verify) = match &self.cmd {
1515
SubCommand::Trigger(TriggerConfig {
1616
ca_cert,
17+
tls_no_verify,
1718
influxdb3_config:
1819
InfluxDb3Config {
1920
host_url,
2021
auth_token,
2122
..
2223
},
2324
..
24-
}) => (host_url, auth_token, ca_cert),
25+
}) => (host_url, auth_token, ca_cert, tls_no_verify),
2526
};
26-
let mut client = Client::new(host_url.clone(), ca_cert.clone())?;
27+
let mut client = Client::new(host_url.clone(), ca_cert.clone(), *tls_no_verify)?;
2728
if let Some(token) = &auth_token {
2829
client = client.with_auth_token(token.expose_secret());
2930
}
@@ -49,6 +50,10 @@ struct TriggerConfig {
4950
/// An optional arg to use a custom ca for useful for testing with self signed certs
5051
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
5152
pub ca_cert: Option<PathBuf>,
53+
54+
/// Disable TLS certificate verification
55+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
56+
pub tls_no_verify: bool,
5257
}
5358

5459
pub async fn command(config: Config) -> Result<(), Box<dyn Error>> {

influxdb3/src/commands/install.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,19 @@ pub struct PackageConfig {
5555
/// An optional arg to use a custom ca for useful for testing with self signed certs
5656
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
5757
ca_cert: Option<PathBuf>,
58+
59+
/// Disable TLS certificate verification
60+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
61+
tls_no_verify: bool,
5862
}
5963

6064
impl PackageConfig {
6165
async fn run_command(&self) -> Result<(), anyhow::Error> {
62-
let mut client = Client::new(self.host_url.clone(), self.ca_cert.clone())?;
66+
let mut client = Client::new(
67+
self.host_url.clone(),
68+
self.ca_cert.clone(),
69+
self.tls_no_verify,
70+
)?;
6371
if let Some(token) = &self.auth_token {
6472
client = client.with_auth_token(token.expose_secret());
6573
}

influxdb3/src/commands/plugin_test/wal.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use influxdb3_client::plugin_development::WalPluginTestRequest;
33
use secrecy::ExposeSecret;
44
use std::collections::HashMap;
55
use std::error::Error;
6+
use std::path::PathBuf;
67

78
#[derive(Debug, clap::Parser)]
89
pub struct Config {
@@ -11,6 +12,14 @@ pub struct Config {
1112

1213
#[clap(flatten)]
1314
wal_plugin_test: WalPluginTest,
15+
16+
/// An optional arg to use a custom ca for useful for testing with self signed certs
17+
#[clap(long = "tls-ca", env = "INFLUXDB3_TLS_CA")]
18+
ca_cert: Option<PathBuf>,
19+
20+
/// Disable TLS certificate verification
21+
#[clap(long = "tls-no-verify", env = "INFLUXDB3_TLS_NO_VERIFY")]
22+
tls_no_verify: bool,
1423
}
1524

1625
#[derive(Debug, clap::Parser)]
@@ -55,7 +64,7 @@ pub(super) async fn command(config: Config) -> Result<(), Box<dyn Error>> {
5564

5665
let wal_plugin_test_request: WalPluginTestRequest = config.wal_plugin_test.into();
5766

58-
let mut client = influxdb3_client::Client::new(host_url)?;
67+
let mut client = influxdb3_client::Client::new(host_url, config.ca_cert, config.tls_no_verify)?;
5968
if let Some(t) = auth_token {
6069
client = client.with_auth_token(t.expose_secret());
6170
}

0 commit comments

Comments
 (0)