Coder Social home page Coder Social logo

hrobot-rs's Introduction

hrobot-rs Latest Version Docs codecov

hrobot is an unofficial asynchronous Rust client for interacting with the Hetzner Robot API

See the AsyncRobot struct for a complete list of supported API Endpoints.

Disclaimer: the authors are not associated with Hetzner (except as customers), and the crate is in no way endorsed or supported by Hetzner Online GmbH.

Requirements for usage

A Hetzner WebService/app user is required to make use of this library.

If you already have a Hetzner account, you can create one through the Hetzner Robot web interface under Settings/Preferences.

Example

Here's a quick example showing how to instantiate the AsyncRobot client object and fetching a list of all dedicated servers owned by the account identified by username

use hrobot::*;

#[tokio::main]
async fn main() {
    // Robot is instantiated using the environment
    // variables HROBOT_USERNAME an HROBOT_PASSWORD.
    let robot = AsyncRobot::default();

    for server in robot.list_servers().await.unwrap() {
        println!("{name}: {product} in {location}",
            name = server.name,
            product = server.product,
            location = server.dc
        );
    }
}

Running the above example should yield something similar to the output below:

foo: AX51-NVMe in FSN1-DC18
bar: Server Auction in FSN1-DC5

API Endpoint Implementation Progress

The entire Hetzner Robot API is covered at this point!

Some endpoints have not been tested due to the cost and disruption to running servers, so please consult the section below for a detailed overview of the endpoints.

Detailed API overview.

Warning!

1 not tested, use at your own risk.

2 not officially documented by Hetzner, use at own risk.

  • Server.
    • List servers.
    • Get server.
    • Rename server.
    • Cancellation.
      • Get cancellation status.
      • Cancel server.1
      • Withdraw cancellation.1
    • Withdraw server order.1 - Deprecated by Hetzner.
  • IP.
    • List IPs.
    • Get IP.
    • Update traffic warnings.
    • Separate MAC.
      • Get separate MAC.
      • Generate separate MAC.1
      • Disable separate MAC.1
    • Cancellation.
      • Get cancellation status.
      • Cancel IP address1
      • Withdraw cancellation1
  • Subnet.
    • List subnets.
    • Get subnet.
    • Separate MAC.
      • Get separate MAC.
      • Generate separate MAC.1
      • Disable separate MAC.1
    • Cancellation.1
      • Get cancellation status.1
      • Cancel subnet.1
      • Withdraw cancellation.1
  • Reset
    • List reset options for all servers.
    • Get reset options for single server
    • Trigger reset.1
  • Failover
    • Get failover IP.1
    • Switch routing of failover traffic.1
    • Disable failover routing.1
  • Wake on LAN
    • Check availability of Wake-on-LAN.
    • Send Wake-on-LAN packet to server.
  • Boot Configuration
    • Get status of all boot configurations.
    • Rescue.
      • Get rescue config.
      • Get last rescue config.
      • Enable rescue config.
      • Disable rescue config.
    • Linux.
      • Get linux config.
      • Get last linux config.
      • Enable linux config.
      • Disable linux config.
    • VNC.
      • Get VNC config.
      • Get last VNC config.2
      • Enable VNC config.
      • Disable VNC config.
    • Windows.1
      • Get Windows config.1
      • Get last Windows config.1 2
      • Enable Windows config.1
      • Disable Windows config.1
    • Plesk.1
      • Get Plesk config.1
      • Get last Plesk config.1 2
      • Enable Plesk config.1
      • Disable Plesk config.1
    • CPanel.1
      • Get CPanel config.1
      • Get last CPanel config.1 2
      • Enable CPanel config.1
      • Disable CPanel config.1
  • Reverse DNS.
    • List reverse DNS entries.
    • Get reverse DNS entry
    • Create reverse DNS entry.
    • Update/create reverse DNS entry.
  • Traffic.
    • Query traffic data.
  • SSH Keys.
    • List SSH keys
    • Upload new SSH key
    • Get SSH key
    • Rename SSH key
    • Delete SSH key
  • Server Ordering.
    • Products.
      • List products.
      • Get product information.
      • List recent product transactions.1
      • Get specific transaction information.1
      • Order new product.
    • Market (auction).
      • List market products.
      • Get market product information.
      • List recent market transactions.1
      • Get specific market transaction information.1
      • Order new server from market.
    • Addons.
      • List available addons for server.
      • List recent addon transactions.1
      • Get specific addon transaction information.1
      • Order addon for server.
  • Storage Box.
    • List storageboxes.
    • Get specific storage box.
    • Change storage box password.
    • Toggle storage box services.
      • Enable/disable Samba
      • Enable/disable WebDAV
      • Enable/disable SSH
      • Enable/disable External reachability
      • Enable/disable snapshot directory visibility.
    • Snapshots.
      • List storagebox snapshots.
      • Create storagebox snapshot.
      • Delete storagebox snapshot.
      • Revert storagebox to snapshot.
      • Change comment for snapshot.
      • Get storagebox snapshot plan.
      • Edit storagebox snapshot plan.
    • Subaccounts.
      • List subaccounts.
      • Create subaccount.
      • Update subaccount configuration.
      • Delete subaccount.
      • Change subaccount password.
  • Firewall.
    • Get firewall configuration for server.
    • Apply firewall configuration to server.
      • Override rules.
      • Apply template.
    • Clear firewall configuration for server.
    • Template.
      • List firewall templates.
      • Create firewall template.
      • Get firewall template.
      • Update firewall template.
      • Delete firewall template.
  • vSwitch.
    • List vSwitches.
    • Create new vSwitch.
    • Get vSwitch.
    • Update vSwitch.
    • Cancel vSwitch.
    • Add servers to vSwitch.
    • Remove servers from vSwitch.

