From 7d52df4699646c0909b75ea2f685a6edf1465bbe Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 21 Jan 2022 11:35:40 -0800 Subject: [PATCH] Bump github.com/hashicorp/consul/api from 1.11.0 to 1.12.0 (#18) Bumps [github.com/hashicorp/consul/api](https://github.com/hashicorp/consul) from 1.11.0 to 1.12.0. - [Release notes](https://github.com/hashicorp/consul/releases) - [Changelog](https://github.com/hashicorp/consul/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/consul/compare/v1.11.0...api/v1.12.0) --- updated-dependencies: - dependency-name: github.com/hashicorp/consul/api dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 +- go.sum | 28 +- vendor/github.com/hashicorp/consul/api/acl.go | 290 +++++++++++---- .../github.com/hashicorp/consul/api/agent.go | 331 +++++++++++++----- vendor/github.com/hashicorp/consul/api/api.go | 109 ++++-- .../hashicorp/consul/api/catalog.go | 55 ++- .../hashicorp/consul/api/config_entry.go | 125 ++++--- .../consul/api/config_entry_cluster.go | 53 --- .../consul/api/config_entry_discoverychain.go | 64 +++- .../consul/api/config_entry_exports.go | 72 ++++ .../consul/api/config_entry_gateways.go | 111 +++--- .../consul/api/config_entry_intentions.go | 32 +- .../hashicorp/consul/api/config_entry_mesh.go | 56 +++ .../hashicorp/consul/api/connect_ca.go | 16 +- .../hashicorp/consul/api/connect_intention.go | 61 +++- .../hashicorp/consul/api/coordinate.go | 27 +- .../github.com/hashicorp/consul/api/debug.go | 41 ++- .../hashicorp/consul/api/discovery_chain.go | 6 +- .../github.com/hashicorp/consul/api/event.go | 10 +- .../github.com/hashicorp/consul/api/health.go | 21 +- vendor/github.com/hashicorp/consul/api/kv.go | 23 +- .../hashicorp/consul/api/namespace.go | 31 +- .../hashicorp/consul/api/operator_area.go | 20 +- .../consul/api/operator_autopilot.go | 55 ++- .../hashicorp/consul/api/operator_keyring.go | 29 +- .../hashicorp/consul/api/operator_license.go | 19 +- .../hashicorp/consul/api/operator_raft.go | 21 +- .../hashicorp/consul/api/partition.go | 164 +++++++++ .../hashicorp/consul/api/prepared_query.go | 10 +- .../hashicorp/consul/api/snapshot.go | 10 +- .../github.com/hashicorp/consul/api/status.go | 10 +- vendor/github.com/hashicorp/consul/api/txn.go | 1 + vendor/modules.txt | 4 +- 33 files changed, 1405 insertions(+), 504 deletions(-) delete mode 100644 vendor/github.com/hashicorp/consul/api/config_entry_cluster.go create mode 100644 vendor/github.com/hashicorp/consul/api/config_entry_exports.go create mode 100644 vendor/github.com/hashicorp/consul/api/config_entry_mesh.go create mode 100644 vendor/github.com/hashicorp/consul/api/partition.go diff --git a/go.mod b/go.mod index ff06507..5e2e275 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.17 require ( github.com/go-redis/redis/v8 v8.11.4 github.com/gorilla/mux v1.8.0 - github.com/hashicorp/consul/api v1.11.0 + github.com/hashicorp/consul/api v1.12.0 github.com/sirupsen/logrus v1.8.1 gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b ) @@ -20,7 +20,7 @@ require ( github.com/hashicorp/go-immutable-radix v1.0.0 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/golang-lru v0.5.0 // indirect - github.com/hashicorp/serf v0.9.5 // indirect + github.com/hashicorp/serf v0.9.6 // indirect github.com/mattn/go-colorable v0.1.6 // indirect github.com/mattn/go-isatty v0.0.12 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect diff --git a/go.sum b/go.sum index bb541f2..c0a8388 100644 --- a/go.sum +++ b/go.sum @@ -38,8 +38,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= -github.com/hashicorp/consul/api v1.11.0 h1:Hw/G8TtRvOElqxVIhBzXciiSTbapq8hZ2XKZsXk5ZCE= -github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= +github.com/hashicorp/consul/api v1.12.0 h1:k3y1FYv6nuKyNTqj6w9gXOx5r5CfLj/k/euUeBXj1OY= +github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0= github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= @@ -66,11 +66,11 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY= -github.com/hashicorp/memberlist v0.2.2 h1:5+RffWKwqJ71YPu9mWsF7ZOscZmwfasdA8kbdC7AO2g= -github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= -github.com/hashicorp/serf v0.9.5 h1:EBWvyu9tcRszt3Bxp3KNssBMP1KuHWyO51lz9+786iM= -github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= +github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= +github.com/hashicorp/memberlist v0.3.0 h1:8+567mCcFDnS5ADl7lrpxPMWiFCElyUEeW0gtj34fMA= +github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE= +github.com/hashicorp/serf v0.9.6 h1:uuEX1kLR6aoda1TBttmJQKDLZE1Ob7KN0NPdE7EtCDc= +github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= @@ -87,9 +87,9 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= +github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY= +github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -129,29 +129,27 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -169,6 +167,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/vendor/github.com/hashicorp/consul/api/acl.go b/vendor/github.com/hashicorp/consul/api/acl.go index 5dc83a1..0f44494 100644 --- a/vendor/github.com/hashicorp/consul/api/acl.go +++ b/vendor/github.com/hashicorp/consul/api/acl.go @@ -52,6 +52,14 @@ type ACLToken struct { // Namespace is the namespace the ACLToken is associated with. // Namespaces are a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLToken is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // AuthMethodNamespace is the namespace the token's AuthMethod is associated with. + // Namespacing is a Consul Enterprise feature. + AuthMethodNamespace string `json:",omitempty"` } type ACLTokenListEntry struct { @@ -74,6 +82,14 @@ type ACLTokenListEntry struct { // Namespace is the namespace the ACLTokenListEntry is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLTokenListEntry is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // AuthMethodNamespace is the namespace the token's AuthMethod is associated with. + // Namespacing is a Consul Enterprise feature. + AuthMethodNamespace string `json:",omitempty"` } // ACLEntry is used to represent a legacy ACL token @@ -98,6 +114,7 @@ type ACLReplicationStatus struct { ReplicatedTokenIndex uint64 LastSuccess time.Time LastError time.Time + LastErrorMessage string } // ACLServiceIdentity represents a high-level grant of all necessary privileges @@ -129,6 +146,10 @@ type ACLPolicy struct { // Namespace is the namespace the ACLPolicy is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLPolicy is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } type ACLPolicyListEntry struct { @@ -143,6 +164,10 @@ type ACLPolicyListEntry struct { // Namespace is the namespace the ACLPolicyListEntry is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLPolicyListEntry is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } type ACLRolePolicyLink = ACLLink @@ -162,6 +187,10 @@ type ACLRole struct { // Namespace is the namespace the ACLRole is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLRole is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } // BindingRuleBindType is the type of binding rule mechanism used. @@ -189,6 +218,10 @@ type ACLBindingRule struct { // Namespace is the namespace the ACLBindingRule is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLBindingRule is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } type ACLAuthMethod struct { @@ -217,6 +250,10 @@ type ACLAuthMethod struct { // Namespace is the namespace the ACLAuthMethod is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLAuthMethod is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } func (m *ACLAuthMethod) MarshalJSON() ([]byte, error) { @@ -284,6 +321,10 @@ type ACLAuthMethodListEntry struct { // Namespace is the namespace the ACLAuthMethodListEntry is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the ACLAuthMethodListEntry is associated with. + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } // This is nearly identical to the ACLAuthMethod MarshalJSON @@ -448,12 +489,14 @@ func (c *Client) ACL() *ACL { // to get the first management token. func (a *ACL) Bootstrap() (*ACLToken, *WriteMeta, error) { r := a.c.newRequest("PUT", "/v1/acl/bootstrap") - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { @@ -469,11 +512,14 @@ func (a *ACL) Create(acl *ACLEntry, q *WriteOptions) (string, *WriteMeta, error) r := a.c.newRequest("PUT", "/v1/acl/create") r.setWriteOptions(q) r.obj = acl - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{RequestTime: rtt} var out struct{ ID string } @@ -490,12 +536,14 @@ func (a *ACL) Update(acl *ACLEntry, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("PUT", "/v1/acl/update") r.setWriteOptions(q) r.obj = acl - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{RequestTime: rtt} return wm, nil } @@ -506,10 +554,13 @@ func (a *ACL) Update(acl *ACLEntry, q *WriteOptions) (*WriteMeta, error) { func (a *ACL) Destroy(id string, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("PUT", "/v1/acl/destroy/"+id) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } closeResponseBody(resp) wm := &WriteMeta{RequestTime: rtt} @@ -522,11 +573,14 @@ func (a *ACL) Destroy(id string, q *WriteOptions) (*WriteMeta, error) { func (a *ACL) Clone(id string, q *WriteOptions) (string, *WriteMeta, error) { r := a.c.newRequest("PUT", "/v1/acl/clone/"+id) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{RequestTime: rtt} var out struct{ ID string } @@ -542,12 +596,14 @@ func (a *ACL) Clone(id string, q *WriteOptions) (string, *WriteMeta, error) { func (a *ACL) Info(id string, q *QueryOptions) (*ACLEntry, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/info/"+id) r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -568,12 +624,14 @@ func (a *ACL) Info(id string, q *QueryOptions) (*ACLEntry, *QueryMeta, error) { func (a *ACL) List(q *QueryOptions) ([]*ACLEntry, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/list") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -589,12 +647,14 @@ func (a *ACL) List(q *QueryOptions) ([]*ACLEntry, *QueryMeta, error) { func (a *ACL) Replication(q *QueryOptions) (*ACLReplicationStatus, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/replication") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -612,12 +672,14 @@ func (a *ACL) TokenCreate(token *ACLToken, q *WriteOptions) (*ACLToken, *WriteMe r := a.c.newRequest("PUT", "/v1/acl/token") r.setWriteOptions(q) r.obj = token - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { @@ -637,12 +699,14 @@ func (a *ACL) TokenUpdate(token *ACLToken, q *WriteOptions) (*ACLToken, *WriteMe r := a.c.newRequest("PUT", "/v1/acl/token/"+token.AccessorID) r.setWriteOptions(q) r.obj = token - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { @@ -664,12 +728,14 @@ func (a *ACL) TokenClone(tokenID string, description string, q *WriteOptions) (* r := a.c.newRequest("PUT", "/v1/acl/token/"+tokenID+"/clone") r.setWriteOptions(q) r.obj = struct{ Description string }{description} - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { @@ -684,10 +750,13 @@ func (a *ACL) TokenClone(tokenID string, description string, q *WriteOptions) (* func (a *ACL) TokenDelete(tokenID string, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("DELETE", "/v1/acl/token/"+tokenID) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } closeResponseBody(resp) wm := &WriteMeta{RequestTime: rtt} @@ -699,12 +768,14 @@ func (a *ACL) TokenDelete(tokenID string, q *WriteOptions) (*WriteMeta, error) { func (a *ACL) TokenRead(tokenID string, q *QueryOptions) (*ACLToken, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/token/"+tokenID) r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -723,12 +794,14 @@ func (a *ACL) TokenRead(tokenID string, q *QueryOptions) (*ACLToken, *QueryMeta, func (a *ACL) TokenReadSelf(q *QueryOptions) (*ACLToken, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/token/self") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -746,12 +819,14 @@ func (a *ACL) TokenReadSelf(q *QueryOptions) (*ACLToken, *QueryMeta, error) { func (a *ACL) TokenList(q *QueryOptions) ([]*ACLTokenListEntry, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/tokens") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -772,12 +847,14 @@ func (a *ACL) PolicyCreate(policy *ACLPolicy, q *WriteOptions) (*ACLPolicy, *Wri r := a.c.newRequest("PUT", "/v1/acl/policy") r.setWriteOptions(q) r.obj = policy - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLPolicy if err := decodeBody(resp, &out); err != nil { @@ -797,12 +874,14 @@ func (a *ACL) PolicyUpdate(policy *ACLPolicy, q *WriteOptions) (*ACLPolicy, *Wri r := a.c.newRequest("PUT", "/v1/acl/policy/"+policy.ID) r.setWriteOptions(q) r.obj = policy - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLPolicy if err := decodeBody(resp, &out); err != nil { @@ -816,11 +895,14 @@ func (a *ACL) PolicyUpdate(policy *ACLPolicy, q *WriteOptions) (*ACLPolicy, *Wri func (a *ACL) PolicyDelete(policyID string, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("DELETE", "/v1/acl/policy/"+policyID) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{RequestTime: rtt} return wm, nil @@ -830,12 +912,14 @@ func (a *ACL) PolicyDelete(policyID string, q *WriteOptions) (*WriteMeta, error) func (a *ACL) PolicyRead(policyID string, q *QueryOptions) (*ACLPolicy, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/policy/"+policyID) r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -852,11 +936,15 @@ func (a *ACL) PolicyRead(policyID string, q *QueryOptions) (*ACLPolicy, *QueryMe func (a *ACL) PolicyReadByName(policyName string, q *QueryOptions) (*ACLPolicy, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/policy/name/"+url.QueryEscape(policyName)) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -879,12 +967,14 @@ func (a *ACL) PolicyReadByName(policyName string, q *QueryOptions) (*ACLPolicy, func (a *ACL) PolicyList(q *QueryOptions) ([]*ACLPolicyListEntry, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/policies") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -904,11 +994,15 @@ func (a *ACL) RulesTranslate(rules io.Reader) (string, error) { r := a.c.newRequest("POST", "/v1/acl/rules/translate") r.body = rules r.header.Set("Content-Type", "text/plain") - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return "", err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", err + } + qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -928,11 +1022,14 @@ func (a *ACL) RulesTranslate(rules io.Reader) (string, error) { // when legacy ACL support is removed. func (a *ACL) RulesTranslateToken(tokenID string) (string, error) { r := a.c.newRequest("GET", "/v1/acl/rules/translate/"+tokenID) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return "", err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -955,12 +1052,14 @@ func (a *ACL) RoleCreate(role *ACLRole, q *WriteOptions) (*ACLRole, *WriteMeta, r := a.c.newRequest("PUT", "/v1/acl/role") r.setWriteOptions(q) r.obj = role - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLRole if err := decodeBody(resp, &out); err != nil { @@ -980,12 +1079,14 @@ func (a *ACL) RoleUpdate(role *ACLRole, q *WriteOptions) (*ACLRole, *WriteMeta, r := a.c.newRequest("PUT", "/v1/acl/role/"+role.ID) r.setWriteOptions(q) r.obj = role - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLRole if err := decodeBody(resp, &out); err != nil { @@ -999,10 +1100,13 @@ func (a *ACL) RoleUpdate(role *ACLRole, q *WriteOptions) (*ACLRole, *WriteMeta, func (a *ACL) RoleDelete(roleID string, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("DELETE", "/v1/acl/role/"+roleID) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } closeResponseBody(resp) wm := &WriteMeta{RequestTime: rtt} @@ -1013,11 +1117,15 @@ func (a *ACL) RoleDelete(roleID string, q *WriteOptions) (*WriteMeta, error) { func (a *ACL) RoleRead(roleID string, q *QueryOptions) (*ACLRole, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/role/"+roleID) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -1039,11 +1147,15 @@ func (a *ACL) RoleRead(roleID string, q *QueryOptions) (*ACLRole, *QueryMeta, er func (a *ACL) RoleReadByName(roleName string, q *QueryOptions) (*ACLRole, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/role/name/"+url.QueryEscape(roleName)) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -1067,12 +1179,14 @@ func (a *ACL) RoleReadByName(roleName string, q *QueryOptions) (*ACLRole, *Query func (a *ACL) RoleList(q *QueryOptions) ([]*ACLRole, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/roles") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -1093,12 +1207,14 @@ func (a *ACL) AuthMethodCreate(method *ACLAuthMethod, q *WriteOptions) (*ACLAuth r := a.c.newRequest("PUT", "/v1/acl/auth-method") r.setWriteOptions(q) r.obj = method - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLAuthMethod if err := decodeBody(resp, &out); err != nil { @@ -1117,12 +1233,14 @@ func (a *ACL) AuthMethodUpdate(method *ACLAuthMethod, q *WriteOptions) (*ACLAuth r := a.c.newRequest("PUT", "/v1/acl/auth-method/"+url.QueryEscape(method.Name)) r.setWriteOptions(q) r.obj = method - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLAuthMethod if err := decodeBody(resp, &out); err != nil { @@ -1140,10 +1258,13 @@ func (a *ACL) AuthMethodDelete(methodName string, q *WriteOptions) (*WriteMeta, r := a.c.newRequest("DELETE", "/v1/acl/auth-method/"+url.QueryEscape(methodName)) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } closeResponseBody(resp) wm := &WriteMeta{RequestTime: rtt} @@ -1158,11 +1279,15 @@ func (a *ACL) AuthMethodRead(methodName string, q *QueryOptions) (*ACLAuthMethod r := a.c.newRequest("GET", "/v1/acl/auth-method/"+url.QueryEscape(methodName)) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -1186,12 +1311,14 @@ func (a *ACL) AuthMethodRead(methodName string, q *QueryOptions) (*ACLAuthMethod func (a *ACL) AuthMethodList(q *QueryOptions) ([]*ACLAuthMethodListEntry, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/auth-methods") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -1214,12 +1341,14 @@ func (a *ACL) BindingRuleCreate(rule *ACLBindingRule, q *WriteOptions) (*ACLBind r := a.c.newRequest("PUT", "/v1/acl/binding-rule") r.setWriteOptions(q) r.obj = rule - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLBindingRule if err := decodeBody(resp, &out); err != nil { @@ -1239,12 +1368,14 @@ func (a *ACL) BindingRuleUpdate(rule *ACLBindingRule, q *WriteOptions) (*ACLBind r := a.c.newRequest("PUT", "/v1/acl/binding-rule/"+rule.ID) r.setWriteOptions(q) r.obj = rule - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLBindingRule if err := decodeBody(resp, &out); err != nil { @@ -1258,11 +1389,14 @@ func (a *ACL) BindingRuleUpdate(rule *ACLBindingRule, q *WriteOptions) (*ACLBind func (a *ACL) BindingRuleDelete(bindingRuleID string, q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("DELETE", "/v1/acl/binding-rule/"+bindingRuleID) r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{RequestTime: rtt} return wm, nil @@ -1272,11 +1406,15 @@ func (a *ACL) BindingRuleDelete(bindingRuleID string, q *WriteOptions) (*WriteMe func (a *ACL) BindingRuleRead(bindingRuleID string, q *QueryOptions) (*ACLBindingRule, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/acl/binding-rule/"+bindingRuleID) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -1301,12 +1439,14 @@ func (a *ACL) BindingRuleList(methodName string, q *QueryOptions) ([]*ACLBinding r.params.Set("authmethod", methodName) } r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -1324,12 +1464,14 @@ func (a *ACL) Login(auth *ACLLoginParams, q *WriteOptions) (*ACLToken, *WriteMet r.setWriteOptions(q) r.obj = auth - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { @@ -1342,10 +1484,13 @@ func (a *ACL) Login(auth *ACLLoginParams, q *WriteOptions) (*ACLToken, *WriteMet func (a *ACL) Logout(q *WriteOptions) (*WriteMeta, error) { r := a.c.newRequest("POST", "/v1/acl/logout") r.setWriteOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } closeResponseBody(resp) wm := &WriteMeta{RequestTime: rtt} @@ -1362,11 +1507,14 @@ func (a *ACL) OIDCAuthURL(auth *ACLOIDCAuthURLParams, q *WriteOptions) (string, r.setWriteOptions(q) r.obj = auth - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{RequestTime: rtt} var out aclOIDCAuthURLResponse @@ -1397,12 +1545,14 @@ func (a *ACL) OIDCCallback(auth *ACLOIDCCallbackParams, q *WriteOptions) (*ACLTo r.setWriteOptions(q) r.obj = auth - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out ACLToken if err := decodeBody(resp, &out); err != nil { diff --git a/vendor/github.com/hashicorp/consul/api/agent.go b/vendor/github.com/hashicorp/consul/api/agent.go index 2d13660..e3b5d36 100644 --- a/vendor/github.com/hashicorp/consul/api/agent.go +++ b/vendor/github.com/hashicorp/consul/api/agent.go @@ -2,8 +2,8 @@ package api import ( "bufio" - "bytes" "context" + "errors" "fmt" "io" "net/http" @@ -66,6 +66,7 @@ type AgentCheck struct { ExposedPort int Definition HealthCheckDefinition Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` } // AgentWeights represent optional weights for a service @@ -83,7 +84,7 @@ type AgentService struct { Meta map[string]string Port int Address string - SocketPath string + SocketPath string `json:",omitempty"` TaggedAddresses map[string]ServiceAddress `json:",omitempty"` Weights AgentWeights EnableTagOverride bool @@ -96,6 +97,7 @@ type AgentService struct { // to include the Namespace in the hash. When we do, then we are in for lots of fun with tests. // For now though, ignoring it works well enough. Namespace string `json:",omitempty" bexpr:"-" hash:"ignore"` + Partition string `json:",omitempty" bexpr:"-" hash:"ignore"` // Datacenter is only ever returned and is ignored if presented. Datacenter string `json:",omitempty" bexpr:"-" hash:"ignore"` } @@ -142,11 +144,23 @@ const ( // that the member represents a Consul server. MemberTagValueRoleServer = "consul" + // MemberTagValueRoleClient is the value of the MemberTagKeyRole used to indicate + // that the member represents a Consul client. + MemberTagValueRoleClient = "node" + + // MemberTagKeyDatacenter is the key used to indicate which datacenter this member is in. + MemberTagKeyDatacenter = "dc" + // MemberTagKeySegment is the key name of the tag used to indicate which network // segment this member is in. // Network Segments are a Consul Enterprise feature. MemberTagKeySegment = "segment" + // MemberTagKeyPartition is the key name of the tag used to indicate which partition + // this member is in. + // Partitions are a Consul Enterprise feature. + MemberTagKeyPartition = "ap" + // MemberTagKeyBootstrap is the key name of the tag used to indicate whether this // agent was started with the "bootstrap" configuration enabled MemberTagKeyBootstrap = "bootstrap" @@ -271,13 +285,14 @@ type AgentServiceRegistration struct { Proxy *AgentServiceConnectProxyConfig `json:",omitempty"` Connect *AgentServiceConnect `json:",omitempty"` Namespace string `json:",omitempty" bexpr:"-" hash:"ignore"` + Partition string `json:",omitempty" bexpr:"-" hash:"ignore"` } // ServiceRegisterOpts is used to pass extra options to the service register. type ServiceRegisterOpts struct { - //Missing healthchecks will be deleted from the agent. - //Using this parameter allows to idempotently register a service and its checks without - //having to manually deregister checks. + // Missing healthchecks will be deleted from the agent. + // Using this parameter allows to idempotently register a service and its checks without + // having to manually deregister checks. ReplaceExistingChecks bool // ctx is an optional context pass through to the underlying HTTP @@ -300,6 +315,7 @@ type AgentCheckRegistration struct { ServiceID string `json:",omitempty"` AgentServiceCheck Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` } // AgentServiceCheck is used to define a node or service level check @@ -323,9 +339,12 @@ type AgentServiceCheck struct { TLSSkipVerify bool `json:",omitempty"` GRPC string `json:",omitempty"` GRPCUseTLS bool `json:",omitempty"` + H2PING string `json:",omitempty"` + H2PingUseTLS bool `json:",omitempty"` AliasNode string `json:",omitempty"` AliasService string `json:",omitempty"` SuccessBeforePassing int `json:",omitempty"` + FailuresBeforeWarning int `json:",omitempty"` FailuresBeforeCritical int `json:",omitempty"` // In Consul 0.7 and later, checks that are associated with a service @@ -406,6 +425,7 @@ type ConnectProxyConfig struct { // Upstream is the response structure for a proxy upstream configuration. type Upstream struct { DestinationType UpstreamDestType `json:",omitempty"` + DestinationPartition string `json:",omitempty"` DestinationNamespace string `json:",omitempty"` DestinationName string Datacenter string `json:",omitempty"` @@ -435,11 +455,14 @@ func (c *Client) Agent() *Agent { // information about itself func (a *Agent) Self() (map[string]map[string]interface{}, error) { r := a.c.newRequest("GET", "/v1/agent/self") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out map[string]map[string]interface{} if err := decodeBody(resp, &out); err != nil { @@ -453,12 +476,14 @@ func (a *Agent) Self() (map[string]map[string]interface{}, error) { // a operator:read ACL token. func (a *Agent) Host() (map[string]interface{}, error) { r := a.c.newRequest("GET", "/v1/agent/host") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out map[string]interface{} if err := decodeBody(resp, &out); err != nil { return nil, err @@ -470,12 +495,14 @@ func (a *Agent) Host() (map[string]interface{}, error) { // its current internal metric data func (a *Agent) Metrics() (*MetricsInfo, error) { r := a.c.newRequest("GET", "/v1/agent/metrics") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out *MetricsInfo if err := decodeBody(resp, &out); err != nil { return nil, err @@ -483,14 +510,33 @@ func (a *Agent) Metrics() (*MetricsInfo, error) { return out, nil } +// MetricsStream returns an io.ReadCloser which will emit a stream of metrics +// until the context is cancelled. The metrics are json encoded. +// The caller is responsible for closing the returned io.ReadCloser. +func (a *Agent) MetricsStream(ctx context.Context) (io.ReadCloser, error) { + r := a.c.newRequest("GET", "/v1/agent/metrics/stream") + r.ctx = ctx + _, resp, err := a.c.doRequest(r) + if err != nil { + return nil, err + } + if err := requireOK(resp); err != nil { + return nil, err + } + return resp.Body, nil +} + // Reload triggers a configuration reload for the agent we are connected to. func (a *Agent) Reload() error { r := a.c.newRequest("PUT", "/v1/agent/reload") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -525,12 +571,14 @@ func (a *Agent) ChecksWithFilterOpts(filter string, q *QueryOptions) (map[string r := a.c.newRequest("GET", "/v1/agent/checks") r.setQueryOptions(q) r.filterQuery(filter) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out map[string]*AgentCheck if err := decodeBody(resp, &out); err != nil { return nil, err @@ -555,12 +603,14 @@ func (a *Agent) ServicesWithFilterOpts(filter string, q *QueryOptions) (map[stri r := a.c.newRequest("GET", "/v1/agent/services") r.setQueryOptions(q) r.filterQuery(filter) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out map[string]*AgentService if err := decodeBody(resp, &out); err != nil { return nil, err @@ -574,10 +624,17 @@ func (a *Agent) ServicesWithFilterOpts(filter string, q *QueryOptions) (map[stri // - If the service is found, will return (critical|passing|warning), AgentServiceChecksInfo, nil) // - In all other cases, will return an error func (a *Agent) AgentHealthServiceByID(serviceID string) (string, *AgentServiceChecksInfo, error) { + return a.AgentHealthServiceByIDOpts(serviceID, nil) +} + +func (a *Agent) AgentHealthServiceByIDOpts(serviceID string, q *QueryOptions) (string, *AgentServiceChecksInfo, error) { path := fmt.Sprintf("/v1/agent/health/service/id/%v", url.PathEscape(serviceID)) r := a.c.newRequest("GET", path) + r.setQueryOptions(q) r.params.Add("format", "json") r.header.Set("Accept", "application/json") + // not a lot of value in wrapping the doRequest call in a requireHttpCodes call + // we manipulate the resp body and the require calls "swallow" the content on err _, resp, err := a.c.doRequest(r) if err != nil { return "", nil, err @@ -608,10 +665,17 @@ func (a *Agent) AgentHealthServiceByID(serviceID string) (string, *AgentServiceC // - If the service is found, will return (critical|passing|warning), []api.AgentServiceChecksInfo, nil) // - In all other cases, will return an error func (a *Agent) AgentHealthServiceByName(service string) (string, []AgentServiceChecksInfo, error) { + return a.AgentHealthServiceByNameOpts(service, nil) +} + +func (a *Agent) AgentHealthServiceByNameOpts(service string, q *QueryOptions) (string, []AgentServiceChecksInfo, error) { path := fmt.Sprintf("/v1/agent/health/service/name/%v", url.PathEscape(service)) r := a.c.newRequest("GET", path) + r.setQueryOptions(q) r.params.Add("format", "json") r.header.Set("Accept", "application/json") + // not a lot of value in wrapping the doRequest call in a requireHttpCodes call + // we manipulate the resp body and the require calls "swallow" the content on err _, resp, err := a.c.doRequest(r) if err != nil { return "", nil, err @@ -645,12 +709,14 @@ func (a *Agent) AgentHealthServiceByName(service string) (string, []AgentService func (a *Agent) Service(serviceID string, q *QueryOptions) (*AgentService, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/agent/service/"+serviceID) r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -670,12 +736,14 @@ func (a *Agent) Members(wan bool) ([]*AgentMember, error) { if wan { r.params.Set("wan", "1") } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out []*AgentMember if err := decodeBody(resp, &out); err != nil { return nil, err @@ -692,12 +760,14 @@ func (a *Agent) MembersOpts(opts MembersOpts) ([]*AgentMember, error) { r.params.Set("wan", "1") } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out []*AgentMember if err := decodeBody(resp, &out); err != nil { return nil, err @@ -728,11 +798,14 @@ func (a *Agent) serviceRegister(service *AgentServiceRegistration, opts ServiceR if opts.ReplaceExistingChecks { r.params.Set("replace-existing-checks", "true") } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -740,11 +813,14 @@ func (a *Agent) serviceRegister(service *AgentServiceRegistration, opts ServiceR // the local agent func (a *Agent) ServiceDeregister(serviceID string) error { r := a.c.newRequest("PUT", "/v1/agent/service/deregister/"+serviceID) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -753,11 +829,14 @@ func (a *Agent) ServiceDeregister(serviceID string) error { func (a *Agent) ServiceDeregisterOpts(serviceID string, q *QueryOptions) error { r := a.c.newRequest("PUT", "/v1/agent/service/deregister/"+serviceID) r.setQueryOptions(q) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -808,11 +887,14 @@ func (a *Agent) updateTTL(checkID, note, status string) error { endpoint := fmt.Sprintf("/v1/agent/check/%s/%s", status, checkID) r := a.c.newRequest("PUT", endpoint) r.params.Set("note", note) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -858,11 +940,14 @@ func (a *Agent) UpdateTTLOpts(checkID, output, status string, q *QueryOptions) e Output: output, } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -871,11 +956,14 @@ func (a *Agent) UpdateTTLOpts(checkID, output, status string, q *QueryOptions) e func (a *Agent) CheckRegister(check *AgentCheckRegistration) error { r := a.c.newRequest("PUT", "/v1/agent/check/register") r.obj = check - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -890,11 +978,14 @@ func (a *Agent) CheckDeregister(checkID string) error { func (a *Agent) CheckDeregisterOpts(checkID string, q *QueryOptions) error { r := a.c.newRequest("PUT", "/v1/agent/check/deregister/"+checkID) r.setQueryOptions(q) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -905,46 +996,69 @@ func (a *Agent) Join(addr string, wan bool) error { if wan { r.params.Set("wan", "1") } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } // Leave is used to have the agent gracefully leave the cluster and shutdown func (a *Agent) Leave() error { r := a.c.newRequest("PUT", "/v1/agent/leave") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } +type ForceLeaveOpts struct { + // Prune indicates if we should remove a failed agent from the list of + // members in addition to ejecting it. + Prune bool + + // WAN indicates that the request should exclusively target the WAN pool. + WAN bool +} + // ForceLeave is used to have the agent eject a failed node func (a *Agent) ForceLeave(node string) error { - r := a.c.newRequest("PUT", "/v1/agent/force-leave/"+node) - _, resp, err := requireOK(a.c.doRequest(r)) - if err != nil { - return err - } - closeResponseBody(resp) - return nil + return a.ForceLeaveOpts(node, ForceLeaveOpts{}) } -//ForceLeavePrune is used to have an a failed agent removed -//from the list of members +// ForceLeavePrune is used to have an a failed agent removed +// from the list of members func (a *Agent) ForceLeavePrune(node string) error { + return a.ForceLeaveOpts(node, ForceLeaveOpts{Prune: true}) +} + +// ForceLeaveOpts is used to have the agent eject a failed node or remove it +// completely from the list of members. +func (a *Agent) ForceLeaveOpts(node string, opts ForceLeaveOpts) error { r := a.c.newRequest("PUT", "/v1/agent/force-leave/"+node) - r.params.Set("prune", "1") - _, resp, err := requireOK(a.c.doRequest(r)) + if opts.Prune { + r.params.Set("prune", "1") + } + if opts.WAN { + r.params.Set("wan", "1") + } + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -953,12 +1067,14 @@ func (a *Agent) ForceLeavePrune(node string) error { func (a *Agent) ConnectAuthorize(auth *AgentAuthorizeParams) (*AgentAuthorize, error) { r := a.c.newRequest("POST", "/v1/agent/connect/authorize") r.obj = auth - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } var out AgentAuthorize if err := decodeBody(resp, &out); err != nil { return nil, err @@ -970,11 +1086,14 @@ func (a *Agent) ConnectAuthorize(auth *AgentAuthorizeParams) (*AgentAuthorize, e func (a *Agent) ConnectCARoots(q *QueryOptions) (*CARootList, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/agent/connect/ca/roots") r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -991,12 +1110,14 @@ func (a *Agent) ConnectCARoots(q *QueryOptions) (*CARootList, *QueryMeta, error) func (a *Agent) ConnectCALeaf(serviceID string, q *QueryOptions) (*LeafCert, *QueryMeta, error) { r := a.c.newRequest("GET", "/v1/agent/connect/ca/leaf/"+serviceID) r.setQueryOptions(q) - rtt, resp, err := requireOK(a.c.doRequest(r)) + rtt, resp, err := a.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -1011,27 +1132,43 @@ func (a *Agent) ConnectCALeaf(serviceID string, q *QueryOptions) (*LeafCert, *Qu // EnableServiceMaintenance toggles service maintenance mode on // for the given service ID. func (a *Agent) EnableServiceMaintenance(serviceID, reason string) error { + return a.EnableServiceMaintenanceOpts(serviceID, reason, nil) +} + +func (a *Agent) EnableServiceMaintenanceOpts(serviceID, reason string, q *QueryOptions) error { r := a.c.newRequest("PUT", "/v1/agent/service/maintenance/"+serviceID) + r.setQueryOptions(q) r.params.Set("enable", "true") r.params.Set("reason", reason) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } // DisableServiceMaintenance toggles service maintenance mode off // for the given service ID. func (a *Agent) DisableServiceMaintenance(serviceID string) error { + return a.DisableServiceMaintenanceOpts(serviceID, nil) +} + +func (a *Agent) DisableServiceMaintenanceOpts(serviceID string, q *QueryOptions) error { r := a.c.newRequest("PUT", "/v1/agent/service/maintenance/"+serviceID) + r.setQueryOptions(q) r.params.Set("enable", "false") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -1041,11 +1178,14 @@ func (a *Agent) EnableNodeMaintenance(reason string) error { r := a.c.newRequest("PUT", "/v1/agent/maintenance") r.params.Set("enable", "true") r.params.Set("reason", reason) - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -1054,11 +1194,14 @@ func (a *Agent) EnableNodeMaintenance(reason string) error { func (a *Agent) DisableNodeMaintenance() error { r := a.c.newRequest("PUT", "/v1/agent/maintenance") r.params.Set("enable", "false") - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -1074,6 +1217,7 @@ func (a *Agent) Monitor(loglevel string, stopCh <-chan struct{}, q *QueryOptions func (a *Agent) MonitorJSON(loglevel string, stopCh <-chan struct{}, q *QueryOptions) (chan string, error) { return a.monitor(loglevel, true, stopCh, q) } + func (a *Agent) monitor(loglevel string, logJSON bool, stopCh <-chan struct{}, q *QueryOptions) (chan string, error) { r := a.c.newRequest("GET", "/v1/agent/monitor") r.setQueryOptions(q) @@ -1083,10 +1227,13 @@ func (a *Agent) monitor(loglevel string, logJSON bool, stopCh <-chan struct{}, q if logJSON { r.params.Set("logjson", "true") } - _, resp, err := requireOK(a.c.doRequest(r)) + _, resp, err := a.c.doRequest(r) if err != nil { return nil, err } + if err := requireOK(resp); err != nil { + return nil, err + } logCh := make(chan string, 64) go func() { defer closeResponseBody(resp) @@ -1151,25 +1298,33 @@ func (a *Agent) UpdateACLReplicationToken(token string, q *WriteOptions) (*Write // UpdateDefaultACLToken updates the agent's "default" token. See updateToken // for more details func (a *Agent) UpdateDefaultACLToken(token string, q *WriteOptions) (*WriteMeta, error) { - return a.updateTokenFallback("default", "acl_token", token, q) + return a.updateTokenFallback(token, q, "default", "acl_token") } // UpdateAgentACLToken updates the agent's "agent" token. See updateToken // for more details func (a *Agent) UpdateAgentACLToken(token string, q *WriteOptions) (*WriteMeta, error) { - return a.updateTokenFallback("agent", "acl_agent_token", token, q) + return a.updateTokenFallback(token, q, "agent", "acl_agent_token") +} + +// UpdateAgentRecoveryACLToken updates the agent's "agent_recovery" token. See updateToken +// for more details. +func (a *Agent) UpdateAgentRecoveryACLToken(token string, q *WriteOptions) (*WriteMeta, error) { + return a.updateTokenFallback(token, q, "agent_recovery", "agent_master", "acl_agent_master_token") } // UpdateAgentMasterACLToken updates the agent's "agent_master" token. See updateToken -// for more details +// for more details. +// +// DEPRECATED - Prefer UpdateAgentRecoveryACLToken for v1.11 and above. func (a *Agent) UpdateAgentMasterACLToken(token string, q *WriteOptions) (*WriteMeta, error) { - return a.updateTokenFallback("agent_master", "acl_agent_master_token", token, q) + return a.updateTokenFallback(token, q, "agent_master", "acl_agent_master_token") } // UpdateReplicationACLToken updates the agent's "replication" token. See updateToken // for more details func (a *Agent) UpdateReplicationACLToken(token string, q *WriteOptions) (*WriteMeta, error) { - return a.updateTokenFallback("replication", "acl_replication_token", token, q) + return a.updateTokenFallback(token, q, "replication", "acl_replication_token") } // updateToken can be used to update one of an agent's ACL tokens after the agent has @@ -1180,10 +1335,21 @@ func (a *Agent) updateToken(target, token string, q *WriteOptions) (*WriteMeta, return meta, err } -func (a *Agent) updateTokenFallback(target, fallback, token string, q *WriteOptions) (*WriteMeta, error) { - meta, status, err := a.updateTokenOnce(target, token, q) - if err != nil && status == 404 { - meta, _, err = a.updateTokenOnce(fallback, token, q) +func (a *Agent) updateTokenFallback(token string, q *WriteOptions, targets ...string) (*WriteMeta, error) { + if len(targets) == 0 { + panic("targets must not be empty") + } + + var ( + meta *WriteMeta + err error + ) + for _, target := range targets { + var status int + meta, status, err = a.updateTokenOnce(target, token, q) + if err == nil && status != http.StatusNotFound { + return meta, err + } } return meta, err } @@ -1195,17 +1361,16 @@ func (a *Agent) updateTokenOnce(target, token string, q *WriteOptions) (*WriteMe rtt, resp, err := a.c.doRequest(r) if err != nil { - return nil, 0, err + return nil, 500, err } defer closeResponseBody(resp) - wm := &WriteMeta{RequestTime: rtt} - - if resp.StatusCode != 200 { - var buf bytes.Buffer - io.Copy(&buf, resp.Body) - return wm, resp.StatusCode, fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, buf.Bytes()) + if err := requireOK(resp); err != nil { + var statusE StatusError + if errors.As(err, &statusE) { + return wm, statusE.Code, statusE + } + return nil, 0, err } - return wm, resp.StatusCode, nil } diff --git a/vendor/github.com/hashicorp/consul/api/api.go b/vendor/github.com/hashicorp/consul/api/api.go index a35980a..d97f187 100644 --- a/vendor/github.com/hashicorp/consul/api/api.go +++ b/vendor/github.com/hashicorp/consul/api/api.go @@ -76,14 +76,31 @@ const ( // HTTPNamespaceEnvVar defines an environment variable name which sets // the HTTP Namespace to be used by default. This can still be overridden. HTTPNamespaceEnvName = "CONSUL_NAMESPACE" + + // HTTPPartitionEnvName defines an environment variable name which sets + // the HTTP Partition to be used by default. This can still be overridden. + HTTPPartitionEnvName = "CONSUL_PARTITION" ) +type StatusError struct { + Code int + Body string +} + +func (e StatusError) Error() string { + return fmt.Sprintf("Unexpected response code: %d (%s)", e.Code, e.Body) +} + // QueryOptions are used to parameterize a query type QueryOptions struct { // Namespace overrides the `default` namespace // Note: Namespaces are available only in Consul Enterprise Namespace string + // Partition overrides the `default` partition + // Note: Partitions are available only in Consul Enterprise + Partition string + // Providing a datacenter overwrites the DC provided // by the Config Datacenter string @@ -191,6 +208,10 @@ type WriteOptions struct { // Note: Namespaces are available only in Consul Enterprise Namespace string + // Partition overrides the `default` partition + // Note: Partitions are available only in Consul Enterprise + Partition string + // Providing a datacenter overwrites the DC provided // by the Config Datacenter string @@ -260,6 +281,11 @@ type QueryMeta struct { // defined policy. This can be "allow" which means ACLs are used to // deny-list, or "deny" which means ACLs are allow-lists. DefaultACLPolicy string + + // ResultsFilteredByACLs is true when some of the query's results were + // filtered out by enforcing ACLs. It may be false because nothing was + // removed, or because the endpoint does not yet support this flag. + ResultsFilteredByACLs bool } // WriteMeta is used to return meta data about a write @@ -314,6 +340,10 @@ type Config struct { // when no other Namespace is present in the QueryOptions Namespace string + // Partition is the name of the partition to send along for the request + // when no other Partition is present in the QueryOptions + Partition string + TLSConfig TLSConfig } @@ -466,6 +496,10 @@ func defaultConfig(logger hclog.Logger, transportFn func() *http.Transport) *Con config.Namespace = v } + if v := os.Getenv(HTTPPartitionEnvName); v != "" { + config.Partition = v + } + return config } @@ -640,6 +674,14 @@ func NewClient(config *Config) (*Client, error) { } } + if config.Namespace == "" { + config.Namespace = defConfig.Namespace + } + + if config.Partition == "" { + config.Partition = defConfig.Partition + } + parts := strings.SplitN(config.Address, "://", 2) if len(parts) == 2 { switch parts[0] { @@ -732,6 +774,9 @@ func (r *request) setQueryOptions(q *QueryOptions) { if q.Namespace != "" { r.params.Set("ns", q.Namespace) } + if q.Partition != "" { + r.params.Set("partition", q.Partition) + } if q.Datacenter != "" { r.params.Set("dc", q.Datacenter) } @@ -834,6 +879,9 @@ func (r *request) setWriteOptions(q *WriteOptions) { if q.Namespace != "" { r.params.Set("ns", q.Namespace) } + if q.Partition != "" { + r.params.Set("partition", q.Partition) + } if q.Datacenter != "" { r.params.Set("dc", q.Datacenter) } @@ -908,6 +956,9 @@ func (c *Client) newRequest(method, path string) *request { if c.config.Namespace != "" { r.params.Set("ns", c.config.Namespace) } + if c.config.Partition != "" { + r.params.Set("partition", c.config.Partition) + } if c.config.WaitTime != 0 { r.params.Set("wait", durToMsec(r.config.WaitTime)) } @@ -940,7 +991,9 @@ func (c *Client) query(endpoint string, out interface{}, q *QueryOptions) (*Quer return nil, err } defer closeResponseBody(resp) - + if err := requireOK(resp); err != nil { + return nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -957,11 +1010,14 @@ func (c *Client) write(endpoint string, in, out interface{}, q *WriteOptions) (* r := c.newRequest("PUT", endpoint) r.setWriteOptions(q) r.obj = in - rtt, resp, err := requireOK(c.doRequest(r)) + rtt, resp, err := c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{RequestTime: rtt} if out != nil { @@ -1020,6 +1076,14 @@ func parseQueryMeta(resp *http.Response, q *QueryMeta) error { q.DefaultACLPolicy = v } + // Parse the X-Consul-Results-Filtered-By-ACLs + switch header.Get("X-Consul-Results-Filtered-By-ACLs") { + case "true": + q.ResultsFilteredByACLs = true + default: + q.ResultsFilteredByACLs = false + } + // Parse Cache info if cacheStr := header.Get("X-Cache"); cacheStr != "" { q.CacheHit = strings.EqualFold(cacheStr, "HIT") @@ -1052,17 +1116,22 @@ func encodeBody(obj interface{}) (io.Reader, error) { } // requireOK is used to wrap doRequest and check for a 200 -func requireOK(d time.Duration, resp *http.Response, e error) (time.Duration, *http.Response, error) { - if e != nil { - if resp != nil { - closeResponseBody(resp) +func requireOK(resp *http.Response) error { + return requireHttpCodes(resp, 200) +} + +// requireHttpCodes checks for the "allowable" http codes for a response +func requireHttpCodes(resp *http.Response, httpCodes ...int) error { + // if there is an http code that we require, return w no error + for _, httpCode := range httpCodes { + if resp.StatusCode == httpCode { + return nil } - return d, nil, e - } - if resp.StatusCode != 200 { - return d, nil, generateUnexpectedResponseCodeError(resp) } - return d, resp, nil + + // if we reached here, then none of the http codes in resp matched any that we expected + // so err out + return generateUnexpectedResponseCodeError(resp) } // closeResponseBody reads resp.Body until EOF, and then closes it. The read @@ -1088,22 +1157,18 @@ func generateUnexpectedResponseCodeError(resp *http.Response) error { var buf bytes.Buffer io.Copy(&buf, resp.Body) closeResponseBody(resp) - return fmt.Errorf("Unexpected response code: %d (%s)", resp.StatusCode, buf.Bytes()) + + trimmed := strings.TrimSpace(string(buf.Bytes())) + return StatusError{Code: resp.StatusCode, Body: trimmed} } -func requireNotFoundOrOK(d time.Duration, resp *http.Response, e error) (bool, time.Duration, *http.Response, error) { - if e != nil { - if resp != nil { - closeResponseBody(resp) - } - return false, d, nil, e - } +func requireNotFoundOrOK(resp *http.Response) (bool, *http.Response, error) { switch resp.StatusCode { case 200: - return true, d, resp, nil + return true, resp, nil case 404: - return false, d, resp, nil + return false, resp, nil default: - return false, d, nil, generateUnexpectedResponseCodeError(resp) + return false, nil, generateUnexpectedResponseCodeError(resp) } } diff --git a/vendor/github.com/hashicorp/consul/api/catalog.go b/vendor/github.com/hashicorp/consul/api/catalog.go index b8588d8..80ae325 100644 --- a/vendor/github.com/hashicorp/consul/api/catalog.go +++ b/vendor/github.com/hashicorp/consul/api/catalog.go @@ -19,6 +19,7 @@ type Node struct { Meta map[string]string CreateIndex uint64 ModifyIndex uint64 + Partition string `json:",omitempty"` } type ServiceAddress struct { @@ -47,6 +48,7 @@ type CatalogService struct { Checks HealthChecks ModifyIndex uint64 Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` } type CatalogNode struct { @@ -70,6 +72,7 @@ type CatalogRegistration struct { Check *AgentCheck Checks HealthChecks SkipNodeUpdate bool + Partition string `json:",omitempty"` } type CatalogDeregistration struct { @@ -79,6 +82,7 @@ type CatalogDeregistration struct { ServiceID string CheckID string Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` } type CompoundServiceName struct { @@ -86,6 +90,8 @@ type CompoundServiceName struct { // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + // Partitions are a Consul Enterprise feature. + Partition string `json:",omitempty"` } // GatewayService associates a gateway with a linked service. @@ -118,11 +124,14 @@ func (c *Catalog) Register(reg *CatalogRegistration, q *WriteOptions) (*WriteMet r := c.c.newRequest("PUT", "/v1/catalog/register") r.setWriteOptions(q) r.obj = reg - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -134,11 +143,14 @@ func (c *Catalog) Deregister(dereg *CatalogDeregistration, q *WriteOptions) (*Wr r := c.c.newRequest("PUT", "/v1/catalog/deregister") r.setWriteOptions(q) r.obj = dereg - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -149,11 +161,14 @@ func (c *Catalog) Deregister(dereg *CatalogDeregistration, q *WriteOptions) (*Wr // Datacenters is used to query for all the known datacenters func (c *Catalog) Datacenters() ([]string, error) { r := c.c.newRequest("GET", "/v1/catalog/datacenters") - _, resp, err := requireOK(c.c.doRequest(r)) + _, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out []string if err := decodeBody(resp, &out); err != nil { @@ -166,11 +181,14 @@ func (c *Catalog) Datacenters() ([]string, error) { func (c *Catalog) Nodes(q *QueryOptions) ([]*Node, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/catalog/nodes") r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -187,11 +205,14 @@ func (c *Catalog) Nodes(q *QueryOptions) ([]*Node, *QueryMeta, error) { func (c *Catalog) Services(q *QueryOptions) (map[string][]string, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/catalog/services") r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -244,11 +265,14 @@ func (c *Catalog) service(service string, tags []string, q *QueryOptions, connec r.params.Add("tag", tag) } } - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -265,11 +289,14 @@ func (c *Catalog) service(service string, tags []string, q *QueryOptions, connec func (c *Catalog) Node(node string, q *QueryOptions) (*CatalogNode, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/catalog/node/"+node) r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -289,11 +316,14 @@ func (c *Catalog) Node(node string, q *QueryOptions) (*CatalogNode, *QueryMeta, func (c *Catalog) NodeServiceList(node string, q *QueryOptions) (*CatalogNodeServiceList, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/catalog/node-services/"+node) r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -310,11 +340,14 @@ func (c *Catalog) NodeServiceList(node string, q *QueryOptions) (*CatalogNodeSer func (c *Catalog) GatewayServices(gateway string, q *QueryOptions) ([]*GatewayService, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/catalog/gateway-services/"+gateway) r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/config_entry.go b/vendor/github.com/hashicorp/consul/api/config_entry.go index e28c7dc..91c407b 100644 --- a/vendor/github.com/hashicorp/consul/api/config_entry.go +++ b/vendor/github.com/hashicorp/consul/api/config_entry.go @@ -22,6 +22,7 @@ const ( TerminatingGateway string = "terminating-gateway" ServiceIntentions string = "service-intentions" MeshConfig string = "mesh" + ExportedServices string = "exported-services" ProxyConfigGlobal string = "global" MeshConfigMesh string = "mesh" @@ -30,6 +31,7 @@ const ( type ConfigEntry interface { GetKind() string GetName() string + GetPartition() string GetNamespace() string GetMeta() map[string]string GetCreateIndex() uint64 @@ -133,6 +135,10 @@ type UpstreamConfiguration struct { type UpstreamConfig struct { // Name is only accepted within a service-defaults config entry. Name string `json:",omitempty"` + + // Partition is only accepted within a service-defaults config entry. + Partition string `json:",omitempty"` + // Namespace is only accepted within a service-defaults config entry. Namespace string `json:",omitempty"` @@ -205,6 +211,7 @@ type UpstreamLimits struct { type ServiceConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Protocol string `json:",omitempty"` Mode ProxyMode `json:",omitempty"` @@ -219,33 +226,18 @@ type ServiceConfigEntry struct { ModifyIndex uint64 } -func (s *ServiceConfigEntry) GetKind() string { - return s.Kind -} - -func (s *ServiceConfigEntry) GetName() string { - return s.Name -} - -func (s *ServiceConfigEntry) GetNamespace() string { - return s.Namespace -} - -func (s *ServiceConfigEntry) GetMeta() map[string]string { - return s.Meta -} - -func (s *ServiceConfigEntry) GetCreateIndex() uint64 { - return s.CreateIndex -} - -func (s *ServiceConfigEntry) GetModifyIndex() uint64 { - return s.ModifyIndex -} +func (s *ServiceConfigEntry) GetKind() string { return s.Kind } +func (s *ServiceConfigEntry) GetName() string { return s.Name } +func (s *ServiceConfigEntry) GetPartition() string { return s.Partition } +func (s *ServiceConfigEntry) GetNamespace() string { return s.Namespace } +func (s *ServiceConfigEntry) GetMeta() map[string]string { return s.Meta } +func (s *ServiceConfigEntry) GetCreateIndex() uint64 { return s.CreateIndex } +func (s *ServiceConfigEntry) GetModifyIndex() uint64 { return s.ModifyIndex } type ProxyConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Mode ProxyMode `json:",omitempty"` TransparentProxy *TransparentProxyConfig `json:",omitempty" alias:"transparent_proxy"` @@ -257,29 +249,13 @@ type ProxyConfigEntry struct { ModifyIndex uint64 } -func (p *ProxyConfigEntry) GetKind() string { - return p.Kind -} - -func (p *ProxyConfigEntry) GetName() string { - return p.Name -} - -func (p *ProxyConfigEntry) GetNamespace() string { - return p.Namespace -} - -func (p *ProxyConfigEntry) GetMeta() map[string]string { - return p.Meta -} - -func (p *ProxyConfigEntry) GetCreateIndex() uint64 { - return p.CreateIndex -} - -func (p *ProxyConfigEntry) GetModifyIndex() uint64 { - return p.ModifyIndex -} +func (p *ProxyConfigEntry) GetKind() string { return p.Kind } +func (p *ProxyConfigEntry) GetName() string { return p.Name } +func (p *ProxyConfigEntry) GetPartition() string { return p.Partition } +func (p *ProxyConfigEntry) GetNamespace() string { return p.Namespace } +func (p *ProxyConfigEntry) GetMeta() map[string]string { return p.Meta } +func (p *ProxyConfigEntry) GetCreateIndex() uint64 { return p.CreateIndex } +func (p *ProxyConfigEntry) GetModifyIndex() uint64 { return p.ModifyIndex } func makeConfigEntry(kind, name string) (ConfigEntry, error) { switch kind { @@ -301,6 +277,8 @@ func makeConfigEntry(kind, name string) (ConfigEntry, error) { return &ServiceIntentionsConfigEntry{Kind: kind, Name: name}, nil case MeshConfig: return &MeshConfigEntry{}, nil + case ExportedServices: + return &ExportedServicesConfigEntry{Name: name}, nil default: return nil, fmt.Errorf("invalid config entry kind: %s", kind) } @@ -402,12 +380,14 @@ func (conf *ConfigEntries) Get(kind string, name string, q *QueryOptions) (Confi r := conf.c.newRequest("GET", fmt.Sprintf("/v1/config/%s/%s", kind, name)) r.setQueryOptions(q) - rtt, resp, err := requireOK(conf.c.doRequest(r)) + rtt, resp, err := conf.c.doRequest(r) if err != nil { return nil, nil, err } - defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -427,12 +407,14 @@ func (conf *ConfigEntries) List(kind string, q *QueryOptions) ([]ConfigEntry, *Q r := conf.c.newRequest("GET", fmt.Sprintf("/v1/config/%s", kind)) r.setQueryOptions(q) - rtt, resp, err := requireOK(conf.c.doRequest(r)) + rtt, resp, err := conf.c.doRequest(r) if err != nil { return nil, nil, err } - defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -466,11 +448,14 @@ func (conf *ConfigEntries) set(entry ConfigEntry, params map[string]string, w *W r.params.Set(param, value) } r.obj = entry - rtt, resp, err := requireOK(conf.c.doRequest(r)) + rtt, resp, err := conf.c.doRequest(r) if err != nil { return false, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return false, nil, err + } var buf bytes.Buffer if _, err := io.Copy(&buf, resp.Body); err != nil { @@ -483,17 +468,45 @@ func (conf *ConfigEntries) set(entry ConfigEntry, params map[string]string, w *W } func (conf *ConfigEntries) Delete(kind string, name string, w *WriteOptions) (*WriteMeta, error) { + _, wm, err := conf.delete(kind, name, nil, w) + return wm, err +} + +// DeleteCAS performs a Check-And-Set deletion of the given config entry, and +// returns true if it was successful. If the provided index no longer matches +// the entry's ModifyIndex (i.e. it was modified by another process) then the +// operation will fail and return false. +func (conf *ConfigEntries) DeleteCAS(kind, name string, index uint64, w *WriteOptions) (bool, *WriteMeta, error) { + return conf.delete(kind, name, map[string]string{"cas": strconv.FormatUint(index, 10)}, w) +} + +func (conf *ConfigEntries) delete(kind, name string, params map[string]string, w *WriteOptions) (bool, *WriteMeta, error) { if kind == "" || name == "" { - return nil, fmt.Errorf("Both kind and name parameters must not be empty") + return false, nil, fmt.Errorf("Both kind and name parameters must not be empty") } r := conf.c.newRequest("DELETE", fmt.Sprintf("/v1/config/%s/%s", kind, name)) r.setWriteOptions(w) - rtt, resp, err := requireOK(conf.c.doRequest(r)) + for param, value := range params { + r.params.Set(param, value) + } + + rtt, resp, err := conf.c.doRequest(r) if err != nil { - return nil, err + return false, nil, err } - closeResponseBody(resp) + defer closeResponseBody(resp) + + if err := requireOK(resp); err != nil { + return false, nil, err + } + + var buf bytes.Buffer + if _, err := io.Copy(&buf, resp.Body); err != nil { + return false, nil, fmt.Errorf("Failed to read response: %v", err) + } + + res := strings.Contains(buf.String(), "true") wm := &WriteMeta{RequestTime: rtt} - return wm, nil + return res, wm, nil } diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_cluster.go b/vendor/github.com/hashicorp/consul/api/config_entry_cluster.go deleted file mode 100644 index 9ec18ea..0000000 --- a/vendor/github.com/hashicorp/consul/api/config_entry_cluster.go +++ /dev/null @@ -1,53 +0,0 @@ -package api - -import "encoding/json" - -type MeshConfigEntry struct { - Namespace string `json:",omitempty"` - TransparentProxy TransparentProxyMeshConfig `alias:"transparent_proxy"` - Meta map[string]string `json:",omitempty"` - CreateIndex uint64 - ModifyIndex uint64 -} - -type TransparentProxyMeshConfig struct { - MeshDestinationsOnly bool `alias:"mesh_destinations_only"` -} - -func (e *MeshConfigEntry) GetKind() string { - return MeshConfig -} - -func (e *MeshConfigEntry) GetName() string { - return MeshConfigMesh -} - -func (e *MeshConfigEntry) GetNamespace() string { - return e.Namespace -} - -func (e *MeshConfigEntry) GetMeta() map[string]string { - return e.Meta -} - -func (e *MeshConfigEntry) GetCreateIndex() uint64 { - return e.CreateIndex -} - -func (e *MeshConfigEntry) GetModifyIndex() uint64 { - return e.ModifyIndex -} - -// MarshalJSON adds the Kind field so that the JSON can be decoded back into the -// correct type. -func (e *MeshConfigEntry) MarshalJSON() ([]byte, error) { - type Alias MeshConfigEntry - source := &struct { - Kind string - *Alias - }{ - Kind: MeshConfig, - Alias: (*Alias)(e), - } - return json.Marshal(source) -} diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_discoverychain.go b/vendor/github.com/hashicorp/consul/api/config_entry_discoverychain.go index 5419292..dfb2bcc 100644 --- a/vendor/github.com/hashicorp/consul/api/config_entry_discoverychain.go +++ b/vendor/github.com/hashicorp/consul/api/config_entry_discoverychain.go @@ -8,6 +8,7 @@ import ( type ServiceRouterConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Routes []ServiceRoute `json:",omitempty"` @@ -19,6 +20,7 @@ type ServiceRouterConfigEntry struct { func (e *ServiceRouterConfigEntry) GetKind() string { return e.Kind } func (e *ServiceRouterConfigEntry) GetName() string { return e.Name } +func (e *ServiceRouterConfigEntry) GetPartition() string { return e.Partition } func (e *ServiceRouterConfigEntry) GetNamespace() string { return e.Namespace } func (e *ServiceRouterConfigEntry) GetMeta() map[string]string { return e.Meta } func (e *ServiceRouterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } @@ -61,14 +63,17 @@ type ServiceRouteHTTPMatchQueryParam struct { } type ServiceRouteDestination struct { - Service string `json:",omitempty"` - ServiceSubset string `json:",omitempty" alias:"service_subset"` - Namespace string `json:",omitempty"` - PrefixRewrite string `json:",omitempty" alias:"prefix_rewrite"` - RequestTimeout time.Duration `json:",omitempty" alias:"request_timeout"` - NumRetries uint32 `json:",omitempty" alias:"num_retries"` - RetryOnConnectFailure bool `json:",omitempty" alias:"retry_on_connect_failure"` - RetryOnStatusCodes []uint32 `json:",omitempty" alias:"retry_on_status_codes"` + Service string `json:",omitempty"` + ServiceSubset string `json:",omitempty" alias:"service_subset"` + Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` + PrefixRewrite string `json:",omitempty" alias:"prefix_rewrite"` + RequestTimeout time.Duration `json:",omitempty" alias:"request_timeout"` + NumRetries uint32 `json:",omitempty" alias:"num_retries"` + RetryOnConnectFailure bool `json:",omitempty" alias:"retry_on_connect_failure"` + RetryOnStatusCodes []uint32 `json:",omitempty" alias:"retry_on_status_codes"` + RequestHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"request_headers"` + ResponseHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"response_headers"` } func (e *ServiceRouteDestination) MarshalJSON() ([]byte, error) { @@ -110,6 +115,7 @@ func (e *ServiceRouteDestination) UnmarshalJSON(data []byte) error { type ServiceSplitterConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Splits []ServiceSplit `json:",omitempty"` @@ -121,21 +127,26 @@ type ServiceSplitterConfigEntry struct { func (e *ServiceSplitterConfigEntry) GetKind() string { return e.Kind } func (e *ServiceSplitterConfigEntry) GetName() string { return e.Name } +func (e *ServiceSplitterConfigEntry) GetPartition() string { return e.Partition } func (e *ServiceSplitterConfigEntry) GetNamespace() string { return e.Namespace } func (e *ServiceSplitterConfigEntry) GetMeta() map[string]string { return e.Meta } func (e *ServiceSplitterConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } func (e *ServiceSplitterConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex } type ServiceSplit struct { - Weight float32 - Service string `json:",omitempty"` - ServiceSubset string `json:",omitempty" alias:"service_subset"` - Namespace string `json:",omitempty"` + Weight float32 + Service string `json:",omitempty"` + ServiceSubset string `json:",omitempty" alias:"service_subset"` + Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` + RequestHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"request_headers"` + ResponseHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"response_headers"` } type ServiceResolverConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` DefaultSubset string `json:",omitempty" alias:"default_subset"` @@ -191,6 +202,7 @@ func (e *ServiceResolverConfigEntry) UnmarshalJSON(data []byte) error { func (e *ServiceResolverConfigEntry) GetKind() string { return e.Kind } func (e *ServiceResolverConfigEntry) GetName() string { return e.Name } +func (e *ServiceResolverConfigEntry) GetPartition() string { return e.Partition } func (e *ServiceResolverConfigEntry) GetNamespace() string { return e.Namespace } func (e *ServiceResolverConfigEntry) GetMeta() map[string]string { return e.Meta } func (e *ServiceResolverConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } @@ -205,14 +217,16 @@ type ServiceResolverRedirect struct { Service string `json:",omitempty"` ServiceSubset string `json:",omitempty" alias:"service_subset"` Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` Datacenter string `json:",omitempty"` } type ServiceResolverFailover struct { - Service string `json:",omitempty"` - ServiceSubset string `json:",omitempty" alias:"service_subset"` - Namespace string `json:",omitempty"` - Datacenters []string `json:",omitempty"` + Service string `json:",omitempty"` + ServiceSubset string `json:",omitempty" alias:"service_subset"` + // Referencing other partitions is not supported. + Namespace string `json:",omitempty"` + Datacenters []string `json:",omitempty"` } // LoadBalancer determines the load balancing policy and configuration for services @@ -287,3 +301,21 @@ type CookieConfig struct { // The path to set for the cookie Path string `json:",omitempty"` } + +// HTTPHeaderModifiers is a set of rules for HTTP header modification that +// should be performed by proxies as the request passes through them. It can +// operate on either request or response headers depending on the context in +// which it is used. +type HTTPHeaderModifiers struct { + // Add is a set of name -> value pairs that should be appended to the request + // or response (i.e. allowing duplicates if the same header already exists). + Add map[string]string `json:",omitempty"` + + // Set is a set of name -> value pairs that should be added to the request or + // response, overwriting any existing header values of the same name. + Set map[string]string `json:",omitempty"` + + // Remove is the set of header names that should be stripped from the request + // or response. + Remove []string `json:",omitempty"` +} diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_exports.go b/vendor/github.com/hashicorp/consul/api/config_entry_exports.go new file mode 100644 index 0000000..ae9cb2f --- /dev/null +++ b/vendor/github.com/hashicorp/consul/api/config_entry_exports.go @@ -0,0 +1,72 @@ +package api + +import "encoding/json" + +// ExportedServicesConfigEntry manages the exported services for a single admin partition. +// Admin Partitions are a Consul Enterprise feature. +type ExportedServicesConfigEntry struct { + // Name is the name of the partition the ExportedServicesConfigEntry applies to. + // Partitioning is a Consul Enterprise feature. + Name string `json:",omitempty"` + + // Partition is the partition where the ExportedServicesConfigEntry is stored. + // If the partition does not match the name, the name will overwrite the partition. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // Services is a list of services to be exported and the list of partitions + // to expose them to. + Services []ExportedService + + Meta map[string]string `json:",omitempty"` + + // CreateIndex is the Raft index this entry was created at. This is a + // read-only field. + CreateIndex uint64 + + // ModifyIndex is used for the Check-And-Set operations and can also be fed + // back into the WaitIndex of the QueryOptions in order to perform blocking + // queries. + ModifyIndex uint64 +} + +// ExportedService manages the exporting of a service in the local partition to +// other partitions. +type ExportedService struct { + // Name is the name of the service to be exported. + Name string + + // Namespace is the namespace to export the service from. + Namespace string `json:",omitempty"` + + // Consumers is a list of downstream consumers of the service to be exported. + Consumers []ServiceConsumer +} + +// ServiceConsumer represents a downstream consumer of the service to be exported. +type ServiceConsumer struct { + // Partition is the admin partition to export the service to. + Partition string +} + +func (e *ExportedServicesConfigEntry) GetKind() string { return ExportedServices } +func (e *ExportedServicesConfigEntry) GetName() string { return e.Name } +func (e *ExportedServicesConfigEntry) GetPartition() string { return e.Name } +func (e *ExportedServicesConfigEntry) GetNamespace() string { return IntentionDefaultNamespace } +func (e *ExportedServicesConfigEntry) GetMeta() map[string]string { return e.Meta } +func (e *ExportedServicesConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } +func (e *ExportedServicesConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex } + +// MarshalJSON adds the Kind field so that the JSON can be decoded back into the +// correct type. +func (e *ExportedServicesConfigEntry) MarshalJSON() ([]byte, error) { + type Alias ExportedServicesConfigEntry + source := &struct { + Kind string + *Alias + }{ + Kind: ExportedServices, + Alias: (*Alias)(e), + } + return json.Marshal(source) +} diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_gateways.go b/vendor/github.com/hashicorp/consul/api/config_entry_gateways.go index 822c093..0792ad8 100644 --- a/vendor/github.com/hashicorp/consul/api/config_entry_gateways.go +++ b/vendor/github.com/hashicorp/consul/api/config_entry_gateways.go @@ -10,7 +10,11 @@ type IngressGatewayConfigEntry struct { // service. This should match the name provided in the service definition. Name string - // Namespace is the namespace the IngressGateway is associated with + // Partition is the partition the IngressGateway is associated with. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // Namespace is the namespace the IngressGateway is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` @@ -34,8 +38,21 @@ type IngressGatewayConfigEntry struct { } type GatewayTLSConfig struct { - // Indicates that TLS should be enabled for this gateway service + // Indicates that TLS should be enabled for this gateway service. Enabled bool + + // SDS allows configuring TLS certificate from an SDS service. + SDS *GatewayTLSSDSConfig `json:",omitempty"` +} + +type GatewayServiceTLSConfig struct { + // SDS allows configuring TLS certificate from an SDS service. + SDS *GatewayTLSSDSConfig `json:",omitempty"` +} + +type GatewayTLSSDSConfig struct { + ClusterName string `json:",omitempty" alias:"cluster_name"` + CertResource string `json:",omitempty" alias:"cert_resource"` } // IngressListener manages the configuration for a listener on a specific port. @@ -55,6 +72,9 @@ type IngressListener struct { // For "tcp" protocol listeners, only a single service is allowed. // For "http" listeners, multiple services can be declared. Services []IngressService + + // TLS allows specifying some TLS configuration per listener. + TLS *GatewayTLSConfig `json:",omitempty"` } // IngressService manages configuration for services that are exposed to @@ -67,7 +87,7 @@ type IngressService struct { // protocol and means that the listener will forward traffic to all services. // // A name can be specified on multiple listeners, and will be exposed on both - // of the listeners + // of the listeners. Name string // Hosts is a list of hostnames which should be associated to this service on @@ -86,31 +106,26 @@ type IngressService struct { // Namespace is the namespace where the service is located. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` -} - -func (i *IngressGatewayConfigEntry) GetKind() string { - return i.Kind -} -func (i *IngressGatewayConfigEntry) GetName() string { - return i.Name -} + // Partition is the partition where the service is located. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` -func (i *IngressGatewayConfigEntry) GetNamespace() string { - return i.Namespace -} - -func (i *IngressGatewayConfigEntry) GetMeta() map[string]string { - return i.Meta -} + // TLS allows specifying some TLS configuration per listener. + TLS *GatewayServiceTLSConfig `json:",omitempty"` -func (i *IngressGatewayConfigEntry) GetCreateIndex() uint64 { - return i.CreateIndex + // Allow HTTP header manipulation to be configured. + RequestHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"request_headers"` + ResponseHeaders *HTTPHeaderModifiers `json:",omitempty" alias:"response_headers"` } -func (i *IngressGatewayConfigEntry) GetModifyIndex() uint64 { - return i.ModifyIndex -} +func (i *IngressGatewayConfigEntry) GetKind() string { return i.Kind } +func (i *IngressGatewayConfigEntry) GetName() string { return i.Name } +func (i *IngressGatewayConfigEntry) GetPartition() string { return i.Partition } +func (i *IngressGatewayConfigEntry) GetNamespace() string { return i.Namespace } +func (i *IngressGatewayConfigEntry) GetMeta() map[string]string { return i.Meta } +func (i *IngressGatewayConfigEntry) GetCreateIndex() uint64 { return i.CreateIndex } +func (i *IngressGatewayConfigEntry) GetModifyIndex() uint64 { return i.ModifyIndex } // TerminatingGatewayConfigEntry manages the configuration for a terminating gateway // with the given name. @@ -136,55 +151,45 @@ type TerminatingGatewayConfigEntry struct { // queries. ModifyIndex uint64 - // Namespace is the namespace the config entry is associated with + // Partition is the partition the config entry is associated with. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // Namespace is the namespace the config entry is associated with. // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` } // A LinkedService is a service represented by a terminating gateway type LinkedService struct { - // The namespace the service is registered in + // Referencing other partitions is not supported. + + // Namespace is where the service is registered. Namespace string `json:",omitempty"` - // Name is the name of the service, as defined in Consul's catalog + // Name is the name of the service, as defined in Consul's catalog. Name string `json:",omitempty"` // CAFile is the optional path to a CA certificate to use for TLS connections - // from the gateway to the linked service + // from the gateway to the linked service. CAFile string `json:",omitempty" alias:"ca_file"` // CertFile is the optional path to a client certificate to use for TLS connections - // from the gateway to the linked service + // from the gateway to the linked service. CertFile string `json:",omitempty" alias:"cert_file"` // KeyFile is the optional path to a private key to use for TLS connections - // from the gateway to the linked service + // from the gateway to the linked service. KeyFile string `json:",omitempty" alias:"key_file"` - // SNI is the optional name to specify during the TLS handshake with a linked service + // SNI is the optional name to specify during the TLS handshake with a linked service. SNI string `json:",omitempty"` } -func (g *TerminatingGatewayConfigEntry) GetKind() string { - return g.Kind -} - -func (g *TerminatingGatewayConfigEntry) GetName() string { - return g.Name -} - -func (g *TerminatingGatewayConfigEntry) GetNamespace() string { - return g.Namespace -} - -func (g *TerminatingGatewayConfigEntry) GetMeta() map[string]string { - return g.Meta -} - -func (g *TerminatingGatewayConfigEntry) GetCreateIndex() uint64 { - return g.CreateIndex -} - -func (g *TerminatingGatewayConfigEntry) GetModifyIndex() uint64 { - return g.ModifyIndex -} +func (g *TerminatingGatewayConfigEntry) GetKind() string { return g.Kind } +func (g *TerminatingGatewayConfigEntry) GetName() string { return g.Name } +func (g *TerminatingGatewayConfigEntry) GetPartition() string { return g.Partition } +func (g *TerminatingGatewayConfigEntry) GetNamespace() string { return g.Namespace } +func (g *TerminatingGatewayConfigEntry) GetMeta() map[string]string { return g.Meta } +func (g *TerminatingGatewayConfigEntry) GetCreateIndex() uint64 { return g.CreateIndex } +func (g *TerminatingGatewayConfigEntry) GetModifyIndex() uint64 { return g.ModifyIndex } diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_intentions.go b/vendor/github.com/hashicorp/consul/api/config_entry_intentions.go index 187a425..3741e0a 100644 --- a/vendor/github.com/hashicorp/consul/api/config_entry_intentions.go +++ b/vendor/github.com/hashicorp/consul/api/config_entry_intentions.go @@ -5,6 +5,7 @@ import "time" type ServiceIntentionsConfigEntry struct { Kind string Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Sources []*SourceIntention @@ -17,6 +18,7 @@ type ServiceIntentionsConfigEntry struct { type SourceIntention struct { Name string + Partition string `json:",omitempty"` Namespace string `json:",omitempty"` Action IntentionAction `json:",omitempty"` Permissions []*IntentionPermission `json:",omitempty"` @@ -30,29 +32,13 @@ type SourceIntention struct { LegacyUpdateTime *time.Time `json:",omitempty" alias:"legacy_update_time"` } -func (e *ServiceIntentionsConfigEntry) GetKind() string { - return e.Kind -} - -func (e *ServiceIntentionsConfigEntry) GetName() string { - return e.Name -} - -func (e *ServiceIntentionsConfigEntry) GetNamespace() string { - return e.Namespace -} - -func (e *ServiceIntentionsConfigEntry) GetMeta() map[string]string { - return e.Meta -} - -func (e *ServiceIntentionsConfigEntry) GetCreateIndex() uint64 { - return e.CreateIndex -} - -func (e *ServiceIntentionsConfigEntry) GetModifyIndex() uint64 { - return e.ModifyIndex -} +func (e *ServiceIntentionsConfigEntry) GetKind() string { return e.Kind } +func (e *ServiceIntentionsConfigEntry) GetName() string { return e.Name } +func (e *ServiceIntentionsConfigEntry) GetPartition() string { return e.Partition } +func (e *ServiceIntentionsConfigEntry) GetNamespace() string { return e.Namespace } +func (e *ServiceIntentionsConfigEntry) GetMeta() map[string]string { return e.Meta } +func (e *ServiceIntentionsConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } +func (e *ServiceIntentionsConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex } type IntentionPermission struct { Action IntentionAction diff --git a/vendor/github.com/hashicorp/consul/api/config_entry_mesh.go b/vendor/github.com/hashicorp/consul/api/config_entry_mesh.go new file mode 100644 index 0000000..f58fabc --- /dev/null +++ b/vendor/github.com/hashicorp/consul/api/config_entry_mesh.go @@ -0,0 +1,56 @@ +package api + +import "encoding/json" + +// MeshConfigEntry manages the global configuration for all service mesh +// proxies. +type MeshConfigEntry struct { + // Partition is the partition the MeshConfigEntry applies to. + // Partitioning is a Consul Enterprise feature. + Partition string `json:",omitempty"` + + // Namespace is the namespace the MeshConfigEntry applies to. + // Namespacing is a Consul Enterprise feature. + Namespace string `json:",omitempty"` + + // TransparentProxy applies configuration specific to proxies + // in transparent mode. + TransparentProxy TransparentProxyMeshConfig `alias:"transparent_proxy"` + + Meta map[string]string `json:",omitempty"` + + // CreateIndex is the Raft index this entry was created at. This is a + // read-only field. + CreateIndex uint64 + + // ModifyIndex is used for the Check-And-Set operations and can also be fed + // back into the WaitIndex of the QueryOptions in order to perform blocking + // queries. + ModifyIndex uint64 +} + +type TransparentProxyMeshConfig struct { + MeshDestinationsOnly bool `alias:"mesh_destinations_only"` +} + +func (e *MeshConfigEntry) GetKind() string { return MeshConfig } +func (e *MeshConfigEntry) GetName() string { return MeshConfigMesh } +func (e *MeshConfigEntry) GetPartition() string { return e.Partition } +func (e *MeshConfigEntry) GetNamespace() string { return e.Namespace } +func (e *MeshConfigEntry) GetMeta() map[string]string { return e.Meta } +func (e *MeshConfigEntry) GetCreateIndex() uint64 { return e.CreateIndex } +func (e *MeshConfigEntry) GetModifyIndex() uint64 { return e.ModifyIndex } + +// MarshalJSON adds the Kind field so that the JSON can be decoded back into the +// correct type. +func (e *MeshConfigEntry) MarshalJSON() ([]byte, error) { + type Alias MeshConfigEntry + source := &struct { + Kind string + *Alias + }{ + Kind: MeshConfig, + Alias: (*Alias)(e), + } + return json.Marshal(source) +} diff --git a/vendor/github.com/hashicorp/consul/api/connect_ca.go b/vendor/github.com/hashicorp/consul/api/connect_ca.go index 37e53d9..69c652d 100644 --- a/vendor/github.com/hashicorp/consul/api/connect_ca.go +++ b/vendor/github.com/hashicorp/consul/api/connect_ca.go @@ -38,6 +38,7 @@ type CAConfig struct { // CommonCAProviderConfig is the common options available to all CA providers. type CommonCAProviderConfig struct { LeafCertTTL time.Duration + RootCertTTL time.Duration SkipValidate bool CSRMaxPerSecond float32 CSRMaxConcurrent int @@ -133,11 +134,14 @@ type LeafCert struct { func (h *Connect) CARoots(q *QueryOptions) (*CARootList, *QueryMeta, error) { r := h.c.newRequest("GET", "/v1/connect/ca/roots") r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -154,11 +158,14 @@ func (h *Connect) CARoots(q *QueryOptions) (*CARootList, *QueryMeta, error) { func (h *Connect) CAGetConfig(q *QueryOptions) (*CAConfig, *QueryMeta, error) { r := h.c.newRequest("GET", "/v1/connect/ca/configuration") r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -176,11 +183,14 @@ func (h *Connect) CASetConfig(conf *CAConfig, q *WriteOptions) (*WriteMeta, erro r := h.c.newRequest("PUT", "/v1/connect/ca/configuration") r.setWriteOptions(q) r.obj = conf - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt diff --git a/vendor/github.com/hashicorp/consul/api/connect_intention.go b/vendor/github.com/hashicorp/consul/api/connect_intention.go index d1f0b65..734d4ab 100644 --- a/vendor/github.com/hashicorp/consul/api/connect_intention.go +++ b/vendor/github.com/hashicorp/consul/api/connect_intention.go @@ -30,6 +30,11 @@ type Intention struct { SourceNS, SourceName string DestinationNS, DestinationName string + // SourcePartition and DestinationPartition cannot be wildcards "*" and + // are not compatible with legacy intentions. + SourcePartition string `json:",omitempty"` + DestinationPartition string `json:",omitempty"` + // SourceType is the type of the value for the source. SourceType IntentionSourceType @@ -166,11 +171,14 @@ type IntentionCheck struct { func (h *Connect) Intentions(q *QueryOptions) ([]*Intention, *QueryMeta, error) { r := h.c.newRequest("GET", "/v1/connect/intentions") r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -255,11 +263,14 @@ func (h *Connect) IntentionDeleteExact(source, destination string, q *WriteOptio r.params.Set("source", source) r.params.Set("destination", destination) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } qm := &WriteMeta{} qm.RequestTime = rtt @@ -273,11 +284,14 @@ func (h *Connect) IntentionDeleteExact(source, destination string, q *WriteOptio func (h *Connect) IntentionDelete(id string, q *WriteOptions) (*WriteMeta, error) { r := h.c.newRequest("DELETE", "/v1/connect/intentions/"+id) r.setWriteOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } qm := &WriteMeta{} qm.RequestTime = rtt @@ -299,11 +313,14 @@ func (h *Connect) IntentionMatch(args *IntentionMatch, q *QueryOptions) (map[str for _, name := range args.Names { r.params.Add("name", name) } - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -326,11 +343,14 @@ func (h *Connect) IntentionCheck(args *IntentionCheck, q *QueryOptions) (bool, * if args.SourceType != "" { r.params.Set("source-type", string(args.SourceType)) } - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return false, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return false, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -348,25 +368,34 @@ func (h *Connect) IntentionCheck(args *IntentionCheck, q *QueryOptions) (bool, * func (c *Connect) IntentionUpsert(ixn *Intention, q *WriteOptions) (*WriteMeta, error) { r := c.c.newRequest("PUT", "/v1/connect/intentions/exact") r.setWriteOptions(q) - r.params.Set("source", maybePrefixNamespace(ixn.SourceNS, ixn.SourceName)) - r.params.Set("destination", maybePrefixNamespace(ixn.DestinationNS, ixn.DestinationName)) + r.params.Set("source", maybePrefixNamespaceAndPartition(ixn.SourcePartition, ixn.SourceNS, ixn.SourceName)) + r.params.Set("destination", maybePrefixNamespaceAndPartition(ixn.DestinationPartition, ixn.DestinationNS, ixn.DestinationName)) r.obj = ixn - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt return wm, nil } -func maybePrefixNamespace(ns, name string) string { - if ns == "" { +func maybePrefixNamespaceAndPartition(part, ns, name string) string { + switch { + case part == "" && ns == "": return name + case part == "" && ns != "": + return ns + "/" + name + case part != "" && ns == "": + return part + "/" + IntentionDefaultNamespace + "/" + name + default: + return part + "/" + ns + "/" + name } - return ns + "/" + name } // IntentionCreate will create a new intention. The ID in the given @@ -378,11 +407,14 @@ func (c *Connect) IntentionCreate(ixn *Intention, q *WriteOptions) (string, *Wri r := c.c.newRequest("POST", "/v1/connect/intentions") r.setWriteOptions(q) r.obj = ixn - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -402,11 +434,14 @@ func (c *Connect) IntentionUpdate(ixn *Intention, q *WriteOptions) (*WriteMeta, r := c.c.newRequest("PUT", "/v1/connect/intentions/"+ixn.ID) r.setWriteOptions(q) r.obj = ixn - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt diff --git a/vendor/github.com/hashicorp/consul/api/coordinate.go b/vendor/github.com/hashicorp/consul/api/coordinate.go index 32c7822..7ef6ce2 100644 --- a/vendor/github.com/hashicorp/consul/api/coordinate.go +++ b/vendor/github.com/hashicorp/consul/api/coordinate.go @@ -6,9 +6,10 @@ import ( // CoordinateEntry represents a node and its associated network coordinate. type CoordinateEntry struct { - Node string - Segment string - Coord *coordinate.Coordinate + Node string + Segment string + Partition string `json:",omitempty"` + Coord *coordinate.Coordinate } // CoordinateDatacenterMap has the coordinates for servers in a given datacenter @@ -33,11 +34,14 @@ func (c *Client) Coordinate() *Coordinate { // pool. func (c *Coordinate) Datacenters() ([]*CoordinateDatacenterMap, error) { r := c.c.newRequest("GET", "/v1/coordinate/datacenters") - _, resp, err := requireOK(c.c.doRequest(r)) + _, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out []*CoordinateDatacenterMap if err := decodeBody(resp, &out); err != nil { @@ -50,11 +54,14 @@ func (c *Coordinate) Datacenters() ([]*CoordinateDatacenterMap, error) { func (c *Coordinate) Nodes(q *QueryOptions) ([]*CoordinateEntry, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/coordinate/nodes") r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -72,11 +79,14 @@ func (c *Coordinate) Update(coord *CoordinateEntry, q *WriteOptions) (*WriteMeta r := c.c.newRequest("PUT", "/v1/coordinate/update") r.setWriteOptions(q) r.obj = coord - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -88,11 +98,14 @@ func (c *Coordinate) Update(coord *CoordinateEntry, q *WriteOptions) (*WriteMeta func (c *Coordinate) Node(node string, q *QueryOptions) ([]*CoordinateEntry, *QueryMeta, error) { r := c.c.newRequest("GET", "/v1/coordinate/node/"+node) r.setQueryOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/debug.go b/vendor/github.com/hashicorp/consul/api/debug.go index 56dcc9b..0dfbfd8 100644 --- a/vendor/github.com/hashicorp/consul/api/debug.go +++ b/vendor/github.com/hashicorp/consul/api/debug.go @@ -1,7 +1,9 @@ package api import ( + "context" "fmt" + "io" "io/ioutil" "strconv" ) @@ -28,9 +30,8 @@ func (d *Debug) Heap() ([]byte, error) { return nil, fmt.Errorf("error making request: %s", err) } defer closeResponseBody(resp) - - if resp.StatusCode != 200 { - return nil, generateUnexpectedResponseCodeError(resp) + if err := requireOK(resp); err != nil { + return nil, err } // We return a raw response because we're just passing through a response @@ -55,9 +56,8 @@ func (d *Debug) Profile(seconds int) ([]byte, error) { return nil, fmt.Errorf("error making request: %s", err) } defer closeResponseBody(resp) - - if resp.StatusCode != 200 { - return nil, generateUnexpectedResponseCodeError(resp) + if err := requireOK(resp); err != nil { + return nil, err } // We return a raw response because we're just passing through a response @@ -70,6 +70,25 @@ func (d *Debug) Profile(seconds int) ([]byte, error) { return body, nil } +// PProf returns a pprof profile for the specified number of seconds. The caller +// is responsible for closing the returned io.ReadCloser once all bytes are read. +func (d *Debug) PProf(ctx context.Context, name string, seconds int) (io.ReadCloser, error) { + r := d.c.newRequest("GET", "/debug/pprof/"+name) + r.ctx = ctx + + // Capture a profile for the specified number of seconds + r.params.Set("seconds", strconv.Itoa(seconds)) + + _, resp, err := d.c.doRequest(r) + if err != nil { + return nil, fmt.Errorf("error making request: %s", err) + } + if err := requireOK(resp); err != nil { + return nil, err + } + return resp.Body, nil +} + // Trace returns an execution trace func (d *Debug) Trace(seconds int) ([]byte, error) { r := d.c.newRequest("GET", "/debug/pprof/trace") @@ -82,9 +101,8 @@ func (d *Debug) Trace(seconds int) ([]byte, error) { return nil, fmt.Errorf("error making request: %s", err) } defer closeResponseBody(resp) - - if resp.StatusCode != 200 { - return nil, generateUnexpectedResponseCodeError(resp) + if err := requireOK(resp); err != nil { + return nil, err } // We return a raw response because we're just passing through a response @@ -106,9 +124,8 @@ func (d *Debug) Goroutine() ([]byte, error) { return nil, fmt.Errorf("error making request: %s", err) } defer closeResponseBody(resp) - - if resp.StatusCode != 200 { - return nil, generateUnexpectedResponseCodeError(resp) + if err := requireOK(resp); err != nil { + return nil, err } // We return a raw response because we're just passing through a response diff --git a/vendor/github.com/hashicorp/consul/api/discovery_chain.go b/vendor/github.com/hashicorp/consul/api/discovery_chain.go index b78e6c3..29bda85 100644 --- a/vendor/github.com/hashicorp/consul/api/discovery_chain.go +++ b/vendor/github.com/hashicorp/consul/api/discovery_chain.go @@ -38,12 +38,14 @@ func (d *DiscoveryChain) Get(name string, opts *DiscoveryChainOptions, q *QueryO if method == "POST" { r.obj = opts } - - rtt, resp, err := requireOK(d.c.doRequest(r)) + rtt, resp, err := d.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/event.go b/vendor/github.com/hashicorp/consul/api/event.go index 1da4137..ceded65 100644 --- a/vendor/github.com/hashicorp/consul/api/event.go +++ b/vendor/github.com/hashicorp/consul/api/event.go @@ -47,11 +47,14 @@ func (e *Event) Fire(params *UserEvent, q *WriteOptions) (string, *WriteMeta, er } r.header.Set("Content-Type", "application/octet-stream") - rtt, resp, err := requireOK(e.c.doRequest(r)) + rtt, resp, err := e.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{RequestTime: rtt} var out UserEvent @@ -71,11 +74,14 @@ func (e *Event) List(name string, q *QueryOptions) ([]*UserEvent, *QueryMeta, er if name != "" { r.params.Set("name", name) } - rtt, resp, err := requireOK(e.c.doRequest(r)) + rtt, resp, err := e.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/health.go b/vendor/github.com/hashicorp/consul/api/health.go index 0a3fd8d..2785c4c 100644 --- a/vendor/github.com/hashicorp/consul/api/health.go +++ b/vendor/github.com/hashicorp/consul/api/health.go @@ -44,6 +44,7 @@ type HealthCheck struct { ServiceTags []string Type string Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` Definition HealthCheckDefinition @@ -230,11 +231,14 @@ func (c *Client) Health() *Health { func (h *Health) Node(node string, q *QueryOptions) (HealthChecks, *QueryMeta, error) { r := h.c.newRequest("GET", "/v1/health/node/"+node) r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -251,11 +255,14 @@ func (h *Health) Node(node string, q *QueryOptions) (HealthChecks, *QueryMeta, e func (h *Health) Checks(service string, q *QueryOptions) (HealthChecks, *QueryMeta, error) { r := h.c.newRequest("GET", "/v1/health/checks/"+service) r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -328,11 +335,14 @@ func (h *Health) service(service string, tags []string, passingOnly bool, q *Que if passingOnly { r.params.Set(HealthPassing, "1") } - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -358,11 +368,14 @@ func (h *Health) State(state string, q *QueryOptions) (HealthChecks, *QueryMeta, } r := h.c.newRequest("GET", "/v1/health/state/"+state) r.setQueryOptions(q) - rtt, resp, err := requireOK(h.c.doRequest(r)) + rtt, resp, err := h.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/kv.go b/vendor/github.com/hashicorp/consul/api/kv.go index 1d5c112..85a9d77 100644 --- a/vendor/github.com/hashicorp/consul/api/kv.go +++ b/vendor/github.com/hashicorp/consul/api/kv.go @@ -44,6 +44,10 @@ type KVPair struct { // Namespace is the namespace the KVPair is associated with // Namespacing is a Consul Enterprise feature. Namespace string `json:",omitempty"` + + // Partition is the partition the KVPair is associated with + // Admin Partition is a Consul Enterprise feature. + Partition string `json:",omitempty"` } // KVPairs is a list of KVPair objects @@ -133,6 +137,11 @@ func (k *KV) getInternal(key string, params map[string]string, q *QueryOptions) return nil, nil, err } + err = requireHttpCodes(resp, 200, 404) + if err != nil { + return nil, nil, err + } + qm := &QueryMeta{} parseQueryMeta(resp, qm) qm.RequestTime = rtt @@ -140,10 +149,8 @@ func (k *KV) getInternal(key string, params map[string]string, q *QueryOptions) if resp.StatusCode == 404 { closeResponseBody(resp) return nil, qm, nil - } else if resp.StatusCode != 200 { - closeResponseBody(resp) - return nil, nil, fmt.Errorf("Unexpected response code: %d", resp.StatusCode) } + return resp, qm, nil } @@ -206,11 +213,14 @@ func (k *KV) put(key string, params map[string]string, body []byte, q *WriteOpti } r.body = bytes.NewReader(body) r.header.Set("Content-Type", "application/octet-stream") - rtt, resp, err := requireOK(k.c.doRequest(r)) + rtt, resp, err := k.c.doRequest(r) if err != nil { return false, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return false, nil, err + } qm := &WriteMeta{} qm.RequestTime = rtt @@ -250,11 +260,14 @@ func (k *KV) deleteInternal(key string, params map[string]string, q *WriteOption for param, val := range params { r.params.Set(param, val) } - rtt, resp, err := requireOK(k.c.doRequest(r)) + rtt, resp, err := k.c.doRequest(r) if err != nil { return false, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return false, nil, err + } qm := &WriteMeta{} qm.RequestTime = rtt diff --git a/vendor/github.com/hashicorp/consul/api/namespace.go b/vendor/github.com/hashicorp/consul/api/namespace.go index 20f6c8d..213cd8c 100644 --- a/vendor/github.com/hashicorp/consul/api/namespace.go +++ b/vendor/github.com/hashicorp/consul/api/namespace.go @@ -28,6 +28,9 @@ type Namespace struct { // This is nullable so that we can omit if empty when encoding in JSON DeletedAt *time.Time `json:"DeletedAt,omitempty" alias:"deleted_at"` + // Partition which contains the Namespace. + Partition string `json:"Partition,omitempty"` + // CreateIndex is the Raft index at which the Namespace was created CreateIndex uint64 `json:"CreateIndex,omitempty"` @@ -63,11 +66,14 @@ func (n *Namespaces) Create(ns *Namespace, q *WriteOptions) (*Namespace, *WriteM r := n.c.newRequest("PUT", "/v1/namespace") r.setWriteOptions(q) r.obj = ns - rtt, resp, err := requireOK(n.c.doRequest(r)) + rtt, resp, err := n.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out Namespace @@ -86,11 +92,14 @@ func (n *Namespaces) Update(ns *Namespace, q *WriteOptions) (*Namespace, *WriteM r := n.c.newRequest("PUT", "/v1/namespace/"+ns.Name) r.setWriteOptions(q) r.obj = ns - rtt, resp, err := requireOK(n.c.doRequest(r)) + rtt, resp, err := n.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{RequestTime: rtt} var out Namespace @@ -105,11 +114,15 @@ func (n *Namespaces) Read(name string, q *QueryOptions) (*Namespace, *QueryMeta, var out Namespace r := n.c.newRequest("GET", "/v1/namespace/"+name) r.setQueryOptions(q) - found, rtt, resp, err := requireNotFoundOrOK(n.c.doRequest(r)) + rtt, resp, err := n.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -128,11 +141,14 @@ func (n *Namespaces) Read(name string, q *QueryOptions) (*Namespace, *QueryMeta, func (n *Namespaces) Delete(name string, q *WriteOptions) (*WriteMeta, error) { r := n.c.newRequest("DELETE", "/v1/namespace/"+name) r.setWriteOptions(q) - rtt, resp, err := requireOK(n.c.doRequest(r)) + rtt, resp, err := n.c.doRequest(r) if err != nil { return nil, err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{RequestTime: rtt} return wm, nil @@ -142,11 +158,14 @@ func (n *Namespaces) List(q *QueryOptions) ([]*Namespace, *QueryMeta, error) { var out []*Namespace r := n.c.newRequest("GET", "/v1/namespaces") r.setQueryOptions(q) - rtt, resp, err := requireOK(n.c.doRequest(r)) + rtt, resp, err := n.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) diff --git a/vendor/github.com/hashicorp/consul/api/operator_area.go b/vendor/github.com/hashicorp/consul/api/operator_area.go index 5476f5c..f9fa133 100644 --- a/vendor/github.com/hashicorp/consul/api/operator_area.go +++ b/vendor/github.com/hashicorp/consul/api/operator_area.go @@ -89,11 +89,14 @@ func (op *Operator) AreaCreate(area *Area, q *WriteOptions) (string, *WriteMeta, r := op.c.newRequest("POST", "/v1/operator/area") r.setWriteOptions(q) r.obj = area - rtt, resp, err := requireOK(op.c.doRequest(r)) + rtt, resp, err := op.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -110,11 +113,14 @@ func (op *Operator) AreaUpdate(areaID string, area *Area, q *WriteOptions) (stri r := op.c.newRequest("PUT", "/v1/operator/area/"+areaID) r.setWriteOptions(q) r.obj = area - rtt, resp, err := requireOK(op.c.doRequest(r)) + rtt, resp, err := op.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -150,11 +156,14 @@ func (op *Operator) AreaList(q *QueryOptions) ([]*Area, *QueryMeta, error) { func (op *Operator) AreaDelete(areaID string, q *WriteOptions) (*WriteMeta, error) { r := op.c.newRequest("DELETE", "/v1/operator/area/"+areaID) r.setWriteOptions(q) - rtt, resp, err := requireOK(op.c.doRequest(r)) + rtt, resp, err := op.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -167,11 +176,14 @@ func (op *Operator) AreaJoin(areaID string, addresses []string, q *WriteOptions) r := op.c.newRequest("PUT", "/v1/operator/area/"+areaID+"/join") r.setWriteOptions(q) r.obj = addresses - rtt, resp, err := requireOK(op.c.doRequest(r)) + rtt, resp, err := op.c.doRequest(r) if err != nil { return nil, nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt diff --git a/vendor/github.com/hashicorp/consul/api/operator_autopilot.go b/vendor/github.com/hashicorp/consul/api/operator_autopilot.go index 8175f51..6ab5769 100644 --- a/vendor/github.com/hashicorp/consul/api/operator_autopilot.go +++ b/vendor/github.com/hashicorp/consul/api/operator_autopilot.go @@ -58,6 +58,23 @@ type AutopilotConfiguration struct { ModifyIndex uint64 } +// Defines default values for the AutopilotConfiguration type, consistent with +// https://www.consul.io/api-docs/operator/autopilot#parameters-1 +func NewAutopilotConfiguration() AutopilotConfiguration { + cfg := AutopilotConfiguration{ + CleanupDeadServers: true, + LastContactThreshold: NewReadableDuration(200 * time.Millisecond), + MaxTrailingLogs: 250, + MinQuorum: 0, + ServerStabilizationTime: NewReadableDuration(10 * time.Second), + RedundancyZoneTag: "", + DisableUpgradeMigration: false, + UpgradeVersionTag: "", + } + + return cfg +} + // ServerHealth is the health (from the leader's point of view) of a server. type ServerHealth struct { // ID is the raft ID of the server. @@ -280,11 +297,14 @@ func (d *ReadableDuration) UnmarshalJSON(raw []byte) (err error) { func (op *Operator) AutopilotGetConfiguration(q *QueryOptions) (*AutopilotConfiguration, error) { r := op.c.newRequest("GET", "/v1/operator/autopilot/configuration") r.setQueryOptions(q) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out AutopilotConfiguration if err := decodeBody(resp, &out); err != nil { @@ -299,11 +319,14 @@ func (op *Operator) AutopilotSetConfiguration(conf *AutopilotConfiguration, q *W r := op.c.newRequest("PUT", "/v1/operator/autopilot/configuration") r.setWriteOptions(q) r.obj = conf - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -315,11 +338,14 @@ func (op *Operator) AutopilotCASConfiguration(conf *AutopilotConfiguration, q *W r.setWriteOptions(q) r.params.Set("cas", strconv.FormatUint(conf.ModifyIndex, 10)) r.obj = conf - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return false, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return false, err + } var buf bytes.Buffer if _, err := io.Copy(&buf, resp.Body); err != nil { @@ -335,22 +361,16 @@ func (op *Operator) AutopilotServerHealth(q *QueryOptions) (*OperatorHealthReply r := op.c.newRequest("GET", "/v1/operator/autopilot/health") r.setQueryOptions(q) - // we cannot just use requireOK because this endpoint might use a 429 status to indicate - // that unhealthiness + // we use 429 status to indicate unhealthiness _, resp, err := op.c.doRequest(r) if err != nil { - if resp != nil { - closeResponseBody(resp) - } return nil, err } - - // these are the only 2 status codes that would indicate that we should - // expect the body to contain the right format. - if resp.StatusCode != 200 && resp.StatusCode != 429 { - return nil, generateUnexpectedResponseCodeError(resp) + defer closeResponseBody(resp) + err = requireHttpCodes(resp, 200, 429) + if err != nil { + return nil, err } - defer closeResponseBody(resp) var out OperatorHealthReply @@ -363,11 +383,14 @@ func (op *Operator) AutopilotServerHealth(q *QueryOptions) (*OperatorHealthReply func (op *Operator) AutopilotState(q *QueryOptions) (*AutopilotState, error) { r := op.c.newRequest("GET", "/v1/operator/autopilot/state") r.setQueryOptions(q) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out AutopilotState if err := decodeBody(resp, &out); err != nil { diff --git a/vendor/github.com/hashicorp/consul/api/operator_keyring.go b/vendor/github.com/hashicorp/consul/api/operator_keyring.go index baad70e..6db31a2 100644 --- a/vendor/github.com/hashicorp/consul/api/operator_keyring.go +++ b/vendor/github.com/hashicorp/consul/api/operator_keyring.go @@ -16,6 +16,9 @@ type KeyringResponse struct { // Segment has the network segment this request corresponds to. Segment string + // Partition has the admin partition this request corresponds to. + Partition string `json:",omitempty"` + // Messages has information or errors from serf Messages map[string]string `json:",omitempty"` @@ -36,11 +39,14 @@ func (op *Operator) KeyringInstall(key string, q *WriteOptions) error { r.obj = keyringRequest{ Key: key, } - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -48,11 +54,14 @@ func (op *Operator) KeyringInstall(key string, q *WriteOptions) error { func (op *Operator) KeyringList(q *QueryOptions) ([]*KeyringResponse, error) { r := op.c.newRequest("GET", "/v1/operator/keyring") r.setQueryOptions(q) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out []*KeyringResponse if err := decodeBody(resp, &out); err != nil { @@ -68,11 +77,14 @@ func (op *Operator) KeyringRemove(key string, q *WriteOptions) error { r.obj = keyringRequest{ Key: key, } - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -83,10 +95,13 @@ func (op *Operator) KeyringUse(key string, q *WriteOptions) error { r.obj = keyringRequest{ Key: key, } - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } diff --git a/vendor/github.com/hashicorp/consul/api/operator_license.go b/vendor/github.com/hashicorp/consul/api/operator_license.go index 73e5051..7b65431 100644 --- a/vendor/github.com/hashicorp/consul/api/operator_license.go +++ b/vendor/github.com/hashicorp/consul/api/operator_license.go @@ -62,11 +62,14 @@ func (op *Operator) LicenseGetSigned(q *QueryOptions) (string, error) { r := op.c.newRequest("GET", "/v1/operator/license") r.params.Set("signed", "1") r.setQueryOptions(q) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return "", err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", err + } data, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -85,11 +88,14 @@ func (op *Operator) LicenseReset(opts *WriteOptions) (*LicenseReply, error) { var reply LicenseReply r := op.c.newRequest("DELETE", "/v1/operator/license") r.setWriteOptions(opts) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } - defer resp.Body.Close() + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } if err := decodeBody(resp, &reply); err != nil { return nil, err } @@ -105,11 +111,14 @@ func (op *Operator) LicensePut(license string, opts *WriteOptions) (*LicenseRepl r := op.c.newRequest("PUT", "/v1/operator/license") r.setWriteOptions(opts) r.body = strings.NewReader(license) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } - defer resp.Body.Close() + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } if err := decodeBody(resp, &reply); err != nil { return nil, err diff --git a/vendor/github.com/hashicorp/consul/api/operator_raft.go b/vendor/github.com/hashicorp/consul/api/operator_raft.go index 0bfb85d..1b48fdc 100644 --- a/vendor/github.com/hashicorp/consul/api/operator_raft.go +++ b/vendor/github.com/hashicorp/consul/api/operator_raft.go @@ -40,11 +40,14 @@ type RaftConfiguration struct { func (op *Operator) RaftGetConfiguration(q *QueryOptions) (*RaftConfiguration, error) { r := op.c.newRequest("GET", "/v1/operator/raft/configuration") r.setQueryOptions(q) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var out RaftConfiguration if err := decodeBody(resp, &out); err != nil { @@ -62,12 +65,14 @@ func (op *Operator) RaftRemovePeerByAddress(address string, q *WriteOptions) err r.params.Set("address", address) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } @@ -79,11 +84,13 @@ func (op *Operator) RaftRemovePeerByID(id string, q *WriteOptions) error { r.params.Set("id", id) - _, resp, err := requireOK(op.c.doRequest(r)) + _, resp, err := op.c.doRequest(r) if err != nil { return err } - - closeResponseBody(resp) + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return err + } return nil } diff --git a/vendor/github.com/hashicorp/consul/api/partition.go b/vendor/github.com/hashicorp/consul/api/partition.go new file mode 100644 index 0000000..88edfb7 --- /dev/null +++ b/vendor/github.com/hashicorp/consul/api/partition.go @@ -0,0 +1,164 @@ +package api + +import ( + "context" + "fmt" + "time" +) + +// Partition is the configuration of a single admin partition. Admin Partitions are a Consul Enterprise feature. +type Partition struct { + // Name is the name of the Partition. + Name string `json:"Name"` + + // Description is where the user puts any information they want + // about the admin partition. It is not used internally. + Description string `json:"Description,omitempty"` + + // DeletedAt is the time when the Partition was marked for deletion + // This is nullable so that we can omit if empty when encoding in JSON + DeletedAt *time.Time `json:"DeletedAt,omitempty" alias:"deleted_at"` + + // CreateIndex is the Raft index at which the Partition was created + CreateIndex uint64 `json:"CreateIndex,omitempty"` + + // ModifyIndex is the latest Raft index at which the Partition was modified. + ModifyIndex uint64 `json:"ModifyIndex,omitempty"` +} + +// PartitionDefaultName is the default partition value. +const PartitionDefaultName = "default" + +// Partitions can be used to manage Partitions in Consul Enterprise. +type Partitions struct { + c *Client +} + +// Operator returns a handle to the operator endpoints. +func (c *Client) Partitions() *Partitions { + return &Partitions{c} +} + +func (p *Partitions) Create(ctx context.Context, partition *Partition, q *WriteOptions) (*Partition, *WriteMeta, error) { + if partition.Name == "" { + return nil, nil, fmt.Errorf("Must specify a Name for Partition creation") + } + + r := p.c.newRequest("PUT", "/v1/partition") + r.setWriteOptions(q) + r.ctx = ctx + r.obj = partition + rtt, resp, err := p.c.doRequest(r) + if err != nil { + return nil, nil, err + } + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } + + wm := &WriteMeta{RequestTime: rtt} + var out Partition + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } + + return &out, wm, nil +} + +func (p *Partitions) Update(ctx context.Context, partition *Partition, q *WriteOptions) (*Partition, *WriteMeta, error) { + if partition.Name == "" { + return nil, nil, fmt.Errorf("Must specify a Name for Partition updating") + } + + r := p.c.newRequest("PUT", "/v1/partition/"+partition.Name) + r.setWriteOptions(q) + r.ctx = ctx + r.obj = partition + rtt, resp, err := p.c.doRequest(r) + if err != nil { + return nil, nil, err + } + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } + + wm := &WriteMeta{RequestTime: rtt} + var out Partition + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } + + return &out, wm, nil +} + +func (p *Partitions) Read(ctx context.Context, name string, q *QueryOptions) (*Partition, *QueryMeta, error) { + var out Partition + r := p.c.newRequest("GET", "/v1/partition/"+name) + r.setQueryOptions(q) + r.ctx = ctx + rtt, resp, err := p.c.doRequest(r) + if err != nil { + return nil, nil, err + } + defer closeResponseBody(resp) + found, resp, err := requireNotFoundOrOK(resp) + if err != nil { + return nil, nil, err + } + + qm := &QueryMeta{} + parseQueryMeta(resp, qm) + qm.RequestTime = rtt + + if !found { + return nil, qm, nil + } + + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } + return &out, qm, nil +} + +func (p *Partitions) Delete(ctx context.Context, name string, q *WriteOptions) (*WriteMeta, error) { + r := p.c.newRequest("DELETE", "/v1/partition/"+name) + r.setWriteOptions(q) + r.ctx = ctx + rtt, resp, err := p.c.doRequest(r) + if err != nil { + return nil, err + } + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } + + wm := &WriteMeta{RequestTime: rtt} + return wm, nil +} + +func (p *Partitions) List(ctx context.Context, q *QueryOptions) ([]*Partition, *QueryMeta, error) { + var out []*Partition + r := p.c.newRequest("GET", "/v1/partitions") + r.setQueryOptions(q) + r.ctx = ctx + rtt, resp, err := p.c.doRequest(r) + if err != nil { + return nil, nil, err + } + defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, nil, err + } + + qm := &QueryMeta{} + parseQueryMeta(resp, qm) + qm.RequestTime = rtt + + if err := decodeBody(resp, &out); err != nil { + return nil, nil, err + } + return out, qm, nil +} diff --git a/vendor/github.com/hashicorp/consul/api/prepared_query.go b/vendor/github.com/hashicorp/consul/api/prepared_query.go index 5b2d5a5..b3dd7be 100644 --- a/vendor/github.com/hashicorp/consul/api/prepared_query.go +++ b/vendor/github.com/hashicorp/consul/api/prepared_query.go @@ -154,11 +154,14 @@ func (c *PreparedQuery) Create(query *PreparedQueryDefinition, q *WriteOptions) r := c.c.newRequest("POST", "/v1/query") r.setWriteOptions(q) r.obj = query - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return "", nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt @@ -200,11 +203,14 @@ func (c *PreparedQuery) Get(queryID string, q *QueryOptions) ([]*PreparedQueryDe func (c *PreparedQuery) Delete(queryID string, q *WriteOptions) (*WriteMeta, error) { r := c.c.newRequest("DELETE", "/v1/query/"+queryID) r.setWriteOptions(q) - rtt, resp, err := requireOK(c.c.doRequest(r)) + rtt, resp, err := c.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } wm := &WriteMeta{} wm.RequestTime = rtt diff --git a/vendor/github.com/hashicorp/consul/api/snapshot.go b/vendor/github.com/hashicorp/consul/api/snapshot.go index 0c8294f..b526b79 100644 --- a/vendor/github.com/hashicorp/consul/api/snapshot.go +++ b/vendor/github.com/hashicorp/consul/api/snapshot.go @@ -23,10 +23,13 @@ func (s *Snapshot) Save(q *QueryOptions) (io.ReadCloser, *QueryMeta, error) { r := s.c.newRequest("GET", "/v1/snapshot") r.setQueryOptions(q) - rtt, resp, err := requireOK(s.c.doRequest(r)) + rtt, resp, err := s.c.doRequest(r) if err != nil { return nil, nil, err } + if err := requireOK(resp); err != nil { + return nil, nil, err + } qm := &QueryMeta{} parseQueryMeta(resp, qm) @@ -40,9 +43,12 @@ func (s *Snapshot) Restore(q *WriteOptions, in io.Reader) error { r.body = in r.header.Set("Content-Type", "application/octet-stream") r.setWriteOptions(q) - _, _, err := requireOK(s.c.doRequest(r)) + _, resp, err := s.c.doRequest(r) if err != nil { return err } + if err := requireOK(resp); err != nil { + return err + } return nil } diff --git a/vendor/github.com/hashicorp/consul/api/status.go b/vendor/github.com/hashicorp/consul/api/status.go index 2a81b9b..86f943b 100644 --- a/vendor/github.com/hashicorp/consul/api/status.go +++ b/vendor/github.com/hashicorp/consul/api/status.go @@ -18,11 +18,14 @@ func (s *Status) LeaderWithQueryOptions(q *QueryOptions) (string, error) { r.setQueryOptions(q) } - _, resp, err := requireOK(s.c.doRequest(r)) + _, resp, err := s.c.doRequest(r) if err != nil { return "", err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return "", err + } var leader string if err := decodeBody(resp, &leader); err != nil { @@ -43,11 +46,14 @@ func (s *Status) PeersWithQueryOptions(q *QueryOptions) ([]string, error) { r.setQueryOptions(q) } - _, resp, err := requireOK(s.c.doRequest(r)) + _, resp, err := s.c.doRequest(r) if err != nil { return nil, err } defer closeResponseBody(resp) + if err := requireOK(resp); err != nil { + return nil, err + } var peers []string if err := decodeBody(resp, &peers); err != nil { diff --git a/vendor/github.com/hashicorp/consul/api/txn.go b/vendor/github.com/hashicorp/consul/api/txn.go index 55eb805..59fd1c0 100644 --- a/vendor/github.com/hashicorp/consul/api/txn.go +++ b/vendor/github.com/hashicorp/consul/api/txn.go @@ -82,6 +82,7 @@ type KVTxnOp struct { Index uint64 Session string Namespace string `json:",omitempty"` + Partition string `json:",omitempty"` } // KVTxnOps defines a set of operations to be performed inside a single diff --git a/vendor/modules.txt b/vendor/modules.txt index c6eace0..5e9464b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -23,7 +23,7 @@ github.com/go-redis/redis/v8/internal/util # github.com/gorilla/mux v1.8.0 ## explicit; go 1.12 github.com/gorilla/mux -# github.com/hashicorp/consul/api v1.11.0 +# github.com/hashicorp/consul/api v1.12.0 ## explicit; go 1.12 github.com/hashicorp/consul/api # github.com/hashicorp/go-cleanhttp v0.5.1 @@ -41,7 +41,7 @@ github.com/hashicorp/go-rootcerts # github.com/hashicorp/golang-lru v0.5.0 ## explicit github.com/hashicorp/golang-lru/simplelru -# github.com/hashicorp/serf v0.9.5 +# github.com/hashicorp/serf v0.9.6 ## explicit; go 1.12 github.com/hashicorp/serf/coordinate # github.com/mattn/go-colorable v0.1.6