Skip to content

Commit

Permalink
feat: Allow custom ports for cloud provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
korewaChino committed Dec 13, 2023
1 parent d4e6924 commit f5036ae
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/cloud/cloud_init.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub fn generate_cloud_init_config(password: &str) -> String {
pub fn generate_cloud_init_config(password: &str, port: u16) -> String {
let cloud_config = serde_json::json!({
"runcmd": ["curl https://i.jpillora.com/chisel! | bash", "systemctl enable --now chisel"],
"write_files": [{
"path": "/etc/systemd/system/chisel.service",
"content": r#"
"content": format!(r#"
[Unit]
Description=Chisel Tunnel
Wants=network-online.target
Expand All @@ -19,10 +19,10 @@ pub fn generate_cloud_init_config(password: &str) -> String {
User=root
# You can add any additional flags here
# This example uses port 9090 for the tunnel socket. `--reverse` is required for our use case.
ExecStart=/usr/local/bin/chisel server --port=9090 --reverse
ExecStart=/usr/local/bin/chisel server --port={port} --reverse
# Additional .env file for auth and secrets
EnvironmentFile=-/etc/sysconfig/chisel
"#
"#)
}, {
"path": "/etc/sysconfig/chisel",
"content": format!("AUTH=chisel:{}\n", password)
Expand All @@ -35,7 +35,7 @@ pub fn generate_cloud_init_config(password: &str) -> String {
#[test]
fn test_generate_cloud_init_config() {
let password = "test";
let config = generate_cloud_init_config(password);
let config = generate_cloud_init_config(password, 9090);
println!("{}", config);
assert!(config.contains("chisel:test"));
}
2 changes: 1 addition & 1 deletion src/cloud/digitalocean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Provisioner for DigitalOceanProvisioner {

let _secret = exit_node.generate_secret(password.clone()).await?;

let config = generate_cloud_init_config(&password);
let config = generate_cloud_init_config(&password, exit_node.spec.port);

// TODO: Secret reference, not plaintext
let api: DigitalOceanApi = DigitalOceanApi::new(self.get_token(auth).await?);
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/linode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Provisioner for LinodeProvisioner {

let _secret = exit_node.generate_secret(password.clone()).await?;

let config = generate_cloud_init_config(&password);
let config = generate_cloud_init_config(&password, exit_node.spec.port);

// Okay, so apparently Linode uses base64 for user_data, so let's
// base64 encode the config
Expand Down
2 changes: 1 addition & 1 deletion src/cloud/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct CloudExitNode {
pub ip: String,
}

const CHISEL_PORT: u16 = 9090;
pub const CHISEL_PORT: u16 = 9090;

#[async_trait]
pub trait Provisioner {
Expand Down
2 changes: 1 addition & 1 deletion src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async fn exit_node_from_service(
},
spec: ExitNodeSpec {
host: "".to_string(),
port: 9090,
port: crate::cloud::CHISEL_PORT,
auth: None,
external_host: None,
default_route: true,
Expand Down

0 comments on commit f5036ae

Please sign in to comment.