Skip to content

Commit c87203f

Browse files
committed
SSH and HC Vault support exposed to optional features
1 parent 7d941fd commit c87203f

File tree

15 files changed

+107
-33
lines changed

15 files changed

+107
-33
lines changed

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ inquire = { optional = true, git = "https://github.com/markcda/inquire.git", bra
1818
mimalloc = "0.1.43"
1919
nix = { optional = true, version = "0.29", features = ["signal", "user"] }
2020
regex = "1.11"
21-
russh = "0.49"
21+
russh = { optional = true, version = "0.49" }
2222
safe-path = "0.1"
2323
serde = { version = "1.0", features = ["derive"] }
2424
serde_json = "1.0"
2525
serde_yaml = { git = "https://github.com/markcda/serde-yaml.git", tag = "0.9.36" }
2626
smart-patcher = { git = "https://github.com/impulse-sw/smart-patcher", tag = "0.2.1", default-features = false }
2727
strip-ansi-escapes = "0.2"
2828
termimad = "0.20"
29-
tokio = { version = "1.0", features = ["rt-multi-thread", "io-std"] }
29+
tokio = { optional = true, version = "1.0", features = ["rt-multi-thread", "io-std"] }
3030
toml = "0.8"
3131
uuid = { version = "1.11", features = ["v4", "fast-rng"] }
32-
vaultrs = "0.7"
32+
vaultrs = { optional = true, version = "0.7" }
3333

3434
[features]
3535
default = ["lua", "rhai", "tui", "containered"]
@@ -40,3 +40,5 @@ lua = ["smart-patcher/lua"]
4040
rhai = ["smart-patcher/rhai"]
4141
tui = ["dep:inquire"]
4242
containered = ["dep:nix"]
43+
hc-vault = ["dep:vaultrs", "dep:tokio"]
44+
ssh-remotes = ["dep:russh", "dep:tokio"]

deploy-config.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pipelines:
4444
supported_langs:
4545
- rust
4646
commands:
47-
- bash_c: cargo clippy --no-default-features --features=lua,rhai,tui,containered
47+
- bash_c: cargo clippy --no-default-features --features=lua,rhai,tui,containered,hc-vault,ssh-remotes
4848
show_success_output: true
4949
- title: Format
5050
info: cargo-fmt@0.1.0
@@ -74,7 +74,7 @@ pipelines:
7474
supported_langs:
7575
- rust
7676
commands:
77-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=lua,rhai,tui,containered
77+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=lua,rhai,tui,containered,hc-vault,ssh-remotes
7878
- title: Compress
7979
info: upx@0.1.0
8080
tags:
@@ -154,7 +154,7 @@ pipelines:
154154
supported_langs:
155155
- rust
156156
commands:
157-
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered
157+
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
158158
show_success_output: true
159159
- title: Форматирование кода
160160
info: cargo-fmt@0.1.0
@@ -184,7 +184,7 @@ pipelines:
184184
supported_langs:
185185
- rust
186186
commands:
187-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered
187+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
188188
- title: Сжатие
189189
info: upx@0.1.0
190190
tags:
@@ -264,7 +264,7 @@ pipelines:
264264
supported_langs:
265265
- rust
266266
commands:
267-
- bash_c: cargo clippy --no-default-features --features=python,lua,rhai,tui,containered
267+
- bash_c: cargo clippy --no-default-features --features=python,lua,rhai,tui,containered,hc-vault,ssh-remotes
268268
show_success_output: true
269269
- title: Format
270270
info: cargo-fmt@0.1.0
@@ -294,7 +294,7 @@ pipelines:
294294
supported_langs:
295295
- rust
296296
commands:
297-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=python,lua,rhai,tui,containered
297+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=python,lua,rhai,tui,containered,hc-vault,ssh-remotes
298298
- title: Compress
299299
info: upx@0.1.0
300300
tags:
@@ -374,7 +374,7 @@ pipelines:
374374
supported_langs:
375375
- rust
376376
commands:
377-
- bash_c: cargo clippy --no-default-features --features=python,i18n-ru,lua,rhai,tui,containered
377+
- bash_c: cargo clippy --no-default-features --features=python,i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
378378
show_success_output: true
379379
- title: Форматирование кода
380380
info: cargo-fmt@0.1.0
@@ -404,7 +404,7 @@ pipelines:
404404
supported_langs:
405405
- rust
406406
commands:
407-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=python,i18n-ru,lua,rhai,tui,containered
407+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=python,i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
408408
- title: Сжатие
409409
info: upx@0.1.0
410410
tags:
@@ -491,7 +491,7 @@ pipelines:
491491
supported_langs:
492492
- rust
493493
commands:
494-
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered
494+
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
495495
show_success_output: true
496496
- title: Форматирование кода
497497
info: cargo-fmt@0.1.0
@@ -521,7 +521,7 @@ pipelines:
521521
supported_langs:
522522
- rust
523523
commands:
524-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered
524+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
525525
- title: Сжатие
526526
info: upx@0.1.0
527527
tags:
@@ -597,7 +597,7 @@ pipelines:
597597
supported_langs:
598598
- rust
599599
commands:
600-
- bash_c: cargo clippy --no-default-features --lib --features=lua,rhai
600+
- bash_c: cargo clippy --no-default-features --lib --features=lua,rhai,hc-vault,ssh-remotes
601601
show_success_output: true
602602
- title: Lint with `containered` feature
603603
info: cargo-clippy@0.1.0
@@ -614,7 +614,7 @@ pipelines:
614614
supported_langs:
615615
- rust
616616
commands:
617-
- bash_c: cargo clippy --no-default-features --lib --features=lua,rhai,containered
617+
- bash_c: cargo clippy --no-default-features --lib --features=lua,rhai,containered,hc-vault,ssh-remotes
618618
show_success_output: true
619619
- title: test
620620
desc: ""
@@ -727,7 +727,7 @@ pipelines:
727727
supported_langs:
728728
- rust
729729
commands:
730-
- bash_c: cargo clippy --no-default-features --features=lua,rhai,tui,containered
730+
- bash_c: cargo clippy --no-default-features --features=lua,rhai,tui,containered,hc-vault,ssh-remotes
731731
show_success_output: true
732732
- title: Build
733733
info: cargo-rel@0.1
@@ -744,7 +744,7 @@ pipelines:
744744
supported_langs:
745745
- rust
746746
commands:
747-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=lua,rhai,tui,containered
747+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=lua,rhai,tui,containered,hc-vault,ssh-remotes
748748
- title: ru-containered
749749
desc: Got from `Deployer Pipeline`.
750750
info: deployer-default@0.1.2
@@ -795,7 +795,7 @@ pipelines:
795795
supported_langs:
796796
- rust
797797
commands:
798-
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered
798+
- bash_c: cargo clippy --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes
799799
show_success_output: true
800800
- title: Сборка
801801
info: cargo-rel@0.1
@@ -812,4 +812,4 @@ pipelines:
812812
supported_langs:
813813
- rust
814814
commands:
815-
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered
815+
- bash_c: RUSTFLAGS='-Zthreads=16' cargo build --release --no-default-features --features=i18n-ru,lua,rhai,tui,containered,hc-vault,ssh-remotes

src/actions.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,12 @@ impl Action {
145145

146146
pub fn run_with(&self, config: &DeployerProjectOptions, env: &RunEnvironment) -> anyhow::Result<(bool, Vec<String>)> {
147147
use crate::entities::traits::Execute;
148+
#[cfg(feature = "ssh-remotes")]
148149
use crate::remote::{sync_from_remote, sync_to_remote};
149150
use crate::run::{execute_pipeline, place_artifacts};
150151

151152
let (status, output) = match self {
153+
#[cfg(feature = "ssh-remotes")]
152154
Action::SyncToRemote { remote_host_name } => {
153155
if let Some(remote) = env.remotes.get(remote_host_name) {
154156
if let Err(e) = sync_to_remote(env.run_dir, remote, env.ignore) {
@@ -160,6 +162,7 @@ impl Action {
160162
(false, vec![i18n::NO_SUCH_REMOTE.to_string()])
161163
}
162164
}
165+
#[cfg(feature = "ssh-remotes")]
163166
Action::SyncFromRemote { remote_host_name } => {
164167
if let Some(remote) = env.remotes.get(remote_host_name) {
165168
if let Err(e) = sync_from_remote(env.run_dir, remote) {
@@ -212,6 +215,11 @@ impl Action {
212215
#[cfg(not(feature = "containered"))]
213216
Action::ConfigureDeploy(a) | Action::Deploy(a) | Action::PostDeploy(a) => a.execute(env)?,
214217

218+
#[cfg(not(feature = "ssh-remotes"))]
219+
Action::SyncToRemote { .. } | Action::SyncFromRemote { .. } => {
220+
panic!("SSH remotes are not enabled in this configuration");
221+
}
222+
215223
#[cfg(feature = "containered")]
216224
_ => (true, vec![i18n::CTRD_SKIP_ACTION.to_string()]),
217225
};

src/cmd.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub enum ListType {
7171
/// List available content in Deployer's storage
7272
Content,
7373
/// List available remote hosts
74+
#[cfg(feature = "ssh-remotes")]
7475
Remote,
7576
}
7677

@@ -83,6 +84,7 @@ pub enum RemoveType {
8384
/// Remove content
8485
Content,
8586
/// Remove remote host
87+
#[cfg(feature = "ssh-remotes")]
8688
Remote,
8789
}
8890

@@ -95,6 +97,7 @@ pub enum CatType {
9597
/// Prints all Pipelines used by current Project
9698
Project(CatProjectArgs),
9799
/// Prints all information about remote host
100+
#[cfg(feature = "ssh-remotes")]
98101
Remote(CatRemoteArgs),
99102
}
100103

@@ -107,6 +110,7 @@ pub enum EditType {
107110
/// Edits Project settings
108111
Project,
109112
/// Edits an information about remote hosts
113+
#[cfg(feature = "ssh-remotes")]
110114
Remote(CatRemoteArgs),
111115
}
112116

@@ -140,6 +144,7 @@ pub enum NewType {
140144
/// Add new Content to Deployer's storage
141145
Content,
142146
/// Add new remote host to Deployer's registry
147+
#[cfg(feature = "ssh-remotes")]
143148
Remote(NewRemoteArgs),
144149
}
145150

src/entities/custom_command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize};
1515
use crate::CTRLC_HANDLER;
1616
use crate::entities::environment::RunEnvironment;
1717
use crate::entities::info::ShortName;
18+
#[cfg(feature = "ssh-remotes")]
1819
use crate::entities::remote_host::RemoteHost;
1920
use crate::entities::traits::Execute;
2021
use crate::i18n;
@@ -125,6 +126,7 @@ pub struct Replacement {
125126
impl Execute for CustomCommand {
126127
/// Runs given command one time or more, replacing the placeholders with given values.
127128
fn execute(&self, env: &RunEnvironment) -> anyhow::Result<(bool, Vec<String>)> {
129+
#[cfg(feature = "ssh-remotes")]
128130
if self.remote_exec.as_ref().is_some_and(|rs| !rs.is_empty()) {
129131
return self.remote_execute(env);
130132
}
@@ -219,6 +221,7 @@ impl Execute for CustomCommand {
219221

220222
/// Runs given command one time or more, replacing the placeholders with given values, and forcing `no_pipe` option.
221223
fn execute_observer(&self, env: &RunEnvironment) -> anyhow::Result<(bool, Vec<String>)> {
224+
#[cfg(feature = "ssh-remotes")]
222225
if self.remote_exec.as_ref().is_some_and(|rs| !rs.is_empty()) {
223226
return self.remote_execute(env);
224227
}
@@ -297,6 +300,7 @@ impl Execute for CustomCommand {
297300

298301
impl CustomCommand {
299302
/// Runs given command remotely on one or more remote hosts.
303+
#[cfg(feature = "ssh-remotes")]
300304
pub fn remote_execute(&self, env: &RunEnvironment) -> anyhow::Result<(bool, Vec<String>)> {
301305
let hosts = self.remote_exec.as_ref().unwrap();
302306
let mut output = vec![];

src/entities/environment.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
//! `RunEnvironment` is just a struct that have all needed variables
44
//! and paths during Pipeline execution.
55
6-
use std::collections::{HashMap, HashSet};
6+
#[cfg(feature = "ssh-remotes")]
7+
use std::collections::HashMap;
8+
use std::collections::HashSet;
79
use std::path::{Path, PathBuf};
810

911
use crate::configs::Placement;
1012
use crate::entities::daemons::Daemons;
13+
#[cfg(feature = "ssh-remotes")]
1114
use crate::entities::info::ShortName;
15+
#[cfg(feature = "ssh-remotes")]
1216
use crate::entities::remote_host::RemoteHost;
1317

1418
/// Run environment.
@@ -18,6 +22,7 @@ pub struct RunEnvironment<'a> {
1822
/// System-wide or local common cache folder (usually `~/.cache`).
1923
pub cache_dir: &'a Path,
2024
/// System-wide or local common configuration folder (usually `~/.config`).
25+
#[allow(dead_code)]
2126
pub config_dir: &'a Path,
2227
/// Project folder.
2328
pub project_dir: Option<&'a Path>,
@@ -28,6 +33,7 @@ pub struct RunEnvironment<'a> {
2833
/// Artifacts placements.
2934
pub artifacts_placements: &'a Vec<Placement>,
3035
/// Remote hosts's Registry. Used to find hosts by short name.
36+
#[cfg(feature = "ssh-remotes")]
3137
pub remotes: &'a HashMap<ShortName, RemoteHost>,
3238
/// What files you should ignore when running Pipelines remotely.
3339
pub ignore: &'a HashSet<PathBuf>,

src/entities/remote_host.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
//!
33
//! Any remote host struct is a set of properties needed to connect and authenticate by `ssh`.
44
5+
#![allow(unused_imports)]
6+
57
use anyhow::bail;
68
use serde::{Deserialize, Serialize};
79
use std::borrow::Cow;
810
use std::net::IpAddr;
911
use std::path::{Path, PathBuf};
1012
use std::sync::Arc;
13+
14+
#[cfg(feature = "ssh-remotes")]
1115
use tokio::net::ToSocketAddrs;
1216

1317
use crate::entities::custom_command::compose_output;
@@ -29,6 +33,7 @@ pub struct RemoteHost {
2933
pub ssh_private_key_file: PathBuf,
3034
}
3135

36+
#[cfg(feature = "ssh-remotes")]
3237
impl RemoteHost {
3338
/// Checks the remote host connectivity, authorization and Deployer installation existence.
3439
pub fn check(&self) -> anyhow::Result<()> {
@@ -112,8 +117,10 @@ impl RemoteHost {
112117
}
113118
}
114119

120+
#[cfg(feature = "ssh-remotes")]
115121
struct Client {}
116122

123+
#[cfg(feature = "ssh-remotes")]
117124
#[async_trait::async_trait]
118125
impl russh::client::Handler for Client {
119126
type Error = anyhow::Error;
@@ -126,10 +133,12 @@ impl russh::client::Handler for Client {
126133
}
127134
}
128135

136+
#[cfg(feature = "ssh-remotes")]
129137
pub struct Session {
130138
session: russh::client::Handle<Client>,
131139
}
132140

141+
#[cfg(feature = "ssh-remotes")]
133142
impl Session {
134143
async fn connect<P: AsRef<Path>, A: ToSocketAddrs>(
135144
key_path: P,

src/entities/requirements.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::actions::test::TestAction;
88
use crate::entities::environment::RunEnvironment;
99
use crate::entities::info::ShortName;
1010
use crate::entities::traits::Execute;
11+
#[cfg(feature = "ssh-remotes")]
1112
use crate::i18n;
1213

1314
/// Requirement.
@@ -82,6 +83,7 @@ impl<'a> Satisfy<'a> for Requirement {
8283
.map_err(|e| SatisfyErr::Check(vec![e.to_string()]))?;
8384
if status { Ok(()) } else { Err(SatisfyErr::Check(out)) }
8485
}
86+
#[cfg(feature = "ssh-remotes")]
8587
Self::RemoteAccessibleAndReady { remote_host_name } => {
8688
let globals = crate::rw::read::<crate::configs::DeployerGlobalConfig>(&env.config_dir, crate::GLOBAL_CONF);
8789
if let Some(remote) = globals.remote_hosts.get(remote_host_name) {
@@ -90,6 +92,8 @@ impl<'a> Satisfy<'a> for Requirement {
9092
Err(SatisfyErr::Remote(i18n::NO_SUCH_REMOTE.to_string()))
9193
}
9294
}
95+
#[cfg(not(feature = "ssh-remotes"))]
96+
Self::RemoteAccessibleAndReady { .. } => Err(SatisfyErr::Remote("Remote hosts aren't supported!".to_string())),
9397
}
9498
}
9599
}

0 commit comments

Comments
 (0)