Skip to content

Commit

Permalink
Refactor merge DeployDefs into DeployData (single view)
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Aug 11, 2021
1 parent 7cd09ef commit 390aea6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub enum RunDeployError {
ResolveTarget(#[from] data::ResolveTargetError),

#[error("Error processing deployment definitions: {0}")]
DeployDataDefs(#[from] data::DeployDataDefsError),
DeployDataError(#[from] data::DeployDataError),
#[error("Failed to make printable TOML of deployment: {0}")]
TomlFormat(#[from] toml::ser::Error),
#[error("{0}")]
Expand Down
28 changes: 14 additions & 14 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ pub struct DeployData<'a> {
pub merged_settings: settings::GenericSettings,
}

#[derive(Error, Debug)]
pub enum DeployDataError {
#[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")]
NoProfileUser(String, String),
#[error("Value `hostname` is not define for profile {0} of node {1}")]
NoProfileHost(String, String),
}

#[derive(Clap, Debug, Clone)]
pub struct Flags {
/// Check signatures when using `nix copy`
Expand Down Expand Up @@ -310,14 +318,6 @@ pub struct DeployDefs {
pub sudo: Option<String>,
}

#[derive(Error, Debug)]
pub enum DeployDataDefsError {
#[error("Neither `user` nor `sshUser` are set for profile {0} of node {1}")]
NoProfileUser(String, String),
#[error("Value `hostname` is not define for profile {0} of node {1}")]
NoProfileHost(String, String),
}

impl<'a> DeployData<'a> {

fn new(
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<'a> DeployData<'a> {
}
}

pub fn defs(&'a self) -> Result<DeployDefs, DeployDataDefsError> {
pub fn defs(&'a self) -> Result<DeployDefs, DeployDataError> {
let ssh_user = match self.merged_settings.ssh_user {
Some(ref u) => u.clone(),
None => whoami::username(),
Expand All @@ -375,7 +375,7 @@ impl<'a> DeployData<'a> {
})
}

pub fn ssh_uri(&'a self) -> Result<String, DeployDataDefsError> {
pub fn ssh_uri(&'a self) -> Result<String, DeployDataError> {

let hostname = match self.hostname {
Some(x) => x,
Expand All @@ -390,7 +390,7 @@ impl<'a> DeployData<'a> {
}

// can be dropped once ssh fully supports ipv6 uris
pub fn ssh_non_uri(&'a self) -> Result<String, DeployDataDefsError> {
pub fn ssh_non_uri(&'a self) -> Result<String, DeployDataError> {

let hostname = match self.hostname {
Some(x) => x,
Expand All @@ -408,7 +408,7 @@ impl<'a> DeployData<'a> {
self.merged_settings.ssh_opts.iter()
}

pub fn get_profile_path(&'a self) -> Result<String, DeployDataDefsError> {
pub fn get_profile_path(&'a self) -> Result<String, DeployDataError> {
let profile_user = self.get_profile_user()?;
let profile_path = match self.profile.profile_settings.profile_path {
None => match &profile_user[..] {
Expand All @@ -423,13 +423,13 @@ impl<'a> DeployData<'a> {
Ok(profile_path)
}

pub fn get_profile_user(&'a self) -> Result<String, DeployDataDefsError> {
pub fn get_profile_user(&'a self) -> Result<String, DeployDataError> {
let profile_user = match self.merged_settings.user {
Some(ref x) => x.clone(),
None => match self.merged_settings.ssh_user {
Some(ref x) => x.clone(),
None => {
return Err(DeployDataDefsError::NoProfileUser(
return Err(DeployDataError::NoProfileUser(
self.profile_name.to_owned(),
self.node_name.to_owned(),
))
Expand Down
6 changes: 3 additions & 3 deletions src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub enum ConfirmProfileError {
SSHConfirmExitError(Option<i32>),

#[error("Deployment data invalid: {0}")]
InvalidDeployDataDefsError(#[from] data::DeployDataDefsError),
InvalidDeployDataError(#[from] data::DeployDataError),
}

pub async fn confirm_profile(
Expand Down Expand Up @@ -265,7 +265,7 @@ pub enum DeployProfileError {
ConfirmError(#[from] ConfirmProfileError),

#[error("Deployment data invalid: {0}")]
InvalidDeployDataDefsError(#[from] data::DeployDataDefsError),
InvalidDeployDataError(#[from] data::DeployDataError),
}

pub async fn deploy_profile(
Expand Down Expand Up @@ -404,7 +404,7 @@ pub enum RevokeProfileError {
SSHRevokeExitError(Option<i32>),

#[error("Deployment data invalid: {0}")]
InvalidDeployDataDefsError(#[from] data::DeployDataDefsError),
InvalidDeployDataError(#[from] data::DeployDataError),
}
pub async fn revoke(
deploy_data: &data::DeployData<'_>,
Expand Down
2 changes: 1 addition & 1 deletion src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum PushProfileError {
CopyExitError(Option<i32>),

#[error("Deployment data invalid: {0}")]
InvalidDeployDataDefsError(#[from] data::DeployDataDefsError),
InvalidDeployDataError(#[from] data::DeployDataError),
}

pub struct PushProfileData<'a> {
Expand Down

0 comments on commit 390aea6

Please sign in to comment.