Skip to content

Read certificate files directly#1267

Merged
wfchandler merged 6 commits into
mainfrom
wc/read-certs-directly
Nov 14, 2025
Merged

Read certificate files directly#1267
wfchandler merged 6 commits into
mainfrom
wc/read-certs-directly

Conversation

@wfchandler
Copy link
Copy Markdown
Collaborator

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).

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).
@wfchandler wfchandler requested a review from ahl November 12, 2025 20:24
Comment thread cli/src/cli_builder.rs
Comment on lines +137 to +145
CliCommand::CertificateCreate => cmd
.mut_arg("cert", |arg| {
arg.value_name("cert-file")
.help("path to PEM-formatted string containing public certificate chain")
})
.mut_arg("key", |arg| {
arg.value_name("key-file")
.help("path to PEM-formatted string containing public certificate chain")
}),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment?

We'd like users to provide a file rather than an inline string value. We avoid having the generated code that would normally handle these arguments misinterpret these as string by simply changing the names of the arguments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the value_name calls are adding a placeholder value to the help text. I've capitalized these and the other value_names to be consistent with the generated code.

Options:
      --cert <CERT-FILE>
          path to a PEM-formatted file containing a public certificate chain

Added a comment explaining the change.

Comment thread cli/src/cli_builder.rs Outdated
Comment thread cli/src/cli_builder.rs Outdated
Comment thread cli/src/main.rs
matches: &clap::ArgMatches,
request: &mut oxide::builder::CertificateCreate,
) -> anyhow::Result<()> {
let key_path = matches.get_one::<String>("key").unwrap();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth mentioning that the name of the arg is "key" but the actual parameter is "key-file"?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, the value_name is purely for display purposes in the help string.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I misunderstood completely. So the generated code does do the wrong thing and then we fix it? Is that as-intended?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not so much that the generated code is wrong, as that it's not a great user experience. We can make the user's life easier by reading the file for them.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The generated code is wrong in that it first puts the file names in those body params

Comment thread cli/src/main.rs
Comment on lines +271 to +274
*request = request
.to_owned()
.body_map(|body| body.key(key_bytes).cert(cert_bytes));
Ok(())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a version of body_map we could use on a &mut?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a little awkward using body_map like this, but not so much that it bothered me. Given the very small number methods we're overriding, I think the extra codegen from adding a new method isn't worth it.

Comment thread cli/src/main.rs
.with_context(|| format!("failed to read cert file {cert_path}"))?;

*request = request
.to_owned()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling to_owned rather than, say, clone? I'm not asking you to change it, I'm asking why you made this choice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was following the pattern used in the existing overrides like execute_networking_allow_list_update

.to_owned()

clone is probably slightly clearer here, since it's just a normal ref we're copying, but I don't feel strongly about it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough!

Comment thread cli/src/main.rs
.with_context(|| format!("failed to read cert file {cert_path}"))?;

*request = request
.to_owned()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough!

Comment thread cli/src/main.rs
@wfchandler wfchandler merged commit 06f4a01 into main Nov 14, 2025
17 checks passed
@wfchandler wfchandler deleted the wc/read-certs-directly branch November 14, 2025 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants