├── wol_types.go ├── vserver_types.go ├── .gitignore ├── README.md ├── ssh_key_types.go ├── reset_types.go ├── vserver.go ├── wol.go ├── error.go ├── types.go ├── reset.go ├── boot.go ├── server_types.go ├── ordering_type.go ├── ssh_key.go ├── ordering.go ├── server.go ├── boot_types.go ├── client.go └── LICENSE /wol_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | type WOL struct { 4 | ServerIP string `json:"server_ip"` 5 | ServerNumber int `json:"server_number"` 6 | } 7 | -------------------------------------------------------------------------------- /vserver_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | const ( 4 | VServerCommand_Start = "start" 5 | VServerCommand_Stop = "stop" 6 | VServerCommand_Shutdown = "shutdown" 7 | ) 8 | 9 | type VServerCommandRequest struct { 10 | ServerIP string 11 | Type string `url:"type"` 12 | } 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Go Report Card](https://goreportcard.com/badge/github.com/appscode/go-hetzner)](https://goreportcard.com/report/github.com/appscode/go-hetzner) 2 | 3 | [Website](https://appscode.com) • [Slack](https://slack.appscode.com) • [Forum](https://discuss.appscode.com) • [Twitter](https://twitter.com/AppsCodeHQ) 4 | 5 | # go-hetzner 6 | Golang client for Hetzner 7 | 8 | ## API Documentation 9 | https://robot.your-server.de/doc/webservice/en.html 10 | -------------------------------------------------------------------------------- /ssh_key_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | type SSHKey struct { 4 | Name string `json:"name"` 5 | Fingerprint string `json:"fingerprint"` 6 | Type string `json:"type"` 7 | Size int `json:"size"` 8 | Data string `json:"data"` 9 | } 10 | 11 | type SSHKeyCreateRequest struct { 12 | Name string `url:"name"` 13 | Data string `url:"data"` 14 | } 15 | 16 | type SSHKeyUpdateRequest struct { 17 | Fingerprint string 18 | Name string `url:"name"` 19 | } 20 | -------------------------------------------------------------------------------- /reset_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | type Reset struct { 4 | ServerIP string `json:"server_ip"` 5 | ServerNumber int `json:"server_number"` 6 | Type []string `json:"type"` 7 | OperatingStatus string `json:"operating_status"` 8 | } 9 | 10 | type ResetCreateRequest struct { 11 | ServerIP string 12 | Type string `url:"type"` 13 | } 14 | 15 | type ResetCreateResponse struct { 16 | ServerIP string `json:"server_ip"` 17 | ServerNumber int `json:"server_number"` 18 | Type string `json:"type"` 19 | } 20 | -------------------------------------------------------------------------------- /vserver.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#vServer 9 | type VServerService interface { 10 | Command(req *VServerCommandRequest) (*http.Response, error) 11 | } 12 | 13 | type VServerServiceImpl struct { 14 | client *Client 15 | } 16 | 17 | var _ VServerService = &VServerServiceImpl{} 18 | 19 | func (s *VServerServiceImpl) Command(req *VServerCommandRequest) (*http.Response, error) { 20 | path := fmt.Sprintf("/vserver/%v/command", req.ServerIP) 21 | return s.client.Call(http.MethodPost, path, req, nil, true) 22 | } 23 | -------------------------------------------------------------------------------- /wol.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#Wake_on_LAN 9 | type WOLService interface { 10 | Create(serverIP string) (*WOL, *http.Response, error) 11 | Get(serverIP string) (*WOL, *http.Response, error) 12 | } 13 | 14 | type WOLServiceImpl struct { 15 | client *Client 16 | } 17 | 18 | var _ WOLService = &WOLServiceImpl{} 19 | 20 | func (s *WOLServiceImpl) Create(serverIP string) (*WOL, *http.Response, error) { 21 | path := fmt.Sprintf("/wol/%v", serverIP) 22 | 23 | type Data struct { 24 | WOL *WOL `json:"wol"` 25 | } 26 | data := Data{} 27 | resp, err := s.client.Call(http.MethodPost, path, nil, &data, true) 28 | return data.WOL, resp, err 29 | } 30 | 31 | func (s *WOLServiceImpl) Get(serverIP string) (*WOL, *http.Response, error) { 32 | path := fmt.Sprintf("/wol/%v", serverIP) 33 | 34 | type Data struct { 35 | WOL *WOL `json:"wol"` 36 | } 37 | data := Data{} 38 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 39 | return data.WOL, resp, err 40 | } 41 | -------------------------------------------------------------------------------- /error.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "strings" 7 | ) 8 | 9 | // An ErrorResponse reports the error caused by an API request 10 | type APIError struct { 11 | // HTTP response that caused this error 12 | Response *http.Response `json:"-"` 13 | 14 | Status int `json:"status"` 15 | Code string `json:"code"` 16 | Message string `json:"message"` 17 | 18 | // Array of missing input parameters or null 19 | Missing []string `json:"missing"` 20 | // Array of invalid input paramaters or null 21 | Invalid []string `json:"invalid"` 22 | 23 | // Maximum allowed requests 24 | MaxRequest int `json:"max_request"` 25 | // Time interval in seconds 26 | Interval int `json:"interval"` 27 | } 28 | 29 | func (r *APIError) Error() string { 30 | if r.Status == 400 && r.Code == "INVALID_INPUT" { 31 | return fmt.Sprintf("%v %v: %d %v %v (missing %v) (invalid %v)", 32 | r.Response.Request.Method, r.Response.Request.URL, r.Status, r.Code, r.Message, strings.Join(r.Missing, ","), strings.Join(r.Invalid, ",")) 33 | } else if r.Status == 403 && r.Code == "RATE_LIMIT_EXCEEDED" { 34 | return fmt.Sprintf("%v %v: %d %v %v (max_request %v) (internal %v sec)", 35 | r.Response.Request.Method, r.Response.Request.URL, r.Status, r.Code, r.Message, r.MaxRequest, r.Interval) 36 | } else { 37 | return fmt.Sprintf("%v %v: %d %v %v", 38 | r.Response.Request.Method, r.Response.Request.URL, r.Status, r.Code, r.Message) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | 8 | "github.com/cenkalti/backoff" 9 | ) 10 | 11 | // An ErrorResponse reports the error caused by an API request 12 | type ErrorResponse struct { 13 | // HTTP response that caused this error 14 | Response *http.Response 15 | 16 | // Error message 17 | Message string `json:"message"` 18 | } 19 | 20 | func (r *ErrorResponse) Error() string { 21 | return fmt.Sprintf("%v %v: %d %v", 22 | r.Response.Request.Method, r.Response.Request.URL, r.Response.StatusCode, r.Message) 23 | } 24 | 25 | // Default values for ExponentialBackOff. 26 | const ( 27 | DefaultInitialInterval = 50 * time.Millisecond 28 | DefaultRandomizationFactor = 0.5 29 | DefaultMultiplier = 1.5 30 | DefaultMaxInterval = 5 * time.Second 31 | DefaultMaxElapsedTime = 60 * time.Second 32 | ) 33 | 34 | // NewExponentialBackOff creates an instance of ExponentialBackOff using default values. 35 | func NewExponentialBackOff() *backoff.ExponentialBackOff { 36 | b := &backoff.ExponentialBackOff{ 37 | InitialInterval: DefaultInitialInterval, 38 | RandomizationFactor: DefaultRandomizationFactor, 39 | Multiplier: DefaultMultiplier, 40 | MaxInterval: DefaultMaxInterval, 41 | MaxElapsedTime: DefaultMaxElapsedTime, 42 | Clock: backoff.SystemClock, 43 | } 44 | if b.RandomizationFactor < 0 { 45 | b.RandomizationFactor = 0 46 | } else if b.RandomizationFactor > 1 { 47 | b.RandomizationFactor = 1 48 | } 49 | b.Reset() 50 | return b 51 | } 52 | -------------------------------------------------------------------------------- /reset.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#Reset 9 | type ResetService interface { 10 | List() ([]*Reset, *http.Response, error) 11 | Get(serverIP string) (*Reset, *http.Response, error) 12 | Create(req *ResetCreateRequest) (*Reset, *http.Response, error) 13 | } 14 | 15 | type ResetServiceImpl struct { 16 | client *Client 17 | } 18 | 19 | var _ ResetService = &ResetServiceImpl{} 20 | 21 | func (s *ResetServiceImpl) List() ([]*Reset, *http.Response, error) { 22 | path := "/reset" 23 | 24 | type Data struct { 25 | Reset *Reset `json:"reset"` 26 | } 27 | data := make([]Data, 0) 28 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 29 | 30 | a := make([]*Reset, len(data)) 31 | for i, d := range data { 32 | a[i] = d.Reset 33 | } 34 | return a, resp, err 35 | } 36 | 37 | func (s *ResetServiceImpl) Get(serverIP string) (*Reset, *http.Response, error) { 38 | path := fmt.Sprintf("/reset/%v", serverIP) 39 | 40 | type Data struct { 41 | Reset *Reset `json:"reset"` 42 | } 43 | data := Data{} 44 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 45 | return data.Reset, resp, err 46 | } 47 | 48 | func (s *ResetServiceImpl) Create(req *ResetCreateRequest) (*Reset, *http.Response, error) { 49 | path := fmt.Sprintf("/reset/%v", req.ServerIP) 50 | 51 | type Data struct { 52 | Reset *ResetCreateResponse `json:"reset"` 53 | } 54 | 55 | data := Data{} 56 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 57 | 58 | out := &Reset{ 59 | ServerIP: data.Reset.ServerIP, 60 | ServerNumber: data.Reset.ServerNumber, 61 | Type: []string{data.Reset.Type}, 62 | } 63 | return out, resp, err 64 | } 65 | -------------------------------------------------------------------------------- /boot.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#Boot 9 | type BootService interface { 10 | GetConfig(serverIP string) (*Boot, *http.Response, error) 11 | 12 | GetLinuxConfig(serverIP string) (*Linux, *http.Response, error) 13 | ActivateLinux(req *ActivateLinuxRequest) (*Linux, *http.Response, error) 14 | DeactivateLinux(serverIP string) (*http.Response, error) 15 | } 16 | 17 | type BootServiceImpl struct { 18 | client *Client 19 | } 20 | 21 | var _ BootService = &BootServiceImpl{} 22 | 23 | func (s *BootServiceImpl) GetConfig(serverIP string) (*Boot, *http.Response, error) { 24 | path := fmt.Sprintf("/boot/%v", serverIP) 25 | 26 | type Data struct { 27 | Boot *Boot `json:"boot"` 28 | } 29 | data := Data{} 30 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 31 | return data.Boot, resp, err 32 | } 33 | 34 | func (s *BootServiceImpl) GetLinuxConfig(serverIP string) (*Linux, *http.Response, error) { 35 | path := fmt.Sprintf("/boot/%v/linux", serverIP) 36 | 37 | type Data struct { 38 | Linux *Linux `json:"linux"` 39 | } 40 | data := Data{} 41 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 42 | return data.Linux, resp, err 43 | } 44 | 45 | func (s *BootServiceImpl) ActivateLinux(req *ActivateLinuxRequest) (*Linux, *http.Response, error) { 46 | path := fmt.Sprintf("/boot/%v/linux", req.ServerIP) 47 | 48 | type Data struct { 49 | Linux *Linux `json:"linux"` 50 | } 51 | data := Data{} 52 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 53 | return data.Linux, resp, err 54 | } 55 | 56 | func (s *BootServiceImpl) DeactivateLinux(serverIP string) (*http.Response, error) { 57 | path := fmt.Sprintf("/boot/%v/linux", serverIP) 58 | 59 | return s.client.Call(http.MethodDelete, path, nil, nil, true) 60 | } 61 | -------------------------------------------------------------------------------- /server_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import . "github.com/appscode/go/encoding/json/types" 4 | 5 | type ServerSummary struct { 6 | ServerIP string `json:"server_ip"` 7 | ServerNumber int `json:"server_number"` 8 | ServerName string `json:"server_name"` 9 | Product string `json:"product"` 10 | Dc string `json:"dc"` 11 | Traffic string `json:"traffic"` 12 | Flatrate bool `json:"flatrate"` 13 | Status string `json:"status"` 14 | Throttled bool `json:"throttled"` 15 | Cancelled bool `json:"cancelled"` 16 | PaidUntil string `json:"paid_until"` 17 | } 18 | 19 | type Server struct { 20 | ServerSummary 21 | IP []string `json:"ip"` 22 | Subnet []struct { 23 | IP string `json:"ip"` 24 | Mask string `json:"mask"` 25 | } `json:"subnet"` 26 | Reset bool `json:"reset"` 27 | Rescue bool `json:"rescue"` 28 | Vnc bool `json:"vnc"` 29 | Windows bool `json:"windows"` 30 | Plesk bool `json:"plesk"` 31 | Cpanel bool `json:"cpanel"` 32 | Wol bool `json:"wol"` 33 | } 34 | 35 | type ServerUpdateRequest struct { 36 | ServerIP string 37 | ServerName string `url:"server_name"` 38 | } 39 | 40 | type Cancellation struct { 41 | ServerIP string `json:"server_ip"` 42 | ServerNumber int `json:"server_number"` 43 | ServerName string `json:"server_name"` 44 | EarliestCancellationDate string `json:"earliest_cancellation_date"` 45 | Cancelled bool `json:"cancelled"` 46 | CancellationDate string `json:"cancellation_date"` 47 | CancellationReason ArrayOrString `json:"cancellation_reason"` 48 | } 49 | 50 | type CancelServerRequest struct { 51 | ServerIP string 52 | CancellationDate string `url:"cancellation_date"` 53 | CancellationReason string `url:"cancellation_reason,omitempty"` 54 | } 55 | -------------------------------------------------------------------------------- /ordering_type.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import "time" 4 | 5 | type Product struct { 6 | ID string `json:"id"` 7 | Name string `json:"name"` 8 | Description []string `json:"description"` 9 | Traffic string `json:"traffic"` 10 | Dist []string `json:"dist"` 11 | Arch []int `json:"arch"` 12 | Lang []string `json:"lang"` 13 | Price string `json:"price"` 14 | PriceSetup string `json:"price_setup"` 15 | PriceVat string `json:"price_vat"` 16 | PriceSetupVat string `json:"price_setup_vat"` 17 | } 18 | 19 | type AuthorizedKey struct { 20 | Name string `json:"name"` 21 | Fingerprint string `json:"fingerprint"` 22 | Type string `json:"type"` 23 | Size int `json:"size"` 24 | } 25 | type HostKey struct { 26 | Fingerprint string `json:"fingerprint"` 27 | Type string `json:"type"` 28 | Size int `json:"size"` 29 | } 30 | type Transaction struct { 31 | ID string `json:"id"` 32 | Date time.Time `json:"date"` 33 | Status string `json:"status"` 34 | ServerNumber *string `json:"server_number"` 35 | ServerIP *string `json:"server_ip"` 36 | AuthorizedKey []struct { 37 | Key *AuthorizedKey `json:"key"` 38 | } `json:"authorized_key"` 39 | HostKey []struct { 40 | Key *HostKey `json:"key"` 41 | } `json:"host_key"` 42 | Comment *string `json:"comment"` 43 | Product struct { 44 | ID string `json:"id"` 45 | Name string `json:"name"` 46 | Description []string `json:"description"` 47 | Traffic string `json:"traffic"` 48 | Dist string `json:"dist"` 49 | Arch string `json:"arch"` 50 | Lang string `json:"lang"` 51 | } `json:"product"` 52 | } 53 | 54 | type CreateTransactionRequest struct { 55 | ProductID string `url:"product_id"` 56 | AuthorizedKey []string `url:"authorized_key,brackets"` 57 | Password string `url:"password,omitempty"` 58 | Dist string `url:"dist,omitempty"` 59 | Arch int `url:"arch,omitempty"` 60 | Lang string `url:"lang,omitempty"` 61 | Comment string `url:"comment,omitempty"` 62 | Test bool `url:"test"` 63 | } 64 | -------------------------------------------------------------------------------- /ssh_key.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#SSH_keys 9 | type SSHKeyService interface { 10 | List() ([]*SSHKey, *http.Response, error) 11 | Create(req *SSHKeyCreateRequest) (*SSHKey, *http.Response, error) 12 | Get(fingerprint string) (*SSHKey, *http.Response, error) 13 | Update(req *SSHKeyUpdateRequest) (*SSHKey, *http.Response, error) 14 | Delete(fingerprint string) (*http.Response, error) 15 | } 16 | 17 | type SSHKeyServiceImpl struct { 18 | client *Client 19 | } 20 | 21 | var _ SSHKeyService = &SSHKeyServiceImpl{} 22 | 23 | func (s *SSHKeyServiceImpl) List() ([]*SSHKey, *http.Response, error) { 24 | path := "/key" 25 | 26 | type Data struct { 27 | Key *SSHKey `json:"key"` 28 | } 29 | data := make([]Data, 0) 30 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 31 | 32 | a := make([]*SSHKey, len(data)) 33 | for i, d := range data { 34 | a[i] = d.Key 35 | } 36 | return a, resp, err 37 | } 38 | 39 | func (s *SSHKeyServiceImpl) Create(req *SSHKeyCreateRequest) (*SSHKey, *http.Response, error) { 40 | path := "/key" 41 | 42 | type Data struct { 43 | Key *SSHKey `json:"key"` 44 | } 45 | data := Data{} 46 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 47 | return data.Key, resp, err 48 | } 49 | 50 | func (s *SSHKeyServiceImpl) Get(fingerprint string) (*SSHKey, *http.Response, error) { 51 | path := fmt.Sprintf("/key/%v", fingerprint) 52 | 53 | type Data struct { 54 | Key *SSHKey `json:"key"` 55 | } 56 | data := Data{} 57 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 58 | return data.Key, resp, err 59 | } 60 | 61 | func (s *SSHKeyServiceImpl) Update(req *SSHKeyUpdateRequest) (*SSHKey, *http.Response, error) { 62 | path := fmt.Sprintf("/key/%v", req.Fingerprint) 63 | 64 | type Data struct { 65 | Key *SSHKey `json:"key"` 66 | } 67 | data := Data{} 68 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 69 | return data.Key, resp, err 70 | } 71 | 72 | func (s *SSHKeyServiceImpl) Delete(fingerprint string) (*http.Response, error) { 73 | path := fmt.Sprintf("/key/%v", fingerprint) 74 | return s.client.Call(http.MethodDelete, path, nil, nil, true) 75 | } 76 | -------------------------------------------------------------------------------- /ordering.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#Server_ordering 9 | type OrderingService interface { 10 | ListProducts() ([]*Product, *http.Response, error) 11 | GetProduct(id string) (*Product, *http.Response, error) 12 | 13 | ListTransactions() ([]*Transaction, *http.Response, error) 14 | CreateTransaction(req *CreateTransactionRequest) (*Transaction, *http.Response, error) 15 | GetTransaction(id string) (*Transaction, *http.Response, error) 16 | } 17 | 18 | type OrderingServiceImpl struct { 19 | client *Client 20 | } 21 | 22 | var _ OrderingService = &OrderingServiceImpl{} 23 | 24 | func (s *OrderingServiceImpl) ListProducts() ([]*Product, *http.Response, error) { 25 | path := "/order/server/product" 26 | 27 | type Data struct { 28 | Product *Product `json:"product"` 29 | } 30 | data := make([]Data, 0) 31 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 32 | 33 | a := make([]*Product, len(data)) 34 | for i, d := range data { 35 | a[i] = d.Product 36 | } 37 | return a, resp, err 38 | } 39 | 40 | func (s *OrderingServiceImpl) GetProduct(id string) (*Product, *http.Response, error) { 41 | path := fmt.Sprintf("/order/server/product/%v", id) 42 | 43 | type Data struct { 44 | Product *Product `json:"product"` 45 | } 46 | data := Data{} 47 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 48 | return data.Product, resp, err 49 | } 50 | 51 | func (s *OrderingServiceImpl) ListTransactions() ([]*Transaction, *http.Response, error) { 52 | path := "/order/server/transaction" 53 | 54 | type Data struct { 55 | Transaction *Transaction `json:"transaction"` 56 | } 57 | data := make([]Data, 0) 58 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 59 | 60 | a := make([]*Transaction, len(data)) 61 | for i, d := range data { 62 | a[i] = d.Transaction 63 | } 64 | return a, resp, err 65 | } 66 | 67 | func (s *OrderingServiceImpl) CreateTransaction(req *CreateTransactionRequest) (*Transaction, *http.Response, error) { 68 | path := "/order/server/transaction" 69 | 70 | type Data struct { 71 | Transaction *Transaction `json:"transaction"` 72 | } 73 | data := Data{} 74 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 75 | return data.Transaction, resp, err 76 | } 77 | 78 | func (s *OrderingServiceImpl) GetTransaction(id string) (*Transaction, *http.Response, error) { 79 | path := fmt.Sprintf("/order/server/transaction/%v", id) 80 | 81 | type Data struct { 82 | Transaction *Transaction `json:"transaction"` 83 | } 84 | data := Data{} 85 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 86 | return data.Transaction, resp, err 87 | } 88 | -------------------------------------------------------------------------------- /server.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | ) 7 | 8 | // See: https://wiki.hetzner.de/index.php/Robot_Webservice/en#Server 9 | type ServerService interface { 10 | ListServers() ([]*ServerSummary, *http.Response, error) 11 | GetServer(serverIP string) (*Server, *http.Response, error) 12 | UpdateServer(req *ServerUpdateRequest) (*Server, *http.Response, error) 13 | 14 | GetCancellation(serverIP string) (*Cancellation, *http.Response, error) 15 | CancelServer(req *CancelServerRequest) (*Cancellation, *http.Response, error) 16 | WithdrawCancellation(serverIP string) (*http.Response, error) 17 | } 18 | 19 | type ServerServiceImpl struct { 20 | client *Client 21 | } 22 | 23 | var _ ServerService = &ServerServiceImpl{} 24 | 25 | func (s *ServerServiceImpl) ListServers() ([]*ServerSummary, *http.Response, error) { 26 | path := "/server" 27 | 28 | type Data struct { 29 | Server *ServerSummary `json:"server"` 30 | } 31 | data := make([]Data, 0) 32 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 33 | 34 | a := make([]*ServerSummary, len(data)) 35 | for i, d := range data { 36 | a[i] = d.Server 37 | } 38 | return a, resp, err 39 | } 40 | 41 | func (s *ServerServiceImpl) GetServer(serverIP string) (*Server, *http.Response, error) { 42 | path := fmt.Sprintf("/server/%v", serverIP) 43 | 44 | type Data struct { 45 | Server *Server `json:"server"` 46 | } 47 | data := Data{} 48 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 49 | return data.Server, resp, err 50 | } 51 | 52 | func (s *ServerServiceImpl) UpdateServer(req *ServerUpdateRequest) (*Server, *http.Response, error) { 53 | path := fmt.Sprintf("/server/%v", req.ServerIP) 54 | 55 | type Data struct { 56 | Server *Server `json:"server"` 57 | } 58 | data := Data{} 59 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 60 | return data.Server, resp, err 61 | } 62 | 63 | func (s *ServerServiceImpl) GetCancellation(serverIP string) (*Cancellation, *http.Response, error) { 64 | path := fmt.Sprintf("/server/%v/cancellation", serverIP) 65 | 66 | type Data struct { 67 | Cancellation *Cancellation `json:"cancellation"` 68 | } 69 | data := Data{} 70 | resp, err := s.client.Call(http.MethodGet, path, nil, &data, true) 71 | return data.Cancellation, resp, err 72 | } 73 | 74 | func (s *ServerServiceImpl) CancelServer(req *CancelServerRequest) (*Cancellation, *http.Response, error) { 75 | path := fmt.Sprintf("/server/%v/cancellation", req.ServerIP) 76 | 77 | type Data struct { 78 | Cancellation *Cancellation `json:"cancellation"` 79 | } 80 | data := Data{} 81 | resp, err := s.client.Call(http.MethodPost, path, req, &data, true) 82 | return data.Cancellation, resp, err 83 | } 84 | 85 | func (s *ServerServiceImpl) WithdrawCancellation(serverIP string) (*http.Response, error) { 86 | path := fmt.Sprintf("/server/%v/cancellation", serverIP) 87 | 88 | return s.client.Call(http.MethodDelete, path, nil, nil, true) 89 | } 90 | -------------------------------------------------------------------------------- /boot_types.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import . "github.com/appscode/go/encoding/json/types" 4 | 5 | type Rescue struct { 6 | ServerIP string `json:"server_ip"` 7 | ServerNumber int `json:"server_number"` 8 | Os ArrayOrString `json:"os"` 9 | Arch ArrayOrInt `json:"arch"` 10 | Active bool `json:"active"` 11 | Password *string `json:"password"` 12 | AuthorizedKey []*AuthorizedKey `json:"authorized_key"` 13 | HostKey []*HostKey `json:"host_key"` 14 | } 15 | 16 | type Linux struct { 17 | ServerIP string `json:"server_ip"` 18 | ServerNumber int `json:"server_number"` 19 | Dist ArrayOrString `json:"dist"` 20 | Arch ArrayOrInt `json:"arch"` 21 | Lang ArrayOrString `json:"lang"` 22 | Active bool `json:"active"` 23 | Password *string `json:"password"` 24 | AuthorizedKey []*AuthorizedKey `json:"authorized_key"` 25 | HostKey []*HostKey `json:"host_key"` 26 | } 27 | 28 | type Vnc struct { 29 | ServerIP string `json:"server_ip"` 30 | ServerNumber int `json:"server_number"` 31 | Dist ArrayOrString `json:"dist"` 32 | Arch ArrayOrInt `json:"arch"` 33 | Lang ArrayOrString `json:"lang"` 34 | Active bool `json:"active"` 35 | Password *string `json:"password"` 36 | } 37 | 38 | type Windows struct { 39 | ServerIP string `json:"server_ip"` 40 | ServerNumber int `json:"server_number"` 41 | Dist ArrayOrString `json:"dist"` 42 | Lang ArrayOrString `json:"lang"` 43 | Active bool `json:"active"` 44 | Password *string `json:"password"` 45 | } 46 | 47 | type Plesk struct { 48 | ServerIP string `json:"server_ip"` 49 | ServerNumber int `json:"server_number"` 50 | Dist ArrayOrString `json:"dist"` 51 | Arch ArrayOrInt `json:"arch"` 52 | Lang ArrayOrString `json:"lang"` 53 | Active bool `json:"active"` 54 | Password *string `json:"password"` 55 | Hostname *string `json:"hostname"` 56 | } 57 | 58 | type Cpanel struct { 59 | ServerIP string `json:"server_ip"` 60 | ServerNumber int `json:"server_number"` 61 | Dist ArrayOrString `json:"dist"` 62 | Arch ArrayOrInt `json:"arch"` 63 | Lang ArrayOrString `json:"lang"` 64 | Active bool `json:"active"` 65 | Password *string `json:"password"` 66 | Hostname *string `json:"hostname"` 67 | } 68 | 69 | type Boot struct { 70 | Rescue *Rescue `json:"rescue"` 71 | Linux *Linux `json:"linux"` 72 | Vnc *Vnc `json:"vnc"` 73 | Windows *Windows `json:"windows"` 74 | Plesk *Plesk `json:"plesk"` 75 | Cpanel *Cpanel `json:"cpanel"` 76 | } 77 | 78 | type ActivateLinuxRequest struct { 79 | ServerIP string 80 | Dist string `url:"dist"` 81 | Arch int `url:"arch"` 82 | Lang string `url:"lang"` 83 | AuthorizedKey []string `url:"authorized_key,brackets"` 84 | } 85 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | package hetzner 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "errors" 8 | "fmt" 9 | "io/ioutil" 10 | "net/http" 11 | "net/http/httputil" 12 | "net/url" 13 | "sort" 14 | "strconv" 15 | "strings" 16 | "time" 17 | 18 | "github.com/cenkalti/backoff" 19 | "github.com/google/go-querystring/query" 20 | ) 21 | 22 | const ( 23 | // Version of this libary 24 | Version = "0.1.0" 25 | 26 | // User agent for this library 27 | UserAgent = "appscode/" + Version 28 | 29 | // DefaultEndpoint to be used 30 | DefaultEndpoint = "https://robot-ws.your-server.de" 31 | 32 | mediaType = "application/json" 33 | ) 34 | 35 | type Client struct { 36 | // HTTP client used to communicate with Hertzner API. 37 | client *http.Client 38 | 39 | // Base URL for API requests. 40 | BaseURL string 41 | 42 | // User agent for client 43 | UserAgent string 44 | 45 | // Debug will dump http request and response 46 | Debug bool 47 | 48 | headers map[string]string 49 | 50 | b backoff.BackOff 51 | 52 | Boot BootService 53 | Ordering OrderingService 54 | Reset ResetService 55 | Server ServerService 56 | SSHKey SSHKeyService 57 | VServer VServerService 58 | } 59 | 60 | func NewClient(username, password string) *Client { 61 | c := &Client{} 62 | c.client = &http.Client{Timeout: time.Second * 10} 63 | c.BaseURL = DefaultEndpoint 64 | c.headers = map[string]string{ 65 | "Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(username+":"+password)), 66 | } 67 | c.UserAgent = UserAgent 68 | c.b = NewExponentialBackOff() 69 | 70 | c.Boot = &BootServiceImpl{client: c} 71 | c.Ordering = &OrderingServiceImpl{client: c} 72 | c.Reset = &ResetServiceImpl{client: c} 73 | c.Server = &ServerServiceImpl{client: c} 74 | c.SSHKey = &SSHKeyServiceImpl{client: c} 75 | c.VServer = &VServerServiceImpl{client: c} 76 | return c 77 | } 78 | 79 | func (c *Client) WithUserAgent(ua string) *Client { 80 | c.UserAgent = ua 81 | return c 82 | } 83 | 84 | func (c *Client) WithBackOff(b backoff.BackOff) *Client { 85 | c.b = b 86 | return c 87 | } 88 | 89 | func (c *Client) WithTimeout(timeout time.Duration) *Client { 90 | c.client.Timeout = timeout 91 | return c 92 | } 93 | 94 | // NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL 95 | // of the Client. If specified, the value pointed to by request is www-form-urlencoded and included in as the request body. 96 | func (c *Client) NewRequest(method, path string, request interface{}) (*http.Request, error) { 97 | var u *url.URL 98 | var err error 99 | 100 | if c.BaseURL != "" { 101 | u, err = url.Parse(c.BaseURL) 102 | if err != nil { 103 | return nil, err 104 | } 105 | } 106 | 107 | qv, err := query.Values(request) 108 | if err != nil { 109 | return nil, err 110 | } 111 | qs := encode(qv) 112 | if qs != "" && method == http.MethodGet || method == http.MethodDelete { 113 | if strings.Contains(path, "?") { 114 | path += "&" + qs 115 | } else { 116 | path += "?" + qs 117 | } 118 | } 119 | if path != "" { 120 | rel, err := url.Parse(path) 121 | if err != nil { 122 | return nil, err 123 | } 124 | if u != nil { 125 | u = u.ResolveReference(rel) 126 | } else { 127 | u = rel 128 | } 129 | } 130 | if u == nil { 131 | return nil, errors.New("No URL is provided.") 132 | } 133 | 134 | req, err := http.NewRequest(method, u.String(), bytes.NewBufferString(qs)) 135 | if err != nil { 136 | return nil, err 137 | } 138 | 139 | req.Header.Add("Accept", "application/json") 140 | req.Header.Add("User-Agent", c.UserAgent) 141 | for k, v := range c.headers { 142 | req.Header.Add(k, v) 143 | } 144 | if method == http.MethodPost || method == http.MethodPut { 145 | req.Header.Add("Content-Type", "application/x-www-form-urlencoded") 146 | req.Header.Add("Content-Length", strconv.Itoa(len(qs))) 147 | } 148 | if c.Debug { 149 | dump, err := httputil.DumpRequestOut(req, true) 150 | if err == nil { 151 | fmt.Println(string(dump)) 152 | } 153 | } 154 | return req, nil 155 | } 156 | 157 | // Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value 158 | // pointed to by v, or returned as an error if an API error has occurred. 159 | func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) { 160 | var resp *http.Response 161 | var err error 162 | 163 | if c.Debug { 164 | fmt.Println(req.URL.String()) 165 | } 166 | 167 | err = backoff.Retry(func() error { 168 | resp, err = c.client.Do(req) 169 | if err != nil { 170 | return err 171 | } 172 | if c := resp.StatusCode; c == 500 || c >= 502 && c <= 599 { 173 | // Avoid retry on 501: Not Implemented 174 | err = &status5xx{} 175 | } 176 | return err 177 | }, c.b) 178 | c.b.Reset() 179 | 180 | if err != nil { 181 | if _, ok := err.(*status5xx); !ok { 182 | return nil, err 183 | } 184 | } 185 | 186 | if c.Debug { 187 | dump, err := httputil.DumpResponse(resp, true) 188 | if err == nil { 189 | fmt.Println(string(dump)) 190 | } 191 | } 192 | 193 | defer func() { 194 | if rerr := resp.Body.Close(); err == nil { 195 | err = rerr 196 | } 197 | }() 198 | 199 | err = checkResponse(resp) 200 | if err != nil { 201 | return resp, err 202 | } 203 | 204 | if v != nil { 205 | //bb, _ := ioutil.ReadAll(resp.Body) 206 | //fmt.Println(string(bb)) 207 | // 208 | //err := json.Unmarshal(bb, v) 209 | //if err != nil { 210 | // return nil, err 211 | //} 212 | 213 | err = json.NewDecoder(resp.Body).Decode(v) 214 | if err != nil { 215 | return nil, err 216 | } 217 | } 218 | return resp, err 219 | } 220 | 221 | type status5xx struct { 222 | } 223 | 224 | func (r *status5xx) Error() string { 225 | return "5xx Server Error" 226 | } 227 | 228 | // CheckResponse checks the API response for errors, and returns them if present. A response is considered an 229 | // error if it has a status code outside the 200 range. API error responses are expected to have either no response 230 | // body, or a JSON response body that maps to APIError. 231 | func checkResponse(r *http.Response) error { 232 | if c := r.StatusCode; c >= 200 && c <= 299 { 233 | return nil 234 | } 235 | 236 | apiErr := &APIError{Response: r} 237 | data, err := ioutil.ReadAll(r.Body) 238 | if err == nil && len(data) > 0 { 239 | type E struct { 240 | Error *APIError `json:"error"` 241 | } 242 | e := E{} 243 | if err = json.Unmarshal(data, &e); err == nil { 244 | e.Error.Response = r 245 | apiErr = e.Error 246 | } 247 | } 248 | return apiErr 249 | } 250 | 251 | func (c *Client) Call(method, path string, reqBody, resType interface{}, needAuth bool) (*http.Response, error) { 252 | req, err := c.NewRequest(method, path, reqBody) 253 | if err != nil { 254 | return nil, err 255 | } 256 | if !needAuth { 257 | req.Header.Del("Authorization") 258 | } 259 | return c.Do(req, resType) 260 | } 261 | 262 | // Encode encodes the values into ``URL encoded'' form 263 | // ("bar=baz&foo=quux") sorted by key. 264 | // Unlike std lib, this avoid escaping keys. 265 | func encode(v url.Values) string { 266 | if v == nil { 267 | return "" 268 | } 269 | var buf bytes.Buffer 270 | keys := make([]string, 0, len(v)) 271 | for k := range v { 272 | keys = append(keys, k) 273 | } 274 | sort.Strings(keys) 275 | for _, k := range keys { 276 | vs := v[k] 277 | prefix := k + "=" // QueryEscape(k) 278 | for _, v := range vs { 279 | if buf.Len() > 0 { 280 | buf.WriteByte('&') 281 | } 282 | buf.WriteString(prefix) 283 | buf.WriteString(url.QueryEscape(v)) 284 | } 285 | } 286 | return buf.String() 287 | } 288 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------