Testing

Tests are divided into two categories:

  • Unit tests. s These do not touch the Hetzner API at all and generally test assumptions made in some of the constructs of the library such as serialization/deserialization from known API output. These are always safe to run and do not require Hetzner credentials.

  • Integration tests. ⚠️

    These tests do interact with the Hetzner API, and therefore require the following two environment variables to be set:

    • HROBOT_USERNAME
    • HROBOT_PASSWORD

    These tests will ⚠️ PURCHASE AN AUCTION SERVER ⚠️ and (ideally) cancel the server once tests have run.

    They interact ⚠️ DESTRUCTIVELY ⚠️ with the resources provided through the following environment variables:

    • HETZNER_INTEGRATION_TEST_STORAGEBOX_ID specifies a pre-allocated storagebox resource which Storagebox-related tests are run against.

Footnotes

  1. Not tested, but should work. Use at own risk. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

  2. Not officially documented by Hetzner, use at own risk. 2 3 4 5

hrobot-rs's People

Contributors

mathiaspius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hrobot-rs's Issues

Use bytesize crate for any byte measurement

Places where byte sizes should be used:

  • Traffic Warnings are implicitly in MB, should be coerced into ByteSize.
  • Traffic limits are strings "5 TB" instead of Option<ByteSize> where None implies unlimited.

Use type-specific IDs for Servers, Templates, etc.

These types should be easily constructible from u32 integers.

Should make the API much more intuitive since a function taking a TemplateId lets you search the docs for references to it and thereby ways of acquiring one/constructing

Automatically makes impossible errors like trying to fetch a server using a firewall template ID for instance, except when explicitly constructing a TemplateId using a server_number Id.

ip field in Server response can be null

I have a dedicated server without an IPv4 Address, so only IPv6 subnet, and in the response of e.g. get_server or list_servers, the ip field is null, which means serde can't deserialize the response.

It looks like this is undocumented behavior, at least the Robot API docs have no example for this.

The relevant piece of code:

/// IP Addresses associated with this server.
///
/// Includes both IPv4 and IPv6 but excludes associated subnets,
/// which are instead listed in [`subnets`](Server::subnets)
#[serde(rename = "ip", default)]
pub ips: Vec<String>,

This could be fixed by either wrapping the Vec in an Option (I tried that locally, would be a breaking change), or using a custom deserialization function.

AsyncRobot should really have a username/password constructor

I just noticed that I've been relying solely on the AsyncRobot::default() functionality which uses AsyncRobot::from_env() under the hood for fetching username and password.

There is an AsyncRobot::new() constructor which takes username and password, but it also requires passing in a hyper client which is very cumbersome to construct.

It would be nice to have a simple AsyncRobot::from_credentials(username: &str, password: &str) constructor which handles the heavy client construction.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.