ic-query-cli 0.104.0

Command-line wrapper for read-only Internet Computer metadata queries
Documentation
//! Module: cloud_engine::provider
//!
//! Responsibility: parse and dispatch official Dashboard CloudEngine provider reports.
//! Does not own: HTTP transport, source validation, report rendering, or caching.
//! Boundary: provider identity means an NNS node-provider principal, not an engine canister.

use super::CloudEngineCommandError;
use crate::cli::common::{
    COLLECTION_MODE_LIVE, SourceOutputOptions, collection_help, current_unix_secs,
    write_text_or_json,
};
use crate::presentation::cloud_engine::cloud_engine_provider_info_report_text;
use crate::presentation::cloud_engine::cloud_engine_provider_list_report_text;
use clap::Subcommand;
use ic_query::cloud_engine::CloudEngineProviderInfoRequest;
use ic_query::cloud_engine::CloudEngineProviderListRequest;
use ic_query::cloud_engine::DEFAULT_CLOUD_ENGINE_DASHBOARD_SOURCE_ENDPOINT;
use ic_query::cloud_engine::build_cloud_engine_provider_info_report_with_source;
use ic_query::cloud_engine::build_cloud_engine_provider_list_report_with_source;
use ic_query::ic::LiveIcSource;

const SOURCE_ENDPOINT_HELP: &str = "Official Dashboard v3 endpoint used for provider metadata";

const INFO_HELP_AFTER: &str = "\
Examples:
  icq cloud-engine provider info rbn2y-6vfsb-gv35j-4cyvy-pzbdu-e5aum-jzjg6-5b4n5-vuguf-ycubq-zae
  icq cloud-engine provider info rbn2y-6vfsb-gv35j-4cyvy-pzbdu-e5aum-jzjg6-5b4n5-vuguf-ycubq-zae --json

This command makes one exact official Dashboard request for an NNS node-provider
principal. It preserves the provider's raw CloudEngine and general node counts,
and explicitly reports when the provider has no CloudEngine evidence. Dashboard
responses are off-chain, uncertified, and not point-in-time guaranteed.";
const LIST_HELP_AFTER: &str = "\
Examples:
  icq cloud-engine provider list
  icq cloud-engine provider list --json

This command makes one official Dashboard request for the complete node-provider
resource, validates every returned row up to 1,000, and then retains providers
with explicit CloudEngine counts or locations. Dashboard responses are off-chain,
uncertified, and not point-in-time guaranteed.";

pub(super) async fn run(
    command: ProviderCommand,
    network: &str,
) -> Result<(), CloudEngineCommandError> {
    match command {
        ProviderCommand::Info(options) => run_info(options, network).await,
        ProviderCommand::List(options) => run_list(options, network).await,
    }
}

async fn run_info(
    options: ProviderInfoOptions,
    network: &str,
) -> Result<(), CloudEngineCommandError> {
    let (format, dashboard) = options.source.into_dashboard_request(current_unix_secs()?);
    let request = CloudEngineProviderInfoRequest::new(network, dashboard, options.node_provider_id);
    let report =
        build_cloud_engine_provider_info_report_with_source(&request, &LiveIcSource::default())
            .await?;
    write_text_or_json(format, &report, cloud_engine_provider_info_report_text)
}

async fn run_list(
    options: SourceOutputOptions,
    network: &str,
) -> Result<(), CloudEngineCommandError> {
    let (format, dashboard) = options.into_dashboard_request(current_unix_secs()?);
    let request = CloudEngineProviderListRequest::new(network, dashboard);
    let report =
        build_cloud_engine_provider_list_report_with_source(&request, &LiveIcSource::default())
            .await?;
    write_text_or_json(format, &report, cloud_engine_provider_list_report_text)
}

///
/// ProviderCommand
///
/// Typed CloudEngine provider operation and its admitted arguments.
///

#[derive(Subcommand)]
#[command(about = "Inspect official Dashboard CloudEngine provider metadata", long_about = None, after_help = "Examples:\n  icq cloud-engine provider list\n  icq cloud-engine provider info <node-provider-id>", mut_subcommands(|command| command.mut_arg("source-endpoint", |arg| arg.default_value(DEFAULT_CLOUD_ENGINE_DASHBOARD_SOURCE_ENDPOINT).help(SOURCE_ENDPOINT_HELP))))]
pub(super) enum ProviderCommand {
    #[command(about = "Show one exact node provider and its CloudEngine evidence", long_about = None, after_help = collection_help(COLLECTION_MODE_LIVE, INFO_HELP_AFTER))]
    Info(ProviderInfoOptions),
    #[command(about = "List providers carrying explicit CloudEngine evidence", long_about = None, after_help = collection_help(COLLECTION_MODE_LIVE, LIST_HELP_AFTER))]
    List(SourceOutputOptions),
}

///
/// ProviderInfoOptions
///
/// Typed arguments for the info_command operation.
///

#[derive(clap::Args)]
#[group(skip)]
pub(super) struct ProviderInfoOptions {
    #[command(flatten)]
    source: SourceOutputOptions,
    #[arg(
        id = "node-provider-id",
        value_name = "node-provider-id",
        help = "Exact NNS node-provider principal; not an engine canister principal"
    )]
    pub(super) node_provider_id: String,
}

#[cfg(test)]
mod tests;