├── .gitignore ├── .travis.yml ├── Gopkg.lock ├── Gopkg.toml ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── hcloud_floating_ip │ ├── main.go │ └── main_test.go ├── hcloud_inventory │ └── main.go ├── hcloud_server │ ├── main.go │ └── main_test.go └── hcloud_ssh_key │ ├── main.go │ └── main_test.go ├── docs ├── hcloud_floating_ip.md ├── hcloud_server.md └── hcloud_ssh_key.md ├── pkg ├── ansible │ ├── inventory.go │ ├── messages.go │ └── module.go ├── hcloud │ ├── hcloud.go │ └── hcloudtest │ │ ├── action_client.go │ │ ├── floatingip_client.go │ │ ├── image_client.go │ │ ├── iso_client.go │ │ ├── server_client.go │ │ ├── server_type_client.go │ │ └── sshkey_client.go ├── util │ ├── id.go │ ├── id_test.go │ └── watch.go └── version │ ├── version.go │ └── version_test.go ├── scripts ├── git-version └── test ├── test.yml └── vendor ├── github.com ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── hetznercloud │ └── hcloud-go │ │ ├── LICENSE │ │ └── hcloud │ │ ├── action.go │ │ ├── client.go │ │ ├── datacenter.go │ │ ├── error.go │ │ ├── floating_ip.go │ │ ├── hcloud.go │ │ ├── helper.go │ │ ├── image.go │ │ ├── iso.go │ │ ├── location.go │ │ ├── pricing.go │ │ ├── schema.go │ │ ├── schema │ │ ├── action.go │ │ ├── datacenter.go │ │ ├── error.go │ │ ├── floating_ip.go │ │ ├── image.go │ │ ├── iso.go │ │ ├── location.go │ │ ├── meta.go │ │ ├── pricing.go │ │ ├── server.go │ │ ├── server_type.go │ │ └── ssh_key.go │ │ ├── server.go │ │ ├── server_type.go │ │ └── ssh_key.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go ├── spf13 │ └── pflag │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── bool.go │ │ ├── bool_slice.go │ │ ├── bytes.go │ │ ├── count.go │ │ ├── duration.go │ │ ├── duration_slice.go │ │ ├── flag.go │ │ ├── float32.go │ │ ├── float64.go │ │ ├── golangflag.go │ │ ├── int.go │ │ ├── int16.go │ │ ├── int32.go │ │ ├── int64.go │ │ ├── int8.go │ │ ├── int_slice.go │ │ ├── ip.go │ │ ├── ip_slice.go │ │ ├── ipmask.go │ │ ├── ipnet.go │ │ ├── string.go │ │ ├── string_array.go │ │ ├── string_slice.go │ │ ├── uint.go │ │ ├── uint16.go │ │ ├── uint32.go │ │ ├── uint64.go │ │ ├── uint8.go │ │ └── uint_slice.go └── stretchr │ ├── objx │ ├── .gitignore │ ├── .travis.yml │ ├── Gopkg.lock │ ├── Gopkg.toml │ ├── LICENSE │ ├── README.md │ ├── Taskfile.yml │ ├── accessors.go │ ├── constants.go │ ├── conversions.go │ ├── doc.go │ ├── map.go │ ├── mutations.go │ ├── security.go │ ├── tests.go │ ├── type_specific_codegen.go │ └── value.go │ └── testify │ ├── LICENSE │ ├── assert │ ├── assertion_format.go │ ├── assertion_format.go.tmpl │ ├── assertion_forward.go │ ├── assertion_forward.go.tmpl │ ├── assertions.go │ ├── doc.go │ ├── errors.go │ ├── forward_assertions.go │ └── http_assertions.go │ └── mock │ ├── doc.go │ └── mock.go └── golang.org └── x └── crypto ├── AUTHORS ├── CONTRIBUTORS ├── LICENSE ├── PATENTS ├── curve25519 ├── const_amd64.h ├── const_amd64.s ├── cswap_amd64.s ├── curve25519.go ├── doc.go ├── freeze_amd64.s ├── ladderstep_amd64.s ├── mont25519_amd64.go ├── mul_amd64.s └── square_amd64.s ├── ed25519 ├── ed25519.go └── internal │ └── edwards25519 │ ├── const.go │ └── edwards25519.go ├── internal └── chacha20 │ ├── asm_s390x.s │ ├── chacha_generic.go │ ├── chacha_noasm.go │ ├── chacha_s390x.go │ └── xor.go ├── poly1305 ├── poly1305.go ├── sum_amd64.go ├── sum_amd64.s ├── sum_arm.go ├── sum_arm.s └── sum_ref.go └── ssh ├── buffer.go ├── certs.go ├── channel.go ├── cipher.go ├── client.go ├── client_auth.go ├── common.go ├── connection.go ├── doc.go ├── handshake.go ├── kex.go ├── keys.go ├── mac.go ├── messages.go ├── mux.go ├── server.go ├── session.go ├── streamlocal.go ├── tcpip.go └── transport.go /.gitignore: -------------------------------------------------------------------------------- 1 | /bin 2 | /_output 3 | /library 4 | /*.retry 5 | 6 | .vscode 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: go 3 | go: 4 | - 1.9 5 | before_script: 6 | - go get github.com/golang/lint/golint 7 | script: 8 | - make test 9 | - make 10 | -------------------------------------------------------------------------------- /Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/davecgh/go-spew" 6 | packages = ["spew"] 7 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 8 | version = "v1.1.0" 9 | 10 | [[projects]] 11 | name = "github.com/hetznercloud/hcloud-go" 12 | packages = [ 13 | "hcloud", 14 | "hcloud/schema" 15 | ] 16 | revision = "f4c8a4379a2c0a24e9c4fc242be72b9110e1426d" 17 | version = "v1.7.0" 18 | 19 | [[projects]] 20 | name = "github.com/pmezard/go-difflib" 21 | packages = ["difflib"] 22 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 23 | version = "v1.0.0" 24 | 25 | [[projects]] 26 | name = "github.com/spf13/pflag" 27 | packages = ["."] 28 | revision = "583c0c0531f06d5278b7d917446061adc344b5cd" 29 | version = "v1.0.1" 30 | 31 | [[projects]] 32 | name = "github.com/stretchr/objx" 33 | packages = ["."] 34 | revision = "facf9a85c22f48d2f52f2380e4efce1768749a89" 35 | version = "v0.1" 36 | 37 | [[projects]] 38 | name = "github.com/stretchr/testify" 39 | packages = [ 40 | "assert", 41 | "mock" 42 | ] 43 | revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71" 44 | version = "v1.2.1" 45 | 46 | [[projects]] 47 | branch = "master" 48 | name = "golang.org/x/crypto" 49 | packages = [ 50 | "curve25519", 51 | "ed25519", 52 | "ed25519/internal/edwards25519", 53 | "internal/chacha20", 54 | "poly1305", 55 | "ssh" 56 | ] 57 | revision = "21052ae46654ecf18dfdba0f7c12701a1e2b3164" 58 | 59 | [solve-meta] 60 | analyzer-name = "dep" 61 | analyzer-version = 1 62 | inputs-digest = "66b691b7aee3c0874aecd2f3ebaad6ff8de3c04818556ab41e23b77bc11177b4" 63 | solver-name = "gps-cdcl" 64 | solver-version = 1 65 | -------------------------------------------------------------------------------- /Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "github.com/hetznercloud/hcloud-go" 3 | version = "1.7.0" 4 | 5 | [[constraint]] 6 | name = "github.com/spf13/pflag" 7 | version = "1.0.0" 8 | 9 | [[constraint]] 10 | name = "github.com/stretchr/testify" 11 | version = "1.2.1" 12 | 13 | [[constraint]] 14 | branch = "master" 15 | name = "golang.org/x/crypto" 16 | 17 | [prune] 18 | go-tests = true 19 | unused-packages = true 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Nico Schieder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export CGO_ENABLED:=0 2 | 3 | VERSION=$(shell ./scripts/git-version) 4 | BRANCH=$(shell git rev-parse --abbrev-ref HEAD) 5 | BUILD_DATE=$(shell date +%s) 6 | REPO=github.com/thetechnick/hcloud-ansible 7 | LD_FLAGS="-w -X $(REPO)/pkg/version.VersionTag=$(VERSION) -X $(REPO)/pkg/version.Branch=$(BRANCH) -X $(REPO)/pkg/version.BuildDate=$(BUILD_DATE)" 8 | 9 | all: build 10 | 11 | build: clean \ 12 | bin/hcloud_ssh_key \ 13 | bin/hcloud_server \ 14 | bin/hcloud_floating_ip \ 15 | bin/hcloud_inventory 16 | 17 | bin/%: 18 | @go build -o bin/$* -v -ldflags $(LD_FLAGS) $(REPO)/cmd/$* 19 | 20 | test: 21 | @./scripts/test 22 | 23 | acceptance-test: build 24 | @rm -rf library 25 | @cp -a bin library 26 | ansible-playbook test.yml 27 | 28 | clean: 29 | @rm -rf bin 30 | 31 | clean-release: 32 | @rm -rf _output 33 | 34 | release: \ 35 | clean \ 36 | clean-release \ 37 | _output/hcloud-ansible_linux_amd64.zip \ 38 | _output/hcloud-ansible_linux_386.zip \ 39 | _output/hcloud-ansible_darwin_amd64.zip 40 | 41 | bin/linux_amd64/hcloud_server: GOARGS = GOOS=linux GOARCH=amd64 42 | bin/linux_386/hcloud_server: GOARGS = GOOS=linux GOARCH=386 43 | bin/darwin_amd64/hcloud_server: GOARGS = GOOS=darwin GOARCH=amd64 44 | 45 | bin/linux_amd64/hcloud_ssh_key: GOARGS = GOOS=linux GOARCH=amd64 46 | bin/linux_386/hcloud_ssh_key: GOARGS = GOOS=linux GOARCH=386 47 | bin/darwin_amd64/hcloud_ssh_key: GOARGS = GOOS=darwin GOARCH=amd64 48 | 49 | bin/linux_amd64/hcloud_floating_ip: GOARGS = GOOS=linux GOARCH=amd64 50 | bin/linux_386/hcloud_floating_ip: GOARGS = GOOS=linux GOARCH=386 51 | bin/darwin_amd64/hcloud_floating_ip: GOARGS = GOOS=darwin GOARCH=amd64 52 | 53 | bin/linux_amd64/hcloud_inventory: GOARGS = GOOS=linux GOARCH=amd64 54 | bin/linux_386/hcloud_inventory: GOARGS = GOOS=linux GOARCH=386 55 | bin/darwin_amd64/hcloud_inventory: GOARGS = GOOS=darwin GOARCH=amd64 56 | 57 | bin/%/hcloud_server: clean 58 | $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/hcloud_server 59 | 60 | bin/%/hcloud_ssh_key: clean 61 | $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/hcloud_ssh_key 62 | 63 | bin/%/hcloud_floating_ip: clean 64 | $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/hcloud_floating_ip 65 | 66 | bin/%/hcloud_inventory: clean 67 | $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/hcloud_inventory 68 | 69 | _output/hcloud-ansible_%.zip: NAME=hcloud-ansible_$(VERSION)_$* 70 | _output/hcloud-ansible_%.zip: DEST=_output/$(NAME) 71 | _output/hcloud-ansible_%.zip: \ 72 | bin/%/hcloud_server \ 73 | bin/%/hcloud_ssh_key \ 74 | bin/%/hcloud_floating_ip \ 75 | bin/%/hcloud_inventory 76 | 77 | mkdir -p $(DEST) 78 | cp bin/$*/hcloud_floating_ip bin/$*/hcloud_server bin/$*/hcloud_ssh_key bin/$*/hcloud_inventory README.md LICENSE $(DEST) 79 | cd $(DEST) && zip -r ../$(NAME).zip . 80 | 81 | .PHONY: all build clean test release acceptance-test 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Archived** 2 | As I don't use this project anymore myself, I decided to archive it. 3 | 4 | # Hetzner Cloud - Ansible 5 | [![GitHub release](https://img.shields.io/github/release/thetechnick/hcloud-ansible.svg)](https://github.com/thetechnick/hcloud-ansible/releases/latest) [![Build Status](https://travis-ci.org/thetechnick/hcloud-ansible.svg?branch=master)](https://travis-ci.org/thetechnick/hcloud-ansible) 6 | 7 | The Hetzner Cloud (hcloud) ansible modules and inventory are used to interact with the resources supported by Hetzner Cloud. The modules and inventory need to be configured with an Hetzner Cloud API token before they can be used. 8 | 9 | ## Inventory Example Usage 10 | 11 | ```sh 12 | # ping all hosts in Hetzner Cloud Project 13 | ansible -i hcloud_inventory all -m ping 14 | 15 | # ping all hosts with cx11 server type 16 | ansible -i hcloud_inventory cx11 -m ping 17 | ``` 18 | 19 | ## Modules 20 | 21 | - [hcloud_server - Manage Hetzner Cloud Servers](./docs/hcloud_server.md) 22 | - [hcloud_ssh_key - Manage Hetzner Cloud SSH Keys](./docs/hcloud_ssh_key.md) 23 | - [hcloud_floating_ip - Manage Hetzner Cloud Floating IPs](./docs/hcloud_floating_ip.md) 24 | 25 | ## Installation 26 | 27 | Download the binaries for your OS from the releases page and place them into your [Ansible library](http://docs.ansible.com/ansible/latest/intro_configuration.html#library). 28 | 29 | ## Licence 30 | 31 | MIT license 32 | -------------------------------------------------------------------------------- /cmd/hcloud_inventory/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "os" 8 | 9 | "github.com/spf13/pflag" 10 | "github.com/thetechnick/hcloud-ansible/pkg/ansible" 11 | "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 12 | "github.com/thetechnick/hcloud-ansible/pkg/version" 13 | ) 14 | 15 | var flags = pflag.NewFlagSet("hcloud_inventory", pflag.ContinueOnError) 16 | 17 | func init() { 18 | flags.BoolP("version", "v", false, "Print version and exit") 19 | flags.Bool("list", false, "Print inventory") 20 | flags.String("host", "", "Return hostvars of a single server (unsupported)") 21 | } 22 | 23 | func main() { 24 | if err := flags.Parse(os.Args[1:]); err != nil { 25 | fmt.Fprintf(os.Stderr, "Error parsing flags: %v\n", err) 26 | os.Exit(1) 27 | } 28 | if v, _ := flags.GetBool("version"); v { 29 | version.PrintText() 30 | } 31 | 32 | if printHost, _ := flags.GetString("host"); printHost != "" { 33 | fmt.Fprintf(os.Stderr, "--host is unsupported\n") 34 | os.Exit(1) 35 | } 36 | 37 | client, err := hcloud.BuildClient("") 38 | if err != nil { 39 | fmt.Fprintf(os.Stderr, "Error creating Hetzner Cloud client: %v\n", err) 40 | os.Exit(1) 41 | } 42 | 43 | servers, err := client.Server.All(context.Background()) 44 | if err != nil { 45 | fmt.Fprintf(os.Stderr, "Error listing servers: %v\n", err) 46 | os.Exit(1) 47 | } 48 | 49 | inventory := ansible.NewInventory() 50 | for _, server := range servers { 51 | inventory.AddHost(ansible.InventoryHost{ 52 | Host: server.Name, 53 | Vars: varsForServer(server), 54 | Groups: []string{ 55 | server.Datacenter.Name, 56 | server.Datacenter.Location.Name, 57 | server.ServerType.Name, 58 | fmt.Sprintf("status_%s", string(server.Status)), 59 | imageTag(server), 60 | }, 61 | }) 62 | } 63 | 64 | json, _ := json.MarshalIndent(inventory, "", " ") 65 | fmt.Println(string(json)) 66 | } 67 | 68 | func imageTag(server *hcloud.Server) string { 69 | if server.Image.Name != "" { 70 | return server.Image.Name 71 | } 72 | return fmt.Sprintf("image_%d", server.Image.ID) 73 | } 74 | 75 | func varsForServer(server *hcloud.Server) map[string]interface{} { 76 | vars := map[string]interface{}{ 77 | "hcloud_id": server.ID, 78 | "hcloud_name": server.Name, 79 | "hcloud_public_ipv4": server.PublicNet.IPv4.IP.String(), 80 | "hcloud_public_ipv6": server.PublicNet.IPv6.IP.String(), 81 | "hcloud_location": server.Datacenter.Location.Name, 82 | "hcloud_datacenter": server.Datacenter.Name, 83 | "hcloud_status": string(server.Status), 84 | "hcloud_server_type": server.ServerType.Name, 85 | 86 | "ansible_host": server.PublicNet.IPv4.IP.String(), 87 | } 88 | 89 | if server.Image.Name != "" { 90 | vars["hcloud_image"] = server.Image.Name 91 | } else { 92 | vars["hcloud_image"] = server.Image.ID 93 | } 94 | 95 | return vars 96 | } 97 | -------------------------------------------------------------------------------- /docs/hcloud_floating_ip.md: -------------------------------------------------------------------------------- 1 | # hcloud_floating_ip 2 | 3 | Manages Hetzner Cloud floating ips. This module can be used to create, modify, assign and delete floating ips. 4 | 5 | ## Requirements (on host that executes module) 6 | - ansible >= 2.2.x (binary module support) 7 | 8 | ## Options 9 | |parameter|required|default|choices|comments| 10 | |---------|--------|-------|-------|--------| 11 | |token|no|||Hetzner Cloud API Token. Can also be specified with `HCLOUD_TOKEN` environment variable. | 12 | |state|no|present|| `list` lists all existing floating ips.
**NOTICE:**
`present` is not idempotent and will create a new floating ip when `id` is not specified. | 13 | | id | no | | | ID of the floating ip.
Required when `state=absent`. | 14 | | description | no | | | Description of the floating ip. | 15 | | type | no | ipv4 || Required when `state=present` and `id` is not specified. | 16 | | home_location | no | | | Home location of the floating ip.
Required when `state=present` and `server` is not specified.
Mutually exclusive with `server`. | 17 | | server | no | | | Server to assign the floating ip to.
Required when `state=present` and `home_location` is not specified.
Mutually exclusive with `home_location`. | 18 | 19 | ## Return Values 20 | 21 | These values can be used when registering the modules output. 22 | 23 | ```yaml 24 | floating_ips: 25 | - id: 123 26 | type: ipv4 27 | ip: 131.232.99.1 28 | description: Loadbalancer IP 29 | home_location: fsn1 30 | server_id: 123 31 | ``` 32 | 33 | ## Examples 34 | 35 | ```yaml 36 | # create a floating ip and assign it to a server 37 | - hcloud_floating_ip: 38 | description: Loadbalancer IP 39 | type: ipv4 40 | server: 123 # by id 41 | 42 | # list all floating ips in the Hetzner Cloud Project and 43 | # assign all of them to a server 44 | - hcloud_floating_ip: 45 | state: list 46 | register: hcloud_floating_ips 47 | 48 | - hcloud_floating_ip: 49 | id: "{{item.id}}" 50 | server: 123 51 | with_items: {{hcloud_floating_ips.floating_ips}} 52 | 53 | # assign floating ip 123 to server "loadbalancer" 54 | - hcloud_floating_ip: 55 | id: 123 56 | server: "loadbalancer" # by name 57 | ``` 58 | -------------------------------------------------------------------------------- /docs/hcloud_ssh_key.md: -------------------------------------------------------------------------------- 1 | # hcloud_ssh_key 2 | 3 | Manages Hetzner Cloud SSH Keys. This module can be used to create, list and delete ssh keys. 4 | 5 | ## Requirements (on host that executes module) 6 | - ansible >= 2.2.x (binary module support) 7 | 8 | ## Options 9 | |parameter|required|default|choices|comments| 10 | |---------|--------|-------|-------|--------| 11 | |token|no|||Hetzner Cloud API Token. Can also be specified with `HCLOUD_TOKEN` environment variable. | 12 | |state|no|present|| `list` lists all existing ssh keys. | 13 | | id | no | | | ID of the ssh key. (with state: `absent`) | 14 | | name | no | | | Name of the ssh key. Required when state is `present`. | 15 | | public_key | no | | | Required when state is `present`. | 16 | 17 | ## Return Values 18 | 19 | These values can be used when registering the modules output. 20 | 21 | ```yaml 22 | ssh_keys: 23 | - id: 123 24 | name: mykey@machine 25 | fingerprint: a2:94:75:0d:cf:fd:2c:fc:77:81:0e:c6:7a:8d:a2:21 26 | ``` 27 | 28 | ## Examples 29 | 30 | ```yaml 31 | # create an ssh key 32 | - hcloud_ssh_key: 33 | name: test key 34 | public_key: "{{lookup('file', '~/.ssh/id_rsa.pub')}}" 35 | 36 | 37 | # list all ssh keys in the Hetzner Cloud Project and 38 | # create a single server with the fetched ssh keys 39 | - hcloud_ssh_key: 40 | state: list 41 | register: hcloud_ssh_keys 42 | 43 | - hcloud_server: 44 | name: example-server 45 | image: debian-9 46 | server_type: cx11 47 | datacenter: nbg1-dc3 48 | ssh_keys: "{{ hcloud_ssh_keys.ssh_keys }}" 49 | ``` 50 | -------------------------------------------------------------------------------- /pkg/ansible/inventory.go: -------------------------------------------------------------------------------- 1 | package ansible 2 | 3 | import "encoding/json" 4 | 5 | // Inventory represents a Ansible Inventory 6 | type Inventory struct { 7 | hosts map[string]InventoryHost 8 | groups map[string]InventoryGroup 9 | } 10 | 11 | // InventoryHost represents a Host in an Ansible Inventory 12 | type InventoryHost struct { 13 | Host string 14 | Groups []string 15 | Vars map[string]interface{} 16 | } 17 | 18 | // InventoryGroup represents a Group in an Ansible Inventory 19 | type InventoryGroup struct { 20 | Name string 21 | Vars map[string]interface{} 22 | Children []string 23 | } 24 | 25 | // NewInventory creates a new empty Inventory 26 | func NewInventory() Inventory { 27 | return Inventory{ 28 | hosts: map[string]InventoryHost{}, 29 | groups: map[string]InventoryGroup{}, 30 | } 31 | } 32 | 33 | // AddHost adds the host to the inventory 34 | func (i Inventory) AddHost(host InventoryHost) { 35 | for _, group := range host.Groups { 36 | if _, ok := i.groups[group]; !ok { 37 | i.AddGroup(InventoryGroup{Name: group}) 38 | } 39 | } 40 | i.hosts[host.Host] = host 41 | } 42 | 43 | // AddGroup adds a group to the inventory 44 | func (i Inventory) AddGroup(group InventoryGroup) { 45 | i.groups[group.Name] = group 46 | } 47 | 48 | func (i Inventory) buildMetaHostvars() (vars map[string]interface{}) { 49 | vars = map[string]interface{}{} 50 | for _, host := range i.hosts { 51 | vars[host.Host] = host.Vars 52 | } 53 | return 54 | } 55 | 56 | func (i Inventory) buildMeta() (meta map[string]interface{}) { 57 | meta = map[string]interface{}{ 58 | "hostvars": i.buildMetaHostvars(), 59 | } 60 | return 61 | } 62 | 63 | func (i Inventory) hostsInGroup(group string) (hosts []string) { 64 | for _, host := range i.hosts { 65 | for _, g := range host.Groups { 66 | if g == group { 67 | hosts = append(hosts, host.Host) 68 | } 69 | } 70 | } 71 | return 72 | } 73 | 74 | // MarshalJSON converts this object into the ansible format 75 | func (i Inventory) MarshalJSON() ([]byte, error) { 76 | data := map[string]interface{}{ 77 | "_meta": i.buildMeta(), 78 | } 79 | 80 | for _, group := range i.groups { 81 | hosts := i.hostsInGroup(group.Name) 82 | if len(hosts) == 0 { 83 | continue 84 | } 85 | data[group.Name] = inventoryGroup{ 86 | Hosts: hosts, 87 | Vars: group.Vars, 88 | Children: group.Children, 89 | } 90 | } 91 | return json.Marshal(data) 92 | } 93 | 94 | type inventoryGroup struct { 95 | Hosts []string `json:"hosts"` 96 | Vars map[string]interface{} `json:"vars,omitempty"` 97 | Children []string `json:"children,omitempty"` 98 | } 99 | -------------------------------------------------------------------------------- /pkg/ansible/messages.go: -------------------------------------------------------------------------------- 1 | package ansible 2 | 3 | import ( 4 | "strings" 5 | "sync" 6 | ) 7 | 8 | // MessageLog holds messages during module run 9 | type MessageLog struct { 10 | messages []string 11 | mux sync.Mutex 12 | } 13 | 14 | // Add appends a message to the log 15 | func (l *MessageLog) Add(msg string) { 16 | l.mux.Lock() 17 | defer l.mux.Unlock() 18 | l.messages = append(l.messages, msg) 19 | } 20 | 21 | func (l *MessageLog) String() string { 22 | l.mux.Lock() 23 | defer l.mux.Unlock() 24 | return strings.Join(l.messages, ", ") 25 | } 26 | -------------------------------------------------------------------------------- /pkg/ansible/module.go: -------------------------------------------------------------------------------- 1 | package ansible 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | 9 | "github.com/spf13/pflag" 10 | "github.com/thetechnick/hcloud-ansible/pkg/version" 11 | ) 12 | 13 | // Module interface for Ansible modules 14 | type Module interface { 15 | Args() interface{} 16 | Run() (ModuleResponse, error) 17 | } 18 | 19 | // RunModule executes the module 20 | func RunModule(m Module, flags *pflag.FlagSet) { 21 | var resp ModuleResponse 22 | if err := flags.Parse(os.Args[1:]); err != nil { 23 | resp.Msg(fmt.Sprintf("Error parsing flags: %v", err)). 24 | Failed(). 25 | exitJSON() 26 | } 27 | if v, _ := flags.GetBool("version"); v { 28 | version.PrintText() 29 | } 30 | 31 | if len(os.Args) != 2 { 32 | resp.Msg("No arguments file provided"). 33 | Failed(). 34 | exitJSON() 35 | } 36 | 37 | argsFile := os.Args[1] 38 | argsString, err := ioutil.ReadFile(argsFile) 39 | if err != nil { 40 | resp.Msg(fmt.Sprintf("Cannot read arguments file: %v", err)). 41 | Failed(). 42 | exitJSON() 43 | } 44 | 45 | if err := json.Unmarshal(argsString, m.Args()); err != nil { 46 | resp.Msg(fmt.Sprintf("Cannot parse arguments file: %v", err)). 47 | Failed(). 48 | exitJSON() 49 | } 50 | 51 | if resp, err := m.Run(); err != nil { 52 | resp.Msg(err.Error()). 53 | Failed(). 54 | exitJSON() 55 | } else { 56 | resp.exitJSON() 57 | } 58 | } 59 | 60 | // ModuleResponse represents the reponse of the module 61 | type ModuleResponse struct { 62 | msg string 63 | changed bool 64 | failed bool 65 | data map[string]interface{} 66 | } 67 | 68 | // Msg sets the module message 69 | func (r *ModuleResponse) Msg(msg string) *ModuleResponse { 70 | r.msg = msg 71 | return r 72 | } 73 | 74 | // Changed marks the the module as changed 75 | func (r *ModuleResponse) Changed() *ModuleResponse { 76 | r.changed = true 77 | return r 78 | } 79 | 80 | // Failed marks the module as failed 81 | func (r *ModuleResponse) Failed() *ModuleResponse { 82 | r.failed = true 83 | return r 84 | } 85 | 86 | // Set adds data to the reponse 87 | func (r *ModuleResponse) Set(key string, value interface{}) *ModuleResponse { 88 | if r.data == nil { 89 | r.data = map[string]interface{}{} 90 | } 91 | r.data[key] = value 92 | return r 93 | } 94 | 95 | // Data returns the data of the response 96 | func (r *ModuleResponse) Data() map[string]interface{} { 97 | return r.data 98 | } 99 | 100 | // HasChanged returns true if the module has changed 101 | func (r *ModuleResponse) HasChanged() bool { 102 | return r.changed 103 | } 104 | 105 | // HasFailed returns true if the module has failed 106 | func (r *ModuleResponse) HasFailed() bool { 107 | return r.failed 108 | } 109 | 110 | // MarshalJSON custom json marshalling 111 | func (r *ModuleResponse) MarshalJSON() ([]byte, error) { 112 | data := map[string]interface{}{ 113 | "changed": r.changed, 114 | "failed": r.failed, 115 | "msg": r.msg, 116 | } 117 | 118 | for key, value := range r.data { 119 | data[key] = value 120 | } 121 | return json.Marshal(data) 122 | } 123 | 124 | func (r *ModuleResponse) exitJSON() { 125 | response, _ := json.Marshal(r) 126 | fmt.Println(string(response)) 127 | if r.failed { 128 | os.Exit(1) 129 | } else { 130 | os.Exit(0) 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/action_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/hetznercloud/hcloud-go/hcloud" 7 | "github.com/stretchr/testify/mock" 8 | hcloud_wrapped "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 9 | ) 10 | 11 | // ActionClientMock mocks the hcloud.ActionClient interface 12 | type ActionClientMock struct { 13 | mock.Mock 14 | } 15 | 16 | // NewActionClientMock creates a new ActionClient mock 17 | func NewActionClientMock() hcloud_wrapped.ActionClient { 18 | return &ActionClientMock{} 19 | } 20 | 21 | // GetByID mock 22 | func (m *ActionClientMock) GetByID(ctx context.Context, id int) (*hcloud.Action, *hcloud.Response, error) { 23 | args := m.Called(ctx, id) 24 | return args.Get(0).(*hcloud.Action), args.Get(1).(*hcloud.Response), args.Error(2) 25 | } 26 | 27 | // List mock 28 | func (m *ActionClientMock) List(ctx context.Context, opts hcloud.ActionListOpts) ([]*hcloud.Action, *hcloud.Response, error) { 29 | args := m.Called(ctx, opts) 30 | return args.Get(0).([]*hcloud.Action), args.Get(1).(*hcloud.Response), args.Error(2) 31 | } 32 | 33 | // All mock 34 | func (m *ActionClientMock) All(ctx context.Context) ([]*hcloud.Action, error) { 35 | args := m.Called(ctx) 36 | return args.Get(0).([]*hcloud.Action), args.Error(1) 37 | } 38 | 39 | // WatchProgress mock 40 | func (m *ActionClientMock) WatchProgress(ctx context.Context, action *hcloud.Action) (<-chan int, <-chan error) { 41 | args := m.Called(ctx, action) 42 | return args.Get(0).(<-chan int), args.Get(1).(<-chan error) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/floatingip_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stretchr/testify/mock" 7 | "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 8 | ) 9 | 10 | // FloatingIPClientMock mock of hcloud.FloatingIPClient 11 | type FloatingIPClientMock struct { 12 | mock.Mock 13 | } 14 | 15 | // NewFloatingIPClientMock creates a FloatingIPClientMock 16 | func NewFloatingIPClientMock() hcloud.FloatingIPClient { 17 | return &FloatingIPClientMock{} 18 | } 19 | 20 | // GetByID mock 21 | func (m *FloatingIPClientMock) GetByID(ctx context.Context, id int) (*hcloud.FloatingIP, *hcloud.Response, error) { 22 | args := m.Called(ctx, id) 23 | return args.Get(0).(*hcloud.FloatingIP), args.Get(1).(*hcloud.Response), args.Error(2) 24 | } 25 | 26 | // List mock 27 | func (m *FloatingIPClientMock) List(ctx context.Context, opts hcloud.FloatingIPListOpts) ([]*hcloud.FloatingIP, *hcloud.Response, error) { 28 | args := m.Called(ctx, opts) 29 | return args.Get(0).([]*hcloud.FloatingIP), args.Get(1).(*hcloud.Response), args.Error(2) 30 | } 31 | 32 | // All mock 33 | func (m *FloatingIPClientMock) All(ctx context.Context) ([]*hcloud.FloatingIP, error) { 34 | args := m.Called(ctx) 35 | return args.Get(0).([]*hcloud.FloatingIP), args.Error(1) 36 | } 37 | 38 | // Create mock 39 | func (m *FloatingIPClientMock) Create(ctx context.Context, opts hcloud.FloatingIPCreateOpts) (hcloud.FloatingIPCreateResult, *hcloud.Response, error) { 40 | args := m.Called(ctx, opts) 41 | return args.Get(0).(hcloud.FloatingIPCreateResult), args.Get(1).(*hcloud.Response), args.Error(2) 42 | } 43 | 44 | // Delete mock 45 | func (m *FloatingIPClientMock) Delete(ctx context.Context, floatingIP *hcloud.FloatingIP) (*hcloud.Response, error) { 46 | args := m.Called(ctx, floatingIP) 47 | return args.Get(0).(*hcloud.Response), args.Error(1) 48 | } 49 | 50 | // Assign mock 51 | func (m *FloatingIPClientMock) Assign(ctx context.Context, floatingIP *hcloud.FloatingIP, server *hcloud.Server) (*hcloud.Action, *hcloud.Response, error) { 52 | args := m.Called(ctx, floatingIP, server) 53 | return args.Get(0).(*hcloud.Action), args.Get(1).(*hcloud.Response), args.Error(2) 54 | } 55 | 56 | // Unassign mock 57 | func (m *FloatingIPClientMock) Unassign(ctx context.Context, floatingIP *hcloud.FloatingIP) (*hcloud.Action, *hcloud.Response, error) { 58 | args := m.Called(ctx, floatingIP) 59 | return args.Get(0).(*hcloud.Action), args.Get(1).(*hcloud.Response), args.Error(2) 60 | } 61 | 62 | // Update mock 63 | func (m *FloatingIPClientMock) Update(ctx context.Context, floatingIP *hcloud.FloatingIP, opts hcloud.FloatingIPUpdateOpts) (*hcloud.FloatingIP, *hcloud.Response, error) { 64 | args := m.Called(ctx, floatingIP, opts) 65 | return args.Get(0).(*hcloud.FloatingIP), args.Get(1).(*hcloud.Response), args.Error(2) 66 | } 67 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/image_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stretchr/testify/mock" 7 | "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 8 | ) 9 | 10 | // ImageClientMock mocks the ImageClient interface 11 | type ImageClientMock struct { 12 | mock.Mock 13 | } 14 | 15 | // NewImageClientMock creates a new ImageClientMock 16 | func NewImageClientMock() hcloud.ImageClient { 17 | return &ImageClientMock{} 18 | } 19 | 20 | // GetByID mock 21 | func (m *ImageClientMock) GetByID(ctx context.Context, id int) (*hcloud.Image, *hcloud.Response, error) { 22 | args := m.Called(ctx, id) 23 | return args.Get(0).(*hcloud.Image), args.Get(1).(*hcloud.Response), args.Error(2) 24 | } 25 | 26 | // Get mock 27 | func (m *ImageClientMock) Get(ctx context.Context, idOrName string) (*hcloud.Image, *hcloud.Response, error) { 28 | args := m.Called(ctx, idOrName) 29 | return args.Get(0).(*hcloud.Image), args.Get(1).(*hcloud.Response), args.Error(2) 30 | } 31 | 32 | // GetByName mock 33 | func (m *ImageClientMock) GetByName(ctx context.Context, name string) (*hcloud.Image, *hcloud.Response, error) { 34 | args := m.Called(ctx, name) 35 | return args.Get(0).(*hcloud.Image), args.Get(1).(*hcloud.Response), args.Error(2) 36 | } 37 | 38 | // List mock 39 | func (m *ImageClientMock) List(ctx context.Context, opts hcloud.ImageListOpts) ([]*hcloud.Image, *hcloud.Response, error) { 40 | args := m.Called(ctx, opts) 41 | return args.Get(0).([]*hcloud.Image), args.Get(1).(*hcloud.Response), args.Error(2) 42 | } 43 | 44 | // All mock 45 | func (m *ImageClientMock) All(ctx context.Context) ([]*hcloud.Image, error) { 46 | args := m.Called(ctx) 47 | return args.Get(0).([]*hcloud.Image), args.Error(1) 48 | } 49 | 50 | // Delete mock 51 | func (m *ImageClientMock) Delete(ctx context.Context, image *hcloud.Image) (*hcloud.Response, error) { 52 | args := m.Called(ctx, image) 53 | return args.Get(0).(*hcloud.Response), args.Error(1) 54 | } 55 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/iso_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/hetznercloud/hcloud-go/hcloud" 7 | "github.com/stretchr/testify/mock" 8 | hcloud_wrapped "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 9 | ) 10 | 11 | // ISOClientMock mocks the ISOClient interface 12 | type ISOClientMock struct { 13 | mock.Mock 14 | } 15 | 16 | // NewISOClientMock creates a new ISOClientMock 17 | func NewISOClientMock() hcloud_wrapped.ISOClient { 18 | return &ISOClientMock{} 19 | } 20 | 21 | // GetByID mock 22 | func (m *ISOClientMock) GetByID(ctx context.Context, id int) (*hcloud.ISO, *hcloud.Response, error) { 23 | args := m.Called(ctx, id) 24 | return args.Get(0).(*hcloud.ISO), args.Get(1).(*hcloud.Response), args.Error(2) 25 | } 26 | 27 | // GetByName mock 28 | func (m *ISOClientMock) GetByName(ctx context.Context, name string) (*hcloud.ISO, *hcloud.Response, error) { 29 | args := m.Called(ctx, name) 30 | return args.Get(0).(*hcloud.ISO), args.Get(1).(*hcloud.Response), args.Error(2) 31 | } 32 | 33 | // Get mock 34 | func (m *ISOClientMock) Get(ctx context.Context, idOrName string) (*hcloud.ISO, *hcloud.Response, error) { 35 | args := m.Called(ctx, idOrName) 36 | return args.Get(0).(*hcloud.ISO), args.Get(1).(*hcloud.Response), args.Error(2) 37 | } 38 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/server_type_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/stretchr/testify/mock" 7 | "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 8 | ) 9 | 10 | // ServerTypeClientMock mocks the ServerTypeClient interface 11 | type ServerTypeClientMock struct { 12 | mock.Mock 13 | } 14 | 15 | // NewServerTypeClientMock creates a new ServerTypeClientMock 16 | func NewServerTypeClientMock() hcloud.ServerTypeClient { 17 | return &ServerTypeClientMock{} 18 | } 19 | 20 | // GetByID mock 21 | func (m *ServerTypeClientMock) GetByID(ctx context.Context, id int) (*hcloud.ServerType, *hcloud.Response, error) { 22 | args := m.Called(ctx, id) 23 | return args.Get(0).(*hcloud.ServerType), args.Get(1).(*hcloud.Response), args.Error(2) 24 | } 25 | 26 | // Get mock 27 | func (m *ServerTypeClientMock) Get(ctx context.Context, idOrName string) (*hcloud.ServerType, *hcloud.Response, error) { 28 | args := m.Called(ctx, idOrName) 29 | return args.Get(0).(*hcloud.ServerType), args.Get(1).(*hcloud.Response), args.Error(2) 30 | } 31 | 32 | // GetByName mock 33 | func (m *ServerTypeClientMock) GetByName(ctx context.Context, name string) (*hcloud.ServerType, *hcloud.Response, error) { 34 | args := m.Called(ctx, name) 35 | return args.Get(0).(*hcloud.ServerType), args.Get(1).(*hcloud.Response), args.Error(2) 36 | } 37 | 38 | // List mock 39 | func (m *ServerTypeClientMock) List(ctx context.Context, opts hcloud.ServerTypeListOpts) ([]*hcloud.ServerType, *hcloud.Response, error) { 40 | args := m.Called(ctx, opts) 41 | return args.Get(0).([]*hcloud.ServerType), args.Get(1).(*hcloud.Response), args.Error(2) 42 | } 43 | 44 | // All mock 45 | func (m *ServerTypeClientMock) All(ctx context.Context) ([]*hcloud.ServerType, error) { 46 | args := m.Called(ctx) 47 | return args.Get(0).([]*hcloud.ServerType), args.Error(1) 48 | } 49 | -------------------------------------------------------------------------------- /pkg/hcloud/hcloudtest/sshkey_client.go: -------------------------------------------------------------------------------- 1 | package hcloudtest 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/hetznercloud/hcloud-go/hcloud" 7 | "github.com/stretchr/testify/mock" 8 | hcloud_wrapped "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 9 | ) 10 | 11 | // SSHKeyClientMock mocks the hcloud.SSHKeyClient interface 12 | type SSHKeyClientMock struct { 13 | mock.Mock 14 | } 15 | 16 | // NewSSHClientMock creates a new SSHKeyClientMock 17 | func NewSSHClientMock() hcloud_wrapped.SSHKeyClient { 18 | return &SSHKeyClientMock{} 19 | } 20 | 21 | // GetByID mock 22 | func (m *SSHKeyClientMock) GetByID(ctx context.Context, id int) (*hcloud.SSHKey, *hcloud.Response, error) { 23 | args := m.Called(ctx, id) 24 | return args.Get(0).(*hcloud.SSHKey), args.Get(1).(*hcloud.Response), args.Error(2) 25 | } 26 | 27 | // GetByName mock 28 | func (m *SSHKeyClientMock) GetByName(ctx context.Context, name string) (*hcloud.SSHKey, *hcloud.Response, error) { 29 | args := m.Called(ctx, name) 30 | return args.Get(0).(*hcloud.SSHKey), args.Get(1).(*hcloud.Response), args.Error(2) 31 | } 32 | 33 | // Get mock 34 | func (m *SSHKeyClientMock) Get(ctx context.Context, idOrName string) (*hcloud.SSHKey, *hcloud.Response, error) { 35 | args := m.Called(ctx, idOrName) 36 | return args.Get(0).(*hcloud.SSHKey), args.Get(1).(*hcloud.Response), args.Error(2) 37 | } 38 | 39 | // All mock 40 | func (m *SSHKeyClientMock) All(ctx context.Context) ([]*hcloud.SSHKey, error) { 41 | args := m.Called(ctx) 42 | return args.Get(0).([]*hcloud.SSHKey), args.Error(1) 43 | } 44 | 45 | // Create mock 46 | func (m *SSHKeyClientMock) Create(ctx context.Context, opts hcloud.SSHKeyCreateOpts) (*hcloud.SSHKey, *hcloud.Response, error) { 47 | args := m.Called(ctx, opts) 48 | return args.Get(0).(*hcloud.SSHKey), args.Get(1).(*hcloud.Response), args.Error(2) 49 | } 50 | 51 | // Delete mock 52 | func (m *SSHKeyClientMock) Delete(ctx context.Context, sshKey *hcloud.SSHKey) (*hcloud.Response, error) { 53 | args := m.Called(ctx, sshKey) 54 | return args.Get(0).(*hcloud.Response), args.Error(1) 55 | } 56 | 57 | // Update mock 58 | func (m *SSHKeyClientMock) Update(ctx context.Context, sshKey *hcloud.SSHKey, opts hcloud.SSHKeyUpdateOpts) (*hcloud.SSHKey, *hcloud.Response, error) { 59 | args := m.Called(ctx, sshKey, opts) 60 | return args.Get(0).(*hcloud.SSHKey), args.Get(1).(*hcloud.Response), args.Error(2) 61 | } 62 | -------------------------------------------------------------------------------- /pkg/util/id.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | // GetIdentifiers returns a list of strings for client.Get methods 8 | func GetIdentifiers(value interface{}) (ids []string) { 9 | if s, ok := value.([]interface{}); ok { 10 | for _, v := range s { 11 | n := GetIdentifier(v) 12 | if n != "" { 13 | ids = append(ids, n) 14 | } 15 | } 16 | } else { 17 | n := GetIdentifier(value) 18 | if n != "" { 19 | ids = append(ids, n) 20 | } 21 | } 22 | return 23 | } 24 | 25 | // GetIdentifier parses the input to get a resource identifier for client.Get 26 | func GetIdentifier(value interface{}) (id string) { 27 | switch v := value.(type) { 28 | case string: 29 | return v 30 | case float64: 31 | return strconv.Itoa(int(v)) 32 | case map[string]interface{}: 33 | if id, ok := v["id"]; ok { 34 | return GetIdentifier(id) 35 | } 36 | if name, ok := v["name"]; ok { 37 | return GetIdentifier(name) 38 | } 39 | } 40 | return 41 | } 42 | 43 | // GetIDs parses the input to get resource ids 44 | func GetIDs(value interface{}) (ids []int) { 45 | if i, ok := value.([]interface{}); ok { 46 | for _, v := range i { 47 | id := GetID(v) 48 | if id != 0 { 49 | ids = append(ids, id) 50 | } 51 | } 52 | } else { 53 | id := GetID(value) 54 | if id != 0 { 55 | ids = append(ids, id) 56 | } 57 | } 58 | return 59 | } 60 | 61 | // GetID parses the input to get a resource id 62 | func GetID(value interface{}) (id int) { 63 | switch v := value.(type) { 64 | case float64: 65 | return int(v) 66 | case int: 67 | return v 68 | case string: 69 | id, _ = strconv.Atoi(v) 70 | return 71 | case map[string]interface{}: 72 | if id, ok := v["id"]; ok { 73 | return GetID(id) 74 | } 75 | } 76 | return 0 77 | } 78 | 79 | // GetNames parses the input to get resource names 80 | func GetNames(value interface{}) (names []string) { 81 | if s, ok := value.([]interface{}); ok { 82 | for _, v := range s { 83 | n := GetName(v) 84 | if n != "" { 85 | names = append(names, n) 86 | } 87 | } 88 | } else { 89 | n := GetName(value) 90 | if n != "" { 91 | names = append(names, n) 92 | } 93 | } 94 | return 95 | } 96 | 97 | // GetName parses the input to get a resource name 98 | func GetName(value interface{}) (name string) { 99 | switch v := value.(type) { 100 | case string: 101 | return v 102 | case float64: 103 | return strconv.Itoa(int(v)) 104 | case map[string]interface{}: 105 | if name, ok := v["name"]; ok { 106 | return GetName(name) 107 | } 108 | } 109 | return 110 | } 111 | -------------------------------------------------------------------------------- /pkg/util/id_test.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "encoding/json" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGetIdentifiers(t *testing.T) { 11 | t.Run("[]string", func(t *testing.T) { 12 | var value interface{} 13 | json.Unmarshal([]byte(`["test1", "test2"]`), &value) 14 | 15 | names := GetIdentifiers(value) 16 | assert.Equal(t, []string{"test1", "test2"}, names) 17 | }) 18 | t.Run("string", func(t *testing.T) { 19 | var value interface{} 20 | json.Unmarshal([]byte(`"test1"`), &value) 21 | 22 | names := GetIdentifiers(value) 23 | assert.Equal(t, []string{"test1"}, names) 24 | }) 25 | } 26 | 27 | func TestGetIdentifier(t *testing.T) { 28 | t.Run("string", func(t *testing.T) { 29 | var value interface{} 30 | json.Unmarshal([]byte(`"test"`), &value) 31 | 32 | name := GetIdentifier(value) 33 | assert.Equal(t, "test", name) 34 | }) 35 | t.Run("int", func(t *testing.T) { 36 | var value interface{} 37 | json.Unmarshal([]byte(`1`), &value) 38 | 39 | name := GetIdentifier(value) 40 | assert.Equal(t, "1", name) 41 | }) 42 | t.Run("object id", func(t *testing.T) { 43 | var value interface{} 44 | json.Unmarshal([]byte(`{"id":123}`), &value) 45 | 46 | id := GetIdentifier(value) 47 | assert.Equal(t, "123", id) 48 | }) 49 | t.Run("object name", func(t *testing.T) { 50 | var value interface{} 51 | json.Unmarshal([]byte(`{"name":"test"}`), &value) 52 | 53 | id := GetIdentifier(value) 54 | assert.Equal(t, "test", id) 55 | }) 56 | } 57 | 58 | func TestGetNames(t *testing.T) { 59 | t.Run("[]string", func(t *testing.T) { 60 | var value interface{} 61 | json.Unmarshal([]byte(`["test1", "test2"]`), &value) 62 | 63 | names := GetNames(value) 64 | assert.Equal(t, []string{"test1", "test2"}, names) 65 | }) 66 | t.Run("string", func(t *testing.T) { 67 | var value interface{} 68 | json.Unmarshal([]byte(`"test1"`), &value) 69 | 70 | names := GetNames(value) 71 | assert.Equal(t, []string{"test1"}, names) 72 | }) 73 | } 74 | 75 | func TestGetName(t *testing.T) { 76 | t.Run("string", func(t *testing.T) { 77 | var value interface{} 78 | json.Unmarshal([]byte(`"test"`), &value) 79 | 80 | name := GetName(value) 81 | assert.Equal(t, "test", name) 82 | }) 83 | t.Run("int", func(t *testing.T) { 84 | var value interface{} 85 | json.Unmarshal([]byte(`1`), &value) 86 | 87 | name := GetName(value) 88 | assert.Equal(t, "1", name) 89 | }) 90 | t.Run("object name", func(t *testing.T) { 91 | var value interface{} 92 | json.Unmarshal([]byte(`{"name":"test"}`), &value) 93 | 94 | id := GetName(value) 95 | assert.Equal(t, "test", id) 96 | }) 97 | } 98 | 99 | func TestGetIDs(t *testing.T) { 100 | t.Run("[]int", func(t *testing.T) { 101 | var value interface{} 102 | json.Unmarshal([]byte(`[2, 5]`), &value) 103 | 104 | names := GetIDs(value) 105 | assert.Equal(t, []int{2, 5}, names) 106 | }) 107 | t.Run("string", func(t *testing.T) { 108 | var value interface{} 109 | json.Unmarshal([]byte(`"5"`), &value) 110 | 111 | names := GetIDs(value) 112 | assert.Equal(t, []int{5}, names) 113 | }) 114 | t.Run("int", func(t *testing.T) { 115 | var value interface{} 116 | json.Unmarshal([]byte(`5`), &value) 117 | 118 | names := GetIDs(value) 119 | assert.Equal(t, []int{5}, names) 120 | }) 121 | } 122 | 123 | func TestGetID(t *testing.T) { 124 | t.Run("number", func(t *testing.T) { 125 | var value interface{} 126 | json.Unmarshal([]byte("123"), &value) 127 | 128 | id := GetID(value) 129 | assert.Equal(t, 123, id) 130 | }) 131 | 132 | t.Run("null", func(t *testing.T) { 133 | var value interface{} 134 | json.Unmarshal([]byte("null"), &value) 135 | 136 | id := GetID(value) 137 | assert.Equal(t, 0, id) 138 | }) 139 | 140 | t.Run("int", func(t *testing.T) { 141 | id := GetID(interface{}(123)) 142 | assert.Equal(t, 123, id) 143 | }) 144 | 145 | t.Run("object id", func(t *testing.T) { 146 | var value interface{} 147 | json.Unmarshal([]byte(`{"id":123, "name":"test"}`), &value) 148 | 149 | id := GetID(value) 150 | assert.Equal(t, 123, id) 151 | }) 152 | } 153 | -------------------------------------------------------------------------------- /pkg/util/watch.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "context" 5 | "sync" 6 | 7 | "github.com/thetechnick/hcloud-ansible/pkg/hcloud" 8 | ) 9 | 10 | // WaitFn waits for the competion of an action 11 | type WaitFn func(ctx context.Context, client *hcloud.Client, action *hcloud.Action) error 12 | 13 | var actionWaitLock sync.Mutex 14 | 15 | // WaitForAction makes sure we only watch one action at a time 16 | func WaitForAction(ctx context.Context, client *hcloud.Client, action *hcloud.Action) error { 17 | actionWaitLock.Lock() 18 | defer actionWaitLock.Unlock() 19 | _, errCh := client.Action.WatchProgress(ctx, action) 20 | return <-errCh 21 | } 22 | -------------------------------------------------------------------------------- /pkg/version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "runtime" 7 | "strconv" 8 | "time" 9 | ) 10 | 11 | // Version provided by compile time -ldflags. 12 | var ( 13 | defaultContent = "was not build properly" 14 | VersionTag = defaultContent 15 | Branch = defaultContent 16 | BuildDate = defaultContent 17 | ) 18 | 19 | // Version holds information about the build 20 | type Version struct { 21 | Version, Branch, GoVersion, Platform string 22 | BuildDate time.Time 23 | } 24 | 25 | // Get returns the version information 26 | func Get() Version { 27 | v := Version{ 28 | Version: VersionTag, 29 | Branch: Branch, 30 | GoVersion: runtime.Version(), 31 | Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH), 32 | } 33 | 34 | i, err := strconv.ParseInt(BuildDate, 10, 64) 35 | if err != nil { 36 | panic(fmt.Errorf("Error parsing build time: %v", err)) 37 | } 38 | v.BuildDate = time.Unix(i, 0).UTC() 39 | return v 40 | } 41 | 42 | // PrintText prints the version informations to stdout 43 | func PrintText() { 44 | v := Get() 45 | fmt.Printf("Version:\t%s\n", v.Version) 46 | fmt.Printf("BuildDate:\t%s\n", v.BuildDate.Local().Format(time.UnixDate)) 47 | fmt.Printf("Branch:\t\t%s\n", v.Branch) 48 | fmt.Printf("Go Version:\t%s\n", v.GoVersion) 49 | fmt.Printf("Platform:\t%s\n", v.Platform) 50 | os.Exit(0) 51 | } 52 | -------------------------------------------------------------------------------- /pkg/version/version_test.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | 7 | "github.com/stretchr/testify/assert" 8 | ) 9 | 10 | func TestGet(t *testing.T) { 11 | VersionTag = "1.2.3" 12 | Branch = "test" 13 | BuildDate = "1512490612" 14 | 15 | assert := assert.New(t) 16 | v := Get() 17 | 18 | assert.Equal(VersionTag, v.Version) 19 | assert.Equal(Branch, v.Branch) 20 | assert.Equal(BuildDate, fmt.Sprint(v.BuildDate.Unix())) 21 | } 22 | -------------------------------------------------------------------------------- /scripts/git-version: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | 5 | # parse the current git commit hash 6 | COMMIT=`git rev-parse HEAD` 7 | 8 | # check if the current commit has a matching tag 9 | TAG=$(git describe --exact-match --abbrev=0 --tags ${COMMIT} 2> /dev/null || true) 10 | SUFFIX='' 11 | DETAIL='' 12 | 13 | # use the matching tag as the version, if available 14 | if [ -z "$TAG" ]; then 15 | TAG=$(git describe --abbrev=0) 16 | COMMITS=$(git --no-pager log ${TAG}..HEAD --oneline) 17 | COMMIT_COUNT=$(echo -e "${COMMITS}" | wc -l) 18 | COMMIT_COUNT_PADDING=$(printf %03d $COMMIT_COUNT) 19 | SHORT_COMMIT_ID=$(git rev-parse --short HEAD) 20 | 21 | SUFFIX='-dev' 22 | DETAIL=".${COMMIT_COUNT_PADDING}.${SHORT_COMMIT_ID}" 23 | fi 24 | 25 | if [ -n "$(git diff --shortstat 2> /dev/null | tail -n1)" ]; then 26 | SUFFIX="-dirty" 27 | fi 28 | 29 | 30 | VERSION="${TAG}${SUFFIX}${DETAIL}" 31 | echo $VERSION 32 | -------------------------------------------------------------------------------- /scripts/test: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -eu 4 | 5 | diff -u <(echo -n) <(gofmt -d -s $(find . -type f -name '*.go' | grep -v ^./vendor)) 6 | go vet ./... 7 | go test ./... 8 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | # E2E tests 2 | --- 3 | 4 | # 5 | - hosts: localhost 6 | connection: local 7 | gather_facts: false 8 | tasks: 9 | # 10 | # SSH Key 11 | # 12 | 13 | # create an ssh key 14 | - hcloud_ssh_key: 15 | name: user@example-notebook 16 | public_key: "{{lookup('file', '~/.ssh/id_rsa.pub')}}" 17 | 18 | # 19 | # Server docs 20 | # 21 | # create tree servers at once 22 | - hcloud_server: 23 | name: 24 | - example-server01 25 | - example-server02 26 | - example-server03 27 | image: debian-9 28 | server_type: cx11 29 | location: nbg1 30 | ssh_keys: 31 | - user@example-notebook # by name 32 | 33 | # ensure server is running (if the server already exists) 34 | - hcloud_server: 35 | name: example-server01 36 | state: running 37 | 38 | # mount iso on server 39 | - hcloud_server: 40 | name: example-server01 41 | iso: ubuntu-17.10.1-server-amd64.iso 42 | 43 | - hcloud_server: 44 | state: list 45 | register: hcloud_servers 46 | 47 | - debug: 48 | var: hcloud_servers 49 | 50 | - hcloud_server: 51 | id: "{{ hcloud_servers.servers }}" 52 | state: absent 53 | 54 | - hcloud_server: 55 | name: 56 | - non-existent 57 | state: absent 58 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Hetzner Cloud GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/datacenter.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | "github.com/hetznercloud/hcloud-go/hcloud/schema" 10 | ) 11 | 12 | // Datacenter represents a datacenter in the Hetzner Cloud. 13 | type Datacenter struct { 14 | ID int 15 | Name string 16 | Description string 17 | Location *Location 18 | ServerTypes DatacenterServerTypes 19 | } 20 | 21 | // DatacenterServerTypes represents the server types available and supported in a datacenter. 22 | type DatacenterServerTypes struct { 23 | Supported []*ServerType 24 | Available []*ServerType 25 | } 26 | 27 | // DatacenterClient is a client for the datacenter API. 28 | type DatacenterClient struct { 29 | client *Client 30 | } 31 | 32 | // GetByID retrieves a datacenter by its ID. 33 | func (c *DatacenterClient) GetByID(ctx context.Context, id int) (*Datacenter, *Response, error) { 34 | req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/datacenters/%d", id), nil) 35 | if err != nil { 36 | return nil, nil, err 37 | } 38 | 39 | var body schema.DatacenterGetResponse 40 | resp, err := c.client.Do(req, &body) 41 | if err != nil { 42 | if IsError(err, ErrorCodeNotFound) { 43 | return nil, resp, nil 44 | } 45 | return nil, resp, err 46 | } 47 | return DatacenterFromSchema(body.Datacenter), resp, nil 48 | } 49 | 50 | // GetByName retrieves an datacenter by its name. 51 | func (c *DatacenterClient) GetByName(ctx context.Context, name string) (*Datacenter, *Response, error) { 52 | path := "/datacenters?name=" + url.QueryEscape(name) 53 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 54 | if err != nil { 55 | return nil, nil, err 56 | } 57 | 58 | var body schema.DatacenterListResponse 59 | resp, err := c.client.Do(req, &body) 60 | if err != nil { 61 | return nil, nil, err 62 | } 63 | 64 | if len(body.Datacenters) == 0 { 65 | return nil, resp, nil 66 | } 67 | return DatacenterFromSchema(body.Datacenters[0]), resp, nil 68 | } 69 | 70 | // Get retrieves a datacenter by its ID if the input can be parsed as an integer, otherwise it retrieves a datacenter by its name. 71 | func (c *DatacenterClient) Get(ctx context.Context, idOrName string) (*Datacenter, *Response, error) { 72 | if id, err := strconv.Atoi(idOrName); err == nil { 73 | return c.GetByID(ctx, int(id)) 74 | } 75 | return c.GetByName(ctx, idOrName) 76 | } 77 | 78 | // DatacenterListOpts specifies options for listing datacenters. 79 | type DatacenterListOpts struct { 80 | ListOpts 81 | } 82 | 83 | // List returns a list of datacenters for a specific page. 84 | func (c *DatacenterClient) List(ctx context.Context, opts DatacenterListOpts) ([]*Datacenter, *Response, error) { 85 | path := "/datacenters?" + valuesForListOpts(opts.ListOpts).Encode() 86 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 87 | if err != nil { 88 | return nil, nil, err 89 | } 90 | 91 | var body schema.DatacenterListResponse 92 | resp, err := c.client.Do(req, &body) 93 | if err != nil { 94 | return nil, nil, err 95 | } 96 | datacenters := make([]*Datacenter, 0, len(body.Datacenters)) 97 | for _, i := range body.Datacenters { 98 | datacenters = append(datacenters, DatacenterFromSchema(i)) 99 | } 100 | return datacenters, resp, nil 101 | } 102 | 103 | // All returns all datacenters. 104 | func (c *DatacenterClient) All(ctx context.Context) ([]*Datacenter, error) { 105 | allDatacenters := []*Datacenter{} 106 | 107 | opts := DatacenterListOpts{} 108 | opts.PerPage = 50 109 | 110 | _, err := c.client.all(func(page int) (*Response, error) { 111 | opts.Page = page 112 | datacenters, resp, err := c.List(ctx, opts) 113 | if err != nil { 114 | return resp, err 115 | } 116 | allDatacenters = append(allDatacenters, datacenters...) 117 | return resp, nil 118 | }) 119 | if err != nil { 120 | return nil, err 121 | } 122 | 123 | return allDatacenters, nil 124 | } 125 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/error.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import "fmt" 4 | 5 | // ErrorCode represents an error code returned from the API. 6 | type ErrorCode string 7 | 8 | // Error codes returned from the API. 9 | const ( 10 | ErrorCodeServiceError ErrorCode = "service_error" // Generic server error 11 | ErrorCodeRateLimitExceeded ErrorCode = "rate_limit_exceeded" // Rate limit exceeded 12 | ErrorCodeUnknownError ErrorCode = "unknown_error" // Unknown error 13 | ErrorCodeNotFound ErrorCode = "not_found" // Resource not found 14 | ErrorCodeInvalidInput ErrorCode = "invalid_input" // Validation error 15 | 16 | // Deprecated error codes 17 | 18 | // The actual value of this error code is limit_reached. The new error code 19 | // rate_limit_exceeded for ratelimiting was introduced before Hetzner Cloud 20 | // launched into the public. To make clients using the old error code still 21 | // work as expected, we set the value of the old error code to that of the 22 | // new error code. 23 | ErrorCodeLimitReached = ErrorCodeRateLimitExceeded 24 | ) 25 | 26 | // Error is an error returned from the API. 27 | type Error struct { 28 | Code ErrorCode 29 | Message string 30 | Details interface{} 31 | } 32 | 33 | func (e Error) Error() string { 34 | return fmt.Sprintf("%s (%s)", e.Message, e.Code) 35 | } 36 | 37 | // ErrorDetailsInvalidInput contains the details of an 'invalid_input' error. 38 | type ErrorDetailsInvalidInput struct { 39 | Fields []ErrorDetailsInvalidInputField 40 | } 41 | 42 | // ErrorDetailsInvalidInputField contains the validation errors reported on a field. 43 | type ErrorDetailsInvalidInputField struct { 44 | Name string 45 | Messages []string 46 | } 47 | 48 | // IsError returns whether err is an API error with the given error code. 49 | func IsError(err error, code ErrorCode) bool { 50 | apiErr, ok := err.(Error) 51 | return ok && apiErr.Code == code 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/hcloud.go: -------------------------------------------------------------------------------- 1 | // Package hcloud is a library for the Hetzner Cloud API. 2 | package hcloud 3 | 4 | // Version is the library's version following Semantic Versioning. 5 | const Version = "1.7.0" 6 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/helper.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | // String returns a pointer to the passed string s. 4 | func String(s string) *string { return &s } 5 | 6 | // Int returns a pointer to the passed integer i. 7 | func Int(i int) *int { return &i } 8 | 9 | // Bool returns a pointer to the passed bool b. 10 | func Bool(b bool) *bool { return &b } 11 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/iso.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | "time" 9 | 10 | "github.com/hetznercloud/hcloud-go/hcloud/schema" 11 | ) 12 | 13 | // ISO represents an ISO image in the Hetzner Cloud. 14 | type ISO struct { 15 | ID int 16 | Name string 17 | Description string 18 | Type ISOType 19 | Deprecated time.Time 20 | } 21 | 22 | // IsDeprecated returns true if the ISO is deprecated 23 | func (iso *ISO) IsDeprecated() bool { 24 | return !iso.Deprecated.IsZero() 25 | } 26 | 27 | // ISOType specifies the type of an ISO image. 28 | type ISOType string 29 | 30 | const ( 31 | // ISOTypePublic is the type of a public ISO image. 32 | ISOTypePublic ISOType = "public" 33 | 34 | // ISOTypePrivate is the type of a private ISO image. 35 | ISOTypePrivate ISOType = "private" 36 | ) 37 | 38 | // ISOClient is a client for the ISO API. 39 | type ISOClient struct { 40 | client *Client 41 | } 42 | 43 | // GetByID retrieves an ISO by its ID. 44 | func (c *ISOClient) GetByID(ctx context.Context, id int) (*ISO, *Response, error) { 45 | req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/isos/%d", id), nil) 46 | if err != nil { 47 | return nil, nil, err 48 | } 49 | 50 | var body schema.ISOGetResponse 51 | resp, err := c.client.Do(req, &body) 52 | if err != nil { 53 | if IsError(err, ErrorCodeNotFound) { 54 | return nil, resp, nil 55 | } 56 | return nil, resp, err 57 | } 58 | return ISOFromSchema(body.ISO), resp, nil 59 | } 60 | 61 | // GetByName retrieves an ISO by its name. 62 | func (c *ISOClient) GetByName(ctx context.Context, name string) (*ISO, *Response, error) { 63 | path := "/isos?name=" + url.QueryEscape(name) 64 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 65 | if err != nil { 66 | return nil, nil, err 67 | } 68 | 69 | var body schema.ISOListResponse 70 | resp, err := c.client.Do(req, &body) 71 | if err != nil { 72 | return nil, nil, err 73 | } 74 | 75 | if len(body.ISOs) == 0 { 76 | return nil, resp, nil 77 | } 78 | return ISOFromSchema(body.ISOs[0]), resp, nil 79 | } 80 | 81 | // Get retrieves an ISO by its ID if the input can be parsed as an integer, otherwise it retrieves an ISO by its name. 82 | func (c *ISOClient) Get(ctx context.Context, idOrName string) (*ISO, *Response, error) { 83 | if id, err := strconv.Atoi(idOrName); err == nil { 84 | return c.GetByID(ctx, int(id)) 85 | } 86 | return c.GetByName(ctx, idOrName) 87 | } 88 | 89 | // ISOListOpts specifies options for listing isos. 90 | type ISOListOpts struct { 91 | ListOpts 92 | } 93 | 94 | // List returns a list of ISOs for a specific page. 95 | func (c *ISOClient) List(ctx context.Context, opts ISOListOpts) ([]*ISO, *Response, error) { 96 | path := "/isos?" + valuesForListOpts(opts.ListOpts).Encode() 97 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 98 | if err != nil { 99 | return nil, nil, err 100 | } 101 | 102 | var body schema.ISOListResponse 103 | resp, err := c.client.Do(req, &body) 104 | if err != nil { 105 | return nil, nil, err 106 | } 107 | isos := make([]*ISO, 0, len(body.ISOs)) 108 | for _, i := range body.ISOs { 109 | isos = append(isos, ISOFromSchema(i)) 110 | } 111 | return isos, resp, nil 112 | } 113 | 114 | // All returns all ISOs. 115 | func (c *ISOClient) All(ctx context.Context) ([]*ISO, error) { 116 | allISOs := []*ISO{} 117 | 118 | opts := ISOListOpts{} 119 | opts.PerPage = 50 120 | 121 | _, err := c.client.all(func(page int) (*Response, error) { 122 | opts.Page = page 123 | isos, resp, err := c.List(ctx, opts) 124 | if err != nil { 125 | return resp, err 126 | } 127 | allISOs = append(allISOs, isos...) 128 | return resp, nil 129 | }) 130 | if err != nil { 131 | return nil, err 132 | } 133 | 134 | return allISOs, nil 135 | } 136 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/location.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | "github.com/hetznercloud/hcloud-go/hcloud/schema" 10 | ) 11 | 12 | // Location represents a location in the Hetzner Cloud. 13 | type Location struct { 14 | ID int 15 | Name string 16 | Description string 17 | Country string 18 | City string 19 | Latitude float64 20 | Longitude float64 21 | } 22 | 23 | // LocationClient is a client for the location API. 24 | type LocationClient struct { 25 | client *Client 26 | } 27 | 28 | // GetByID retrieves a location by its ID. 29 | func (c *LocationClient) GetByID(ctx context.Context, id int) (*Location, *Response, error) { 30 | req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/locations/%d", id), nil) 31 | if err != nil { 32 | return nil, nil, err 33 | } 34 | 35 | var body schema.LocationGetResponse 36 | resp, err := c.client.Do(req, &body) 37 | if err != nil { 38 | if IsError(err, ErrorCodeNotFound) { 39 | return nil, resp, nil 40 | } 41 | return nil, resp, err 42 | } 43 | return LocationFromSchema(body.Location), resp, nil 44 | } 45 | 46 | // GetByName retrieves an location by its name. 47 | func (c *LocationClient) GetByName(ctx context.Context, name string) (*Location, *Response, error) { 48 | path := "/locations?name=" + url.QueryEscape(name) 49 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 50 | if err != nil { 51 | return nil, nil, err 52 | } 53 | 54 | var body schema.LocationListResponse 55 | resp, err := c.client.Do(req, &body) 56 | if err != nil { 57 | return nil, nil, err 58 | } 59 | 60 | if len(body.Locations) == 0 { 61 | return nil, resp, nil 62 | } 63 | return LocationFromSchema(body.Locations[0]), resp, nil 64 | } 65 | 66 | // Get retrieves a location by its ID if the input can be parsed as an integer, otherwise it retrieves a location by its name. 67 | func (c *LocationClient) Get(ctx context.Context, idOrName string) (*Location, *Response, error) { 68 | if id, err := strconv.Atoi(idOrName); err == nil { 69 | return c.GetByID(ctx, int(id)) 70 | } 71 | return c.GetByName(ctx, idOrName) 72 | } 73 | 74 | // LocationListOpts specifies options for listing location. 75 | type LocationListOpts struct { 76 | ListOpts 77 | } 78 | 79 | // List returns a list of locations for a specific page. 80 | func (c *LocationClient) List(ctx context.Context, opts LocationListOpts) ([]*Location, *Response, error) { 81 | path := "/locations?" + valuesForListOpts(opts.ListOpts).Encode() 82 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 83 | if err != nil { 84 | return nil, nil, err 85 | } 86 | 87 | var body schema.LocationListResponse 88 | resp, err := c.client.Do(req, &body) 89 | if err != nil { 90 | return nil, nil, err 91 | } 92 | locations := make([]*Location, 0, len(body.Locations)) 93 | for _, i := range body.Locations { 94 | locations = append(locations, LocationFromSchema(i)) 95 | } 96 | return locations, resp, nil 97 | } 98 | 99 | // All returns all locations. 100 | func (c *LocationClient) All(ctx context.Context) ([]*Location, error) { 101 | allLocations := []*Location{} 102 | 103 | opts := LocationListOpts{} 104 | opts.PerPage = 50 105 | 106 | _, err := c.client.all(func(page int) (*Response, error) { 107 | opts.Page = page 108 | locations, resp, err := c.List(ctx, opts) 109 | if err != nil { 110 | return resp, err 111 | } 112 | allLocations = append(allLocations, locations...) 113 | return resp, nil 114 | }) 115 | if err != nil { 116 | return nil, err 117 | } 118 | 119 | return allLocations, nil 120 | } 121 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/pricing.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/hetznercloud/hcloud-go/hcloud/schema" 7 | ) 8 | 9 | // Pricing specifies pricing information for various resources. 10 | type Pricing struct { 11 | Image ImagePricing 12 | FloatingIP FloatingIPPricing 13 | Traffic TrafficPricing 14 | ServerBackup ServerBackupPricing 15 | ServerTypes []ServerTypePricing 16 | } 17 | 18 | // Price represents a price. Net amount, gross amount, as well as VAT rate are 19 | // specified as strings and it is the user's responsibility to convert them to 20 | // appropriate types for calculations. 21 | type Price struct { 22 | Currency string 23 | VATRate string 24 | Net string 25 | Gross string 26 | } 27 | 28 | // ImagePricing provides pricing information for imaegs. 29 | type ImagePricing struct { 30 | PerGBMonth Price 31 | } 32 | 33 | // FloatingIPPricing provides pricing information for Floating IPs. 34 | type FloatingIPPricing struct { 35 | Monthly Price 36 | } 37 | 38 | // TrafficPricing provides pricing information for traffic. 39 | type TrafficPricing struct { 40 | PerTB Price 41 | } 42 | 43 | // ServerBackupPricing provides pricing information for server backups. 44 | type ServerBackupPricing struct { 45 | Percentage string 46 | } 47 | 48 | // ServerTypePricing provides pricing information for a server type. 49 | type ServerTypePricing struct { 50 | ServerType *ServerType 51 | Pricings []ServerTypeLocationPricing 52 | } 53 | 54 | // ServerTypeLocationPricing provides pricing information for a server type 55 | // at a location. 56 | type ServerTypeLocationPricing struct { 57 | Location *Location 58 | Hourly Price 59 | Monthly Price 60 | } 61 | 62 | // PricingClient is a client for the pricing API. 63 | type PricingClient struct { 64 | client *Client 65 | } 66 | 67 | // Get retrieves pricing information. 68 | func (c *PricingClient) Get(ctx context.Context) (Pricing, *Response, error) { 69 | req, err := c.client.NewRequest(ctx, "GET", "/pricing", nil) 70 | if err != nil { 71 | return Pricing{}, nil, err 72 | } 73 | 74 | var body schema.PricingGetResponse 75 | resp, err := c.client.Do(req, &body) 76 | if err != nil { 77 | return Pricing{}, nil, err 78 | } 79 | return PricingFromSchema(body.Pricing), resp, nil 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/action.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import "time" 4 | 5 | // Action defines the schema of an action. 6 | type Action struct { 7 | ID int `json:"id"` 8 | Status string `json:"status"` 9 | Command string `json:"command"` 10 | Progress int `json:"progress"` 11 | Started time.Time `json:"started"` 12 | Finished *time.Time `json:"finished"` 13 | Error *ActionError `json:"error"` 14 | Resources []ActionResourceReference `json:"resources"` 15 | } 16 | 17 | // ActionResourceReference defines the schema of an action resource reference. 18 | type ActionResourceReference struct { 19 | ID int `json:"id"` 20 | Type string `json:"type"` 21 | } 22 | 23 | // ActionError defines the schema of an error embedded 24 | // in an action. 25 | type ActionError struct { 26 | Code string `json:"code"` 27 | Message string `json:"message"` 28 | } 29 | 30 | // ActionGetResponse is the schema of the response when 31 | // retrieving a single action. 32 | type ActionGetResponse struct { 33 | Action Action `json:"action"` 34 | } 35 | 36 | // ActionListResponse defines the schema of the response when listing actions. 37 | type ActionListResponse struct { 38 | Actions []Action `json:"actions"` 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/datacenter.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // Datacenter defines the schema of a datacenter. 4 | type Datacenter struct { 5 | ID int `json:"id"` 6 | Name string `json:"name"` 7 | Description string `json:"description"` 8 | Location Location `json:"location"` 9 | ServerTypes struct { 10 | Supported []int `json:"supported"` 11 | Available []int `json:"available"` 12 | } `json:"server_types"` 13 | } 14 | 15 | // DatacenterGetResponse defines the schema of the response when retrieving a single datacenter. 16 | type DatacenterGetResponse struct { 17 | Datacenter Datacenter `json:"datacenter"` 18 | } 19 | 20 | // DatacenterListResponse defines the schema of the response when listing datacenters. 21 | type DatacenterListResponse struct { 22 | Datacenters []Datacenter `json:"datacenters"` 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/error.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import "encoding/json" 4 | 5 | // Error represents the schema of an error response. 6 | type Error struct { 7 | Code string `json:"code"` 8 | Message string `json:"message"` 9 | DetailsRaw json.RawMessage `json:"details"` 10 | Details interface{} 11 | } 12 | 13 | // UnmarshalJSON overrides default json unmarshalling. 14 | func (e *Error) UnmarshalJSON(data []byte) (err error) { 15 | type Alias Error 16 | alias := (*Alias)(e) 17 | if err = json.Unmarshal(data, alias); err != nil { 18 | return 19 | } 20 | switch e.Code { 21 | case "invalid_input": 22 | details := ErrorDetailsInvalidInput{} 23 | if err = json.Unmarshal(e.DetailsRaw, &details); err != nil { 24 | return 25 | } 26 | alias.Details = details 27 | } 28 | return 29 | } 30 | 31 | // ErrorResponse defines the schema of a response containing an error. 32 | type ErrorResponse struct { 33 | Error Error `json:"error"` 34 | } 35 | 36 | // ErrorDetailsInvalidInput defines the schema of the Details field 37 | // of an error with code 'invalid_input'. 38 | type ErrorDetailsInvalidInput struct { 39 | Fields []struct { 40 | Name string `json:"name"` 41 | Messages []string `json:"messages"` 42 | } `json:"fields"` 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/floating_ip.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // FloatingIP defines the schema of a Floating IP. 4 | type FloatingIP struct { 5 | ID int `json:"id"` 6 | Description *string `json:"description"` 7 | IP string `json:"ip"` 8 | Type string `json:"type"` 9 | Server *int `json:"server"` 10 | DNSPtr []FloatingIPDNSPtr `json:"dns_ptr"` 11 | HomeLocation Location `json:"home_location"` 12 | Blocked bool `json:"blocked"` 13 | Protection FloatingIPProtection `json:"protection"` 14 | } 15 | 16 | // FloatingIPProtection represents the protection level of a Floating IP. 17 | type FloatingIPProtection struct { 18 | Delete bool `json:"delete"` 19 | } 20 | 21 | // FloatingIPDNSPtr contains reverse DNS information for a 22 | // IPv4 or IPv6 Floating IP. 23 | type FloatingIPDNSPtr struct { 24 | IP string `json:"ip"` 25 | DNSPtr string `json:"dns_ptr"` 26 | } 27 | 28 | // FloatingIPGetResponse defines the schema of the response when 29 | // retrieving a single Floating IP. 30 | type FloatingIPGetResponse struct { 31 | FloatingIP FloatingIP `json:"floating_ip"` 32 | } 33 | 34 | // FloatingIPUpdateRequest defines the schema of the request to update a Floating IP. 35 | type FloatingIPUpdateRequest struct { 36 | Description string `json:"description,omitempty"` 37 | } 38 | 39 | // FloatingIPUpdateResponse defines the schema of the response when updating a Floating IP. 40 | type FloatingIPUpdateResponse struct { 41 | FloatingIP FloatingIP `json:"floating_ip"` 42 | } 43 | 44 | // FloatingIPListResponse defines the schema of the response when 45 | // listing Floating IPs. 46 | type FloatingIPListResponse struct { 47 | FloatingIPs []FloatingIP `json:"floating_ips"` 48 | } 49 | 50 | // FloatingIPCreateRequest defines the schema of the request to 51 | // create a Floating IP. 52 | type FloatingIPCreateRequest struct { 53 | Type string `json:"type"` 54 | HomeLocation *string `json:"home_location,omitempty"` 55 | Server *int `json:"server,omitempty"` 56 | Description *string `json:"description,omitempty"` 57 | } 58 | 59 | // FloatingIPCreateResponse defines the schema of the response 60 | // when creating a Floating IP. 61 | type FloatingIPCreateResponse struct { 62 | FloatingIP FloatingIP `json:"floating_ip"` 63 | Action *Action `json:"action"` 64 | } 65 | 66 | // FloatingIPActionAssignRequest defines the schema of the request to 67 | // create an assign Floating IP action. 68 | type FloatingIPActionAssignRequest struct { 69 | Server int `json:"server"` 70 | } 71 | 72 | // FloatingIPActionAssignResponse defines the schema of the response when 73 | // creating an assign action. 74 | type FloatingIPActionAssignResponse struct { 75 | Action Action `json:"action"` 76 | } 77 | 78 | // FloatingIPActionUnassignRequest defines the schema of the request to 79 | // create an unassign Floating IP action. 80 | type FloatingIPActionUnassignRequest struct{} 81 | 82 | // FloatingIPActionUnassignResponse defines the schema of the response when 83 | // creating an unassign action. 84 | type FloatingIPActionUnassignResponse struct { 85 | Action Action `json:"action"` 86 | } 87 | 88 | // FloatingIPActionChangeDNSPtrRequest defines the schema for the request to 89 | // change a Floating IP's reverse DNS pointer. 90 | type FloatingIPActionChangeDNSPtrRequest struct { 91 | IP string `json:"ip"` 92 | DNSPtr *string `json:"dns_ptr"` 93 | } 94 | 95 | // FloatingIPActionChangeDNSPtrResponse defines the schema of the response when 96 | // creating a change_dns_ptr Floating IP action. 97 | type FloatingIPActionChangeDNSPtrResponse struct { 98 | Action Action `json:"action"` 99 | } 100 | 101 | // FloatingIPActionChangeProtectionRequest defines the schema of the request to change the resource protection of a Floating IP. 102 | type FloatingIPActionChangeProtectionRequest struct { 103 | Delete *bool `json:"delete,omitempty"` 104 | } 105 | 106 | // FloatingIPActionChangeProtectionResponse defines the schema of the response when changing the resource protection of a Floating IP. 107 | type FloatingIPActionChangeProtectionResponse struct { 108 | Action Action `json:"action"` 109 | } 110 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/image.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import "time" 4 | 5 | // Image defines the schema of an image. 6 | type Image struct { 7 | ID int `json:"id"` 8 | Status string `json:"status"` 9 | Type string `json:"type"` 10 | Name *string `json:"name"` 11 | Description string `json:"description"` 12 | ImageSize *float32 `json:"image_size"` 13 | DiskSize float32 `json:"disk_size"` 14 | Created time.Time `json:"created"` 15 | CreatedFrom *ImageCreatedFrom `json:"created_from"` 16 | BoundTo *int `json:"bound_to"` 17 | OSFlavor string `json:"os_flavor"` 18 | OSVersion *string `json:"os_version"` 19 | RapidDeploy bool `json:"rapid_deploy"` 20 | Protection ImageProtection `json:"protection"` 21 | Deprecated time.Time `json:"deprecated"` 22 | } 23 | 24 | // ImageProtection represents the protection level of a image. 25 | type ImageProtection struct { 26 | Delete bool `json:"delete"` 27 | } 28 | 29 | // ImageCreatedFrom defines the schema of the images created from reference. 30 | type ImageCreatedFrom struct { 31 | ID int `json:"id"` 32 | Name string `json:"name"` 33 | } 34 | 35 | // ImageGetResponse defines the schema of the response when 36 | // retrieving a single image. 37 | type ImageGetResponse struct { 38 | Image Image `json:"image"` 39 | } 40 | 41 | // ImageListResponse defines the schema of the response when 42 | // listing images. 43 | type ImageListResponse struct { 44 | Images []Image `json:"images"` 45 | } 46 | 47 | // ImageUpdateRequest defines the schema of the request to update an image. 48 | type ImageUpdateRequest struct { 49 | Description *string `json:"description,omitempty"` 50 | Type *string `json:"type,omitempty"` 51 | } 52 | 53 | // ImageUpdateResponse defines the schema of the response when updating an image. 54 | type ImageUpdateResponse struct { 55 | Image Image `json:"image"` 56 | } 57 | 58 | // ImageActionChangeProtectionRequest defines the schema of the request to change the resource protection of an image. 59 | type ImageActionChangeProtectionRequest struct { 60 | Delete *bool `json:"delete,omitempty"` 61 | } 62 | 63 | // ImageActionChangeProtectionResponse defines the schema of the response when changing the resource protection of an image. 64 | type ImageActionChangeProtectionResponse struct { 65 | Action Action `json:"action"` 66 | } 67 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/iso.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | import "time" 4 | 5 | // ISO defines the schema of an ISO image. 6 | type ISO struct { 7 | ID int `json:"id"` 8 | Name string `json:"name"` 9 | Description string `json:"description"` 10 | Type string `json:"type"` 11 | Deprecated time.Time `json:"deprecated"` 12 | } 13 | 14 | // ISOGetResponse defines the schema of the response when retrieving a single ISO. 15 | type ISOGetResponse struct { 16 | ISO ISO `json:"iso"` 17 | } 18 | 19 | // ISOListResponse defines the schema of the response when listing ISOs. 20 | type ISOListResponse struct { 21 | ISOs []ISO `json:"isos"` 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/location.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // Location defines the schema of a location. 4 | type Location struct { 5 | ID int `json:"id"` 6 | Name string `json:"name"` 7 | Description string `json:"description"` 8 | Country string `json:"country"` 9 | City string `json:"city"` 10 | Latitude float64 `json:"latitude"` 11 | Longitude float64 `json:"longitude"` 12 | } 13 | 14 | // LocationGetResponse defines the schema of the response when retrieving a single location. 15 | type LocationGetResponse struct { 16 | Location Location `json:"location"` 17 | } 18 | 19 | // LocationListResponse defines the schema of the response when listing locations. 20 | type LocationListResponse struct { 21 | Locations []Location `json:"locations"` 22 | } 23 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/meta.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // Meta defines the schema of meta information which may be included 4 | // in responses. 5 | type Meta struct { 6 | Pagination *MetaPagination `json:"pagination"` 7 | } 8 | 9 | // MetaPagination defines the schema of pagination information. 10 | type MetaPagination struct { 11 | Page int `json:"page"` 12 | PerPage int `json:"per_page"` 13 | PreviousPage int `json:"previous_page"` 14 | NextPage int `json:"next_page"` 15 | LastPage int `json:"last_page"` 16 | TotalEntries int `json:"total_entries"` 17 | } 18 | 19 | // MetaResponse defines the schema of a response containing 20 | // meta information. 21 | type MetaResponse struct { 22 | Meta Meta `json:"meta"` 23 | } 24 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/pricing.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // Pricing defines the schema for pricing information. 4 | type Pricing struct { 5 | Currency string `json:"currency"` 6 | VATRate string `json:"vat_rate"` 7 | Image PricingImage `json:"image"` 8 | FloatingIP PricingFloatingIP `json:"floating_ip"` 9 | Traffic PricingTraffic `json:"traffic"` 10 | ServerBackup PricingServerBackup `json:"server_backup"` 11 | ServerTypes []PricingServerType `json:"server_types"` 12 | } 13 | 14 | // Price defines the schema of a single price with net and gross amount. 15 | type Price struct { 16 | Net string `json:"net"` 17 | Gross string `json:"gross"` 18 | } 19 | 20 | // PricingImage defines the schema of pricing information for an image. 21 | type PricingImage struct { 22 | PricePerGBMonth Price `json:"price_per_gb_month"` 23 | } 24 | 25 | // PricingFloatingIP defines the schema of pricing information for a Floating IP. 26 | type PricingFloatingIP struct { 27 | PriceMonthly Price `json:"price_monthly"` 28 | } 29 | 30 | // PricingTraffic defines the schema of pricing information for traffic. 31 | type PricingTraffic struct { 32 | PricePerTB Price `json:"price_per_tb"` 33 | } 34 | 35 | // PricingServerBackup defines the schema of pricing information for server backups. 36 | type PricingServerBackup struct { 37 | Percentage string `json:"percentage"` 38 | } 39 | 40 | // PricingServerType defines the schema of pricing information for a server type. 41 | type PricingServerType struct { 42 | ID int `json:"id"` 43 | Name string `json:"name"` 44 | Prices []PricingServerTypePrice `json:"prices"` 45 | } 46 | 47 | // PricingServerTypePrice defines the schema of pricing information for a server 48 | // type at a location. 49 | type PricingServerTypePrice struct { 50 | Location string `json:"location"` 51 | PriceHourly Price `json:"price_hourly"` 52 | PriceMonthly Price `json:"price_monthly"` 53 | } 54 | 55 | // PricingGetResponse defines the schema of the response when retrieving pricing information. 56 | type PricingGetResponse struct { 57 | Pricing Pricing `json:"pricing"` 58 | } 59 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/server_type.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // ServerType defines the schema of a server type. 4 | type ServerType struct { 5 | ID int `json:"id"` 6 | Name string `json:"name"` 7 | Description string `json:"description"` 8 | Cores int `json:"cores"` 9 | Memory float32 `json:"memory"` 10 | Disk int `json:"disk"` 11 | StorageType string `json:"storage_type"` 12 | Prices []PricingServerTypePrice `json:"prices"` 13 | } 14 | 15 | // ServerTypeListResponse defines the schema of the response when 16 | // listing server types. 17 | type ServerTypeListResponse struct { 18 | ServerTypes []ServerType `json:"server_types"` 19 | } 20 | 21 | // ServerTypeGetResponse defines the schema of the response when 22 | // retrieving a single server type. 23 | type ServerTypeGetResponse struct { 24 | ServerType ServerType `json:"server_type"` 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/schema/ssh_key.go: -------------------------------------------------------------------------------- 1 | package schema 2 | 3 | // SSHKey defines the schema of a SSH key. 4 | type SSHKey struct { 5 | ID int `json:"id"` 6 | Name string `json:"name"` 7 | Fingerprint string `json:"fingerprint"` 8 | PublicKey string `json:"public_key"` 9 | } 10 | 11 | // SSHKeyCreateRequest defines the schema of the request 12 | // to create a SSH key. 13 | type SSHKeyCreateRequest struct { 14 | Name string `json:"name"` 15 | PublicKey string `json:"public_key"` 16 | } 17 | 18 | // SSHKeyCreateResponse defines the schema of the response 19 | // when creating a SSH key. 20 | type SSHKeyCreateResponse struct { 21 | SSHKey SSHKey `json:"ssh_key"` 22 | } 23 | 24 | // SSHKeyListResponse defines the schema of the response 25 | // when listing SSH keys. 26 | type SSHKeyListResponse struct { 27 | SSHKeys []SSHKey `json:"ssh_keys"` 28 | } 29 | 30 | // SSHKeyGetResponse defines the schema of the response 31 | // when retrieving a single SSH key. 32 | type SSHKeyGetResponse struct { 33 | SSHKey SSHKey `json:"ssh_key"` 34 | } 35 | 36 | // SSHKeyUpdateRequest defines the schema of the request to update a SSH key. 37 | type SSHKeyUpdateRequest struct { 38 | Name string `json:"name,omitempty"` 39 | } 40 | 41 | // SSHKeyUpdateResponse defines the schema of the response when updating a SSH key. 42 | type SSHKeyUpdateResponse struct { 43 | SSHKey SSHKey `json:"ssh_key"` 44 | } 45 | -------------------------------------------------------------------------------- /vendor/github.com/hetznercloud/hcloud-go/hcloud/server_type.go: -------------------------------------------------------------------------------- 1 | package hcloud 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/url" 7 | "strconv" 8 | 9 | "github.com/hetznercloud/hcloud-go/hcloud/schema" 10 | ) 11 | 12 | // ServerType represents a server type in the Hetzner Cloud. 13 | type ServerType struct { 14 | ID int 15 | Name string 16 | Description string 17 | Cores int 18 | Memory float32 19 | Disk int 20 | StorageType StorageType 21 | Pricings []ServerTypeLocationPricing 22 | } 23 | 24 | // StorageType specifies the type of storage. 25 | type StorageType string 26 | 27 | const ( 28 | // StorageTypeLocal is the type for local storage. 29 | StorageTypeLocal StorageType = "local" 30 | 31 | // StorageTypeCeph is the type for remote storage. 32 | StorageTypeCeph StorageType = "ceph" 33 | ) 34 | 35 | // ServerTypeClient is a client for the server types API. 36 | type ServerTypeClient struct { 37 | client *Client 38 | } 39 | 40 | // GetByID retrieves a server type by its ID. 41 | func (c *ServerTypeClient) GetByID(ctx context.Context, id int) (*ServerType, *Response, error) { 42 | req, err := c.client.NewRequest(ctx, "GET", fmt.Sprintf("/server_types/%d", id), nil) 43 | if err != nil { 44 | return nil, nil, err 45 | } 46 | 47 | var body schema.ServerTypeGetResponse 48 | resp, err := c.client.Do(req, &body) 49 | if err != nil { 50 | if IsError(err, ErrorCodeNotFound) { 51 | return nil, resp, nil 52 | } 53 | return nil, nil, err 54 | } 55 | return ServerTypeFromSchema(body.ServerType), resp, nil 56 | } 57 | 58 | // GetByName retrieves a server type by its name. 59 | func (c *ServerTypeClient) GetByName(ctx context.Context, name string) (*ServerType, *Response, error) { 60 | path := "/server_types?name=" + url.QueryEscape(name) 61 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 62 | if err != nil { 63 | return nil, nil, err 64 | } 65 | 66 | var body schema.ServerTypeListResponse 67 | resp, err := c.client.Do(req, &body) 68 | if err != nil { 69 | return nil, nil, err 70 | } 71 | 72 | if len(body.ServerTypes) == 0 { 73 | return nil, resp, nil 74 | } 75 | return ServerTypeFromSchema(body.ServerTypes[0]), resp, nil 76 | } 77 | 78 | // Get retrieves a server type by its ID if the input can be parsed as an integer, otherwise it retrieves a server type by its name. 79 | func (c *ServerTypeClient) Get(ctx context.Context, idOrName string) (*ServerType, *Response, error) { 80 | if id, err := strconv.Atoi(idOrName); err == nil { 81 | return c.GetByID(ctx, int(id)) 82 | } 83 | return c.GetByName(ctx, idOrName) 84 | } 85 | 86 | // ServerTypeListOpts specifies options for listing server types. 87 | type ServerTypeListOpts struct { 88 | ListOpts 89 | } 90 | 91 | // List returns a list of server types for a specific page. 92 | func (c *ServerTypeClient) List(ctx context.Context, opts ServerTypeListOpts) ([]*ServerType, *Response, error) { 93 | path := "/server_types?" + valuesForListOpts(opts.ListOpts).Encode() 94 | req, err := c.client.NewRequest(ctx, "GET", path, nil) 95 | if err != nil { 96 | return nil, nil, err 97 | } 98 | 99 | var body schema.ServerTypeListResponse 100 | resp, err := c.client.Do(req, &body) 101 | if err != nil { 102 | return nil, nil, err 103 | } 104 | serverTypes := make([]*ServerType, 0, len(body.ServerTypes)) 105 | for _, s := range body.ServerTypes { 106 | serverTypes = append(serverTypes, ServerTypeFromSchema(s)) 107 | } 108 | return serverTypes, resp, nil 109 | } 110 | 111 | // All returns all server types. 112 | func (c *ServerTypeClient) All(ctx context.Context) ([]*ServerType, error) { 113 | allServerTypes := []*ServerType{} 114 | 115 | opts := ServerTypeListOpts{} 116 | opts.PerPage = 50 117 | 118 | _, err := c.client.all(func(page int) (*Response, error) { 119 | opts.Page = page 120 | serverTypes, resp, err := c.List(ctx, opts) 121 | if err != nil { 122 | return resp, err 123 | } 124 | allServerTypes = append(allServerTypes, serverTypes...) 125 | return resp, nil 126 | }) 127 | if err != nil { 128 | return nil, err 129 | } 130 | 131 | return allServerTypes, nil 132 | } 133 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* 2 | 3 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.7.3 7 | - 1.8.1 8 | - tip 9 | 10 | matrix: 11 | allow_failures: 12 | - go: tip 13 | 14 | install: 15 | - go get github.com/golang/lint/golint 16 | - export PATH=$GOPATH/bin:$PATH 17 | - go install ./... 18 | 19 | script: 20 | - verify/all.sh -v 21 | - go test ./... 22 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bool.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // optional interface to indicate boolean flags that can be 6 | // supplied without "=value" text 7 | type boolFlag interface { 8 | Value 9 | IsBoolFlag() bool 10 | } 11 | 12 | // -- bool Value 13 | type boolValue bool 14 | 15 | func newBoolValue(val bool, p *bool) *boolValue { 16 | *p = val 17 | return (*boolValue)(p) 18 | } 19 | 20 | func (b *boolValue) Set(s string) error { 21 | v, err := strconv.ParseBool(s) 22 | *b = boolValue(v) 23 | return err 24 | } 25 | 26 | func (b *boolValue) Type() string { 27 | return "bool" 28 | } 29 | 30 | func (b *boolValue) String() string { return strconv.FormatBool(bool(*b)) } 31 | 32 | func (b *boolValue) IsBoolFlag() bool { return true } 33 | 34 | func boolConv(sval string) (interface{}, error) { 35 | return strconv.ParseBool(sval) 36 | } 37 | 38 | // GetBool return the bool value of a flag with the given name 39 | func (f *FlagSet) GetBool(name string) (bool, error) { 40 | val, err := f.getFlagType(name, "bool", boolConv) 41 | if err != nil { 42 | return false, err 43 | } 44 | return val.(bool), nil 45 | } 46 | 47 | // BoolVar defines a bool flag with specified name, default value, and usage string. 48 | // The argument p points to a bool variable in which to store the value of the flag. 49 | func (f *FlagSet) BoolVar(p *bool, name string, value bool, usage string) { 50 | f.BoolVarP(p, name, "", value, usage) 51 | } 52 | 53 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 54 | func (f *FlagSet) BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 55 | flag := f.VarPF(newBoolValue(value, p), name, shorthand, usage) 56 | flag.NoOptDefVal = "true" 57 | } 58 | 59 | // BoolVar defines a bool flag with specified name, default value, and usage string. 60 | // The argument p points to a bool variable in which to store the value of the flag. 61 | func BoolVar(p *bool, name string, value bool, usage string) { 62 | BoolVarP(p, name, "", value, usage) 63 | } 64 | 65 | // BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash. 66 | func BoolVarP(p *bool, name, shorthand string, value bool, usage string) { 67 | flag := CommandLine.VarPF(newBoolValue(value, p), name, shorthand, usage) 68 | flag.NoOptDefVal = "true" 69 | } 70 | 71 | // Bool defines a bool flag with specified name, default value, and usage string. 72 | // The return value is the address of a bool variable that stores the value of the flag. 73 | func (f *FlagSet) Bool(name string, value bool, usage string) *bool { 74 | return f.BoolP(name, "", value, usage) 75 | } 76 | 77 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 78 | func (f *FlagSet) BoolP(name, shorthand string, value bool, usage string) *bool { 79 | p := new(bool) 80 | f.BoolVarP(p, name, shorthand, value, usage) 81 | return p 82 | } 83 | 84 | // Bool defines a bool flag with specified name, default value, and usage string. 85 | // The return value is the address of a bool variable that stores the value of the flag. 86 | func Bool(name string, value bool, usage string) *bool { 87 | return BoolP(name, "", value, usage) 88 | } 89 | 90 | // BoolP is like Bool, but accepts a shorthand letter that can be used after a single dash. 91 | func BoolP(name, shorthand string, value bool, usage string) *bool { 92 | b := CommandLine.BoolP(name, shorthand, value, usage) 93 | return b 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/bytes.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "encoding/hex" 5 | "fmt" 6 | "strings" 7 | ) 8 | 9 | // BytesHex adapts []byte for use as a flag. Value of flag is HEX encoded 10 | type bytesHexValue []byte 11 | 12 | func (bytesHex bytesHexValue) String() string { 13 | return fmt.Sprintf("%X", []byte(bytesHex)) 14 | } 15 | 16 | func (bytesHex *bytesHexValue) Set(value string) error { 17 | bin, err := hex.DecodeString(strings.TrimSpace(value)) 18 | 19 | if err != nil { 20 | return err 21 | } 22 | 23 | *bytesHex = bin 24 | 25 | return nil 26 | } 27 | 28 | func (*bytesHexValue) Type() string { 29 | return "bytesHex" 30 | } 31 | 32 | func newBytesHexValue(val []byte, p *[]byte) *bytesHexValue { 33 | *p = val 34 | return (*bytesHexValue)(p) 35 | } 36 | 37 | func bytesHexConv(sval string) (interface{}, error) { 38 | 39 | bin, err := hex.DecodeString(sval) 40 | 41 | if err == nil { 42 | return bin, nil 43 | } 44 | 45 | return nil, fmt.Errorf("invalid string being converted to Bytes: %s %s", sval, err) 46 | } 47 | 48 | // GetBytesHex return the []byte value of a flag with the given name 49 | func (f *FlagSet) GetBytesHex(name string) ([]byte, error) { 50 | val, err := f.getFlagType(name, "bytesHex", bytesHexConv) 51 | 52 | if err != nil { 53 | return []byte{}, err 54 | } 55 | 56 | return val.([]byte), nil 57 | } 58 | 59 | // BytesHexVar defines an []byte flag with specified name, default value, and usage string. 60 | // The argument p points to an []byte variable in which to store the value of the flag. 61 | func (f *FlagSet) BytesHexVar(p *[]byte, name string, value []byte, usage string) { 62 | f.VarP(newBytesHexValue(value, p), name, "", usage) 63 | } 64 | 65 | // BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash. 66 | func (f *FlagSet) BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) { 67 | f.VarP(newBytesHexValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // BytesHexVar defines an []byte flag with specified name, default value, and usage string. 71 | // The argument p points to an []byte variable in which to store the value of the flag. 72 | func BytesHexVar(p *[]byte, name string, value []byte, usage string) { 73 | CommandLine.VarP(newBytesHexValue(value, p), name, "", usage) 74 | } 75 | 76 | // BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash. 77 | func BytesHexVarP(p *[]byte, name, shorthand string, value []byte, usage string) { 78 | CommandLine.VarP(newBytesHexValue(value, p), name, shorthand, usage) 79 | } 80 | 81 | // BytesHex defines an []byte flag with specified name, default value, and usage string. 82 | // The return value is the address of an []byte variable that stores the value of the flag. 83 | func (f *FlagSet) BytesHex(name string, value []byte, usage string) *[]byte { 84 | p := new([]byte) 85 | f.BytesHexVarP(p, name, "", value, usage) 86 | return p 87 | } 88 | 89 | // BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash. 90 | func (f *FlagSet) BytesHexP(name, shorthand string, value []byte, usage string) *[]byte { 91 | p := new([]byte) 92 | f.BytesHexVarP(p, name, shorthand, value, usage) 93 | return p 94 | } 95 | 96 | // BytesHex defines an []byte flag with specified name, default value, and usage string. 97 | // The return value is the address of an []byte variable that stores the value of the flag. 98 | func BytesHex(name string, value []byte, usage string) *[]byte { 99 | return CommandLine.BytesHexP(name, "", value, usage) 100 | } 101 | 102 | // BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash. 103 | func BytesHexP(name, shorthand string, value []byte, usage string) *[]byte { 104 | return CommandLine.BytesHexP(name, shorthand, value, usage) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/count.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- count Value 6 | type countValue int 7 | 8 | func newCountValue(val int, p *int) *countValue { 9 | *p = val 10 | return (*countValue)(p) 11 | } 12 | 13 | func (i *countValue) Set(s string) error { 14 | // "+1" means that no specific value was passed, so increment 15 | if s == "+1" { 16 | *i = countValue(*i + 1) 17 | return nil 18 | } 19 | v, err := strconv.ParseInt(s, 0, 0) 20 | *i = countValue(v) 21 | return err 22 | } 23 | 24 | func (i *countValue) Type() string { 25 | return "count" 26 | } 27 | 28 | func (i *countValue) String() string { return strconv.Itoa(int(*i)) } 29 | 30 | func countConv(sval string) (interface{}, error) { 31 | i, err := strconv.Atoi(sval) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return i, nil 36 | } 37 | 38 | // GetCount return the int value of a flag with the given name 39 | func (f *FlagSet) GetCount(name string) (int, error) { 40 | val, err := f.getFlagType(name, "count", countConv) 41 | if err != nil { 42 | return 0, err 43 | } 44 | return val.(int), nil 45 | } 46 | 47 | // CountVar defines a count flag with specified name, default value, and usage string. 48 | // The argument p points to an int variable in which to store the value of the flag. 49 | // A count flag will add 1 to its value evey time it is found on the command line 50 | func (f *FlagSet) CountVar(p *int, name string, usage string) { 51 | f.CountVarP(p, name, "", usage) 52 | } 53 | 54 | // CountVarP is like CountVar only take a shorthand for the flag name. 55 | func (f *FlagSet) CountVarP(p *int, name, shorthand string, usage string) { 56 | flag := f.VarPF(newCountValue(0, p), name, shorthand, usage) 57 | flag.NoOptDefVal = "+1" 58 | } 59 | 60 | // CountVar like CountVar only the flag is placed on the CommandLine instead of a given flag set 61 | func CountVar(p *int, name string, usage string) { 62 | CommandLine.CountVar(p, name, usage) 63 | } 64 | 65 | // CountVarP is like CountVar only take a shorthand for the flag name. 66 | func CountVarP(p *int, name, shorthand string, usage string) { 67 | CommandLine.CountVarP(p, name, shorthand, usage) 68 | } 69 | 70 | // Count defines a count flag with specified name, default value, and usage string. 71 | // The return value is the address of an int variable that stores the value of the flag. 72 | // A count flag will add 1 to its value evey time it is found on the command line 73 | func (f *FlagSet) Count(name string, usage string) *int { 74 | p := new(int) 75 | f.CountVarP(p, name, "", usage) 76 | return p 77 | } 78 | 79 | // CountP is like Count only takes a shorthand for the flag name. 80 | func (f *FlagSet) CountP(name, shorthand string, usage string) *int { 81 | p := new(int) 82 | f.CountVarP(p, name, shorthand, usage) 83 | return p 84 | } 85 | 86 | // Count defines a count flag with specified name, default value, and usage string. 87 | // The return value is the address of an int variable that stores the value of the flag. 88 | // A count flag will add 1 to its value evey time it is found on the command line 89 | func Count(name string, usage string) *int { 90 | return CommandLine.CountP(name, "", usage) 91 | } 92 | 93 | // CountP is like Count only takes a shorthand for the flag name. 94 | func CountP(name, shorthand string, usage string) *int { 95 | return CommandLine.CountP(name, shorthand, usage) 96 | } 97 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/duration.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "time" 5 | ) 6 | 7 | // -- time.Duration Value 8 | type durationValue time.Duration 9 | 10 | func newDurationValue(val time.Duration, p *time.Duration) *durationValue { 11 | *p = val 12 | return (*durationValue)(p) 13 | } 14 | 15 | func (d *durationValue) Set(s string) error { 16 | v, err := time.ParseDuration(s) 17 | *d = durationValue(v) 18 | return err 19 | } 20 | 21 | func (d *durationValue) Type() string { 22 | return "duration" 23 | } 24 | 25 | func (d *durationValue) String() string { return (*time.Duration)(d).String() } 26 | 27 | func durationConv(sval string) (interface{}, error) { 28 | return time.ParseDuration(sval) 29 | } 30 | 31 | // GetDuration return the duration value of a flag with the given name 32 | func (f *FlagSet) GetDuration(name string) (time.Duration, error) { 33 | val, err := f.getFlagType(name, "duration", durationConv) 34 | if err != nil { 35 | return 0, err 36 | } 37 | return val.(time.Duration), nil 38 | } 39 | 40 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 41 | // The argument p points to a time.Duration variable in which to store the value of the flag. 42 | func (f *FlagSet) DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 43 | f.VarP(newDurationValue(value, p), name, "", usage) 44 | } 45 | 46 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 47 | func (f *FlagSet) DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 48 | f.VarP(newDurationValue(value, p), name, shorthand, usage) 49 | } 50 | 51 | // DurationVar defines a time.Duration flag with specified name, default value, and usage string. 52 | // The argument p points to a time.Duration variable in which to store the value of the flag. 53 | func DurationVar(p *time.Duration, name string, value time.Duration, usage string) { 54 | CommandLine.VarP(newDurationValue(value, p), name, "", usage) 55 | } 56 | 57 | // DurationVarP is like DurationVar, but accepts a shorthand letter that can be used after a single dash. 58 | func DurationVarP(p *time.Duration, name, shorthand string, value time.Duration, usage string) { 59 | CommandLine.VarP(newDurationValue(value, p), name, shorthand, usage) 60 | } 61 | 62 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 63 | // The return value is the address of a time.Duration variable that stores the value of the flag. 64 | func (f *FlagSet) Duration(name string, value time.Duration, usage string) *time.Duration { 65 | p := new(time.Duration) 66 | f.DurationVarP(p, name, "", value, usage) 67 | return p 68 | } 69 | 70 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 71 | func (f *FlagSet) DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 72 | p := new(time.Duration) 73 | f.DurationVarP(p, name, shorthand, value, usage) 74 | return p 75 | } 76 | 77 | // Duration defines a time.Duration flag with specified name, default value, and usage string. 78 | // The return value is the address of a time.Duration variable that stores the value of the flag. 79 | func Duration(name string, value time.Duration, usage string) *time.Duration { 80 | return CommandLine.DurationP(name, "", value, usage) 81 | } 82 | 83 | // DurationP is like Duration, but accepts a shorthand letter that can be used after a single dash. 84 | func DurationP(name, shorthand string, value time.Duration, usage string) *time.Duration { 85 | return CommandLine.DurationP(name, shorthand, value, usage) 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float32 Value 6 | type float32Value float32 7 | 8 | func newFloat32Value(val float32, p *float32) *float32Value { 9 | *p = val 10 | return (*float32Value)(p) 11 | } 12 | 13 | func (f *float32Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 32) 15 | *f = float32Value(v) 16 | return err 17 | } 18 | 19 | func (f *float32Value) Type() string { 20 | return "float32" 21 | } 22 | 23 | func (f *float32Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 32) } 24 | 25 | func float32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseFloat(sval, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return float32(v), nil 31 | } 32 | 33 | // GetFloat32 return the float32 value of a flag with the given name 34 | func (f *FlagSet) GetFloat32(name string) (float32, error) { 35 | val, err := f.getFlagType(name, "float32", float32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(float32), nil 40 | } 41 | 42 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 43 | // The argument p points to a float32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Float32Var(p *float32, name string, value float32, usage string) { 45 | f.VarP(newFloat32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 50 | f.VarP(newFloat32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Float32Var defines a float32 flag with specified name, default value, and usage string. 54 | // The argument p points to a float32 variable in which to store the value of the flag. 55 | func Float32Var(p *float32, name string, value float32, usage string) { 56 | CommandLine.VarP(newFloat32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Float32VarP is like Float32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Float32VarP(p *float32, name, shorthand string, value float32, usage string) { 61 | CommandLine.VarP(newFloat32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Float32 defines a float32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a float32 variable that stores the value of the flag. 66 | func (f *FlagSet) Float32(name string, value float32, usage string) *float32 { 67 | p := new(float32) 68 | f.Float32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Float32P(name, shorthand string, value float32, usage string) *float32 { 74 | p := new(float32) 75 | f.Float32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Float32 defines a float32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a float32 variable that stores the value of the flag. 81 | func Float32(name string, value float32, usage string) *float32 { 82 | return CommandLine.Float32P(name, "", value, usage) 83 | } 84 | 85 | // Float32P is like Float32, but accepts a shorthand letter that can be used after a single dash. 86 | func Float32P(name, shorthand string, value float32, usage string) *float32 { 87 | return CommandLine.Float32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/float64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- float64 Value 6 | type float64Value float64 7 | 8 | func newFloat64Value(val float64, p *float64) *float64Value { 9 | *p = val 10 | return (*float64Value)(p) 11 | } 12 | 13 | func (f *float64Value) Set(s string) error { 14 | v, err := strconv.ParseFloat(s, 64) 15 | *f = float64Value(v) 16 | return err 17 | } 18 | 19 | func (f *float64Value) Type() string { 20 | return "float64" 21 | } 22 | 23 | func (f *float64Value) String() string { return strconv.FormatFloat(float64(*f), 'g', -1, 64) } 24 | 25 | func float64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseFloat(sval, 64) 27 | } 28 | 29 | // GetFloat64 return the float64 value of a flag with the given name 30 | func (f *FlagSet) GetFloat64(name string) (float64, error) { 31 | val, err := f.getFlagType(name, "float64", float64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(float64), nil 36 | } 37 | 38 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 39 | // The argument p points to a float64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Float64Var(p *float64, name string, value float64, usage string) { 41 | f.VarP(newFloat64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 46 | f.VarP(newFloat64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Float64Var defines a float64 flag with specified name, default value, and usage string. 50 | // The argument p points to a float64 variable in which to store the value of the flag. 51 | func Float64Var(p *float64, name string, value float64, usage string) { 52 | CommandLine.VarP(newFloat64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Float64VarP is like Float64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Float64VarP(p *float64, name, shorthand string, value float64, usage string) { 57 | CommandLine.VarP(newFloat64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Float64 defines a float64 flag with specified name, default value, and usage string. 61 | // The return value is the address of a float64 variable that stores the value of the flag. 62 | func (f *FlagSet) Float64(name string, value float64, usage string) *float64 { 63 | p := new(float64) 64 | f.Float64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Float64P(name, shorthand string, value float64, usage string) *float64 { 70 | p := new(float64) 71 | f.Float64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Float64 defines a float64 flag with specified name, default value, and usage string. 76 | // The return value is the address of a float64 variable that stores the value of the flag. 77 | func Float64(name string, value float64, usage string) *float64 { 78 | return CommandLine.Float64P(name, "", value, usage) 79 | } 80 | 81 | // Float64P is like Float64, but accepts a shorthand letter that can be used after a single dash. 82 | func Float64P(name, shorthand string, value float64, usage string) *float64 { 83 | return CommandLine.Float64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/golangflag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pflag 6 | 7 | import ( 8 | goflag "flag" 9 | "reflect" 10 | "strings" 11 | ) 12 | 13 | // flagValueWrapper implements pflag.Value around a flag.Value. The main 14 | // difference here is the addition of the Type method that returns a string 15 | // name of the type. As this is generally unknown, we approximate that with 16 | // reflection. 17 | type flagValueWrapper struct { 18 | inner goflag.Value 19 | flagType string 20 | } 21 | 22 | // We are just copying the boolFlag interface out of goflag as that is what 23 | // they use to decide if a flag should get "true" when no arg is given. 24 | type goBoolFlag interface { 25 | goflag.Value 26 | IsBoolFlag() bool 27 | } 28 | 29 | func wrapFlagValue(v goflag.Value) Value { 30 | // If the flag.Value happens to also be a pflag.Value, just use it directly. 31 | if pv, ok := v.(Value); ok { 32 | return pv 33 | } 34 | 35 | pv := &flagValueWrapper{ 36 | inner: v, 37 | } 38 | 39 | t := reflect.TypeOf(v) 40 | if t.Kind() == reflect.Interface || t.Kind() == reflect.Ptr { 41 | t = t.Elem() 42 | } 43 | 44 | pv.flagType = strings.TrimSuffix(t.Name(), "Value") 45 | return pv 46 | } 47 | 48 | func (v *flagValueWrapper) String() string { 49 | return v.inner.String() 50 | } 51 | 52 | func (v *flagValueWrapper) Set(s string) error { 53 | return v.inner.Set(s) 54 | } 55 | 56 | func (v *flagValueWrapper) Type() string { 57 | return v.flagType 58 | } 59 | 60 | // PFlagFromGoFlag will return a *pflag.Flag given a *flag.Flag 61 | // If the *flag.Flag.Name was a single character (ex: `v`) it will be accessiblei 62 | // with both `-v` and `--v` in flags. If the golang flag was more than a single 63 | // character (ex: `verbose`) it will only be accessible via `--verbose` 64 | func PFlagFromGoFlag(goflag *goflag.Flag) *Flag { 65 | // Remember the default value as a string; it won't change. 66 | flag := &Flag{ 67 | Name: goflag.Name, 68 | Usage: goflag.Usage, 69 | Value: wrapFlagValue(goflag.Value), 70 | // Looks like golang flags don't set DefValue correctly :-( 71 | //DefValue: goflag.DefValue, 72 | DefValue: goflag.Value.String(), 73 | } 74 | // Ex: if the golang flag was -v, allow both -v and --v to work 75 | if len(flag.Name) == 1 { 76 | flag.Shorthand = flag.Name 77 | } 78 | if fv, ok := goflag.Value.(goBoolFlag); ok && fv.IsBoolFlag() { 79 | flag.NoOptDefVal = "true" 80 | } 81 | return flag 82 | } 83 | 84 | // AddGoFlag will add the given *flag.Flag to the pflag.FlagSet 85 | func (f *FlagSet) AddGoFlag(goflag *goflag.Flag) { 86 | if f.Lookup(goflag.Name) != nil { 87 | return 88 | } 89 | newflag := PFlagFromGoFlag(goflag) 90 | f.AddFlag(newflag) 91 | } 92 | 93 | // AddGoFlagSet will add the given *flag.FlagSet to the pflag.FlagSet 94 | func (f *FlagSet) AddGoFlagSet(newSet *goflag.FlagSet) { 95 | if newSet == nil { 96 | return 97 | } 98 | newSet.VisitAll(func(goflag *goflag.Flag) { 99 | f.AddGoFlag(goflag) 100 | }) 101 | if f.addedGoFlagSets == nil { 102 | f.addedGoFlagSets = make([]*goflag.FlagSet, 0) 103 | } 104 | f.addedGoFlagSets = append(f.addedGoFlagSets, newSet) 105 | } 106 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int Value 6 | type intValue int 7 | 8 | func newIntValue(val int, p *int) *intValue { 9 | *p = val 10 | return (*intValue)(p) 11 | } 12 | 13 | func (i *intValue) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = intValue(v) 16 | return err 17 | } 18 | 19 | func (i *intValue) Type() string { 20 | return "int" 21 | } 22 | 23 | func (i *intValue) String() string { return strconv.Itoa(int(*i)) } 24 | 25 | func intConv(sval string) (interface{}, error) { 26 | return strconv.Atoi(sval) 27 | } 28 | 29 | // GetInt return the int value of a flag with the given name 30 | func (f *FlagSet) GetInt(name string) (int, error) { 31 | val, err := f.getFlagType(name, "int", intConv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int), nil 36 | } 37 | 38 | // IntVar defines an int flag with specified name, default value, and usage string. 39 | // The argument p points to an int variable in which to store the value of the flag. 40 | func (f *FlagSet) IntVar(p *int, name string, value int, usage string) { 41 | f.VarP(newIntValue(value, p), name, "", usage) 42 | } 43 | 44 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) IntVarP(p *int, name, shorthand string, value int, usage string) { 46 | f.VarP(newIntValue(value, p), name, shorthand, usage) 47 | } 48 | 49 | // IntVar defines an int flag with specified name, default value, and usage string. 50 | // The argument p points to an int variable in which to store the value of the flag. 51 | func IntVar(p *int, name string, value int, usage string) { 52 | CommandLine.VarP(newIntValue(value, p), name, "", usage) 53 | } 54 | 55 | // IntVarP is like IntVar, but accepts a shorthand letter that can be used after a single dash. 56 | func IntVarP(p *int, name, shorthand string, value int, usage string) { 57 | CommandLine.VarP(newIntValue(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int defines an int flag with specified name, default value, and usage string. 61 | // The return value is the address of an int variable that stores the value of the flag. 62 | func (f *FlagSet) Int(name string, value int, usage string) *int { 63 | p := new(int) 64 | f.IntVarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) IntP(name, shorthand string, value int, usage string) *int { 70 | p := new(int) 71 | f.IntVarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int defines an int flag with specified name, default value, and usage string. 76 | // The return value is the address of an int variable that stores the value of the flag. 77 | func Int(name string, value int, usage string) *int { 78 | return CommandLine.IntP(name, "", value, usage) 79 | } 80 | 81 | // IntP is like Int, but accepts a shorthand letter that can be used after a single dash. 82 | func IntP(name, shorthand string, value int, usage string) *int { 83 | return CommandLine.IntP(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int16 Value 6 | type int16Value int16 7 | 8 | func newInt16Value(val int16, p *int16) *int16Value { 9 | *p = val 10 | return (*int16Value)(p) 11 | } 12 | 13 | func (i *int16Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 16) 15 | *i = int16Value(v) 16 | return err 17 | } 18 | 19 | func (i *int16Value) Type() string { 20 | return "int16" 21 | } 22 | 23 | func (i *int16Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int16(v), nil 31 | } 32 | 33 | // GetInt16 returns the int16 value of a flag with the given name 34 | func (f *FlagSet) GetInt16(name string) (int16, error) { 35 | val, err := f.getFlagType(name, "int16", int16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int16), nil 40 | } 41 | 42 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 43 | // The argument p points to an int16 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int16Var(p *int16, name string, value int16, usage string) { 45 | f.VarP(newInt16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 50 | f.VarP(newInt16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int16Var defines an int16 flag with specified name, default value, and usage string. 54 | // The argument p points to an int16 variable in which to store the value of the flag. 55 | func Int16Var(p *int16, name string, value int16, usage string) { 56 | CommandLine.VarP(newInt16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int16VarP is like Int16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int16VarP(p *int16, name, shorthand string, value int16, usage string) { 61 | CommandLine.VarP(newInt16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int16 defines an int16 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int16 variable that stores the value of the flag. 66 | func (f *FlagSet) Int16(name string, value int16, usage string) *int16 { 67 | p := new(int16) 68 | f.Int16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int16P(name, shorthand string, value int16, usage string) *int16 { 74 | p := new(int16) 75 | f.Int16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int16 defines an int16 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int16 variable that stores the value of the flag. 81 | func Int16(name string, value int16, usage string) *int16 { 82 | return CommandLine.Int16P(name, "", value, usage) 83 | } 84 | 85 | // Int16P is like Int16, but accepts a shorthand letter that can be used after a single dash. 86 | func Int16P(name, shorthand string, value int16, usage string) *int16 { 87 | return CommandLine.Int16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int32 Value 6 | type int32Value int32 7 | 8 | func newInt32Value(val int32, p *int32) *int32Value { 9 | *p = val 10 | return (*int32Value)(p) 11 | } 12 | 13 | func (i *int32Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 32) 15 | *i = int32Value(v) 16 | return err 17 | } 18 | 19 | func (i *int32Value) Type() string { 20 | return "int32" 21 | } 22 | 23 | func (i *int32Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int32(v), nil 31 | } 32 | 33 | // GetInt32 return the int32 value of a flag with the given name 34 | func (f *FlagSet) GetInt32(name string) (int32, error) { 35 | val, err := f.getFlagType(name, "int32", int32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int32), nil 40 | } 41 | 42 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 43 | // The argument p points to an int32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int32Var(p *int32, name string, value int32, usage string) { 45 | f.VarP(newInt32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 50 | f.VarP(newInt32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int32Var defines an int32 flag with specified name, default value, and usage string. 54 | // The argument p points to an int32 variable in which to store the value of the flag. 55 | func Int32Var(p *int32, name string, value int32, usage string) { 56 | CommandLine.VarP(newInt32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int32VarP is like Int32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int32VarP(p *int32, name, shorthand string, value int32, usage string) { 61 | CommandLine.VarP(newInt32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int32 defines an int32 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int32 variable that stores the value of the flag. 66 | func (f *FlagSet) Int32(name string, value int32, usage string) *int32 { 67 | p := new(int32) 68 | f.Int32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int32P(name, shorthand string, value int32, usage string) *int32 { 74 | p := new(int32) 75 | f.Int32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int32 defines an int32 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int32 variable that stores the value of the flag. 81 | func Int32(name string, value int32, usage string) *int32 { 82 | return CommandLine.Int32P(name, "", value, usage) 83 | } 84 | 85 | // Int32P is like Int32, but accepts a shorthand letter that can be used after a single dash. 86 | func Int32P(name, shorthand string, value int32, usage string) *int32 { 87 | return CommandLine.Int32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int64 Value 6 | type int64Value int64 7 | 8 | func newInt64Value(val int64, p *int64) *int64Value { 9 | *p = val 10 | return (*int64Value)(p) 11 | } 12 | 13 | func (i *int64Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 64) 15 | *i = int64Value(v) 16 | return err 17 | } 18 | 19 | func (i *int64Value) Type() string { 20 | return "int64" 21 | } 22 | 23 | func (i *int64Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int64Conv(sval string) (interface{}, error) { 26 | return strconv.ParseInt(sval, 0, 64) 27 | } 28 | 29 | // GetInt64 return the int64 value of a flag with the given name 30 | func (f *FlagSet) GetInt64(name string) (int64, error) { 31 | val, err := f.getFlagType(name, "int64", int64Conv) 32 | if err != nil { 33 | return 0, err 34 | } 35 | return val.(int64), nil 36 | } 37 | 38 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 39 | // The argument p points to an int64 variable in which to store the value of the flag. 40 | func (f *FlagSet) Int64Var(p *int64, name string, value int64, usage string) { 41 | f.VarP(newInt64Value(value, p), name, "", usage) 42 | } 43 | 44 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 45 | func (f *FlagSet) Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 46 | f.VarP(newInt64Value(value, p), name, shorthand, usage) 47 | } 48 | 49 | // Int64Var defines an int64 flag with specified name, default value, and usage string. 50 | // The argument p points to an int64 variable in which to store the value of the flag. 51 | func Int64Var(p *int64, name string, value int64, usage string) { 52 | CommandLine.VarP(newInt64Value(value, p), name, "", usage) 53 | } 54 | 55 | // Int64VarP is like Int64Var, but accepts a shorthand letter that can be used after a single dash. 56 | func Int64VarP(p *int64, name, shorthand string, value int64, usage string) { 57 | CommandLine.VarP(newInt64Value(value, p), name, shorthand, usage) 58 | } 59 | 60 | // Int64 defines an int64 flag with specified name, default value, and usage string. 61 | // The return value is the address of an int64 variable that stores the value of the flag. 62 | func (f *FlagSet) Int64(name string, value int64, usage string) *int64 { 63 | p := new(int64) 64 | f.Int64VarP(p, name, "", value, usage) 65 | return p 66 | } 67 | 68 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 69 | func (f *FlagSet) Int64P(name, shorthand string, value int64, usage string) *int64 { 70 | p := new(int64) 71 | f.Int64VarP(p, name, shorthand, value, usage) 72 | return p 73 | } 74 | 75 | // Int64 defines an int64 flag with specified name, default value, and usage string. 76 | // The return value is the address of an int64 variable that stores the value of the flag. 77 | func Int64(name string, value int64, usage string) *int64 { 78 | return CommandLine.Int64P(name, "", value, usage) 79 | } 80 | 81 | // Int64P is like Int64, but accepts a shorthand letter that can be used after a single dash. 82 | func Int64P(name, shorthand string, value int64, usage string) *int64 { 83 | return CommandLine.Int64P(name, shorthand, value, usage) 84 | } 85 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/int8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- int8 Value 6 | type int8Value int8 7 | 8 | func newInt8Value(val int8, p *int8) *int8Value { 9 | *p = val 10 | return (*int8Value)(p) 11 | } 12 | 13 | func (i *int8Value) Set(s string) error { 14 | v, err := strconv.ParseInt(s, 0, 8) 15 | *i = int8Value(v) 16 | return err 17 | } 18 | 19 | func (i *int8Value) Type() string { 20 | return "int8" 21 | } 22 | 23 | func (i *int8Value) String() string { return strconv.FormatInt(int64(*i), 10) } 24 | 25 | func int8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseInt(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return int8(v), nil 31 | } 32 | 33 | // GetInt8 return the int8 value of a flag with the given name 34 | func (f *FlagSet) GetInt8(name string) (int8, error) { 35 | val, err := f.getFlagType(name, "int8", int8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(int8), nil 40 | } 41 | 42 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 43 | // The argument p points to an int8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Int8Var(p *int8, name string, value int8, usage string) { 45 | f.VarP(newInt8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 50 | f.VarP(newInt8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Int8Var defines an int8 flag with specified name, default value, and usage string. 54 | // The argument p points to an int8 variable in which to store the value of the flag. 55 | func Int8Var(p *int8, name string, value int8, usage string) { 56 | CommandLine.VarP(newInt8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Int8VarP is like Int8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Int8VarP(p *int8, name, shorthand string, value int8, usage string) { 61 | CommandLine.VarP(newInt8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Int8 defines an int8 flag with specified name, default value, and usage string. 65 | // The return value is the address of an int8 variable that stores the value of the flag. 66 | func (f *FlagSet) Int8(name string, value int8, usage string) *int8 { 67 | p := new(int8) 68 | f.Int8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Int8P(name, shorthand string, value int8, usage string) *int8 { 74 | p := new(int8) 75 | f.Int8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Int8 defines an int8 flag with specified name, default value, and usage string. 80 | // The return value is the address of an int8 variable that stores the value of the flag. 81 | func Int8(name string, value int8, usage string) *int8 { 82 | return CommandLine.Int8P(name, "", value, usage) 83 | } 84 | 85 | // Int8P is like Int8, but accepts a shorthand letter that can be used after a single dash. 86 | func Int8P(name, shorthand string, value int8, usage string) *int8 { 87 | return CommandLine.Int8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ip.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // -- net.IP value 10 | type ipValue net.IP 11 | 12 | func newIPValue(val net.IP, p *net.IP) *ipValue { 13 | *p = val 14 | return (*ipValue)(p) 15 | } 16 | 17 | func (i *ipValue) String() string { return net.IP(*i).String() } 18 | func (i *ipValue) Set(s string) error { 19 | ip := net.ParseIP(strings.TrimSpace(s)) 20 | if ip == nil { 21 | return fmt.Errorf("failed to parse IP: %q", s) 22 | } 23 | *i = ipValue(ip) 24 | return nil 25 | } 26 | 27 | func (i *ipValue) Type() string { 28 | return "ip" 29 | } 30 | 31 | func ipConv(sval string) (interface{}, error) { 32 | ip := net.ParseIP(sval) 33 | if ip != nil { 34 | return ip, nil 35 | } 36 | return nil, fmt.Errorf("invalid string being converted to IP address: %s", sval) 37 | } 38 | 39 | // GetIP return the net.IP value of a flag with the given name 40 | func (f *FlagSet) GetIP(name string) (net.IP, error) { 41 | val, err := f.getFlagType(name, "ip", ipConv) 42 | if err != nil { 43 | return nil, err 44 | } 45 | return val.(net.IP), nil 46 | } 47 | 48 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 49 | // The argument p points to an net.IP variable in which to store the value of the flag. 50 | func (f *FlagSet) IPVar(p *net.IP, name string, value net.IP, usage string) { 51 | f.VarP(newIPValue(value, p), name, "", usage) 52 | } 53 | 54 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 55 | func (f *FlagSet) IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 56 | f.VarP(newIPValue(value, p), name, shorthand, usage) 57 | } 58 | 59 | // IPVar defines an net.IP flag with specified name, default value, and usage string. 60 | // The argument p points to an net.IP variable in which to store the value of the flag. 61 | func IPVar(p *net.IP, name string, value net.IP, usage string) { 62 | CommandLine.VarP(newIPValue(value, p), name, "", usage) 63 | } 64 | 65 | // IPVarP is like IPVar, but accepts a shorthand letter that can be used after a single dash. 66 | func IPVarP(p *net.IP, name, shorthand string, value net.IP, usage string) { 67 | CommandLine.VarP(newIPValue(value, p), name, shorthand, usage) 68 | } 69 | 70 | // IP defines an net.IP flag with specified name, default value, and usage string. 71 | // The return value is the address of an net.IP variable that stores the value of the flag. 72 | func (f *FlagSet) IP(name string, value net.IP, usage string) *net.IP { 73 | p := new(net.IP) 74 | f.IPVarP(p, name, "", value, usage) 75 | return p 76 | } 77 | 78 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 79 | func (f *FlagSet) IPP(name, shorthand string, value net.IP, usage string) *net.IP { 80 | p := new(net.IP) 81 | f.IPVarP(p, name, shorthand, value, usage) 82 | return p 83 | } 84 | 85 | // IP defines an net.IP flag with specified name, default value, and usage string. 86 | // The return value is the address of an net.IP variable that stores the value of the flag. 87 | func IP(name string, value net.IP, usage string) *net.IP { 88 | return CommandLine.IPP(name, "", value, usage) 89 | } 90 | 91 | // IPP is like IP, but accepts a shorthand letter that can be used after a single dash. 92 | func IPP(name, shorthand string, value net.IP, usage string) *net.IP { 93 | return CommandLine.IPP(name, shorthand, value, usage) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/ipnet.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "strings" 7 | ) 8 | 9 | // IPNet adapts net.IPNet for use as a flag. 10 | type ipNetValue net.IPNet 11 | 12 | func (ipnet ipNetValue) String() string { 13 | n := net.IPNet(ipnet) 14 | return n.String() 15 | } 16 | 17 | func (ipnet *ipNetValue) Set(value string) error { 18 | _, n, err := net.ParseCIDR(strings.TrimSpace(value)) 19 | if err != nil { 20 | return err 21 | } 22 | *ipnet = ipNetValue(*n) 23 | return nil 24 | } 25 | 26 | func (*ipNetValue) Type() string { 27 | return "ipNet" 28 | } 29 | 30 | func newIPNetValue(val net.IPNet, p *net.IPNet) *ipNetValue { 31 | *p = val 32 | return (*ipNetValue)(p) 33 | } 34 | 35 | func ipNetConv(sval string) (interface{}, error) { 36 | _, n, err := net.ParseCIDR(strings.TrimSpace(sval)) 37 | if err == nil { 38 | return *n, nil 39 | } 40 | return nil, fmt.Errorf("invalid string being converted to IPNet: %s", sval) 41 | } 42 | 43 | // GetIPNet return the net.IPNet value of a flag with the given name 44 | func (f *FlagSet) GetIPNet(name string) (net.IPNet, error) { 45 | val, err := f.getFlagType(name, "ipNet", ipNetConv) 46 | if err != nil { 47 | return net.IPNet{}, err 48 | } 49 | return val.(net.IPNet), nil 50 | } 51 | 52 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 53 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 54 | func (f *FlagSet) IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 55 | f.VarP(newIPNetValue(value, p), name, "", usage) 56 | } 57 | 58 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 59 | func (f *FlagSet) IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 60 | f.VarP(newIPNetValue(value, p), name, shorthand, usage) 61 | } 62 | 63 | // IPNetVar defines an net.IPNet flag with specified name, default value, and usage string. 64 | // The argument p points to an net.IPNet variable in which to store the value of the flag. 65 | func IPNetVar(p *net.IPNet, name string, value net.IPNet, usage string) { 66 | CommandLine.VarP(newIPNetValue(value, p), name, "", usage) 67 | } 68 | 69 | // IPNetVarP is like IPNetVar, but accepts a shorthand letter that can be used after a single dash. 70 | func IPNetVarP(p *net.IPNet, name, shorthand string, value net.IPNet, usage string) { 71 | CommandLine.VarP(newIPNetValue(value, p), name, shorthand, usage) 72 | } 73 | 74 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 75 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 76 | func (f *FlagSet) IPNet(name string, value net.IPNet, usage string) *net.IPNet { 77 | p := new(net.IPNet) 78 | f.IPNetVarP(p, name, "", value, usage) 79 | return p 80 | } 81 | 82 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 83 | func (f *FlagSet) IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 84 | p := new(net.IPNet) 85 | f.IPNetVarP(p, name, shorthand, value, usage) 86 | return p 87 | } 88 | 89 | // IPNet defines an net.IPNet flag with specified name, default value, and usage string. 90 | // The return value is the address of an net.IPNet variable that stores the value of the flag. 91 | func IPNet(name string, value net.IPNet, usage string) *net.IPNet { 92 | return CommandLine.IPNetP(name, "", value, usage) 93 | } 94 | 95 | // IPNetP is like IPNet, but accepts a shorthand letter that can be used after a single dash. 96 | func IPNetP(name, shorthand string, value net.IPNet, usage string) *net.IPNet { 97 | return CommandLine.IPNetP(name, shorthand, value, usage) 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/string.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | // -- string Value 4 | type stringValue string 5 | 6 | func newStringValue(val string, p *string) *stringValue { 7 | *p = val 8 | return (*stringValue)(p) 9 | } 10 | 11 | func (s *stringValue) Set(val string) error { 12 | *s = stringValue(val) 13 | return nil 14 | } 15 | func (s *stringValue) Type() string { 16 | return "string" 17 | } 18 | 19 | func (s *stringValue) String() string { return string(*s) } 20 | 21 | func stringConv(sval string) (interface{}, error) { 22 | return sval, nil 23 | } 24 | 25 | // GetString return the string value of a flag with the given name 26 | func (f *FlagSet) GetString(name string) (string, error) { 27 | val, err := f.getFlagType(name, "string", stringConv) 28 | if err != nil { 29 | return "", err 30 | } 31 | return val.(string), nil 32 | } 33 | 34 | // StringVar defines a string flag with specified name, default value, and usage string. 35 | // The argument p points to a string variable in which to store the value of the flag. 36 | func (f *FlagSet) StringVar(p *string, name string, value string, usage string) { 37 | f.VarP(newStringValue(value, p), name, "", usage) 38 | } 39 | 40 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 41 | func (f *FlagSet) StringVarP(p *string, name, shorthand string, value string, usage string) { 42 | f.VarP(newStringValue(value, p), name, shorthand, usage) 43 | } 44 | 45 | // StringVar defines a string flag with specified name, default value, and usage string. 46 | // The argument p points to a string variable in which to store the value of the flag. 47 | func StringVar(p *string, name string, value string, usage string) { 48 | CommandLine.VarP(newStringValue(value, p), name, "", usage) 49 | } 50 | 51 | // StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash. 52 | func StringVarP(p *string, name, shorthand string, value string, usage string) { 53 | CommandLine.VarP(newStringValue(value, p), name, shorthand, usage) 54 | } 55 | 56 | // String defines a string flag with specified name, default value, and usage string. 57 | // The return value is the address of a string variable that stores the value of the flag. 58 | func (f *FlagSet) String(name string, value string, usage string) *string { 59 | p := new(string) 60 | f.StringVarP(p, name, "", value, usage) 61 | return p 62 | } 63 | 64 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 65 | func (f *FlagSet) StringP(name, shorthand string, value string, usage string) *string { 66 | p := new(string) 67 | f.StringVarP(p, name, shorthand, value, usage) 68 | return p 69 | } 70 | 71 | // String defines a string flag with specified name, default value, and usage string. 72 | // The return value is the address of a string variable that stores the value of the flag. 73 | func String(name string, value string, usage string) *string { 74 | return CommandLine.StringP(name, "", value, usage) 75 | } 76 | 77 | // StringP is like String, but accepts a shorthand letter that can be used after a single dash. 78 | func StringP(name, shorthand string, value string, usage string) *string { 79 | return CommandLine.StringP(name, shorthand, value, usage) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint Value 6 | type uintValue uint 7 | 8 | func newUintValue(val uint, p *uint) *uintValue { 9 | *p = val 10 | return (*uintValue)(p) 11 | } 12 | 13 | func (i *uintValue) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uintValue(v) 16 | return err 17 | } 18 | 19 | func (i *uintValue) Type() string { 20 | return "uint" 21 | } 22 | 23 | func (i *uintValue) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uintConv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 0) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint(v), nil 31 | } 32 | 33 | // GetUint return the uint value of a flag with the given name 34 | func (f *FlagSet) GetUint(name string) (uint, error) { 35 | val, err := f.getFlagType(name, "uint", uintConv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint), nil 40 | } 41 | 42 | // UintVar defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) UintVar(p *uint, name string, value uint, usage string) { 45 | f.VarP(newUintValue(value, p), name, "", usage) 46 | } 47 | 48 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) UintVarP(p *uint, name, shorthand string, value uint, usage string) { 50 | f.VarP(newUintValue(value, p), name, shorthand, usage) 51 | } 52 | 53 | // UintVar defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func UintVar(p *uint, name string, value uint, usage string) { 56 | CommandLine.VarP(newUintValue(value, p), name, "", usage) 57 | } 58 | 59 | // UintVarP is like UintVar, but accepts a shorthand letter that can be used after a single dash. 60 | func UintVarP(p *uint, name, shorthand string, value uint, usage string) { 61 | CommandLine.VarP(newUintValue(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint(name string, value uint, usage string) *uint { 67 | p := new(uint) 68 | f.UintVarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) UintP(name, shorthand string, value uint, usage string) *uint { 74 | p := new(uint) 75 | f.UintVarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint(name string, value uint, usage string) *uint { 82 | return CommandLine.UintP(name, "", value, usage) 83 | } 84 | 85 | // UintP is like Uint, but accepts a shorthand letter that can be used after a single dash. 86 | func UintP(name, shorthand string, value uint, usage string) *uint { 87 | return CommandLine.UintP(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint16.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint16 value 6 | type uint16Value uint16 7 | 8 | func newUint16Value(val uint16, p *uint16) *uint16Value { 9 | *p = val 10 | return (*uint16Value)(p) 11 | } 12 | 13 | func (i *uint16Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 16) 15 | *i = uint16Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint16Value) Type() string { 20 | return "uint16" 21 | } 22 | 23 | func (i *uint16Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint16Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 16) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint16(v), nil 31 | } 32 | 33 | // GetUint16 return the uint16 value of a flag with the given name 34 | func (f *FlagSet) GetUint16(name string) (uint16, error) { 35 | val, err := f.getFlagType(name, "uint16", uint16Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint16), nil 40 | } 41 | 42 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 43 | // The argument p points to a uint variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint16Var(p *uint16, name string, value uint16, usage string) { 45 | f.VarP(newUint16Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 50 | f.VarP(newUint16Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint16Var defines a uint flag with specified name, default value, and usage string. 54 | // The argument p points to a uint variable in which to store the value of the flag. 55 | func Uint16Var(p *uint16, name string, value uint16, usage string) { 56 | CommandLine.VarP(newUint16Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint16VarP is like Uint16Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint16VarP(p *uint16, name, shorthand string, value uint16, usage string) { 61 | CommandLine.VarP(newUint16Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint16 defines a uint flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint variable that stores the value of the flag. 66 | func (f *FlagSet) Uint16(name string, value uint16, usage string) *uint16 { 67 | p := new(uint16) 68 | f.Uint16VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 74 | p := new(uint16) 75 | f.Uint16VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint16 defines a uint flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint variable that stores the value of the flag. 81 | func Uint16(name string, value uint16, usage string) *uint16 { 82 | return CommandLine.Uint16P(name, "", value, usage) 83 | } 84 | 85 | // Uint16P is like Uint16, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint16P(name, shorthand string, value uint16, usage string) *uint16 { 87 | return CommandLine.Uint16P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint32.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint32 value 6 | type uint32Value uint32 7 | 8 | func newUint32Value(val uint32, p *uint32) *uint32Value { 9 | *p = val 10 | return (*uint32Value)(p) 11 | } 12 | 13 | func (i *uint32Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 32) 15 | *i = uint32Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint32Value) Type() string { 20 | return "uint32" 21 | } 22 | 23 | func (i *uint32Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint32Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 32) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint32(v), nil 31 | } 32 | 33 | // GetUint32 return the uint32 value of a flag with the given name 34 | func (f *FlagSet) GetUint32(name string) (uint32, error) { 35 | val, err := f.getFlagType(name, "uint32", uint32Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint32), nil 40 | } 41 | 42 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint32 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint32Var(p *uint32, name string, value uint32, usage string) { 45 | f.VarP(newUint32Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 50 | f.VarP(newUint32Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint32Var defines a uint32 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint32 variable in which to store the value of the flag. 55 | func Uint32Var(p *uint32, name string, value uint32, usage string) { 56 | CommandLine.VarP(newUint32Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint32VarP is like Uint32Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint32VarP(p *uint32, name, shorthand string, value uint32, usage string) { 61 | CommandLine.VarP(newUint32Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint32 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint32(name string, value uint32, usage string) *uint32 { 67 | p := new(uint32) 68 | f.Uint32VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 74 | p := new(uint32) 75 | f.Uint32VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint32 defines a uint32 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint32 variable that stores the value of the flag. 81 | func Uint32(name string, value uint32, usage string) *uint32 { 82 | return CommandLine.Uint32P(name, "", value, usage) 83 | } 84 | 85 | // Uint32P is like Uint32, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint32P(name, shorthand string, value uint32, usage string) *uint32 { 87 | return CommandLine.Uint32P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint64.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint64 Value 6 | type uint64Value uint64 7 | 8 | func newUint64Value(val uint64, p *uint64) *uint64Value { 9 | *p = val 10 | return (*uint64Value)(p) 11 | } 12 | 13 | func (i *uint64Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 64) 15 | *i = uint64Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint64Value) Type() string { 20 | return "uint64" 21 | } 22 | 23 | func (i *uint64Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint64Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 64) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint64(v), nil 31 | } 32 | 33 | // GetUint64 return the uint64 value of a flag with the given name 34 | func (f *FlagSet) GetUint64(name string) (uint64, error) { 35 | val, err := f.getFlagType(name, "uint64", uint64Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint64), nil 40 | } 41 | 42 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint64 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint64Var(p *uint64, name string, value uint64, usage string) { 45 | f.VarP(newUint64Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 50 | f.VarP(newUint64Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint64Var defines a uint64 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint64 variable in which to store the value of the flag. 55 | func Uint64Var(p *uint64, name string, value uint64, usage string) { 56 | CommandLine.VarP(newUint64Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint64VarP is like Uint64Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint64VarP(p *uint64, name, shorthand string, value uint64, usage string) { 61 | CommandLine.VarP(newUint64Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint64 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint64(name string, value uint64, usage string) *uint64 { 67 | p := new(uint64) 68 | f.Uint64VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 74 | p := new(uint64) 75 | f.Uint64VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint64 defines a uint64 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint64 variable that stores the value of the flag. 81 | func Uint64(name string, value uint64, usage string) *uint64 { 82 | return CommandLine.Uint64P(name, "", value, usage) 83 | } 84 | 85 | // Uint64P is like Uint64, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint64P(name, shorthand string, value uint64, usage string) *uint64 { 87 | return CommandLine.Uint64P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/spf13/pflag/uint8.go: -------------------------------------------------------------------------------- 1 | package pflag 2 | 3 | import "strconv" 4 | 5 | // -- uint8 Value 6 | type uint8Value uint8 7 | 8 | func newUint8Value(val uint8, p *uint8) *uint8Value { 9 | *p = val 10 | return (*uint8Value)(p) 11 | } 12 | 13 | func (i *uint8Value) Set(s string) error { 14 | v, err := strconv.ParseUint(s, 0, 8) 15 | *i = uint8Value(v) 16 | return err 17 | } 18 | 19 | func (i *uint8Value) Type() string { 20 | return "uint8" 21 | } 22 | 23 | func (i *uint8Value) String() string { return strconv.FormatUint(uint64(*i), 10) } 24 | 25 | func uint8Conv(sval string) (interface{}, error) { 26 | v, err := strconv.ParseUint(sval, 0, 8) 27 | if err != nil { 28 | return 0, err 29 | } 30 | return uint8(v), nil 31 | } 32 | 33 | // GetUint8 return the uint8 value of a flag with the given name 34 | func (f *FlagSet) GetUint8(name string) (uint8, error) { 35 | val, err := f.getFlagType(name, "uint8", uint8Conv) 36 | if err != nil { 37 | return 0, err 38 | } 39 | return val.(uint8), nil 40 | } 41 | 42 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 43 | // The argument p points to a uint8 variable in which to store the value of the flag. 44 | func (f *FlagSet) Uint8Var(p *uint8, name string, value uint8, usage string) { 45 | f.VarP(newUint8Value(value, p), name, "", usage) 46 | } 47 | 48 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 49 | func (f *FlagSet) Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 50 | f.VarP(newUint8Value(value, p), name, shorthand, usage) 51 | } 52 | 53 | // Uint8Var defines a uint8 flag with specified name, default value, and usage string. 54 | // The argument p points to a uint8 variable in which to store the value of the flag. 55 | func Uint8Var(p *uint8, name string, value uint8, usage string) { 56 | CommandLine.VarP(newUint8Value(value, p), name, "", usage) 57 | } 58 | 59 | // Uint8VarP is like Uint8Var, but accepts a shorthand letter that can be used after a single dash. 60 | func Uint8VarP(p *uint8, name, shorthand string, value uint8, usage string) { 61 | CommandLine.VarP(newUint8Value(value, p), name, shorthand, usage) 62 | } 63 | 64 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 65 | // The return value is the address of a uint8 variable that stores the value of the flag. 66 | func (f *FlagSet) Uint8(name string, value uint8, usage string) *uint8 { 67 | p := new(uint8) 68 | f.Uint8VarP(p, name, "", value, usage) 69 | return p 70 | } 71 | 72 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 73 | func (f *FlagSet) Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 74 | p := new(uint8) 75 | f.Uint8VarP(p, name, shorthand, value, usage) 76 | return p 77 | } 78 | 79 | // Uint8 defines a uint8 flag with specified name, default value, and usage string. 80 | // The return value is the address of a uint8 variable that stores the value of the flag. 81 | func Uint8(name string, value uint8, usage string) *uint8 { 82 | return CommandLine.Uint8P(name, "", value, usage) 83 | } 84 | 85 | // Uint8P is like Uint8, but accepts a shorthand letter that can be used after a single dash. 86 | func Uint8P(name, shorthand string, value uint8, usage string) *uint8 { 87 | return CommandLine.Uint8P(name, shorthand, value, usage) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/.gitignore: -------------------------------------------------------------------------------- 1 | /dep 2 | /testdep 3 | /profile.out 4 | /coverage.txt 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.8 4 | - 1.9 5 | - tip 6 | 7 | install: 8 | - go get github.com/go-task/task/cmd/task 9 | 10 | script: 11 | - task dl-deps 12 | - task lint 13 | - task test 14 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/davecgh/go-spew" 6 | packages = ["spew"] 7 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 8 | version = "v1.1.0" 9 | 10 | [[projects]] 11 | name = "github.com/pmezard/go-difflib" 12 | packages = ["difflib"] 13 | revision = "792786c7400a136282c1664665ae0a8db921c6c2" 14 | version = "v1.0.0" 15 | 16 | [[projects]] 17 | name = "github.com/stretchr/testify" 18 | packages = ["assert"] 19 | revision = "b91bfb9ebec76498946beb6af7c0230c7cc7ba6c" 20 | version = "v1.2.0" 21 | 22 | [solve-meta] 23 | analyzer-name = "dep" 24 | analyzer-version = 1 25 | inputs-digest = "50e2495ec1af6e2f7ffb2f3551e4300d30357d7c7fe38ff6056469fa9cfb3673" 26 | solver-name = "gps-cdcl" 27 | solver-version = 1 28 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "github.com/stretchr/testify" 3 | version = "~1.2.0" 4 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 Stretchr, Inc. 4 | Copyright (c) 2017-2018 objx contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/README.md: -------------------------------------------------------------------------------- 1 | # Objx 2 | [![Build Status](https://travis-ci.org/stretchr/objx.svg?branch=master)](https://travis-ci.org/stretchr/objx) 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/objx)](https://goreportcard.com/report/github.com/stretchr/objx) 4 | [![Sourcegraph](https://sourcegraph.com/github.com/stretchr/objx/-/badge.svg)](https://sourcegraph.com/github.com/stretchr/objx) 5 | [![GoDoc](https://godoc.org/github.com/stretchr/objx?status.svg)](https://godoc.org/github.com/stretchr/objx) 6 | 7 | Objx - Go package for dealing with maps, slices, JSON and other data. 8 | 9 | Get started: 10 | 11 | - Install Objx with [one line of code](#installation), or [update it with another](#staying-up-to-date) 12 | - Check out the API Documentation http://godoc.org/github.com/stretchr/objx 13 | 14 | ## Overview 15 | Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes a powerful `Get` method (among others) that allows you to easily and quickly get access to data within the map, without having to worry too much about type assertions, missing data, default values etc. 16 | 17 | ### Pattern 18 | Objx uses a preditable pattern to make access data from within `map[string]interface{}` easy. Call one of the `objx.` functions to create your `objx.Map` to get going: 19 | 20 | m, err := objx.FromJSON(json) 21 | 22 | NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong, the rest will be optimistic and try to figure things out without panicking. 23 | 24 | Use `Get` to access the value you're interested in. You can use dot and array 25 | notation too: 26 | 27 | m.Get("places[0].latlng") 28 | 29 | Once you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type. 30 | 31 | if m.Get("code").IsStr() { // Your code... } 32 | 33 | Or you can just assume the type, and use one of the strong type methods to extract the real value: 34 | 35 | m.Get("code").Int() 36 | 37 | If there's no value there (or if it's the wrong type) then a default value will be returned, or you can be explicit about the default value. 38 | 39 | Get("code").Int(-1) 40 | 41 | If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, manipulating and selecting that data. You can find out more by exploring the index below. 42 | 43 | ### Reading data 44 | A simple example of how to use Objx: 45 | 46 | // Use MustFromJSON to make an objx.Map from some JSON 47 | m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`) 48 | 49 | // Get the details 50 | name := m.Get("name").Str() 51 | age := m.Get("age").Int() 52 | 53 | // Get their nickname (or use their name if they don't have one) 54 | nickname := m.Get("nickname").Str(name) 55 | 56 | ### Ranging 57 | Since `objx.Map` is a `map[string]interface{}` you can treat it as such. For example, to `range` the data, do what you would expect: 58 | 59 | m := objx.MustFromJSON(json) 60 | for key, value := range m { 61 | // Your code... 62 | } 63 | 64 | ## Installation 65 | To install Objx, use go get: 66 | 67 | go get github.com/stretchr/objx 68 | 69 | ### Staying up to date 70 | To update Objx to the latest version, run: 71 | 72 | go get -u github.com/stretchr/objx 73 | 74 | ### Supported go versions 75 | We support the lastest two major Go versions, which are 1.8 and 1.9 at the moment. 76 | 77 | ## Contributing 78 | Please feel free to submit issues, fork the repository and send pull requests! 79 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/Taskfile.yml: -------------------------------------------------------------------------------- 1 | default: 2 | deps: [test] 3 | 4 | dl-deps: 5 | desc: Downloads cli dependencies 6 | cmds: 7 | - go get -u github.com/golang/lint/golint 8 | - go get -u github.com/golang/dep/cmd/dep 9 | 10 | update-deps: 11 | desc: Updates dependencies 12 | cmds: 13 | - dep ensure 14 | - dep ensure -update 15 | - dep prune 16 | 17 | lint: 18 | desc: Runs golint 19 | cmds: 20 | - golint $(ls *.go | grep -v "doc.go") 21 | silent: true 22 | 23 | test: 24 | desc: Runs go tests 25 | cmds: 26 | - go test -race . 27 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/constants.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | const ( 4 | // PathSeparator is the character used to separate the elements 5 | // of the keypath. 6 | // 7 | // For example, `location.address.city` 8 | PathSeparator string = "." 9 | 10 | // SignatureSeparator is the character that is used to 11 | // separate the Base64 string from the security signature. 12 | SignatureSeparator = "_" 13 | ) 14 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/conversions.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | import ( 4 | "bytes" 5 | "encoding/base64" 6 | "encoding/json" 7 | "errors" 8 | "fmt" 9 | "net/url" 10 | ) 11 | 12 | // JSON converts the contained object to a JSON string 13 | // representation 14 | func (m Map) JSON() (string, error) { 15 | result, err := json.Marshal(m) 16 | if err != nil { 17 | err = errors.New("objx: JSON encode failed with: " + err.Error()) 18 | } 19 | return string(result), err 20 | } 21 | 22 | // MustJSON converts the contained object to a JSON string 23 | // representation and panics if there is an error 24 | func (m Map) MustJSON() string { 25 | result, err := m.JSON() 26 | if err != nil { 27 | panic(err.Error()) 28 | } 29 | return result 30 | } 31 | 32 | // Base64 converts the contained object to a Base64 string 33 | // representation of the JSON string representation 34 | func (m Map) Base64() (string, error) { 35 | var buf bytes.Buffer 36 | 37 | jsonData, err := m.JSON() 38 | if err != nil { 39 | return "", err 40 | } 41 | 42 | encoder := base64.NewEncoder(base64.StdEncoding, &buf) 43 | _, err = encoder.Write([]byte(jsonData)) 44 | if err != nil { 45 | return "", err 46 | } 47 | _ = encoder.Close() 48 | 49 | return buf.String(), nil 50 | } 51 | 52 | // MustBase64 converts the contained object to a Base64 string 53 | // representation of the JSON string representation and panics 54 | // if there is an error 55 | func (m Map) MustBase64() string { 56 | result, err := m.Base64() 57 | if err != nil { 58 | panic(err.Error()) 59 | } 60 | return result 61 | } 62 | 63 | // SignedBase64 converts the contained object to a Base64 string 64 | // representation of the JSON string representation and signs it 65 | // using the provided key. 66 | func (m Map) SignedBase64(key string) (string, error) { 67 | base64, err := m.Base64() 68 | if err != nil { 69 | return "", err 70 | } 71 | 72 | sig := HashWithKey(base64, key) 73 | return base64 + SignatureSeparator + sig, nil 74 | } 75 | 76 | // MustSignedBase64 converts the contained object to a Base64 string 77 | // representation of the JSON string representation and signs it 78 | // using the provided key and panics if there is an error 79 | func (m Map) MustSignedBase64(key string) string { 80 | result, err := m.SignedBase64(key) 81 | if err != nil { 82 | panic(err.Error()) 83 | } 84 | return result 85 | } 86 | 87 | /* 88 | URL Query 89 | ------------------------------------------------ 90 | */ 91 | 92 | // URLValues creates a url.Values object from an Obj. This 93 | // function requires that the wrapped object be a map[string]interface{} 94 | func (m Map) URLValues() url.Values { 95 | vals := make(url.Values) 96 | for k, v := range m { 97 | //TODO: can this be done without sprintf? 98 | vals.Set(k, fmt.Sprintf("%v", v)) 99 | } 100 | return vals 101 | } 102 | 103 | // URLQuery gets an encoded URL query representing the given 104 | // Obj. This function requires that the wrapped object be a 105 | // map[string]interface{} 106 | func (m Map) URLQuery() (string, error) { 107 | return m.URLValues().Encode(), nil 108 | } 109 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Objx - Go package for dealing with maps, slices, JSON and other data. 3 | 4 | Overview 5 | 6 | Objx provides the `objx.Map` type, which is a `map[string]interface{}` that exposes 7 | a powerful `Get` method (among others) that allows you to easily and quickly get 8 | access to data within the map, without having to worry too much about type assertions, 9 | missing data, default values etc. 10 | 11 | Pattern 12 | 13 | Objx uses a preditable pattern to make access data from within `map[string]interface{}` easy. 14 | Call one of the `objx.` functions to create your `objx.Map` to get going: 15 | 16 | m, err := objx.FromJSON(json) 17 | 18 | NOTE: Any methods or functions with the `Must` prefix will panic if something goes wrong, 19 | the rest will be optimistic and try to figure things out without panicking. 20 | 21 | Use `Get` to access the value you're interested in. You can use dot and array 22 | notation too: 23 | 24 | m.Get("places[0].latlng") 25 | 26 | Once you have sought the `Value` you're interested in, you can use the `Is*` methods to determine its type. 27 | 28 | if m.Get("code").IsStr() { // Your code... } 29 | 30 | Or you can just assume the type, and use one of the strong type methods to extract the real value: 31 | 32 | m.Get("code").Int() 33 | 34 | If there's no value there (or if it's the wrong type) then a default value will be returned, 35 | or you can be explicit about the default value. 36 | 37 | Get("code").Int(-1) 38 | 39 | If you're dealing with a slice of data as a value, Objx provides many useful methods for iterating, 40 | manipulating and selecting that data. You can find out more by exploring the index below. 41 | 42 | Reading data 43 | 44 | A simple example of how to use Objx: 45 | 46 | // Use MustFromJSON to make an objx.Map from some JSON 47 | m := objx.MustFromJSON(`{"name": "Mat", "age": 30}`) 48 | 49 | // Get the details 50 | name := m.Get("name").Str() 51 | age := m.Get("age").Int() 52 | 53 | // Get their nickname (or use their name if they don't have one) 54 | nickname := m.Get("nickname").Str(name) 55 | 56 | Ranging 57 | 58 | Since `objx.Map` is a `map[string]interface{}` you can treat it as such. 59 | For example, to `range` the data, do what you would expect: 60 | 61 | m := objx.MustFromJSON(json) 62 | for key, value := range m { 63 | // Your code... 64 | } 65 | */ 66 | package objx 67 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/mutations.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | // Exclude returns a new Map with the keys in the specified []string 4 | // excluded. 5 | func (m Map) Exclude(exclude []string) Map { 6 | excluded := make(Map) 7 | for k, v := range m { 8 | var shouldInclude = true 9 | for _, toExclude := range exclude { 10 | if k == toExclude { 11 | shouldInclude = false 12 | break 13 | } 14 | } 15 | if shouldInclude { 16 | excluded[k] = v 17 | } 18 | } 19 | return excluded 20 | } 21 | 22 | // Copy creates a shallow copy of the Obj. 23 | func (m Map) Copy() Map { 24 | copied := make(map[string]interface{}) 25 | for k, v := range m { 26 | copied[k] = v 27 | } 28 | return New(copied) 29 | } 30 | 31 | // Merge blends the specified map with a copy of this map and returns the result. 32 | // 33 | // Keys that appear in both will be selected from the specified map. 34 | // This method requires that the wrapped object be a map[string]interface{} 35 | func (m Map) Merge(merge Map) Map { 36 | return m.Copy().MergeHere(merge) 37 | } 38 | 39 | // MergeHere blends the specified map with this map and returns the current map. 40 | // 41 | // Keys that appear in both will be selected from the specified map. The original map 42 | // will be modified. This method requires that 43 | // the wrapped object be a map[string]interface{} 44 | func (m Map) MergeHere(merge Map) Map { 45 | for k, v := range merge { 46 | m[k] = v 47 | } 48 | return m 49 | } 50 | 51 | // Transform builds a new Obj giving the transformer a chance 52 | // to change the keys and values as it goes. This method requires that 53 | // the wrapped object be a map[string]interface{} 54 | func (m Map) Transform(transformer func(key string, value interface{}) (string, interface{})) Map { 55 | newMap := make(map[string]interface{}) 56 | for k, v := range m { 57 | modifiedKey, modifiedVal := transformer(k, v) 58 | newMap[modifiedKey] = modifiedVal 59 | } 60 | return New(newMap) 61 | } 62 | 63 | // TransformKeys builds a new map using the specified key mapping. 64 | // 65 | // Unspecified keys will be unaltered. 66 | // This method requires that the wrapped object be a map[string]interface{} 67 | func (m Map) TransformKeys(mapping map[string]string) Map { 68 | return m.Transform(func(key string, value interface{}) (string, interface{}) { 69 | if newKey, ok := mapping[key]; ok { 70 | return newKey, value 71 | } 72 | return key, value 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/security.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | import ( 4 | "crypto/sha1" 5 | "encoding/hex" 6 | ) 7 | 8 | // HashWithKey hashes the specified string using the security 9 | // key. 10 | func HashWithKey(data, key string) string { 11 | hash := sha1.New() 12 | _, err := hash.Write([]byte(data + ":" + key)) 13 | if err != nil { 14 | return "" 15 | } 16 | return hex.EncodeToString(hash.Sum(nil)) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/tests.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | // Has gets whether there is something at the specified selector 4 | // or not. 5 | // 6 | // If m is nil, Has will always return false. 7 | func (m Map) Has(selector string) bool { 8 | if m == nil { 9 | return false 10 | } 11 | return !m.Get(selector).IsNil() 12 | } 13 | 14 | // IsNil gets whether the data is nil or not. 15 | func (v *Value) IsNil() bool { 16 | return v == nil || v.data == nil 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/objx/value.go: -------------------------------------------------------------------------------- 1 | package objx 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | // Value provides methods for extracting interface{} data in various 9 | // types. 10 | type Value struct { 11 | // data contains the raw data being managed by this Value 12 | data interface{} 13 | } 14 | 15 | // Data returns the raw data contained by this Value 16 | func (v *Value) Data() interface{} { 17 | return v.data 18 | } 19 | 20 | // String returns the value always as a string 21 | func (v *Value) String() string { 22 | switch { 23 | case v.IsStr(): 24 | return v.Str() 25 | case v.IsBool(): 26 | return strconv.FormatBool(v.Bool()) 27 | case v.IsFloat32(): 28 | return strconv.FormatFloat(float64(v.Float32()), 'f', -1, 32) 29 | case v.IsFloat64(): 30 | return strconv.FormatFloat(v.Float64(), 'f', -1, 64) 31 | case v.IsInt(): 32 | return strconv.FormatInt(int64(v.Int()), 10) 33 | case v.IsInt(): 34 | return strconv.FormatInt(int64(v.Int()), 10) 35 | case v.IsInt8(): 36 | return strconv.FormatInt(int64(v.Int8()), 10) 37 | case v.IsInt16(): 38 | return strconv.FormatInt(int64(v.Int16()), 10) 39 | case v.IsInt32(): 40 | return strconv.FormatInt(int64(v.Int32()), 10) 41 | case v.IsInt64(): 42 | return strconv.FormatInt(v.Int64(), 10) 43 | case v.IsUint(): 44 | return strconv.FormatUint(uint64(v.Uint()), 10) 45 | case v.IsUint8(): 46 | return strconv.FormatUint(uint64(v.Uint8()), 10) 47 | case v.IsUint16(): 48 | return strconv.FormatUint(uint64(v.Uint16()), 10) 49 | case v.IsUint32(): 50 | return strconv.FormatUint(uint64(v.Uint32()), 10) 51 | case v.IsUint64(): 52 | return strconv.FormatUint(v.Uint64(), 10) 53 | } 54 | 55 | return fmt.Sprintf("%#v", v.Data()) 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell 2 | 3 | Please consider promoting this project if you find it useful. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without restriction, 8 | including without limitation the rights to use, copy, modify, merge, 9 | publish, distribute, sublicense, and/or sell copies of the Software, 10 | and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included 14 | in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 18 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT 21 | OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 4 | } 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 4 | } 5 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // import ( 7 | // "testing" 8 | // "github.com/stretchr/testify/assert" 9 | // ) 10 | // 11 | // func TestSomething(t *testing.T) { 12 | // 13 | // var a string = "Hello" 14 | // var b string = "Hello" 15 | // 16 | // assert.Equal(t, a, b, "The two words should be the same.") 17 | // 18 | // } 19 | // 20 | // if you assert many times, use the format below: 21 | // 22 | // import ( 23 | // "testing" 24 | // "github.com/stretchr/testify/assert" 25 | // ) 26 | // 27 | // func TestSomething(t *testing.T) { 28 | // assert := assert.New(t) 29 | // 30 | // var a string = "Hello" 31 | // var b string = "Hello" 32 | // 33 | // assert.Equal(a, b, "The two words should be the same.") 34 | // } 35 | // 36 | // Assertions 37 | // 38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 40 | // testing framework. This allows the assertion funcs to write the failings and other details to 41 | // the correct place. 42 | // 43 | // Every assertion function also takes an optional string message as the final argument, 44 | // allowing custom error messages to be appended to the message the assertion method outputs. 45 | package assert 46 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/mock/doc.go: -------------------------------------------------------------------------------- 1 | // Package mock provides a system by which it is possible to mock your objects 2 | // and verify calls are happening as expected. 3 | // 4 | // Example Usage 5 | // 6 | // The mock package provides an object, Mock, that tracks activity on another object. It is usually 7 | // embedded into a test object as shown below: 8 | // 9 | // type MyTestObject struct { 10 | // // add a Mock object instance 11 | // mock.Mock 12 | // 13 | // // other fields go here as normal 14 | // } 15 | // 16 | // When implementing the methods of an interface, you wire your functions up 17 | // to call the Mock.Called(args...) method, and return the appropriate values. 18 | // 19 | // For example, to mock a method that saves the name and age of a person and returns 20 | // the year of their birth or an error, you might write this: 21 | // 22 | // func (o *MyTestObject) SavePersonDetails(firstname, lastname string, age int) (int, error) { 23 | // args := o.Called(firstname, lastname, age) 24 | // return args.Int(0), args.Error(1) 25 | // } 26 | // 27 | // The Int, Error and Bool methods are examples of strongly typed getters that take the argument 28 | // index position. Given this argument list: 29 | // 30 | // (12, true, "Something") 31 | // 32 | // You could read them out strongly typed like this: 33 | // 34 | // args.Int(0) 35 | // args.Bool(1) 36 | // args.String(2) 37 | // 38 | // For objects of your own type, use the generic Arguments.Get(index) method and make a type assertion: 39 | // 40 | // return args.Get(0).(*MyObject), args.Get(1).(*AnotherObjectOfMine) 41 | // 42 | // This may cause a panic if the object you are getting is nil (the type assertion will fail), in those 43 | // cases you should check for nil first. 44 | package mock 45 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at https://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at https://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/const_amd64.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html 7 | 8 | #define REDMASK51 0x0007FFFFFFFFFFFF 9 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/const_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | // These constants cannot be encoded in non-MOVQ immediates. 11 | // We access them directly from memory instead. 12 | 13 | DATA ·_121666_213(SB)/8, $996687872 14 | GLOBL ·_121666_213(SB), 8, $8 15 | 16 | DATA ·_2P0(SB)/8, $0xFFFFFFFFFFFDA 17 | GLOBL ·_2P0(SB), 8, $8 18 | 19 | DATA ·_2P1234(SB)/8, $0xFFFFFFFFFFFFE 20 | GLOBL ·_2P1234(SB), 8, $8 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/cswap_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | // func cswap(inout *[4][5]uint64, v uint64) 8 | TEXT ·cswap(SB),7,$0 9 | MOVQ inout+0(FP),DI 10 | MOVQ v+8(FP),SI 11 | 12 | SUBQ $1, SI 13 | NOTQ SI 14 | MOVQ SI, X15 15 | PSHUFD $0x44, X15, X15 16 | 17 | MOVOU 0(DI), X0 18 | MOVOU 16(DI), X2 19 | MOVOU 32(DI), X4 20 | MOVOU 48(DI), X6 21 | MOVOU 64(DI), X8 22 | MOVOU 80(DI), X1 23 | MOVOU 96(DI), X3 24 | MOVOU 112(DI), X5 25 | MOVOU 128(DI), X7 26 | MOVOU 144(DI), X9 27 | 28 | MOVO X1, X10 29 | MOVO X3, X11 30 | MOVO X5, X12 31 | MOVO X7, X13 32 | MOVO X9, X14 33 | 34 | PXOR X0, X10 35 | PXOR X2, X11 36 | PXOR X4, X12 37 | PXOR X6, X13 38 | PXOR X8, X14 39 | PAND X15, X10 40 | PAND X15, X11 41 | PAND X15, X12 42 | PAND X15, X13 43 | PAND X15, X14 44 | PXOR X10, X0 45 | PXOR X10, X1 46 | PXOR X11, X2 47 | PXOR X11, X3 48 | PXOR X12, X4 49 | PXOR X12, X5 50 | PXOR X13, X6 51 | PXOR X13, X7 52 | PXOR X14, X8 53 | PXOR X14, X9 54 | 55 | MOVOU X0, 0(DI) 56 | MOVOU X2, 16(DI) 57 | MOVOU X4, 32(DI) 58 | MOVOU X6, 48(DI) 59 | MOVOU X8, 64(DI) 60 | MOVOU X1, 80(DI) 61 | MOVOU X3, 96(DI) 62 | MOVOU X5, 112(DI) 63 | MOVOU X7, 128(DI) 64 | MOVOU X9, 144(DI) 65 | RET 66 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package curve25519 provides an implementation of scalar multiplication on 6 | // the elliptic curve known as curve25519. See https://cr.yp.to/ecdh.html 7 | package curve25519 // import "golang.org/x/crypto/curve25519" 8 | 9 | // basePoint is the x coordinate of the generator of the curve. 10 | var basePoint = [32]byte{9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 11 | 12 | // ScalarMult sets dst to the product in*base where dst and base are the x 13 | // coordinates of group points and all values are in little-endian form. 14 | func ScalarMult(dst, in, base *[32]byte) { 15 | scalarMult(dst, in, base) 16 | } 17 | 18 | // ScalarBaseMult sets dst to the product in*base where dst and base are the x 19 | // coordinates of group points, base is the standard generator and all values 20 | // are in little-endian form. 21 | func ScalarBaseMult(dst, in *[32]byte) { 22 | ScalarMult(dst, in, &basePoint) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/freeze_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | #include "const_amd64.h" 11 | 12 | // func freeze(inout *[5]uint64) 13 | TEXT ·freeze(SB),7,$0-8 14 | MOVQ inout+0(FP), DI 15 | 16 | MOVQ 0(DI),SI 17 | MOVQ 8(DI),DX 18 | MOVQ 16(DI),CX 19 | MOVQ 24(DI),R8 20 | MOVQ 32(DI),R9 21 | MOVQ $REDMASK51,AX 22 | MOVQ AX,R10 23 | SUBQ $18,R10 24 | MOVQ $3,R11 25 | REDUCELOOP: 26 | MOVQ SI,R12 27 | SHRQ $51,R12 28 | ANDQ AX,SI 29 | ADDQ R12,DX 30 | MOVQ DX,R12 31 | SHRQ $51,R12 32 | ANDQ AX,DX 33 | ADDQ R12,CX 34 | MOVQ CX,R12 35 | SHRQ $51,R12 36 | ANDQ AX,CX 37 | ADDQ R12,R8 38 | MOVQ R8,R12 39 | SHRQ $51,R12 40 | ANDQ AX,R8 41 | ADDQ R12,R9 42 | MOVQ R9,R12 43 | SHRQ $51,R12 44 | ANDQ AX,R9 45 | IMUL3Q $19,R12,R12 46 | ADDQ R12,SI 47 | SUBQ $1,R11 48 | JA REDUCELOOP 49 | MOVQ $1,R12 50 | CMPQ R10,SI 51 | CMOVQLT R11,R12 52 | CMPQ AX,DX 53 | CMOVQNE R11,R12 54 | CMPQ AX,CX 55 | CMOVQNE R11,R12 56 | CMPQ AX,R8 57 | CMOVQNE R11,R12 58 | CMPQ AX,R9 59 | CMOVQNE R11,R12 60 | NEGQ R12 61 | ANDQ R12,AX 62 | ANDQ R12,R10 63 | SUBQ R10,SI 64 | SUBQ AX,DX 65 | SUBQ AX,CX 66 | SUBQ AX,R8 67 | SUBQ AX,R9 68 | MOVQ SI,0(DI) 69 | MOVQ DX,8(DI) 70 | MOVQ CX,16(DI) 71 | MOVQ R8,24(DI) 72 | MOVQ R9,32(DI) 73 | RET 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/mul_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | #include "const_amd64.h" 11 | 12 | // func mul(dest, a, b *[5]uint64) 13 | TEXT ·mul(SB),0,$16-24 14 | MOVQ dest+0(FP), DI 15 | MOVQ a+8(FP), SI 16 | MOVQ b+16(FP), DX 17 | 18 | MOVQ DX,CX 19 | MOVQ 24(SI),DX 20 | IMUL3Q $19,DX,AX 21 | MOVQ AX,0(SP) 22 | MULQ 16(CX) 23 | MOVQ AX,R8 24 | MOVQ DX,R9 25 | MOVQ 32(SI),DX 26 | IMUL3Q $19,DX,AX 27 | MOVQ AX,8(SP) 28 | MULQ 8(CX) 29 | ADDQ AX,R8 30 | ADCQ DX,R9 31 | MOVQ 0(SI),AX 32 | MULQ 0(CX) 33 | ADDQ AX,R8 34 | ADCQ DX,R9 35 | MOVQ 0(SI),AX 36 | MULQ 8(CX) 37 | MOVQ AX,R10 38 | MOVQ DX,R11 39 | MOVQ 0(SI),AX 40 | MULQ 16(CX) 41 | MOVQ AX,R12 42 | MOVQ DX,R13 43 | MOVQ 0(SI),AX 44 | MULQ 24(CX) 45 | MOVQ AX,R14 46 | MOVQ DX,R15 47 | MOVQ 0(SI),AX 48 | MULQ 32(CX) 49 | MOVQ AX,BX 50 | MOVQ DX,BP 51 | MOVQ 8(SI),AX 52 | MULQ 0(CX) 53 | ADDQ AX,R10 54 | ADCQ DX,R11 55 | MOVQ 8(SI),AX 56 | MULQ 8(CX) 57 | ADDQ AX,R12 58 | ADCQ DX,R13 59 | MOVQ 8(SI),AX 60 | MULQ 16(CX) 61 | ADDQ AX,R14 62 | ADCQ DX,R15 63 | MOVQ 8(SI),AX 64 | MULQ 24(CX) 65 | ADDQ AX,BX 66 | ADCQ DX,BP 67 | MOVQ 8(SI),DX 68 | IMUL3Q $19,DX,AX 69 | MULQ 32(CX) 70 | ADDQ AX,R8 71 | ADCQ DX,R9 72 | MOVQ 16(SI),AX 73 | MULQ 0(CX) 74 | ADDQ AX,R12 75 | ADCQ DX,R13 76 | MOVQ 16(SI),AX 77 | MULQ 8(CX) 78 | ADDQ AX,R14 79 | ADCQ DX,R15 80 | MOVQ 16(SI),AX 81 | MULQ 16(CX) 82 | ADDQ AX,BX 83 | ADCQ DX,BP 84 | MOVQ 16(SI),DX 85 | IMUL3Q $19,DX,AX 86 | MULQ 24(CX) 87 | ADDQ AX,R8 88 | ADCQ DX,R9 89 | MOVQ 16(SI),DX 90 | IMUL3Q $19,DX,AX 91 | MULQ 32(CX) 92 | ADDQ AX,R10 93 | ADCQ DX,R11 94 | MOVQ 24(SI),AX 95 | MULQ 0(CX) 96 | ADDQ AX,R14 97 | ADCQ DX,R15 98 | MOVQ 24(SI),AX 99 | MULQ 8(CX) 100 | ADDQ AX,BX 101 | ADCQ DX,BP 102 | MOVQ 0(SP),AX 103 | MULQ 24(CX) 104 | ADDQ AX,R10 105 | ADCQ DX,R11 106 | MOVQ 0(SP),AX 107 | MULQ 32(CX) 108 | ADDQ AX,R12 109 | ADCQ DX,R13 110 | MOVQ 32(SI),AX 111 | MULQ 0(CX) 112 | ADDQ AX,BX 113 | ADCQ DX,BP 114 | MOVQ 8(SP),AX 115 | MULQ 16(CX) 116 | ADDQ AX,R10 117 | ADCQ DX,R11 118 | MOVQ 8(SP),AX 119 | MULQ 24(CX) 120 | ADDQ AX,R12 121 | ADCQ DX,R13 122 | MOVQ 8(SP),AX 123 | MULQ 32(CX) 124 | ADDQ AX,R14 125 | ADCQ DX,R15 126 | MOVQ $REDMASK51,SI 127 | SHLQ $13,R9:R8 128 | ANDQ SI,R8 129 | SHLQ $13,R11:R10 130 | ANDQ SI,R10 131 | ADDQ R9,R10 132 | SHLQ $13,R13:R12 133 | ANDQ SI,R12 134 | ADDQ R11,R12 135 | SHLQ $13,R15:R14 136 | ANDQ SI,R14 137 | ADDQ R13,R14 138 | SHLQ $13,BP:BX 139 | ANDQ SI,BX 140 | ADDQ R15,BX 141 | IMUL3Q $19,BP,DX 142 | ADDQ DX,R8 143 | MOVQ R8,DX 144 | SHRQ $51,DX 145 | ADDQ R10,DX 146 | MOVQ DX,CX 147 | SHRQ $51,DX 148 | ANDQ SI,R8 149 | ADDQ R12,DX 150 | MOVQ DX,R9 151 | SHRQ $51,DX 152 | ANDQ SI,CX 153 | ADDQ R14,DX 154 | MOVQ DX,AX 155 | SHRQ $51,DX 156 | ANDQ SI,R9 157 | ADDQ BX,DX 158 | MOVQ DX,R10 159 | SHRQ $51,DX 160 | ANDQ SI,AX 161 | IMUL3Q $19,DX,DX 162 | ADDQ DX,R8 163 | ANDQ SI,R10 164 | MOVQ R8,0(DI) 165 | MOVQ CX,8(DI) 166 | MOVQ R9,16(DI) 167 | MOVQ AX,24(DI) 168 | MOVQ R10,32(DI) 169 | RET 170 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/curve25519/square_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This code was translated into a form compatible with 6a from the public 6 | // domain sources in SUPERCOP: https://bench.cr.yp.to/supercop.html 7 | 8 | // +build amd64,!gccgo,!appengine 9 | 10 | #include "const_amd64.h" 11 | 12 | // func square(out, in *[5]uint64) 13 | TEXT ·square(SB),7,$0-16 14 | MOVQ out+0(FP), DI 15 | MOVQ in+8(FP), SI 16 | 17 | MOVQ 0(SI),AX 18 | MULQ 0(SI) 19 | MOVQ AX,CX 20 | MOVQ DX,R8 21 | MOVQ 0(SI),AX 22 | SHLQ $1,AX 23 | MULQ 8(SI) 24 | MOVQ AX,R9 25 | MOVQ DX,R10 26 | MOVQ 0(SI),AX 27 | SHLQ $1,AX 28 | MULQ 16(SI) 29 | MOVQ AX,R11 30 | MOVQ DX,R12 31 | MOVQ 0(SI),AX 32 | SHLQ $1,AX 33 | MULQ 24(SI) 34 | MOVQ AX,R13 35 | MOVQ DX,R14 36 | MOVQ 0(SI),AX 37 | SHLQ $1,AX 38 | MULQ 32(SI) 39 | MOVQ AX,R15 40 | MOVQ DX,BX 41 | MOVQ 8(SI),AX 42 | MULQ 8(SI) 43 | ADDQ AX,R11 44 | ADCQ DX,R12 45 | MOVQ 8(SI),AX 46 | SHLQ $1,AX 47 | MULQ 16(SI) 48 | ADDQ AX,R13 49 | ADCQ DX,R14 50 | MOVQ 8(SI),AX 51 | SHLQ $1,AX 52 | MULQ 24(SI) 53 | ADDQ AX,R15 54 | ADCQ DX,BX 55 | MOVQ 8(SI),DX 56 | IMUL3Q $38,DX,AX 57 | MULQ 32(SI) 58 | ADDQ AX,CX 59 | ADCQ DX,R8 60 | MOVQ 16(SI),AX 61 | MULQ 16(SI) 62 | ADDQ AX,R15 63 | ADCQ DX,BX 64 | MOVQ 16(SI),DX 65 | IMUL3Q $38,DX,AX 66 | MULQ 24(SI) 67 | ADDQ AX,CX 68 | ADCQ DX,R8 69 | MOVQ 16(SI),DX 70 | IMUL3Q $38,DX,AX 71 | MULQ 32(SI) 72 | ADDQ AX,R9 73 | ADCQ DX,R10 74 | MOVQ 24(SI),DX 75 | IMUL3Q $19,DX,AX 76 | MULQ 24(SI) 77 | ADDQ AX,R9 78 | ADCQ DX,R10 79 | MOVQ 24(SI),DX 80 | IMUL3Q $38,DX,AX 81 | MULQ 32(SI) 82 | ADDQ AX,R11 83 | ADCQ DX,R12 84 | MOVQ 32(SI),DX 85 | IMUL3Q $19,DX,AX 86 | MULQ 32(SI) 87 | ADDQ AX,R13 88 | ADCQ DX,R14 89 | MOVQ $REDMASK51,SI 90 | SHLQ $13,R8:CX 91 | ANDQ SI,CX 92 | SHLQ $13,R10:R9 93 | ANDQ SI,R9 94 | ADDQ R8,R9 95 | SHLQ $13,R12:R11 96 | ANDQ SI,R11 97 | ADDQ R10,R11 98 | SHLQ $13,R14:R13 99 | ANDQ SI,R13 100 | ADDQ R12,R13 101 | SHLQ $13,BX:R15 102 | ANDQ SI,R15 103 | ADDQ R14,R15 104 | IMUL3Q $19,BX,DX 105 | ADDQ DX,CX 106 | MOVQ CX,DX 107 | SHRQ $51,DX 108 | ADDQ R9,DX 109 | ANDQ SI,CX 110 | MOVQ DX,R8 111 | SHRQ $51,DX 112 | ADDQ R11,DX 113 | ANDQ SI,R8 114 | MOVQ DX,R9 115 | SHRQ $51,DX 116 | ADDQ R13,DX 117 | ANDQ SI,R9 118 | MOVQ DX,AX 119 | SHRQ $51,DX 120 | ADDQ R15,DX 121 | ANDQ SI,AX 122 | MOVQ DX,R10 123 | SHRQ $51,DX 124 | IMUL3Q $19,DX,DX 125 | ADDQ DX,CX 126 | ANDQ SI,R10 127 | MOVQ CX,0(DI) 128 | MOVQ R8,8(DI) 129 | MOVQ R9,16(DI) 130 | MOVQ AX,24(DI) 131 | MOVQ R10,32(DI) 132 | RET 133 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/chacha20/chacha_noasm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !s390x gccgo appengine 6 | 7 | package chacha20 8 | 9 | const ( 10 | bufSize = 64 11 | haveAsm = false 12 | ) 13 | 14 | func (*Cipher) xorKeyStreamAsm(dst, src []byte) { 15 | panic("not implemented") 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/chacha20/chacha_s390x.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build s390x,!gccgo,!appengine 6 | 7 | package chacha20 8 | 9 | var haveAsm = hasVectorFacility() 10 | 11 | const bufSize = 256 12 | 13 | // hasVectorFacility reports whether the machine supports the vector 14 | // facility (vx). 15 | // Implementation in asm_s390x.s. 16 | func hasVectorFacility() bool 17 | 18 | // xorKeyStreamVX is an assembly implementation of XORKeyStream. It must only 19 | // be called when the vector facility is available. 20 | // Implementation in asm_s390x.s. 21 | //go:noescape 22 | func xorKeyStreamVX(dst, src []byte, key *[8]uint32, nonce *[3]uint32, counter *uint32, buf *[256]byte, len *int) 23 | 24 | func (c *Cipher) xorKeyStreamAsm(dst, src []byte) { 25 | xorKeyStreamVX(dst, src, &c.key, &c.nonce, &c.counter, &c.buf, &c.len) 26 | } 27 | 28 | // EXRL targets, DO NOT CALL! 29 | func mvcSrcToBuf() 30 | func mvcBufToDst() 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/internal/chacha20/xor.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found src the LICENSE file. 4 | 5 | package chacha20 6 | 7 | import ( 8 | "runtime" 9 | ) 10 | 11 | // Platforms that have fast unaligned 32-bit little endian accesses. 12 | const unaligned = runtime.GOARCH == "386" || 13 | runtime.GOARCH == "amd64" || 14 | runtime.GOARCH == "arm64" || 15 | runtime.GOARCH == "ppc64le" || 16 | runtime.GOARCH == "s390x" 17 | 18 | // xor reads a little endian uint32 from src, XORs it with u and 19 | // places the result in little endian byte order in dst. 20 | func xor(dst, src []byte, u uint32) { 21 | _, _ = src[3], dst[3] // eliminate bounds checks 22 | if unaligned { 23 | // The compiler should optimize this code into 24 | // 32-bit unaligned little endian loads and stores. 25 | // TODO: delete once the compiler does a reliably 26 | // good job with the generic code below. 27 | // See issue #25111 for more details. 28 | v := uint32(src[0]) 29 | v |= uint32(src[1]) << 8 30 | v |= uint32(src[2]) << 16 31 | v |= uint32(src[3]) << 24 32 | v ^= u 33 | dst[0] = byte(v) 34 | dst[1] = byte(v >> 8) 35 | dst[2] = byte(v >> 16) 36 | dst[3] = byte(v >> 24) 37 | } else { 38 | dst[0] = src[0] ^ byte(u) 39 | dst[1] = src[1] ^ byte(u>>8) 40 | dst[2] = src[2] ^ byte(u>>16) 41 | dst[3] = src[3] ^ byte(u>>24) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/poly1305.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package poly1305 implements Poly1305 one-time message authentication code as 7 | specified in https://cr.yp.to/mac/poly1305-20050329.pdf. 8 | 9 | Poly1305 is a fast, one-time authentication function. It is infeasible for an 10 | attacker to generate an authenticator for a message without the key. However, a 11 | key must only be used for a single message. Authenticating two different 12 | messages with the same key allows an attacker to forge authenticators for other 13 | messages with the same key. 14 | 15 | Poly1305 was originally coupled with AES in order to make Poly1305-AES. AES was 16 | used with a fixed key in order to generate one-time keys from an nonce. 17 | However, in this package AES isn't used and the one-time key is specified 18 | directly. 19 | */ 20 | package poly1305 // import "golang.org/x/crypto/poly1305" 21 | 22 | import "crypto/subtle" 23 | 24 | // TagSize is the size, in bytes, of a poly1305 authenticator. 25 | const TagSize = 16 26 | 27 | // Verify returns true if mac is a valid authenticator for m with the given 28 | // key. 29 | func Verify(mac *[16]byte, m []byte, key *[32]byte) bool { 30 | var tmp [16]byte 31 | Sum(&tmp, m, key) 32 | return subtle.ConstantTimeCompare(tmp[:], mac[:]) == 1 33 | } 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | package poly1305 8 | 9 | // This function is implemented in sum_amd64.s 10 | //go:noescape 11 | func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]byte) 12 | 13 | // Sum generates an authenticator for m using a one-time key and puts the 14 | // 16-byte result into out. Authenticating two different messages with the same 15 | // key allows an attacker to forge messages at will. 16 | func Sum(out *[16]byte, m []byte, key *[32]byte) { 17 | var mPtr *byte 18 | if len(m) > 0 { 19 | mPtr = &m[0] 20 | } 21 | poly1305(out, mPtr, uint64(len(m)), key) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build amd64,!gccgo,!appengine 6 | 7 | #include "textflag.h" 8 | 9 | #define POLY1305_ADD(msg, h0, h1, h2) \ 10 | ADDQ 0(msg), h0; \ 11 | ADCQ 8(msg), h1; \ 12 | ADCQ $1, h2; \ 13 | LEAQ 16(msg), msg 14 | 15 | #define POLY1305_MUL(h0, h1, h2, r0, r1, t0, t1, t2, t3) \ 16 | MOVQ r0, AX; \ 17 | MULQ h0; \ 18 | MOVQ AX, t0; \ 19 | MOVQ DX, t1; \ 20 | MOVQ r0, AX; \ 21 | MULQ h1; \ 22 | ADDQ AX, t1; \ 23 | ADCQ $0, DX; \ 24 | MOVQ r0, t2; \ 25 | IMULQ h2, t2; \ 26 | ADDQ DX, t2; \ 27 | \ 28 | MOVQ r1, AX; \ 29 | MULQ h0; \ 30 | ADDQ AX, t1; \ 31 | ADCQ $0, DX; \ 32 | MOVQ DX, h0; \ 33 | MOVQ r1, t3; \ 34 | IMULQ h2, t3; \ 35 | MOVQ r1, AX; \ 36 | MULQ h1; \ 37 | ADDQ AX, t2; \ 38 | ADCQ DX, t3; \ 39 | ADDQ h0, t2; \ 40 | ADCQ $0, t3; \ 41 | \ 42 | MOVQ t0, h0; \ 43 | MOVQ t1, h1; \ 44 | MOVQ t2, h2; \ 45 | ANDQ $3, h2; \ 46 | MOVQ t2, t0; \ 47 | ANDQ $0xFFFFFFFFFFFFFFFC, t0; \ 48 | ADDQ t0, h0; \ 49 | ADCQ t3, h1; \ 50 | ADCQ $0, h2; \ 51 | SHRQ $2, t3, t2; \ 52 | SHRQ $2, t3; \ 53 | ADDQ t2, h0; \ 54 | ADCQ t3, h1; \ 55 | ADCQ $0, h2 56 | 57 | DATA ·poly1305Mask<>+0x00(SB)/8, $0x0FFFFFFC0FFFFFFF 58 | DATA ·poly1305Mask<>+0x08(SB)/8, $0x0FFFFFFC0FFFFFFC 59 | GLOBL ·poly1305Mask<>(SB), RODATA, $16 60 | 61 | // func poly1305(out *[16]byte, m *byte, mlen uint64, key *[32]key) 62 | TEXT ·poly1305(SB), $0-32 63 | MOVQ out+0(FP), DI 64 | MOVQ m+8(FP), SI 65 | MOVQ mlen+16(FP), R15 66 | MOVQ key+24(FP), AX 67 | 68 | MOVQ 0(AX), R11 69 | MOVQ 8(AX), R12 70 | ANDQ ·poly1305Mask<>(SB), R11 // r0 71 | ANDQ ·poly1305Mask<>+8(SB), R12 // r1 72 | XORQ R8, R8 // h0 73 | XORQ R9, R9 // h1 74 | XORQ R10, R10 // h2 75 | 76 | CMPQ R15, $16 77 | JB bytes_between_0_and_15 78 | 79 | loop: 80 | POLY1305_ADD(SI, R8, R9, R10) 81 | 82 | multiply: 83 | POLY1305_MUL(R8, R9, R10, R11, R12, BX, CX, R13, R14) 84 | SUBQ $16, R15 85 | CMPQ R15, $16 86 | JAE loop 87 | 88 | bytes_between_0_and_15: 89 | TESTQ R15, R15 90 | JZ done 91 | MOVQ $1, BX 92 | XORQ CX, CX 93 | XORQ R13, R13 94 | ADDQ R15, SI 95 | 96 | flush_buffer: 97 | SHLQ $8, BX, CX 98 | SHLQ $8, BX 99 | MOVB -1(SI), R13 100 | XORQ R13, BX 101 | DECQ SI 102 | DECQ R15 103 | JNZ flush_buffer 104 | 105 | ADDQ BX, R8 106 | ADCQ CX, R9 107 | ADCQ $0, R10 108 | MOVQ $16, R15 109 | JMP multiply 110 | 111 | done: 112 | MOVQ R8, AX 113 | MOVQ R9, BX 114 | SUBQ $0xFFFFFFFFFFFFFFFB, AX 115 | SBBQ $0xFFFFFFFFFFFFFFFF, BX 116 | SBBQ $3, R10 117 | CMOVQCS R8, AX 118 | CMOVQCS R9, BX 119 | MOVQ key+24(FP), R8 120 | ADDQ 16(R8), AX 121 | ADCQ 24(R8), BX 122 | 123 | MOVQ AX, 0(DI) 124 | MOVQ BX, 8(DI) 125 | RET 126 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/poly1305/sum_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build arm,!gccgo,!appengine,!nacl 6 | 7 | package poly1305 8 | 9 | // This function is implemented in sum_arm.s 10 | //go:noescape 11 | func poly1305_auth_armv6(out *[16]byte, m *byte, mlen uint32, key *[32]byte) 12 | 13 | // Sum generates an authenticator for m using a one-time key and puts the 14 | // 16-byte result into out. Authenticating two different messages with the same 15 | // key allows an attacker to forge messages at will. 16 | func Sum(out *[16]byte, m []byte, key *[32]byte) { 17 | var mPtr *byte 18 | if len(m) > 0 { 19 | mPtr = &m[0] 20 | } 21 | poly1305_auth_armv6(out, mPtr, uint32(len(m)), key) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/buffer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "io" 9 | "sync" 10 | ) 11 | 12 | // buffer provides a linked list buffer for data exchange 13 | // between producer and consumer. Theoretically the buffer is 14 | // of unlimited capacity as it does no allocation of its own. 15 | type buffer struct { 16 | // protects concurrent access to head, tail and closed 17 | *sync.Cond 18 | 19 | head *element // the buffer that will be read first 20 | tail *element // the buffer that will be read last 21 | 22 | closed bool 23 | } 24 | 25 | // An element represents a single link in a linked list. 26 | type element struct { 27 | buf []byte 28 | next *element 29 | } 30 | 31 | // newBuffer returns an empty buffer that is not closed. 32 | func newBuffer() *buffer { 33 | e := new(element) 34 | b := &buffer{ 35 | Cond: newCond(), 36 | head: e, 37 | tail: e, 38 | } 39 | return b 40 | } 41 | 42 | // write makes buf available for Read to receive. 43 | // buf must not be modified after the call to write. 44 | func (b *buffer) write(buf []byte) { 45 | b.Cond.L.Lock() 46 | e := &element{buf: buf} 47 | b.tail.next = e 48 | b.tail = e 49 | b.Cond.Signal() 50 | b.Cond.L.Unlock() 51 | } 52 | 53 | // eof closes the buffer. Reads from the buffer once all 54 | // the data has been consumed will receive io.EOF. 55 | func (b *buffer) eof() { 56 | b.Cond.L.Lock() 57 | b.closed = true 58 | b.Cond.Signal() 59 | b.Cond.L.Unlock() 60 | } 61 | 62 | // Read reads data from the internal buffer in buf. Reads will block 63 | // if no data is available, or until the buffer is closed. 64 | func (b *buffer) Read(buf []byte) (n int, err error) { 65 | b.Cond.L.Lock() 66 | defer b.Cond.L.Unlock() 67 | 68 | for len(buf) > 0 { 69 | // if there is data in b.head, copy it 70 | if len(b.head.buf) > 0 { 71 | r := copy(buf, b.head.buf) 72 | buf, b.head.buf = buf[r:], b.head.buf[r:] 73 | n += r 74 | continue 75 | } 76 | // if there is a next buffer, make it the head 77 | if len(b.head.buf) == 0 && b.head != b.tail { 78 | b.head = b.head.next 79 | continue 80 | } 81 | 82 | // if at least one byte has been copied, return 83 | if n > 0 { 84 | break 85 | } 86 | 87 | // if nothing was read, and there is nothing outstanding 88 | // check to see if the buffer is closed. 89 | if b.closed { 90 | err = io.EOF 91 | break 92 | } 93 | // out of buffers, wait for producer 94 | b.Cond.Wait() 95 | } 96 | return 97 | } 98 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/connection.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | import ( 8 | "fmt" 9 | "net" 10 | ) 11 | 12 | // OpenChannelError is returned if the other side rejects an 13 | // OpenChannel request. 14 | type OpenChannelError struct { 15 | Reason RejectionReason 16 | Message string 17 | } 18 | 19 | func (e *OpenChannelError) Error() string { 20 | return fmt.Sprintf("ssh: rejected: %s (%s)", e.Reason, e.Message) 21 | } 22 | 23 | // ConnMetadata holds metadata for the connection. 24 | type ConnMetadata interface { 25 | // User returns the user ID for this connection. 26 | User() string 27 | 28 | // SessionID returns the session hash, also denoted by H. 29 | SessionID() []byte 30 | 31 | // ClientVersion returns the client's version string as hashed 32 | // into the session ID. 33 | ClientVersion() []byte 34 | 35 | // ServerVersion returns the server's version string as hashed 36 | // into the session ID. 37 | ServerVersion() []byte 38 | 39 | // RemoteAddr returns the remote address for this connection. 40 | RemoteAddr() net.Addr 41 | 42 | // LocalAddr returns the local address for this connection. 43 | LocalAddr() net.Addr 44 | } 45 | 46 | // Conn represents an SSH connection for both server and client roles. 47 | // Conn is the basis for implementing an application layer, such 48 | // as ClientConn, which implements the traditional shell access for 49 | // clients. 50 | type Conn interface { 51 | ConnMetadata 52 | 53 | // SendRequest sends a global request, and returns the 54 | // reply. If wantReply is true, it returns the response status 55 | // and payload. See also RFC4254, section 4. 56 | SendRequest(name string, wantReply bool, payload []byte) (bool, []byte, error) 57 | 58 | // OpenChannel tries to open an channel. If the request is 59 | // rejected, it returns *OpenChannelError. On success it returns 60 | // the SSH Channel and a Go channel for incoming, out-of-band 61 | // requests. The Go channel must be serviced, or the 62 | // connection will hang. 63 | OpenChannel(name string, data []byte) (Channel, <-chan *Request, error) 64 | 65 | // Close closes the underlying network connection 66 | Close() error 67 | 68 | // Wait blocks until the connection has shut down, and returns the 69 | // error causing the shutdown. 70 | Wait() error 71 | 72 | // TODO(hanwen): consider exposing: 73 | // RequestKeyChange 74 | // Disconnect 75 | } 76 | 77 | // DiscardRequests consumes and rejects all requests from the 78 | // passed-in channel. 79 | func DiscardRequests(in <-chan *Request) { 80 | for req := range in { 81 | if req.WantReply { 82 | req.Reply(false, nil) 83 | } 84 | } 85 | } 86 | 87 | // A connection represents an incoming connection. 88 | type connection struct { 89 | transport *handshakeTransport 90 | sshConn 91 | 92 | // The connection protocol. 93 | *mux 94 | } 95 | 96 | func (c *connection) Close() error { 97 | return c.sshConn.conn.Close() 98 | } 99 | 100 | // sshconn provides net.Conn metadata, but disallows direct reads and 101 | // writes. 102 | type sshConn struct { 103 | conn net.Conn 104 | 105 | user string 106 | sessionID []byte 107 | clientVersion []byte 108 | serverVersion []byte 109 | } 110 | 111 | func dup(src []byte) []byte { 112 | dst := make([]byte, len(src)) 113 | copy(dst, src) 114 | return dst 115 | } 116 | 117 | func (c *sshConn) User() string { 118 | return c.user 119 | } 120 | 121 | func (c *sshConn) RemoteAddr() net.Addr { 122 | return c.conn.RemoteAddr() 123 | } 124 | 125 | func (c *sshConn) Close() error { 126 | return c.conn.Close() 127 | } 128 | 129 | func (c *sshConn) LocalAddr() net.Addr { 130 | return c.conn.LocalAddr() 131 | } 132 | 133 | func (c *sshConn) SessionID() []byte { 134 | return dup(c.sessionID) 135 | } 136 | 137 | func (c *sshConn) ClientVersion() []byte { 138 | return dup(c.clientVersion) 139 | } 140 | 141 | func (c *sshConn) ServerVersion() []byte { 142 | return dup(c.serverVersion) 143 | } 144 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package ssh implements an SSH client and server. 7 | 8 | SSH is a transport security protocol, an authentication protocol and a 9 | family of application protocols. The most typical application level 10 | protocol is a remote shell and this is specifically implemented. However, 11 | the multiplexed nature of SSH is exposed to users that wish to support 12 | others. 13 | 14 | References: 15 | [PROTOCOL.certkeys]: http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.certkeys?rev=HEAD 16 | [SSH-PARAMETERS]: http://www.iana.org/assignments/ssh-parameters/ssh-parameters.xml#ssh-parameters-1 17 | 18 | This package does not fall under the stability promise of the Go language itself, 19 | so its API may be changed when pressing needs arise. 20 | */ 21 | package ssh // import "golang.org/x/crypto/ssh" 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/mac.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssh 6 | 7 | // Message authentication support 8 | 9 | import ( 10 | "crypto/hmac" 11 | "crypto/sha1" 12 | "crypto/sha256" 13 | "hash" 14 | ) 15 | 16 | type macMode struct { 17 | keySize int 18 | etm bool 19 | new func(key []byte) hash.Hash 20 | } 21 | 22 | // truncatingMAC wraps around a hash.Hash and truncates the output digest to 23 | // a given size. 24 | type truncatingMAC struct { 25 | length int 26 | hmac hash.Hash 27 | } 28 | 29 | func (t truncatingMAC) Write(data []byte) (int, error) { 30 | return t.hmac.Write(data) 31 | } 32 | 33 | func (t truncatingMAC) Sum(in []byte) []byte { 34 | out := t.hmac.Sum(in) 35 | return out[:len(in)+t.length] 36 | } 37 | 38 | func (t truncatingMAC) Reset() { 39 | t.hmac.Reset() 40 | } 41 | 42 | func (t truncatingMAC) Size() int { 43 | return t.length 44 | } 45 | 46 | func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() } 47 | 48 | var macModes = map[string]*macMode{ 49 | "hmac-sha2-256-etm@openssh.com": {32, true, func(key []byte) hash.Hash { 50 | return hmac.New(sha256.New, key) 51 | }}, 52 | "hmac-sha2-256": {32, false, func(key []byte) hash.Hash { 53 | return hmac.New(sha256.New, key) 54 | }}, 55 | "hmac-sha1": {20, false, func(key []byte) hash.Hash { 56 | return hmac.New(sha1.New, key) 57 | }}, 58 | "hmac-sha1-96": {20, false, func(key []byte) hash.Hash { 59 | return truncatingMAC{12, hmac.New(sha1.New, key)} 60 | }}, 61 | } 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/ssh/streamlocal.go: -------------------------------------------------------------------------------- 1 | package ssh 2 | 3 | import ( 4 | "errors" 5 | "io" 6 | "net" 7 | ) 8 | 9 | // streamLocalChannelOpenDirectMsg is a struct used for SSH_MSG_CHANNEL_OPEN message 10 | // with "direct-streamlocal@openssh.com" string. 11 | // 12 | // See openssh-portable/PROTOCOL, section 2.4. connection: Unix domain socket forwarding 13 | // https://github.com/openssh/openssh-portable/blob/master/PROTOCOL#L235 14 | type streamLocalChannelOpenDirectMsg struct { 15 | socketPath string 16 | reserved0 string 17 | reserved1 uint32 18 | } 19 | 20 | // forwardedStreamLocalPayload is a struct used for SSH_MSG_CHANNEL_OPEN message 21 | // with "forwarded-streamlocal@openssh.com" string. 22 | type forwardedStreamLocalPayload struct { 23 | SocketPath string 24 | Reserved0 string 25 | } 26 | 27 | // streamLocalChannelForwardMsg is a struct used for SSH2_MSG_GLOBAL_REQUEST message 28 | // with "streamlocal-forward@openssh.com"/"cancel-streamlocal-forward@openssh.com" string. 29 | type streamLocalChannelForwardMsg struct { 30 | socketPath string 31 | } 32 | 33 | // ListenUnix is similar to ListenTCP but uses a Unix domain socket. 34 | func (c *Client) ListenUnix(socketPath string) (net.Listener, error) { 35 | m := streamLocalChannelForwardMsg{ 36 | socketPath, 37 | } 38 | // send message 39 | ok, _, err := c.SendRequest("streamlocal-forward@openssh.com", true, Marshal(&m)) 40 | if err != nil { 41 | return nil, err 42 | } 43 | if !ok { 44 | return nil, errors.New("ssh: streamlocal-forward@openssh.com request denied by peer") 45 | } 46 | ch := c.forwards.add(&net.UnixAddr{Name: socketPath, Net: "unix"}) 47 | 48 | return &unixListener{socketPath, c, ch}, nil 49 | } 50 | 51 | func (c *Client) dialStreamLocal(socketPath string) (Channel, error) { 52 | msg := streamLocalChannelOpenDirectMsg{ 53 | socketPath: socketPath, 54 | } 55 | ch, in, err := c.OpenChannel("direct-streamlocal@openssh.com", Marshal(&msg)) 56 | if err != nil { 57 | return nil, err 58 | } 59 | go DiscardRequests(in) 60 | return ch, err 61 | } 62 | 63 | type unixListener struct { 64 | socketPath string 65 | 66 | conn *Client 67 | in <-chan forward 68 | } 69 | 70 | // Accept waits for and returns the next connection to the listener. 71 | func (l *unixListener) Accept() (net.Conn, error) { 72 | s, ok := <-l.in 73 | if !ok { 74 | return nil, io.EOF 75 | } 76 | ch, incoming, err := s.newCh.Accept() 77 | if err != nil { 78 | return nil, err 79 | } 80 | go DiscardRequests(incoming) 81 | 82 | return &chanConn{ 83 | Channel: ch, 84 | laddr: &net.UnixAddr{ 85 | Name: l.socketPath, 86 | Net: "unix", 87 | }, 88 | raddr: &net.UnixAddr{ 89 | Name: "@", 90 | Net: "unix", 91 | }, 92 | }, nil 93 | } 94 | 95 | // Close closes the listener. 96 | func (l *unixListener) Close() error { 97 | // this also closes the listener. 98 | l.conn.forwards.remove(&net.UnixAddr{Name: l.socketPath, Net: "unix"}) 99 | m := streamLocalChannelForwardMsg{ 100 | l.socketPath, 101 | } 102 | ok, _, err := l.conn.SendRequest("cancel-streamlocal-forward@openssh.com", true, Marshal(&m)) 103 | if err == nil && !ok { 104 | err = errors.New("ssh: cancel-streamlocal-forward@openssh.com failed") 105 | } 106 | return err 107 | } 108 | 109 | // Addr returns the listener's network address. 110 | func (l *unixListener) Addr() net.Addr { 111 | return &net.UnixAddr{ 112 | Name: l.socketPath, 113 | Net: "unix", 114 | } 115 | } 116 | --------------------------------------------------------------------------------