Skip to content
Open
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
17 changes: 9 additions & 8 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion crates/icp-cli/src/commands/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ use anyhow::{Context as _, bail};
use candid::Principal;
use clap::{Args, ValueHint};
use clap_complete::ArgValueCandidates;
use icp::context::{CanisterSelection, EnvironmentSelection, NetworkSelection};
use icp::identity::IdentitySelection;
use icp::manifest::ArgsFormat;
use icp::prelude::PathBuf;
use icp::{CanisterArgs, fs};
use icp::{
context::NetworkSelection,
host::{CanisterSelection, EnvironmentSelection},
};

use crate::options::{EnvironmentOpt, IdentityOpt, NetworkOpt};

Expand Down
17 changes: 8 additions & 9 deletions crates/icp-cli/src/commands/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Args;
use clap_complete::ArgValueCandidates;
use futures::future::try_join_all;
use icp::context::{Context, EnvironmentSelection};
use icp::{context::Context, host::EnvironmentSelection};

use tracing::info;

Expand Down Expand Up @@ -34,7 +34,7 @@ pub(crate) async fn exec(ctx: &Context, args: &BuildArgs) -> Result<(), anyhow::
let environment_selection: EnvironmentSelection = args.environment.0.clone().into();

// Load target environment
let env = ctx.get_environment(&environment_selection).await?;
let env = ctx.host.get_environment(&environment_selection).await?;

// Determine which canisters to build
let cnames = match args.canisters.is_empty() {
Expand All @@ -50,11 +50,10 @@ pub(crate) async fn exec(ctx: &Context, args: &BuildArgs) -> Result<(), anyhow::
return Ok(());
}

let canisters_to_build = try_join_all(
cnames
.iter()
.map(|name| ctx.get_canister_and_path_for_env(name, &environment_selection)),
)
let canisters_to_build = try_join_all(cnames.iter().map(|name| {
ctx.host
.get_canister_and_path_for_env(name, &environment_selection)
}))
.await?;
// Build the selected canisters
info!("Building canisters:");
Expand All @@ -64,8 +63,8 @@ pub(crate) async fn exec(ctx: &Context, args: &BuildArgs) -> Result<(), anyhow::
build_many(
canisters_to_build,
environment_selection.name(),
ctx.builder.clone(),
ctx.artifacts.clone(),
ctx.host.builder.clone(),
ctx.host.artifacts.clone(),
&pkg_cache,
reporter,
)
Expand Down
15 changes: 9 additions & 6 deletions crates/icp-cli/src/commands/canister/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ use candid_parser::assist;
use candid_parser::parse_idl_args;
use clap::{Args, ValueHint};
use ic_agent::agent::EffectiveId;
use icp::context::{Context, EnvironmentSelection, NetworkSelection};
use icp::manifest::ArgsFormat;
use icp::network::{Configuration as NetworkConfiguration, RootKeySpec};
use icp::parsers::{CyclesAmount, DurationAmount};
use icp::prelude::*;
use icp::signed_message::{
self, CallType, Destination, Request, SignedMessage, Summary, WindowState,
};
use icp::{
context::{Context, NetworkSelection},
host::EnvironmentSelection,
};
use std::io::{self, Write};
use std::str::FromStr;
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
Expand Down Expand Up @@ -505,7 +508,7 @@ async fn resolve_network_offline(
| (EnvironmentSelection::Named(_), NetworkSelection::Url(_, _)) => {
bail!("You can't specify both an environment and a network")
}
(_, NetworkSelection::Default) => ctx.get_environment(environment).await?.network,
(_, NetworkSelection::Default) => ctx.host.get_environment(environment).await?.network,
(EnvironmentSelection::Default, _) => ctx.get_network(network).await?,
};

