Skip to content

Commit

Permalink
Implement station file
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawchord committed Oct 25, 2024
1 parent 3f6eb10 commit 583f017
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tools/dfx-orbit/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::path::PathBuf;

use crate::{
asset::{RequestAssetArgs, VerifyAssetArgs},
canister::{RequestCanisterArgs, VerifyCanisterArgs},
Expand Down Expand Up @@ -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<String>,

/// Load station information from a json file. (Useful in CI)
#[clap(long, conflicts_with = "station")]
pub(crate) station_file: Option<PathBuf>,

// TODO: Allow to specify --network, to overwrite the network specified by the station
/// The user identity to run this command as
#[clap(short, long)]
Expand Down Expand Up @@ -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?;
Expand Down
11 changes: 11 additions & 0 deletions tools/dfx-orbit/src/local_config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -139,6 +141,15 @@ impl OrbitExtensionAgent {
Ok(station)
}

pub fn station_from_path(&self, path: &Path) -> anyhow::Result<StationConfig> {
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()?;
Expand Down

0 comments on commit 583f017

Please sign in to comment.