diff --git a/src/hetzner.rs b/src/hetzner.rs index e30f9e7..3d7a89b 100644 --- a/src/hetzner.rs +++ b/src/hetzner.rs @@ -43,6 +43,7 @@ pub struct PublicNet { pub ipv4: Ipv4, } +#[allow(dead_code)] #[derive(Debug, Serialize, Deserialize)] pub struct IpAddress { pub ip: String, @@ -87,13 +88,22 @@ struct CreateServerRequest { #[derive(Debug, Deserialize)] struct CreateServerResponse { server: Server, + root_password: Option, } +/// Result of creating a server, includes the server info and root password +pub struct CreateServerResult { + pub server: Server, + pub root_password: Option, +} + +#[allow(dead_code)] #[derive(Debug, Deserialize)] struct ErrorResponse { error: ErrorDetail, } +#[allow(dead_code)] #[derive(Debug, Deserialize)] struct ErrorDetail { message: String, @@ -112,7 +122,7 @@ impl HetznerClient { } } - pub async fn create_server(&self, config: &ServerConfig) -> Result { + pub async fn create_server(&self, config: &ServerConfig) -> Result { let url = format!("{}/servers", HETZNER_API_BASE); let labels = if config.labels.is_empty() { @@ -183,7 +193,10 @@ impl HetznerClient { result.server.name, result.server.id, result.server.public_net.ipv4.ip ); - Ok(result.server) + Ok(CreateServerResult { + server: result.server, + root_password: result.root_password, + }) } pub async fn delete_server(&self, id: u64) -> Result<()> { @@ -338,7 +351,9 @@ impl HetznerClient { #[derive(Debug, Deserialize)] struct ServerTypesAvailable { available: Vec, + #[allow(dead_code)] available_for_migration: Vec, + #[allow(dead_code)] supported: Vec, } @@ -370,6 +385,7 @@ impl HetznerClient { .collect()) } + #[allow(dead_code)] pub async fn get_server(&self, id: u64) -> Result { let url = format!("{}/servers/{}", HETZNER_API_BASE, id); @@ -448,6 +464,7 @@ final_message: "FFmpeg worker is ready!" } /// Cloud-init config with SSH key access +#[allow(dead_code)] pub fn worker_cloud_init_with_ssh( queue_url: &str, binary_url: &str, @@ -496,13 +513,19 @@ final_message: "FFmpeg worker is ready!" ) } +/// Result of provisioning a worker +pub struct ProvisionResult { + pub ip: String, + pub root_password: Option, +} + pub async fn provision_worker( hetzner_token: &str, queue_url: &str, binary_url: &str, bg_image_url: &str, name: Option, -) -> Result { +) -> Result { let client = HetznerClient::new(hetzner_token.to_string()); let name = name.unwrap_or_else(|| { @@ -520,6 +543,9 @@ pub async fn provision_worker( ..Default::default() }; - let server = client.create_server(&config).await?; - Ok(server.public_net.ipv4.ip) + let result = client.create_server(&config).await?; + Ok(ProvisionResult { + ip: result.server.public_net.ipv4.ip, + root_password: result.root_password, + }) } diff --git a/src/hetzner_cli.rs b/src/hetzner_cli.rs index 4619882..b914edd 100644 --- a/src/hetzner_cli.rs +++ b/src/hetzner_cli.rs @@ -77,7 +77,7 @@ async fn main() -> Result<()> { let binary_url = format!("{}/assets/worker", base); let bg_image_url = format!("{}/assets/gpc-bg.png", base); - let ip = hetzner::provision_worker( + let result = hetzner::provision_worker( &token, &queue_url, &binary_url, @@ -85,7 +85,10 @@ async fn main() -> Result<()> { name, ) .await?; - println!("Worker provisioned at IP: {}", ip); + println!("Worker provisioned at IP: {}", result.ip); + if let Some(password) = result.root_password { + println!("Root password: {}", password); + } } Commands::ListServers { token } => { let client = hetzner::HetznerClient::new(token); diff --git a/src/jobs.rs b/src/jobs.rs index a13bf84..12842e2 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -316,7 +316,7 @@ impl RemoteLogger { } let client = reqwest::Client::new(); - let url = format!("{}/jobs/{}/logs", self.queue_url, self.job_id); + let url = format!("{}/api/jobs/{}/logs", self.queue_url, self.job_id); #[derive(Serialize)] struct LogsPayload { @@ -811,7 +811,7 @@ async fn update_job_progress_remote( let client = reqwest::Client::new(); client - .patch(format!("{}/jobs/{}/progress", queue_url, job_id)) + .patch(format!("{}/api/jobs/{}/progress", queue_url, job_id)) .json(&progress) .send() .await @@ -845,7 +845,7 @@ async fn update_job_status_remote( }; client - .patch(format!("{}/jobs/{}", queue_url, job_id)) + .patch(format!("{}/api/jobs/{}", queue_url, job_id)) .json(&update) .send() .await