Skip to content

Commit ce3964e

Browse files
committed
Read certificate files directly
Customers have found it inconvenient and error-prone to pass in the contents of certs and keys to the `certificate create` subcommand. To make this command easier to use, update its `key` and `cert` arguments to be treated as the path to their respective files, rather than their contents. We previously updated the SAML IdP creation command the same way with 11fe44b (Take paths instead of base64 for SAML creation (#1112), 2025-05-28).
1 parent 3420d09 commit ce3964e

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

cli/docs/cli.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@
823823
"args": [
824824
{
825825
"long": "cert",
826-
"help": "PEM-formatted string containing public certificate chain"
826+
"help": "path to PEM-formatted string containing public certificate chain"
827827
},
828828
{
829829
"long": "description"
@@ -838,7 +838,7 @@
838838
},
839839
{
840840
"long": "key",
841-
"help": "PEM-formatted string containing private key"
841+
"help": "path to PEM-formatted string containing public certificate chain"
842842
},
843843
{
844844
"long": "name"

cli/src/cli_builder.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ impl Default for NewCli<'_> {
134134
.required(true)
135135
.value_parser(clap::value_parser!(std::net::IpAddr)),
136136
),
137+
CliCommand::CertificateCreate => cmd
138+
.mut_arg("cert", |arg| {
139+
arg.value_name("cert-file")
140+
.help("path to PEM-formatted string containing public certificate chain")
141+
})
142+
.mut_arg("key", |arg| {
143+
arg.value_name("key-file")
144+
.help("path to PEM-formatted string containing public certificate chain")
145+
}),
137146

138147
CliCommand::SamlIdentityProviderCreate => cmd
139148
.mut_arg("json-body", |arg| arg.required(false))

cli/src/main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ impl CliConfig for OxideOverride {
255255
Ok(())
256256
}
257257

258+
fn execute_certificate_create(
259+
&self,
260+
matches: &clap::ArgMatches,
261+
request: &mut oxide::builder::CertificateCreate,
262+
) -> anyhow::Result<()> {
263+
let key_path = matches.get_one::<String>("key").unwrap();
264+
let key_bytes = std::fs::read(key_path)
265+
.with_context(|| format!("failed to read key file {key_path}"))?;
266+
267+
let cert_path = matches.get_one::<String>("cert").unwrap();
268+
let cert_bytes = std::fs::read(cert_path)
269+
.with_context(|| format!("failed to read cert file {cert_path}"))?;
270+
271+
*request = request
272+
.to_owned()
273+
.body_map(|body| body.key(key_bytes).cert(cert_bytes));
274+
Ok(())
275+
}
276+
258277
fn execute_saml_identity_provider_create(
259278
&self,
260279
matches: &clap::ArgMatches,

0 commit comments

Comments
 (0)