hetzner_robot_rhai/examples/ssh_key_management.rhai
2025-07-24 13:01:05 +02:00

83 lines
2.9 KiB
Plaintext

// Fingerprint of an existing SSH key for fetching, updating, or deleting.
// Example: "13:dc:a2:1e:a9:d2:1d:a9:39:f4:44:c5:f1:00:ec:c7"
let SSH_KEY_FINGERPRINT = "YOUR_SSH_KEY_FINGERPRINT_HERE";
// Name for a new SSH key or for updating an existing key.
// Example: "my-new-ssh-key" or "my-updated-key-name"
let SSH_KEY_NAME = "YOUR_SSH_KEY_NAME_HERE";
// Public key content for adding a new SSH key.
// Example: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFyZJCEsvRc0eitsOoq+ywC5Lmqejvk3hXMVbO0AxPrd your_email@example.com"
let SSH_PUBLIC_KEY = "YOUR_SSH_PUBLIC_KEY_HERE";
// --- SSH Key Management Operations ---
// 1. Get all SSH keys
// This section retrieves all SSH keys associated with your Hetzner account
// and prints them in a human-readable table format.
print("Fetching all SSH keys...");
let all_keys = hetzner.get_ssh_keys();
all_keys.pretty_print();
print("All SSH keys fetched and displayed.");
// 2. Get a specific SSH key by fingerprint
// This section demonstrates how to retrieve details for a single SSH key
// using its fingerprint.
// Uncomment the following lines and set SSH_KEY_FINGERPRINT to an actual key fingerprint to use.
/*
print("\nAttempting to fetch specific SSH key with fingerprint: " + SSH_KEY_FINGERPRINT);
try {
let specific_key = hetzner.get_ssh_key(SSH_KEY_FINGERPRINT);
print("Specific SSH key details:");
print(specific_key);
} catch (err) {
print("Error fetching specific SSH key: " + err);
}
*/
// 3. Add a new SSH key
// This section adds a new SSH key to your Hetzner account.
// Ensure SSH_KEY_NAME and SSH_PUBLIC_KEY are set correctly.
// Uncomment the following lines to add a new key.
/*
print("\nAttempting to add new SSH key with name: " + SSH_KEY_NAME);
try {
let added_key = hetzner.add_ssh_key(SSH_KEY_NAME, SSH_PUBLIC_KEY);
print("New SSH key added successfully:");
print(added_key);
} catch (err) {
print("Error adding new SSH key: " + err);
}
*/
// 4. Update an SSH key's name
// This section updates the name of an existing SSH key.
// Uncomment the following lines and set SSH_KEY_FINGERPRINT and SSH_KEY_NAME to actual values to use.
/*
print("\nAttempting to update SSH key name for fingerprint: " + SSH_KEY_FINGERPRINT + " to new name: " + SSH_KEY_NAME);
try {
let updated_key = hetzner.update_ssh_key_name(SSH_KEY_FINGERPRINT, SSH_KEY_NAME);
print("SSH key name updated successfully:");
print(updated_key);
} catch (err) {
print("Error updating SSH key name: " + err);
}
*/
// 5. Delete an SSH key
// This section deletes an SSH key from your Hetzner account.
// Use with caution! Once deleted, an SSH key cannot be recovered.
// Uncomment the following lines and set SSH_KEY_FINGERPRINT to the key you wish to delete.
/*
print("\nAttempting to delete SSH key with fingerprint: " + SSH_KEY_FINGERPRINT);
try {
hetzner.delete_ssh_key(SSH_KEY_FINGERPRINT);
print("SSH key deleted successfully.");
} catch (err) {
print("Error deleting SSH key: " + err);
}
*/