/// Loads a provider archive and prints the contents of the claims
Loads a provider archive and prints the contents of the claims
Loads a provider archive and prints the contents of the claims
pub(crate) async fn handle_inspect(cmd: InspectCommand) -> Result<String> {
    let archive = match File::open(&cmd.archive) {
        Ok(mut f) => {
            let mut buf = Vec::new();
            f.read_to_end(&mut buf)?;
            ProviderArchive::try_load(&buf).map_err(|e| format!("{}", e))?
        }
        Err(_) => {
            let artifact = crate::reg::pull_artifact(
                cmd.archive,
                cmd.digest,
                cmd.allow_latest,
                cmd.user,
                cmd.password,
                cmd.insecure,
            )
            .await?;
            ProviderArchive::try_load(&artifact).map_err(|e| format!("{}", e))?
        }
    };
    let claims = archive.claims().unwrap();
    let metadata = claims.metadata.unwrap();
    let output = match cmd.output.kind {
        OutputKind::JSON => {
            let friendly_rev = if metadata.rev.is_some() {
                format!("{}", metadata.rev.unwrap())
            } else {
                "None".to_string()
            };
            let friendly_ver = metadata.ver.unwrap_or("None".to_string());
            format!(
                "{}",
                json!({"name": metadata.name.unwrap(),
                    "public_key": claims.subject,
                    "capability_contract_id": metadata.capid,
                    "vendor": metadata.vendor,
                    "ver": friendly_ver,
                    "rev": friendly_rev,
                    "targets": archive.targets()})
            )
        }
        OutputKind::Text => {
            use term_table::row::Row;
            use term_table::table_cell::*;
            use term_table::{Table, TableStyle};
            let mut table = Table::new();
            table.max_column_width = 68;
            table.style = TableStyle::extended();
            table.add_row(Row::new(vec![TableCell::new_with_alignment(
                format!("{} - Provider Archive", metadata.name.unwrap()),
                2,
                Alignment::Center,
            )]));
            table.add_row(Row::new(vec![
                TableCell::new("Public Key"),
                TableCell::new_with_alignment(claims.subject, 1, Alignment::Right),
            ]));
            table.add_row(Row::new(vec![
                TableCell::new("Capability Contract ID"),
                TableCell::new_with_alignment(metadata.capid, 1, Alignment::Right),
            ]));
            table.add_row(Row::new(vec![
                TableCell::new("Vendor"),
                TableCell::new_with_alignment(metadata.vendor, 1, Alignment::Right),
            ]));
            if let Some(ver) = metadata.ver {
                table.add_row(Row::new(vec![
                    TableCell::new("Version"),
                    TableCell::new_with_alignment(ver, 1, Alignment::Right),
                ]));
            }
            if let Some(rev) = metadata.rev {
                table.add_row(Row::new(vec![
                    TableCell::new("Revision"),
                    TableCell::new_with_alignment(rev, 1, Alignment::Right),
                ]));
            }
            table.add_row(Row::new(vec![TableCell::new_with_alignment(
                "Supported Architecture Targets",
                2,
                Alignment::Center,
            )]));
            table.add_row(Row::new(vec![TableCell::new_with_alignment(
                archive.targets().join("\n"),
                2,
                Alignment::Left,
            )]));
            table.render()
        }
    };
    Ok(output)
}
pub ( crate ) async fn handle_inspect ( cmd : InspectCommand ) -> Result < String > { let archive = match File :: open ( & cmd . archive ) { Ok ( mut f ) => { let mut buf = Vec :: new ( ) ; f . read_to_end ( & mut buf ) ? ; ProviderArchive :: try_load ( & buf ) . map_err ( | e | format ! ( " " e ) ) ? } Err ( _ ) => { let artifact = crate :: reg :: pull_artifact ( cmd . archive , cmd . digest , cmd . allow_latest , cmd . user , cmd . password , cmd . insecure , ) . await ? ; ProviderArchive :: try_load ( & artifact ) . map_err ( | e | format ! ( " " e ) ) ? } } ; let claims = archive . claims ( ) . unwrap ( ) ; let metadata = claims . metadata . unwrap ( ) ; let output = match cmd . output . kind { OutputKind :: JSON => { let friendly_rev = if metadata . rev . is_some ( ) { format ! ( " " metadata rev unwrap ( ) ) } else { " " . to_string ( ) } ; let friendly_ver = metadata . ver . unwrap_or ( " " . to_string ( ) ) ; format ! ( " " json ( { " " metadata name unwrap ( ) " " claims subject " " metadata capid " " metadata vendor " " friendly_ver " " friendly_rev " " archive targets ( ) } ) ) } OutputKind :: Text => { use term_table :: row :: Row ; use term_table :: table_cell :: * ; use term_table :: { Table , TableStyle } ; let mut table = Table :: new ( ) ; table . max_column_width = 68 ; table . style = TableStyle :: extended ( ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( format ( " " metadata name unwrap ( ) ) 2 Alignment Center ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new ( " " ) TableCell new_with_alignment ( claims subject 1 Alignment Right ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new ( " " ) TableCell new_with_alignment ( metadata capid 1 Alignment Right ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new ( " " ) TableCell new_with_alignment ( metadata vendor 1 Alignment Right ) ] ) ) ; if let Some ( ver ) = metadata . ver { table . add_row ( Row :: new ( vec ! [ TableCell new ( " " ) TableCell new_with_alignment ( ver 1 Alignment Right ) ] ) ) ; } if let Some ( rev ) = metadata . rev { table . add_row ( Row :: new ( vec ! [ TableCell new ( " " ) TableCell new_with_alignment ( rev 1 Alignment Right ) ] ) ) ; } table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( " " 2 Alignment Center ) ] ) ) ; table . add_row ( Row :: new ( vec ! [ TableCell new_with_alignment ( archive targets ( ) join ( " \n " ) 2 Alignment Left ) ] ) ) ; table . render ( ) } } ; Ok ( output ) }
Loads a provider archive and prints the contents of the claims
Loads a provider archive and prints the contents of the claims
cmd
InspectCommand