Expand All @@ -525,7 +528,7 @@ async fn resolve_network_offline(
// A managed network's root key comes out of the descriptor this machine
// wrote when it started the network: a local file, not a request.
NetworkConfiguration::Managed { .. } => {
let access = ctx.network.access(&net).await?;
let access = ctx.host.network.access(&net).await?;
Ok((access.api_url, RootKeySpec::Explicit(access.root_key)))
}
}
Expand All @@ -550,11 +553,11 @@ fn floor_to_minute(t: OffsetDateTime) -> OffsetDateTime {
/// by principal rather than by name, simply yields nothing.
async fn local_candid_type(
ctx: &Context,
canister: &icp::context::CanisterSelection,
canister: &icp::host::CanisterSelection,
) -> Option<CanisterInterface> {
let icp::context::CanisterSelection::Named(name) = canister else {
let icp::host::CanisterSelection::Named(name) = canister else {
return None;
};
let wasm = ctx.artifacts.lookup(name).await.ok()?;
let wasm = ctx.host.artifacts.lookup(name).await.ok()?;
CanisterInterface::from_text(extract_candid_service(&wasm)?).ok()
}
22 changes: 15 additions & 7 deletions crates/icp-cli/src/commands/canister/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ use candid::{Nat, Principal};
use clap::{ArgGroup, Args, Parser};
use ic_management_canister_types::CanisterSettings as MgmtCanisterSettings;
use icp::canister::resolve_controllers;
use icp::context::{Context, EnvironmentSelection, NetworkSelection};
use icp::identity::IdentitySelection;
use icp::parsers::{CyclesAmount, DurationAmount, MemoryAmount, parse_token_amount};
use icp::store_id::IdMapping;
use icp::{Canister, context::CanisterSelection, prelude::*};
use icp::{Canister, host::CanisterSelection, prelude::*};
use icp::{
context::{Context, NetworkSelection},
host::EnvironmentSelection,
};
use serde::Serialize;
use tracing::{info, warn};

Expand Down Expand Up @@ -340,12 +343,13 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),
CanisterSelection::Principal(_) => Err(anyhow!("Cannot create a canister by principal"))?,
};

let env = ctx.get_environment(&selections.environment).await?;
let env = ctx.host.get_environment(&selections.environment).await?;
let (_, canister_info) = env.get_canister_info(&canister).map_err(|e| anyhow!(e))?;

if ctx
.host
.get_canister_id_for_env(
&icp::context::CanisterSelection::Named(canister.clone()),
&icp::host::CanisterSelection::Named(canister.clone()),
&selections.environment,
)
.await
Expand All @@ -363,6 +367,7 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),
.get_agent_for_env(&selections.identity, &selections.environment)
.await?;
let ids = ctx
.host
.ids_by_environment(&selections.environment)
.await
.map_err(|e| anyhow!(e))?;
Expand All @@ -385,11 +390,12 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),

let id = create_operation.create(&canister_settings).await?;

ctx.set_canister_id_for_env(&canister, id, &selections.environment)
ctx.host
.set_canister_id_for_env(&canister, id, &selections.environment)
.await?;

icp::operations::settings::sync_controller_dependents(
ctx,
&ctx.host,
&agent,
args.proxy,
&canister,
Expand All @@ -398,7 +404,9 @@ async fn create_project_canister(ctx: &Context, args: &CreateArgs) -> Result<(),
.await
.map_err(|e| anyhow!(e))?;

ctx.update_custom_domains(&selections.environment).await;
ctx.host
.update_custom_domains(&selections.environment)
.await;

if args.quiet {
println!("{id}");
Expand Down
9 changes: 6 additions & 3 deletions crates/icp-cli/src/commands/canister/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::anyhow;
use candid::Principal;
use clap::Args;
use ic_management_canister_types::CanisterIdRecord;
use icp::context::{CanisterSelection, Context};
use icp::{context::Context, host::CanisterSelection};

use icp::operations::{proxy_management, recover_cycles};

Expand Down Expand Up @@ -68,9 +68,12 @@ pub(crate) async fn exec(ctx: &Context, args: &DeleteArgs) -> Result<(), anyhow:

// Remove canister ID from the id store if it was referenced by name
if let CanisterSelection::Named(canister_name) = &selections.canister {
ctx.remove_canister_id_for_env(canister_name, &selections.environment)
ctx.host
.remove_canister_id_for_env(canister_name, &selections.environment)
.await?;
ctx.update_custom_domains(&selections.environment).await;
ctx.host
.update_custom_domains(&selections.environment)
.await;
}

Ok(())
Expand Down
5 changes: 3 additions & 2 deletions crates/icp-cli/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use candid::Principal;
use clap::{Args, ValueHint};
use dialoguer::Confirm;
use ic_management_canister_types::CanisterInstallMode;
use icp::context::{CanisterSelection, Context};
use icp::fs;
use icp::prelude::*;
use icp::{context::Context, host::CanisterSelection};
use tracing::{info, warn};

use icp::operations::{
Expand Down Expand Up @@ -76,7 +76,8 @@ pub(crate) async fn exec(ctx: &Context, args: &InstallArgs) -> Result<(), anyhow
))?;
}
};
ctx.artifacts
ctx.host
.artifacts
.lookup(canister)
.await
.map_err(|e| anyhow!(e))?
Expand Down
10 changes: 6 additions & 4 deletions crates/icp-cli/src/commands/canister/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::bail;
use candid::Principal;
use clap::Args;
use clap_complete::ArgValueCandidates;
use icp::context::{Context, EnvironmentSelection};
use icp::{context::Context, host::EnvironmentSelection};
use tracing::info;

use crate::options::EnvironmentOpt;
Expand Down Expand Up @@ -35,7 +35,7 @@ pub(crate) async fn exec(ctx: &Context, args: &LinkArgs) -> Result<(), anyhow::E

