diff --git a/tools/dfx-orbit/src/args.rs b/tools/dfx-orbit/src/args.rs index ba15ee6e9..156d5010b 100644 --- a/tools/dfx-orbit/src/args.rs +++ b/tools/dfx-orbit/src/args.rs @@ -1,3 +1,5 @@ +use std::path::PathBuf; + use crate::{ asset::{RequestAssetArgs, VerifyAssetArgs}, canister::{RequestCanisterArgs, VerifyCanisterArgs}, @@ -26,9 +28,13 @@ pub struct DfxOrbitArgs { pub(crate) quiet: u8, /// Name of the station to execute the command on. (Uses default station if unspecified) - #[clap(short, long)] + #[clap(short, long, conflicts_with = "station_file")] pub(crate) station: Option, + /// Load station information from a json file. (Useful in CI) + #[clap(long, conflicts_with = "station")] + pub(crate) station_file: Option, + // TODO: Allow to specify --network, to overwrite the network specified by the station /// The user identity to run this command as #[clap(short, long)] @@ -106,11 +112,14 @@ impl DfxOrbitArgs { return Ok(()); }; - let config = match self.station { - Some(station_name) => orbit_agent.station(&station_name)?, - None => orbit_agent + let config = if let Some(station_name) = self.station { + orbit_agent.station(&station_name)? + } else if let Some(station_file) = self.station_file { + orbit_agent.station_from_path(&station_file)? + } else { + orbit_agent .default_station()? - .ok_or_else(|| anyhow::format_err!("No default station specified"))?, + .ok_or_else(|| anyhow::format_err!("No default station specified"))? }; let dfx_orbit = DfxOrbit::new(orbit_agent, config, self.identity, logger).await?; diff --git a/tools/dfx-orbit/src/local_config.rs b/tools/dfx-orbit/src/local_config.rs index 931efb741..213be5bf4 100644 --- a/tools/dfx-orbit/src/local_config.rs +++ b/tools/dfx-orbit/src/local_config.rs @@ -1,4 +1,6 @@ //! Local dfx configuration of Orbit stations. +use std::path::Path; + use crate::{dfx::OrbitExtensionAgent, station::StationConfig}; use anyhow::Context; use candid::Principal; @@ -139,6 +141,15 @@ impl OrbitExtensionAgent { Ok(station) } + pub fn station_from_path(&self, path: &Path) -> anyhow::Result { + let station_file = std::fs::File::open(path) + .with_context(|| format!("Failed to open station file at {}", path.display()))?; + + let station: StationConfig = serde_json::from_reader(station_file) + .with_context(|| "Failed to parse station file")?; + Ok(station) + } + /// Removes an Orbit station from the local dfx configuration. pub fn remove_station(&self, name: &str) -> anyhow::Result<()> { let dir = self.stations_dir()?;