Skip to content
Draft
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ prometheus = "0.14.0"
prost = "0.14.3"
prost-build = "0.14.3"
prost-types = "0.14.3"
protobuf = "3.7.2"
pwhash = "1.0.0"
quick-xml = "0.39"
quote = { default-features = false, version = "1.0" }
Expand Down
16 changes: 14 additions & 2 deletions crates/admin-cli/src/managed_host/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod maintenance;
mod power_options;
mod quarantine;
mod reset_host_reprovisioning;
mod set_primary_dpu;
mod set_primary_interface;
mod show;
mod start_updates;
Expand Down Expand Up @@ -61,7 +60,20 @@ pub enum Cmd {
#[clap(about = "Set the primary interface (boot device) for the managed host")]
SetPrimaryInterface(set_primary_interface::Args),
#[clap(about = "Deprecated: use set-primary-interface. Sets the primary DPU.")]
SetPrimaryDpu(set_primary_dpu::Args),
#[command(after_long_help = "\
EXAMPLES:

Set the primary DPU for a host:
$ nico-admin-cli managed-host set-primary-dpu 12345678-1234-5678-90ab-cdef01234567 \
abcdef01-2345-6789-abcd-ef0123456789

Set the primary DPU and reboot the host afterward:
$ nico-admin-cli managed-host set-primary-dpu 12345678-1234-5678-90ab-cdef01234567 \
abcdef01-2345-6789-abcd-ef0123456789 --reboot

")]
#[rpc]
SetPrimaryDpu(rpc::forge::set_primary_dpu::Args),
#[clap(about = "Download debug bundle with logs for a specific host")]
DebugBundle(debug_bundle::Args),
}
52 changes: 0 additions & 52 deletions crates/admin-cli/src/managed_host/set_primary_dpu/args.rs

This file was deleted.

25 changes: 0 additions & 25 deletions crates/admin-cli/src/managed_host/set_primary_dpu/cmd.rs

This file was deleted.

32 changes: 0 additions & 32 deletions crates/admin-cli/src/managed_host/set_primary_dpu/mod.rs

This file was deleted.

15 changes: 15 additions & 0 deletions crates/admin-cli/src/managed_host/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ fn parse_set_primary_dpu() {
match cmd {
Cmd::SetPrimaryDpu(args) => {
assert!(!args.reboot);
let request: rpc::forge::SetPrimaryDpuRequest = args.into();
assert_eq!(
request
.host_machine_id
.expect("host ID must be populated")
.to_string(),
TEST_MACHINE_ID
);
assert_eq!(
request
.dpu_machine_id
.expect("DPU ID must be populated")
.to_string(),
TEST_MACHINE_ID
);
}
_ => panic!("expected SetPrimaryDpu variant"),
}
Expand Down
31 changes: 0 additions & 31 deletions crates/admin-cli/src/tpm_ca/delete/args.rs

This file was deleted.

23 changes: 0 additions & 23 deletions crates/admin-cli/src/tpm_ca/delete/cmd.rs

This file was deleted.

31 changes: 0 additions & 31 deletions crates/admin-cli/src/tpm_ca/delete/mod.rs

This file was deleted.

11 changes: 9 additions & 2 deletions crates/admin-cli/src/tpm_ca/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

mod add;
mod add_bulk;
mod delete;
mod show;
mod show_unmatched_ek;

Expand All @@ -33,7 +32,15 @@ pub enum Cmd {
#[clap(about = "Show all TPM CA certificates")]
Show(show::Args),
#[clap(about = "Delete TPM CA certificate with a given id")]
Delete(delete::Args),
#[command(after_long_help = "\
EXAMPLES:

Delete a TPM CA certificate by its id (from `tpm-ca show`):
$ nico-admin-cli tpm-ca delete --ca-id 42

")]
#[rpc]
Delete(rpc::forge::tpm_delete_ca_cert::Args),
#[clap(about = "Add TPM CA certificate encoded in DER/CER/PEM format in a given file")]
Add(add::Args),
#[clap(about = "Show TPM EK certificates for which there is no CA match")]
Expand Down
5 changes: 4 additions & 1 deletion crates/admin-cli/src/tpm_ca/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ fn parse_delete() {
run = |argv| {
Cmd::try_parse_from(argv.iter().copied())
.map(|cmd| match cmd {
Cmd::Delete(args) => args.ca_id,
Cmd::Delete(args) => {
let request: rpc::forge::TpmCaCertId = args.into();
request.ca_cert_id
}
_ => panic!("expected Delete variant"),
})
.map_err(drop)
Expand Down
25 changes: 23 additions & 2 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type AttributeArgs = syn::punctuated::Punctuated<syn::Meta, syn::Token![,]>;
/// SubGroup(sub::Cmd),
/// }
/// ```
#[proc_macro_derive(Dispatch, attributes(dispatch))]
#[proc_macro_derive(Dispatch, attributes(dispatch, rpc))]
pub fn derive_dispatch(input: TokenStream) -> TokenStream {
let input = syn::parse_macro_input!(input as DeriveInput);
match expand_dispatch(input) {
Expand All @@ -74,15 +74,29 @@ fn expand_dispatch(input: DeriveInput) -> syn::Result<TokenStream> {

let mut run_arms = Vec::new();
let mut dispatch_arms = Vec::new();
let mut rpc_arms = Vec::new();

for variant in &data.variants {
let variant_name = &variant.ident;
let is_dispatch = variant.attrs.iter().any(|a| a.path().is_ident("dispatch"));
let is_rpc = variant.attrs.iter().any(|a| a.path().is_ident("rpc"));

if is_dispatch {
if is_dispatch && is_rpc {
return Err(syn::Error::new_spanned(
variant,
"a Dispatch variant cannot be both #[dispatch] and #[rpc]",
));
} else if is_dispatch {
dispatch_arms.push(quote! {
#name::#variant_name(cmd) => cmd.dispatch(ctx).await,
});
} else if is_rpc {
rpc_arms.push(quote! {
#name::#variant_name(args) => args
.execute(&ctx.api_client.0)
.await
.map_err(Into::into),
});
} else {
run_arms.push(quote! {
#name::#variant_name(args) => args.run(&mut ctx).await,
Expand All @@ -95,6 +109,11 @@ fn expand_dispatch(input: DeriveInput) -> syn::Result<TokenStream> {
} else {
quote! { use crate::cfg::dispatch::Dispatch as _; }
};
let rpc_import = if rpc_arms.is_empty() {
quote! {}
} else {
quote! { use ::rpc::admin_cli::CliRpcCommand as _; }
};

let output = quote! {
impl crate::cfg::dispatch::Dispatch for #name {
Expand All @@ -104,9 +123,11 @@ fn expand_dispatch(input: DeriveInput) -> syn::Result<TokenStream> {
) -> crate::errors::CarbideCliResult<()> {
use crate::cfg::run::Run;
#dispatch_import
#rpc_import
match self {
#(#run_arms)*
#(#dispatch_arms)*
#(#rpc_arms)*
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ name = "rpc"

[features]
sqlx = ["dep:sqlx"]
cli = ["dep:clap", "dep:prettytable-rs", "dep:serde_yaml", "dep:csv"]
cli = [
"dep:clap",
"dep:prettytable-rs",
"dep:serde_yaml",
"dep:csv",
]
model = [
"dep:carbide-api-model",
"dep:once_cell",
Expand Down
Loading