// A principal must map to at most one canister within an environment; linking an
// ID already claimed by another canister would create an ambiguous mapping.
let existing = ctx.ids_by_environment(&environment).await?;
let existing = ctx.host.ids_by_environment(&environment).await?;
if let Some((owner, _)) = existing
.iter()
.find(|(name, id)| **id == args.principal && *name != &args.name)
Expand All @@ -50,11 +50,13 @@ pub(crate) async fn exec(ctx: &Context, args: &LinkArgs) -> Result<(), anyhow::E
// Replacing an existing entry requires clearing it first; the id store refuses
// to register a name that is already mapped.
if args.force {
ctx.remove_canister_id_for_env(&args.name, &environment)
ctx.host
.remove_canister_id_for_env(&args.name, &environment)
.await?;
}

ctx.set_canister_id_for_env(&args.name, args.principal, &environment)
ctx.host
.set_canister_id_for_env(&args.name, args.principal, &environment)
.await?;

info!(
Expand Down
2 changes: 1 addition & 1 deletion crates/icp-cli/src/commands/canister/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) struct ListArgs {

pub(crate) async fn exec(ctx: &Context, args: &ListArgs) -> Result<(), anyhow::Error> {
let environment_selection = args.environment.clone().into();
let env = ctx.get_environment(&environment_selection).await?;
let env = ctx.host.get_environment(&environment_selection).await?;
let canisters = env.canisters.keys().cloned().collect();
if args.json {
serde_json::to_writer(stdout(), &JsonList { canisters })?;
Expand Down
2 changes: 1 addition & 1 deletion crates/icp-cli/src/commands/canister/migrate_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use num_traits::ToPrimitive;
use tracing::{info, warn};

use crate::commands::args::{self, Canister};
use icp::context::CanisterSelection;
use icp::host::CanisterSelection;
use icp::operations::canister_migration::{
get_subnet_for_canister, migrate_canister, migration_status,
};
Expand Down
4 changes: 3 additions & 1 deletion crates/icp-cli/src/commands/canister/settings/sync.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::bail;
use candid::Principal;
use clap::Args;
use icp::context::{CanisterSelection, Context};
use icp::{context::Context, host::CanisterSelection};
use tracing::warn;

use crate::commands::args::CanisterCommandArgs;
Expand All @@ -24,6 +24,7 @@ pub(crate) async fn exec(ctx: &Context, args: &SyncArgs) -> Result<(), anyhow::E
};

let (_, canister) = ctx
.host
.get_canister_and_path_for_env(name, &selections.environment)
.await?;

Expand All @@ -42,6 +43,7 @@ pub(crate) async fn exec(ctx: &Context, args: &SyncArgs) -> Result<(), anyhow::E
)
.await?;
let ids = ctx
.host
.ids_by_environment(&selections.environment)
.await
.map_err(|e| anyhow::anyhow!(e))?;
Expand Down
4 changes: 2 additions & 2 deletions crates/icp-cli/src/commands/canister/settings/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use ic_management_canister_types::{
};
use icp::ProjectLoadError;
use icp::canister::Visibility;
use icp::context::{CanisterSelection, Context};
use icp::parsers::{CyclesAmount, DurationAmount, MemoryAmount};
use icp::{context::Context, host::CanisterSelection};
use std::collections::{HashMap, HashSet};
use tracing::warn;

Expand Down Expand Up @@ -412,7 +412,7 @@ pub(crate) async fn exec(ctx: &Context, args: &UpdateArgs) -> Result<(), anyhow:
.await?;

let configured_settings = if let CanisterSelection::Named(name) = &selections.canister {
match ctx.project.load().await {
match ctx.host.project.load().await {
Ok(p) => p.canisters[name].1.settings.clone(),
Err(ProjectLoadError::Locate { .. }) => <_>::default(),
Err(e) => bail!("failed to load project: {}", e),
Expand Down
5 changes: 3 additions & 2 deletions crates/icp-cli/src/commands/canister/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use ic_agent::{Agent, AgentError, agent::RejectResponse, export::Principal};
use ic_management_canister_types::{CanisterIdRecord, CanisterStatusResult, EnvironmentVariable};
use icp::{
canister::Visibility,
context::{CanisterSelection, Context, EnvironmentSelection, NetworkSelection},
context::{Context, NetworkSelection},
host::{CanisterSelection, EnvironmentSelection},
identity::IdentitySelection,
};
use serde::Serialize;
Expand Down Expand Up @@ -131,7 +132,7 @@ async fn get_principals(
};
}
None => {
let env = ctx.get_environment(environment).await?;
let env = ctx.host.get_environment(environment).await?;
for (_, c) in env.canisters.values() {
let cid = ctx
.get_canister_id(
Expand Down
Loading
Loading