inject all ssh keys by default is non are provided
This commit is contained in:
parent
1839cfd002
commit
34e810b611
@ -85,7 +85,7 @@ client.reboot(test_server.id);
|
||||
```
|
||||
#### Injecting SSH Keys into Rescue Mode
|
||||
|
||||
You can also inject SSH keys into the rescue image. The `enable_rescue_mode` function accepts an optional SSH key ID (integer) or an array of SSH key IDs.
|
||||
You can also inject SSH keys into the rescue image. The `enable_rescue_mode` function accepts an optional SSH key ID (integer) or an array of SSH key IDs. If no keys are provided, all available SSH keys in your project will be automatically used.
|
||||
|
||||
**Important:** The SSH keys must already exist in your Hetzner Cloud project. You can add them in the [Hetzner Cloud Console](https://console.hetzner.cloud/). For more details, refer to the [official documentation on enabling rescue mode](https://docs.hetzner.cloud/reference/cloud#server-actions-enable-rescue-mode-for-a-server).
|
||||
|
||||
|
@ -10,6 +10,7 @@ pub enum Request {
|
||||
RebootServer(HetznerClient, i64),
|
||||
ResetServer(HetznerClient, i64),
|
||||
EnableRescueMode(HetznerClient, i64, Vec<i64>),
|
||||
EnableRescueModeWithAllKeys(HetznerClient, i64),
|
||||
DisableRescueMode(HetznerClient, i64),
|
||||
ListSshKeys(HetznerClient),
|
||||
}
|
||||
@ -58,7 +59,22 @@ pub fn run_worker(
|
||||
Response::ResetServer(result)
|
||||
}
|
||||
Request::EnableRescueMode(client, server_id, ssh_keys) => {
|
||||
let result = rt.block_on(client.enable_rescue_mode_for_server(server_id, ssh_keys)).map_err(|e| e.to_string());
|
||||
let result = rt
|
||||
.block_on(client.enable_rescue_mode_for_server(server_id, ssh_keys))
|
||||
.map_err(|e| e.to_string());
|
||||
Response::EnableRescueMode(result)
|
||||
}
|
||||
Request::EnableRescueModeWithAllKeys(client, server_id) => {
|
||||
let result = rt
|
||||
.block_on(async {
|
||||
let ssh_keys = client.list_ssh_keys().await?;
|
||||
let ssh_key_ids: Vec<i64> = ssh_keys.into_iter().map(|k| k.0.id).collect();
|
||||
println!("Passing in the following ssh key ids: {:#?}", ssh_key_ids);
|
||||
client
|
||||
.enable_rescue_mode_for_server(server_id, ssh_key_ids)
|
||||
.await
|
||||
})
|
||||
.map_err(|e: Box<dyn std::error::Error>| e.to_string());
|
||||
Response::EnableRescueMode(result)
|
||||
}
|
||||
Request::DisableRescueMode(client, server_id) => {
|
||||
|
@ -120,7 +120,7 @@ pub fn register_hetzner_api(
|
||||
.register_fn("enable_rescue_mode", {
|
||||
let bridge = api_bridge.clone();
|
||||
move |client: &mut HetznerClient, server_id: i64| {
|
||||
bridge.call(Request::EnableRescueMode(client.clone(), server_id, Vec::new()), |response| {
|
||||
bridge.call(Request::EnableRescueModeWithAllKeys(client.clone(), server_id), |response| {
|
||||
match response {
|
||||
Response::EnableRescueMode(result) => result.map_err(|e| e.into()),
|
||||
_ => Err("Unexpected response".into()),
|
||||
|
@ -17,7 +17,7 @@ print(test_server.show_details());
|
||||
|
||||
// Enable rescue mode flag on server
|
||||
// print(`Enabling rescue mode on server with ID: ${test_server.id}`);
|
||||
// let root_password = client.enable_rescue_mode(test_server.id, 1337);
|
||||
// let root_password = client.enable_rescue_mode(test_server.id);
|
||||
// print(`Root password is: ${root_password}`);
|
||||
|
||||
// Enable rescue mode with multiple keys from array
|
||||
|
Loading…
Reference in New Issue
Block a user