Skip to content

Commit

Permalink
Improve CLI for docker
Browse files Browse the repository at this point in the history
  • Loading branch information
loriopatrick committed Aug 21, 2024
1 parent 79c0d42 commit 00d02cc
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
]

[workspace.package]
version = "0.15.19"
version = "0.15.20"

[workspace.dependencies]
tokio = { version = "1.39", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ if [ -z "${SECRET_KEY}" ]; then
fi
fi

playit --secret "${SECRET_KEY}" run
playit -s --secret "${SECRET_KEY}" start
2 changes: 1 addition & 1 deletion linux/playit.service
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Wants=network-pre.target
After=network-pre.target NetworkManager.service systemd-resolved.service

[Service]
ExecStart=/opt/playit/playit --secret_wait --secret_path /etc/playit/playit.toml -l /var/log/playit/playit.log
ExecStart=/opt/playit/playit --secret_wait --secret_path /etc/playit/playit.toml -l /var/log/playit/playit.log start
Restart=on-failure

[Install]
Expand Down
11 changes: 9 additions & 2 deletions packages/agent_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ async fn main() -> Result<std::process::ExitCode, CliError> {
tokio::time::sleep(Duration::from_secs(1)).await;
autorun(&mut ui, secret).await?;
}
Some(("start", _)) => {
autorun(&mut ui, secret).await?;
}
Some(("version", _)) => println!("{}", env!("CARGO_PKG_VERSION")),
#[cfg(target_os = "linux")]
Some(("setup", _)) => {
Expand Down Expand Up @@ -179,7 +182,7 @@ async fn main() -> Result<std::process::ExitCode, CliError> {
_ => return Err(CliError::NotImplemented.into())
}
Some(("run", m)) => {
let _ = tracing_subscriber::fmt().try_init();
tracing::error!("run is depreciated and will be removed in a future version of the CLI");

let secret_key = secret.get().await?;
let api = PlayitApi::create(API_BASE.to_string(), Some(secret_key.clone()));
Expand Down Expand Up @@ -587,6 +590,10 @@ fn cli() -> Command {
.arg(arg!(--wait <WAIT_SEC> "number of seconds to wait 0=infinite").default_value("0"))
)
)
.subcommand(
Command::new("start")
.about("Start the playit agent")
)
.subcommand(
Command::new("tunnels")
.subcommand_required(true)
Expand All @@ -608,7 +615,7 @@ fn cli() -> Command {
)
.subcommand(
Command::new("run")
.about("Run the playit agent")
.about("(depreciated will be removed) Run the playit agent with manual port mappings")
.arg(arg!([MAPPING_OVERRIDE] "(format \"<tunnel-id>=[<local-ip>:]<local-port> [, ..]\")").required(false).value_delimiter(','))
)
.subcommand(
Expand Down
10 changes: 8 additions & 2 deletions packages/agent_cli/src/playit_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,17 @@ impl PlayitSecret {
pub async fn ensure_valid(&mut self, ui: &mut UI) -> Result<&mut Self, CliError> {
let api = match self.create_api().await {
Ok(v) => v,
Err(_) => {
Err(error) => {
if !self.allow_path_read {
tracing::warn!("invalid secret, not reading secret from path");
return Err(error);
}

{
let mut secret = self.secret.write().await;
let _ = secret.take();
}

return Ok(self);
}
};
Expand All @@ -92,7 +98,7 @@ impl PlayitSecret {
tokio::time::sleep(Duration::from_secs(3)).await;
}
Err(ApiErrorNoFail::ApiError(ApiResponseError::Auth(AuthError::InvalidAgentKey))) => {
if !self.path.is_some() {
if !self.path.is_some() || !self.allow_path_read {
return Err(CliError::InvalidSecret);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/agent_core/src/agent_control/platform.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::api::api::Platform;

pub fn get_platform() -> Platform {
#[cfg(target_os = "window")]
#[cfg(target_os = "windows")]
return Platform::Windows;

#[cfg(target_os = "linux")]
Expand Down
12 changes: 11 additions & 1 deletion packages/agent_proto/src/control_messages.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Debug;
use std::io::{Read, Write};
use std::net::SocketAddr;
use std::sync::Arc;
Expand Down Expand Up @@ -289,12 +290,21 @@ impl MessageEncoding for AgentPortMappingFound {
}
}

#[derive(Debug, Eq, PartialEq, Clone)]
#[derive(Eq, PartialEq, Clone)]
pub struct UdpChannelDetails {
pub tunnel_addr: SocketAddr,
pub token: Arc<Vec<u8>>,
}

impl Debug for UdpChannelDetails {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("UdpChannelDetails")
.field("tunnel_addr", &self.tunnel_addr)
.field("token", &hex::encode(&self.token[..]))
.finish()
}
}

impl MessageEncoding for UdpChannelDetails {
fn write_to<T: Write>(&self, out: &mut T) -> std::io::Result<usize> {
let mut sum = 0;
Expand Down

0 comments on commit 00d02cc

Please sign in to comment.