From 66b8c209904d0b377f3c561c5b21b393bdeb1235 Mon Sep 17 00:00:00 2001 From: Mike Morris Date: Wed, 4 Dec 2019 11:59:16 -0500 Subject: [PATCH] Bump go-discover to support EC2 Metadata Service v2 (#6865) Refs https://github.com/hashicorp/go-discover/pull/128 * deps: add replace directive for gocheck Transitive dep, source at https://launchpad.net/gocheck indicates project moved. This also avoids a dependency on bzr when fetching modules. Refs https://github.com/hashicorp/consul/pull/6818 * deps: make update-vendor * test: update retry-join expected names from go-discover --- agent/retry_join_test.go | 5 +- go.mod | 6 +- go.sum | 33 +- .../go-autorest/autorest/azure/auth/auth.go | 444 + .../aws/aws-sdk-go/aws/awsutil/path_value.go | 2 +- .../github.com/aws/aws-sdk-go/aws/config.go | 14 + .../aws/aws-sdk-go/aws/ec2metadata/api.go | 51 +- .../aws/aws-sdk-go/aws/ec2metadata/service.go | 114 +- .../aws/ec2metadata/token_provider.go | 92 + .../aws/aws-sdk-go/aws/endpoints/decode.go | 28 + .../aws/aws-sdk-go/aws/endpoints/defaults.go | 101 +- .../aws/aws-sdk-go/aws/endpoints/endpoints.go | 69 +- .../aws/endpoints/legacy_regions.go | 24 + .../aws/endpoints/sts_legacy_regions.go | 19 - .../aws/aws-sdk-go/aws/endpoints/v3model.go | 33 +- .../aws/request/request_pagination.go | 6 +- .../aws/aws-sdk-go/aws/session/credentials.go | 4 +- .../aws/aws-sdk-go/aws/session/env_config.go | 29 +- .../aws/aws-sdk-go/aws/session/session.go | 44 +- .../aws-sdk-go/aws/session/shared_config.go | 24 +- .../github.com/aws/aws-sdk-go/aws/version.go | 2 +- .../aws/aws-sdk-go/service/acmpca/api.go | 24 +- .../aws/aws-sdk-go/service/acmpca/service.go | 2 + .../aws/aws-sdk-go/service/ec2/api.go | 3826 ++++++- .../aws/aws-sdk-go/service/ec2/service.go | 2 + .../aws/aws-sdk-go/service/ec2/waiters.go | 51 + .../aws/aws-sdk-go/service/sts/api.go | 617 +- .../aws/aws-sdk-go/service/sts/errors.go | 29 +- .../aws/aws-sdk-go/service/sts/service.go | 2 + .../github.com/dimchansky/utfbom/.gitignore | 37 + .../github.com/dimchansky/utfbom/.travis.yml | 18 + vendor/github.com/dimchansky/utfbom/LICENSE | 201 + vendor/github.com/dimchansky/utfbom/README.md | 66 + vendor/github.com/dimchansky/utfbom/go.mod | 1 + vendor/github.com/dimchansky/utfbom/utfbom.go | 192 + .../hashicorp/go-discover/README.md | 8 + .../hashicorp/go-discover/discover.go | 4 + .../github.com/hashicorp/go-discover/go.mod | 9 +- .../github.com/hashicorp/go-discover/go.sum | 24 + .../provider/azure/azure_discover.go | 47 +- .../provider/linode/linode_discover.go | 142 + .../tencentcloud/tencentcloud_discover.go | 134 + vendor/github.com/linode/linodego/.gitignore | 19 + vendor/github.com/linode/linodego/.travis.yml | 22 + .../github.com/linode/linodego/API_SUPPORT.md | 379 + .../github.com/linode/linodego/CHANGELOG.md | 239 + vendor/github.com/linode/linodego/Gopkg.lock | 111 + vendor/github.com/linode/linodego/Gopkg.toml | 29 + vendor/github.com/linode/linodego/LICENSE | 21 + vendor/github.com/linode/linodego/Makefile | 43 + vendor/github.com/linode/linodego/README.md | 178 + vendor/github.com/linode/linodego/account.go | 45 + .../linode/linodego/account_events.go | 277 + .../linode/linodego/account_invoices.go | 125 + .../linode/linodego/account_notifications.go | 101 + .../linode/linodego/account_users.go | 164 + vendor/github.com/linode/linodego/client.go | 257 + .../linode/linodego/domain_records.go | 195 + vendor/github.com/linode/linodego/domains.go | 295 + vendor/github.com/linode/linodego/env.sample | 2 + vendor/github.com/linode/linodego/errors.go | 109 + vendor/github.com/linode/linodego/images.go | 168 + .../linode/linodego/instance_configs.go | 246 + .../linode/linodego/instance_disks.go | 251 + .../linode/linodego/instance_ips.go | 106 + .../linode/linodego/instance_snapshots.go | 188 + .../linode/linodego/instance_volumes.go | 38 + .../github.com/linode/linodego/instances.go | 454 + vendor/github.com/linode/linodego/kernels.go | 61 + vendor/github.com/linode/linodego/longview.go | 67 + .../linode/linodego/longview_subscriptions.go | 70 + vendor/github.com/linode/linodego/managed.go | 1 + .../github.com/linode/linodego/network_ips.go | 90 + .../linode/linodego/network_pools.go | 50 + .../linode/linodego/network_ranges.go | 50 + .../linode/linodego/nodebalancer.go | 199 + .../linodego/nodebalancer_config_nodes.go | 186 + .../linode/linodego/nodebalancer_configs.go | 334 + .../github.com/linode/linodego/pagination.go | 430 + vendor/github.com/linode/linodego/profile.go | 117 + .../linode/linodego/profile_sshkeys.go | 160 + .../linode/linodego/profile_tokens.go | 195 + vendor/github.com/linode/linodego/regions.go | 64 + .../github.com/linode/linodego/resources.go | 162 + .../linode/linodego/stackscripts.go | 208 + vendor/github.com/linode/linodego/support.go | 88 + vendor/github.com/linode/linodego/tags.go | 219 + vendor/github.com/linode/linodego/template.go | 167 + vendor/github.com/linode/linodego/types.go | 90 + vendor/github.com/linode/linodego/util.go | 15 + vendor/github.com/linode/linodego/volumes.go | 299 + vendor/github.com/linode/linodego/waitfor.go | 273 + .../tencentcloud/tencentcloud-sdk-go/LICENSE | 201 + .../tencentcloud/common/client.go | 264 + .../tencentcloud/common/credentials.go | 58 + .../tencentcloud/common/errors/errors.go | 35 + .../tencentcloud/common/http/request.go | 233 + .../tencentcloud/common/http/response.go | 81 + .../common/profile/client_profile.go | 21 + .../common/profile/http_profile.go | 17 + .../tencentcloud/common/sign.go | 94 + .../tencentcloud/common/types.go | 47 + .../tencentcloud/cvm/v20170312/client.go | 1758 +++ .../tencentcloud/cvm/v20170312/models.go | 3490 ++++++ .../golang.org/x/crypto/pkcs12/bmp-string.go | 50 + vendor/golang.org/x/crypto/pkcs12/crypto.go | 131 + vendor/golang.org/x/crypto/pkcs12/errors.go | 23 + .../x/crypto/pkcs12/internal/rc2/rc2.go | 271 + vendor/golang.org/x/crypto/pkcs12/mac.go | 45 + vendor/golang.org/x/crypto/pkcs12/pbkdf.go | 170 + vendor/golang.org/x/crypto/pkcs12/pkcs12.go | 349 + vendor/golang.org/x/crypto/pkcs12/safebags.go | 57 + vendor/golang.org/x/net/publicsuffix/gen.go | 717 ++ vendor/golang.org/x/net/publicsuffix/list.go | 181 + vendor/golang.org/x/net/publicsuffix/table.go | 9962 +++++++++++++++++ vendor/gopkg.in/resty.v1/.gitignore | 28 + vendor/gopkg.in/resty.v1/.travis.yml | 28 + vendor/gopkg.in/resty.v1/BUILD.bazel | 36 + vendor/gopkg.in/resty.v1/LICENSE | 21 + vendor/gopkg.in/resty.v1/README.md | 741 ++ vendor/gopkg.in/resty.v1/WORKSPACE | 27 + vendor/gopkg.in/resty.v1/client.go | 926 ++ vendor/gopkg.in/resty.v1/default.go | 327 + vendor/gopkg.in/resty.v1/go.mod | 3 + vendor/gopkg.in/resty.v1/middleware.go | 469 + vendor/gopkg.in/resty.v1/redirect.go | 99 + vendor/gopkg.in/resty.v1/request.go | 586 + vendor/gopkg.in/resty.v1/request16.go | 63 + vendor/gopkg.in/resty.v1/request17.go | 96 + vendor/gopkg.in/resty.v1/response.go | 150 + vendor/gopkg.in/resty.v1/resty.go | 9 + vendor/gopkg.in/resty.v1/retry.go | 118 + vendor/gopkg.in/resty.v1/util.go | 281 + vendor/modules.txt | 24 +- 134 files changed, 35968 insertions(+), 556 deletions(-) create mode 100644 vendor/github.com/Azure/go-autorest/autorest/azure/auth/auth.go create mode 100644 vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/token_provider.go create mode 100644 vendor/github.com/aws/aws-sdk-go/aws/endpoints/legacy_regions.go delete mode 100644 vendor/github.com/aws/aws-sdk-go/aws/endpoints/sts_legacy_regions.go create mode 100644 vendor/github.com/dimchansky/utfbom/.gitignore create mode 100644 vendor/github.com/dimchansky/utfbom/.travis.yml create mode 100644 vendor/github.com/dimchansky/utfbom/LICENSE create mode 100644 vendor/github.com/dimchansky/utfbom/README.md create mode 100644 vendor/github.com/dimchansky/utfbom/go.mod create mode 100644 vendor/github.com/dimchansky/utfbom/utfbom.go create mode 100644 vendor/github.com/hashicorp/go-discover/provider/linode/linode_discover.go create mode 100644 vendor/github.com/hashicorp/go-discover/provider/tencentcloud/tencentcloud_discover.go create mode 100644 vendor/github.com/linode/linodego/.gitignore create mode 100644 vendor/github.com/linode/linodego/.travis.yml create mode 100644 vendor/github.com/linode/linodego/API_SUPPORT.md create mode 100644 vendor/github.com/linode/linodego/CHANGELOG.md create mode 100644 vendor/github.com/linode/linodego/Gopkg.lock create mode 100644 vendor/github.com/linode/linodego/Gopkg.toml create mode 100644 vendor/github.com/linode/linodego/LICENSE create mode 100644 vendor/github.com/linode/linodego/Makefile create mode 100644 vendor/github.com/linode/linodego/README.md create mode 100644 vendor/github.com/linode/linodego/account.go create mode 100644 vendor/github.com/linode/linodego/account_events.go create mode 100644 vendor/github.com/linode/linodego/account_invoices.go create mode 100644 vendor/github.com/linode/linodego/account_notifications.go create mode 100644 vendor/github.com/linode/linodego/account_users.go create mode 100644 vendor/github.com/linode/linodego/client.go create mode 100644 vendor/github.com/linode/linodego/domain_records.go create mode 100644 vendor/github.com/linode/linodego/domains.go create mode 100644 vendor/github.com/linode/linodego/env.sample create mode 100644 vendor/github.com/linode/linodego/errors.go create mode 100644 vendor/github.com/linode/linodego/images.go create mode 100644 vendor/github.com/linode/linodego/instance_configs.go create mode 100644 vendor/github.com/linode/linodego/instance_disks.go create mode 100644 vendor/github.com/linode/linodego/instance_ips.go create mode 100644 vendor/github.com/linode/linodego/instance_snapshots.go create mode 100644 vendor/github.com/linode/linodego/instance_volumes.go create mode 100644 vendor/github.com/linode/linodego/instances.go create mode 100644 vendor/github.com/linode/linodego/kernels.go create mode 100644 vendor/github.com/linode/linodego/longview.go create mode 100644 vendor/github.com/linode/linodego/longview_subscriptions.go create mode 100644 vendor/github.com/linode/linodego/managed.go create mode 100644 vendor/github.com/linode/linodego/network_ips.go create mode 100644 vendor/github.com/linode/linodego/network_pools.go create mode 100644 vendor/github.com/linode/linodego/network_ranges.go create mode 100644 vendor/github.com/linode/linodego/nodebalancer.go create mode 100644 vendor/github.com/linode/linodego/nodebalancer_config_nodes.go create mode 100644 vendor/github.com/linode/linodego/nodebalancer_configs.go create mode 100644 vendor/github.com/linode/linodego/pagination.go create mode 100644 vendor/github.com/linode/linodego/profile.go create mode 100644 vendor/github.com/linode/linodego/profile_sshkeys.go create mode 100644 vendor/github.com/linode/linodego/profile_tokens.go create mode 100644 vendor/github.com/linode/linodego/regions.go create mode 100644 vendor/github.com/linode/linodego/resources.go create mode 100644 vendor/github.com/linode/linodego/stackscripts.go create mode 100644 vendor/github.com/linode/linodego/support.go create mode 100644 vendor/github.com/linode/linodego/tags.go create mode 100644 vendor/github.com/linode/linodego/template.go create mode 100644 vendor/github.com/linode/linodego/types.go create mode 100644 vendor/github.com/linode/linodego/util.go create mode 100644 vendor/github.com/linode/linodego/volumes.go create mode 100644 vendor/github.com/linode/linodego/waitfor.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/LICENSE create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/credentials.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors/errors.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/response.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/client_profile.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/http_profile.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/types.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/client.go create mode 100644 vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/models.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/bmp-string.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/crypto.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/errors.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/mac.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/pbkdf.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/pkcs12.go create mode 100644 vendor/golang.org/x/crypto/pkcs12/safebags.go create mode 100644 vendor/golang.org/x/net/publicsuffix/gen.go create mode 100644 vendor/golang.org/x/net/publicsuffix/list.go create mode 100644 vendor/golang.org/x/net/publicsuffix/table.go create mode 100644 vendor/gopkg.in/resty.v1/.gitignore create mode 100644 vendor/gopkg.in/resty.v1/.travis.yml create mode 100644 vendor/gopkg.in/resty.v1/BUILD.bazel create mode 100644 vendor/gopkg.in/resty.v1/LICENSE create mode 100644 vendor/gopkg.in/resty.v1/README.md create mode 100644 vendor/gopkg.in/resty.v1/WORKSPACE create mode 100644 vendor/gopkg.in/resty.v1/client.go create mode 100644 vendor/gopkg.in/resty.v1/default.go create mode 100644 vendor/gopkg.in/resty.v1/go.mod create mode 100644 vendor/gopkg.in/resty.v1/middleware.go create mode 100644 vendor/gopkg.in/resty.v1/redirect.go create mode 100644 vendor/gopkg.in/resty.v1/request.go create mode 100644 vendor/gopkg.in/resty.v1/request16.go create mode 100644 vendor/gopkg.in/resty.v1/request17.go create mode 100644 vendor/gopkg.in/resty.v1/response.go create mode 100644 vendor/gopkg.in/resty.v1/resty.go create mode 100644 vendor/gopkg.in/resty.v1/retry.go create mode 100644 vendor/gopkg.in/resty.v1/util.go diff --git a/agent/retry_join_test.go b/agent/retry_join_test.go index f31f1aee65..2962f00ebd 100644 --- a/agent/retry_join_test.go +++ b/agent/retry_join_test.go @@ -12,8 +12,9 @@ func TestAgentRetryNewDiscover(t *testing.T) { d, err := newDiscover() require.NoError(t, err) expected := []string{ - "aliyun", "aws", "azure", "digitalocean", "gce", "k8s", "mdns", - "os", "packet", "scaleway", "softlayer", "triton", "vsphere", + "aliyun", "aws", "azure", "digitalocean", "gce", "k8s", "linode", + "mdns", "os", "packet", "scaleway", "softlayer", "tencentcloud", + "triton", "vsphere", } require.Equal(t, expected, d.Names()) } diff --git a/go.mod b/go.mod index c3af7c0332..2088d5bf33 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,8 @@ replace github.com/hashicorp/consul/api => ./api replace github.com/hashicorp/consul/sdk => ./sdk +replace launchpad.net/gocheck => github.com/go-check/check v0.0.0-20140225173054-eb6ee6f84d0a848c7f11b46cd11f28875ba56b1c + require ( github.com/Azure/go-autorest v10.15.3+incompatible // indirect github.com/Microsoft/go-winio v0.4.3 // indirect @@ -14,7 +16,7 @@ require ( github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 github.com/armon/go-radix v1.0.0 - github.com/aws/aws-sdk-go v1.25.32 + github.com/aws/aws-sdk-go v1.25.41 github.com/coredns/coredns v1.1.2 github.com/digitalocean/godo v1.10.0 // indirect github.com/docker/go-connections v0.3.0 @@ -30,7 +32,7 @@ require ( github.com/hashicorp/go-bexpr v0.1.2 github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de github.com/hashicorp/go-cleanhttp v0.5.1 - github.com/hashicorp/go-discover v0.0.0-20190403160810-22221edb15cd + github.com/hashicorp/go-discover v0.0.0-20191202160150-7ec2cfbda7a2 github.com/hashicorp/go-hclog v0.9.2 github.com/hashicorp/go-memdb v1.0.3 github.com/hashicorp/go-msgpack v0.5.5 diff --git a/go.sum b/go.sum index 74b28b9f07..fda5361442 100644 --- a/go.sum +++ b/go.sum @@ -26,10 +26,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26 github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.15.24 h1:xLAdTA/ore6xdPAljzZRed7IGqQgC+nY+ERS5vaj4Ro= -github.com/aws/aws-sdk-go v1.15.24/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= -github.com/aws/aws-sdk-go v1.25.32 h1:GhqlDvuPXnlW46VoKvfLZkJj5IA6jGLO+/TUPCJSYOY= -github.com/aws/aws-sdk-go v1.25.32/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/aws/aws-sdk-go v1.25.41 h1:/hj7nZ0586wFqpwjNpzWiUTwtaMgxAZNZKHay80MdXw= +github.com/aws/aws-sdk-go v1.25.41/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= @@ -54,6 +52,10 @@ github.com/digitalocean/godo v1.1.1 h1:v0A7yF3xmKLjjdJGIeBbINfMufcrrRhqZsxuVQMoT github.com/digitalocean/godo v1.1.1/go.mod h1:h6faOIcZ8lWIwNQ+DN7b3CgX4Kwby5T+nbpNqkUIozU= github.com/digitalocean/godo v1.10.0 h1:uW1/FcvZE/hoixnJcnlmIUvTVNdZCLjRLzmDtRi1xXY= github.com/digitalocean/godo v1.10.0/go.mod h1:h6faOIcZ8lWIwNQ+DN7b3CgX4Kwby5T+nbpNqkUIozU= +github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4= +github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= +github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY= +github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/docker/go-connections v0.3.0 h1:3lOnM9cSzgGwx8VfK/NGOW5fLQ0GjIlCkaktF+n1M6o= github.com/docker/go-connections v0.3.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0 h1:ZoRgc53qJCfSLimXqJDrmBhnt5GChDsExMCK7t48o0Y= @@ -69,8 +71,7 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-ini/ini v1.25.4 h1:Mujh4R/dH6YL8bxuISne3xX2+qcQ9p0IxKAP6ExWoUo= -github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= +github.com/go-check/check v0.0.0-20140225173054-eb6ee6f84d0a848c7f11b46cd11f28875ba56b1c/go.mod h1:9ES+weclKsC9YodN5RgxqK/VD9HM9JsCSh7rNhMZE98= github.com/go-ldap/ldap v3.0.2+incompatible h1:kD5HQcAzlQ7yrhfn+h+MSABeAy/jAJhvIJ/QDllP44g= github.com/go-ldap/ldap v3.0.2+incompatible/go.mod h1:qfd9rJvER9Q0/D/Sqn1DfHRoBp40uXYvFoEVrNEPqRc= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= @@ -119,8 +120,8 @@ github.com/hashicorp/go-checkpoint v0.0.0-20171009173528-1545e56e46de/go.mod h1: github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-discover v0.0.0-20190403160810-22221edb15cd h1:SynRxs8h2h7lLSA5py5a3WWkYpImhREtju0CuRd97wc= -github.com/hashicorp/go-discover v0.0.0-20190403160810-22221edb15cd/go.mod h1:ueUgD9BeIocT7QNuvxSyJyPAM9dfifBcaWmeybb67OY= +github.com/hashicorp/go-discover v0.0.0-20191202160150-7ec2cfbda7a2 h1:r7GtRT+VXoM5WqHMxSVDIKgVCfK9T8CoS51RDKeOjBM= +github.com/hashicorp/go-discover v0.0.0-20191202160150-7ec2cfbda7a2/go.mod h1:NnH5X4UCBEBdTuK2L8s4e4ilJm3UmGX0bANHCz0HSs0= github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= github.com/hashicorp/go-hclog v0.8.0/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxuKuM= @@ -207,8 +208,6 @@ github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da h1:FjHUJJ7oBW4G/9j1KzlHaXL09LyMVM9rupS39lncbXk= github.com/jarcoal/httpmock v0.0.0-20180424175123-9c70cfe4a1da/go.mod h1:ks+b9deReOc7jgqp+e7LuFiCBH6Rm5hL32cLcEAArb4= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 h1:12VvqtR6Aowv3l/EQUlocDHW2Cp4G9WJVH7uyH8QFJE= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/joyent/triton-go v0.0.0-20180628001255-830d2b111e62 h1:JHCT6xuyPUrbbgAPE/3dqlvUKzRHMNuTBKKUb6OeR/k= @@ -225,6 +224,15 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk= +github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk= +github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y= +github.com/likexian/gokit v0.20.16/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU= +github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg= +github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec= +github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8= +github.com/linode/linodego v0.7.1 h1:4WZmMpSA2NRwlPZcc0+4Gyn7rr99Evk9bnr0B3gXRKE= +github.com/linode/linodego v0.7.1/go.mod h1:ga11n3ivecUrPCHN0rANxKmfWBJVkOXfLMZinAbj2sY= github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= @@ -328,6 +336,8 @@ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible h1:8uRvJleFpqLsO77WaAh2UrasMOzd8MxXrNj20e7El+Q= +github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 h1:/Bsw4C+DEdqPjt8vAqaC9LAqpAQnaCQQqmolqq3S1T4= github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9/go.mod h1:RHkNRtSLfOK7qBTHaeSX1D6BNpI3qw7NTxsmNr4RvN8= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 h1:G3dpKMzFDjgEh2q1Z7zUUtKa8ViPtH+ocF0bE0g00O8= @@ -350,6 +360,7 @@ golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 h1:x6rhz8Y9CjbgQkccRGmELH6K+ golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0= golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -425,6 +436,8 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNj gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.3.1 h1:SK5KegNXmKmqE342YYN2qPHEnUYeoMiXXl1poUlI+o4= gopkg.in/square/go-jose.v2 v2.3.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= diff --git a/vendor/github.com/Azure/go-autorest/autorest/azure/auth/auth.go b/vendor/github.com/Azure/go-autorest/autorest/azure/auth/auth.go new file mode 100644 index 0000000000..a14b87900f --- /dev/null +++ b/vendor/github.com/Azure/go-autorest/autorest/azure/auth/auth.go @@ -0,0 +1,444 @@ +package auth + +// Copyright 2017 Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import ( + "bytes" + "crypto/rsa" + "crypto/x509" + "encoding/binary" + "encoding/json" + "errors" + "fmt" + "io/ioutil" + "log" + "os" + "strings" + "unicode/utf16" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/adal" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/dimchansky/utfbom" + "golang.org/x/crypto/pkcs12" +) + +// NewAuthorizerFromEnvironment creates an Authorizer configured from environment variables in the order: +// 1. Client credentials +// 2. Client certificate +// 3. Username password +// 4. MSI +func NewAuthorizerFromEnvironment() (autorest.Authorizer, error) { + settings, err := getAuthenticationSettings() + if err != nil { + return nil, err + } + + if settings.resource == "" { + settings.resource = settings.environment.ResourceManagerEndpoint + } + + return settings.getAuthorizer() +} + +// NewAuthorizerFromEnvironmentWithResource creates an Authorizer configured from environment variables in the order: +// 1. Client credentials +// 2. Client certificate +// 3. Username password +// 4. MSI +func NewAuthorizerFromEnvironmentWithResource(resource string) (autorest.Authorizer, error) { + settings, err := getAuthenticationSettings() + if err != nil { + return nil, err + } + settings.resource = resource + return settings.getAuthorizer() +} + +type settings struct { + tenantID string + clientID string + clientSecret string + certificatePath string + certificatePassword string + username string + password string + envName string + resource string + environment azure.Environment +} + +func getAuthenticationSettings() (s settings, err error) { + s = settings{ + tenantID: os.Getenv("AZURE_TENANT_ID"), + clientID: os.Getenv("AZURE_CLIENT_ID"), + clientSecret: os.Getenv("AZURE_CLIENT_SECRET"), + certificatePath: os.Getenv("AZURE_CERTIFICATE_PATH"), + certificatePassword: os.Getenv("AZURE_CERTIFICATE_PASSWORD"), + username: os.Getenv("AZURE_USERNAME"), + password: os.Getenv("AZURE_PASSWORD"), + envName: os.Getenv("AZURE_ENVIRONMENT"), + resource: os.Getenv("AZURE_AD_RESOURCE"), + } + + if s.envName == "" { + s.environment = azure.PublicCloud + } else { + s.environment, err = azure.EnvironmentFromName(s.envName) + } + return +} + +func (settings settings) getAuthorizer() (autorest.Authorizer, error) { + //1.Client Credentials + if settings.clientSecret != "" { + config := NewClientCredentialsConfig(settings.clientID, settings.clientSecret, settings.tenantID) + config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint + config.Resource = settings.resource + return config.Authorizer() + } + + //2. Client Certificate + if settings.certificatePath != "" { + config := NewClientCertificateConfig(settings.certificatePath, settings.certificatePassword, settings.clientID, settings.tenantID) + config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint + config.Resource = settings.resource + return config.Authorizer() + } + + //3. Username Password + if settings.username != "" && settings.password != "" { + config := NewUsernamePasswordConfig(settings.username, settings.password, settings.clientID, settings.tenantID) + config.AADEndpoint = settings.environment.ActiveDirectoryEndpoint + config.Resource = settings.resource + return config.Authorizer() + } + + // 4. MSI + config := NewMSIConfig() + config.Resource = settings.resource + config.ClientID = settings.clientID + return config.Authorizer() +} + +// NewAuthorizerFromFile creates an Authorizer configured from a configuration file. +func NewAuthorizerFromFile(baseURI string) (autorest.Authorizer, error) { + fileLocation := os.Getenv("AZURE_AUTH_LOCATION") + if fileLocation == "" { + return nil, errors.New("auth file not found. Environment variable AZURE_AUTH_LOCATION is not set") + } + + contents, err := ioutil.ReadFile(fileLocation) + if err != nil { + return nil, err + } + + // Auth file might be encoded + decoded, err := decode(contents) + if err != nil { + return nil, err + } + + file := file{} + err = json.Unmarshal(decoded, &file) + if err != nil { + return nil, err + } + + resource, err := getResourceForToken(file, baseURI) + if err != nil { + return nil, err + } + + config, err := adal.NewOAuthConfig(file.ActiveDirectoryEndpoint, file.TenantID) + if err != nil { + return nil, err + } + + spToken, err := adal.NewServicePrincipalToken(*config, file.ClientID, file.ClientSecret, resource) + if err != nil { + return nil, err + } + + return autorest.NewBearerAuthorizer(spToken), nil +} + +// File represents the authentication file +type file struct { + ClientID string `json:"clientId,omitempty"` + ClientSecret string `json:"clientSecret,omitempty"` + SubscriptionID string `json:"subscriptionId,omitempty"` + TenantID string `json:"tenantId,omitempty"` + ActiveDirectoryEndpoint string `json:"activeDirectoryEndpointUrl,omitempty"` + ResourceManagerEndpoint string `json:"resourceManagerEndpointUrl,omitempty"` + GraphResourceID string `json:"activeDirectoryGraphResourceId,omitempty"` + SQLManagementEndpoint string `json:"sqlManagementEndpointUrl,omitempty"` + GalleryEndpoint string `json:"galleryEndpointUrl,omitempty"` + ManagementEndpoint string `json:"managementEndpointUrl,omitempty"` +} + +func decode(b []byte) ([]byte, error) { + reader, enc := utfbom.Skip(bytes.NewReader(b)) + + switch enc { + case utfbom.UTF16LittleEndian: + u16 := make([]uint16, (len(b)/2)-1) + err := binary.Read(reader, binary.LittleEndian, &u16) + if err != nil { + return nil, err + } + return []byte(string(utf16.Decode(u16))), nil + case utfbom.UTF16BigEndian: + u16 := make([]uint16, (len(b)/2)-1) + err := binary.Read(reader, binary.BigEndian, &u16) + if err != nil { + return nil, err + } + return []byte(string(utf16.Decode(u16))), nil + } + return ioutil.ReadAll(reader) +} + +func getResourceForToken(f file, baseURI string) (string, error) { + // Compare dafault base URI from the SDK to the endpoints from the public cloud + // Base URI and token resource are the same string. This func finds the authentication + // file field that matches the SDK base URI. The SDK defines the public cloud + // endpoint as its default base URI + if !strings.HasSuffix(baseURI, "/") { + baseURI += "/" + } + switch baseURI { + case azure.PublicCloud.ServiceManagementEndpoint: + return f.ManagementEndpoint, nil + case azure.PublicCloud.ResourceManagerEndpoint: + return f.ResourceManagerEndpoint, nil + case azure.PublicCloud.ActiveDirectoryEndpoint: + return f.ActiveDirectoryEndpoint, nil + case azure.PublicCloud.GalleryEndpoint: + return f.GalleryEndpoint, nil + case azure.PublicCloud.GraphEndpoint: + return f.GraphResourceID, nil + } + return "", fmt.Errorf("auth: base URI not found in endpoints") +} + +// NewClientCredentialsConfig creates an AuthorizerConfig object configured to obtain an Authorizer through Client Credentials. +// Defaults to Public Cloud and Resource Manager Endpoint. +func NewClientCredentialsConfig(clientID string, clientSecret string, tenantID string) ClientCredentialsConfig { + return ClientCredentialsConfig{ + ClientID: clientID, + ClientSecret: clientSecret, + TenantID: tenantID, + Resource: azure.PublicCloud.ResourceManagerEndpoint, + AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, + } +} + +// NewClientCertificateConfig creates a ClientCertificateConfig object configured to obtain an Authorizer through client certificate. +// Defaults to Public Cloud and Resource Manager Endpoint. +func NewClientCertificateConfig(certificatePath string, certificatePassword string, clientID string, tenantID string) ClientCertificateConfig { + return ClientCertificateConfig{ + CertificatePath: certificatePath, + CertificatePassword: certificatePassword, + ClientID: clientID, + TenantID: tenantID, + Resource: azure.PublicCloud.ResourceManagerEndpoint, + AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, + } +} + +// NewUsernamePasswordConfig creates an UsernamePasswordConfig object configured to obtain an Authorizer through username and password. +// Defaults to Public Cloud and Resource Manager Endpoint. +func NewUsernamePasswordConfig(username string, password string, clientID string, tenantID string) UsernamePasswordConfig { + return UsernamePasswordConfig{ + Username: username, + Password: password, + ClientID: clientID, + TenantID: tenantID, + Resource: azure.PublicCloud.ResourceManagerEndpoint, + AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, + } +} + +// NewMSIConfig creates an MSIConfig object configured to obtain an Authorizer through MSI. +func NewMSIConfig() MSIConfig { + return MSIConfig{ + Resource: azure.PublicCloud.ResourceManagerEndpoint, + } +} + +// NewDeviceFlowConfig creates a DeviceFlowConfig object configured to obtain an Authorizer through device flow. +// Defaults to Public Cloud and Resource Manager Endpoint. +func NewDeviceFlowConfig(clientID string, tenantID string) DeviceFlowConfig { + return DeviceFlowConfig{ + ClientID: clientID, + TenantID: tenantID, + Resource: azure.PublicCloud.ResourceManagerEndpoint, + AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, + } +} + +//AuthorizerConfig provides an authorizer from the configuration provided. +type AuthorizerConfig interface { + Authorizer() (autorest.Authorizer, error) +} + +// ClientCredentialsConfig provides the options to get a bearer authorizer from client credentials. +type ClientCredentialsConfig struct { + ClientID string + ClientSecret string + TenantID string + AADEndpoint string + Resource string +} + +// Authorizer gets the authorizer from client credentials. +func (ccc ClientCredentialsConfig) Authorizer() (autorest.Authorizer, error) { + oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) + if err != nil { + return nil, err + } + + spToken, err := adal.NewServicePrincipalToken(*oauthConfig, ccc.ClientID, ccc.ClientSecret, ccc.Resource) + if err != nil { + return nil, fmt.Errorf("failed to get oauth token from client credentials: %v", err) + } + + return autorest.NewBearerAuthorizer(spToken), nil +} + +// ClientCertificateConfig provides the options to get a bearer authorizer from a client certificate. +type ClientCertificateConfig struct { + ClientID string + CertificatePath string + CertificatePassword string + TenantID string + AADEndpoint string + Resource string +} + +// Authorizer gets an authorizer object from client certificate. +func (ccc ClientCertificateConfig) Authorizer() (autorest.Authorizer, error) { + oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) + + certData, err := ioutil.ReadFile(ccc.CertificatePath) + if err != nil { + return nil, fmt.Errorf("failed to read the certificate file (%s): %v", ccc.CertificatePath, err) + } + + certificate, rsaPrivateKey, err := decodePkcs12(certData, ccc.CertificatePassword) + if err != nil { + return nil, fmt.Errorf("failed to decode pkcs12 certificate while creating spt: %v", err) + } + + spToken, err := adal.NewServicePrincipalTokenFromCertificate(*oauthConfig, ccc.ClientID, certificate, rsaPrivateKey, ccc.Resource) + + if err != nil { + return nil, fmt.Errorf("failed to get oauth token from certificate auth: %v", err) + } + + return autorest.NewBearerAuthorizer(spToken), nil +} + +// DeviceFlowConfig provides the options to get a bearer authorizer using device flow authentication. +type DeviceFlowConfig struct { + ClientID string + TenantID string + AADEndpoint string + Resource string +} + +// Authorizer gets the authorizer from device flow. +func (dfc DeviceFlowConfig) Authorizer() (autorest.Authorizer, error) { + oauthClient := &autorest.Client{} + oauthConfig, err := adal.NewOAuthConfig(dfc.AADEndpoint, dfc.TenantID) + deviceCode, err := adal.InitiateDeviceAuth(oauthClient, *oauthConfig, dfc.ClientID, dfc.Resource) + if err != nil { + return nil, fmt.Errorf("failed to start device auth flow: %s", err) + } + + log.Println(*deviceCode.Message) + + token, err := adal.WaitForUserCompletion(oauthClient, deviceCode) + if err != nil { + return nil, fmt.Errorf("failed to finish device auth flow: %s", err) + } + + spToken, err := adal.NewServicePrincipalTokenFromManualToken(*oauthConfig, dfc.ClientID, dfc.Resource, *token) + if err != nil { + return nil, fmt.Errorf("failed to get oauth token from device flow: %v", err) + } + + return autorest.NewBearerAuthorizer(spToken), nil +} + +func decodePkcs12(pkcs []byte, password string) (*x509.Certificate, *rsa.PrivateKey, error) { + privateKey, certificate, err := pkcs12.Decode(pkcs, password) + if err != nil { + return nil, nil, err + } + + rsaPrivateKey, isRsaKey := privateKey.(*rsa.PrivateKey) + if !isRsaKey { + return nil, nil, fmt.Errorf("PKCS#12 certificate must contain an RSA private key") + } + + return certificate, rsaPrivateKey, nil +} + +// UsernamePasswordConfig provides the options to get a bearer authorizer from a username and a password. +type UsernamePasswordConfig struct { + ClientID string + Username string + Password string + TenantID string + AADEndpoint string + Resource string +} + +// Authorizer gets the authorizer from a username and a password. +func (ups UsernamePasswordConfig) Authorizer() (autorest.Authorizer, error) { + + oauthConfig, err := adal.NewOAuthConfig(ups.AADEndpoint, ups.TenantID) + + spToken, err := adal.NewServicePrincipalTokenFromUsernamePassword(*oauthConfig, ups.ClientID, ups.Username, ups.Password, ups.Resource) + + if err != nil { + return nil, fmt.Errorf("failed to get oauth token from username and password auth: %v", err) + } + + return autorest.NewBearerAuthorizer(spToken), nil +} + +// MSIConfig provides the options to get a bearer authorizer through MSI. +type MSIConfig struct { + Resource string + ClientID string +} + +// Authorizer gets the authorizer from MSI. +func (mc MSIConfig) Authorizer() (autorest.Authorizer, error) { + msiEndpoint, err := adal.GetMSIVMEndpoint() + if err != nil { + return nil, err + } + + spToken, err := adal.NewServicePrincipalTokenFromMSI(msiEndpoint, mc.Resource) + if err != nil { + return nil, fmt.Errorf("failed to get oauth token from MSI: %v", err) + } + + return autorest.NewBearerAuthorizer(spToken), nil +} diff --git a/vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go b/vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go index 285e54d679..a4eb6a7f43 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/awsutil/path_value.go @@ -70,7 +70,7 @@ func rValuesAtPath(v interface{}, path string, createPath, caseSensitive, nilTer value = value.FieldByNameFunc(func(name string) bool { if c == name { return true - } else if !caseSensitive && strings.ToLower(name) == strings.ToLower(c) { + } else if !caseSensitive && strings.EqualFold(name, c) { return true } return false diff --git a/vendor/github.com/aws/aws-sdk-go/aws/config.go b/vendor/github.com/aws/aws-sdk-go/aws/config.go index 8a7699b961..93ebbcc13f 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/config.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/config.go @@ -249,6 +249,9 @@ type Config struct { // STSRegionalEndpoint will enable regional or legacy endpoint resolving STSRegionalEndpoint endpoints.STSRegionalEndpoint + + // S3UsEast1RegionalEndpoint will enable regional or legacy endpoint resolving + S3UsEast1RegionalEndpoint endpoints.S3UsEast1RegionalEndpoint } // NewConfig returns a new Config pointer that can be chained with builder @@ -430,6 +433,13 @@ func (c *Config) WithSTSRegionalEndpoint(sre endpoints.STSRegionalEndpoint) *Con return c } +// WithS3UsEast1RegionalEndpoint will set whether or not to use regional endpoint flag +// when resolving the endpoint for a service +func (c *Config) WithS3UsEast1RegionalEndpoint(sre endpoints.S3UsEast1RegionalEndpoint) *Config { + c.S3UsEast1RegionalEndpoint = sre + return c +} + func mergeInConfig(dst *Config, other *Config) { if other == nil { return @@ -534,6 +544,10 @@ func mergeInConfig(dst *Config, other *Config) { if other.STSRegionalEndpoint != endpoints.UnsetSTSEndpoint { dst.STSRegionalEndpoint = other.STSRegionalEndpoint } + + if other.S3UsEast1RegionalEndpoint != endpoints.UnsetS3UsEast1Endpoint { + dst.S3UsEast1RegionalEndpoint = other.S3UsEast1RegionalEndpoint + } } // Copy will return a shallow copy of the Config object. If any additional diff --git a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/api.go b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/api.go index d126764ce4..fe25edf888 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/api.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/api.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strconv" "strings" "time" @@ -12,8 +13,41 @@ import ( "github.com/aws/aws-sdk-go/internal/sdkuri" ) +// getToken uses the duration to return a token for EC2 metadata service, +// or an error if the request failed. +func (c *EC2Metadata) getToken(duration time.Duration) (tokenOutput, error) { + op := &request.Operation{ + Name: "GetToken", + HTTPMethod: "PUT", + HTTPPath: "/api/token", + } + + var output tokenOutput + req := c.NewRequest(op, nil, &output) + + // remove the fetch token handler from the request handlers to avoid infinite recursion + req.Handlers.Sign.RemoveByName(fetchTokenHandlerName) + + // Swap the unmarshalMetadataHandler with unmarshalTokenHandler on this request. + req.Handlers.Unmarshal.Swap(unmarshalMetadataHandlerName, unmarshalTokenHandler) + + ttl := strconv.FormatInt(int64(duration / time.Second),10) + req.HTTPRequest.Header.Set(ttlHeader, ttl) + + err := req.Send() + + // Errors with bad request status should be returned. + if err != nil { + err = awserr.NewRequestFailure( + awserr.New(req.HTTPResponse.Status, http.StatusText(req.HTTPResponse.StatusCode), err), + req.HTTPResponse.StatusCode, req.RequestID) + } + + return output, err +} + // GetMetadata uses the path provided to request information from the EC2 -// instance metdata service. The content will be returned as a string, or +// instance metadata service. The content will be returned as a string, or // error if the request failed. func (c *EC2Metadata) GetMetadata(p string) (string, error) { op := &request.Operation{ @@ -21,11 +55,11 @@ func (c *EC2Metadata) GetMetadata(p string) (string, error) { HTTPMethod: "GET", HTTPPath: sdkuri.PathJoin("/meta-data", p), } - output := &metadataOutput{} - req := c.NewRequest(op, nil, output) - err := req.Send() + req := c.NewRequest(op, nil, output) + + err := req.Send() return output.Content, err } @@ -41,13 +75,8 @@ func (c *EC2Metadata) GetUserData() (string, error) { output := &metadataOutput{} req := c.NewRequest(op, nil, output) - req.Handlers.UnmarshalError.PushBack(func(r *request.Request) { - if r.HTTPResponse.StatusCode == http.StatusNotFound { - r.Error = awserr.New("NotFoundError", "user-data not found", r.Error) - } - }) - err := req.Send() + err := req.Send() return output.Content, err } @@ -63,8 +92,8 @@ func (c *EC2Metadata) GetDynamicData(p string) (string, error) { output := &metadataOutput{} req := c.NewRequest(op, nil, output) - err := req.Send() + err := req.Send() return output.Content, err } diff --git a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go index 4c5636e350..8eccac05aa 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/service.go @@ -13,6 +13,7 @@ import ( "io" "net/http" "os" + "strconv" "strings" "time" @@ -24,9 +25,25 @@ import ( "github.com/aws/aws-sdk-go/aws/request" ) -// ServiceName is the name of the service. -const ServiceName = "ec2metadata" -const disableServiceEnvVar = "AWS_EC2_METADATA_DISABLED" +const ( + // ServiceName is the name of the service. + ServiceName = "ec2metadata" + disableServiceEnvVar = "AWS_EC2_METADATA_DISABLED" + + // Headers for Token and TTL + ttlHeader = "x-aws-ec2-metadata-token-ttl-seconds" + tokenHeader = "x-aws-ec2-metadata-token" + + // Named Handler constants + fetchTokenHandlerName = "FetchTokenHandler" + unmarshalMetadataHandlerName = "unmarshalMetadataHandler" + unmarshalTokenHandlerName = "unmarshalTokenHandler" + enableTokenProviderHandlerName = "enableTokenProviderHandler" + + // TTL constants + defaultTTL = 21600 * time.Second + ttlExpirationWindow = 30 * time.Second +) // A EC2Metadata is an EC2 Metadata service Client. type EC2Metadata struct { @@ -80,13 +97,27 @@ func NewClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio ), } - svc.Handlers.Unmarshal.PushBack(unmarshalHandler) + // token provider instance + tp := newTokenProvider(svc, defaultTTL) + + // NamedHandler for fetching token + svc.Handlers.Sign.PushBackNamed(request.NamedHandler{ + Name: fetchTokenHandlerName, + Fn: tp.fetchTokenHandler, + }) + // NamedHandler for enabling token provider + svc.Handlers.Complete.PushBackNamed(request.NamedHandler{ + Name: enableTokenProviderHandlerName, + Fn: tp.enableTokenProviderHandler, + }) + + svc.Handlers.Unmarshal.PushBackNamed(unmarshalHandler) svc.Handlers.UnmarshalError.PushBack(unmarshalError) svc.Handlers.Validate.Clear() svc.Handlers.Validate.PushBack(validateEndpointHandler) // Disable the EC2 Metadata service if the environment variable is set. - // This shortcirctes the service's functionality to always fail to send + // This short-circuits the service's functionality to always fail to send // requests. if strings.ToLower(os.Getenv(disableServiceEnvVar)) == "true" { svc.Handlers.Send.SwapNamed(request.NamedHandler{ @@ -107,7 +138,6 @@ func NewClient(cfg aws.Config, handlers request.Handlers, endpoint, signingRegio for _, option := range opts { option(svc.Client) } - return svc } @@ -119,30 +149,74 @@ type metadataOutput struct { Content string } -func unmarshalHandler(r *request.Request) { - defer r.HTTPResponse.Body.Close() - b := &bytes.Buffer{} - if _, err := io.Copy(b, r.HTTPResponse.Body); err != nil { - r.Error = awserr.New(request.ErrCodeSerialization, "unable to unmarshal EC2 metadata response", err) - return - } +type tokenOutput struct { + Token string + TTL time.Duration +} - if data, ok := r.Data.(*metadataOutput); ok { - data.Content = b.String() - } +// unmarshal token handler is used to parse the response of a getToken operation +var unmarshalTokenHandler = request.NamedHandler{ + Name: unmarshalTokenHandlerName, + Fn: func(r *request.Request) { + defer r.HTTPResponse.Body.Close() + var b bytes.Buffer + if _, err := io.Copy(&b, r.HTTPResponse.Body); err != nil { + r.Error = awserr.NewRequestFailure(awserr.New(request.ErrCodeSerialization, + "unable to unmarshal EC2 metadata response", err), r.HTTPResponse.StatusCode, r.RequestID) + return + } + + v := r.HTTPResponse.Header.Get(ttlHeader) + data, ok := r.Data.(*tokenOutput) + if !ok { + return + } + + data.Token = b.String() + // TTL is in seconds + i, err := strconv.ParseInt(v, 10, 64) + if err != nil { + r.Error = awserr.NewRequestFailure(awserr.New(request.ParamFormatErrCode, + "unable to parse EC2 token TTL response", err), r.HTTPResponse.StatusCode, r.RequestID) + return + } + t := time.Duration(i) * time.Second + data.TTL = t + }, +} + +var unmarshalHandler = request.NamedHandler{ + Name: unmarshalMetadataHandlerName, + Fn: func(r *request.Request) { + defer r.HTTPResponse.Body.Close() + var b bytes.Buffer + if _, err := io.Copy(&b, r.HTTPResponse.Body); err != nil { + r.Error = awserr.NewRequestFailure(awserr.New(request.ErrCodeSerialization, + "unable to unmarshal EC2 metadata response", err), r.HTTPResponse.StatusCode, r.RequestID) + return + } + + if data, ok := r.Data.(*metadataOutput); ok { + data.Content = b.String() + } + }, } func unmarshalError(r *request.Request) { defer r.HTTPResponse.Body.Close() - b := &bytes.Buffer{} - if _, err := io.Copy(b, r.HTTPResponse.Body); err != nil { - r.Error = awserr.New(request.ErrCodeSerialization, "unable to unmarshal EC2 metadata error response", err) + var b bytes.Buffer + + if _, err := io.Copy(&b, r.HTTPResponse.Body); err != nil { + r.Error = awserr.NewRequestFailure( + awserr.New(request.ErrCodeSerialization, "unable to unmarshal EC2 metadata error response", err), + r.HTTPResponse.StatusCode, r.RequestID) return } // Response body format is not consistent between metadata endpoints. // Grab the error message as a string and include that as the source error - r.Error = awserr.New("EC2MetadataError", "failed to make EC2Metadata request", errors.New(b.String())) + r.Error = awserr.NewRequestFailure(awserr.New("EC2MetadataError", "failed to make EC2Metadata request", errors.New(b.String())), + r.HTTPResponse.StatusCode, r.RequestID) } func validateEndpointHandler(r *request.Request) { diff --git a/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/token_provider.go b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/token_provider.go new file mode 100644 index 0000000000..06f76055f3 --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/aws/ec2metadata/token_provider.go @@ -0,0 +1,92 @@ +package ec2metadata + +import ( + "net/http" + "sync/atomic" + "time" + + "github.com/aws/aws-sdk-go/aws/awserr" + "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/request" +) + +// A tokenProvider struct provides access to EC2Metadata client +// and atomic instance of a token, along with configuredTTL for it. +// tokenProvider also provides an atomic flag to disable the +// fetch token operation. +// The disabled member will use 0 as false, and 1 as true. +type tokenProvider struct { + client *EC2Metadata + token atomic.Value + configuredTTL time.Duration + disabled uint32 +} + +// A ec2Token struct helps use of token in EC2 Metadata service ops +type ec2Token struct { + token string + credentials.Expiry +} + +// newTokenProvider provides a pointer to a tokenProvider instance +func newTokenProvider(c *EC2Metadata, duration time.Duration) *tokenProvider { + return &tokenProvider{client: c, configuredTTL: duration} +} + +// fetchTokenHandler fetches token for EC2Metadata service client by default. +func (t *tokenProvider) fetchTokenHandler(r *request.Request) { + + // short-circuits to insecure data flow if tokenProvider is disabled. + if v := atomic.LoadUint32(&t.disabled); v == 1 { + return + } + + if ec2Token, ok := t.token.Load().(ec2Token); ok && !ec2Token.IsExpired() { + r.HTTPRequest.Header.Set(tokenHeader, ec2Token.token) + return + } + + output, err := t.client.getToken(t.configuredTTL) + + if err != nil { + + // change the disabled flag on token provider to true, + // when error is request timeout error. + if requestFailureError, ok := err.(awserr.RequestFailure); ok { + switch requestFailureError.StatusCode() { + case http.StatusForbidden, http.StatusNotFound, http.StatusMethodNotAllowed: + atomic.StoreUint32(&t.disabled, 1) + case http.StatusBadRequest: + r.Error = requestFailureError + } + + // Check if request timed out while waiting for response + if e, ok := requestFailureError.OrigErr().(awserr.Error); ok { + if e.Code() == "RequestError" { + atomic.StoreUint32(&t.disabled, 1) + } + } + } + return + } + + newToken := ec2Token{ + token: output.Token, + } + newToken.SetExpiration(time.Now().Add(output.TTL), ttlExpirationWindow) + t.token.Store(newToken) + + // Inject token header to the request. + if ec2Token, ok := t.token.Load().(ec2Token); ok { + r.HTTPRequest.Header.Set(tokenHeader, ec2Token.token) + } +} + +// enableTokenProviderHandler enables the token provider +func (t *tokenProvider) enableTokenProviderHandler(r *request.Request) { + // If the error code status is 401, we enable the token provider + if e, ok := r.Error.(awserr.RequestFailure); ok && e != nil && + e.StatusCode() == http.StatusUnauthorized { + atomic.StoreUint32(&t.disabled, 0) + } +} diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/decode.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/decode.go index 87b9ff3ffe..343a2106f8 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/decode.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/decode.go @@ -83,6 +83,7 @@ func decodeV3Endpoints(modelDef modelDefinition, opts DecodeModelOptions) (Resol p := &ps[i] custAddEC2Metadata(p) custAddS3DualStack(p) + custRegionalS3(p) custRmIotDataService(p) custFixAppAutoscalingChina(p) custFixAppAutoscalingUsGov(p) @@ -100,6 +101,33 @@ func custAddS3DualStack(p *partition) { custAddDualstack(p, "s3-control") } +func custRegionalS3(p *partition) { + if p.ID != "aws" { + return + } + + service, ok := p.Services["s3"] + if !ok { + return + } + + // If global endpoint already exists no customization needed. + if _, ok := service.Endpoints["aws-global"]; ok { + return + } + + service.PartitionEndpoint = "aws-global" + service.Endpoints["us-east-1"] = endpoint{} + service.Endpoints["aws-global"] = endpoint{ + Hostname: "s3.amazonaws.com", + CredentialScope: credentialScope{ + Region: "us-east-1", + }, + } + + p.Services["s3"] = service +} + func custAddDualstack(p *partition, svcName string) { s, ok := p.Services[svcName] if !ok { diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go index f63449788a..0f77e9caea 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/defaults.go @@ -425,11 +425,7 @@ var awsPartition = partition{ }, "application-autoscaling": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", Protocols: []string{"http", "https"}, - CredentialScope: credentialScope{ - Service: "application-autoscaling", - }, }, Endpoints: endpoints{ "ap-east-1": endpoint{}, @@ -560,11 +556,7 @@ var awsPartition = partition{ }, "autoscaling-plans": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", Protocols: []string{"http", "https"}, - CredentialScope: credentialScope{ - Service: "autoscaling-plans", - }, }, Endpoints: endpoints{ "ap-northeast-1": endpoint{}, @@ -1104,6 +1096,22 @@ var awsPartition = partition{ "us-west-2": endpoint{}, }, }, + "dataexchange": service{ + + Endpoints: endpoints{ + "ap-northeast-1": endpoint{}, + "ap-northeast-2": endpoint{}, + "ap-southeast-1": endpoint{}, + "ap-southeast-2": endpoint{}, + "eu-central-1": endpoint{}, + "eu-west-1": endpoint{}, + "eu-west-2": endpoint{}, + "us-east-1": endpoint{}, + "us-east-2": endpoint{}, + "us-west-1": endpoint{}, + "us-west-2": endpoint{}, + }, + }, "datapipeline": service{ Endpoints: endpoints{ @@ -1117,12 +1125,15 @@ var awsPartition = partition{ "datasync": service{ Endpoints: endpoints{ + "ap-east-1": endpoint{}, "ap-northeast-1": endpoint{}, "ap-northeast-2": endpoint{}, + "ap-south-1": endpoint{}, "ap-southeast-1": endpoint{}, "ap-southeast-2": endpoint{}, "ca-central-1": endpoint{}, "eu-central-1": endpoint{}, + "eu-north-1": endpoint{}, "eu-west-1": endpoint{}, "eu-west-2": endpoint{}, "eu-west-3": endpoint{}, @@ -1151,6 +1162,7 @@ var awsPartition = partition{ }, }, "me-south-1": endpoint{}, + "sa-east-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, "us-west-1": endpoint{}, @@ -1166,6 +1178,8 @@ var awsPartition = partition{ "ap-southeast-2": endpoint{}, "eu-central-1": endpoint{}, "eu-west-1": endpoint{}, + "eu-west-2": endpoint{}, + "eu-west-3": endpoint{}, "sa-east-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, @@ -1205,7 +1219,8 @@ var awsPartition = partition{ "discovery": service{ Endpoints: endpoints{ - "us-west-2": endpoint{}, + "eu-central-1": endpoint{}, + "us-west-2": endpoint{}, }, }, "dms": service{ @@ -1505,6 +1520,7 @@ var awsPartition = partition{ "elasticfilesystem": service{ Endpoints: endpoints{ + "ap-east-1": endpoint{}, "ap-northeast-1": endpoint{}, "ap-northeast-2": endpoint{}, "ap-south-1": endpoint{}, @@ -1512,9 +1528,12 @@ var awsPartition = partition{ "ap-southeast-2": endpoint{}, "ca-central-1": endpoint{}, "eu-central-1": endpoint{}, + "eu-north-1": endpoint{}, "eu-west-1": endpoint{}, "eu-west-2": endpoint{}, "eu-west-3": endpoint{}, + "me-south-1": endpoint{}, + "sa-east-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, "us-west-1": endpoint{}, @@ -1692,11 +1711,16 @@ var awsPartition = partition{ Endpoints: endpoints{ "ap-northeast-1": endpoint{}, "ap-northeast-2": endpoint{}, + "ap-south-1": endpoint{}, "ap-southeast-1": endpoint{}, "ap-southeast-2": endpoint{}, + "ca-central-1": endpoint{}, "eu-central-1": endpoint{}, + "eu-north-1": endpoint{}, "eu-west-1": endpoint{}, "eu-west-2": endpoint{}, + "eu-west-3": endpoint{}, + "sa-east-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, "us-west-1": endpoint{}, @@ -2169,12 +2193,17 @@ var awsPartition = partition{ Endpoints: endpoints{ "ap-northeast-1": endpoint{}, + "ap-northeast-2": endpoint{}, "ap-south-1": endpoint{}, "ap-southeast-1": endpoint{}, "ap-southeast-2": endpoint{}, + "ca-central-1": endpoint{}, + "eu-central-1": endpoint{}, "eu-west-1": endpoint{}, + "eu-west-2": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, + "us-west-1": endpoint{}, "us-west-2": endpoint{}, }, }, @@ -2398,7 +2427,8 @@ var awsPartition = partition{ "mgh": service{ Endpoints: endpoints{ - "us-west-2": endpoint{}, + "eu-central-1": endpoint{}, + "us-west-2": endpoint{}, }, }, "mobileanalytics": service{ @@ -2803,6 +2833,10 @@ var awsPartition = partition{ Endpoints: endpoints{ "ap-northeast-1": endpoint{}, + "ap-northeast-2": endpoint{}, + "ap-southeast-1": endpoint{}, + "ap-southeast-2": endpoint{}, + "eu-central-1": endpoint{}, "eu-west-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, @@ -3053,7 +3087,7 @@ var awsPartition = partition{ }, }, "s3": service{ - PartitionEndpoint: "us-east-1", + PartitionEndpoint: "aws-global", IsRegionalized: boxedTrue, Defaults: endpoint{ Protocols: []string{"http", "https"}, @@ -3078,6 +3112,12 @@ var awsPartition = partition{ Hostname: "s3.ap-southeast-2.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, + "aws-global": endpoint{ + Hostname: "s3.amazonaws.com", + CredentialScope: credentialScope{ + Region: "us-east-1", + }, + }, "ca-central-1": endpoint{}, "eu-central-1": endpoint{}, "eu-north-1": endpoint{}, @@ -3099,10 +3139,7 @@ var awsPartition = partition{ Hostname: "s3.sa-east-1.amazonaws.com", SignatureVersions: []string{"s3", "s3v4"}, }, - "us-east-1": endpoint{ - Hostname: "s3.amazonaws.com", - SignatureVersions: []string{"s3", "s3v4"}, - }, + "us-east-1": endpoint{}, "us-east-2": endpoint{}, "us-west-1": endpoint{ Hostname: "s3.us-west-1.amazonaws.com", @@ -3499,6 +3536,10 @@ var awsPartition = partition{ Endpoints: endpoints{ "ap-northeast-1": endpoint{}, + "ap-northeast-2": endpoint{}, + "ap-southeast-1": endpoint{}, + "ap-southeast-2": endpoint{}, + "eu-central-1": endpoint{}, "eu-west-1": endpoint{}, "us-east-1": endpoint{}, "us-east-2": endpoint{}, @@ -4122,11 +4163,7 @@ var awscnPartition = partition{ }, "application-autoscaling": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com.cn", Protocols: []string{"http", "https"}, - CredentialScope: credentialScope{ - Service: "application-autoscaling", - }, }, Endpoints: endpoints{ "cn-north-1": endpoint{}, @@ -4204,6 +4241,12 @@ var awscnPartition = partition{ "cn-northwest-1": endpoint{}, }, }, + "dax": service{ + + Endpoints: endpoints{ + "cn-northwest-1": endpoint{}, + }, + }, "directconnect": service{ Endpoints: endpoints{ @@ -4591,6 +4634,12 @@ var awscnPartition = partition{ }, }, }, + "workspaces": service{ + + Endpoints: endpoints{ + "cn-northwest-1": endpoint{}, + }, + }, }, } @@ -4671,7 +4720,8 @@ var awsusgovPartition = partition{ }, "application-autoscaling": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", + Hostname: "autoscaling.{region}.amazonaws.com", + Protocols: []string{"http", "https"}, CredentialScope: credentialScope{ Service: "application-autoscaling", }, @@ -4808,6 +4858,7 @@ var awsusgovPartition = partition{ Region: "us-gov-west-1", }, }, + "us-gov-east-1": endpoint{}, "us-gov-west-1": endpoint{}, }, }, @@ -5476,11 +5527,8 @@ var awsisoPartition = partition{ }, "application-autoscaling": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", + Hostname: "autoscaling.us-iso-east-1.c2s.ic.gov", Protocols: []string{"http", "https"}, - CredentialScope: credentialScope{ - Service: "application-autoscaling", - }, }, Endpoints: endpoints{ "us-iso-east-1": endpoint{}, @@ -5808,11 +5856,8 @@ var awsisobPartition = partition{ Services: services{ "application-autoscaling": service{ Defaults: endpoint{ - Hostname: "autoscaling.{region}.amazonaws.com", + Hostname: "autoscaling.us-isob-east-1.sc2s.sgov.gov", Protocols: []string{"http", "https"}, - CredentialScope: credentialScope{ - Service: "application-autoscaling", - }, }, Endpoints: endpoints{ "us-isob-east-1": endpoint{}, diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/endpoints.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/endpoints.go index fadff07d64..1f53d9cb68 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/endpoints.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/endpoints.go @@ -50,12 +50,28 @@ type Options struct { // STS Regional Endpoint flag helps with resolving the STS endpoint STSRegionalEndpoint STSRegionalEndpoint + + // S3 Regional Endpoint flag helps with resolving the S3 endpoint + S3UsEast1RegionalEndpoint S3UsEast1RegionalEndpoint } -// STSRegionalEndpoint is an enum type alias for int -// It is used internally by the core sdk as STS Regional Endpoint flag value +// STSRegionalEndpoint is an enum for the states of the STS Regional Endpoint +// options. type STSRegionalEndpoint int +func (e STSRegionalEndpoint) String() string { + switch e { + case LegacySTSEndpoint: + return "legacy" + case RegionalSTSEndpoint: + return "regional" + case UnsetSTSEndpoint: + return "" + default: + return "unknown" + } +} + const ( // UnsetSTSEndpoint represents that STS Regional Endpoint flag is not specified. @@ -86,6 +102,55 @@ func GetSTSRegionalEndpoint(s string) (STSRegionalEndpoint, error) { } } +// S3UsEast1RegionalEndpoint is an enum for the states of the S3 us-east-1 +// Regional Endpoint options. +type S3UsEast1RegionalEndpoint int + +func (e S3UsEast1RegionalEndpoint) String() string { + switch e { + case LegacyS3UsEast1Endpoint: + return "legacy" + case RegionalS3UsEast1Endpoint: + return "regional" + case UnsetS3UsEast1Endpoint: + return "" + default: + return "unknown" + } +} + +const ( + + // UnsetS3UsEast1Endpoint represents that S3 Regional Endpoint flag is not + // specified. + UnsetS3UsEast1Endpoint S3UsEast1RegionalEndpoint = iota + + // LegacyS3UsEast1Endpoint represents when S3 Regional Endpoint flag is + // specified to use legacy endpoints. + LegacyS3UsEast1Endpoint + + // RegionalS3UsEast1Endpoint represents when S3 Regional Endpoint flag is + // specified to use regional endpoints. + RegionalS3UsEast1Endpoint +) + +// GetS3UsEast1RegionalEndpoint function returns the S3UsEast1RegionalEndpointFlag based +// on the input string provided in env config or shared config by the user. +// +// `legacy`, `regional` are the only case-insensitive valid strings for +// resolving the S3 regional Endpoint flag. +func GetS3UsEast1RegionalEndpoint(s string) (S3UsEast1RegionalEndpoint, error) { + switch { + case strings.EqualFold(s, "legacy"): + return LegacyS3UsEast1Endpoint, nil + case strings.EqualFold(s, "regional"): + return RegionalS3UsEast1Endpoint, nil + default: + return UnsetS3UsEast1Endpoint, + fmt.Errorf("unable to resolve the value of S3UsEast1RegionalEndpoint for %v", s) + } +} + // Set combines all of the option functions together. func (o *Options) Set(optFns ...func(*Options)) { for _, fn := range optFns { diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/legacy_regions.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/legacy_regions.go new file mode 100644 index 0000000000..df75e899ad --- /dev/null +++ b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/legacy_regions.go @@ -0,0 +1,24 @@ +package endpoints + +var legacyGlobalRegions = map[string]map[string]struct{}{ + "sts": { + "ap-northeast-1": {}, + "ap-south-1": {}, + "ap-southeast-1": {}, + "ap-southeast-2": {}, + "ca-central-1": {}, + "eu-central-1": {}, + "eu-north-1": {}, + "eu-west-1": {}, + "eu-west-2": {}, + "eu-west-3": {}, + "sa-east-1": {}, + "us-east-1": {}, + "us-east-2": {}, + "us-west-1": {}, + "us-west-2": {}, + }, + "s3": { + "us-east-1": {}, + }, +} diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/sts_legacy_regions.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/sts_legacy_regions.go deleted file mode 100644 index 2613962197..0000000000 --- a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/sts_legacy_regions.go +++ /dev/null @@ -1,19 +0,0 @@ -package endpoints - -var stsLegacyGlobalRegions = map[string]struct{}{ - "ap-northeast-1": {}, - "ap-south-1": {}, - "ap-southeast-1": {}, - "ap-southeast-2": {}, - "ca-central-1": {}, - "eu-central-1": {}, - "eu-north-1": {}, - "eu-west-1": {}, - "eu-west-2": {}, - "eu-west-3": {}, - "sa-east-1": {}, - "us-east-1": {}, - "us-east-2": {}, - "us-west-1": {}, - "us-west-2": {}, -} diff --git a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/v3model.go b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/v3model.go index 7b09adff63..eb2ac83c99 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/endpoints/v3model.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/endpoints/v3model.go @@ -110,8 +110,9 @@ func (p partition) EndpointFor(service, region string, opts ...func(*Options)) ( region = s.PartitionEndpoint } - if service == "sts" && opt.STSRegionalEndpoint != RegionalSTSEndpoint { - if _, ok := stsLegacyGlobalRegions[region]; ok { + if (service == "sts" && opt.STSRegionalEndpoint != RegionalSTSEndpoint) || + (service == "s3" && opt.S3UsEast1RegionalEndpoint != RegionalS3UsEast1Endpoint) { + if _, ok := legacyGlobalRegions[service][region]; ok { region = "aws-global" } } @@ -240,20 +241,6 @@ func (e endpoint) resolve(service, partitionID, region, dnsSuffix string, defs [ merged.mergeIn(e) e = merged - hostname := e.Hostname - - // Offset the hostname for dualstack if enabled - if opts.UseDualStack && e.HasDualStack == boxedTrue { - hostname = e.DualStackHostname - } - - u := strings.Replace(hostname, "{service}", service, 1) - u = strings.Replace(u, "{region}", region, 1) - u = strings.Replace(u, "{dnsSuffix}", dnsSuffix, 1) - - scheme := getEndpointScheme(e.Protocols, opts.DisableSSL) - u = fmt.Sprintf("%s://%s", scheme, u) - signingRegion := e.CredentialScope.Region if len(signingRegion) == 0 { signingRegion = region @@ -266,6 +253,20 @@ func (e endpoint) resolve(service, partitionID, region, dnsSuffix string, defs [ signingNameDerived = true } + hostname := e.Hostname + // Offset the hostname for dualstack if enabled + if opts.UseDualStack && e.HasDualStack == boxedTrue { + hostname = e.DualStackHostname + region = signingRegion + } + + u := strings.Replace(hostname, "{service}", service, 1) + u = strings.Replace(u, "{region}", region, 1) + u = strings.Replace(u, "{dnsSuffix}", dnsSuffix, 1) + + scheme := getEndpointScheme(e.Protocols, opts.DisableSSL) + u = fmt.Sprintf("%s://%s", scheme, u) + return ResolvedEndpoint{ URL: u, PartitionID: partitionID, diff --git a/vendor/github.com/aws/aws-sdk-go/aws/request/request_pagination.go b/vendor/github.com/aws/aws-sdk-go/aws/request/request_pagination.go index f093fc542d..64784e16f3 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/request/request_pagination.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/request/request_pagination.go @@ -17,11 +17,13 @@ import ( // does the pagination between API operations, and Paginator defines the // configuration that will be used per page request. // -// cont := true -// for p.Next() && cont { +// for p.Next() { // data := p.Page().(*s3.ListObjectsOutput) // // process the page's data +// // ... +// // break out of loop to stop fetching additional pages // } +// // return p.Err() // // See service client API operation Pages methods for examples how the SDK will diff --git a/vendor/github.com/aws/aws-sdk-go/aws/session/credentials.go b/vendor/github.com/aws/aws-sdk-go/aws/session/credentials.go index 7713ccfca5..cc64e24f1d 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/session/credentials.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/session/credentials.go @@ -47,10 +47,10 @@ func resolveCredentials(cfg *aws.Config, } // WebIdentityEmptyRoleARNErr will occur if 'AWS_WEB_IDENTITY_TOKEN_FILE' was set but -// 'AWS_IAM_ROLE_ARN' was not set. +// 'AWS_ROLE_ARN' was not set. var WebIdentityEmptyRoleARNErr = awserr.New(stscreds.ErrCodeWebIdentity, "role ARN is not set", nil) -// WebIdentityEmptyTokenFilePathErr will occur if 'AWS_IAM_ROLE_ARN' was set but +// WebIdentityEmptyTokenFilePathErr will occur if 'AWS_ROLE_ARN' was set but // 'AWS_WEB_IDENTITY_TOKEN_FILE' was not set. var WebIdentityEmptyTokenFilePathErr = awserr.New(stscreds.ErrCodeWebIdentity, "token file path is not set", nil) diff --git a/vendor/github.com/aws/aws-sdk-go/aws/session/env_config.go b/vendor/github.com/aws/aws-sdk-go/aws/session/env_config.go index 530cc3a9c0..4092ab8fb7 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/session/env_config.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/session/env_config.go @@ -128,11 +128,19 @@ type envConfig struct { // AWS_ROLE_SESSION_NAME=session_name RoleSessionName string - // Specifies the Regional Endpoint flag for the sdk to resolve the endpoint for a service + // Specifies the STS Regional Endpoint flag for the SDK to resolve the endpoint + // for a service. // - // AWS_STS_REGIONAL_ENDPOINTS =sts_regional_endpoint + // AWS_STS_REGIONAL_ENDPOINTS=regional // This can take value as `regional` or `legacy` STSRegionalEndpoint endpoints.STSRegionalEndpoint + + // Specifies the S3 Regional Endpoint flag for the SDK to resolve the + // endpoint for a service. + // + // AWS_S3_US_EAST_1_REGIONAL_ENDPOINT=regional + // This can take value as `regional` or `legacy` + S3UsEast1RegionalEndpoint endpoints.S3UsEast1RegionalEndpoint } var ( @@ -190,6 +198,9 @@ var ( stsRegionalEndpointKey = []string{ "AWS_STS_REGIONAL_ENDPOINTS", } + s3UsEast1RegionalEndpoint = []string{ + "AWS_S3_US_EAST_1_REGIONAL_ENDPOINT", + } ) // loadEnvConfig retrieves the SDK's environment configuration. @@ -275,14 +286,24 @@ func envConfigLoad(enableSharedConfig bool) (envConfig, error) { cfg.CustomCABundle = os.Getenv("AWS_CA_BUNDLE") + var err error // STS Regional Endpoint variable for _, k := range stsRegionalEndpointKey { if v := os.Getenv(k); len(v) != 0 { - STSRegionalEndpoint, err := endpoints.GetSTSRegionalEndpoint(v) + cfg.STSRegionalEndpoint, err = endpoints.GetSTSRegionalEndpoint(v) + if err != nil { + return cfg, fmt.Errorf("failed to load, %v from env config, %v", k, err) + } + } + } + + // S3 Regional Endpoint variable + for _, k := range s3UsEast1RegionalEndpoint { + if v := os.Getenv(k); len(v) != 0 { + cfg.S3UsEast1RegionalEndpoint, err = endpoints.GetS3UsEast1RegionalEndpoint(v) if err != nil { return cfg, fmt.Errorf("failed to load, %v from env config, %v", k, err) } - cfg.STSRegionalEndpoint = STSRegionalEndpoint } } diff --git a/vendor/github.com/aws/aws-sdk-go/aws/session/session.go b/vendor/github.com/aws/aws-sdk-go/aws/session/session.go index 15fa647699..ab6daac7c3 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/session/session.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/session/session.go @@ -555,7 +555,20 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config, } // Regional Endpoint flag for STS endpoint resolving - mergeSTSRegionalEndpointConfig(cfg, envCfg, sharedCfg) + mergeSTSRegionalEndpointConfig(cfg, []endpoints.STSRegionalEndpoint{ + userCfg.STSRegionalEndpoint, + envCfg.STSRegionalEndpoint, + sharedCfg.STSRegionalEndpoint, + endpoints.LegacySTSEndpoint, + }) + + // Regional Endpoint flag for S3 endpoint resolving + mergeS3UsEast1RegionalEndpointConfig(cfg, []endpoints.S3UsEast1RegionalEndpoint{ + userCfg.S3UsEast1RegionalEndpoint, + envCfg.S3UsEast1RegionalEndpoint, + sharedCfg.S3UsEast1RegionalEndpoint, + endpoints.LegacyS3UsEast1Endpoint, + }) // Configure credentials if not already set by the user when creating the // Session. @@ -570,20 +583,22 @@ func mergeConfigSrcs(cfg, userCfg *aws.Config, return nil } -// mergeSTSRegionalEndpointConfig function merges the STSRegionalEndpoint into cfg from -// envConfig and SharedConfig with envConfig being given precedence over SharedConfig -func mergeSTSRegionalEndpointConfig(cfg *aws.Config, envCfg envConfig, sharedCfg sharedConfig) error { - - cfg.STSRegionalEndpoint = envCfg.STSRegionalEndpoint - - if cfg.STSRegionalEndpoint == endpoints.UnsetSTSEndpoint { - cfg.STSRegionalEndpoint = sharedCfg.STSRegionalEndpoint +func mergeSTSRegionalEndpointConfig(cfg *aws.Config, values []endpoints.STSRegionalEndpoint) { + for _, v := range values { + if v != endpoints.UnsetSTSEndpoint { + cfg.STSRegionalEndpoint = v + break + } } +} - if cfg.STSRegionalEndpoint == endpoints.UnsetSTSEndpoint { - cfg.STSRegionalEndpoint = endpoints.LegacySTSEndpoint +func mergeS3UsEast1RegionalEndpointConfig(cfg *aws.Config, values []endpoints.S3UsEast1RegionalEndpoint) { + for _, v := range values { + if v != endpoints.UnsetS3UsEast1Endpoint { + cfg.S3UsEast1RegionalEndpoint = v + break + } } - return nil } func initHandlers(s *Session) { @@ -653,6 +668,11 @@ func (s *Session) resolveEndpoint(service, region string, cfg *aws.Config) (endp // precedence. opt.STSRegionalEndpoint = cfg.STSRegionalEndpoint + // Support for S3UsEast1RegionalEndpoint where the S3UsEast1RegionalEndpoint is + // provided in envConfig or sharedConfig with envConfig getting + // precedence. + opt.S3UsEast1RegionalEndpoint = cfg.S3UsEast1RegionalEndpoint + // Support the condition where the service is modeled but its // endpoint metadata is not available. opt.ResolveUnknownService = true diff --git a/vendor/github.com/aws/aws-sdk-go/aws/session/shared_config.go b/vendor/github.com/aws/aws-sdk-go/aws/session/shared_config.go index 8574668960..1d7b049cf7 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/session/shared_config.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/session/shared_config.go @@ -44,6 +44,9 @@ const ( // Additional config fields for regional or legacy endpoints stsRegionalEndpointSharedKey = `sts_regional_endpoints` + // Additional config fields for regional or legacy endpoints + s3UsEast1RegionalSharedKey = `s3_us_east_1_regional_endpoint` + // DefaultSharedConfigProfile is the default profile to be used when // loading configuration from the config files if another profile name // is not provided. @@ -92,11 +95,17 @@ type sharedConfig struct { CSMPort string CSMClientID string - // Specifies the Regional Endpoint flag for the sdk to resolve the endpoint for a service + // Specifies the Regional Endpoint flag for the SDK to resolve the endpoint for a service // - // sts_regional_endpoints = sts_regional_endpoint + // sts_regional_endpoints = regional // This can take value as `LegacySTSEndpoint` or `RegionalSTSEndpoint` STSRegionalEndpoint endpoints.STSRegionalEndpoint + + // Specifies the Regional Endpoint flag for the SDK to resolve the endpoint for a service + // + // s3_us_east_1_regional_endpoint = regional + // This can take value as `LegacyS3UsEast1Endpoint` or `RegionalS3UsEast1Endpoint` + S3UsEast1RegionalEndpoint endpoints.S3UsEast1RegionalEndpoint } type sharedConfigFile struct { @@ -259,10 +268,19 @@ func (cfg *sharedConfig) setFromIniFile(profile string, file sharedConfigFile, e sre, err := endpoints.GetSTSRegionalEndpoint(v) if err != nil { return fmt.Errorf("failed to load %s from shared config, %s, %v", - stsRegionalEndpointKey, file.Filename, err) + stsRegionalEndpointSharedKey, file.Filename, err) } cfg.STSRegionalEndpoint = sre } + + if v := section.String(s3UsEast1RegionalSharedKey); len(v) != 0 { + sre, err := endpoints.GetS3UsEast1RegionalEndpoint(v) + if err != nil { + return fmt.Errorf("failed to load %s from shared config, %s, %v", + s3UsEast1RegionalSharedKey, file.Filename, err) + } + cfg.S3UsEast1RegionalEndpoint = sre + } } updateString(&cfg.CredentialProcess, section, credentialProcessKey) diff --git a/vendor/github.com/aws/aws-sdk-go/aws/version.go b/vendor/github.com/aws/aws-sdk-go/aws/version.go index 52bd1d2423..f094e263e1 100644 --- a/vendor/github.com/aws/aws-sdk-go/aws/version.go +++ b/vendor/github.com/aws/aws-sdk-go/aws/version.go @@ -5,4 +5,4 @@ package aws const SDKName = "aws-sdk-go" // SDKVersion is the version of this SDK -const SDKVersion = "1.25.32" +const SDKVersion = "1.25.41" diff --git a/vendor/github.com/aws/aws-sdk-go/service/acmpca/api.go b/vendor/github.com/aws/aws-sdk-go/service/acmpca/api.go index b9f53ae7a2..c600b04c0a 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/acmpca/api.go +++ b/vendor/github.com/aws/aws-sdk-go/service/acmpca/api.go @@ -1378,10 +1378,12 @@ func (c *ACMPCA) ListCertificateAuthoritiesPagesWithContext(ctx aws.Context, inp }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*ListCertificateAuthoritiesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*ListCertificateAuthoritiesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -1530,10 +1532,12 @@ func (c *ACMPCA) ListPermissionsPagesWithContext(ctx aws.Context, input *ListPer }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*ListPermissionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*ListPermissionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -1677,10 +1681,12 @@ func (c *ACMPCA) ListTagsPagesWithContext(ctx aws.Context, input *ListTagsInput, }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*ListTagsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*ListTagsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } diff --git a/vendor/github.com/aws/aws-sdk-go/service/acmpca/service.go b/vendor/github.com/aws/aws-sdk-go/service/acmpca/service.go index c041442ae4..c06a46be46 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/acmpca/service.go +++ b/vendor/github.com/aws/aws-sdk-go/service/acmpca/service.go @@ -39,6 +39,8 @@ const ( // aws.Config parameter to add your extra config. // // Example: +// mySession := session.Must(session.NewSession()) +// // // Create a ACMPCA client from just a session. // svc := acmpca.New(mySession) // diff --git a/vendor/github.com/aws/aws-sdk-go/service/ec2/api.go b/vendor/github.com/aws/aws-sdk-go/service/ec2/api.go index 17131a9bd3..cf3ccc7568 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/ec2/api.go +++ b/vendor/github.com/aws/aws-sdk-go/service/ec2/api.go @@ -551,8 +551,9 @@ func (c *EC2) AllocateHostsRequest(input *AllocateHostsInput) (req *request.Requ // AllocateHosts API operation for Amazon Elastic Compute Cloud. // -// Allocates a Dedicated Host to your account. At a minimum, specify the instance -// size type, Availability Zone, and quantity of hosts to allocate. +// Allocates a Dedicated Host to your account. At a minimum, specify the supported +// instance type or instance family, the Availability Zone in which to allocate +// the host, and the number of hosts to allocate. // // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about @@ -3493,11 +3494,10 @@ func (c *EC2) CreateCustomerGatewayRequest(input *CreateCustomerGatewayInput) (r // For more information, see AWS Site-to-Site VPN (https://docs.aws.amazon.com/vpn/latest/s2svpn/VPC_VPN.html) // in the AWS Site-to-Site VPN User Guide. // -// You cannot create more than one customer gateway with the same VPN type, -// IP address, and BGP ASN parameter values. If you run an identical request -// more than one time, the first request creates the customer gateway, and subsequent -// requests return information about the existing customer gateway. The subsequent -// requests do not create new customer gateway resources. +// To create more than one customer gateway with the same VPN type, IP address, +// and BGP ASN, specify a unique device name for each customer gateway. Identical +// requests return information about the existing customer gateway and do not +// create new customer gateways. // // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about @@ -11346,10 +11346,12 @@ func (c *EC2) DescribeByoipCidrsPagesWithContext(ctx aws.Context, input *Describ }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeByoipCidrsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeByoipCidrsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -11477,10 +11479,12 @@ func (c *EC2) DescribeCapacityReservationsPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeCapacityReservationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeCapacityReservationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -11610,10 +11614,12 @@ func (c *EC2) DescribeClassicLinkInstancesPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClassicLinkInstancesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClassicLinkInstancesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -11740,10 +11746,12 @@ func (c *EC2) DescribeClientVpnAuthorizationRulesPagesWithContext(ctx aws.Contex }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClientVpnAuthorizationRulesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClientVpnAuthorizationRulesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -11871,10 +11879,12 @@ func (c *EC2) DescribeClientVpnConnectionsPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClientVpnConnectionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClientVpnConnectionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12001,10 +12011,12 @@ func (c *EC2) DescribeClientVpnEndpointsPagesWithContext(ctx aws.Context, input }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClientVpnEndpointsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClientVpnEndpointsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12131,10 +12143,12 @@ func (c *EC2) DescribeClientVpnRoutesPagesWithContext(ctx aws.Context, input *De }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClientVpnRoutesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClientVpnRoutesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12261,10 +12275,12 @@ func (c *EC2) DescribeClientVpnTargetNetworksPagesWithContext(ctx aws.Context, i }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeClientVpnTargetNetworksOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeClientVpnTargetNetworksOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12549,10 +12565,12 @@ func (c *EC2) DescribeDhcpOptionsPagesWithContext(ctx aws.Context, input *Descri }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeDhcpOptionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeDhcpOptionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12679,10 +12697,12 @@ func (c *EC2) DescribeEgressOnlyInternetGatewaysPagesWithContext(ctx aws.Context }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeEgressOnlyInternetGatewaysOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeEgressOnlyInternetGatewaysOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -12793,6 +12813,12 @@ func (c *EC2) DescribeExportImageTasksRequest(input *DescribeExportImageTasksInp Name: opDescribeExportImageTasks, HTTPMethod: "POST", HTTPPath: "/", + Paginator: &request.Paginator{ + InputTokens: []string{"NextToken"}, + OutputTokens: []string{"NextToken"}, + LimitToken: "MaxResults", + TruncationToken: "", + }, } if input == nil { @@ -12836,6 +12862,58 @@ func (c *EC2) DescribeExportImageTasksWithContext(ctx aws.Context, input *Descri return out, req.Send() } +// DescribeExportImageTasksPages iterates over the pages of a DescribeExportImageTasks operation, +// calling the "fn" function with the response data for each page. To stop +// iterating, return false from the fn function. +// +// See DescribeExportImageTasks method for more information on how to use this operation. +// +// Note: This operation can generate multiple requests to a service. +// +// // Example iterating over at most 3 pages of a DescribeExportImageTasks operation. +// pageNum := 0 +// err := client.DescribeExportImageTasksPages(params, +// func(page *ec2.DescribeExportImageTasksOutput, lastPage bool) bool { +// pageNum++ +// fmt.Println(page) +// return pageNum <= 3 +// }) +// +func (c *EC2) DescribeExportImageTasksPages(input *DescribeExportImageTasksInput, fn func(*DescribeExportImageTasksOutput, bool) bool) error { + return c.DescribeExportImageTasksPagesWithContext(aws.BackgroundContext(), input, fn) +} + +// DescribeExportImageTasksPagesWithContext same as DescribeExportImageTasksPages except +// it takes a Context and allows setting request options on the pages. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DescribeExportImageTasksPagesWithContext(ctx aws.Context, input *DescribeExportImageTasksInput, fn func(*DescribeExportImageTasksOutput, bool) bool, opts ...request.Option) error { + p := request.Pagination{ + NewRequest: func() (*request.Request, error) { + var inCpy *DescribeExportImageTasksInput + if input != nil { + tmp := *input + inCpy = &tmp + } + req, _ := c.DescribeExportImageTasksRequest(inCpy) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return req, nil + }, + } + + for p.Next() { + if !fn(p.Page().(*DescribeExportImageTasksOutput), !p.HasNextPage()) { + break + } + } + + return p.Err() +} + const opDescribeExportTasks = "DescribeExportTasks" // DescribeExportTasksRequest generates a "aws/request.Request" representing the @@ -12911,6 +12989,138 @@ func (c *EC2) DescribeExportTasksWithContext(ctx aws.Context, input *DescribeExp return out, req.Send() } +const opDescribeFastSnapshotRestores = "DescribeFastSnapshotRestores" + +// DescribeFastSnapshotRestoresRequest generates a "aws/request.Request" representing the +// client's request for the DescribeFastSnapshotRestores operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See DescribeFastSnapshotRestores for more information on using the DescribeFastSnapshotRestores +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the DescribeFastSnapshotRestoresRequest method. +// req, resp := client.DescribeFastSnapshotRestoresRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeFastSnapshotRestores +func (c *EC2) DescribeFastSnapshotRestoresRequest(input *DescribeFastSnapshotRestoresInput) (req *request.Request, output *DescribeFastSnapshotRestoresOutput) { + op := &request.Operation{ + Name: opDescribeFastSnapshotRestores, + HTTPMethod: "POST", + HTTPPath: "/", + Paginator: &request.Paginator{ + InputTokens: []string{"NextToken"}, + OutputTokens: []string{"NextToken"}, + LimitToken: "MaxResults", + TruncationToken: "", + }, + } + + if input == nil { + input = &DescribeFastSnapshotRestoresInput{} + } + + output = &DescribeFastSnapshotRestoresOutput{} + req = c.newRequest(op, input, output) + return +} + +// DescribeFastSnapshotRestores API operation for Amazon Elastic Compute Cloud. +// +// Describes the state of fast snapshot restores for your snapshots. +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation DescribeFastSnapshotRestores for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeFastSnapshotRestores +func (c *EC2) DescribeFastSnapshotRestores(input *DescribeFastSnapshotRestoresInput) (*DescribeFastSnapshotRestoresOutput, error) { + req, out := c.DescribeFastSnapshotRestoresRequest(input) + return out, req.Send() +} + +// DescribeFastSnapshotRestoresWithContext is the same as DescribeFastSnapshotRestores with the addition of +// the ability to pass a context and additional request options. +// +// See DescribeFastSnapshotRestores for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DescribeFastSnapshotRestoresWithContext(ctx aws.Context, input *DescribeFastSnapshotRestoresInput, opts ...request.Option) (*DescribeFastSnapshotRestoresOutput, error) { + req, out := c.DescribeFastSnapshotRestoresRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + +// DescribeFastSnapshotRestoresPages iterates over the pages of a DescribeFastSnapshotRestores operation, +// calling the "fn" function with the response data for each page. To stop +// iterating, return false from the fn function. +// +// See DescribeFastSnapshotRestores method for more information on how to use this operation. +// +// Note: This operation can generate multiple requests to a service. +// +// // Example iterating over at most 3 pages of a DescribeFastSnapshotRestores operation. +// pageNum := 0 +// err := client.DescribeFastSnapshotRestoresPages(params, +// func(page *ec2.DescribeFastSnapshotRestoresOutput, lastPage bool) bool { +// pageNum++ +// fmt.Println(page) +// return pageNum <= 3 +// }) +// +func (c *EC2) DescribeFastSnapshotRestoresPages(input *DescribeFastSnapshotRestoresInput, fn func(*DescribeFastSnapshotRestoresOutput, bool) bool) error { + return c.DescribeFastSnapshotRestoresPagesWithContext(aws.BackgroundContext(), input, fn) +} + +// DescribeFastSnapshotRestoresPagesWithContext same as DescribeFastSnapshotRestoresPages except +// it takes a Context and allows setting request options on the pages. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DescribeFastSnapshotRestoresPagesWithContext(ctx aws.Context, input *DescribeFastSnapshotRestoresInput, fn func(*DescribeFastSnapshotRestoresOutput, bool) bool, opts ...request.Option) error { + p := request.Pagination{ + NewRequest: func() (*request.Request, error) { + var inCpy *DescribeFastSnapshotRestoresInput + if input != nil { + tmp := *input + inCpy = &tmp + } + req, _ := c.DescribeFastSnapshotRestoresRequest(inCpy) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return req, nil + }, + } + + for p.Next() { + if !fn(p.Page().(*DescribeFastSnapshotRestoresOutput), !p.HasNextPage()) { + break + } + } + + return p.Err() +} + const opDescribeFleetHistory = "DescribeFleetHistory" // DescribeFleetHistoryRequest generates a "aws/request.Request" representing the @@ -12957,6 +13167,10 @@ func (c *EC2) DescribeFleetHistoryRequest(input *DescribeFleetHistoryInput) (req // // Describes the events for the specified EC2 Fleet during the specified time. // +// EC2 Fleet events are delayed by up to 30 seconds before they can be described. +// This ensures that you can query by the last evaluated time and not miss a +// recorded event. EC2 Fleet events are available for 48 hours. +// // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about // the error. @@ -13182,10 +13396,12 @@ func (c *EC2) DescribeFleetsPagesWithContext(ctx aws.Context, input *DescribeFle }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeFleetsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeFleetsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -13314,10 +13530,12 @@ func (c *EC2) DescribeFlowLogsPagesWithContext(ctx aws.Context, input *DescribeF }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeFlowLogsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeFlowLogsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -13520,10 +13738,12 @@ func (c *EC2) DescribeFpgaImagesPagesWithContext(ctx aws.Context, input *Describ }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeFpgaImagesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeFpgaImagesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -13579,8 +13799,8 @@ func (c *EC2) DescribeHostReservationOfferingsRequest(input *DescribeHostReserva // // Describes the Dedicated Host reservations that are available to purchase. // -// The results describe all the Dedicated Host reservation offerings, including -// offerings that may not match the instance family and Region of your Dedicated +// The results describe all of the Dedicated Host reservation offerings, including +// offerings that might not match the instance family and Region of your Dedicated // Hosts. When purchasing an offering, ensure that the instance family and Region // of the offering matches that of the Dedicated Hosts with which it is to be // associated. For more information about supported instance types, see Dedicated @@ -13658,10 +13878,12 @@ func (c *EC2) DescribeHostReservationOfferingsPagesWithContext(ctx aws.Context, }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeHostReservationOfferingsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeHostReservationOfferingsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -13788,10 +14010,12 @@ func (c *EC2) DescribeHostReservationsPagesWithContext(ctx aws.Context, input *D }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeHostReservationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeHostReservationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -13922,10 +14146,12 @@ func (c *EC2) DescribeHostsPagesWithContext(ctx aws.Context, input *DescribeHost }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeHostsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeHostsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -14052,10 +14278,12 @@ func (c *EC2) DescribeIamInstanceProfileAssociationsPagesWithContext(ctx aws.Con }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeIamInstanceProfileAssociationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeIamInstanceProfileAssociationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -14524,10 +14752,12 @@ func (c *EC2) DescribeImportImageTasksPagesWithContext(ctx aws.Context, input *D }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeImportImageTasksOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeImportImageTasksOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -14654,10 +14884,12 @@ func (c *EC2) DescribeImportSnapshotTasksPagesWithContext(ctx aws.Context, input }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeImportSnapshotTasksOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeImportSnapshotTasksOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -14885,10 +15117,12 @@ func (c *EC2) DescribeInstanceCreditSpecificationsPagesWithContext(ctx aws.Conte }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeInstanceCreditSpecificationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeInstanceCreditSpecificationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15036,13 +15270,166 @@ func (c *EC2) DescribeInstanceStatusPagesWithContext(ctx aws.Context, input *Des }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeInstanceStatusOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeInstanceStatusOutput), !p.HasNextPage()) { + break + } } + return p.Err() } +const opDescribeInstanceTypeOfferings = "DescribeInstanceTypeOfferings" + +// DescribeInstanceTypeOfferingsRequest generates a "aws/request.Request" representing the +// client's request for the DescribeInstanceTypeOfferings operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See DescribeInstanceTypeOfferings for more information on using the DescribeInstanceTypeOfferings +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the DescribeInstanceTypeOfferingsRequest method. +// req, resp := client.DescribeInstanceTypeOfferingsRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeInstanceTypeOfferings +func (c *EC2) DescribeInstanceTypeOfferingsRequest(input *DescribeInstanceTypeOfferingsInput) (req *request.Request, output *DescribeInstanceTypeOfferingsOutput) { + op := &request.Operation{ + Name: opDescribeInstanceTypeOfferings, + HTTPMethod: "POST", + HTTPPath: "/", + } + + if input == nil { + input = &DescribeInstanceTypeOfferingsInput{} + } + + output = &DescribeInstanceTypeOfferingsOutput{} + req = c.newRequest(op, input, output) + return +} + +// DescribeInstanceTypeOfferings API operation for Amazon Elastic Compute Cloud. +// +// Returns a list of all instance types offered. The results can be filtered +// by location (Region or Availability Zone). If no location is specified, the +// instance types offered in the current Region are returned. +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation DescribeInstanceTypeOfferings for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeInstanceTypeOfferings +func (c *EC2) DescribeInstanceTypeOfferings(input *DescribeInstanceTypeOfferingsInput) (*DescribeInstanceTypeOfferingsOutput, error) { + req, out := c.DescribeInstanceTypeOfferingsRequest(input) + return out, req.Send() +} + +// DescribeInstanceTypeOfferingsWithContext is the same as DescribeInstanceTypeOfferings with the addition of +// the ability to pass a context and additional request options. +// +// See DescribeInstanceTypeOfferings for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DescribeInstanceTypeOfferingsWithContext(ctx aws.Context, input *DescribeInstanceTypeOfferingsInput, opts ...request.Option) (*DescribeInstanceTypeOfferingsOutput, error) { + req, out := c.DescribeInstanceTypeOfferingsRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + +const opDescribeInstanceTypes = "DescribeInstanceTypes" + +// DescribeInstanceTypesRequest generates a "aws/request.Request" representing the +// client's request for the DescribeInstanceTypes operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See DescribeInstanceTypes for more information on using the DescribeInstanceTypes +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the DescribeInstanceTypesRequest method. +// req, resp := client.DescribeInstanceTypesRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeInstanceTypes +func (c *EC2) DescribeInstanceTypesRequest(input *DescribeInstanceTypesInput) (req *request.Request, output *DescribeInstanceTypesOutput) { + op := &request.Operation{ + Name: opDescribeInstanceTypes, + HTTPMethod: "POST", + HTTPPath: "/", + } + + if input == nil { + input = &DescribeInstanceTypesInput{} + } + + output = &DescribeInstanceTypesOutput{} + req = c.newRequest(op, input, output) + return +} + +// DescribeInstanceTypes API operation for Amazon Elastic Compute Cloud. +// +// Returns a list of all instance types offered in your current AWS Region. +// The results can be filtered by the attributes of the instance types. +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation DescribeInstanceTypes for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DescribeInstanceTypes +func (c *EC2) DescribeInstanceTypes(input *DescribeInstanceTypesInput) (*DescribeInstanceTypesOutput, error) { + req, out := c.DescribeInstanceTypesRequest(input) + return out, req.Send() +} + +// DescribeInstanceTypesWithContext is the same as DescribeInstanceTypes with the addition of +// the ability to pass a context and additional request options. +// +// See DescribeInstanceTypes for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DescribeInstanceTypesWithContext(ctx aws.Context, input *DescribeInstanceTypesInput, opts ...request.Option) (*DescribeInstanceTypesOutput, error) { + req, out := c.DescribeInstanceTypesRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + const opDescribeInstances = "DescribeInstances" // DescribeInstancesRequest generates a "aws/request.Request" representing the @@ -15181,10 +15568,12 @@ func (c *EC2) DescribeInstancesPagesWithContext(ctx aws.Context, input *Describe }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeInstancesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeInstancesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15311,10 +15700,12 @@ func (c *EC2) DescribeInternetGatewaysPagesWithContext(ctx aws.Context, input *D }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeInternetGatewaysOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeInternetGatewaysOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15519,10 +15910,12 @@ func (c *EC2) DescribeLaunchTemplateVersionsPagesWithContext(ctx aws.Context, in }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeLaunchTemplateVersionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeLaunchTemplateVersionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15649,10 +16042,12 @@ func (c *EC2) DescribeLaunchTemplatesPagesWithContext(ctx aws.Context, input *De }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeLaunchTemplatesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeLaunchTemplatesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15781,10 +16176,12 @@ func (c *EC2) DescribeMovingAddressesPagesWithContext(ctx aws.Context, input *De }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeMovingAddressesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeMovingAddressesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -15911,10 +16308,12 @@ func (c *EC2) DescribeNatGatewaysPagesWithContext(ctx aws.Context, input *Descri }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeNatGatewaysOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeNatGatewaysOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16044,10 +16443,12 @@ func (c *EC2) DescribeNetworkAclsPagesWithContext(ctx aws.Context, input *Descri }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeNetworkAclsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeNetworkAclsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16249,10 +16650,12 @@ func (c *EC2) DescribeNetworkInterfacePermissionsPagesWithContext(ctx aws.Contex }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeNetworkInterfacePermissionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeNetworkInterfacePermissionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16379,10 +16782,12 @@ func (c *EC2) DescribeNetworkInterfacesPagesWithContext(ctx aws.Context, input * }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeNetworkInterfacesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeNetworkInterfacesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16590,10 +16995,12 @@ func (c *EC2) DescribePrefixListsPagesWithContext(ctx aws.Context, input *Descri }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribePrefixListsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribePrefixListsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16734,10 +17141,12 @@ func (c *EC2) DescribePrincipalIdFormatPagesWithContext(ctx aws.Context, input * }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribePrincipalIdFormatOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribePrincipalIdFormatOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -16864,10 +17273,12 @@ func (c *EC2) DescribePublicIpv4PoolsPagesWithContext(ctx aws.Context, input *De }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribePublicIpv4PoolsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribePublicIpv4PoolsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -17253,10 +17664,12 @@ func (c *EC2) DescribeReservedInstancesModificationsPagesWithContext(ctx aws.Con }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeReservedInstancesModificationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeReservedInstancesModificationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -17394,10 +17807,12 @@ func (c *EC2) DescribeReservedInstancesOfferingsPagesWithContext(ctx aws.Context }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeReservedInstancesOfferingsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeReservedInstancesOfferingsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -17532,10 +17947,12 @@ func (c *EC2) DescribeRouteTablesPagesWithContext(ctx aws.Context, input *Descri }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeRouteTablesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeRouteTablesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -17670,10 +18087,12 @@ func (c *EC2) DescribeScheduledInstanceAvailabilityPagesWithContext(ctx aws.Cont }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeScheduledInstanceAvailabilityOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeScheduledInstanceAvailabilityOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -17800,10 +18219,12 @@ func (c *EC2) DescribeScheduledInstancesPagesWithContext(ctx aws.Context, input }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeScheduledInstancesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeScheduledInstancesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -18012,10 +18433,12 @@ func (c *EC2) DescribeSecurityGroupsPagesWithContext(ctx aws.Context, input *Des }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSecurityGroupsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSecurityGroupsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -18267,10 +18690,12 @@ func (c *EC2) DescribeSnapshotsPagesWithContext(ctx aws.Context, input *Describe }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSnapshotsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSnapshotsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -18629,10 +19054,12 @@ func (c *EC2) DescribeSpotFleetRequestsPagesWithContext(ctx aws.Context, input * }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSpotFleetRequestsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSpotFleetRequestsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -18775,10 +19202,12 @@ func (c *EC2) DescribeSpotInstanceRequestsPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSpotInstanceRequestsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSpotInstanceRequestsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -18912,10 +19341,12 @@ func (c *EC2) DescribeSpotPriceHistoryPagesWithContext(ctx aws.Context, input *D }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSpotPriceHistoryOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSpotPriceHistoryOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19045,10 +19476,12 @@ func (c *EC2) DescribeStaleSecurityGroupsPagesWithContext(ctx aws.Context, input }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeStaleSecurityGroupsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeStaleSecurityGroupsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19178,10 +19611,12 @@ func (c *EC2) DescribeSubnetsPagesWithContext(ctx aws.Context, input *DescribeSu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeSubnetsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeSubnetsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19311,10 +19746,12 @@ func (c *EC2) DescribeTagsPagesWithContext(ctx aws.Context, input *DescribeTagsI }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTagsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTagsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19441,10 +19878,12 @@ func (c *EC2) DescribeTrafficMirrorFiltersPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTrafficMirrorFiltersOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTrafficMirrorFiltersOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19572,10 +20011,12 @@ func (c *EC2) DescribeTrafficMirrorSessionsPagesWithContext(ctx aws.Context, inp }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTrafficMirrorSessionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTrafficMirrorSessionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19702,10 +20143,12 @@ func (c *EC2) DescribeTrafficMirrorTargetsPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTrafficMirrorTargetsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTrafficMirrorTargetsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19835,10 +20278,12 @@ func (c *EC2) DescribeTransitGatewayAttachmentsPagesWithContext(ctx aws.Context, }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTransitGatewayAttachmentsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTransitGatewayAttachmentsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -19966,10 +20411,12 @@ func (c *EC2) DescribeTransitGatewayRouteTablesPagesWithContext(ctx aws.Context, }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTransitGatewayRouteTablesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTransitGatewayRouteTablesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -20097,10 +20544,12 @@ func (c *EC2) DescribeTransitGatewayVpcAttachmentsPagesWithContext(ctx aws.Conte }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTransitGatewayVpcAttachmentsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTransitGatewayVpcAttachmentsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -20228,10 +20677,12 @@ func (c *EC2) DescribeTransitGatewaysPagesWithContext(ctx aws.Context, input *De }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeTransitGatewaysOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeTransitGatewaysOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -20471,10 +20922,12 @@ func (c *EC2) DescribeVolumeStatusPagesWithContext(ctx aws.Context, input *Descr }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVolumeStatusOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVolumeStatusOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -20611,10 +21064,12 @@ func (c *EC2) DescribeVolumesPagesWithContext(ctx aws.Context, input *DescribeVo }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVolumesOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVolumesOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -20754,10 +21209,12 @@ func (c *EC2) DescribeVolumesModificationsPagesWithContext(ctx aws.Context, inpu }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVolumesModificationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVolumesModificationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21039,10 +21496,12 @@ func (c *EC2) DescribeVpcClassicLinkDnsSupportPagesWithContext(ctx aws.Context, }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcClassicLinkDnsSupportOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcClassicLinkDnsSupportOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21170,10 +21629,12 @@ func (c *EC2) DescribeVpcEndpointConnectionNotificationsPagesWithContext(ctx aws }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcEndpointConnectionNotificationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcEndpointConnectionNotificationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21301,10 +21762,12 @@ func (c *EC2) DescribeVpcEndpointConnectionsPagesWithContext(ctx aws.Context, in }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcEndpointConnectionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcEndpointConnectionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21431,10 +21894,12 @@ func (c *EC2) DescribeVpcEndpointServiceConfigurationsPagesWithContext(ctx aws.C }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcEndpointServiceConfigurationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcEndpointServiceConfigurationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21562,10 +22027,12 @@ func (c *EC2) DescribeVpcEndpointServicePermissionsPagesWithContext(ctx aws.Cont }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcEndpointServicePermissionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcEndpointServicePermissionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21766,10 +22233,12 @@ func (c *EC2) DescribeVpcEndpointsPagesWithContext(ctx aws.Context, input *Descr }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcEndpointsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcEndpointsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -21896,10 +22365,12 @@ func (c *EC2) DescribeVpcPeeringConnectionsPagesWithContext(ctx aws.Context, inp }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcPeeringConnectionsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcPeeringConnectionsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -22026,10 +22497,12 @@ func (c *EC2) DescribeVpcsPagesWithContext(ctx aws.Context, input *DescribeVpcsI }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*DescribeVpcsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*DescribeVpcsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -22667,6 +23140,81 @@ func (c *EC2) DisableEbsEncryptionByDefaultWithContext(ctx aws.Context, input *D return out, req.Send() } +const opDisableFastSnapshotRestores = "DisableFastSnapshotRestores" + +// DisableFastSnapshotRestoresRequest generates a "aws/request.Request" representing the +// client's request for the DisableFastSnapshotRestores operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See DisableFastSnapshotRestores for more information on using the DisableFastSnapshotRestores +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the DisableFastSnapshotRestoresRequest method. +// req, resp := client.DisableFastSnapshotRestoresRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DisableFastSnapshotRestores +func (c *EC2) DisableFastSnapshotRestoresRequest(input *DisableFastSnapshotRestoresInput) (req *request.Request, output *DisableFastSnapshotRestoresOutput) { + op := &request.Operation{ + Name: opDisableFastSnapshotRestores, + HTTPMethod: "POST", + HTTPPath: "/", + } + + if input == nil { + input = &DisableFastSnapshotRestoresInput{} + } + + output = &DisableFastSnapshotRestoresOutput{} + req = c.newRequest(op, input, output) + return +} + +// DisableFastSnapshotRestores API operation for Amazon Elastic Compute Cloud. +// +// Disables fast snapshot restores for the specified snapshots in the specified +// Availability Zones. +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation DisableFastSnapshotRestores for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/DisableFastSnapshotRestores +func (c *EC2) DisableFastSnapshotRestores(input *DisableFastSnapshotRestoresInput) (*DisableFastSnapshotRestoresOutput, error) { + req, out := c.DisableFastSnapshotRestoresRequest(input) + return out, req.Send() +} + +// DisableFastSnapshotRestoresWithContext is the same as DisableFastSnapshotRestores with the addition of +// the ability to pass a context and additional request options. +// +// See DisableFastSnapshotRestores for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) DisableFastSnapshotRestoresWithContext(ctx aws.Context, input *DisableFastSnapshotRestoresInput, opts ...request.Option) (*DisableFastSnapshotRestoresOutput, error) { + req, out := c.DisableFastSnapshotRestoresRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + const opDisableTransitGatewayRouteTablePropagation = "DisableTransitGatewayRouteTablePropagation" // DisableTransitGatewayRouteTablePropagationRequest generates a "aws/request.Request" representing the @@ -23614,6 +24162,85 @@ func (c *EC2) EnableEbsEncryptionByDefaultWithContext(ctx aws.Context, input *En return out, req.Send() } +const opEnableFastSnapshotRestores = "EnableFastSnapshotRestores" + +// EnableFastSnapshotRestoresRequest generates a "aws/request.Request" representing the +// client's request for the EnableFastSnapshotRestores operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See EnableFastSnapshotRestores for more information on using the EnableFastSnapshotRestores +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the EnableFastSnapshotRestoresRequest method. +// req, resp := client.EnableFastSnapshotRestoresRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/EnableFastSnapshotRestores +func (c *EC2) EnableFastSnapshotRestoresRequest(input *EnableFastSnapshotRestoresInput) (req *request.Request, output *EnableFastSnapshotRestoresOutput) { + op := &request.Operation{ + Name: opEnableFastSnapshotRestores, + HTTPMethod: "POST", + HTTPPath: "/", + } + + if input == nil { + input = &EnableFastSnapshotRestoresInput{} + } + + output = &EnableFastSnapshotRestoresOutput{} + req = c.newRequest(op, input, output) + return +} + +// EnableFastSnapshotRestores API operation for Amazon Elastic Compute Cloud. +// +// Enables fast snapshot restores for the specified snapshots in the specified +// Availability Zones. +// +// You get the full benefit of fast snapshot restores after they enter the enabled +// state. To get the current state of fast snapshot restores, use DescribeFastSnapshotRestores. +// To disable fast snapshot restores, use DisableFastSnapshotRestores. +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation EnableFastSnapshotRestores for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/EnableFastSnapshotRestores +func (c *EC2) EnableFastSnapshotRestores(input *EnableFastSnapshotRestoresInput) (*EnableFastSnapshotRestoresOutput, error) { + req, out := c.EnableFastSnapshotRestoresRequest(input) + return out, req.Send() +} + +// EnableFastSnapshotRestoresWithContext is the same as EnableFastSnapshotRestores with the addition of +// the ability to pass a context and additional request options. +// +// See EnableFastSnapshotRestores for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) EnableFastSnapshotRestoresWithContext(ctx aws.Context, input *EnableFastSnapshotRestoresInput, opts ...request.Option) (*EnableFastSnapshotRestoresOutput, error) { + req, out := c.EnableFastSnapshotRestoresRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + const opEnableTransitGatewayRouteTablePropagation = "EnableTransitGatewayRouteTablePropagation" // EnableTransitGatewayRouteTablePropagationRequest generates a "aws/request.Request" representing the @@ -25152,10 +25779,12 @@ func (c *EC2) GetTransitGatewayAttachmentPropagationsPagesWithContext(ctx aws.Co }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*GetTransitGatewayAttachmentPropagationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*GetTransitGatewayAttachmentPropagationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -25283,10 +25912,12 @@ func (c *EC2) GetTransitGatewayRouteTableAssociationsPagesWithContext(ctx aws.Co }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*GetTransitGatewayRouteTableAssociationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*GetTransitGatewayRouteTableAssociationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -25414,10 +26045,12 @@ func (c *EC2) GetTransitGatewayRouteTablePropagationsPagesWithContext(ctx aws.Co }, } - cont := true - for p.Next() && cont { - cont = fn(p.Page().(*GetTransitGatewayRouteTablePropagationsOutput), !p.HasNextPage()) + for p.Next() { + if !fn(p.Page().(*GetTransitGatewayRouteTablePropagationsOutput), !p.HasNextPage()) { + break + } } + return p.Err() } @@ -26360,6 +26993,10 @@ func (c *EC2) ModifyHostsRequest(input *ModifyHostsInput) (req *request.Request, // no host ID is provided, the instance is launched onto a suitable host with // auto-placement enabled. // +// You can also use this API action to modify a Dedicated Host to support either +// multiple instance types in an instance family, or to support a specific instance +// type only. +// // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about // the error. @@ -26981,6 +27618,86 @@ func (c *EC2) ModifyInstanceEventStartTimeWithContext(ctx aws.Context, input *Mo return out, req.Send() } +const opModifyInstanceMetadataOptions = "ModifyInstanceMetadataOptions" + +// ModifyInstanceMetadataOptionsRequest generates a "aws/request.Request" representing the +// client's request for the ModifyInstanceMetadataOptions operation. The "output" return +// value will be populated with the request's response once the request completes +// successfully. +// +// Use "Send" method on the returned Request to send the API call to the service. +// the "output" return value is not valid until after Send returns without error. +// +// See ModifyInstanceMetadataOptions for more information on using the ModifyInstanceMetadataOptions +// API call, and error handling. +// +// This method is useful when you want to inject custom logic or configuration +// into the SDK's request lifecycle. Such as custom headers, or retry logic. +// +// +// // Example sending a request using the ModifyInstanceMetadataOptionsRequest method. +// req, resp := client.ModifyInstanceMetadataOptionsRequest(params) +// +// err := req.Send() +// if err == nil { // resp is now filled +// fmt.Println(resp) +// } +// +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/ModifyInstanceMetadataOptions +func (c *EC2) ModifyInstanceMetadataOptionsRequest(input *ModifyInstanceMetadataOptionsInput) (req *request.Request, output *ModifyInstanceMetadataOptionsOutput) { + op := &request.Operation{ + Name: opModifyInstanceMetadataOptions, + HTTPMethod: "POST", + HTTPPath: "/", + } + + if input == nil { + input = &ModifyInstanceMetadataOptionsInput{} + } + + output = &ModifyInstanceMetadataOptionsOutput{} + req = c.newRequest(op, input, output) + return +} + +// ModifyInstanceMetadataOptions API operation for Amazon Elastic Compute Cloud. +// +// Modify the instance metadata parameters on a running or stopped instance. +// When you modify the parameters on a stopped instance, they are applied when +// the instance is started. When you modify the parameters on a running instance, +// the API responds with a state of “pending”. After the parameter modifications +// are successfully applied to the instance, the state of the modifications +// changes from “pending” to “applied” in subsequent describe-instances +// API calls. For more information, see Instance Metadata and User Data (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html). +// +// Returns awserr.Error for service API and SDK errors. Use runtime type assertions +// with awserr.Error's Code and Message methods to get detailed information about +// the error. +// +// See the AWS API reference guide for Amazon Elastic Compute Cloud's +// API operation ModifyInstanceMetadataOptions for usage and error information. +// See also, https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/ModifyInstanceMetadataOptions +func (c *EC2) ModifyInstanceMetadataOptions(input *ModifyInstanceMetadataOptionsInput) (*ModifyInstanceMetadataOptionsOutput, error) { + req, out := c.ModifyInstanceMetadataOptionsRequest(input) + return out, req.Send() +} + +// ModifyInstanceMetadataOptionsWithContext is the same as ModifyInstanceMetadataOptions with the addition of +// the ability to pass a context and additional request options. +// +// See ModifyInstanceMetadataOptions for details on how to use this API operation. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) ModifyInstanceMetadataOptionsWithContext(ctx aws.Context, input *ModifyInstanceMetadataOptionsInput, opts ...request.Option) (*ModifyInstanceMetadataOptionsOutput, error) { + req, out := c.ModifyInstanceMetadataOptionsRequest(input) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return out, req.Send() +} + const opModifyInstancePlacement = "ModifyInstancePlacement" // ModifyInstancePlacementRequest generates a "aws/request.Request" representing the @@ -33504,12 +34221,23 @@ type AllocateHostsInput struct { // Default: off HostRecovery *string `type:"string" enum:"HostRecovery"` - // Specifies the instance type for which to configure your Dedicated Hosts. - // When you specify the instance type, that is the only instance type that you - // can launch onto that host. + // Specifies the instance family to be supported by the Dedicated Hosts. If + // you specify an instance family, the Dedicated Hosts support multiple instance + // types within that instance family. // - // InstanceType is a required field - InstanceType *string `locationName:"instanceType" type:"string" required:"true"` + // If you want the Dedicated Hosts to support a specific instance type only, + // omit this parameter and specify InstanceType instead. You cannot specify + // InstanceFamily and InstanceType in the same request. + InstanceFamily *string `type:"string"` + + // Specifies the instance type to be supported by the Dedicated Hosts. If you + // specify an instance type, the Dedicated Hosts support instances of the specified + // instance type only. + // + // If you want the Dedicated Hosts to support multiple instance types in a specific + // instance family, omit this parameter and specify InstanceFamily instead. + // You cannot specify InstanceType and InstanceFamily in the same request. + InstanceType *string `locationName:"instanceType" type:"string"` // The number of Dedicated Hosts to allocate to your account with these parameters. // @@ -33536,9 +34264,6 @@ func (s *AllocateHostsInput) Validate() error { if s.AvailabilityZone == nil { invalidParams.Add(request.NewErrParamRequired("AvailabilityZone")) } - if s.InstanceType == nil { - invalidParams.Add(request.NewErrParamRequired("InstanceType")) - } if s.Quantity == nil { invalidParams.Add(request.NewErrParamRequired("Quantity")) } @@ -33573,6 +34298,12 @@ func (s *AllocateHostsInput) SetHostRecovery(v string) *AllocateHostsInput { return s } +// SetInstanceFamily sets the InstanceFamily field's value. +func (s *AllocateHostsInput) SetInstanceFamily(v string) *AllocateHostsInput { + s.InstanceFamily = &v + return s +} + // SetInstanceType sets the InstanceType field's value. func (s *AllocateHostsInput) SetInstanceType(v string) *AllocateHostsInput { s.InstanceType = &v @@ -35058,7 +35789,6 @@ func (s *AttachNetworkInterfaceOutput) SetAttachmentId(v string) *AttachNetworkI return s } -// Contains the parameters for AttachVolume. type AttachVolumeInput struct { _ struct{} `type:"structure"` @@ -35845,14 +36575,19 @@ func (s *AvailabilityZoneMessage) SetMessage(v string) *AvailabilityZoneMessage return s } -// The capacity information for instances launched onto the Dedicated Host. +// The capacity information for instances that can be launched onto the Dedicated +// Host. type AvailableCapacity struct { _ struct{} `type:"structure"` - // The total number of instances supported by the Dedicated Host. + // The number of instances that can be launched onto the Dedicated Host depending + // on the host's available capacity. For Dedicated Hosts that support multiple + // instance types, this parameter represents the number of instances for each + // instance size that is supported on the host. AvailableInstanceCapacity []*InstanceCapacity `locationName:"availableInstanceCapacity" locationNameList:"item" type:"list"` - // The number of vCPUs available on the Dedicated Host. + // The number of vCPUs available for launching instances onto the Dedicated + // Host. AvailableVCpus *int64 `locationName:"availableVCpus" type:"integer"` } @@ -38958,7 +39693,6 @@ func (s *CopyImageOutput) SetImageId(v string) *CopyImageOutput { return s } -// Contains the parameters for CopySnapshot. type CopySnapshotInput struct { _ struct{} `type:"structure"` @@ -39033,6 +39767,9 @@ type CopySnapshotInput struct { // // SourceSnapshotId is a required field SourceSnapshotId *string `type:"string" required:"true"` + + // The tags to apply to the new snapshot. + TagSpecifications []*TagSpecification `locationName:"TagSpecification" locationNameList:"item" type:"list"` } // String returns the string representation @@ -39109,12 +39846,20 @@ func (s *CopySnapshotInput) SetSourceSnapshotId(v string) *CopySnapshotInput { return s } -// Contains the output of CopySnapshot. +// SetTagSpecifications sets the TagSpecifications field's value. +func (s *CopySnapshotInput) SetTagSpecifications(v []*TagSpecification) *CopySnapshotInput { + s.TagSpecifications = v + return s +} + type CopySnapshotOutput struct { _ struct{} `type:"structure"` // The ID of the new snapshot. SnapshotId *string `locationName:"snapshotId" type:"string"` + + // Any tags applied to the new snapshot. + Tags []*Tag `locationName:"tagSet" locationNameList:"item" type:"list"` } // String returns the string representation @@ -39133,6 +39878,12 @@ func (s *CopySnapshotOutput) SetSnapshotId(v string) *CopySnapshotOutput { return s } +// SetTags sets the Tags field's value. +func (s *CopySnapshotOutput) SetTags(v []*Tag) *CopySnapshotOutput { + s.Tags = v + return s +} + // The CPU options for the instance. type CpuOptions struct { _ struct{} `type:"structure"` @@ -39800,6 +40551,11 @@ type CreateCustomerGatewayInput struct { // The Amazon Resource Name (ARN) for the customer gateway certificate. CertificateArn *string `type:"string"` + // A name for the customer gateway device. + // + // Length Constraints: Up to 255 characters. + DeviceName *string `type:"string"` + // Checks whether you have the required permissions for the action, without // actually making the request, and provides an error response. If you have // the required permissions, the error response is DryRunOperation. Otherwise, @@ -39854,6 +40610,12 @@ func (s *CreateCustomerGatewayInput) SetCertificateArn(v string) *CreateCustomer return s } +// SetDeviceName sets the DeviceName field's value. +func (s *CreateCustomerGatewayInput) SetDeviceName(v string) *CreateCustomerGatewayInput { + s.DeviceName = &v + return s +} + // SetDryRun sets the DryRun field's value. func (s *CreateCustomerGatewayInput) SetDryRun(v bool) *CreateCustomerGatewayInput { s.DryRun = &v @@ -42627,7 +43389,6 @@ func (s *CreateSecurityGroupOutput) SetGroupId(v string) *CreateSecurityGroupOut return s } -// Contains the parameters for CreateSnapshot. type CreateSnapshotInput struct { _ struct{} `type:"structure"` @@ -42705,9 +43466,10 @@ type CreateSnapshotsInput struct { // A description propagated to every snapshot specified by the instance. Description *string `type:"string"` - // Checks whether you have the required permissions for the action without actually - // making the request. Provides an error response. If you have the required - // permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation. + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. DryRun *bool `type:"boolean"` // The instance to specify which volumes should be included in the snapshots. @@ -44081,7 +44843,6 @@ func (s *CreateTransitGatewayVpcAttachmentRequestOptions) SetIpv6Support(v strin return s } -// Contains the parameters for CreateVolume. type CreateVolumeInput struct { _ struct{} `type:"structure"` @@ -45275,6 +46036,9 @@ type CustomerGateway struct { // The ID of the customer gateway. CustomerGatewayId *string `locationName:"customerGatewayId" type:"string"` + // The name of customer gateway device. + DeviceName *string `locationName:"deviceName" type:"string"` + // The Internet-routable IP address of the customer gateway's outside interface. IpAddress *string `locationName:"ipAddress" type:"string"` @@ -45317,6 +46081,12 @@ func (s *CustomerGateway) SetCustomerGatewayId(v string) *CustomerGateway { return s } +// SetDeviceName sets the DeviceName field's value. +func (s *CustomerGateway) SetDeviceName(v string) *CustomerGateway { + s.DeviceName = &v + return s +} + // SetIpAddress sets the IpAddress field's value. func (s *CustomerGateway) SetIpAddress(v string) *CustomerGateway { s.IpAddress = &v @@ -47230,7 +48000,6 @@ func (s DeleteSecurityGroupOutput) GoString() string { return s.String() } -// Contains the parameters for DeleteSnapshot. type DeleteSnapshotInput struct { _ struct{} `type:"structure"` @@ -48081,7 +48850,6 @@ func (s *DeleteTransitGatewayVpcAttachmentOutput) SetTransitGatewayVpcAttachment return s } -// Contains the parameters for DeleteVolume. type DeleteVolumeInput struct { _ struct{} `type:"structure"` @@ -50831,6 +51599,222 @@ func (s *DescribeExportTasksOutput) SetExportTasks(v []*ExportTask) *DescribeExp return s } +// Describes fast snapshot restores for a snapshot. +type DescribeFastSnapshotRestoreSuccessItem struct { + _ struct{} `type:"structure"` + + // The Availability Zone. + AvailabilityZone *string `locationName:"availabilityZone" type:"string"` + + // The time at which fast snapshot restores entered the disabled state. + DisabledTime *time.Time `locationName:"disabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the disabling state. + DisablingTime *time.Time `locationName:"disablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabled state. + EnabledTime *time.Time `locationName:"enabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabling state. + EnablingTime *time.Time `locationName:"enablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the optimizing state. + OptimizingTime *time.Time `locationName:"optimizingTime" type:"timestamp"` + + // The alias of the snapshot owner. + OwnerAlias *string `locationName:"ownerAlias" type:"string"` + + // The ID of the AWS account that owns the snapshot. + OwnerId *string `locationName:"ownerId" type:"string"` + + // The ID of the snapshot. + SnapshotId *string `locationName:"snapshotId" type:"string"` + + // The state of fast snapshot restores. + State *string `locationName:"state" type:"string" enum:"FastSnapshotRestoreStateCode"` + + // The reason for the state transition. The possible values are as follows: + // + // * Client.UserInitiated - The state successfully transitioned to enabling + // or disabling. + // + // * Client.UserInitiated - Lifecycle state transition - The state successfully + // transitioned to optimizing, enabled, or disabled. + StateTransitionReason *string `locationName:"stateTransitionReason" type:"string"` +} + +// String returns the string representation +func (s DescribeFastSnapshotRestoreSuccessItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeFastSnapshotRestoreSuccessItem) GoString() string { + return s.String() +} + +// SetAvailabilityZone sets the AvailabilityZone field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetAvailabilityZone(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.AvailabilityZone = &v + return s +} + +// SetDisabledTime sets the DisabledTime field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetDisabledTime(v time.Time) *DescribeFastSnapshotRestoreSuccessItem { + s.DisabledTime = &v + return s +} + +// SetDisablingTime sets the DisablingTime field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetDisablingTime(v time.Time) *DescribeFastSnapshotRestoreSuccessItem { + s.DisablingTime = &v + return s +} + +// SetEnabledTime sets the EnabledTime field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetEnabledTime(v time.Time) *DescribeFastSnapshotRestoreSuccessItem { + s.EnabledTime = &v + return s +} + +// SetEnablingTime sets the EnablingTime field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetEnablingTime(v time.Time) *DescribeFastSnapshotRestoreSuccessItem { + s.EnablingTime = &v + return s +} + +// SetOptimizingTime sets the OptimizingTime field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetOptimizingTime(v time.Time) *DescribeFastSnapshotRestoreSuccessItem { + s.OptimizingTime = &v + return s +} + +// SetOwnerAlias sets the OwnerAlias field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetOwnerAlias(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.OwnerAlias = &v + return s +} + +// SetOwnerId sets the OwnerId field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetOwnerId(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.OwnerId = &v + return s +} + +// SetSnapshotId sets the SnapshotId field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetSnapshotId(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.SnapshotId = &v + return s +} + +// SetState sets the State field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetState(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.State = &v + return s +} + +// SetStateTransitionReason sets the StateTransitionReason field's value. +func (s *DescribeFastSnapshotRestoreSuccessItem) SetStateTransitionReason(v string) *DescribeFastSnapshotRestoreSuccessItem { + s.StateTransitionReason = &v + return s +} + +type DescribeFastSnapshotRestoresInput struct { + _ struct{} `type:"structure"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // The filters. The possible values are: + // + // * availability-zone: The Availability Zone of the snapshot. + // + // * owner-id: The ID of the AWS account that owns the snapshot. + // + // * snapshot-id: The ID of the snapshot. + // + // * state: The state of fast snapshot restores for the snapshot (enabling + // | optimizing | enabled | disabling | disabled). + Filters []*Filter `locationName:"Filter" locationNameList:"Filter" type:"list"` + + // The maximum number of results to return with a single call. To retrieve the + // remaining results, make another call with the returned nextToken value. + MaxResults *int64 `type:"integer"` + + // The token for the next page of results. + NextToken *string `type:"string"` +} + +// String returns the string representation +func (s DescribeFastSnapshotRestoresInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeFastSnapshotRestoresInput) GoString() string { + return s.String() +} + +// SetDryRun sets the DryRun field's value. +func (s *DescribeFastSnapshotRestoresInput) SetDryRun(v bool) *DescribeFastSnapshotRestoresInput { + s.DryRun = &v + return s +} + +// SetFilters sets the Filters field's value. +func (s *DescribeFastSnapshotRestoresInput) SetFilters(v []*Filter) *DescribeFastSnapshotRestoresInput { + s.Filters = v + return s +} + +// SetMaxResults sets the MaxResults field's value. +func (s *DescribeFastSnapshotRestoresInput) SetMaxResults(v int64) *DescribeFastSnapshotRestoresInput { + s.MaxResults = &v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeFastSnapshotRestoresInput) SetNextToken(v string) *DescribeFastSnapshotRestoresInput { + s.NextToken = &v + return s +} + +type DescribeFastSnapshotRestoresOutput struct { + _ struct{} `type:"structure"` + + // Information about the state of fast snapshot restores. + FastSnapshotRestores []*DescribeFastSnapshotRestoreSuccessItem `locationName:"fastSnapshotRestoreSet" locationNameList:"item" type:"list"` + + // The token to use to retrieve the next page of results. This value is null + // when there are no more results to return. + NextToken *string `locationName:"nextToken" type:"string"` +} + +// String returns the string representation +func (s DescribeFastSnapshotRestoresOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeFastSnapshotRestoresOutput) GoString() string { + return s.String() +} + +// SetFastSnapshotRestores sets the FastSnapshotRestores field's value. +func (s *DescribeFastSnapshotRestoresOutput) SetFastSnapshotRestores(v []*DescribeFastSnapshotRestoreSuccessItem) *DescribeFastSnapshotRestoresOutput { + s.FastSnapshotRestores = v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeFastSnapshotRestoresOutput) SetNextToken(v string) *DescribeFastSnapshotRestoresOutput { + s.NextToken = &v + return s +} + // Describes the instances that could not be launched by the fleet. type DescribeFleetError struct { _ struct{} `type:"structure"` @@ -53271,6 +54255,305 @@ func (s *DescribeInstanceStatusOutput) SetNextToken(v string) *DescribeInstanceS return s } +type DescribeInstanceTypeOfferingsInput struct { + _ struct{} `type:"structure"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // One or more filters. Filter names and values are case-sensitive. + // + // * location - This depends on the location type. For example, if the location + // type is region (default), the location is the Region code (for example, + // us-east-2.) + // + // * instance-type - The instance type. + Filters []*Filter `locationName:"Filter" locationNameList:"Filter" type:"list"` + + // The location type. + LocationType *string `type:"string" enum:"LocationType"` + + // The maximum number of results to return for the request in a single page. + // The remaining results can be seen by sending another request with the next + // token value. + MaxResults *int64 `min:"5" type:"integer"` + + // The token to retrieve the next page of results. + NextToken *string `type:"string"` +} + +// String returns the string representation +func (s DescribeInstanceTypeOfferingsInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeInstanceTypeOfferingsInput) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *DescribeInstanceTypeOfferingsInput) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "DescribeInstanceTypeOfferingsInput"} + if s.MaxResults != nil && *s.MaxResults < 5 { + invalidParams.Add(request.NewErrParamMinValue("MaxResults", 5)) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetDryRun sets the DryRun field's value. +func (s *DescribeInstanceTypeOfferingsInput) SetDryRun(v bool) *DescribeInstanceTypeOfferingsInput { + s.DryRun = &v + return s +} + +// SetFilters sets the Filters field's value. +func (s *DescribeInstanceTypeOfferingsInput) SetFilters(v []*Filter) *DescribeInstanceTypeOfferingsInput { + s.Filters = v + return s +} + +// SetLocationType sets the LocationType field's value. +func (s *DescribeInstanceTypeOfferingsInput) SetLocationType(v string) *DescribeInstanceTypeOfferingsInput { + s.LocationType = &v + return s +} + +// SetMaxResults sets the MaxResults field's value. +func (s *DescribeInstanceTypeOfferingsInput) SetMaxResults(v int64) *DescribeInstanceTypeOfferingsInput { + s.MaxResults = &v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeInstanceTypeOfferingsInput) SetNextToken(v string) *DescribeInstanceTypeOfferingsInput { + s.NextToken = &v + return s +} + +type DescribeInstanceTypeOfferingsOutput struct { + _ struct{} `type:"structure"` + + // The instance types offered. + InstanceTypeOfferings []*InstanceTypeOffering `locationName:"instanceTypeOfferingSet" locationNameList:"item" type:"list"` + + // The token to use to retrieve the next page of results. This value is null + // when there are no more results to return. + NextToken *string `locationName:"nextToken" type:"string"` +} + +// String returns the string representation +func (s DescribeInstanceTypeOfferingsOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeInstanceTypeOfferingsOutput) GoString() string { + return s.String() +} + +// SetInstanceTypeOfferings sets the InstanceTypeOfferings field's value. +func (s *DescribeInstanceTypeOfferingsOutput) SetInstanceTypeOfferings(v []*InstanceTypeOffering) *DescribeInstanceTypeOfferingsOutput { + s.InstanceTypeOfferings = v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeInstanceTypeOfferingsOutput) SetNextToken(v string) *DescribeInstanceTypeOfferingsOutput { + s.NextToken = &v + return s +} + +type DescribeInstanceTypesInput struct { + _ struct{} `type:"structure"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // One or more filters. Filter names and values are case-sensitive. + // + // * auto-recovery-supported - Indicates whether auto recovery is supported. + // (true | false) + // + // * bare-metal - Indicates whether it is a bare metal instance type. (true + // | false) + // + // * burstable-performance-supported - Indicates whether it is a burstable + // performance instance type. (true | false) + // + // * current-generation - Indicates whether this instance type is the latest + // generation instance type of an instance family. (true | false) + // + // * ebs-info.ebs-optimized-support - Indicates whether the instance type + // is EBS-optimized. (true | false) + // + // * ebs-info.encryption-support - Indicates whether EBS encryption is supported. + // (true | false) + // + // * free-tier-eligible - Indicates whether the instance type is eligible + // to use in the free tier. (true | false) + // + // * hibernation-supported - Indicates whether On-Demand hibernation is supported. + // (true | false) + // + // * hypervisor - The hypervisor used. (nitro | xen) + // + // * instance-storage-info.disk.count - The number of local disks. + // + // * instance-storage-info.disk.size-in-gb - The storage size of each instance + // storage disk, in GB. + // + // * instance-storage-info.disk.type - The storage technology for the local + // instance storage disks. (hdd | ssd) + // + // * instance-storage-info.total-size-in-gb - The total amount of storage + // available from all local instance storage, in GB. + // + // * instance-storage-supported - Indicates whether the instance type has + // local instance storage. (true | false) + // + // * memory-info.size-in-mib - The memory size. + // + // * network-info.ena-support - Indicates whether Elastic Network Adapter + // (ENA) is supported or required. (required | supported | unsupported) + // + // * network-info.ipv4-addresses-per-interface - The maximum number of private + // IPv4 addresses per network interface. + // + // * network-info.ipv6-addresses-per-interface - The maximum number of private + // IPv6 addresses per network interface. + // + // * network-info.ipv6-supported - Indicates whether the instance type supports + // IPv6. (true | false) + // + // * network-info.maximum-network-interfaces - The maximum number of network + // interfaces per instance. + // + // * network-info.network-performance - Describes the network performance. + // + // * processor-info.sustained-clock-speed-in-ghz - The CPU clock speed, in + // GHz. + // + // * vcpu-info.default-cores - The default number of cores for the instance + // type. + // + // * vcpu-info.default-threads-per-core - The default number of threads per + // cores for the instance type. + // + // * vcpu-info.default-vcpus - The default number of vCPUs for the instance + // type. + Filters []*Filter `locationName:"Filter" locationNameList:"Filter" type:"list"` + + // The instance types. For more information, see Instance Types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) + // in the Amazon Elastic Compute Cloud User Guide. + InstanceTypes []*string `locationName:"InstanceType" type:"list"` + + // The maximum number of results to return for the request in a single page. + // The remaining results can be seen by sending another request with the next + // token value. + MaxResults *int64 `min:"5" type:"integer"` + + // The token to retrieve the next page of results. + NextToken *string `type:"string"` +} + +// String returns the string representation +func (s DescribeInstanceTypesInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeInstanceTypesInput) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *DescribeInstanceTypesInput) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "DescribeInstanceTypesInput"} + if s.MaxResults != nil && *s.MaxResults < 5 { + invalidParams.Add(request.NewErrParamMinValue("MaxResults", 5)) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetDryRun sets the DryRun field's value. +func (s *DescribeInstanceTypesInput) SetDryRun(v bool) *DescribeInstanceTypesInput { + s.DryRun = &v + return s +} + +// SetFilters sets the Filters field's value. +func (s *DescribeInstanceTypesInput) SetFilters(v []*Filter) *DescribeInstanceTypesInput { + s.Filters = v + return s +} + +// SetInstanceTypes sets the InstanceTypes field's value. +func (s *DescribeInstanceTypesInput) SetInstanceTypes(v []*string) *DescribeInstanceTypesInput { + s.InstanceTypes = v + return s +} + +// SetMaxResults sets the MaxResults field's value. +func (s *DescribeInstanceTypesInput) SetMaxResults(v int64) *DescribeInstanceTypesInput { + s.MaxResults = &v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeInstanceTypesInput) SetNextToken(v string) *DescribeInstanceTypesInput { + s.NextToken = &v + return s +} + +type DescribeInstanceTypesOutput struct { + _ struct{} `type:"structure"` + + // The instance type. For more information, see Instance Types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) + // in the Amazon Elastic Compute Cloud User Guide. + InstanceTypes []*InstanceTypeInfo `locationName:"instanceTypeSet" locationNameList:"item" type:"list"` + + // The token to use to retrieve the next page of results. This value is null + // when there are no more results to return. + NextToken *string `locationName:"nextToken" type:"string"` +} + +// String returns the string representation +func (s DescribeInstanceTypesOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DescribeInstanceTypesOutput) GoString() string { + return s.String() +} + +// SetInstanceTypes sets the InstanceTypes field's value. +func (s *DescribeInstanceTypesOutput) SetInstanceTypes(v []*InstanceTypeInfo) *DescribeInstanceTypesOutput { + s.InstanceTypes = v + return s +} + +// SetNextToken sets the NextToken field's value. +func (s *DescribeInstanceTypesOutput) SetNextToken(v string) *DescribeInstanceTypesOutput { + s.NextToken = &v + return s +} + type DescribeInstancesInput struct { _ struct{} `type:"structure"` @@ -53324,9 +54607,8 @@ type DescribeInstancesInput struct { // * hypervisor - The hypervisor type of the instance (ovm | xen). // // * iam-instance-profile.arn - The instance profile associated with the - // instance. Specified as an ARN. - // - // * image-id - The ID of the image used to launch the instance. + // instance. Specified as an ARN. image-id - The ID of the image used to + // launch the instance. // // * instance-id - The ID of the instance. // @@ -53359,6 +54641,15 @@ type DescribeInstancesInput struct { // // * launch-time - The time when the instance was launched. // + // * metadata-http-tokens - The metadata request authorization state (optional + // | required) + // + // * metadata-http-put-response-hop-limit - The http metadata request put + // response hop limit (integer, possible values 1 to 64) + // + // * metadata-http-endpoint - Enable or disable metadata access on http endpoint + // (enabled | disabled) + // // * monitoring-state - Indicates whether detailed monitoring is enabled // (disabled | enabled). // @@ -56704,7 +57995,6 @@ func (s *DescribeSecurityGroupsOutput) SetSecurityGroups(v []*SecurityGroup) *De return s } -// Contains the parameters for DescribeSnapshotAttribute. type DescribeSnapshotAttributeInput struct { _ struct{} `type:"structure"` @@ -56769,7 +58059,6 @@ func (s *DescribeSnapshotAttributeInput) SetSnapshotId(v string) *DescribeSnapsh return s } -// Contains the output of DescribeSnapshotAttribute. type DescribeSnapshotAttributeOutput struct { _ struct{} `type:"structure"` @@ -59003,7 +60292,6 @@ func (s *DescribeTransitGatewaysOutput) SetTransitGateways(v []*TransitGateway) return s } -// Contains the parameters for DescribeVolumeAttribute. type DescribeVolumeAttributeInput struct { _ struct{} `type:"structure"` @@ -59068,7 +60356,6 @@ func (s *DescribeVolumeAttributeInput) SetVolumeId(v string) *DescribeVolumeAttr return s } -// Contains the output of DescribeVolumeAttribute. type DescribeVolumeAttributeOutput struct { _ struct{} `type:"structure"` @@ -60809,6 +62096,9 @@ type DescribeVpnConnectionsInput struct { // // * vpn-gateway-id - The ID of a virtual private gateway associated with // the VPN connection. + // + // * transit-gateway-id - The ID of a transit gateway associated with the + // VPN connection. Filters []*Filter `locationName:"Filter" locationNameList:"Filter" type:"list"` // One or more VPN connection IDs. @@ -61221,7 +62511,6 @@ func (s DetachNetworkInterfaceOutput) GoString() string { return s.String() } -// Contains the parameters for DetachVolume. type DetachVolumeInput struct { _ struct{} `type:"structure"` @@ -61565,6 +62854,325 @@ func (s *DisableEbsEncryptionByDefaultOutput) SetEbsEncryptionByDefault(v bool) return s } +// Contains information about the errors that occurred when disabling fast snapshot +// restores. +type DisableFastSnapshotRestoreErrorItem struct { + _ struct{} `type:"structure"` + + // The errors. + FastSnapshotRestoreStateErrors []*DisableFastSnapshotRestoreStateErrorItem `locationName:"fastSnapshotRestoreStateErrorSet" locationNameList:"item" type:"list"` + + // The ID of the snapshot. + SnapshotId *string `locationName:"snapshotId" type:"string"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoreErrorItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoreErrorItem) GoString() string { + return s.String() +} + +// SetFastSnapshotRestoreStateErrors sets the FastSnapshotRestoreStateErrors field's value. +func (s *DisableFastSnapshotRestoreErrorItem) SetFastSnapshotRestoreStateErrors(v []*DisableFastSnapshotRestoreStateErrorItem) *DisableFastSnapshotRestoreErrorItem { + s.FastSnapshotRestoreStateErrors = v + return s +} + +// SetSnapshotId sets the SnapshotId field's value. +func (s *DisableFastSnapshotRestoreErrorItem) SetSnapshotId(v string) *DisableFastSnapshotRestoreErrorItem { + s.SnapshotId = &v + return s +} + +// Describes an error that occurred when disabling fast snapshot restores. +type DisableFastSnapshotRestoreStateError struct { + _ struct{} `type:"structure"` + + // The error code. + Code *string `locationName:"code" type:"string"` + + // The error message. + Message *string `locationName:"message" type:"string"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoreStateError) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoreStateError) GoString() string { + return s.String() +} + +// SetCode sets the Code field's value. +func (s *DisableFastSnapshotRestoreStateError) SetCode(v string) *DisableFastSnapshotRestoreStateError { + s.Code = &v + return s +} + +// SetMessage sets the Message field's value. +func (s *DisableFastSnapshotRestoreStateError) SetMessage(v string) *DisableFastSnapshotRestoreStateError { + s.Message = &v + return s +} + +// Contains information about an error that occurred when disabling fast snapshot +// restores. +type DisableFastSnapshotRestoreStateErrorItem struct { + _ struct{} `type:"structure"` + + // The Availability Zone. + AvailabilityZone *string `locationName:"availabilityZone" type:"string"` + + // The error. + Error *DisableFastSnapshotRestoreStateError `locationName:"error" type:"structure"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoreStateErrorItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoreStateErrorItem) GoString() string { + return s.String() +} + +// SetAvailabilityZone sets the AvailabilityZone field's value. +func (s *DisableFastSnapshotRestoreStateErrorItem) SetAvailabilityZone(v string) *DisableFastSnapshotRestoreStateErrorItem { + s.AvailabilityZone = &v + return s +} + +// SetError sets the Error field's value. +func (s *DisableFastSnapshotRestoreStateErrorItem) SetError(v *DisableFastSnapshotRestoreStateError) *DisableFastSnapshotRestoreStateErrorItem { + s.Error = v + return s +} + +// Describes fast snapshot restores that were successfully disabled. +type DisableFastSnapshotRestoreSuccessItem struct { + _ struct{} `type:"structure"` + + // The Availability Zone. + AvailabilityZone *string `locationName:"availabilityZone" type:"string"` + + // The time at which fast snapshot restores entered the disabled state. + DisabledTime *time.Time `locationName:"disabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the disabling state. + DisablingTime *time.Time `locationName:"disablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabled state. + EnabledTime *time.Time `locationName:"enabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabling state. + EnablingTime *time.Time `locationName:"enablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the optimizing state. + OptimizingTime *time.Time `locationName:"optimizingTime" type:"timestamp"` + + // The alias of the snapshot owner. + OwnerAlias *string `locationName:"ownerAlias" type:"string"` + + // The ID of the AWS account that owns the snapshot. + OwnerId *string `locationName:"ownerId" type:"string"` + + // The ID of the snapshot. + SnapshotId *string `locationName:"snapshotId" type:"string"` + + // The state of fast snapshot restores for the snapshot. + State *string `locationName:"state" type:"string" enum:"FastSnapshotRestoreStateCode"` + + // The reason for the state transition. The possible values are as follows: + // + // * Client.UserInitiated - The state successfully transitioned to enabling + // or disabling. + // + // * Client.UserInitiated - Lifecycle state transition - The state successfully + // transitioned to optimizing, enabled, or disabled. + StateTransitionReason *string `locationName:"stateTransitionReason" type:"string"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoreSuccessItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoreSuccessItem) GoString() string { + return s.String() +} + +// SetAvailabilityZone sets the AvailabilityZone field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetAvailabilityZone(v string) *DisableFastSnapshotRestoreSuccessItem { + s.AvailabilityZone = &v + return s +} + +// SetDisabledTime sets the DisabledTime field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetDisabledTime(v time.Time) *DisableFastSnapshotRestoreSuccessItem { + s.DisabledTime = &v + return s +} + +// SetDisablingTime sets the DisablingTime field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetDisablingTime(v time.Time) *DisableFastSnapshotRestoreSuccessItem { + s.DisablingTime = &v + return s +} + +// SetEnabledTime sets the EnabledTime field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetEnabledTime(v time.Time) *DisableFastSnapshotRestoreSuccessItem { + s.EnabledTime = &v + return s +} + +// SetEnablingTime sets the EnablingTime field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetEnablingTime(v time.Time) *DisableFastSnapshotRestoreSuccessItem { + s.EnablingTime = &v + return s +} + +// SetOptimizingTime sets the OptimizingTime field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetOptimizingTime(v time.Time) *DisableFastSnapshotRestoreSuccessItem { + s.OptimizingTime = &v + return s +} + +// SetOwnerAlias sets the OwnerAlias field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetOwnerAlias(v string) *DisableFastSnapshotRestoreSuccessItem { + s.OwnerAlias = &v + return s +} + +// SetOwnerId sets the OwnerId field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetOwnerId(v string) *DisableFastSnapshotRestoreSuccessItem { + s.OwnerId = &v + return s +} + +// SetSnapshotId sets the SnapshotId field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetSnapshotId(v string) *DisableFastSnapshotRestoreSuccessItem { + s.SnapshotId = &v + return s +} + +// SetState sets the State field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetState(v string) *DisableFastSnapshotRestoreSuccessItem { + s.State = &v + return s +} + +// SetStateTransitionReason sets the StateTransitionReason field's value. +func (s *DisableFastSnapshotRestoreSuccessItem) SetStateTransitionReason(v string) *DisableFastSnapshotRestoreSuccessItem { + s.StateTransitionReason = &v + return s +} + +type DisableFastSnapshotRestoresInput struct { + _ struct{} `type:"structure"` + + // One or more Availability Zones. For example, us-east-2a. + // + // AvailabilityZones is a required field + AvailabilityZones []*string `locationName:"AvailabilityZone" locationNameList:"AvailabilityZone" type:"list" required:"true"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // The IDs of one or more snapshots. For example, snap-1234567890abcdef0. + // + // SourceSnapshotIds is a required field + SourceSnapshotIds []*string `locationName:"SourceSnapshotId" locationNameList:"SnapshotId" type:"list" required:"true"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoresInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoresInput) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *DisableFastSnapshotRestoresInput) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "DisableFastSnapshotRestoresInput"} + if s.AvailabilityZones == nil { + invalidParams.Add(request.NewErrParamRequired("AvailabilityZones")) + } + if s.SourceSnapshotIds == nil { + invalidParams.Add(request.NewErrParamRequired("SourceSnapshotIds")) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetAvailabilityZones sets the AvailabilityZones field's value. +func (s *DisableFastSnapshotRestoresInput) SetAvailabilityZones(v []*string) *DisableFastSnapshotRestoresInput { + s.AvailabilityZones = v + return s +} + +// SetDryRun sets the DryRun field's value. +func (s *DisableFastSnapshotRestoresInput) SetDryRun(v bool) *DisableFastSnapshotRestoresInput { + s.DryRun = &v + return s +} + +// SetSourceSnapshotIds sets the SourceSnapshotIds field's value. +func (s *DisableFastSnapshotRestoresInput) SetSourceSnapshotIds(v []*string) *DisableFastSnapshotRestoresInput { + s.SourceSnapshotIds = v + return s +} + +type DisableFastSnapshotRestoresOutput struct { + _ struct{} `type:"structure"` + + // Information about the snapshots for which fast snapshot restores were successfully + // disabled. + Successful []*DisableFastSnapshotRestoreSuccessItem `locationName:"successful" locationNameList:"item" type:"list"` + + // Information about the snapshots for which fast snapshot restores could not + // be disabled. + Unsuccessful []*DisableFastSnapshotRestoreErrorItem `locationName:"unsuccessful" locationNameList:"item" type:"list"` +} + +// String returns the string representation +func (s DisableFastSnapshotRestoresOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DisableFastSnapshotRestoresOutput) GoString() string { + return s.String() +} + +// SetSuccessful sets the Successful field's value. +func (s *DisableFastSnapshotRestoresOutput) SetSuccessful(v []*DisableFastSnapshotRestoreSuccessItem) *DisableFastSnapshotRestoresOutput { + s.Successful = v + return s +} + +// SetUnsuccessful sets the Unsuccessful field's value. +func (s *DisableFastSnapshotRestoresOutput) SetUnsuccessful(v []*DisableFastSnapshotRestoreErrorItem) *DisableFastSnapshotRestoresOutput { + s.Unsuccessful = v + return s +} + type DisableTransitGatewayRouteTablePropagationInput struct { _ struct{} `type:"structure"` @@ -62581,6 +64189,48 @@ func (s *DiskImageVolumeDescription) SetSize(v int64) *DiskImageVolumeDescriptio return s } +// Describes the disk. +type DiskInfo struct { + _ struct{} `type:"structure"` + + // The number of disks with this configuration. + Count *int64 `locationName:"count" type:"integer"` + + // The size of the disk in GiB. + SizeInGB *int64 `locationName:"sizeInGB" type:"long"` + + // The type of disk. + Type *string `locationName:"type" type:"string" enum:"DiskType"` +} + +// String returns the string representation +func (s DiskInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s DiskInfo) GoString() string { + return s.String() +} + +// SetCount sets the Count field's value. +func (s *DiskInfo) SetCount(v int64) *DiskInfo { + s.Count = &v + return s +} + +// SetSizeInGB sets the SizeInGB field's value. +func (s *DiskInfo) SetSizeInGB(v int64) *DiskInfo { + s.SizeInGB = &v + return s +} + +// SetType sets the Type field's value. +func (s *DiskInfo) SetType(v string) *DiskInfo { + s.Type = &v + return s +} + // Describes a DNS entry. type DnsEntry struct { _ struct{} `type:"structure"` @@ -62774,6 +64424,41 @@ func (s *EbsBlockDevice) SetVolumeType(v string) *EbsBlockDevice { return s } +// Describes the Amazon EBS features supported by the instance type. +type EbsInfo struct { + _ struct{} `type:"structure"` + + // Indicates that the instance type is Amazon EBS-optimized. For more information, + // see Amazon EBS-Optimized Instances (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html) + // in Amazon EC2 User Guide for Linux Instances. + EbsOptimizedSupport *string `locationName:"ebsOptimizedSupport" type:"string" enum:"EbsOptimizedSupport"` + + // Indicates whether Amazon EBS encryption is supported. + EncryptionSupport *string `locationName:"encryptionSupport" type:"string" enum:"EbsEncryptionSupport"` +} + +// String returns the string representation +func (s EbsInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EbsInfo) GoString() string { + return s.String() +} + +// SetEbsOptimizedSupport sets the EbsOptimizedSupport field's value. +func (s *EbsInfo) SetEbsOptimizedSupport(v string) *EbsInfo { + s.EbsOptimizedSupport = &v + return s +} + +// SetEncryptionSupport sets the EncryptionSupport field's value. +func (s *EbsInfo) SetEncryptionSupport(v string) *EbsInfo { + s.EncryptionSupport = &v + return s +} + // Describes a parameter used to set up an EBS volume in a block device mapping. type EbsInstanceBlockDevice struct { _ struct{} `type:"structure"` @@ -63241,6 +64926,326 @@ func (s *EnableEbsEncryptionByDefaultOutput) SetEbsEncryptionByDefault(v bool) * return s } +// Contains information about the errors that occurred when enabling fast snapshot +// restores. +type EnableFastSnapshotRestoreErrorItem struct { + _ struct{} `type:"structure"` + + // The errors. + FastSnapshotRestoreStateErrors []*EnableFastSnapshotRestoreStateErrorItem `locationName:"fastSnapshotRestoreStateErrorSet" locationNameList:"item" type:"list"` + + // The ID of the snapshot. + SnapshotId *string `locationName:"snapshotId" type:"string"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoreErrorItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoreErrorItem) GoString() string { + return s.String() +} + +// SetFastSnapshotRestoreStateErrors sets the FastSnapshotRestoreStateErrors field's value. +func (s *EnableFastSnapshotRestoreErrorItem) SetFastSnapshotRestoreStateErrors(v []*EnableFastSnapshotRestoreStateErrorItem) *EnableFastSnapshotRestoreErrorItem { + s.FastSnapshotRestoreStateErrors = v + return s +} + +// SetSnapshotId sets the SnapshotId field's value. +func (s *EnableFastSnapshotRestoreErrorItem) SetSnapshotId(v string) *EnableFastSnapshotRestoreErrorItem { + s.SnapshotId = &v + return s +} + +// Describes an error that occurred when enabling fast snapshot restores. +type EnableFastSnapshotRestoreStateError struct { + _ struct{} `type:"structure"` + + // The error code. + Code *string `locationName:"code" type:"string"` + + // The error message. + Message *string `locationName:"message" type:"string"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoreStateError) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoreStateError) GoString() string { + return s.String() +} + +// SetCode sets the Code field's value. +func (s *EnableFastSnapshotRestoreStateError) SetCode(v string) *EnableFastSnapshotRestoreStateError { + s.Code = &v + return s +} + +// SetMessage sets the Message field's value. +func (s *EnableFastSnapshotRestoreStateError) SetMessage(v string) *EnableFastSnapshotRestoreStateError { + s.Message = &v + return s +} + +// Contains information about an error that occurred when enabling fast snapshot +// restores. +type EnableFastSnapshotRestoreStateErrorItem struct { + _ struct{} `type:"structure"` + + // The Availability Zone. + AvailabilityZone *string `locationName:"availabilityZone" type:"string"` + + // The error. + Error *EnableFastSnapshotRestoreStateError `locationName:"error" type:"structure"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoreStateErrorItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoreStateErrorItem) GoString() string { + return s.String() +} + +// SetAvailabilityZone sets the AvailabilityZone field's value. +func (s *EnableFastSnapshotRestoreStateErrorItem) SetAvailabilityZone(v string) *EnableFastSnapshotRestoreStateErrorItem { + s.AvailabilityZone = &v + return s +} + +// SetError sets the Error field's value. +func (s *EnableFastSnapshotRestoreStateErrorItem) SetError(v *EnableFastSnapshotRestoreStateError) *EnableFastSnapshotRestoreStateErrorItem { + s.Error = v + return s +} + +// Describes fast snapshot restores that were successfully enabled. +type EnableFastSnapshotRestoreSuccessItem struct { + _ struct{} `type:"structure"` + + // The Availability Zone. + AvailabilityZone *string `locationName:"availabilityZone" type:"string"` + + // The time at which fast snapshot restores entered the disabled state. + DisabledTime *time.Time `locationName:"disabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the disabling state. + DisablingTime *time.Time `locationName:"disablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabled state. + EnabledTime *time.Time `locationName:"enabledTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the enabling state. + EnablingTime *time.Time `locationName:"enablingTime" type:"timestamp"` + + // The time at which fast snapshot restores entered the optimizing state. + OptimizingTime *time.Time `locationName:"optimizingTime" type:"timestamp"` + + // The alias of the snapshot owner. + OwnerAlias *string `locationName:"ownerAlias" type:"string"` + + // The ID of the AWS account that owns the snapshot. + OwnerId *string `locationName:"ownerId" type:"string"` + + // The ID of the snapshot. + SnapshotId *string `locationName:"snapshotId" type:"string"` + + // The state of fast snapshot restores. + State *string `locationName:"state" type:"string" enum:"FastSnapshotRestoreStateCode"` + + // The reason for the state transition. The possible values are as follows: + // + // * Client.UserInitiated - The state successfully transitioned to enabling + // or disabling. + // + // * Client.UserInitiated - Lifecycle state transition - The state successfully + // transitioned to optimizing, enabled, or disabled. + StateTransitionReason *string `locationName:"stateTransitionReason" type:"string"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoreSuccessItem) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoreSuccessItem) GoString() string { + return s.String() +} + +// SetAvailabilityZone sets the AvailabilityZone field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetAvailabilityZone(v string) *EnableFastSnapshotRestoreSuccessItem { + s.AvailabilityZone = &v + return s +} + +// SetDisabledTime sets the DisabledTime field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetDisabledTime(v time.Time) *EnableFastSnapshotRestoreSuccessItem { + s.DisabledTime = &v + return s +} + +// SetDisablingTime sets the DisablingTime field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetDisablingTime(v time.Time) *EnableFastSnapshotRestoreSuccessItem { + s.DisablingTime = &v + return s +} + +// SetEnabledTime sets the EnabledTime field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetEnabledTime(v time.Time) *EnableFastSnapshotRestoreSuccessItem { + s.EnabledTime = &v + return s +} + +// SetEnablingTime sets the EnablingTime field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetEnablingTime(v time.Time) *EnableFastSnapshotRestoreSuccessItem { + s.EnablingTime = &v + return s +} + +// SetOptimizingTime sets the OptimizingTime field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetOptimizingTime(v time.Time) *EnableFastSnapshotRestoreSuccessItem { + s.OptimizingTime = &v + return s +} + +// SetOwnerAlias sets the OwnerAlias field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetOwnerAlias(v string) *EnableFastSnapshotRestoreSuccessItem { + s.OwnerAlias = &v + return s +} + +// SetOwnerId sets the OwnerId field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetOwnerId(v string) *EnableFastSnapshotRestoreSuccessItem { + s.OwnerId = &v + return s +} + +// SetSnapshotId sets the SnapshotId field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetSnapshotId(v string) *EnableFastSnapshotRestoreSuccessItem { + s.SnapshotId = &v + return s +} + +// SetState sets the State field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetState(v string) *EnableFastSnapshotRestoreSuccessItem { + s.State = &v + return s +} + +// SetStateTransitionReason sets the StateTransitionReason field's value. +func (s *EnableFastSnapshotRestoreSuccessItem) SetStateTransitionReason(v string) *EnableFastSnapshotRestoreSuccessItem { + s.StateTransitionReason = &v + return s +} + +type EnableFastSnapshotRestoresInput struct { + _ struct{} `type:"structure"` + + // One or more Availability Zones. For example, us-east-2a. + // + // AvailabilityZones is a required field + AvailabilityZones []*string `locationName:"AvailabilityZone" locationNameList:"AvailabilityZone" type:"list" required:"true"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // The IDs of one or more snapshots. For example, snap-1234567890abcdef0. You + // can specify a snapshot that was shared with you from another AWS account. + // + // SourceSnapshotIds is a required field + SourceSnapshotIds []*string `locationName:"SourceSnapshotId" locationNameList:"SnapshotId" type:"list" required:"true"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoresInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoresInput) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *EnableFastSnapshotRestoresInput) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "EnableFastSnapshotRestoresInput"} + if s.AvailabilityZones == nil { + invalidParams.Add(request.NewErrParamRequired("AvailabilityZones")) + } + if s.SourceSnapshotIds == nil { + invalidParams.Add(request.NewErrParamRequired("SourceSnapshotIds")) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetAvailabilityZones sets the AvailabilityZones field's value. +func (s *EnableFastSnapshotRestoresInput) SetAvailabilityZones(v []*string) *EnableFastSnapshotRestoresInput { + s.AvailabilityZones = v + return s +} + +// SetDryRun sets the DryRun field's value. +func (s *EnableFastSnapshotRestoresInput) SetDryRun(v bool) *EnableFastSnapshotRestoresInput { + s.DryRun = &v + return s +} + +// SetSourceSnapshotIds sets the SourceSnapshotIds field's value. +func (s *EnableFastSnapshotRestoresInput) SetSourceSnapshotIds(v []*string) *EnableFastSnapshotRestoresInput { + s.SourceSnapshotIds = v + return s +} + +type EnableFastSnapshotRestoresOutput struct { + _ struct{} `type:"structure"` + + // Information about the snapshots for which fast snapshot restores were successfully + // enabled. + Successful []*EnableFastSnapshotRestoreSuccessItem `locationName:"successful" locationNameList:"item" type:"list"` + + // Information about the snapshots for which fast snapshot restores could not + // be enabled. + Unsuccessful []*EnableFastSnapshotRestoreErrorItem `locationName:"unsuccessful" locationNameList:"item" type:"list"` +} + +// String returns the string representation +func (s EnableFastSnapshotRestoresOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s EnableFastSnapshotRestoresOutput) GoString() string { + return s.String() +} + +// SetSuccessful sets the Successful field's value. +func (s *EnableFastSnapshotRestoresOutput) SetSuccessful(v []*EnableFastSnapshotRestoreSuccessItem) *EnableFastSnapshotRestoresOutput { + s.Successful = v + return s +} + +// SetUnsuccessful sets the Unsuccessful field's value. +func (s *EnableFastSnapshotRestoresOutput) SetUnsuccessful(v []*EnableFastSnapshotRestoreErrorItem) *EnableFastSnapshotRestoresOutput { + s.Unsuccessful = v + return s +} + type EnableTransitGatewayRouteTablePropagationInput struct { _ struct{} `type:"structure"` @@ -63398,7 +65403,6 @@ func (s EnableVgwRoutePropagationOutput) GoString() string { return s.String() } -// Contains the parameters for EnableVolumeIO. type EnableVolumeIOInput struct { _ struct{} `type:"structure"` @@ -65320,6 +67324,81 @@ func (s *FlowLog) SetTrafficType(v string) *FlowLog { return s } +// Describes the FPGA accelerator for the instance type. +type FpgaDeviceInfo struct { + _ struct{} `type:"structure"` + + // The count of FPGA accelerators for the instance type. + Count *int64 `locationName:"count" type:"integer"` + + // The manufacturer of the FPGA accelerator. + Manufacturer *string `locationName:"manufacturer" type:"string"` + + // Describes the memory for the FPGA accelerator for the instance type. + MemoryInfo *FpgaDeviceMemoryInfo `locationName:"memoryInfo" type:"structure"` + + // The name of the FPGA accelerator. + Name *string `locationName:"name" type:"string"` +} + +// String returns the string representation +func (s FpgaDeviceInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s FpgaDeviceInfo) GoString() string { + return s.String() +} + +// SetCount sets the Count field's value. +func (s *FpgaDeviceInfo) SetCount(v int64) *FpgaDeviceInfo { + s.Count = &v + return s +} + +// SetManufacturer sets the Manufacturer field's value. +func (s *FpgaDeviceInfo) SetManufacturer(v string) *FpgaDeviceInfo { + s.Manufacturer = &v + return s +} + +// SetMemoryInfo sets the MemoryInfo field's value. +func (s *FpgaDeviceInfo) SetMemoryInfo(v *FpgaDeviceMemoryInfo) *FpgaDeviceInfo { + s.MemoryInfo = v + return s +} + +// SetName sets the Name field's value. +func (s *FpgaDeviceInfo) SetName(v string) *FpgaDeviceInfo { + s.Name = &v + return s +} + +// Describes the memory for the FPGA accelerator for the instance type. +type FpgaDeviceMemoryInfo struct { + _ struct{} `type:"structure"` + + // The size (in MiB) for the memory available to the FPGA accelerator. + SizeInMiB *int64 `locationName:"sizeInMiB" type:"integer"` +} + +// String returns the string representation +func (s FpgaDeviceMemoryInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s FpgaDeviceMemoryInfo) GoString() string { + return s.String() +} + +// SetSizeInMiB sets the SizeInMiB field's value. +func (s *FpgaDeviceMemoryInfo) SetSizeInMiB(v int64) *FpgaDeviceMemoryInfo { + s.SizeInMiB = &v + return s +} + // Describes an Amazon FPGA image (AFI). type FpgaImage struct { _ struct{} `type:"structure"` @@ -65572,6 +67651,39 @@ func (s *FpgaImageState) SetMessage(v string) *FpgaImageState { return s } +// Describes the FPGAs for the instance type. +type FpgaInfo struct { + _ struct{} `type:"structure"` + + // Describes the FPGAs for the instance type. + Fpgas []*FpgaDeviceInfo `locationName:"fpgas" locationNameList:"item" type:"list"` + + // The total memory of all FPGA accelerators for the instance type. + TotalFpgaMemoryInMiB *int64 `locationName:"totalFpgaMemoryInMiB" type:"integer"` +} + +// String returns the string representation +func (s FpgaInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s FpgaInfo) GoString() string { + return s.String() +} + +// SetFpgas sets the Fpgas field's value. +func (s *FpgaInfo) SetFpgas(v []*FpgaDeviceInfo) *FpgaInfo { + s.Fpgas = v + return s +} + +// SetTotalFpgaMemoryInMiB sets the TotalFpgaMemoryInMiB field's value. +func (s *FpgaInfo) SetTotalFpgaMemoryInMiB(v int64) *FpgaInfo { + s.TotalFpgaMemoryInMiB = &v + return s +} + type GetCapacityReservationUsageInput struct { _ struct{} `type:"structure"` @@ -66830,6 +68942,114 @@ func (s *GetTransitGatewayRouteTablePropagationsOutput) SetTransitGatewayRouteTa return s } +// Describes the GPU accelerators for the instance type. +type GpuDeviceInfo struct { + _ struct{} `type:"structure"` + + // The number of GPUs for the instance type. + Count *int64 `locationName:"count" type:"integer"` + + // The manufacturer of the GPU accelerator. + Manufacturer *string `locationName:"manufacturer" type:"string"` + + // Describes the memory available to the GPU accelerator. + MemoryInfo *GpuDeviceMemoryInfo `locationName:"memoryInfo" type:"structure"` + + // The name of the GPU accelerator. + Name *string `locationName:"name" type:"string"` +} + +// String returns the string representation +func (s GpuDeviceInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s GpuDeviceInfo) GoString() string { + return s.String() +} + +// SetCount sets the Count field's value. +func (s *GpuDeviceInfo) SetCount(v int64) *GpuDeviceInfo { + s.Count = &v + return s +} + +// SetManufacturer sets the Manufacturer field's value. +func (s *GpuDeviceInfo) SetManufacturer(v string) *GpuDeviceInfo { + s.Manufacturer = &v + return s +} + +// SetMemoryInfo sets the MemoryInfo field's value. +func (s *GpuDeviceInfo) SetMemoryInfo(v *GpuDeviceMemoryInfo) *GpuDeviceInfo { + s.MemoryInfo = v + return s +} + +// SetName sets the Name field's value. +func (s *GpuDeviceInfo) SetName(v string) *GpuDeviceInfo { + s.Name = &v + return s +} + +// Describes the memory available to the GPU accelerator. +type GpuDeviceMemoryInfo struct { + _ struct{} `type:"structure"` + + // The size (in MiB) for the memory available to the GPU accelerator. + SizeInMiB *int64 `locationName:"sizeInMiB" type:"integer"` +} + +// String returns the string representation +func (s GpuDeviceMemoryInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s GpuDeviceMemoryInfo) GoString() string { + return s.String() +} + +// SetSizeInMiB sets the SizeInMiB field's value. +func (s *GpuDeviceMemoryInfo) SetSizeInMiB(v int64) *GpuDeviceMemoryInfo { + s.SizeInMiB = &v + return s +} + +// Describes the GPU accelerators for the instance type. +type GpuInfo struct { + _ struct{} `type:"structure"` + + // Describes the GPU accelerators for the instance type. + Gpus []*GpuDeviceInfo `locationName:"gpus" locationNameList:"item" type:"list"` + + // The total size of the memory for the GPU accelerators for the instance type. + TotalGpuMemoryInMiB *int64 `locationName:"totalGpuMemoryInMiB" type:"integer"` +} + +// String returns the string representation +func (s GpuInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s GpuInfo) GoString() string { + return s.String() +} + +// SetGpus sets the Gpus field's value. +func (s *GpuInfo) SetGpus(v []*GpuDeviceInfo) *GpuInfo { + s.Gpus = v + return s +} + +// SetTotalGpuMemoryInMiB sets the TotalGpuMemoryInMiB field's value. +func (s *GpuInfo) SetTotalGpuMemoryInMiB(v int64) *GpuInfo { + s.TotalGpuMemoryInMiB = &v + return s +} + // Describes a security group. type GroupIdentifier struct { _ struct{} `type:"structure"` @@ -67020,13 +69240,23 @@ type Host struct { // The time that the Dedicated Host was allocated. AllocationTime *time.Time `locationName:"allocationTime" type:"timestamp"` + // Indicates whether the Dedicated Host supports multiple instance types of + // the same instance family, or a specific instance type only. one indicates + // that the Dedicated Host supports multiple instance types in the instance + // family. off indicates that the Dedicated Host supports a single instance + // type only. + AllowsMultipleInstanceTypes *string `locationName:"allowsMultipleInstanceTypes" type:"string" enum:"AllowsMultipleInstanceTypes"` + // Whether auto-placement is on or off. AutoPlacement *string `locationName:"autoPlacement" type:"string" enum:"AutoPlacement"` // The Availability Zone of the Dedicated Host. AvailabilityZone *string `locationName:"availabilityZone" type:"string"` - // The number of new instances that can be launched onto the Dedicated Host. + // The ID of the Availability Zone in which the Dedicated Host is allocated. + AvailabilityZoneId *string `locationName:"availabilityZoneId" type:"string"` + + // Information about the instances running on the Dedicated Host. AvailableCapacity *AvailableCapacity `locationName:"availableCapacity" type:"structure"` // Unique, case-sensitive identifier that you provide to ensure the idempotency @@ -67050,6 +69280,9 @@ type Host struct { // The IDs and instance type that are currently running on the Dedicated Host. Instances []*HostInstance `locationName:"instances" locationNameList:"item" type:"list"` + // The ID of the AWS account that owns the Dedicated Host. + OwnerId *string `locationName:"ownerId" type:"string"` + // The time that the Dedicated Host was released. ReleaseTime *time.Time `locationName:"releaseTime" type:"timestamp"` @@ -67076,6 +69309,12 @@ func (s *Host) SetAllocationTime(v time.Time) *Host { return s } +// SetAllowsMultipleInstanceTypes sets the AllowsMultipleInstanceTypes field's value. +func (s *Host) SetAllowsMultipleInstanceTypes(v string) *Host { + s.AllowsMultipleInstanceTypes = &v + return s +} + // SetAutoPlacement sets the AutoPlacement field's value. func (s *Host) SetAutoPlacement(v string) *Host { s.AutoPlacement = &v @@ -67088,6 +69327,12 @@ func (s *Host) SetAvailabilityZone(v string) *Host { return s } +// SetAvailabilityZoneId sets the AvailabilityZoneId field's value. +func (s *Host) SetAvailabilityZoneId(v string) *Host { + s.AvailabilityZoneId = &v + return s +} + // SetAvailableCapacity sets the AvailableCapacity field's value. func (s *Host) SetAvailableCapacity(v *AvailableCapacity) *Host { s.AvailableCapacity = v @@ -67130,6 +69375,12 @@ func (s *Host) SetInstances(v []*HostInstance) *Host { return s } +// SetOwnerId sets the OwnerId field's value. +func (s *Host) SetOwnerId(v string) *Host { + s.OwnerId = &v + return s +} + // SetReleaseTime sets the ReleaseTime field's value. func (s *Host) SetReleaseTime(v time.Time) *Host { s.ReleaseTime = &v @@ -67152,11 +69403,14 @@ func (s *Host) SetTags(v []*Tag) *Host { type HostInstance struct { _ struct{} `type:"structure"` - // the IDs of instances that are running on the Dedicated Host. + // The ID of instance that is running on the Dedicated Host. InstanceId *string `locationName:"instanceId" type:"string"` - // The instance type size (for example, m3.medium) of the running instance. + // The instance type (for example, m3.medium) of the running instance. InstanceType *string `locationName:"instanceType" type:"string"` + + // The ID of the AWS account that owns the instance. + OwnerId *string `locationName:"ownerId" type:"string"` } // String returns the string representation @@ -67181,6 +69435,12 @@ func (s *HostInstance) SetInstanceType(v string) *HostInstance { return s } +// SetOwnerId sets the OwnerId field's value. +func (s *HostInstance) SetOwnerId(v string) *HostInstance { + s.OwnerId = &v + return s +} + // Details about the Dedicated Host Reservation offering. type HostOffering struct { _ struct{} `type:"structure"` @@ -67259,20 +69519,24 @@ func (s *HostOffering) SetUpfrontPrice(v string) *HostOffering { return s } -// Describes properties of a Dedicated Host. +// Describes the properties of a Dedicated Host. type HostProperties struct { _ struct{} `type:"structure"` // The number of cores on the Dedicated Host. Cores *int64 `locationName:"cores" type:"integer"` - // The instance type size that the Dedicated Host supports (for example, m3.medium). + // The instance family supported by the Dedicated Host. For example, m5. + InstanceFamily *string `locationName:"instanceFamily" type:"string"` + + // The instance type supported by the Dedicated Host. For example, m5.large. + // If the host supports multiple instance types, no instanceType is returned. InstanceType *string `locationName:"instanceType" type:"string"` // The number of sockets on the Dedicated Host. Sockets *int64 `locationName:"sockets" type:"integer"` - // The number of vCPUs on the Dedicated Host. + // The total number of vCPUs on the Dedicated Host. TotalVCpus *int64 `locationName:"totalVCpus" type:"integer"` } @@ -67292,6 +69556,12 @@ func (s *HostProperties) SetCores(v int64) *HostProperties { return s } +// SetInstanceFamily sets the InstanceFamily field's value. +func (s *HostProperties) SetInstanceFamily(v string) *HostProperties { + s.InstanceFamily = &v + return s +} + // SetInstanceType sets the InstanceType field's value. func (s *HostProperties) SetInstanceType(v string) *HostProperties { s.InstanceType = &v @@ -68175,6 +70445,9 @@ type ImportImageInput struct { // The specified CMK must exist in the Region that the AMI is being copied to. KmsKeyId *string `type:"string"` + // The ARNs of the license configurations. + LicenseSpecifications []*ImportImageLicenseConfigurationRequest `locationNameList:"item" type:"list"` + // The license type to be used for the Amazon Machine Image (AMI) after importing. // // By default, we detect the source-system operating system (OS) and apply the @@ -68261,6 +70534,12 @@ func (s *ImportImageInput) SetKmsKeyId(v string) *ImportImageInput { return s } +// SetLicenseSpecifications sets the LicenseSpecifications field's value. +func (s *ImportImageInput) SetLicenseSpecifications(v []*ImportImageLicenseConfigurationRequest) *ImportImageInput { + s.LicenseSpecifications = v + return s +} + // SetLicenseType sets the LicenseType field's value. func (s *ImportImageInput) SetLicenseType(v string) *ImportImageInput { s.LicenseType = &v @@ -68279,6 +70558,54 @@ func (s *ImportImageInput) SetRoleName(v string) *ImportImageInput { return s } +// The request information of license configurations. +type ImportImageLicenseConfigurationRequest struct { + _ struct{} `type:"structure"` + + // The ARN of a license configuration. + LicenseConfigurationArn *string `type:"string"` +} + +// String returns the string representation +func (s ImportImageLicenseConfigurationRequest) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s ImportImageLicenseConfigurationRequest) GoString() string { + return s.String() +} + +// SetLicenseConfigurationArn sets the LicenseConfigurationArn field's value. +func (s *ImportImageLicenseConfigurationRequest) SetLicenseConfigurationArn(v string) *ImportImageLicenseConfigurationRequest { + s.LicenseConfigurationArn = &v + return s +} + +// The response information of license configurations. +type ImportImageLicenseConfigurationResponse struct { + _ struct{} `type:"structure"` + + // The ARN of a license configuration. + LicenseConfigurationArn *string `locationName:"licenseConfigurationArn" type:"string"` +} + +// String returns the string representation +func (s ImportImageLicenseConfigurationResponse) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s ImportImageLicenseConfigurationResponse) GoString() string { + return s.String() +} + +// SetLicenseConfigurationArn sets the LicenseConfigurationArn field's value. +func (s *ImportImageLicenseConfigurationResponse) SetLicenseConfigurationArn(v string) *ImportImageLicenseConfigurationResponse { + s.LicenseConfigurationArn = &v + return s +} + type ImportImageOutput struct { _ struct{} `type:"structure"` @@ -68304,6 +70631,9 @@ type ImportImageOutput struct { // key (CMK) that was used to create the encrypted AMI. KmsKeyId *string `locationName:"kmsKeyId" type:"string"` + // The ARNs of the license configurations. + LicenseSpecifications []*ImportImageLicenseConfigurationResponse `locationName:"licenseSpecifications" locationNameList:"item" type:"list"` + // The license type of the virtual machine. LicenseType *string `locationName:"licenseType" type:"string"` @@ -68375,6 +70705,12 @@ func (s *ImportImageOutput) SetKmsKeyId(v string) *ImportImageOutput { return s } +// SetLicenseSpecifications sets the LicenseSpecifications field's value. +func (s *ImportImageOutput) SetLicenseSpecifications(v []*ImportImageLicenseConfigurationResponse) *ImportImageOutput { + s.LicenseSpecifications = v + return s +} + // SetLicenseType sets the LicenseType field's value. func (s *ImportImageOutput) SetLicenseType(v string) *ImportImageOutput { s.LicenseType = &v @@ -68441,6 +70777,9 @@ type ImportImageTask struct { // key (CMK) that was used to create the encrypted image. KmsKeyId *string `locationName:"kmsKeyId" type:"string"` + // The ARNs of the license configurations associated to the import image task. + LicenseSpecifications []*ImportImageLicenseConfigurationResponse `locationName:"licenseSpecifications" locationNameList:"item" type:"list"` + // The license type of the virtual machine. LicenseType *string `locationName:"licenseType" type:"string"` @@ -68512,6 +70851,12 @@ func (s *ImportImageTask) SetKmsKeyId(v string) *ImportImageTask { return s } +// SetLicenseSpecifications sets the LicenseSpecifications field's value. +func (s *ImportImageTask) SetLicenseSpecifications(v []*ImportImageLicenseConfigurationResponse) *ImportImageTask { + s.LicenseSpecifications = v + return s +} + // SetLicenseType sets the LicenseType field's value. func (s *ImportImageTask) SetLicenseType(v string) *ImportImageTask { s.LicenseType = &v @@ -69462,6 +71807,9 @@ type Instance struct { // The license configurations. Licenses []*LicenseConfiguration `locationName:"licenseSet" locationNameList:"item" type:"list"` + // The metadata options for the instance. + MetadataOptions *InstanceMetadataOptionsResponse `locationName:"metadataOptions" type:"structure"` + // The monitoring for the instance. Monitoring *Monitoring `locationName:"monitoring" type:"structure"` @@ -69690,6 +72038,12 @@ func (s *Instance) SetLicenses(v []*LicenseConfiguration) *Instance { return s } +// SetMetadataOptions sets the MetadataOptions field's value. +func (s *Instance) SetMetadataOptions(v *InstanceMetadataOptionsResponse) *Instance { + s.MetadataOptions = v + return s +} + // SetMonitoring sets the Monitoring field's value. func (s *Instance) SetMonitoring(v *Monitoring) *Instance { s.Monitoring = v @@ -69914,17 +72268,20 @@ func (s *InstanceBlockDeviceMappingSpecification) SetVirtualName(v string) *Inst return s } -// Information about the instance type that the Dedicated Host supports. +// Information about the number of instances that can be launched onto the Dedicated +// Host. type InstanceCapacity struct { _ struct{} `type:"structure"` - // The number of instances that can still be launched onto the Dedicated Host. + // The number of instances that can be launched onto the Dedicated Host based + // on the host's available capacity. AvailableCapacity *int64 `locationName:"availableCapacity" type:"integer"` - // The instance type size supported by the Dedicated Host. + // The instance type supported by the Dedicated Host. InstanceType *string `locationName:"instanceType" type:"string"` - // The total number of instances that can be launched onto the Dedicated Host. + // The total number of instances that can be launched onto the Dedicated Host + // if there are no instances running on it. TotalCapacity *int64 `locationName:"totalCapacity" type:"integer"` } @@ -70171,6 +72528,146 @@ func (s *InstanceMarketOptionsRequest) SetSpotOptions(v *SpotMarketOptions) *Ins return s } +// The metadata options for the instance. +type InstanceMetadataOptionsRequest struct { + _ struct{} `type:"structure"` + + // This parameter enables or disables the HTTP metadata endpoint on your instances. + // If the parameter is not specified, the default state is enabled. + // + // If you specify a value of disabled, you will not be able to access your instance + // metadata. + HttpEndpoint *string `type:"string" enum:"InstanceMetadataEndpointState"` + + // The desired HTTP PUT response hop limit for instance metadata requests. The + // larger the number, the further instance metadata requests can travel. + // + // Default: 1 + // + // Possible values: Integers from 1 to 64 + HttpPutResponseHopLimit *int64 `type:"integer"` + + // The state of token usage for your instance metadata requests. If the parameter + // is not specified in the request, the default state is optional. + // + // If the state is optional, you can choose to retrieve instance metadata with + // or without a signed token header on your request. If you retrieve the IAM + // role credentials without a token, the version 1.0 role credentials are returned. + // If you retrieve the IAM role credentials using a valid signed token, the + // version 2.0 role credentials are returned. + // + // If the state is required, you must send a signed token header with any instance + // metadata retrieval requests. In this state, retrieving the IAM role credentials + // always returns the version 2.0 credentials; the version 1.0 credentials are + // not available. + HttpTokens *string `type:"string" enum:"HttpTokensState"` +} + +// String returns the string representation +func (s InstanceMetadataOptionsRequest) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s InstanceMetadataOptionsRequest) GoString() string { + return s.String() +} + +// SetHttpEndpoint sets the HttpEndpoint field's value. +func (s *InstanceMetadataOptionsRequest) SetHttpEndpoint(v string) *InstanceMetadataOptionsRequest { + s.HttpEndpoint = &v + return s +} + +// SetHttpPutResponseHopLimit sets the HttpPutResponseHopLimit field's value. +func (s *InstanceMetadataOptionsRequest) SetHttpPutResponseHopLimit(v int64) *InstanceMetadataOptionsRequest { + s.HttpPutResponseHopLimit = &v + return s +} + +// SetHttpTokens sets the HttpTokens field's value. +func (s *InstanceMetadataOptionsRequest) SetHttpTokens(v string) *InstanceMetadataOptionsRequest { + s.HttpTokens = &v + return s +} + +// The metadata options for the instance. +type InstanceMetadataOptionsResponse struct { + _ struct{} `type:"structure"` + + // This parameter enables or disables the HTTP metadata endpoint on your instances. + // If the parameter is not specified, the default state is enabled. + // + // If you specify a value of disabled, you will not be able to access your instance + // metadata. + HttpEndpoint *string `locationName:"httpEndpoint" type:"string" enum:"InstanceMetadataEndpointState"` + + // The desired HTTP PUT response hop limit for instance metadata requests. The + // larger the number, the further instance metadata requests can travel. + // + // Default: 1 + // + // Possible values: Integers from 1 to 64 + HttpPutResponseHopLimit *int64 `locationName:"httpPutResponseHopLimit" type:"integer"` + + // The state of token usage for your instance metadata requests. If the parameter + // is not specified in the request, the default state is optional. + // + // If the state is optional, you can choose to retrieve instance metadata with + // or without a signed token header on your request. If you retrieve the IAM + // role credentials without a token, the version 1.0 role credentials are returned. + // If you retrieve the IAM role credentials using a valid signed token, the + // version 2.0 role credentials are returned. + // + // If the state is required, you must send a signed token header with any instance + // metadata retrieval requests. In this state, retrieving the IAM role credential + // always returns the version 2.0 credentials; the version 1.0 credentials are + // not available. + HttpTokens *string `locationName:"httpTokens" type:"string" enum:"HttpTokensState"` + + // The state of the metadata option changes. + // + // pending - The metadata options are being updated and the instance is not + // ready to process metadata traffic with the new selection. + // + // applied - The metadata options have been successfully applied on the instance. + State *string `locationName:"state" type:"string" enum:"InstanceMetadataOptionsState"` +} + +// String returns the string representation +func (s InstanceMetadataOptionsResponse) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s InstanceMetadataOptionsResponse) GoString() string { + return s.String() +} + +// SetHttpEndpoint sets the HttpEndpoint field's value. +func (s *InstanceMetadataOptionsResponse) SetHttpEndpoint(v string) *InstanceMetadataOptionsResponse { + s.HttpEndpoint = &v + return s +} + +// SetHttpPutResponseHopLimit sets the HttpPutResponseHopLimit field's value. +func (s *InstanceMetadataOptionsResponse) SetHttpPutResponseHopLimit(v int64) *InstanceMetadataOptionsResponse { + s.HttpPutResponseHopLimit = &v + return s +} + +// SetHttpTokens sets the HttpTokens field's value. +func (s *InstanceMetadataOptionsResponse) SetHttpTokens(v string) *InstanceMetadataOptionsResponse { + s.HttpTokens = &v + return s +} + +// SetState sets the State field's value. +func (s *InstanceMetadataOptionsResponse) SetState(v string) *InstanceMetadataOptionsResponse { + s.State = &v + return s +} + // Describes the monitoring of an instance. type InstanceMonitoring struct { _ struct{} `type:"structure"` @@ -71044,6 +73541,289 @@ func (s *InstanceStatusSummary) SetStatus(v string) *InstanceStatusSummary { return s } +// Describes the disks that are available for the instance type. +type InstanceStorageInfo struct { + _ struct{} `type:"structure"` + + // Array describing the disks that are available for the instance type. + Disks []*DiskInfo `locationName:"disks" locationNameList:"item" type:"list"` + + // The total size of the disks, in GiB. + TotalSizeInGB *int64 `locationName:"totalSizeInGB" type:"long"` +} + +// String returns the string representation +func (s InstanceStorageInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s InstanceStorageInfo) GoString() string { + return s.String() +} + +// SetDisks sets the Disks field's value. +func (s *InstanceStorageInfo) SetDisks(v []*DiskInfo) *InstanceStorageInfo { + s.Disks = v + return s +} + +// SetTotalSizeInGB sets the TotalSizeInGB field's value. +func (s *InstanceStorageInfo) SetTotalSizeInGB(v int64) *InstanceStorageInfo { + s.TotalSizeInGB = &v + return s +} + +// Describes the instance type. +type InstanceTypeInfo struct { + _ struct{} `type:"structure"` + + // Indicates whether auto recovery is supported. + AutoRecoverySupported *bool `locationName:"autoRecoverySupported" type:"boolean"` + + // Indicates whether the instance is bare metal. + BareMetal *bool `locationName:"bareMetal" type:"boolean"` + + // Indicates whether the instance type is a burstable performance instance type. + BurstablePerformanceSupported *bool `locationName:"burstablePerformanceSupported" type:"boolean"` + + // Indicates whether the instance type is a current generation. + CurrentGeneration *bool `locationName:"currentGeneration" type:"boolean"` + + // Indicates whether Dedicated Hosts are supported on the instance type. + DedicatedHostsSupported *bool `locationName:"dedicatedHostsSupported" type:"boolean"` + + // Describes the Amazon EBS settings for the instance type. + EbsInfo *EbsInfo `locationName:"ebsInfo" type:"structure"` + + // Describes the FPGA accelerator settings for the instance type. + FpgaInfo *FpgaInfo `locationName:"fpgaInfo" type:"structure"` + + // Indicates whether the instance type is eligible for the free tier. + FreeTierEligible *bool `locationName:"freeTierEligible" type:"boolean"` + + // Describes the GPU accelerator settings for the instance type. + GpuInfo *GpuInfo `locationName:"gpuInfo" type:"structure"` + + // Indicates whether On-Demand hibernation is supported. + HibernationSupported *bool `locationName:"hibernationSupported" type:"boolean"` + + // Indicates the hypervisor used for the instance type. + Hypervisor *string `locationName:"hypervisor" type:"string" enum:"InstanceTypeHypervisor"` + + // Describes the disks for the instance type. + InstanceStorageInfo *InstanceStorageInfo `locationName:"instanceStorageInfo" type:"structure"` + + // Indicates whether instance storage is supported. + InstanceStorageSupported *bool `locationName:"instanceStorageSupported" type:"boolean"` + + // The instance type. For more information, see Instance Types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) + // in the Amazon Elastic Compute Cloud User Guide. + InstanceType *string `locationName:"instanceType" type:"string" enum:"InstanceType"` + + // Describes the memory for the instance type. + MemoryInfo *MemoryInfo `locationName:"memoryInfo" type:"structure"` + + // Describes the network settings for the instance type. + NetworkInfo *NetworkInfo `locationName:"networkInfo" type:"structure"` + + // Describes the placement group settings for the instance type. + PlacementGroupInfo *PlacementGroupInfo `locationName:"placementGroupInfo" type:"structure"` + + // Describes the processor. + ProcessorInfo *ProcessorInfo `locationName:"processorInfo" type:"structure"` + + // Indicates the supported root devices. + SupportedRootDevices []*string `locationName:"supportedRootDevices" locationNameList:"item" type:"list"` + + // Indicates whether the instance type is offered for spot or On-Demand. + SupportedUsageClasses []*string `locationName:"supportedUsageClasses" locationNameList:"item" type:"list"` + + // Describes the vCPU configurations for the instance type. + VCpuInfo *VCpuInfo `locationName:"vCpuInfo" type:"structure"` +} + +// String returns the string representation +func (s InstanceTypeInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s InstanceTypeInfo) GoString() string { + return s.String() +} + +// SetAutoRecoverySupported sets the AutoRecoverySupported field's value. +func (s *InstanceTypeInfo) SetAutoRecoverySupported(v bool) *InstanceTypeInfo { + s.AutoRecoverySupported = &v + return s +} + +// SetBareMetal sets the BareMetal field's value. +func (s *InstanceTypeInfo) SetBareMetal(v bool) *InstanceTypeInfo { + s.BareMetal = &v + return s +} + +// SetBurstablePerformanceSupported sets the BurstablePerformanceSupported field's value. +func (s *InstanceTypeInfo) SetBurstablePerformanceSupported(v bool) *InstanceTypeInfo { + s.BurstablePerformanceSupported = &v + return s +} + +// SetCurrentGeneration sets the CurrentGeneration field's value. +func (s *InstanceTypeInfo) SetCurrentGeneration(v bool) *InstanceTypeInfo { + s.CurrentGeneration = &v + return s +} + +// SetDedicatedHostsSupported sets the DedicatedHostsSupported field's value. +func (s *InstanceTypeInfo) SetDedicatedHostsSupported(v bool) *InstanceTypeInfo { + s.DedicatedHostsSupported = &v + return s +} + +// SetEbsInfo sets the EbsInfo field's value. +func (s *InstanceTypeInfo) SetEbsInfo(v *EbsInfo) *InstanceTypeInfo { + s.EbsInfo = v + return s +} + +// SetFpgaInfo sets the FpgaInfo field's value. +func (s *InstanceTypeInfo) SetFpgaInfo(v *FpgaInfo) *InstanceTypeInfo { + s.FpgaInfo = v + return s +} + +// SetFreeTierEligible sets the FreeTierEligible field's value. +func (s *InstanceTypeInfo) SetFreeTierEligible(v bool) *InstanceTypeInfo { + s.FreeTierEligible = &v + return s +} + +// SetGpuInfo sets the GpuInfo field's value. +func (s *InstanceTypeInfo) SetGpuInfo(v *GpuInfo) *InstanceTypeInfo { + s.GpuInfo = v + return s +} + +// SetHibernationSupported sets the HibernationSupported field's value. +func (s *InstanceTypeInfo) SetHibernationSupported(v bool) *InstanceTypeInfo { + s.HibernationSupported = &v + return s +} + +// SetHypervisor sets the Hypervisor field's value. +func (s *InstanceTypeInfo) SetHypervisor(v string) *InstanceTypeInfo { + s.Hypervisor = &v + return s +} + +// SetInstanceStorageInfo sets the InstanceStorageInfo field's value. +func (s *InstanceTypeInfo) SetInstanceStorageInfo(v *InstanceStorageInfo) *InstanceTypeInfo { + s.InstanceStorageInfo = v + return s +} + +// SetInstanceStorageSupported sets the InstanceStorageSupported field's value. +func (s *InstanceTypeInfo) SetInstanceStorageSupported(v bool) *InstanceTypeInfo { + s.InstanceStorageSupported = &v + return s +} + +// SetInstanceType sets the InstanceType field's value. +func (s *InstanceTypeInfo) SetInstanceType(v string) *InstanceTypeInfo { + s.InstanceType = &v + return s +} + +// SetMemoryInfo sets the MemoryInfo field's value. +func (s *InstanceTypeInfo) SetMemoryInfo(v *MemoryInfo) *InstanceTypeInfo { + s.MemoryInfo = v + return s +} + +// SetNetworkInfo sets the NetworkInfo field's value. +func (s *InstanceTypeInfo) SetNetworkInfo(v *NetworkInfo) *InstanceTypeInfo { + s.NetworkInfo = v + return s +} + +// SetPlacementGroupInfo sets the PlacementGroupInfo field's value. +func (s *InstanceTypeInfo) SetPlacementGroupInfo(v *PlacementGroupInfo) *InstanceTypeInfo { + s.PlacementGroupInfo = v + return s +} + +// SetProcessorInfo sets the ProcessorInfo field's value. +func (s *InstanceTypeInfo) SetProcessorInfo(v *ProcessorInfo) *InstanceTypeInfo { + s.ProcessorInfo = v + return s +} + +// SetSupportedRootDevices sets the SupportedRootDevices field's value. +func (s *InstanceTypeInfo) SetSupportedRootDevices(v []*string) *InstanceTypeInfo { + s.SupportedRootDevices = v + return s +} + +// SetSupportedUsageClasses sets the SupportedUsageClasses field's value. +func (s *InstanceTypeInfo) SetSupportedUsageClasses(v []*string) *InstanceTypeInfo { + s.SupportedUsageClasses = v + return s +} + +// SetVCpuInfo sets the VCpuInfo field's value. +func (s *InstanceTypeInfo) SetVCpuInfo(v *VCpuInfo) *InstanceTypeInfo { + s.VCpuInfo = v + return s +} + +// The instance types offered. +type InstanceTypeOffering struct { + _ struct{} `type:"structure"` + + // The instance type. For more information, see Instance Types (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) + // in the Amazon Elastic Compute Cloud User Guide. + InstanceType *string `locationName:"instanceType" type:"string" enum:"InstanceType"` + + // The identifier for the location. This depends on the location type. For example, + // if the location type is region, the location is the Region code (for example, + // us-east-2.) + Location *string `locationName:"location" type:"string"` + + // The location type. + LocationType *string `locationName:"locationType" type:"string" enum:"LocationType"` +} + +// String returns the string representation +func (s InstanceTypeOffering) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s InstanceTypeOffering) GoString() string { + return s.String() +} + +// SetInstanceType sets the InstanceType field's value. +func (s *InstanceTypeOffering) SetInstanceType(v string) *InstanceTypeOffering { + s.InstanceType = &v + return s +} + +// SetLocation sets the Location field's value. +func (s *InstanceTypeOffering) SetLocation(v string) *InstanceTypeOffering { + s.Location = &v + return s +} + +// SetLocationType sets the LocationType field's value. +func (s *InstanceTypeOffering) SetLocationType(v string) *InstanceTypeOffering { + s.LocationType = &v + return s +} + // Information about the Capacity Reservation usage. type InstanceUsage struct { _ struct{} `type:"structure"` @@ -73577,6 +76357,30 @@ func (s *LoadPermissionRequest) SetUserId(v string) *LoadPermissionRequest { return s } +// Describes the memory for the instance type. +type MemoryInfo struct { + _ struct{} `type:"structure"` + + // Size of the memory, in MiB. + SizeInMiB *int64 `locationName:"sizeInMiB" type:"long"` +} + +// String returns the string representation +func (s MemoryInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s MemoryInfo) GoString() string { + return s.String() +} + +// SetSizeInMiB sets the SizeInMiB field's value. +func (s *MemoryInfo) SetSizeInMiB(v int64) *MemoryInfo { + s.SizeInMiB = &v + return s +} + type ModifyCapacityReservationInput struct { _ struct{} `type:"structure"` @@ -74185,6 +76989,24 @@ type ModifyHostsInput struct { // For more information, see Host Recovery (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/dedicated-hosts-recovery.html) // in the Amazon Elastic Compute Cloud User Guide. HostRecovery *string `type:"string" enum:"HostRecovery"` + + // Specifies the instance family to be supported by the Dedicated Host. Specify + // this parameter to modify a Dedicated Host to support multiple instance types + // within its current instance family. + // + // If you want to modify a Dedicated Host to support a specific instance type + // only, omit this parameter and specify InstanceType instead. You cannot specify + // InstanceFamily and InstanceType in the same request. + InstanceFamily *string `type:"string"` + + // Specifies the instance type to be supported by the Dedicated Host. Specify + // this parameter to modify a Dedicated Host to support only a specific instance + // type. + // + // If you want to modify a Dedicated Host to support multiple instance types + // in its current instance family, omit this parameter and specify InstanceFamily + // instead. You cannot specify InstanceType and InstanceFamily in the same request. + InstanceType *string `type:"string"` } // String returns the string representation @@ -74228,6 +77050,18 @@ func (s *ModifyHostsInput) SetHostRecovery(v string) *ModifyHostsInput { return s } +// SetInstanceFamily sets the InstanceFamily field's value. +func (s *ModifyHostsInput) SetInstanceFamily(v string) *ModifyHostsInput { + s.InstanceFamily = &v + return s +} + +// SetInstanceType sets the InstanceType field's value. +func (s *ModifyHostsInput) SetInstanceType(v string) *ModifyHostsInput { + s.InstanceType = &v + return s +} + type ModifyHostsOutput struct { _ struct{} `type:"structure"` @@ -75082,6 +77916,135 @@ func (s *ModifyInstanceEventStartTimeOutput) SetEvent(v *InstanceStatusEvent) *M return s } +type ModifyInstanceMetadataOptionsInput struct { + _ struct{} `type:"structure"` + + // Checks whether you have the required permissions for the action, without + // actually making the request, and provides an error response. If you have + // the required permissions, the error response is DryRunOperation. Otherwise, + // it is UnauthorizedOperation. + DryRun *bool `type:"boolean"` + + // This parameter enables or disables the HTTP metadata endpoint on your instances. + // If the parameter is not specified, the existing state is maintained. + // + // If you specify a value of disabled, you will not be able to access your instance + // metadata. + HttpEndpoint *string `type:"string" enum:"InstanceMetadataEndpointState"` + + // The desired HTTP PUT response hop limit for instance metadata requests. The + // larger the number, the further instance metadata requests can travel. If + // no parameter is specified, the existing state is maintained. + // + // Possible values: Integers from 1 to 64 + HttpPutResponseHopLimit *int64 `type:"integer"` + + // The state of token usage for your instance metadata requests. If the parameter + // is not specified in the request, the default state is optional. + // + // If the state is optional, you can choose to retrieve instance metadata with + // or without a signed token header on your request. If you retrieve the IAM + // role credentials without a token, the version 1.0 role credentials are returned. + // If you retrieve the IAM role credentials using a valid signed token, the + // version 2.0 role credentials are returned. + // + // If the state is required, you must send a signed token header with any instance + // metadata retrieval requests. In this state, retrieving the IAM role credential + // always returns the version 2.0 credentials; the version 1.0 credentials are + // not available. + HttpTokens *string `type:"string" enum:"HttpTokensState"` + + // The ID of the instance. + // + // InstanceId is a required field + InstanceId *string `type:"string" required:"true"` +} + +// String returns the string representation +func (s ModifyInstanceMetadataOptionsInput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s ModifyInstanceMetadataOptionsInput) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *ModifyInstanceMetadataOptionsInput) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "ModifyInstanceMetadataOptionsInput"} + if s.InstanceId == nil { + invalidParams.Add(request.NewErrParamRequired("InstanceId")) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetDryRun sets the DryRun field's value. +func (s *ModifyInstanceMetadataOptionsInput) SetDryRun(v bool) *ModifyInstanceMetadataOptionsInput { + s.DryRun = &v + return s +} + +// SetHttpEndpoint sets the HttpEndpoint field's value. +func (s *ModifyInstanceMetadataOptionsInput) SetHttpEndpoint(v string) *ModifyInstanceMetadataOptionsInput { + s.HttpEndpoint = &v + return s +} + +// SetHttpPutResponseHopLimit sets the HttpPutResponseHopLimit field's value. +func (s *ModifyInstanceMetadataOptionsInput) SetHttpPutResponseHopLimit(v int64) *ModifyInstanceMetadataOptionsInput { + s.HttpPutResponseHopLimit = &v + return s +} + +// SetHttpTokens sets the HttpTokens field's value. +func (s *ModifyInstanceMetadataOptionsInput) SetHttpTokens(v string) *ModifyInstanceMetadataOptionsInput { + s.HttpTokens = &v + return s +} + +// SetInstanceId sets the InstanceId field's value. +func (s *ModifyInstanceMetadataOptionsInput) SetInstanceId(v string) *ModifyInstanceMetadataOptionsInput { + s.InstanceId = &v + return s +} + +type ModifyInstanceMetadataOptionsOutput struct { + _ struct{} `type:"structure"` + + // The ID of the instance. + InstanceId *string `locationName:"instanceId" type:"string"` + + // The metadata options for the instance. + InstanceMetadataOptions *InstanceMetadataOptionsResponse `locationName:"instanceMetadataOptions" type:"structure"` +} + +// String returns the string representation +func (s ModifyInstanceMetadataOptionsOutput) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s ModifyInstanceMetadataOptionsOutput) GoString() string { + return s.String() +} + +// SetInstanceId sets the InstanceId field's value. +func (s *ModifyInstanceMetadataOptionsOutput) SetInstanceId(v string) *ModifyInstanceMetadataOptionsOutput { + s.InstanceId = &v + return s +} + +// SetInstanceMetadataOptions sets the InstanceMetadataOptions field's value. +func (s *ModifyInstanceMetadataOptionsOutput) SetInstanceMetadataOptions(v *InstanceMetadataOptionsResponse) *ModifyInstanceMetadataOptionsOutput { + s.InstanceMetadataOptions = v + return s +} + type ModifyInstancePlacementInput struct { _ struct{} `type:"structure"` @@ -75492,7 +78455,6 @@ func (s *ModifyReservedInstancesOutput) SetReservedInstancesModificationId(v str return s } -// Contains the parameters for ModifySnapshotAttribute. type ModifySnapshotAttributeInput struct { _ struct{} `type:"structure"` @@ -76314,7 +79276,6 @@ func (s *ModifyTransitGatewayVpcAttachmentRequestOptions) SetIpv6Support(v strin return s } -// Contains the parameters for ModifyVolumeAttribute. type ModifyVolumeAttributeInput struct { _ struct{} `type:"structure"` @@ -78355,6 +81316,75 @@ func (s *NetworkAclEntry) SetRuleNumber(v int64) *NetworkAclEntry { return s } +// Describes the networking features of the instance type. +type NetworkInfo struct { + _ struct{} `type:"structure"` + + // Indicates whether Elastic Network Adapter (ENA) is supported. + EnaSupport *string `locationName:"enaSupport" type:"string" enum:"EnaSupport"` + + // The maximum number of IPv4 addresses per network interface. + Ipv4AddressesPerInterface *int64 `locationName:"ipv4AddressesPerInterface" type:"integer"` + + // The maximum number of IPv6 addresses per network interface. + Ipv6AddressesPerInterface *int64 `locationName:"ipv6AddressesPerInterface" type:"integer"` + + // Indicates whether IPv6 is supported. + Ipv6Supported *bool `locationName:"ipv6Supported" type:"boolean"` + + // The maximum number of network interfaces for the instance type. + MaximumNetworkInterfaces *int64 `locationName:"maximumNetworkInterfaces" type:"integer"` + + // Describes the network performance. + NetworkPerformance *string `locationName:"networkPerformance" type:"string"` +} + +// String returns the string representation +func (s NetworkInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s NetworkInfo) GoString() string { + return s.String() +} + +// SetEnaSupport sets the EnaSupport field's value. +func (s *NetworkInfo) SetEnaSupport(v string) *NetworkInfo { + s.EnaSupport = &v + return s +} + +// SetIpv4AddressesPerInterface sets the Ipv4AddressesPerInterface field's value. +func (s *NetworkInfo) SetIpv4AddressesPerInterface(v int64) *NetworkInfo { + s.Ipv4AddressesPerInterface = &v + return s +} + +// SetIpv6AddressesPerInterface sets the Ipv6AddressesPerInterface field's value. +func (s *NetworkInfo) SetIpv6AddressesPerInterface(v int64) *NetworkInfo { + s.Ipv6AddressesPerInterface = &v + return s +} + +// SetIpv6Supported sets the Ipv6Supported field's value. +func (s *NetworkInfo) SetIpv6Supported(v bool) *NetworkInfo { + s.Ipv6Supported = &v + return s +} + +// SetMaximumNetworkInterfaces sets the MaximumNetworkInterfaces field's value. +func (s *NetworkInfo) SetMaximumNetworkInterfaces(v int64) *NetworkInfo { + s.MaximumNetworkInterfaces = &v + return s +} + +// SetNetworkPerformance sets the NetworkPerformance field's value. +func (s *NetworkInfo) SetNetworkPerformance(v string) *NetworkInfo { + s.NetworkPerformance = &v + return s +} + // Describes a network interface. type NetworkInterface struct { _ struct{} `type:"structure"` @@ -79639,6 +82669,30 @@ func (s *PlacementGroup) SetStrategy(v string) *PlacementGroup { return s } +// Describes the placement group support of the instance type. +type PlacementGroupInfo struct { + _ struct{} `type:"structure"` + + // A list of supported placement groups types. + SupportedStrategies []*string `locationName:"supportedStrategies" locationNameList:"item" type:"list"` +} + +// String returns the string representation +func (s PlacementGroupInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s PlacementGroupInfo) GoString() string { + return s.String() +} + +// SetSupportedStrategies sets the SupportedStrategies field's value. +func (s *PlacementGroupInfo) SetSupportedStrategies(v []*string) *PlacementGroupInfo { + s.SupportedStrategies = v + return s +} + // Describes the placement of an instance. type PlacementResponse struct { _ struct{} `type:"structure"` @@ -79981,6 +83035,39 @@ func (s *PrivateIpAddressSpecification) SetPrivateIpAddress(v string) *PrivateIp return s } +// Describes the processor used by the instance type. +type ProcessorInfo struct { + _ struct{} `type:"structure"` + + // A list of architectures supported by the instance type. + SupportedArchitectures []*string `locationName:"supportedArchitectures" locationNameList:"item" type:"list"` + + // The speed of the processor, in GHz. + SustainedClockSpeedInGhz *float64 `locationName:"sustainedClockSpeedInGhz" type:"double"` +} + +// String returns the string representation +func (s ProcessorInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s ProcessorInfo) GoString() string { + return s.String() +} + +// SetSupportedArchitectures sets the SupportedArchitectures field's value. +func (s *ProcessorInfo) SetSupportedArchitectures(v []*string) *ProcessorInfo { + s.SupportedArchitectures = v + return s +} + +// SetSustainedClockSpeedInGhz sets the SustainedClockSpeedInGhz field's value. +func (s *ProcessorInfo) SetSustainedClockSpeedInGhz(v float64) *ProcessorInfo { + s.SustainedClockSpeedInGhz = &v + return s +} + // Describes a product code. type ProductCode struct { _ struct{} `type:"structure"` @@ -84341,7 +87428,6 @@ func (s ResetNetworkInterfaceAttributeOutput) GoString() string { return s.String() } -// Contains the parameters for ResetSnapshotAttribute. type ResetSnapshotAttributeInput struct { _ struct{} `type:"structure"` @@ -85582,6 +88668,10 @@ type RunInstancesInput struct { // MaxCount is a required field MaxCount *int64 `type:"integer" required:"true"` + // The metadata options for the instance. For more information, see Instance + // Metadata and User Data (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html). + MetadataOptions *InstanceMetadataOptionsRequest `type:"structure"` + // The minimum number of instances to launch. If you specify a minimum that // is more instances than Amazon EC2 can launch in the target Availability Zone, // Amazon EC2 launches no instances. @@ -85864,6 +88954,12 @@ func (s *RunInstancesInput) SetMaxCount(v int64) *RunInstancesInput { return s } +// SetMetadataOptions sets the MetadataOptions field's value. +func (s *RunInstancesInput) SetMetadataOptions(v *InstanceMetadataOptionsRequest) *RunInstancesInput { + s.MetadataOptions = v + return s +} + // SetMinCount sets the MinCount field's value. func (s *RunInstancesInput) SetMinCount(v int64) *RunInstancesInput { s.MinCount = &v @@ -93530,6 +96626,68 @@ func (s *UserIdGroupPair) SetVpcPeeringConnectionId(v string) *UserIdGroupPair { return s } +// Describes the vCPU configurations for the instance type. +type VCpuInfo struct { + _ struct{} `type:"structure"` + + // The default number of cores for the instance type. + DefaultCores *int64 `locationName:"defaultCores" type:"integer"` + + // The default number of threads per core for the instance type. + DefaultThreadsPerCore *int64 `locationName:"defaultThreadsPerCore" type:"integer"` + + // The default number of vCPUs for the instance type. + DefaultVCpus *int64 `locationName:"defaultVCpus" type:"integer"` + + // List of the valid number of cores that can be configured for the instance + // type. + ValidCores []*int64 `locationName:"validCores" locationNameList:"item" type:"list"` + + // List of the valid number of threads per core that can be configured for the + // instance type. + ValidThreadsPerCore []*int64 `locationName:"validThreadsPerCore" locationNameList:"item" type:"list"` +} + +// String returns the string representation +func (s VCpuInfo) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s VCpuInfo) GoString() string { + return s.String() +} + +// SetDefaultCores sets the DefaultCores field's value. +func (s *VCpuInfo) SetDefaultCores(v int64) *VCpuInfo { + s.DefaultCores = &v + return s +} + +// SetDefaultThreadsPerCore sets the DefaultThreadsPerCore field's value. +func (s *VCpuInfo) SetDefaultThreadsPerCore(v int64) *VCpuInfo { + s.DefaultThreadsPerCore = &v + return s +} + +// SetDefaultVCpus sets the DefaultVCpus field's value. +func (s *VCpuInfo) SetDefaultVCpus(v int64) *VCpuInfo { + s.DefaultVCpus = &v + return s +} + +// SetValidCores sets the ValidCores field's value. +func (s *VCpuInfo) SetValidCores(v []*int64) *VCpuInfo { + s.ValidCores = v + return s +} + +// SetValidThreadsPerCore sets the ValidThreadsPerCore field's value. +func (s *VCpuInfo) SetValidThreadsPerCore(v []*int64) *VCpuInfo { + s.ValidThreadsPerCore = v + return s +} + // Describes telemetry for a VPN tunnel. type VgwTelemetry struct { _ struct{} `type:"structure"` @@ -93616,6 +96774,9 @@ type Volume struct { // Indicates whether the volume is encrypted. Encrypted *bool `locationName:"encrypted" type:"boolean"` + // Indicates whether the volume was created using fast snapshot restore. + FastRestored *bool `locationName:"fastRestored" type:"boolean"` + // The number of I/O operations per second (IOPS) that the volume supports. // For Provisioned IOPS SSD volumes, this represents the number of IOPS that // are provisioned for the volume. For General Purpose SSD volumes, this represents @@ -93693,6 +96854,12 @@ func (s *Volume) SetEncrypted(v bool) *Volume { return s } +// SetFastRestored sets the FastRestored field's value. +func (s *Volume) SetFastRestored(v bool) *Volume { + s.FastRestored = &v + return s +} + // SetIops sets the Iops field's value. func (s *Volume) SetIops(v int64) *Volume { s.Iops = &v @@ -95652,6 +98819,25 @@ const ( AllocationStrategyCapacityOptimized = "capacityOptimized" ) +const ( + // AllowsMultipleInstanceTypesOn is a AllowsMultipleInstanceTypes enum value + AllowsMultipleInstanceTypesOn = "on" + + // AllowsMultipleInstanceTypesOff is a AllowsMultipleInstanceTypes enum value + AllowsMultipleInstanceTypesOff = "off" +) + +const ( + // ArchitectureTypeI386 is a ArchitectureType enum value + ArchitectureTypeI386 = "i386" + + // ArchitectureTypeX8664 is a ArchitectureType enum value + ArchitectureTypeX8664 = "x86_64" + + // ArchitectureTypeArm64 is a ArchitectureType enum value + ArchitectureTypeArm64 = "arm64" +) + const ( // ArchitectureValuesI386 is a ArchitectureValues enum value ArchitectureValuesI386 = "i386" @@ -96087,6 +99273,14 @@ const ( DiskImageFormatVhd = "VHD" ) +const ( + // DiskTypeHdd is a DiskType enum value + DiskTypeHdd = "hdd" + + // DiskTypeSsd is a DiskType enum value + DiskTypeSsd = "ssd" +) + const ( // DnsSupportValueEnable is a DnsSupportValue enum value DnsSupportValueEnable = "enable" @@ -96103,6 +99297,25 @@ const ( DomainTypeStandard = "standard" ) +const ( + // EbsEncryptionSupportUnsupported is a EbsEncryptionSupport enum value + EbsEncryptionSupportUnsupported = "unsupported" + + // EbsEncryptionSupportSupported is a EbsEncryptionSupport enum value + EbsEncryptionSupportSupported = "supported" +) + +const ( + // EbsOptimizedSupportUnsupported is a EbsOptimizedSupport enum value + EbsOptimizedSupportUnsupported = "unsupported" + + // EbsOptimizedSupportSupported is a EbsOptimizedSupport enum value + EbsOptimizedSupportSupported = "supported" + + // EbsOptimizedSupportDefault is a EbsOptimizedSupport enum value + EbsOptimizedSupportDefault = "default" +) + const ( // ElasticGpuStateAttached is a ElasticGpuState enum value ElasticGpuStateAttached = "ATTACHED" @@ -96116,6 +99329,17 @@ const ( ElasticGpuStatusImpaired = "IMPAIRED" ) +const ( + // EnaSupportUnsupported is a EnaSupport enum value + EnaSupportUnsupported = "unsupported" + + // EnaSupportSupported is a EnaSupport enum value + EnaSupportSupported = "supported" + + // EnaSupportRequired is a EnaSupport enum value + EnaSupportRequired = "required" +) + const ( // EndDateTypeUnlimited is a EndDateType enum value EndDateTypeUnlimited = "unlimited" @@ -96188,6 +99412,23 @@ const ( ExportTaskStateCompleted = "completed" ) +const ( + // FastSnapshotRestoreStateCodeEnabling is a FastSnapshotRestoreStateCode enum value + FastSnapshotRestoreStateCodeEnabling = "enabling" + + // FastSnapshotRestoreStateCodeOptimizing is a FastSnapshotRestoreStateCode enum value + FastSnapshotRestoreStateCodeOptimizing = "optimizing" + + // FastSnapshotRestoreStateCodeEnabled is a FastSnapshotRestoreStateCode enum value + FastSnapshotRestoreStateCodeEnabled = "enabled" + + // FastSnapshotRestoreStateCodeDisabling is a FastSnapshotRestoreStateCode enum value + FastSnapshotRestoreStateCodeDisabling = "disabling" + + // FastSnapshotRestoreStateCodeDisabled is a FastSnapshotRestoreStateCode enum value + FastSnapshotRestoreStateCodeDisabled = "disabled" +) + const ( // FleetActivityStatusError is a FleetActivityStatus enum value FleetActivityStatusError = "error" @@ -96323,6 +99564,14 @@ const ( HostTenancyHost = "host" ) +const ( + // HttpTokensStateOptional is a HttpTokensState enum value + HttpTokensStateOptional = "optional" + + // HttpTokensStateRequired is a HttpTokensState enum value + HttpTokensStateRequired = "required" +) + const ( // HypervisorTypeOvm is a HypervisorType enum value HypervisorTypeOvm = "ovm" @@ -96489,6 +99738,22 @@ const ( InstanceMatchCriteriaTargeted = "targeted" ) +const ( + // InstanceMetadataEndpointStateDisabled is a InstanceMetadataEndpointState enum value + InstanceMetadataEndpointStateDisabled = "disabled" + + // InstanceMetadataEndpointStateEnabled is a InstanceMetadataEndpointState enum value + InstanceMetadataEndpointStateEnabled = "enabled" +) + +const ( + // InstanceMetadataOptionsStatePending is a InstanceMetadataOptionsState enum value + InstanceMetadataOptionsStatePending = "pending" + + // InstanceMetadataOptionsStateApplied is a InstanceMetadataOptionsState enum value + InstanceMetadataOptionsStateApplied = "applied" +) + const ( // InstanceStateNamePending is a InstanceStateName enum value InstanceStateNamePending = "pending" @@ -96930,9 +100195,18 @@ const ( // InstanceTypeC5d9xlarge is a InstanceType enum value InstanceTypeC5d9xlarge = "c5d.9xlarge" + // InstanceTypeC5d12xlarge is a InstanceType enum value + InstanceTypeC5d12xlarge = "c5d.12xlarge" + // InstanceTypeC5d18xlarge is a InstanceType enum value InstanceTypeC5d18xlarge = "c5d.18xlarge" + // InstanceTypeC5d24xlarge is a InstanceType enum value + InstanceTypeC5d24xlarge = "c5d.24xlarge" + + // InstanceTypeC5dMetal is a InstanceType enum value + InstanceTypeC5dMetal = "c5d.metal" + // InstanceTypeC5nLarge is a InstanceType enum value InstanceTypeC5nLarge = "c5n.large" @@ -97303,6 +100577,14 @@ const ( InstanceTypeR5n24xlarge = "r5n.24xlarge" ) +const ( + // InstanceTypeHypervisorNitro is a InstanceTypeHypervisor enum value + InstanceTypeHypervisorNitro = "nitro" + + // InstanceTypeHypervisorXen is a InstanceTypeHypervisor enum value + InstanceTypeHypervisorXen = "xen" +) + const ( // InterfacePermissionTypeInstanceAttach is a InterfacePermissionType enum value InterfacePermissionTypeInstanceAttach = "INSTANCE-ATTACH" @@ -97367,6 +100649,17 @@ const ( ListingStatusClosed = "closed" ) +const ( + // LocationTypeRegion is a LocationType enum value + LocationTypeRegion = "region" + + // LocationTypeAvailabilityZone is a LocationType enum value + LocationTypeAvailabilityZone = "availability-zone" + + // LocationTypeAvailabilityZoneId is a LocationType enum value + LocationTypeAvailabilityZoneId = "availability-zone-id" +) + const ( // LogDestinationTypeCloudWatchLogs is a LogDestinationType enum value LogDestinationTypeCloudWatchLogs = "cloud-watch-logs" @@ -97554,6 +100847,17 @@ const ( PlacementGroupStateDeleted = "deleted" ) +const ( + // PlacementGroupStrategyCluster is a PlacementGroupStrategy enum value + PlacementGroupStrategyCluster = "cluster" + + // PlacementGroupStrategyPartition is a PlacementGroupStrategy enum value + PlacementGroupStrategyPartition = "partition" + + // PlacementGroupStrategySpread is a PlacementGroupStrategy enum value + PlacementGroupStrategySpread = "spread" +) + const ( // PlacementStrategyCluster is a PlacementStrategy enum value PlacementStrategyCluster = "cluster" @@ -97796,6 +101100,14 @@ const ( ResourceTypeVpnGateway = "vpn-gateway" ) +const ( + // RootDeviceTypeEbs is a RootDeviceType enum value + RootDeviceTypeEbs = "ebs" + + // RootDeviceTypeInstanceStore is a RootDeviceType enum value + RootDeviceTypeInstanceStore = "instance-store" +) + const ( // RouteOriginCreateRouteTable is a RouteOrigin enum value RouteOriginCreateRouteTable = "CreateRouteTable" @@ -98259,6 +101571,14 @@ const ( UnsuccessfulInstanceCreditSpecificationErrorCodeInstanceCreditSpecificationNotSupported = "InstanceCreditSpecification.NotSupported" ) +const ( + // UsageClassTypeSpot is a UsageClassType enum value + UsageClassTypeSpot = "spot" + + // UsageClassTypeOnDemand is a UsageClassType enum value + UsageClassTypeOnDemand = "on-demand" +) + const ( // VirtualizationTypeHvm is a VirtualizationType enum value VirtualizationTypeHvm = "hvm" diff --git a/vendor/github.com/aws/aws-sdk-go/service/ec2/service.go b/vendor/github.com/aws/aws-sdk-go/service/ec2/service.go index b2b9fb8c56..f8c075614f 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/ec2/service.go +++ b/vendor/github.com/aws/aws-sdk-go/service/ec2/service.go @@ -39,6 +39,8 @@ const ( // aws.Config parameter to add your extra config. // // Example: +// mySession := session.Must(session.NewSession()) +// // // Create a EC2 client from just a session. // svc := ec2.New(mySession) // diff --git a/vendor/github.com/aws/aws-sdk-go/service/ec2/waiters.go b/vendor/github.com/aws/aws-sdk-go/service/ec2/waiters.go index 0469f0f01a..b9bdbde157 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/ec2/waiters.go +++ b/vendor/github.com/aws/aws-sdk-go/service/ec2/waiters.go @@ -952,6 +952,57 @@ func (c *EC2) WaitUntilPasswordDataAvailableWithContext(ctx aws.Context, input * return w.WaitWithContext(ctx) } +// WaitUntilSecurityGroupExists uses the Amazon EC2 API operation +// DescribeSecurityGroups to wait for a condition to be met before returning. +// If the condition is not met within the max attempt window, an error will +// be returned. +func (c *EC2) WaitUntilSecurityGroupExists(input *DescribeSecurityGroupsInput) error { + return c.WaitUntilSecurityGroupExistsWithContext(aws.BackgroundContext(), input) +} + +// WaitUntilSecurityGroupExistsWithContext is an extended version of WaitUntilSecurityGroupExists. +// With the support for passing in a context and options to configure the +// Waiter and the underlying request options. +// +// The context must be non-nil and will be used for request cancellation. If +// the context is nil a panic will occur. In the future the SDK may create +// sub-contexts for http.Requests. See https://golang.org/pkg/context/ +// for more information on using Contexts. +func (c *EC2) WaitUntilSecurityGroupExistsWithContext(ctx aws.Context, input *DescribeSecurityGroupsInput, opts ...request.WaiterOption) error { + w := request.Waiter{ + Name: "WaitUntilSecurityGroupExists", + MaxAttempts: 6, + Delay: request.ConstantWaiterDelay(5 * time.Second), + Acceptors: []request.WaiterAcceptor{ + { + State: request.SuccessWaiterState, + Matcher: request.PathWaiterMatch, Argument: "length(SecurityGroups[].GroupId) > `0`", + Expected: true, + }, + { + State: request.RetryWaiterState, + Matcher: request.ErrorWaiterMatch, + Expected: "InvalidGroupNotFound", + }, + }, + Logger: c.Config.Logger, + NewRequest: func(opts []request.Option) (*request.Request, error) { + var inCpy *DescribeSecurityGroupsInput + if input != nil { + tmp := *input + inCpy = &tmp + } + req, _ := c.DescribeSecurityGroupsRequest(inCpy) + req.SetContext(ctx) + req.ApplyOptions(opts...) + return req, nil + }, + } + w.ApplyOptions(opts...) + + return w.WaitWithContext(ctx) +} + // WaitUntilSnapshotCompleted uses the Amazon EC2 API operation // DescribeSnapshots to wait for a condition to be met before returning. // If the condition is not met within the max attempt window, an error will diff --git a/vendor/github.com/aws/aws-sdk-go/service/sts/api.go b/vendor/github.com/aws/aws-sdk-go/service/sts/api.go index 9c5ed45453..7f60d4aa18 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/sts/api.go +++ b/vendor/github.com/aws/aws-sdk-go/service/sts/api.go @@ -78,6 +78,8 @@ func (c *STS) AssumeRoleRequest(input *AssumeRoleInput) (req *request.Request, o // IAM Roles (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html) // in the IAM User Guide. // +// Session Duration +// // By default, the temporary security credentials created by AssumeRole last // for one hour. However, you can use the optional DurationSeconds parameter // to specify the duration of your session. You can provide a value from 900 @@ -91,6 +93,8 @@ func (c *STS) AssumeRoleRequest(input *AssumeRoleInput) (req *request.Request, o // URL. For more information, see Using IAM Roles (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html) // in the IAM User Guide. // +// Permissions +// // The temporary security credentials created by AssumeRole can be used to make // API calls to any AWS service with the following exception: You cannot call // the AWS STS GetFederationToken or GetSessionToken API operations. @@ -99,7 +103,7 @@ func (c *STS) AssumeRoleRequest(input *AssumeRoleInput) (req *request.Request, o // to this operation. You can pass a single JSON policy document to use as an // inline session policy. You can also specify up to 10 managed policies to // use as managed session policies. The plain text that you use for both inline -// and managed session policies shouldn't exceed 2048 characters. Passing policies +// and managed session policies can't exceed 2,048 characters. Passing policies // to this operation returns new temporary credentials. The resulting session's // permissions are the intersection of the role's identity-based policy and // the session policies. You can use the role's temporary credentials in subsequent @@ -131,6 +135,24 @@ func (c *STS) AssumeRoleRequest(input *AssumeRoleInput) (req *request.Request, o // see IAM Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html) // in the IAM User Guide. // +// Tags +// +// (Optional) You can pass tag key-value pairs to your session. These tags are +// called session tags. For more information about session tags, see Passing +// Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// An administrator must grant you the permissions necessary to pass session +// tags. The administrator can also create granular permissions to allow you +// to pass only specific session tags. For more information, see Tutorial: Using +// Tags for Attribute-Based Access Control (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html) +// in the IAM User Guide. +// +// You can set the session tags as transitive. Transitive tags persist during +// role chaining. For more information, see Chaining Roles with Session Tags +// (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining) +// in the IAM User Guide. +// // Using MFA with AssumeRole // // (Optional) You can include multi-factor authentication (MFA) information @@ -165,9 +187,18 @@ func (c *STS) AssumeRoleRequest(input *AssumeRoleInput) (req *request.Request, o // message describes the specific error. // // * ErrCodePackedPolicyTooLargeException "PackedPolicyTooLarge" -// The request was rejected because the policy document was too large. The error -// message describes how big the policy document is, in packed form, as a percentage -// of what the API allows. +// The request was rejected because the total packed size of the session policies +// and session tags combined was too large. An AWS conversion compresses the +// session policy document, session policy ARNs, and session tags into a packed +// binary format that has a separate limit. The error message indicates by percentage +// how close the policies and tags are to the upper size limit. For more information, +// see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You could receive this error even though you meet other defined session policy +// and session tag limits. For more information, see IAM and STS Entity Character +// Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) +// in the IAM User Guide. // // * ErrCodeRegionDisabledException "RegionDisabledException" // STS is not activated in the requested region for the account that is being @@ -256,6 +287,8 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // an access key ID, a secret access key, and a security token. Applications // can use these temporary security credentials to sign calls to AWS services. // +// Session Duration +// // By default, the temporary security credentials created by AssumeRoleWithSAML // last for one hour. However, you can use the optional DurationSeconds parameter // to specify the duration of your session. Your role session lasts for the @@ -271,6 +304,8 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // URL. For more information, see Using IAM Roles (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html) // in the IAM User Guide. // +// Permissions +// // The temporary security credentials created by AssumeRoleWithSAML can be used // to make API calls to any AWS service with the following exception: you cannot // call the STS GetFederationToken or GetSessionToken API operations. @@ -279,7 +314,7 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // to this operation. You can pass a single JSON policy document to use as an // inline session policy. You can also specify up to 10 managed policies to // use as managed session policies. The plain text that you use for both inline -// and managed session policies shouldn't exceed 2048 characters. Passing policies +// and managed session policies can't exceed 2,048 characters. Passing policies // to this operation returns new temporary credentials. The resulting session's // permissions are the intersection of the role's identity-based policy and // the session policies. You can use the role's temporary credentials in subsequent @@ -289,12 +324,6 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // in the IAM User Guide. // -// Before your application can call AssumeRoleWithSAML, you must configure your -// SAML identity provider (IdP) to issue the claims required by AWS. Additionally, -// you must use AWS Identity and Access Management (IAM) to create a SAML provider -// entity in your AWS account that represents your identity provider. You must -// also create an IAM role that specifies this SAML provider in its trust policy. -// // Calling AssumeRoleWithSAML does not require the use of AWS security credentials. // The identity of the caller is validated by using keys in the metadata document // that is uploaded for the SAML provider entity for your identity provider. @@ -302,8 +331,50 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // Calling AssumeRoleWithSAML can result in an entry in your AWS CloudTrail // logs. The entry includes the value in the NameID element of the SAML assertion. // We recommend that you use a NameIDType that is not associated with any personally -// identifiable information (PII). For example, you could instead use the Persistent -// Identifier (urn:oasis:names:tc:SAML:2.0:nameid-format:persistent). +// identifiable information (PII). For example, you could instead use the persistent +// identifier (urn:oasis:names:tc:SAML:2.0:nameid-format:persistent). +// +// Tags +// +// (Optional) You can configure your IdP to pass attributes into your SAML assertion +// as session tags. Each session tag consists of a key name and an associated +// value. For more information about session tags, see Passing Session Tags +// in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You can pass up to 50 session tags. The plain text session tag keys can’t +// exceed 128 characters and the values can’t exceed 256 characters. For these +// and additional limits, see IAM and STS Character Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) +// in the IAM User Guide. +// +// An AWS conversion compresses the passed session policies and session tags +// into a packed binary format that has a separate limit. Your request can fail +// for this limit even if your plain text meets the other requirements. The +// PackedPolicySize response element indicates by percentage how close the policies +// and tags for your request are to the upper size limit. +// +// You can pass a session tag with the same key as a tag that is attached to +// the role. When you do, session tags override the role's tags with the same +// key. +// +// An administrator must grant you the permissions necessary to pass session +// tags. The administrator can also create granular permissions to allow you +// to pass only specific session tags. For more information, see Tutorial: Using +// Tags for Attribute-Based Access Control (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html) +// in the IAM User Guide. +// +// You can set the session tags as transitive. Transitive tags persist during +// role chaining. For more information, see Chaining Roles with Session Tags +// (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining) +// in the IAM User Guide. +// +// SAML Configuration +// +// Before your application can call AssumeRoleWithSAML, you must configure your +// SAML identity provider (IdP) to issue the claims required by AWS. Additionally, +// you must use AWS Identity and Access Management (IAM) to create a SAML provider +// entity in your AWS account that represents your identity provider. You must +// also create an IAM role that specifies this SAML provider in its trust policy. // // For more information, see the following resources: // @@ -332,9 +403,18 @@ func (c *STS) AssumeRoleWithSAMLRequest(input *AssumeRoleWithSAMLInput) (req *re // message describes the specific error. // // * ErrCodePackedPolicyTooLargeException "PackedPolicyTooLarge" -// The request was rejected because the policy document was too large. The error -// message describes how big the policy document is, in packed form, as a percentage -// of what the API allows. +// The request was rejected because the total packed size of the session policies +// and session tags combined was too large. An AWS conversion compresses the +// session policy document, session policy ARNs, and session tags into a packed +// binary format that has a separate limit. The error message indicates by percentage +// how close the policies and tags are to the upper size limit. For more information, +// see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You could receive this error even though you meet other defined session policy +// and session tag limits. For more information, see IAM and STS Entity Character +// Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) +// in the IAM User Guide. // // * ErrCodeIDPRejectedClaimException "IDPRejectedClaim" // The identity provider (IdP) reported that authentication failed. This might @@ -456,6 +536,8 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // key ID, a secret access key, and a security token. Applications can use these // temporary security credentials to sign calls to AWS service API operations. // +// Session Duration +// // By default, the temporary security credentials created by AssumeRoleWithWebIdentity // last for one hour. However, you can use the optional DurationSeconds parameter // to specify the duration of your session. You can provide a value from 900 @@ -469,6 +551,8 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // URL. For more information, see Using IAM Roles (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html) // in the IAM User Guide. // +// Permissions +// // The temporary security credentials created by AssumeRoleWithWebIdentity can // be used to make API calls to any AWS service with the following exception: // you cannot call the STS GetFederationToken or GetSessionToken API operations. @@ -477,7 +561,7 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // to this operation. You can pass a single JSON policy document to use as an // inline session policy. You can also specify up to 10 managed policies to // use as managed session policies. The plain text that you use for both inline -// and managed session policies shouldn't exceed 2048 characters. Passing policies +// and managed session policies can't exceed 2,048 characters. Passing policies // to this operation returns new temporary credentials. The resulting session's // permissions are the intersection of the role's identity-based policy and // the session policies. You can use the role's temporary credentials in subsequent @@ -487,6 +571,42 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // in the IAM User Guide. // +// Tags +// +// (Optional) You can configure your IdP to pass attributes into your web identity +// token as session tags. Each session tag consists of a key name and an associated +// value. For more information about session tags, see Passing Session Tags +// in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You can pass up to 50 session tags. The plain text session tag keys can’t +// exceed 128 characters and the values can’t exceed 256 characters. For these +// and additional limits, see IAM and STS Character Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) +// in the IAM User Guide. +// +// An AWS conversion compresses the passed session policies and session tags +// into a packed binary format that has a separate limit. Your request can fail +// for this limit even if your plain text meets the other requirements. The +// PackedPolicySize response element indicates by percentage how close the policies +// and tags for your request are to the upper size limit. +// +// You can pass a session tag with the same key as a tag that is attached to +// the role. When you do, the session tag overrides the role tag with the same +// key. +// +// An administrator must grant you the permissions necessary to pass session +// tags. The administrator can also create granular permissions to allow you +// to pass only specific session tags. For more information, see Tutorial: Using +// Tags for Attribute-Based Access Control (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html) +// in the IAM User Guide. +// +// You can set the session tags as transitive. Transitive tags persist during +// role chaining. For more information, see Chaining Roles with Session Tags +// (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining) +// in the IAM User Guide. +// +// Identities +// // Before your application can call AssumeRoleWithWebIdentity, you must have // an identity token from a supported identity provider and create a role that // the application can assume. The role that your application assumes must trust @@ -514,8 +634,8 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // * AWS SDK for iOS Developer Guide (http://aws.amazon.com/sdkforios/) and // AWS SDK for Android Developer Guide (http://aws.amazon.com/sdkforandroid/). // These toolkits contain sample apps that show how to invoke the identity -// providers, and then how to use the information from these providers to -// get and use temporary security credentials. +// providers. The toolkits then show how to use the information from these +// providers to get and use temporary security credentials. // // * Web Identity Federation with Mobile Applications (http://aws.amazon.com/articles/web-identity-federation-with-mobile-applications). // This article discusses web identity federation and shows an example of @@ -535,9 +655,18 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // message describes the specific error. // // * ErrCodePackedPolicyTooLargeException "PackedPolicyTooLarge" -// The request was rejected because the policy document was too large. The error -// message describes how big the policy document is, in packed form, as a percentage -// of what the API allows. +// The request was rejected because the total packed size of the session policies +// and session tags combined was too large. An AWS conversion compresses the +// session policy document, session policy ARNs, and session tags into a packed +// binary format that has a separate limit. The error message indicates by percentage +// how close the policies and tags are to the upper size limit. For more information, +// see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You could receive this error even though you meet other defined session policy +// and session tag limits. For more information, see IAM and STS Entity Character +// Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) +// in the IAM User Guide. // // * ErrCodeIDPRejectedClaimException "IDPRejectedClaim" // The identity provider (IdP) reported that authentication failed. This might @@ -547,11 +676,11 @@ func (c *STS) AssumeRoleWithWebIdentityRequest(input *AssumeRoleWithWebIdentityI // can also mean that the claim has expired or has been explicitly revoked. // // * ErrCodeIDPCommunicationErrorException "IDPCommunicationError" -// The request could not be fulfilled because the non-AWS identity provider -// (IDP) that was asked to verify the incoming identity token could not be reached. -// This is often a transient error caused by network conditions. Retry the request +// The request could not be fulfilled because the identity provider (IDP) that +// was asked to verify the incoming identity token could not be reached. This +// is often a transient error caused by network conditions. Retry the request // a limited number of times so that you don't exceed the request rate. If the -// error persists, the non-AWS identity provider might be down or not responding. +// error persists, the identity provider might be down or not responding. // // * ErrCodeInvalidIdentityTokenException "InvalidIdentityToken" // The web identity token that was passed could not be validated by AWS. Get @@ -676,9 +805,9 @@ func (c *STS) DecodeAuthorizationMessageRequest(input *DecodeAuthorizationMessag // // Returned Error Codes: // * ErrCodeInvalidAuthorizationMessageException "InvalidAuthorizationMessageException" -// This error is returned if the message passed to DecodeAuthorizationMessage -// was invalid. This can happen if the token contains invalid characters, such -// as linebreaks. +// The error returned if the message passed to DecodeAuthorizationMessage was +// invalid. This can happen if the token contains invalid characters, such as +// linebreaks. // // See also, https://docs.aws.amazon.com/goto/WebAPI/sts-2011-06-15/DecodeAuthorizationMessage func (c *STS) DecodeAuthorizationMessage(input *DecodeAuthorizationMessageInput) (*DecodeAuthorizationMessageOutput, error) { @@ -763,7 +892,8 @@ func (c *STS) GetAccessKeyInfoRequest(input *GetAccessKeyInfoInput) (req *reques // pull a credentials report (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_getting-report.html) // to learn which IAM user owns the keys. To learn who requested the temporary // credentials for an ASIA access key, view the STS events in your CloudTrail -// logs (https://docs.aws.amazon.com/IAM/latest/UserGuide/cloudtrail-integration.html). +// logs (https://docs.aws.amazon.com/IAM/latest/UserGuide/cloudtrail-integration.html) +// in the IAM User Guide. // // This operation does not indicate the state of the access key. The key might // be active, inactive, or deleted. Active keys might not have permissions to @@ -850,7 +980,8 @@ func (c *STS) GetCallerIdentityRequest(input *GetCallerIdentityInput) (req *requ // sts:GetCallerIdentity action, you can still perform this operation. Permissions // are not required because the same information is returned when an IAM user // or role is denied access. To view an example response, see I Am Not Authorized -// to Perform: iam:DeleteVirtualMFADevice (https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_access-denied-delete-mfa). +// to Perform: iam:DeleteVirtualMFADevice (https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_general.html#troubleshoot_general_access-denied-delete-mfa) +// in the IAM User Guide. // // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about @@ -942,7 +1073,8 @@ func (c *STS) GetFederationTokenRequest(input *GetFederationTokenInput) (req *re // or an OpenID Connect-compatible identity provider. In this case, we recommend // that you use Amazon Cognito (http://aws.amazon.com/cognito/) or AssumeRoleWithWebIdentity. // For more information, see Federation Through a Web-based Identity Provider -// (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity). +// (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity) +// in the IAM User Guide. // // You can also call GetFederationToken using the security credentials of an // AWS account root user, but we do not recommend it. Instead, we recommend @@ -952,41 +1084,67 @@ func (c *STS) GetFederationTokenRequest(input *GetFederationTokenInput) (req *re // Practices (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html) // in the IAM User Guide. // +// Session duration +// // The temporary credentials are valid for the specified duration, from 900 // seconds (15 minutes) up to a maximum of 129,600 seconds (36 hours). The default -// is 43,200 seconds (12 hours). Temporary credentials that are obtained by -// using AWS account root user credentials have a maximum duration of 3,600 -// seconds (1 hour). -// -// The temporary security credentials created by GetFederationToken can be used -// to make API calls to any AWS service with the following exceptions: -// -// * You cannot use these credentials to call any IAM API operations. -// -// * You cannot call any STS API operations except GetCallerIdentity. +// session duration is 43,200 seconds (12 hours). Temporary credentials that +// are obtained by using AWS account root user credentials have a maximum duration +// of 3,600 seconds (1 hour). // // Permissions // +// You can use the temporary credentials created by GetFederationToken in any +// AWS service except the following: +// +// * You cannot call any IAM operations using the AWS CLI or the AWS API. +// +// * You cannot call any STS operations except GetCallerIdentity. +// // You must pass an inline or managed session policy (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // to this operation. You can pass a single JSON policy document to use as an // inline session policy. You can also specify up to 10 managed policies to // use as managed session policies. The plain text that you use for both inline -// and managed session policies shouldn't exceed 2048 characters. +// and managed session policies can't exceed 2,048 characters. // // Though the session policy parameters are optional, if you do not pass a policy, -// then the resulting federated user session has no permissions. The only exception -// is when the credentials are used to access a resource that has a resource-based -// policy that specifically references the federated user session in the Principal -// element of the policy. When you pass session policies, the session permissions -// are the intersection of the IAM user policies and the session policies that -// you pass. This gives you a way to further restrict the permissions for a -// federated user. You cannot use session policies to grant more permissions -// than those that are defined in the permissions policy of the IAM user. For -// more information, see Session Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) +// then the resulting federated user session has no permissions. When you pass +// session policies, the session permissions are the intersection of the IAM +// user policies and the session policies that you pass. This gives you a way +// to further restrict the permissions for a federated user. You cannot use +// session policies to grant more permissions than those that are defined in +// the permissions policy of the IAM user. For more information, see Session +// Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // in the IAM User Guide. For information about using GetFederationToken to // create temporary security credentials, see GetFederationToken—Federation // Through a Custom Identity Broker (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_getfederationtoken). // +// You can use the credentials to access a resource that has a resource-based +// policy. If that policy specifically references the federated user session +// in the Principal element of the policy, the session has the permissions allowed +// by the policy. These permissions are granted in addition to the permissions +// granted by the session policies. +// +// Tags +// +// (Optional) You can pass tag key-value pairs to your session. These are called +// session tags. For more information about session tags, see Passing Session +// Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// An administrator must grant you the permissions necessary to pass session +// tags. The administrator can also create granular permissions to allow you +// to pass only specific session tags. For more information, see Tutorial: Using +// Tags for Attribute-Based Access Control (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html) +// in the IAM User Guide. +// +// Tag key–value pairs are not case sensitive, but case is preserved. This +// means that you cannot have separate Department and department tag keys. Assume +// that the user that you are federating has the Department=Marketing tag and +// you pass the department=engineering session tag. Department and department +// are not saved as separate tags, and the session tag passed in the request +// takes precedence over the user tag. +// // Returns awserr.Error for service API and SDK errors. Use runtime type assertions // with awserr.Error's Code and Message methods to get detailed information about // the error. @@ -1000,9 +1158,18 @@ func (c *STS) GetFederationTokenRequest(input *GetFederationTokenInput) (req *re // message describes the specific error. // // * ErrCodePackedPolicyTooLargeException "PackedPolicyTooLarge" -// The request was rejected because the policy document was too large. The error -// message describes how big the policy document is, in packed form, as a percentage -// of what the API allows. +// The request was rejected because the total packed size of the session policies +// and session tags combined was too large. An AWS conversion compresses the +// session policy document, session policy ARNs, and session tags into a packed +// binary format that has a separate limit. The error message indicates by percentage +// how close the policies and tags are to the upper size limit. For more information, +// see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +// +// You could receive this error even though you meet other defined session policy +// and session tag limits. For more information, see IAM and STS Entity Character +// Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) +// in the IAM User Guide. // // * ErrCodeRegionDisabledException "RegionDisabledException" // STS is not activated in the requested region for the account that is being @@ -1091,6 +1258,8 @@ func (c *STS) GetSessionTokenRequest(input *GetSessionTokenInput) (req *request. // and Comparing the AWS STS API operations (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison) // in the IAM User Guide. // +// Session Duration +// // The GetSessionToken operation must be called by using the long-term AWS security // credentials of the AWS account root user or an IAM user. Credentials that // are created by IAM users are valid for the duration that you specify. This @@ -1099,6 +1268,8 @@ func (c *STS) GetSessionTokenRequest(input *GetSessionTokenInput) (req *request. // based on account credentials can range from 900 seconds (15 minutes) up to // 3,600 seconds (1 hour), with a default of 1 hour. // +// Permissions +// // The temporary security credentials created by GetSessionToken can be used // to make API calls to any AWS service with the following exceptions: // @@ -1213,16 +1384,16 @@ type AssumeRoleInput struct { // in the IAM User Guide. // // The plain text that you use for both inline and managed session policies - // shouldn't exceed 2048 characters. The JSON policy characters can be any ASCII + // can't exceed 2,048 characters. The JSON policy characters can be any ASCII // character from the space character to the end of the valid character list // (\u0020 through \u00FF). It can also include the tab (\u0009), linefeed (\u000A), // and carriage return (\u000D) characters. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. Policy *string `min:"1" type:"string"` // The Amazon Resource Names (ARNs) of the IAM managed policies that you want @@ -1231,15 +1402,15 @@ type AssumeRoleInput struct { // // This parameter is optional. You can provide up to 10 managed policy ARNs. // However, the plain text that you use for both inline and managed session - // policies shouldn't exceed 2048 characters. For more information about ARNs, + // policies can't exceed 2,048 characters. For more information about ARNs, // see Amazon Resource Names (ARNs) and AWS Service Namespaces (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) // in the AWS General Reference. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. // // Passing policies to this operation returns new temporary credentials. The // resulting session's permissions are the intersection of the role's identity-based @@ -1284,6 +1455,41 @@ type AssumeRoleInput struct { // also include underscores or any of the following characters: =,.@- SerialNumber *string `min:"9" type:"string"` + // A list of session tags that you want to pass. Each session tag consists of + // a key name and an associated value. For more information about session tags, + // see Tagging AWS STS Sessions (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) + // in the IAM User Guide. + // + // This parameter is optional. You can pass up to 50 session tags. The plain + // text session tag keys can’t exceed 128 characters, and the values can’t + // exceed 256 characters. For these and additional limits, see IAM and STS Character + // Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) + // in the IAM User Guide. + // + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. + // + // You can pass a session tag with the same key as a tag that is already attached + // to the role. When you do, session tags override a role tag with the same + // key. + // + // Tag key–value pairs are not case sensitive, but case is preserved. This + // means that you cannot have separate Department and department tag keys. Assume + // that the role has the Department=Marketing tag and you pass the department=engineering + // session tag. Department and department are not saved as separate tags, and + // the session tag passed in the request takes precedence over the role tag. + // + // Additionally, if you used temporary credentials to perform this operation, + // the new session inherits any transitive session tags from the calling session. + // If you pass a session tag with the same key as an inherited tag, the operation + // fails. To view the inherited tags for a session, see the AWS CloudTrail logs. + // For more information, see Viewing Session Tags in CloudTrail (https://docs.aws.amazon.com/IAM/latest/UserGuide/session-tags.html#id_session-tags_ctlogs) + // in the IAM User Guide. + Tags []*Tag `type:"list"` + // The value provided by the MFA device, if the trust policy of the role being // assumed requires MFA (that is, if the policy includes a condition that tests // for MFA). If the role being assumed requires MFA and if the TokenCode value @@ -1292,6 +1498,19 @@ type AssumeRoleInput struct { // The format for this parameter, as described by its regex pattern, is a sequence // of six numeric digits. TokenCode *string `min:"6" type:"string"` + + // A list of keys for session tags that you want to set as transitive. If you + // set a tag key as transitive, the corresponding key and value passes to subsequent + // sessions in a role chain. For more information, see Chaining Roles with Session + // Tags (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining) + // in the IAM User Guide. + // + // This parameter is optional. When you set session tags as transitive, the + // session policy and session tags packed binary limit is not affected. + // + // If you choose not to specify a transitive tag key, then no tags are passed + // from this session to any subsequent sessions. + TransitiveTagKeys []*string `type:"list"` } // String returns the string representation @@ -1344,6 +1563,16 @@ func (s *AssumeRoleInput) Validate() error { } } } + if s.Tags != nil { + for i, v := range s.Tags { + if v == nil { + continue + } + if err := v.Validate(); err != nil { + invalidParams.AddNested(fmt.Sprintf("%s[%v]", "Tags", i), err.(request.ErrInvalidParams)) + } + } + } if invalidParams.Len() > 0 { return invalidParams @@ -1393,12 +1622,24 @@ func (s *AssumeRoleInput) SetSerialNumber(v string) *AssumeRoleInput { return s } +// SetTags sets the Tags field's value. +func (s *AssumeRoleInput) SetTags(v []*Tag) *AssumeRoleInput { + s.Tags = v + return s +} + // SetTokenCode sets the TokenCode field's value. func (s *AssumeRoleInput) SetTokenCode(v string) *AssumeRoleInput { s.TokenCode = &v return s } +// SetTransitiveTagKeys sets the TransitiveTagKeys field's value. +func (s *AssumeRoleInput) SetTransitiveTagKeys(v []*string) *AssumeRoleInput { + s.TransitiveTagKeys = v + return s +} + // Contains the response to a successful AssumeRole request, including temporary // AWS credentials that can be used to make AWS requests. type AssumeRoleOutput struct { @@ -1418,9 +1659,10 @@ type AssumeRoleOutput struct { // We strongly recommend that you make no assumptions about the maximum size. Credentials *Credentials `type:"structure"` - // A percentage value that indicates the size of the policy in packed form. - // The service rejects any policy with a packed size greater than 100 percent, - // which means the policy exceeded the allowed space. + // A percentage value that indicates the packed size of the session policies + // and session tags combined passed in the request. The request fails if the + // packed size is greater than 100 percent, which means the policies and tags + // exceeded the allowed space. PackedPolicySize *int64 `type:"integer"` } @@ -1491,16 +1733,16 @@ type AssumeRoleWithSAMLInput struct { // in the IAM User Guide. // // The plain text that you use for both inline and managed session policies - // shouldn't exceed 2048 characters. The JSON policy characters can be any ASCII + // can't exceed 2,048 characters. The JSON policy characters can be any ASCII // character from the space character to the end of the valid character list // (\u0020 through \u00FF). It can also include the tab (\u0009), linefeed (\u000A), // and carriage return (\u000D) characters. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. Policy *string `min:"1" type:"string"` // The Amazon Resource Names (ARNs) of the IAM managed policies that you want @@ -1509,15 +1751,15 @@ type AssumeRoleWithSAMLInput struct { // // This parameter is optional. You can provide up to 10 managed policy ARNs. // However, the plain text that you use for both inline and managed session - // policies shouldn't exceed 2048 characters. For more information about ARNs, + // policies can't exceed 2,048 characters. For more information about ARNs, // see Amazon Resource Names (ARNs) and AWS Service Namespaces (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) // in the AWS General Reference. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. // // Passing policies to this operation returns new temporary credentials. The // resulting session's permissions are the intersection of the role's identity-based @@ -1673,9 +1915,10 @@ type AssumeRoleWithSAMLOutput struct { // ) ) NameQualifier *string `type:"string"` - // A percentage value that indicates the size of the policy in packed form. - // The service rejects any policy with a packed size greater than 100 percent, - // which means the policy exceeded the allowed space. + // A percentage value that indicates the packed size of the session policies + // and session tags combined passed in the request. The request fails if the + // packed size is greater than 100 percent, which means the policies and tags + // exceeded the allowed space. PackedPolicySize *int64 `type:"integer"` // The value of the NameID element in the Subject element of the SAML assertion. @@ -1786,16 +2029,16 @@ type AssumeRoleWithWebIdentityInput struct { // in the IAM User Guide. // // The plain text that you use for both inline and managed session policies - // shouldn't exceed 2048 characters. The JSON policy characters can be any ASCII + // can't exceed 2,048 characters. The JSON policy characters can be any ASCII // character from the space character to the end of the valid character list // (\u0020 through \u00FF). It can also include the tab (\u0009), linefeed (\u000A), // and carriage return (\u000D) characters. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. Policy *string `min:"1" type:"string"` // The Amazon Resource Names (ARNs) of the IAM managed policies that you want @@ -1804,15 +2047,15 @@ type AssumeRoleWithWebIdentityInput struct { // // This parameter is optional. You can provide up to 10 managed policy ARNs. // However, the plain text that you use for both inline and managed session - // policies shouldn't exceed 2048 characters. For more information about ARNs, + // policies can't exceed 2,048 characters. For more information about ARNs, // see Amazon Resource Names (ARNs) and AWS Service Namespaces (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) // in the AWS General Reference. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. // // Passing policies to this operation returns new temporary credentials. The // resulting session's permissions are the intersection of the role's identity-based @@ -1983,9 +2226,10 @@ type AssumeRoleWithWebIdentityOutput struct { // We strongly recommend that you make no assumptions about the maximum size. Credentials *Credentials `type:"structure"` - // A percentage value that indicates the size of the policy in packed form. - // The service rejects any policy with a packed size greater than 100 percent, - // which means the policy exceeded the allowed space. + // A percentage value that indicates the packed size of the session policies + // and session tags combined passed in the request. The request fails if the + // packed size is greater than 100 percent, which means the policies and tags + // exceeded the allowed space. PackedPolicySize *int64 `type:"integer"` // The issuing authority of the web identity token presented. For OpenID Connect @@ -2057,7 +2301,7 @@ type AssumedRoleUser struct { // The ARN of the temporary security credentials that are returned from the // AssumeRole action. For more information about ARNs and how to use them in // policies, see IAM Identifiers (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) - // in Using IAM. + // in the IAM User Guide. // // Arn is a required field Arn *string `min:"20" type:"string" required:"true"` @@ -2225,7 +2469,7 @@ type FederatedUser struct { // The ARN that specifies the federated user that is associated with the credentials. // For more information about ARNs and how to use them in policies, see IAM // Identifiers (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html) - // in Using IAM. + // in the IAM User Guide. // // Arn is a required field Arn *string `min:"20" type:"string" required:"true"` @@ -2265,7 +2509,7 @@ type GetAccessKeyInfoInput struct { // The identifier of an access key. // // This parameter allows (through its regex pattern) a string of characters - // that can consist of any upper- or lowercased letter or digit. + // that can consist of any upper- or lowercase letter or digit. // // AccessKeyId is a required field AccessKeyId *string `min:"16" type:"string" required:"true"` @@ -2418,10 +2662,7 @@ type GetFederationTokenInput struct { // use as managed session policies. // // This parameter is optional. However, if you do not pass any session policies, - // then the resulting federated user session has no permissions. The only exception - // is when the credentials are used to access a resource that has a resource-based - // policy that specifically references the federated user session in the Principal - // element of the policy. + // then the resulting federated user session has no permissions. // // When you pass session policies, the session permissions are the intersection // of the IAM user policies and the session policies that you pass. This gives @@ -2431,17 +2672,23 @@ type GetFederationTokenInput struct { // Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // in the IAM User Guide. // + // The resulting credentials can be used to access a resource that has a resource-based + // policy. If that policy specifically references the federated user session + // in the Principal element of the policy, the session has the permissions allowed + // by the policy. These permissions are granted in addition to the permissions + // that are granted by the session policies. + // // The plain text that you use for both inline and managed session policies - // shouldn't exceed 2048 characters. The JSON policy characters can be any ASCII + // can't exceed 2,048 characters. The JSON policy characters can be any ASCII // character from the space character to the end of the valid character list // (\u0020 through \u00FF). It can also include the tab (\u0009), linefeed (\u000A), // and carriage return (\u000D) characters. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. Policy *string `min:"1" type:"string"` // The Amazon Resource Names (ARNs) of the IAM managed policies that you want @@ -2452,16 +2699,13 @@ type GetFederationTokenInput struct { // to this operation. You can pass a single JSON policy document to use as an // inline session policy. You can also specify up to 10 managed policies to // use as managed session policies. The plain text that you use for both inline - // and managed session policies shouldn't exceed 2048 characters. You can provide + // and managed session policies can't exceed 2,048 characters. You can provide // up to 10 managed policy ARNs. For more information about ARNs, see Amazon // Resource Names (ARNs) and AWS Service Namespaces (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) // in the AWS General Reference. // // This parameter is optional. However, if you do not pass any session policies, - // then the resulting federated user session has no permissions. The only exception - // is when the credentials are used to access a resource that has a resource-based - // policy that specifically references the federated user session in the Principal - // element of the policy. + // then the resulting federated user session has no permissions. // // When you pass session policies, the session permissions are the intersection // of the IAM user policies and the session policies that you pass. This gives @@ -2471,12 +2715,46 @@ type GetFederationTokenInput struct { // Policies (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session) // in the IAM User Guide. // - // The characters in this parameter count towards the 2048 character session - // policy guideline. However, an AWS conversion compresses the session policies - // into a packed binary format that has a separate limit. This is the enforced - // limit. The PackedPolicySize response element indicates by percentage how - // close the policy is to the upper size limit. + // The resulting credentials can be used to access a resource that has a resource-based + // policy. If that policy specifically references the federated user session + // in the Principal element of the policy, the session has the permissions allowed + // by the policy. These permissions are granted in addition to the permissions + // that are granted by the session policies. + // + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. PolicyArns []*PolicyDescriptorType `type:"list"` + + // A list of session tags. Each session tag consists of a key name and an associated + // value. For more information about session tags, see Passing Session Tags + // in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) + // in the IAM User Guide. + // + // This parameter is optional. You can pass up to 50 session tags. The plain + // text session tag keys can’t exceed 128 characters and the values can’t + // exceed 256 characters. For these and additional limits, see IAM and STS Character + // Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) + // in the IAM User Guide. + // + // An AWS conversion compresses the passed session policies and session tags + // into a packed binary format that has a separate limit. Your request can fail + // for this limit even if your plain text meets the other requirements. The + // PackedPolicySize response element indicates by percentage how close the policies + // and tags for your request are to the upper size limit. + // + // You can pass a session tag with the same key as a tag that is already attached + // to the user you are federating. When you do, session tags override a user + // tag with the same key. + // + // Tag key–value pairs are not case sensitive, but case is preserved. This + // means that you cannot have separate Department and department tag keys. Assume + // that the role has the Department=Marketing tag and you pass the department=engineering + // session tag. Department and department are not saved as separate tags, and + // the session tag passed in the request takes precedence over the role tag. + Tags []*Tag `type:"list"` } // String returns the string representation @@ -2514,6 +2792,16 @@ func (s *GetFederationTokenInput) Validate() error { } } } + if s.Tags != nil { + for i, v := range s.Tags { + if v == nil { + continue + } + if err := v.Validate(); err != nil { + invalidParams.AddNested(fmt.Sprintf("%s[%v]", "Tags", i), err.(request.ErrInvalidParams)) + } + } + } if invalidParams.Len() > 0 { return invalidParams @@ -2545,6 +2833,12 @@ func (s *GetFederationTokenInput) SetPolicyArns(v []*PolicyDescriptorType) *GetF return s } +// SetTags sets the Tags field's value. +func (s *GetFederationTokenInput) SetTags(v []*Tag) *GetFederationTokenInput { + s.Tags = v + return s +} + // Contains the response to a successful GetFederationToken request, including // temporary AWS credentials that can be used to make AWS requests. type GetFederationTokenOutput struct { @@ -2563,9 +2857,10 @@ type GetFederationTokenOutput struct { // an Amazon S3 bucket policy. FederatedUser *FederatedUser `type:"structure"` - // A percentage value indicating the size of the policy in packed form. The - // service rejects policies for which the packed size is greater than 100 percent - // of the allowed value. + // A percentage value that indicates the packed size of the session policies + // and session tags combined passed in the request. The request fails if the + // packed size is greater than 100 percent, which means the policies and tags + // exceeded the allowed space. PackedPolicySize *int64 `type:"integer"` } @@ -2748,3 +3043,73 @@ func (s *PolicyDescriptorType) SetArn(v string) *PolicyDescriptorType { s.Arn = &v return s } + +// You can pass custom key-value pair attributes when you assume a role or federate +// a user. These are called session tags. You can then use the session tags +// to control access to resources. For more information, see Tagging AWS STS +// Sessions (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) +// in the IAM User Guide. +type Tag struct { + _ struct{} `type:"structure"` + + // The key for a session tag. + // + // You can pass up to 50 session tags. The plain text session tag keys can’t + // exceed 128 characters. For these and additional limits, see IAM and STS Character + // Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) + // in the IAM User Guide. + // + // Key is a required field + Key *string `min:"1" type:"string" required:"true"` + + // The value for a session tag. + // + // You can pass up to 50 session tags. The plain text session tag values can’t + // exceed 256 characters. For these and additional limits, see IAM and STS Character + // Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length) + // in the IAM User Guide. + // + // Value is a required field + Value *string `type:"string" required:"true"` +} + +// String returns the string representation +func (s Tag) String() string { + return awsutil.Prettify(s) +} + +// GoString returns the string representation +func (s Tag) GoString() string { + return s.String() +} + +// Validate inspects the fields of the type to determine if they are valid. +func (s *Tag) Validate() error { + invalidParams := request.ErrInvalidParams{Context: "Tag"} + if s.Key == nil { + invalidParams.Add(request.NewErrParamRequired("Key")) + } + if s.Key != nil && len(*s.Key) < 1 { + invalidParams.Add(request.NewErrParamMinLen("Key", 1)) + } + if s.Value == nil { + invalidParams.Add(request.NewErrParamRequired("Value")) + } + + if invalidParams.Len() > 0 { + return invalidParams + } + return nil +} + +// SetKey sets the Key field's value. +func (s *Tag) SetKey(v string) *Tag { + s.Key = &v + return s +} + +// SetValue sets the Value field's value. +func (s *Tag) SetValue(v string) *Tag { + s.Value = &v + return s +} diff --git a/vendor/github.com/aws/aws-sdk-go/service/sts/errors.go b/vendor/github.com/aws/aws-sdk-go/service/sts/errors.go index a3e378edad..a233f542ef 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/sts/errors.go +++ b/vendor/github.com/aws/aws-sdk-go/service/sts/errors.go @@ -14,11 +14,11 @@ const ( // ErrCodeIDPCommunicationErrorException for service response error code // "IDPCommunicationError". // - // The request could not be fulfilled because the non-AWS identity provider - // (IDP) that was asked to verify the incoming identity token could not be reached. - // This is often a transient error caused by network conditions. Retry the request + // The request could not be fulfilled because the identity provider (IDP) that + // was asked to verify the incoming identity token could not be reached. This + // is often a transient error caused by network conditions. Retry the request // a limited number of times so that you don't exceed the request rate. If the - // error persists, the non-AWS identity provider might be down or not responding. + // error persists, the identity provider might be down or not responding. ErrCodeIDPCommunicationErrorException = "IDPCommunicationError" // ErrCodeIDPRejectedClaimException for service response error code @@ -34,9 +34,9 @@ const ( // ErrCodeInvalidAuthorizationMessageException for service response error code // "InvalidAuthorizationMessageException". // - // This error is returned if the message passed to DecodeAuthorizationMessage - // was invalid. This can happen if the token contains invalid characters, such - // as linebreaks. + // The error returned if the message passed to DecodeAuthorizationMessage was + // invalid. This can happen if the token contains invalid characters, such as + // linebreaks. ErrCodeInvalidAuthorizationMessageException = "InvalidAuthorizationMessageException" // ErrCodeInvalidIdentityTokenException for service response error code @@ -56,9 +56,18 @@ const ( // ErrCodePackedPolicyTooLargeException for service response error code // "PackedPolicyTooLarge". // - // The request was rejected because the policy document was too large. The error - // message describes how big the policy document is, in packed form, as a percentage - // of what the API allows. + // The request was rejected because the total packed size of the session policies + // and session tags combined was too large. An AWS conversion compresses the + // session policy document, session policy ARNs, and session tags into a packed + // binary format that has a separate limit. The error message indicates by percentage + // how close the policies and tags are to the upper size limit. For more information, + // see Passing Session Tags in STS (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) + // in the IAM User Guide. + // + // You could receive this error even though you meet other defined session policy + // and session tag limits. For more information, see IAM and STS Entity Character + // Limits (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_enable-regions.html) + // in the IAM User Guide. ErrCodePackedPolicyTooLargeException = "PackedPolicyTooLarge" // ErrCodeRegionDisabledException for service response error code diff --git a/vendor/github.com/aws/aws-sdk-go/service/sts/service.go b/vendor/github.com/aws/aws-sdk-go/service/sts/service.go index 2c3c3d2c1e..586faed193 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/sts/service.go +++ b/vendor/github.com/aws/aws-sdk-go/service/sts/service.go @@ -39,6 +39,8 @@ const ( // aws.Config parameter to add your extra config. // // Example: +// mySession := session.Must(session.NewSession()) +// // // Create a STS client from just a session. // svc := sts.New(mySession) // diff --git a/vendor/github.com/dimchansky/utfbom/.gitignore b/vendor/github.com/dimchansky/utfbom/.gitignore new file mode 100644 index 0000000000..d7ec5cebb9 --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/.gitignore @@ -0,0 +1,37 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib +*.o +*.a + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.prof + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ + +# Gogland +.idea/ \ No newline at end of file diff --git a/vendor/github.com/dimchansky/utfbom/.travis.yml b/vendor/github.com/dimchansky/utfbom/.travis.yml new file mode 100644 index 0000000000..3512c85190 --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/.travis.yml @@ -0,0 +1,18 @@ +language: go + +go: + - '1.10' + - '1.11' + +# sudo=false makes the build run using a container +sudo: false + +before_install: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cmd/cover + - go get golang.org/x/tools/cmd/goimports + - go get github.com/golang/lint/golint +script: + - gofiles=$(find ./ -name '*.go') && [ -z "$gofiles" ] || unformatted=$(goimports -l $gofiles) && [ -z "$unformatted" ] || (echo >&2 "Go files must be formatted with gofmt. Following files has problem:\n $unformatted" && false) + - golint ./... # This won't break the build, just show warnings + - $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/vendor/github.com/dimchansky/utfbom/LICENSE b/vendor/github.com/dimchansky/utfbom/LICENSE new file mode 100644 index 0000000000..8dada3edaf --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/dimchansky/utfbom/README.md b/vendor/github.com/dimchansky/utfbom/README.md new file mode 100644 index 0000000000..8ece280089 --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/README.md @@ -0,0 +1,66 @@ +# utfbom [![Godoc](https://godoc.org/github.com/dimchansky/utfbom?status.png)](https://godoc.org/github.com/dimchansky/utfbom) [![License](https://img.shields.io/:license-apache-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://travis-ci.org/dimchansky/utfbom.svg?branch=master)](https://travis-ci.org/dimchansky/utfbom) [![Go Report Card](https://goreportcard.com/badge/github.com/dimchansky/utfbom)](https://goreportcard.com/report/github.com/dimchansky/utfbom) [![Coverage Status](https://coveralls.io/repos/github/dimchansky/utfbom/badge.svg?branch=master)](https://coveralls.io/github/dimchansky/utfbom?branch=master) + +The package utfbom implements the detection of the BOM (Unicode Byte Order Mark) and removing as necessary. It can also return the encoding detected by the BOM. + +## Installation + + go get -u github.com/dimchansky/utfbom + +## Example + +```go +package main + +import ( + "bytes" + "fmt" + "io/ioutil" + + "github.com/dimchansky/utfbom" +) + +func main() { + trySkip([]byte("\xEF\xBB\xBFhello")) + trySkip([]byte("hello")) +} + +func trySkip(byteData []byte) { + fmt.Println("Input:", byteData) + + // just skip BOM + output, err := ioutil.ReadAll(utfbom.SkipOnly(bytes.NewReader(byteData))) + if err != nil { + fmt.Println(err) + return + } + fmt.Println("ReadAll with BOM skipping", output) + + // skip BOM and detect encoding + sr, enc := utfbom.Skip(bytes.NewReader(byteData)) + fmt.Printf("Detected encoding: %s\n", enc) + output, err = ioutil.ReadAll(sr) + if err != nil { + fmt.Println(err) + return + } + fmt.Println("ReadAll with BOM detection and skipping", output) + fmt.Println() +} +``` + +Output: + +``` +$ go run main.go +Input: [239 187 191 104 101 108 108 111] +ReadAll with BOM skipping [104 101 108 108 111] +Detected encoding: UTF8 +ReadAll with BOM detection and skipping [104 101 108 108 111] + +Input: [104 101 108 108 111] +ReadAll with BOM skipping [104 101 108 108 111] +Detected encoding: Unknown +ReadAll with BOM detection and skipping [104 101 108 108 111] +``` + + diff --git a/vendor/github.com/dimchansky/utfbom/go.mod b/vendor/github.com/dimchansky/utfbom/go.mod new file mode 100644 index 0000000000..4b9ecc6f54 --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/go.mod @@ -0,0 +1 @@ +module github.com/dimchansky/utfbom \ No newline at end of file diff --git a/vendor/github.com/dimchansky/utfbom/utfbom.go b/vendor/github.com/dimchansky/utfbom/utfbom.go new file mode 100644 index 0000000000..77a303e564 --- /dev/null +++ b/vendor/github.com/dimchansky/utfbom/utfbom.go @@ -0,0 +1,192 @@ +// Package utfbom implements the detection of the BOM (Unicode Byte Order Mark) and removing as necessary. +// It wraps an io.Reader object, creating another object (Reader) that also implements the io.Reader +// interface but provides automatic BOM checking and removing as necessary. +package utfbom + +import ( + "errors" + "io" +) + +// Encoding is type alias for detected UTF encoding. +type Encoding int + +// Constants to identify detected UTF encodings. +const ( + // Unknown encoding, returned when no BOM was detected + Unknown Encoding = iota + + // UTF8, BOM bytes: EF BB BF + UTF8 + + // UTF-16, big-endian, BOM bytes: FE FF + UTF16BigEndian + + // UTF-16, little-endian, BOM bytes: FF FE + UTF16LittleEndian + + // UTF-32, big-endian, BOM bytes: 00 00 FE FF + UTF32BigEndian + + // UTF-32, little-endian, BOM bytes: FF FE 00 00 + UTF32LittleEndian +) + +// String returns a user-friendly string representation of the encoding. Satisfies fmt.Stringer interface. +func (e Encoding) String() string { + switch e { + case UTF8: + return "UTF8" + case UTF16BigEndian: + return "UTF16BigEndian" + case UTF16LittleEndian: + return "UTF16LittleEndian" + case UTF32BigEndian: + return "UTF32BigEndian" + case UTF32LittleEndian: + return "UTF32LittleEndian" + default: + return "Unknown" + } +} + +const maxConsecutiveEmptyReads = 100 + +// Skip creates Reader which automatically detects BOM (Unicode Byte Order Mark) and removes it as necessary. +// It also returns the encoding detected by the BOM. +// If the detected encoding is not needed, you can call the SkipOnly function. +func Skip(rd io.Reader) (*Reader, Encoding) { + // Is it already a Reader? + b, ok := rd.(*Reader) + if ok { + return b, Unknown + } + + enc, left, err := detectUtf(rd) + return &Reader{ + rd: rd, + buf: left, + err: err, + }, enc +} + +// SkipOnly creates Reader which automatically detects BOM (Unicode Byte Order Mark) and removes it as necessary. +func SkipOnly(rd io.Reader) *Reader { + r, _ := Skip(rd) + return r +} + +// Reader implements automatic BOM (Unicode Byte Order Mark) checking and +// removing as necessary for an io.Reader object. +type Reader struct { + rd io.Reader // reader provided by the client + buf []byte // buffered data + err error // last error +} + +// Read is an implementation of io.Reader interface. +// The bytes are taken from the underlying Reader, but it checks for BOMs, removing them as necessary. +func (r *Reader) Read(p []byte) (n int, err error) { + if len(p) == 0 { + return 0, nil + } + + if r.buf == nil { + if r.err != nil { + return 0, r.readErr() + } + + return r.rd.Read(p) + } + + // copy as much as we can + n = copy(p, r.buf) + r.buf = nilIfEmpty(r.buf[n:]) + return n, nil +} + +func (r *Reader) readErr() error { + err := r.err + r.err = nil + return err +} + +var errNegativeRead = errors.New("utfbom: reader returned negative count from Read") + +func detectUtf(rd io.Reader) (enc Encoding, buf []byte, err error) { + buf, err = readBOM(rd) + + if len(buf) >= 4 { + if isUTF32BigEndianBOM4(buf) { + return UTF32BigEndian, nilIfEmpty(buf[4:]), err + } + if isUTF32LittleEndianBOM4(buf) { + return UTF32LittleEndian, nilIfEmpty(buf[4:]), err + } + } + + if len(buf) > 2 && isUTF8BOM3(buf) { + return UTF8, nilIfEmpty(buf[3:]), err + } + + if (err != nil && err != io.EOF) || (len(buf) < 2) { + return Unknown, nilIfEmpty(buf), err + } + + if isUTF16BigEndianBOM2(buf) { + return UTF16BigEndian, nilIfEmpty(buf[2:]), err + } + if isUTF16LittleEndianBOM2(buf) { + return UTF16LittleEndian, nilIfEmpty(buf[2:]), err + } + + return Unknown, nilIfEmpty(buf), err +} + +func readBOM(rd io.Reader) (buf []byte, err error) { + const maxBOMSize = 4 + var bom [maxBOMSize]byte // used to read BOM + + // read as many bytes as possible + for nEmpty, n := 0, 0; err == nil && len(buf) < maxBOMSize; buf = bom[:len(buf)+n] { + if n, err = rd.Read(bom[len(buf):]); n < 0 { + panic(errNegativeRead) + } + if n > 0 { + nEmpty = 0 + } else { + nEmpty++ + if nEmpty >= maxConsecutiveEmptyReads { + err = io.ErrNoProgress + } + } + } + return +} + +func isUTF32BigEndianBOM4(buf []byte) bool { + return buf[0] == 0x00 && buf[1] == 0x00 && buf[2] == 0xFE && buf[3] == 0xFF +} + +func isUTF32LittleEndianBOM4(buf []byte) bool { + return buf[0] == 0xFF && buf[1] == 0xFE && buf[2] == 0x00 && buf[3] == 0x00 +} + +func isUTF8BOM3(buf []byte) bool { + return buf[0] == 0xEF && buf[1] == 0xBB && buf[2] == 0xBF +} + +func isUTF16BigEndianBOM2(buf []byte) bool { + return buf[0] == 0xFE && buf[1] == 0xFF +} + +func isUTF16LittleEndianBOM2(buf []byte) bool { + return buf[0] == 0xFF && buf[1] == 0xFE +} + +func nilIfEmpty(buf []byte) (res []byte) { + if len(buf) > 0 { + res = buf + } + return +} diff --git a/vendor/github.com/hashicorp/go-discover/README.md b/vendor/github.com/hashicorp/go-discover/README.md index 6d3ead6d14..8eeb44c83b 100644 --- a/vendor/github.com/hashicorp/go-discover/README.md +++ b/vendor/github.com/hashicorp/go-discover/README.md @@ -25,11 +25,13 @@ function. * Amazon AWS [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/aws/aws_discover.go#L19-L33) * DigitalOcean [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/digitalocean/digitalocean_discover.go#L16-L24) * Google Cloud [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/gce/gce_discover.go#L17-L37) + * Linode [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/linode/linode_discover.go#L30-L41) * mDNS [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/mdns/mdns_provider.go#L19-L31) * Microsoft Azure [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/azure/azure_discover.go#L16-L37) * Openstack [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/os/os_discover.go#L23-L38) * Scaleway [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/scaleway/scaleway_discover.go#L14-L22) * SoftLayer [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/softlayer/softlayer_discover.go#L16-L25) + * TencentCloud [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/tencentcloud/tencentcloud_discover.go#L23-L37) * Triton [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/triton/triton_discover.go#L17-L27) * vSphere [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/vsphere/vsphere_discover.go#L148-L155) * Packet [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/packet/packet_discover.go#L25-L35) @@ -59,6 +61,9 @@ provider=digitalocean region=... tag_name=... api_token=... # Google Cloud provider=gce project_name=... zone_pattern=eu-west-* tag_value=consul credentials_file=... +# Linode +provider=linode tag_name=... region=us-east address_type=private_v4 api_token=... + # mDNS provider=mdns service=consul domain=local @@ -74,6 +79,9 @@ provider=scaleway organization=my-org tag_name=consul-server token=... region=.. # SoftLayer provider=softlayer datacenter=dal06 tag_value=consul username=... api_key=... +# TencentCloud +provider=tencentcloud region=ap-guangzhou tag_key=consul tag_value=... access_key_id=... access_key_secret=... + # Triton provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_id=... tag_key=consul-role tag_value=server diff --git a/vendor/github.com/hashicorp/go-discover/discover.go b/vendor/github.com/hashicorp/go-discover/discover.go index ae1d7fbf40..369fd4153a 100644 --- a/vendor/github.com/hashicorp/go-discover/discover.go +++ b/vendor/github.com/hashicorp/go-discover/discover.go @@ -14,11 +14,13 @@ import ( "github.com/hashicorp/go-discover/provider/azure" "github.com/hashicorp/go-discover/provider/digitalocean" "github.com/hashicorp/go-discover/provider/gce" + "github.com/hashicorp/go-discover/provider/linode" "github.com/hashicorp/go-discover/provider/mdns" "github.com/hashicorp/go-discover/provider/os" "github.com/hashicorp/go-discover/provider/packet" "github.com/hashicorp/go-discover/provider/scaleway" "github.com/hashicorp/go-discover/provider/softlayer" + "github.com/hashicorp/go-discover/provider/tencentcloud" "github.com/hashicorp/go-discover/provider/triton" "github.com/hashicorp/go-discover/provider/vsphere" ) @@ -48,10 +50,12 @@ var Providers = map[string]Provider{ "azure": &azure.Provider{}, "digitalocean": &digitalocean.Provider{}, "gce": &gce.Provider{}, + "linode": &linode.Provider{}, "mdns": &mdns.Provider{}, "os": &os.Provider{}, "scaleway": &scaleway.Provider{}, "softlayer": &softlayer.Provider{}, + "tencentcloud": &tencentcloud.Provider{}, "triton": &triton.Provider{}, "vsphere": &vsphere.Provider{}, "packet": &packet.Provider{}, diff --git a/vendor/github.com/hashicorp/go-discover/go.mod b/vendor/github.com/hashicorp/go-discover/go.mod index 55183c7336..e612d66f5a 100644 --- a/vendor/github.com/hashicorp/go-discover/go.mod +++ b/vendor/github.com/hashicorp/go-discover/go.mod @@ -5,11 +5,13 @@ require ( github.com/Azure/azure-sdk-for-go v16.0.0+incompatible github.com/Azure/go-autorest v10.7.0+incompatible github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af // indirect - github.com/aws/aws-sdk-go v1.15.24 + github.com/aws/aws-sdk-go v1.25.41 github.com/davecgh/go-spew v1.1.1 // indirect github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661 github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect github.com/digitalocean/godo v1.1.1 + github.com/dimchansky/utfbom v1.1.0 // indirect + github.com/dnaeon/go-vcr v1.0.1 // indirect github.com/fsnotify/fsnotify v1.4.7 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/gogo/protobuf v1.1.1 // indirect @@ -31,6 +33,8 @@ require ( github.com/joyent/triton-go v0.0.0-20180628001255-830d2b111e62 github.com/json-iterator/go v1.1.5 // indirect github.com/jtolds/gls v4.2.1+incompatible // indirect + github.com/likexian/gokit v0.20.16 + github.com/linode/linodego v0.7.1 github.com/mitchellh/go-homedir v1.0.0 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.1 // indirect @@ -49,6 +53,7 @@ require ( github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d github.com/spf13/pflag v1.0.2 // indirect github.com/stretchr/testify v1.2.2 // indirect + github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 // indirect github.com/vmware/govmomi v0.18.0 golang.org/x/oauth2 v0.0.0-20170807180024-9a379c6b3e95 @@ -60,9 +65,11 @@ require ( gopkg.in/fsnotify.v1 v1.4.7 // indirect gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect gopkg.in/inf.v0 v0.9.1 // indirect + gopkg.in/resty.v1 v1.12.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.2.1 // indirect k8s.io/api v0.0.0-20180806132203-61b11ee65332 k8s.io/apimachinery v0.0.0-20180821005732-488889b0007f k8s.io/client-go v8.0.0+incompatible + launchpad.net/gocheck v0.0.0-20140225173054-000000000087 // indirect ) diff --git a/vendor/github.com/hashicorp/go-discover/go.sum b/vendor/github.com/hashicorp/go-discover/go.sum index 704fedb35e..6d0642a9af 100644 --- a/vendor/github.com/hashicorp/go-discover/go.sum +++ b/vendor/github.com/hashicorp/go-discover/go.sum @@ -8,6 +8,8 @@ github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af h1:DBNMBMuMiWYu0b+8KM github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= github.com/aws/aws-sdk-go v1.15.24 h1:xLAdTA/ore6xdPAljzZRed7IGqQgC+nY+ERS5vaj4Ro= github.com/aws/aws-sdk-go v1.15.24/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= +github.com/aws/aws-sdk-go v1.25.41 h1:/hj7nZ0586wFqpwjNpzWiUTwtaMgxAZNZKHay80MdXw= +github.com/aws/aws-sdk-go v1.25.41/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661 h1:lrWnAyy/F72MbxIxFUzKmcMCdt9Oi8RzpAxzTNQHD7o= @@ -16,6 +18,10 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumC github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/digitalocean/godo v1.1.1 h1:v0A7yF3xmKLjjdJGIeBbINfMufcrrRhqZsxuVQMoT+U= github.com/digitalocean/godo v1.1.1/go.mod h1:h6faOIcZ8lWIwNQ+DN7b3CgX4Kwby5T+nbpNqkUIozU= +github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4= +github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= +github.com/dnaeon/go-vcr v1.0.1 h1:r8L/HqC0Hje5AXMu1ooW8oyQyOFv4GxqpL0nRP7SLLY= +github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -66,6 +72,16 @@ github.com/json-iterator/go v1.1.5 h1:gL2yXlmiIo4+t+y32d4WGwOjKGYcGOuyrg46vadswD github.com/json-iterator/go v1.1.5/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/likexian/gokit v0.0.0-20190309162924-0a377eecf7aa/go.mod h1:QdfYv6y6qPA9pbBA2qXtoT8BMKha6UyNbxWGWl/9Jfk= +github.com/likexian/gokit v0.0.0-20190418170008-ace88ad0983b/go.mod h1:KKqSnk/VVSW8kEyO2vVCXoanzEutKdlBAPohmGXkxCk= +github.com/likexian/gokit v0.0.0-20190501133040-e77ea8b19cdc/go.mod h1:3kvONayqCaj+UgrRZGpgfXzHdMYCAO0KAt4/8n0L57Y= +github.com/likexian/gokit v0.20.16 h1:8ypmVXLx8yIvlTwzH8Ybz8LDAfWjdy0W5O354JWPjA4= +github.com/likexian/gokit v0.20.16/go.mod h1:kn+nTv3tqh6yhor9BC4Lfiu58SmH8NmQ2PmEl+uM6nU= +github.com/likexian/simplejson-go v0.0.0-20190409170913-40473a74d76d/go.mod h1:Typ1BfnATYtZ/+/shXfFYLrovhFyuKvzwrdOnIDHlmg= +github.com/likexian/simplejson-go v0.0.0-20190419151922-c1f9f0b4f084/go.mod h1:U4O1vIJvIKwbMZKUJ62lppfdvkCdVd2nfMimHK81eec= +github.com/likexian/simplejson-go v0.0.0-20190502021454-d8787b4bfa0b/go.mod h1:3BWwtmKP9cXWwYCr5bkoVDEfLywacOv0s06OBEDpyt8= +github.com/linode/linodego v0.7.1 h1:4WZmMpSA2NRwlPZcc0+4Gyn7rr99Evk9bnr0B3gXRKE= +github.com/linode/linodego v0.7.1/go.mod h1:ga11n3ivecUrPCHN0rANxKmfWBJVkOXfLMZinAbj2sY= github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= @@ -104,6 +120,8 @@ github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc= github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible h1:8uRvJleFpqLsO77WaAh2UrasMOzd8MxXrNj20e7El+Q= +github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9 h1:/Bsw4C+DEdqPjt8vAqaC9LAqpAQnaCQQqmolqq3S1T4= github.com/tent/http-link-go v0.0.0-20130702225549-ac974c61c2f9/go.mod h1:RHkNRtSLfOK7qBTHaeSX1D6BNpI3qw7NTxsmNr4RvN8= github.com/vmware/govmomi v0.18.0 h1:f7QxSmP7meCtoAmiKZogvVbLInT+CZx6Px6K5rYsJZo= @@ -112,6 +130,8 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3 h1:KYQXGkl6vs02hK7pK4eIbw golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 h1:x6rhz8Y9CjbgQkccRGmELH6K+LJj7tOoh3XWeC1yaQM= golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/oauth2 v0.0.0-20170807180024-9a379c6b3e95 h1:RS+wSrhdVci7CsPwJaMN8exaP3UTuQU0qB34R/E/JD0= golang.org/x/oauth2 v0.0.0-20170807180024-9a379c6b3e95/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw= @@ -136,6 +156,8 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 h1:OAj3g0cR6Dx/R07QgQe8wkA9RNj gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKWaSkCsqBpgog8nAV2xsGOxlo= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= +gopkg.in/resty.v1 v1.12.0 h1:CuXP0Pjfw9rOuY6EP+UvtNvt5DSqHpIxILZKT/quCZI= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= @@ -146,3 +168,5 @@ k8s.io/apimachinery v0.0.0-20180821005732-488889b0007f h1:V0PkbgaYp5JqCmzLyRmssD k8s.io/apimachinery v0.0.0-20180821005732-488889b0007f/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0= k8s.io/client-go v8.0.0+incompatible h1:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4= k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54= +launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM= diff --git a/vendor/github.com/hashicorp/go-discover/provider/azure/azure_discover.go b/vendor/github.com/hashicorp/go-discover/provider/azure/azure_discover.go index 0409d988b1..2106b663f2 100644 --- a/vendor/github.com/hashicorp/go-discover/provider/azure/azure_discover.go +++ b/vendor/github.com/hashicorp/go-discover/provider/azure/azure_discover.go @@ -10,8 +10,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2015-06-15/network" "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/adal" - "github.com/Azure/go-autorest/autorest/azure" + "github.com/Azure/go-autorest/autorest/azure/auth" ) type Provider struct { @@ -40,6 +39,10 @@ func (p *Provider) Help() string { export ARM_CLIENT_ID for client export ARM_CLIENT_SECRET for secret access key + If none of those options are given, the Azure SDK is using the default environment based authentication outlined + here https://docs.microsoft.com/en-us/go/azure/azure-sdk-go-authorization#use-environment-based-authentication + This will fallback to MSI if nothing is explicitly specified. + Use these configuration parameters when using tags: tag_name: The name of the tag to filter on @@ -60,13 +63,15 @@ func (p *Provider) Help() string { // argsOrEnv allows you to pick an environmental variable for a setting if the arg is not set func argsOrEnv(args map[string]string, key, env string) string { - if value, ok := args[key]; ok { - return value - } - return os.Getenv(env) + if value, ok := args[key]; ok { + return value + } + return os.Getenv(env) } func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) { + var authorizer autorest.Authorizer + if args["provider"] != "azure" { return nil, fmt.Errorf("discover-azure: invalid provider " + args["provider"]) } @@ -81,6 +86,22 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error subscriptionID := argsOrEnv(args, "subscription_id", "ARM_SUBSCRIPTION_ID") secretKey := argsOrEnv(args, "secret_access_key", "ARM_CLIENT_SECRET") + // Try to use the argument and environment provided arguments first, if this fails fall back to the Azure + // SDK provided methods + if tenantID != "" && clientID != "" && secretKey != "" { + var err error + authorizer, err = auth.NewClientCredentialsConfig(clientID, secretKey, tenantID).Authorizer() + if err != nil { + return nil, fmt.Errorf("discover-azure (ClientCredentials): %s", err) + } + } else { + var err error + authorizer, err = auth.NewAuthorizerFromEnvironment() + if err != nil { + return nil, fmt.Errorf("discover-azure (EnvironmentCredentials): %s", err) + } + } + // Use tags if using network interfaces tagName := args["tag_name"] tagValue := args["tag_value"] @@ -89,22 +110,10 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error resourceGroup := args["resource_group"] vmScaleSet := args["vm_scale_set"] - // Only works for the Azure PublicCLoud for now; no ability to test other Environment - oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, tenantID) - if err != nil { - return nil, fmt.Errorf("discover-azure: %s", err) - } - - // Get the ServicePrincipalToken for use searching the NetworkInterfaces - sbt, err := adal.NewServicePrincipalToken(*oauthConfig, clientID, secretKey, azure.PublicCloud.ResourceManagerEndpoint) - if err != nil { - return nil, fmt.Errorf("discover-azure: %s", err) - } - // Setup the client using autorest; followed the structure from Terraform vmnet := network.NewInterfacesClient(subscriptionID) vmnet.Sender = autorest.CreateSender(autorest.WithLogging(l)) - vmnet.Authorizer = autorest.NewBearerAuthorizer(sbt) + vmnet.Authorizer = authorizer if p.userAgent != "" { vmnet.Client.UserAgent = p.userAgent diff --git a/vendor/github.com/hashicorp/go-discover/provider/linode/linode_discover.go b/vendor/github.com/hashicorp/go-discover/provider/linode/linode_discover.go new file mode 100644 index 0000000000..7322dab34f --- /dev/null +++ b/vendor/github.com/hashicorp/go-discover/provider/linode/linode_discover.go @@ -0,0 +1,142 @@ +// Package linode provides node discovery for Linode. +package linode + +import ( + "context" + "encoding/json" + "fmt" + "io/ioutil" + "log" + "net/http" + "os" + + "github.com/linode/linodego" + "golang.org/x/oauth2" +) + +type Filter struct { + Region string `json:"region,omitempty"` + Tag string `json:"tags,omitempty"` +} + +type Provider struct { + userAgent string +} + +func (p *Provider) SetUserAgent(s string) { + p.userAgent = s +} + +func (p *Provider) Help() string { + return `Linode: + provider: "linode" + api_token: The Linode API token to use + region: The Linode region to filter on + tag_name: The tag name to filter on + address_type: "private_v4", "public_v4", "private_v6" or "public_v6". (default: "private_v4") + + Variables can also be provided by environment variables: + export LINODE_TOKEN for api_token +` +} + +func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) { + if args["provider"] != "linode" { + return nil, fmt.Errorf("discover-linode: invalid provider " + args["provider"]) + } + + if l == nil { + l = log.New(ioutil.Discard, "", 0) + } + + addressType := args["address_type"] + region := args["region"] + tagName := args["tag_name"] + apiToken := argsOrEnv(args, "api_token", "LINODE_TOKEN") + l.Printf("[DEBUG] discover-linode: Using address_type=%s region=%s tag_name=%s", addressType, region, tagName) + + client := getLinodeClient(p.userAgent, apiToken) + + filters := Filter{ + Region: "", + Tag: "", + } + + if region != "" { + filters.Region = region + } + if tagName != "" { + filters.Tag = tagName + } + + jsonFilters, _ := json.Marshal(filters) + filterOpt := linodego.ListOptions{Filter: string(jsonFilters)} + + linodes, err := client.ListInstances(context.Background(), &filterOpt) + if err != nil { + return nil, fmt.Errorf("discover-linode: Fetching Linode instances failed: %s", err) + } + + var addrs []string + for _, linode := range linodes { + addr, err := client.GetInstanceIPAddresses(context.Background(), linode.ID) + if err != nil { + return nil, fmt.Errorf("discover-linode: Fetching Linode IP address for instance %v failed: %s", linode.ID, err) + } + + switch addressType { + case "public_v4": + if len(addr.IPv4.Public) == 0 { + break + } + addrs = append(addrs, addr.IPv4.Public[0].Address) + case "private_v4": + if len(addr.IPv4.Private) == 0 { + break + } + addrs = append(addrs, addr.IPv4.Private[0].Address) + case "public_v6": + if addr.IPv6.SLAAC.Address == "" { + break + } + addrs = append(addrs, addr.IPv6.SLAAC.Address) + case "private_v6": + if addr.IPv6.LinkLocal.Address == "" { + break + } + addrs = append(addrs, addr.IPv6.LinkLocal.Address) + default: + if len(addr.IPv4.Private) == 0 { + break + } + addrs = append(addrs, addr.IPv4.Private[0].Address) + } + } + + return addrs, nil +} + +func getLinodeClient(userAgent, apiToken string) linodego.Client { + tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiToken}) + + oauth2Client := &http.Client{ + Transport: &oauth2.Transport{ + Source: tokenSource, + }, + } + + client := linodego.NewClient(oauth2Client) + + if userAgent != "" { + client.SetUserAgent(userAgent) + } + + return client +} + +func argsOrEnv(args map[string]string, key, env string) string { + if value := args[key]; value != "" { + return value + } + return os.Getenv(env) +} diff --git a/vendor/github.com/hashicorp/go-discover/provider/tencentcloud/tencentcloud_discover.go b/vendor/github.com/hashicorp/go-discover/provider/tencentcloud/tencentcloud_discover.go new file mode 100644 index 0000000000..57e195678f --- /dev/null +++ b/vendor/github.com/hashicorp/go-discover/provider/tencentcloud/tencentcloud_discover.go @@ -0,0 +1,134 @@ +// Package tencentcloud provides node discovery for TencentCloud. +package tencentcloud + +import ( + "fmt" + "io/ioutil" + "log" + + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" + cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" +) + +type Provider struct { + userAgent string +} + +func (p *Provider) SetUserAgent(s string) { + p.userAgent = s +} + +func (p *Provider) Help() string { + return `TencentCloud: + + provider: "tencentcloud" + region: The TencentCloud region + tag_key: The tag key to filter on + tag_value: The tag value to filter on + address_type: "private_v4", "public_v4". (default: "private_v4") + access_key_id: The secret id of TencentCloud + access_key_secret: The secret key of TencentCloud + + This required permission to 'cvm:DescribeInstances'. + It is recommended you make a dedicated key used only for auto-joining. +` +} + +func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) { + if args["provider"] != "tencentcloud" { + return nil, fmt.Errorf("discover-tencentcloud: invalid provider " + args["provider"]) + } + + if l == nil { + l = log.New(ioutil.Discard, "", 0) + } + + region := args["region"] + tagKey := args["tag_key"] + tagValue := args["tag_value"] + addressType := args["address_type"] + accessKeyID := args["access_key_id"] + accessKeySecret := args["access_key_secret"] + + l.Printf("[DEBUG] discover-tencentcloud: Using region=%s, tag_key=%s, tag_value=%s", region, tagKey, tagValue) + if accessKeyID == "" { + l.Printf("[DEBUG] discover-tencentcloud: No static credentials provided") + } else { + l.Printf("[DEBUG] discover-tencentcloud: Static credentials provided") + } + + if region == "" { + l.Printf("[DEBUG] discover-tencentcloud: Region not provided") + return nil, fmt.Errorf("discover-tencentcloud: region missing") + } + l.Printf("[DEBUG] discover-tencentcloud: region is %s", region) + + if addressType == "" { + addressType = "private_v4" + } + + if addressType != "private_v4" && addressType != "public_v4" { + l.Printf("[DEBUG] discover-tencentcloud: Address type %s invalid", addressType) + return nil, fmt.Errorf("discover-tencentcloud: invalid address_type " + addressType) + } + l.Printf("[DEBUG] discover-tencentcloud: address type is %s", addressType) + + credential := common.NewCredential( + accessKeyID, + accessKeySecret, + ) + + cpf := profile.NewClientProfile() + cpf.HttpProfile.ReqMethod = "POST" + cpf.HttpProfile.ReqTimeout = 300 + cpf.Language = "en-US" + cvmClient, _ := cvm.NewClient(credential, region, cpf) + + l.Printf("[DEBUG] discover-tencentcloud: Filter instances with %s=%s", tagKey, tagValue) + request := cvm.NewDescribeInstancesRequest() + request.Filters = []*cvm.Filter{ + { + Name: stringToPointer("instance-state"), + Values: []*string{stringToPointer("RUNNING")}, + }, + { + Name: stringToPointer("tag:" + tagKey), + Values: []*string{stringToPointer(tagValue)}, + }, + } + + response, err := cvmClient.DescribeInstances(request) + if err != nil { + l.Printf("[DEBUG] discover-tencentcloud: DescribeInstances failed, %s", err) + return nil, fmt.Errorf("discover-tencentcloud: DescribeInstances failed, %s", err) + } + l.Printf("[DEBUG] discover-tencentcloud: Found %d instances", len(response.Response.InstanceSet)) + + var addrs []string + for _, v := range response.Response.InstanceSet { + switch addressType { + case "public_v4": + if len(v.PublicIpAddresses) == 0 { + l.Printf("[DEBUG] discover-tencentcloud: Instance %s has no public_v4", *v.InstanceId) + continue + } + l.Printf("[DEBUG] discover-tencentcloud: Instance %s has public_v4 %v", *v.InstanceId, *v.PublicIpAddresses[0]) + addrs = append(addrs, *v.PublicIpAddresses[0]) + case "private_v4": + if len(v.PrivateIpAddresses) == 0 { + l.Printf("[DEBUG] discover-tencentcloud: Instance %s has no private_v4", *v.InstanceId) + continue + } + l.Printf("[DEBUG] discover-tencentcloud: Instance %s has private_v4 %v", *v.InstanceId, *v.PrivateIpAddresses[0]) + addrs = append(addrs, *v.PrivateIpAddresses[0]) + } + } + + l.Printf("[DEBUG] discover-tencentcloud: Found address: %v", addrs) + return addrs, nil +} + +func stringToPointer(s string) *string { + return &s +} diff --git a/vendor/github.com/linode/linodego/.gitignore b/vendor/github.com/linode/linodego/.gitignore new file mode 100644 index 0000000000..d16559bdaf --- /dev/null +++ b/vendor/github.com/linode/linodego/.gitignore @@ -0,0 +1,19 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ + +vendor/**/ +.env +coverage.txt + diff --git a/vendor/github.com/linode/linodego/.travis.yml b/vendor/github.com/linode/linodego/.travis.yml new file mode 100644 index 0000000000..83fec93e33 --- /dev/null +++ b/vendor/github.com/linode/linodego/.travis.yml @@ -0,0 +1,22 @@ +language: "go" + +matrix: + allow_failures: + - go: tip + +go: + - "1.10" + - tip + +install: + - go get -u gopkg.in/alecthomas/gometalinter.v2 + - gometalinter.v2 --install + +script: + - touch .env + - make test ARGS='-v -race -count=2 -coverprofile=coverage.txt -covermode=atomic ./...' + - gometalinter.v2 --enable-all --disable=vetshadow --disable=gocyclo --disable=unparam --disable=nakedret --disable=lll --disable=dupl --disable=gosec --disable=gochecknoinits --disable=gochecknoglobals --disable=test --deadline=120s + - gometalinter.v2 --disable-all --enable=vetshadow --enable=gocyclo --enable=unparam --enable=nakedret --enable=lll --enable=dupl --enable=gosec --enable=gochecknoinits --enable=gochecknoglobals --deadline=120s || true + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/linode/linodego/API_SUPPORT.md b/vendor/github.com/linode/linodego/API_SUPPORT.md new file mode 100644 index 0000000000..2fd663f4f1 --- /dev/null +++ b/vendor/github.com/linode/linodego/API_SUPPORT.md @@ -0,0 +1,379 @@ +# API Support + +## Linodes + +- `/linode/instances` + - [x] `GET` + - [X] `POST` +- `/linode/instances/$id` + - [x] `GET` + - [X] `PUT` + - [X] `DELETE` +- `/linode/instances/$id/boot` + - [x] `POST` +- `/linode/instances/$id/clone` + - [x] `POST` +- `/linode/instances/$id/mutate` + - [X] `POST` +- `/linode/instances/$id/reboot` + - [x] `POST` +- `/linode/instances/$id/rebuild` + - [X] `POST` +- `/linode/instances/$id/rescue` + - [X] `POST` +- `/linode/instances/$id/resize` + - [x] `POST` +- `/linode/instances/$id/shutdown` + - [x] `POST` +- `/linode/instances/$id/volumes` + - [X] `GET` + +### Backups + +- `/linode/instances/$id/backups` + - [X] `GET` + - [ ] `POST` +- `/linode/instances/$id/backups/$id/restore` + - [ ] `POST` +- `/linode/instances/$id/backups/cancel` + - [ ] `POST` +- `/linode/instances/$id/backups/enable` + - [ ] `POST` + +### Configs + +- `/linode/instances/$id/configs` + - [X] `GET` + - [X] `POST` +- `/linode/instances/$id/configs/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` + +### Disks + +- `/linode/instances/$id/disks` + - [X] `GET` + - [X] `POST` +- `/linode/instances/$id/disks/$id` + - [X] `GET` + - [X] `PUT` + - [X] `POST` + - [X] `DELETE` +- `/linode/instances/$id/disks/$id/password` + - [X] `POST` +- `/linode/instances/$id/disks/$id/resize` + - [X] `POST` + +### IPs + +- `/linode/instances/$id/ips` + - [ ] `GET` + - [ ] `POST` +- `/linode/instances/$id/ips/$ip_address` + - [ ] `GET` + - [ ] `PUT` + - [ ] `DELETE` +- `/linode/instances/$id/ips/sharing` + - [ ] `POST` + +### Kernels + +- `/linode/kernels` + - [X] `GET` +- `/linode/kernels/$id` + - [X] `GET` + +### StackScripts + +- `/linode/stackscripts` + - [x] `GET` + - [X] `POST` +- `/linode/stackscripts/$id` + - [x] `GET` + - [X] `PUT` + - [X] `DELETE` + +### Stats + +- `/linode/instances/$id/stats` + - [ ] `GET` +- `/linode/instances/$id/stats/$year/$month` + - [ ] `GET` + +### Types + +- `/linode/types` + - [X] `GET` +- `/linode/types/$id` + - [X] `GET` + +## Domains + +- `/domains` + - [X] `GET` + - [X] `POST` +- `/domains/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` +- `/domains/$id/clone` + - [ ] `POST` +- `/domains/$id/records` + - [X] `GET` + - [X] `POST` +- `/domains/$id/records/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` + +## Longview + +- `/longview/clients` + - [X] `GET` + - [ ] `POST` +- `/longview/clients/$id` + - [X] `GET` + - [ ] `PUT` + - [ ] `DELETE` + +### Subscriptions + +- `/longview/subscriptions` + - [ ] `GET` +- `/longview/subscriptions/$id` + - [ ] `GET` + +### NodeBalancers + +- `/nodebalancers` + - [X] `GET` + - [X] `POST` +- `/nodebalancers/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` + +### NodeBalancer Configs + +- `/nodebalancers/$id/configs` + - [X] `GET` + - [X] `POST` +- `/nodebalancers/$id/configs/$id` + - [X] `GET` + - [X] `DELETE` +- `/nodebalancers/$id/configs/$id/nodes` + - [X] `GET` + - [X] `POST` +- `/nodebalancers/$id/configs/$id/nodes/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` +- `/nodebalancers/$id/configs/$id/rebuild` + - [X] `POST` + +## Networking + +- `/networking/ip-assign` + - [ ] `POST` +- `/networking/ips` + - [X] `GET` + - [ ] `POST` +- `/networking/ips/$address` + - [X] `GET` + - [ ] `PUT` + - [ ] `DELETE` + +### IPv6 + +- `/networking/ips` + - [X] `GET` +- `/networking/ips/$address` + - [X] `GET` + - [ ] `PUT` +- /networking/ipv6/ranges + - [X] `GET` +- /networking/ipv6/pools + - [X] `GET` + +## Regions + +- `/regions` + - [x] `GET` +- `/regions/$id` + - [x] `GET` + +## Support + +- `/support/tickets` + - [X] `GET` + - [ ] `POST` +- `/support/tickets/$id` + - [X] `GET` +- `/support/tickets/$id/attachments` + - [ ] `POST` +- `/support/tickets/$id/replies` + - [ ] `GET` + - [ ] `POST` + +## Tags + +- `/tags/` + - [X] `GET` + - [X] `POST` +- `/tags/$id` + - [X] `GET` + - [X] `DELETE` + +## Account + +### Events + +- `/account/events` + - [X] `GET` +- `/account/events/$id` + - [X] `GET` +- `/account/events/$id/read` + - [X] `POST` +- `/account/events/$id/seen` + - [X] `POST` + +### Invoices + +- `/account/invoices/` + - [X] `GET` +- `/account/invoices/$id` + - [X] `GET` +- `/account/invoices/$id/items` + - [X] `GET` + +### Notifications + +- `/account/notifications` + - [X] `GET` + +### OAuth Clients + +- `/account/oauth-clients` + - [ ] `GET` + - [ ] `POST` +- `/account/oauth-clients/$id` + - [ ] `GET` + - [ ] `PUT` + - [ ] `DELETE` +- `/account/oauth-clients/$id/reset_secret` + - [ ] `POST` +- `/account/oauth-clients/$id/thumbnail` + - [ ] `GET` + - [ ] `PUT` + +### Payments + +- `/account/payments` + - [ ] `GET` + - [ ] `POST` +- `/account/payments/$id` + - [ ] `GET` +- `/account/payments/paypal` + - [ ] `GET` +- `/account/payments/paypal/execute` + - [ ] `POST` + +### Settings + +- `/account/settings` + - [ ] `GET` + - [ ] `PUT` + +### Users + +- `/account/users` + - [X] `GET` + - [X] `POST` +- `/account/users/$username` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` +- `/account/users/$username/grants` + - [ ] `GET` + - [ ] `PUT` +- `/account/users/$username/password` + - [ ] `POST` + +## Profile + +### Personalized User Settings + +- `/profile` + - [X] `GET` + - [X] `PUT` + +### Granted OAuth Apps + +- `/profile/apps` + - [ ] `GET` +- `/profile/apps/$id` + - [ ] `GET` + - [ ] `DELETE` + +### Grants to Linode Resources + +- `/profile/grants` + - [ ] `GET` + +### SSH Keys + +- `/profile/sshkeys` + - [x] `GET` + - [x] `POST` +- `/profile/sshkeys/$id` + - [x] `GET` + - [x] `PUT` + - [x] `DELETE` + +### Two-Factor + +- `/profile/tfa-disable` + - [ ] `POST` +- `/profile/tfa-enable` + - [ ] `POST` +- `/profile/tfa-enable-confirm` + - [ ] `POST` + +### Personal Access API Tokens + +- `/profile/tokens` + - [X] `GET` + - [X] `POST` +- `/profile/tokens/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` + +## Images + +- `/images` + - [x] `GET` +- `/images/$id` + - [x] `GET` + - [X] `POST` + - [X] `PUT` + - [X] `DELETE` + +## Volumes + +- `/volumes` + - [X] `GET` + - [X] `POST` +- `/volumes/$id` + - [X] `GET` + - [X] `PUT` + - [X] `DELETE` +- `/volumes/$id/attach` + - [X] `POST` +- `/volumes/$id/clone` + - [X] `POST` +- `/volumes/$id/detach` + - [X] `POST` +- `/volumes/$id/resize` + - [X] `POST` diff --git a/vendor/github.com/linode/linodego/CHANGELOG.md b/vendor/github.com/linode/linodego/CHANGELOG.md new file mode 100644 index 0000000000..54c176642a --- /dev/null +++ b/vendor/github.com/linode/linodego/CHANGELOG.md @@ -0,0 +1,239 @@ +# Change Log + +## Unreleased + +### Fixes + +### Features + + + +## [v0.7.1](https://github.com/linode/linodego/compare/v0.7.0..v0.7.1) (2018-02-05) + +### Features + +* add `ClassDedicated` constant (`dedicated`) for use in `LinodeType` `Class` values + See the [Dedicated CPU Announcement](https://blog.linode.com/2019/02/05/introducing-linode-dedicated-cpu-instances/) + + + +## [v0.7.0](https://github.com/linode/linodego/compare/v0.6.2..v0.7.0) (2018-12-03) + +### Features + +* add `Tags` field in: `NodeBalancer`, `Domain`, `Volume` +* add `UpdateIPAddress` (for setting RDNS) + +### Fixes + +* invalid URL for `/v4/networking/` enpoints (IPv6 Ranges and Pools) has been correcrted + + + +## [v0.6.2](https://github.com/linode/linodego/compare/v0.6.1..v0.6.2) (2018-10-26) + +### Fixes + +* add missing `Account` fields: `address_1`, `address_2`, `phone` + + +## [v0.6.1](https://github.com/linode/linodego/compare/v0.6.0..v0.6.1) (2018-10-26) + +### Features + +* Adds support for fetching and updating basic Profile information + + +## [v0.6.0](https://github.com/linode/linodego/compare/v0.5.1..v0.6.0) (2018-10-25) + +### Fixes + +* Fixes Image date handling +* Fixes broken example code in README +* Fixes WaitForEventFinished when encountering events without entity +* Fixes ResizeInstanceDisk which was executing CloneInstanceDisk +* Fixes go-resty import path to gopkg.in version for future go module support + +### Features + +* Adds support for user account operations +* Adds support for profile tokens +* Adds support for Tags +* Adds PasswordResetInstanceDisk +* Adds DiskStatus constants +* Adds WaitForInstanceDiskStatus +* Adds SetPollDelay for configuring poll duration + + * Reduced polling time to millisecond granularity + * Change polling default to 3s to avoid 429 conditions + * Use poll delay in waitfor functions + + +## [v0.5.1](https://github.com/linode/linodego/compare/v0.5.0...v0.5.1) (2018-09-10) + +### Fixes + +* Domain.Status was not imported from API responses correctly + + +## [v0.5.0](https://github.com/linode/linodego/compare/v0.4.0...v0.5.0) (2018-09-09) + +### Breaking Changes + +* List functions return slice of thing instead of slice of pointer to thing + +### Feature + +* add SSHKeys methods to client (also affects InstanceCreate, InstanceDiskCreate) +* add RebuildNodeBalancerConfig (and CreateNodeBalancerConfig with Nodes) + +### Fixes + +* Event.TimeRemaining wouldn't parse all possible API value +* Tests no longer rely on known/special instance and volume ids + + +## [0.4.0](https://github.com/linode/linodego/compare/v0.3.0...0.4.0) (2018-08-27) + +### Breaking Changes + +Replaces bool, error results with error results, for: + +* instance\_snapshots.go: EnableInstanceBackups +* instance\_snapshots.go: CancelInstanceBackups +* instance\_snapshots.go: RestoreInstanceBackup +* instances.go: BootInstance +* instances.go: RebootInstance +* instances.go: MutateInstance +* instances.go: RescueInstance +* instances.go: ResizeInstance +* instances.go: ShutdownInstance +* volumes.go: DetachVolume +* volumes.go: ResizeVolume + + +### Docs + +* reword text about breaking changes until first tag + +### Feat + +* added MigrateInstance and InstanceResizing from 4.0.1-4.0.3 API Changelog +* added gometalinter to travis builds +* added missing function and type comments as reported by linting tools +* supply json values for all fields, useful for mocking responses using linodego types +* use context channels in WaitFor\* functions +* add LinodeTypeClass type (enum) +* add TicketStatus type (enum) +* update template thing and add a test template + +### Fix + +* TransferQuota was TransferQuote (and not parsed from the api correctly) +* stackscripts udf was not parsed correctly +* add InstanceCreateOptions.PrivateIP +* check the WaitFor timeout before sleeping to avoid extra sleep +* various linting warnings and unhandled err results as reported by linting tools +* fix GetStackscript 404 handling + + + + +## [0.3.0](https://github.com/linode/linodego/compare/v0.2.0...0.3.0) (2018-08-15) + +### Breaking Changes + +* WaitForVolumeLinodeID return fetch volume for consistency with out WaitFors +* Moved linodego from chiefy to github.com/linode. Thanks [@chiefy](https://github.com/chiefy)! + + + +## [v0.2.0](https://github.com/linode/linodego/compare/v0.1.1...v0.2.0) (2018-08-11) + +### Breaking Changes + +* WaitFor\* should be client methods + *use `client.WaitFor...` rather than `linodego.WaitFor(..., client, ...)`* + +* remove ListInstanceSnapshots (does not exist in the API) + *this never worked, so shouldn't cause a problem* + +* Changes UpdateOptions and CreateOptions and similar Options parameters to values instead of pointers + *these were never optional and the function never updated any values in the Options structures* + +* fixed various optional/zero Update and Create options + *some values are now pointers, and vice-versa* + + * Changes InstanceUpdateOptions to use pointers for optional fields Backups and Alerts + * Changes InstanceClone's Disks and Configs to ints instead of strings + +* using new enum string aliased types where appropriate + *`InstanceSnapshotStatus`, `DiskFilesystem`, `NodeMode`* + +### Feature + +* add RescueInstance and RescueInstanceOptions +* add CreateImage, UpdateImage, DeleteImage +* add EnableInstanceBackups, CancelInstanceBackups, RestoreInstanceBackup +* add WatchdogEnabled to InstanceUpdateOptions + +### Fix + +* return Volume from AttachVolume instead of bool +* add more boilerplate to template.go +* nodebalancers and domain records had no pagination support +* NodeBalancer transfer stats are not int + +### Tests + +* add fixtures and tests for NodeBalancerNodes +* fix nodebalancer tests to handle changes due to random labels +* add tests for nodebalancers and nodebalancer configs +* added tests for Backups flow +* TestListInstanceBackups fixture is hand tweaked because repeated polled events + appear to get the tests stuck + +### Deps + +* update all dependencies to latest + + + +## [v0.1.1](https://github.com/linode/linodego/compare/v0.0.1...v0.1.0) (2018-07-30) + +Adds more Domain handling + +### Fixed + +* go-resty doesnt pass errors when content-type is not set +* Domain, DomainRecords, tests and fixtures + +### Added + +* add CreateDomainRecord, UpdateDomainRecord, and DeleteDomainRecord + + + +## [v0.1.0](https://github.com/linode/linodego/compare/v0.0.1...v0.1.0) (2018-07-23) + +Deals with NewClient and context for all http requests + +### Breaking Changes + +* changed `NewClient(token, *http.RoundTripper)` to `NewClient(*http.Client)` +* changed all `Client` `Get`, `List`, `Create`, `Update`, `Delete`, and `Wait` calls to take context as the first parameter + +### Fixed + +* fixed docs should now show Examples for more functions + +### Added + +* added `Client.SetBaseURL(url string)` + + +## v0.0.1 (2018-07-20) + +### Changed + +* Initial tagged release diff --git a/vendor/github.com/linode/linodego/Gopkg.lock b/vendor/github.com/linode/linodego/Gopkg.lock new file mode 100644 index 0000000000..a7ca4f0154 --- /dev/null +++ b/vendor/github.com/linode/linodego/Gopkg.lock @@ -0,0 +1,111 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "master" + digest = "1:6e1c13bc32e58ccb4afa1115a3ba4fc071d918ed897b40dfa323ffb3fcc6619d" + name = "github.com/dnaeon/go-vcr" + packages = [ + "cassette", + "recorder", + ] + pruneopts = "UT" + revision = "aafff18a5cc28fa0b2f26baf6a14472cda9b54c6" + +[[projects]] + digest = "1:97df918963298c287643883209a2c3f642e6593379f97ab400c2a2e219ab647d" + name = "github.com/golang/protobuf" + packages = ["proto"] + pruneopts = "UT" + revision = "aa810b61a9c79d51363740d207bb46cf8e620ed5" + version = "v1.2.0" + +[[projects]] + branch = "master" + digest = "1:33b9d71d1dde2106309484a388eb7ba53cd1f67014e34a71f7b3dbc20bd186e5" + name = "golang.org/x/net" + packages = [ + "context", + "context/ctxhttp", + "idna", + "publicsuffix", + ] + pruneopts = "UT" + revision = "8a410e7b638dca158bf9e766925842f6651ff828" + +[[projects]] + branch = "master" + digest = "1:363b547c971a2b07474c598b6e9ebcb238d556d8a27f37b3895ad20cd50e7281" + name = "golang.org/x/oauth2" + packages = [ + ".", + "internal", + ] + pruneopts = "UT" + revision = "d2e6202438beef2727060aa7cabdd924d92ebfd9" + +[[projects]] + digest = "1:a2ab62866c75542dd18d2b069fec854577a20211d7c0ea6ae746072a1dccdd18" + name = "golang.org/x/text" + packages = [ + "collate", + "collate/build", + "internal/colltab", + "internal/gen", + "internal/tag", + "internal/triegen", + "internal/ucd", + "language", + "secure/bidirule", + "transform", + "unicode/bidi", + "unicode/cldr", + "unicode/norm", + "unicode/rangetable", + ] + pruneopts = "UT" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + digest = "1:328b5e4f197d928c444a51a75385f4b978915c0e75521f0ad6a3db976c97a7d3" + name = "google.golang.org/appengine" + packages = [ + "internal", + "internal/base", + "internal/datastore", + "internal/log", + "internal/remote_api", + "internal/urlfetch", + "urlfetch", + ] + pruneopts = "UT" + revision = "b1f26356af11148e710935ed1ac8a7f5702c7612" + version = "v1.1.0" + +[[projects]] + digest = "1:b7fc4c3fd91df516486f53cc86f4b55a0c815782dbe852c5a19cce8e6c577aac" + name = "gopkg.in/resty.v1" + packages = ["."] + pruneopts = "UT" + revision = "d4920dcf5b7689548a6db640278a9b35a5b48ec6" + version = "v1.9.1" + +[[projects]] + digest = "1:342378ac4dcb378a5448dd723f0784ae519383532f5e70ade24132c4c8693202" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "UT" + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + version = "v2.2.1" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/dnaeon/go-vcr/recorder", + "golang.org/x/oauth2", + "gopkg.in/resty.v1", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/vendor/github.com/linode/linodego/Gopkg.toml b/vendor/github.com/linode/linodego/Gopkg.toml new file mode 100644 index 0000000000..2765dc95c4 --- /dev/null +++ b/vendor/github.com/linode/linodego/Gopkg.toml @@ -0,0 +1,29 @@ +# Gopkg.toml example +# +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + +[prune] + go-tests = true + unused-packages = true diff --git a/vendor/github.com/linode/linodego/LICENSE b/vendor/github.com/linode/linodego/LICENSE new file mode 100644 index 0000000000..6b0e6bace7 --- /dev/null +++ b/vendor/github.com/linode/linodego/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Christopher "Chief" Najewicz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/linode/linodego/Makefile b/vendor/github.com/linode/linodego/Makefile new file mode 100644 index 0000000000..e5f533d428 --- /dev/null +++ b/vendor/github.com/linode/linodego/Makefile @@ -0,0 +1,43 @@ +include .env + +.PHONY: vendor example refresh-fixtures clean-fixtures + +.PHONY: test +test: vendor + @LINODE_FIXTURE_MODE="play" \ + LINODE_TOKEN="awesometokenawesometokenawesometoken" \ + go test $(ARGS) + +$(GOPATH)/bin/dep: + @go get -u github.com/golang/dep/cmd/dep + +vendor: $(GOPATH)/bin/dep + @dep ensure + +example: + @go run example/main.go + +clean-fixtures: + @-rm fixtures/*.yaml + +refresh-fixtures: clean-fixtures fixtures + +.PHONY: fixtures +fixtures: + @echo "* Running fixtures" + @LINODE_TOKEN=$(LINODE_TOKEN) \ + LINODE_FIXTURE_MODE="record" go test $(ARGS) + @echo "* Santizing fixtures" + @for yaml in fixtures/*yaml; do \ + sed -E -i "" -e "s/$(LINODE_TOKEN)/awesometokenawesometokenawesometoken/g" \ + -e 's/20[0-9]{2}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-9]{2}:[0-9]{2}/2018-01-02T03:04:05/g' \ + -e 's/nb-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}-[0-9]{1,3}\./nb-10-20-30-40./g' \ + -e 's/192\.168\.((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.)(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/192.168.030.040/g' \ + -e '/^192\.168/!s/((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])/10.20.30.40/g' \ + -e 's/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/1234::5678/g' \ + $$yaml; \ + done + +.PHONY: godoc +godoc: + @godoc -http=:6060 diff --git a/vendor/github.com/linode/linodego/README.md b/vendor/github.com/linode/linodego/README.md new file mode 100644 index 0000000000..7d0ae2bc12 --- /dev/null +++ b/vendor/github.com/linode/linodego/README.md @@ -0,0 +1,178 @@ +# linodego + +[![Build Status](https://travis-ci.org/linode/linodego.svg?branch=master)](https://travis-ci.org/linode/linodego) +[![GoDoc](https://godoc.org/github.com/linode/linodego?status.svg)](https://godoc.org/github.com/linode/linodego) +[![Go Report Card](https://goreportcard.com/badge/github.com/linode/linodego)](https://goreportcard.com/report/github.com/linode/linodego) +[![codecov](https://codecov.io/gh/linode/linodego/branch/master/graph/badge.svg)](https://codecov.io/gh/linode/linodego) + +Go client for [Linode REST v4 API](https://developers.linode.com/api/v4) + +## Installation + +```sh +go get -u github.com/linode/linodego +``` + +## API Support + +Check [API_SUPPORT.md](API_SUPPORT.md) for current support of the Linode `v4` API endpoints. + +** Note: This project will change and break until we release a v1.0.0 tagged version. Breaking changes in v0.x.x will be denoted with a minor version bump (v0.2.4 -> v0.3.0) ** + +## Documentation + +See [godoc](https://godoc.org/github.com/linode/linodego) for a complete reference. + +The API generally follows the naming patterns prescribed in the [OpenAPIv3 document for Linode APIv4](https://developers.linode.com/api/v4). + +Deviations in naming have been made to avoid using "Linode" and "Instance" redundantly or inconsistently. + +A brief summary of the features offered in this API client are shown here. + +## Examples + +### General Usage + +```go +package main + +import ( + "context" + "fmt" + + "github.com/linode/linodego" + "golang.org/x/oauth2" + + "log" + "net/http" + "os" +) + +func main() { + apiKey, ok := os.LookupEnv("LINODE_TOKEN") + if !ok { + log.Fatal("Could not find LINODE_TOKEN, please assert it is set.") + } + tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: apiKey}) + + oauth2Client := &http.Client{ + Transport: &oauth2.Transport{ + Source: tokenSource, + }, + } + + linodeClient := linodego.NewClient(oauth2Client) + linodeClient.SetDebug(true) + + res, err := linodeClient.GetInstance(context.Background(), 4090913) + if err != nil { + log.Fatal(err) + } + fmt.Printf("%v", res) +} +``` + +### Pagination + +#### Auto-Pagination Requests + +```go +kernels, err := linodego.ListKernels(context.Background(), nil) +// len(kernels) == 218 +``` + +Or, use a page value of "0": + +```go +opts := NewListOptions(0,"") +kernels, err := linodego.ListKernels(context.Background(), opts) +// len(kernels) == 218 +``` + +#### Single Page + +```go +opts := NewListOptions(2,"") +// or opts := ListOptions{PageOptions: &PageOptions: {Page: 2 }} +kernels, err := linodego.ListKernels(context.Background(), opts) +// len(kernels) == 100 +``` + +ListOptions are supplied as a pointer because the Pages and Results +values are set in the supplied ListOptions. + +```go +// opts.Results == 218 +``` + +#### Filtering + +```go +opts := ListOptions{Filter: "{\"mine\":true}"} +// or opts := NewListOptions(0, "{\"mine\":true}") +stackscripts, err := linodego.ListStackscripts(context.Background(), opts) +``` + +### Error Handling + +#### Getting Single Entities + +```go +linode, err := linodego.GetLinode(context.Background(), 555) // any Linode ID that does not exist or is not yours +// linode == nil: true +// err.Error() == "[404] Not Found" +// err.Code == "404" +// err.Message == "Not Found" +``` + +#### Lists + +For lists, the list is still returned as `[]`, but `err` works the same way as on the `Get` request. + +```go +linodes, err := linodego.ListLinodes(context.Background(), NewListOptions(0, "{\"foo\":bar}")) +// linodes == [] +// err.Error() == "[400] [X-Filter] Cannot filter on foo" +``` + +Otherwise sane requests beyond the last page do not trigger an error, just an empty result: + +```go +linodes, err := linodego.ListLinodes(context.Background(), NewListOptions(9999, "")) +// linodes == [] +// err = nil +``` + +### Writes + +When performing a `POST` or `PUT` request, multiple field related errors will be returned as a single error, currently like: + +```go +// err.Error() == "[400] [field1] foo problem; [field2] bar problem; [field3] baz problem" +``` + +## Tests + +Run `make test` to run the unit tests. This is the same as running `go test` except that `make test` will +execute the tests while playing back API response fixtures that were recorded during a previous development build. + +`go test` can be used without the fixtures. Copy `env.sample` to `.env` and configure your persistent test +settings, including an API token. + +`go test -short` can be used to run live API tests that do not require an account token. + +This will be simplified in future versions. + +To update the test fixtures, run `make fixtures`. This will record the API responses into the `fixtures/` directory. +Be careful about committing any sensitive account details. An attempt has been made to sanitize IP addresses and +dates, but no automated sanitization will be performed against `fixtures/*Account*.yaml`, for example. + +To prevent disrupting unaffected fixtures, target fixture generation like so: `make ARGS="-run TestListVolumes" fixtures`. + +## Discussion / Help + +Join us at [#linodego](https://gophers.slack.com/messages/CAG93EB2S) on the [gophers slack](https://gophers.slack.com) + +## License + +[MIT License](LICENSE) diff --git a/vendor/github.com/linode/linodego/account.go b/vendor/github.com/linode/linodego/account.go new file mode 100644 index 0000000000..d6092f07d7 --- /dev/null +++ b/vendor/github.com/linode/linodego/account.go @@ -0,0 +1,45 @@ +package linodego + +import "context" + +// Account associated with the token in use +type Account struct { + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Email string `json:"email"` + Company string `json:"company"` + Address1 string `json:"address_1"` + Address2 string `json:"address_2"` + Balance float32 `json:"balance"` + City string `json:"city"` + State string `json:"state"` + Zip string `json:"zip"` + Country string `json:"country"` + TaxID string `json:"tax_id"` + Phone string `json:"phone"` + CreditCard *CreditCard `json:"credit_card"` +} + +// CreditCard information associated with the Account. +type CreditCard struct { + LastFour string `json:"last_four"` + Expiry string `json:"expiry"` +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *Account) fixDates() *Account { + return v +} + +// GetAccount gets the contact and billing information related to the Account +func (c *Client) GetAccount(ctx context.Context) (*Account, error) { + e, err := c.Account.Endpoint() + if err != nil { + return nil, err + } + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Account{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Account).fixDates(), nil +} diff --git a/vendor/github.com/linode/linodego/account_events.go b/vendor/github.com/linode/linodego/account_events.go new file mode 100644 index 0000000000..e2365c35b6 --- /dev/null +++ b/vendor/github.com/linode/linodego/account_events.go @@ -0,0 +1,277 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "log" + "strconv" + "strings" + "time" +) + +// Event represents an action taken on the Account. +type Event struct { + CreatedStr string `json:"created"` + + // The unique ID of this Event. + ID int `json:"id"` + + // Current status of the Event, Enum: "failed" "finished" "notification" "scheduled" "started" + Status EventStatus `json:"status"` + + // The action that caused this Event. New actions may be added in the future. + Action EventAction `json:"action"` + + // A percentage estimating the amount of time remaining for an Event. Returns null for notification events. + PercentComplete int `json:"percent_complete"` + + // The rate of completion of the Event. Only some Events will return rate; for example, migration and resize Events. + Rate *string `json:"rate"` + + // If this Event has been read. + Read bool `json:"read"` + + // If this Event has been seen. + Seen bool `json:"seen"` + + // The estimated time remaining until the completion of this Event. This value is only returned for in-progress events. + TimeRemainingMsg json.RawMessage `json:"time_remaining"` + TimeRemaining *int `json:"-"` + + // The username of the User who caused the Event. + Username string `json:"username"` + + // Detailed information about the Event's entity, including ID, type, label, and URL used to access it. + Entity *EventEntity `json:"entity"` + + // When this Event was created. + Created *time.Time `json:"-"` +} + +// EventAction constants start with Action and include all known Linode API Event Actions. +type EventAction string + +// EventAction constants represent the actions that cause an Event. New actions may be added in the future. +const ( + ActionBackupsEnable EventAction = "backups_enable" + ActionBackupsCancel EventAction = "backups_cancel" + ActionBackupsRestore EventAction = "backups_restore" + ActionCommunityQuestionReply EventAction = "community_question_reply" + ActionCreateCardUpdated EventAction = "credit_card_updated" + ActionDiskCreate EventAction = "disk_create" + ActionDiskDelete EventAction = "disk_delete" + ActionDiskDuplicate EventAction = "disk_duplicate" + ActionDiskImagize EventAction = "disk_imagize" + ActionDiskResize EventAction = "disk_resize" + ActionDNSRecordCreate EventAction = "dns_record_create" + ActionDNSRecordDelete EventAction = "dns_record_delete" + ActionDNSZoneCreate EventAction = "dns_zone_create" + ActionDNSZoneDelete EventAction = "dns_zone_delete" + ActionImageDelete EventAction = "image_delete" + ActionLinodeAddIP EventAction = "linode_addip" + ActionLinodeBoot EventAction = "linode_boot" + ActionLinodeClone EventAction = "linode_clone" + ActionLinodeCreate EventAction = "linode_create" + ActionLinodeDelete EventAction = "linode_delete" + ActionLinodeDeleteIP EventAction = "linode_deleteip" + ActionLinodeMigrate EventAction = "linode_migrate" + ActionLinodeMutate EventAction = "linode_mutate" + ActionLinodeReboot EventAction = "linode_reboot" + ActionLinodeRebuild EventAction = "linode_rebuild" + ActionLinodeResize EventAction = "linode_resize" + ActionLinodeShutdown EventAction = "linode_shutdown" + ActionLinodeSnapshot EventAction = "linode_snapshot" + ActionLongviewClientCreate EventAction = "longviewclient_create" + ActionLongviewClientDelete EventAction = "longviewclient_delete" + ActionManagedDisabled EventAction = "managed_disabled" + ActionManagedEnabled EventAction = "managed_enabled" + ActionManagedServiceCreate EventAction = "managed_service_create" + ActionManagedServiceDelete EventAction = "managed_service_delete" + ActionNodebalancerCreate EventAction = "nodebalancer_create" + ActionNodebalancerDelete EventAction = "nodebalancer_delete" + ActionNodebalancerConfigCreate EventAction = "nodebalancer_config_create" + ActionNodebalancerConfigDelete EventAction = "nodebalancer_config_delete" + ActionPasswordReset EventAction = "password_reset" + ActionPaymentSubmitted EventAction = "payment_submitted" + ActionStackScriptCreate EventAction = "stackscript_create" + ActionStackScriptDelete EventAction = "stackscript_delete" + ActionStackScriptPublicize EventAction = "stackscript_publicize" + ActionStackScriptRevise EventAction = "stackscript_revise" + ActionTFADisabled EventAction = "tfa_disabled" + ActionTFAEnabled EventAction = "tfa_enabled" + ActionTicketAttachmentUpload EventAction = "ticket_attachment_upload" + ActionTicketCreate EventAction = "ticket_create" + ActionTicketReply EventAction = "ticket_reply" + ActionVolumeAttach EventAction = "volume_attach" + ActionVolumeClone EventAction = "volume_clone" + ActionVolumeCreate EventAction = "volume_create" + ActionVolumeDelte EventAction = "volume_delete" + ActionVolumeDetach EventAction = "volume_detach" + ActionVolumeResize EventAction = "volume_resize" +) + +// EntityType constants start with Entity and include Linode API Event Entity Types +type EntityType string + +// EntityType contants are the entities an Event can be related to +const ( + EntityLinode EntityType = "linode" + EntityDisk EntityType = "disk" +) + +// EventStatus constants start with Event and include Linode API Event Status values +type EventStatus string + +// EventStatus constants reflect the current status of an Event +const ( + EventFailed EventStatus = "failed" + EventFinished EventStatus = "finished" + EventNotification EventStatus = "notification" + EventScheduled EventStatus = "scheduled" + EventStarted EventStatus = "started" +) + +// EventEntity provides detailed information about the Event's +// associated entity, including ID, Type, Label, and a URL that +// can be used to access it. +type EventEntity struct { + // ID may be a string or int, it depends on the EntityType + ID interface{} `json:"id"` + Label string `json:"label"` + Type EntityType `json:"type"` + URL string `json:"url"` +} + +// EventsPagedResponse represents a paginated Events API response +type EventsPagedResponse struct { + *PageOptions + Data []Event `json:"data"` +} + +// endpoint gets the endpoint URL for Event +func (EventsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Events.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// endpointWithID gets the endpoint URL for a specific Event +func (e Event) endpointWithID(c *Client) string { + endpoint, err := c.Events.Endpoint() + if err != nil { + panic(err) + } + endpoint = fmt.Sprintf("%s/%d", endpoint, e.ID) + return endpoint +} + +// appendData appends Events when processing paginated Event responses +func (resp *EventsPagedResponse) appendData(r *EventsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListEvents gets a collection of Event objects representing actions taken +// on the Account. The Events returned depend on the token grants and the grants +// of the associated user. +func (c *Client) ListEvents(ctx context.Context, opts *ListOptions) ([]Event, error) { + response := EventsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetEvent gets the Event with the Event ID +func (c *Client) GetEvent(ctx context.Context, id int) (*Event, error) { + e, err := c.Events.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := c.R(ctx).SetResult(&Event{}).Get(e) + if err != nil { + return nil, err + } + return r.Result().(*Event).fixDates(), nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (e *Event) fixDates() *Event { + e.Created, _ = parseDates(e.CreatedStr) + e.TimeRemaining = unmarshalTimeRemaining(e.TimeRemainingMsg) + return e +} + +// MarkEventRead marks a single Event as read. +func (c *Client) MarkEventRead(ctx context.Context, event *Event) error { + e := event.endpointWithID(c) + e = fmt.Sprintf("%s/read", e) + + _, err := coupleAPIErrors(c.R(ctx).Post(e)) + + return err +} + +// MarkEventsSeen marks all Events up to and including this Event by ID as seen. +func (c *Client) MarkEventsSeen(ctx context.Context, event *Event) error { + e := event.endpointWithID(c) + e = fmt.Sprintf("%s/seen", e) + + _, err := coupleAPIErrors(c.R(ctx).Post(e)) + + return err +} + +func unmarshalTimeRemaining(m json.RawMessage) *int { + jsonBytes, err := m.MarshalJSON() + if err != nil { + panic(jsonBytes) + } + + if len(jsonBytes) == 4 && string(jsonBytes) == "null" { + return nil + } + + var timeStr string + if err := json.Unmarshal(jsonBytes, &timeStr); err == nil && len(timeStr) > 0 { + if dur, err := durationToSeconds(timeStr); err != nil { + panic(err) + } else { + return &dur + } + } else { + var intPtr int + if err := json.Unmarshal(jsonBytes, &intPtr); err == nil { + return &intPtr + } + } + + log.Println("[WARN] Unexpected unmarshalTimeRemaining value: ", jsonBytes) + return nil +} + +// durationToSeconds takes a hh:mm:ss string and returns the number of seconds +func durationToSeconds(s string) (int, error) { + multipliers := [3]int{60 * 60, 60, 1} + segs := strings.Split(s, ":") + if len(segs) > len(multipliers) { + return 0, fmt.Errorf("too many ':' separators in time duration: %s", s) + } + var d int + l := len(segs) + for i := 0; i < l; i++ { + m, err := strconv.Atoi(segs[i]) + if err != nil { + return 0, err + } + d += m * multipliers[i+len(multipliers)-l] + } + return d, nil +} diff --git a/vendor/github.com/linode/linodego/account_invoices.go b/vendor/github.com/linode/linodego/account_invoices.go new file mode 100644 index 0000000000..75ca2f73d2 --- /dev/null +++ b/vendor/github.com/linode/linodego/account_invoices.go @@ -0,0 +1,125 @@ +package linodego + +import ( + "context" + "fmt" + "time" +) + +// Invoice structs reflect an invoice for billable activity on the account. +type Invoice struct { + DateStr string `json:"date"` + + ID int `json:"id"` + Label string `json:"label"` + Total float32 `json:"total"` + Date *time.Time `json:"-"` +} + +// InvoiceItem structs reflect an single billable activity associate with an Invoice +type InvoiceItem struct { + FromStr string `json:"from"` + ToStr string `json:"to"` + + Label string `json:"label"` + Type string `json:"type"` + UnitPrice int `json:"unitprice"` + Quantity int `json:"quantity"` + Amount float32 `json:"amount"` + From *time.Time `json:"-"` + To *time.Time `json:"-"` +} + +// InvoicesPagedResponse represents a paginated Invoice API response +type InvoicesPagedResponse struct { + *PageOptions + Data []Invoice `json:"data"` +} + +// endpoint gets the endpoint URL for Invoice +func (InvoicesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Invoices.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Invoices when processing paginated Invoice responses +func (resp *InvoicesPagedResponse) appendData(r *InvoicesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInvoices gets a paginated list of Invoices against the Account +func (c *Client) ListInvoices(ctx context.Context, opts *ListOptions) ([]Invoice, error) { + response := InvoicesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *Invoice) fixDates() *Invoice { + v.Date, _ = parseDates(v.DateStr) + return v +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *InvoiceItem) fixDates() *InvoiceItem { + v.From, _ = parseDates(v.FromStr) + v.To, _ = parseDates(v.ToStr) + return v +} + +// GetInvoice gets the a single Invoice matching the provided ID +func (c *Client) GetInvoice(ctx context.Context, id int) (*Invoice, error) { + e, err := c.Invoices.Endpoint() + if err != nil { + return nil, err + } + + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Invoice{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Invoice).fixDates(), nil +} + +// InvoiceItemsPagedResponse represents a paginated Invoice Item API response +type InvoiceItemsPagedResponse struct { + *PageOptions + Data []InvoiceItem `json:"data"` +} + +// endpointWithID gets the endpoint URL for InvoiceItems associated with a specific Invoice +func (InvoiceItemsPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.InvoiceItems.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends InvoiceItems when processing paginated Invoice Item responses +func (resp *InvoiceItemsPagedResponse) appendData(r *InvoiceItemsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInvoiceItems gets the invoice items associated with a specific Invoice +func (c *Client) ListInvoiceItems(ctx context.Context, id int, opts *ListOptions) ([]InvoiceItem, error) { + response := InvoiceItemsPagedResponse{} + err := c.listHelperWithID(ctx, &response, id, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} diff --git a/vendor/github.com/linode/linodego/account_notifications.go b/vendor/github.com/linode/linodego/account_notifications.go new file mode 100644 index 0000000000..1d2de2e62c --- /dev/null +++ b/vendor/github.com/linode/linodego/account_notifications.go @@ -0,0 +1,101 @@ +package linodego + +import ( + "context" + "time" +) + +// Notification represents a notification on an Account +type Notification struct { + UntilStr string `json:"until"` + WhenStr string `json:"when"` + + Label string `json:"label"` + Body *string `json:"body"` + Message string `json:"message"` + Type NotificationType `json:"type"` + Severity NotificationSeverity `json:"severity"` + Entity *NotificationEntity `json:"entity"` + Until *time.Time `json:"-"` + When *time.Time `json:"-"` +} + +// NotificationEntity adds detailed information about the Notification. +// This could refer to the ticket that triggered the notification, for example. +type NotificationEntity struct { + ID int `json:"id"` + Label string `json:"label"` + Type string `json:"type"` + URL string `json:"url"` +} + +// NotificationSeverity constants start with Notification and include all known Linode API Notification Severities. +type NotificationSeverity string + +// NotificationSeverity constants represent the actions that cause a Notification. New severities may be added in the future. +const ( + NotificationMinor NotificationSeverity = "minor" + NotificationMajor NotificationSeverity = "major" + NotificationCritical NotificationSeverity = "critical" +) + +// NotificationType constants start with Notification and include all known Linode API Notification Types. +type NotificationType string + +// NotificationType constants represent the actions that cause a Notification. New types may be added in the future. +const ( + NotificationMigrationScheduled NotificationType = "migration_scheduled" + NotificationMigrationImminent NotificationType = "migration_imminent" + NotificationMigrationPending NotificationType = "migration_pending" + NotificationRebootScheduled NotificationType = "reboot_scheduled" + NotificationOutage NotificationType = "outage" + NotificationPaymentDue NotificationType = "payment_due" + NotificationTicketImportant NotificationType = "ticket_important" + NotificationTicketAbuse NotificationType = "ticket_abuse" + NotificationNotice NotificationType = "notice" + NotificationMaintenance NotificationType = "maintenance" +) + +// NotificationsPagedResponse represents a paginated Notifications API response +type NotificationsPagedResponse struct { + *PageOptions + Data []Notification `json:"data"` +} + +// endpoint gets the endpoint URL for Notification +func (NotificationsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Notifications.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Notifications when processing paginated Notification responses +func (resp *NotificationsPagedResponse) appendData(r *NotificationsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListNotifications gets a collection of Notification objects representing important, +// often time-sensitive items related to the Account. An account cannot interact directly with +// Notifications, and a Notification will disappear when the circumstances causing it +// have been resolved. For example, if the account has an important Ticket open, a response +// to the Ticket will dismiss the Notification. +func (c *Client) ListNotifications(ctx context.Context, opts *ListOptions) ([]Notification, error) { + response := NotificationsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *Notification) fixDates() *Notification { + v.Until, _ = parseDates(v.UntilStr) + v.When, _ = parseDates(v.WhenStr) + return v +} diff --git a/vendor/github.com/linode/linodego/account_users.go b/vendor/github.com/linode/linodego/account_users.go new file mode 100644 index 0000000000..a51fbe7f19 --- /dev/null +++ b/vendor/github.com/linode/linodego/account_users.go @@ -0,0 +1,164 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// User represents a User object +type User struct { + Username string `json:"username"` + Email string `json:"email"` + Restricted bool `json:"restricted"` + SSHKeys []string `json:"ssh_keys"` +} + +// UserCreateOptions fields are those accepted by CreateUser +type UserCreateOptions struct { + Username string `json:"username"` + Email string `json:"email"` + Restricted bool `json:"restricted,omitempty"` +} + +// UserUpdateOptions fields are those accepted by UpdateUser +type UserUpdateOptions struct { + Username string `json:"username,omitempty"` + Email string `json:"email,omitempty"` + Restricted *bool `json:"restricted,omitempty"` + SSHKeys *[]string `json:"ssh_keys,omitempty"` +} + +// GetCreateOptions converts a User to UserCreateOptions for use in CreateUser +func (i User) GetCreateOptions() (o UserCreateOptions) { + o.Username = i.Username + o.Email = i.Email + o.Restricted = i.Restricted + return +} + +// GetUpdateOptions converts a User to UserUpdateOptions for use in UpdateUser +func (i User) GetUpdateOptions() (o UserUpdateOptions) { + o.Username = i.Username + o.Email = i.Email + o.Restricted = copyBool(&i.Restricted) + return +} + +// UsersPagedResponse represents a paginated User API response +type UsersPagedResponse struct { + *PageOptions + Data []User `json:"data"` +} + +// endpoint gets the endpoint URL for User +func (UsersPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Users.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Users when processing paginated User responses +func (resp *UsersPagedResponse) appendData(r *UsersPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListUsers lists Users on the account +func (c *Client) ListUsers(ctx context.Context, opts *ListOptions) ([]User, error) { + response := UsersPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *User) fixDates() *User { + return i +} + +// GetUser gets the user with the provided ID +func (c *Client) GetUser(ctx context.Context, id string) (*User, error) { + e, err := c.Users.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&User{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*User).fixDates(), nil +} + +// CreateUser creates a User. The email address must be confirmed before the +// User account can be accessed. +func (c *Client) CreateUser(ctx context.Context, createOpts UserCreateOptions) (*User, error) { + var body string + e, err := c.Users.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&User{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*User).fixDates(), nil +} + +// UpdateUser updates the User with the specified id +func (c *Client) UpdateUser(ctx context.Context, id string, updateOpts UserUpdateOptions) (*User, error) { + var body string + e, err := c.Users.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + + req := c.R(ctx).SetResult(&User{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*User).fixDates(), nil +} + +// DeleteUser deletes the User with the specified id +func (c *Client) DeleteUser(ctx context.Context, id string) error { + e, err := c.Users.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%s", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/client.go b/vendor/github.com/linode/linodego/client.go new file mode 100644 index 0000000000..224a496dec --- /dev/null +++ b/vendor/github.com/linode/linodego/client.go @@ -0,0 +1,257 @@ +package linodego + +import ( + "context" + "fmt" + "log" + "net/http" + "os" + "strconv" + "time" + + "gopkg.in/resty.v1" +) + +const ( + // APIHost Linode API hostname + APIHost = "api.linode.com" + // APIVersion Linode API version + APIVersion = "v4" + // APIProto connect to API with http(s) + APIProto = "https" + // Version of linodego + Version = "0.7.0" + // APIEnvVar environment var to check for API token + APIEnvVar = "LINODE_TOKEN" + // APISecondsPerPoll how frequently to poll for new Events or Status in WaitFor functions + APISecondsPerPoll = 3 + // DefaultUserAgent is the default User-Agent sent in HTTP request headers + DefaultUserAgent = "linodego " + Version + " https://github.com/linode/linodego" +) + +var ( + envDebug = false +) + +// Client is a wrapper around the Resty client +type Client struct { + resty *resty.Client + userAgent string + resources map[string]*Resource + debug bool + + millisecondsPerPoll time.Duration + + Images *Resource + InstanceDisks *Resource + InstanceConfigs *Resource + InstanceSnapshots *Resource + InstanceIPs *Resource + InstanceVolumes *Resource + Instances *Resource + IPAddresses *Resource + IPv6Pools *Resource + IPv6Ranges *Resource + Regions *Resource + StackScripts *Resource + Volumes *Resource + Kernels *Resource + Types *Resource + Domains *Resource + DomainRecords *Resource + Longview *Resource + LongviewClients *Resource + LongviewSubscriptions *Resource + NodeBalancers *Resource + NodeBalancerConfigs *Resource + NodeBalancerNodes *Resource + SSHKeys *Resource + Tickets *Resource + Tokens *Resource + Token *Resource + Account *Resource + Invoices *Resource + InvoiceItems *Resource + Events *Resource + Notifications *Resource + Profile *Resource + Managed *Resource + Tags *Resource + Users *Resource +} + +func init() { + // Wether or not we will enable Resty debugging output + if apiDebug, ok := os.LookupEnv("LINODE_DEBUG"); ok { + if parsed, err := strconv.ParseBool(apiDebug); err == nil { + envDebug = parsed + log.Println("[INFO] LINODE_DEBUG being set to", envDebug) + } else { + log.Println("[WARN] LINODE_DEBUG should be an integer, 0 or 1") + } + } + +} + +// SetUserAgent sets a custom user-agent for HTTP requests +func (c *Client) SetUserAgent(ua string) *Client { + c.userAgent = ua + c.resty.SetHeader("User-Agent", c.userAgent) + + return c +} + +// R wraps resty's R method +func (c *Client) R(ctx context.Context) *resty.Request { + return c.resty.R(). + ExpectContentType("application/json"). + SetHeader("Content-Type", "application/json"). + SetContext(ctx). + SetError(APIError{}) +} + +// SetDebug sets the debug on resty's client +func (c *Client) SetDebug(debug bool) *Client { + c.debug = debug + c.resty.SetDebug(debug) + return c +} + +// SetBaseURL sets the base URL of the Linode v4 API (https://api.linode.com/v4) +func (c *Client) SetBaseURL(url string) *Client { + c.resty.SetHostURL(url) + return c +} + +// SetPollDelay sets the number of milliseconds to wait between events or status polls. +// Affects all WaitFor* functions. +func (c *Client) SetPollDelay(delay time.Duration) *Client { + c.millisecondsPerPoll = delay + return c +} + +// Resource looks up a resource by name +func (c Client) Resource(resourceName string) *Resource { + selectedResource, ok := c.resources[resourceName] + if !ok { + log.Fatalf("Could not find resource named '%s', exiting.", resourceName) + } + return selectedResource +} + +// NewClient factory to create new Client struct +func NewClient(hc *http.Client) (client Client) { + restyClient := resty.NewWithClient(hc) + client.resty = restyClient + client.SetUserAgent(DefaultUserAgent) + client.SetBaseURL(fmt.Sprintf("%s://%s/%s", APIProto, APIHost, APIVersion)) + client.SetPollDelay(1000 * APISecondsPerPoll) + + resources := map[string]*Resource{ + stackscriptsName: NewResource(&client, stackscriptsName, stackscriptsEndpoint, false, Stackscript{}, StackscriptsPagedResponse{}), + imagesName: NewResource(&client, imagesName, imagesEndpoint, false, Image{}, ImagesPagedResponse{}), + instancesName: NewResource(&client, instancesName, instancesEndpoint, false, Instance{}, InstancesPagedResponse{}), + instanceDisksName: NewResource(&client, instanceDisksName, instanceDisksEndpoint, true, InstanceDisk{}, InstanceDisksPagedResponse{}), + instanceConfigsName: NewResource(&client, instanceConfigsName, instanceConfigsEndpoint, true, InstanceConfig{}, InstanceConfigsPagedResponse{}), + instanceSnapshotsName: NewResource(&client, instanceSnapshotsName, instanceSnapshotsEndpoint, true, InstanceSnapshot{}, nil), + instanceIPsName: NewResource(&client, instanceIPsName, instanceIPsEndpoint, true, InstanceIP{}, nil), // really? + instanceVolumesName: NewResource(&client, instanceVolumesName, instanceVolumesEndpoint, true, nil, InstanceVolumesPagedResponse{}), // really? + ipaddressesName: NewResource(&client, ipaddressesName, ipaddressesEndpoint, false, nil, IPAddressesPagedResponse{}), // really? + ipv6poolsName: NewResource(&client, ipv6poolsName, ipv6poolsEndpoint, false, nil, IPv6PoolsPagedResponse{}), // really? + ipv6rangesName: NewResource(&client, ipv6rangesName, ipv6rangesEndpoint, false, IPv6Range{}, IPv6RangesPagedResponse{}), + regionsName: NewResource(&client, regionsName, regionsEndpoint, false, Region{}, RegionsPagedResponse{}), + volumesName: NewResource(&client, volumesName, volumesEndpoint, false, Volume{}, VolumesPagedResponse{}), + kernelsName: NewResource(&client, kernelsName, kernelsEndpoint, false, LinodeKernel{}, LinodeKernelsPagedResponse{}), + typesName: NewResource(&client, typesName, typesEndpoint, false, LinodeType{}, LinodeTypesPagedResponse{}), + domainsName: NewResource(&client, domainsName, domainsEndpoint, false, Domain{}, DomainsPagedResponse{}), + domainRecordsName: NewResource(&client, domainRecordsName, domainRecordsEndpoint, true, DomainRecord{}, DomainRecordsPagedResponse{}), + longviewName: NewResource(&client, longviewName, longviewEndpoint, false, nil, nil), // really? + longviewclientsName: NewResource(&client, longviewclientsName, longviewclientsEndpoint, false, LongviewClient{}, LongviewClientsPagedResponse{}), + longviewsubscriptionsName: NewResource(&client, longviewsubscriptionsName, longviewsubscriptionsEndpoint, false, LongviewSubscription{}, LongviewSubscriptionsPagedResponse{}), + nodebalancersName: NewResource(&client, nodebalancersName, nodebalancersEndpoint, false, NodeBalancer{}, NodeBalancerConfigsPagedResponse{}), + nodebalancerconfigsName: NewResource(&client, nodebalancerconfigsName, nodebalancerconfigsEndpoint, true, NodeBalancerConfig{}, NodeBalancerConfigsPagedResponse{}), + nodebalancernodesName: NewResource(&client, nodebalancernodesName, nodebalancernodesEndpoint, true, NodeBalancerNode{}, NodeBalancerNodesPagedResponse{}), + notificationsName: NewResource(&client, notificationsName, notificationsEndpoint, false, Notification{}, NotificationsPagedResponse{}), + sshkeysName: NewResource(&client, sshkeysName, sshkeysEndpoint, false, SSHKey{}, SSHKeysPagedResponse{}), + ticketsName: NewResource(&client, ticketsName, ticketsEndpoint, false, Ticket{}, TicketsPagedResponse{}), + tokensName: NewResource(&client, tokensName, tokensEndpoint, false, Token{}, TokensPagedResponse{}), + accountName: NewResource(&client, accountName, accountEndpoint, false, Account{}, nil), // really? + eventsName: NewResource(&client, eventsName, eventsEndpoint, false, Event{}, EventsPagedResponse{}), + invoicesName: NewResource(&client, invoicesName, invoicesEndpoint, false, Invoice{}, InvoicesPagedResponse{}), + invoiceItemsName: NewResource(&client, invoiceItemsName, invoiceItemsEndpoint, true, InvoiceItem{}, InvoiceItemsPagedResponse{}), + profileName: NewResource(&client, profileName, profileEndpoint, false, nil, nil), // really? + managedName: NewResource(&client, managedName, managedEndpoint, false, nil, nil), // really? + tagsName: NewResource(&client, tagsName, tagsEndpoint, false, Tag{}, TagsPagedResponse{}), + usersName: NewResource(&client, usersName, usersEndpoint, false, User{}, UsersPagedResponse{}), + } + + client.resources = resources + + client.SetDebug(envDebug) + client.Images = resources[imagesName] + client.StackScripts = resources[stackscriptsName] + client.Instances = resources[instancesName] + client.Regions = resources[regionsName] + client.InstanceDisks = resources[instanceDisksName] + client.InstanceConfigs = resources[instanceConfigsName] + client.InstanceSnapshots = resources[instanceSnapshotsName] + client.InstanceIPs = resources[instanceIPsName] + client.InstanceVolumes = resources[instanceVolumesName] + client.IPAddresses = resources[ipaddressesName] + client.IPv6Pools = resources[ipv6poolsName] + client.IPv6Ranges = resources[ipv6rangesName] + client.Volumes = resources[volumesName] + client.Kernels = resources[kernelsName] + client.Types = resources[typesName] + client.Domains = resources[domainsName] + client.DomainRecords = resources[domainRecordsName] + client.Longview = resources[longviewName] + client.LongviewSubscriptions = resources[longviewsubscriptionsName] + client.NodeBalancers = resources[nodebalancersName] + client.NodeBalancerConfigs = resources[nodebalancerconfigsName] + client.NodeBalancerNodes = resources[nodebalancernodesName] + client.Notifications = resources[notificationsName] + client.SSHKeys = resources[sshkeysName] + client.Tickets = resources[ticketsName] + client.Tokens = resources[tokensName] + client.Account = resources[accountName] + client.Events = resources[eventsName] + client.Invoices = resources[invoicesName] + client.Profile = resources[profileName] + client.Managed = resources[managedName] + client.Tags = resources[tagsName] + client.Users = resources[usersName] + return +} + +func copyBool(bPtr *bool) *bool { + if bPtr == nil { + return nil + } + var t = *bPtr + return &t +} + +func copyInt(iPtr *int) *int { + if iPtr == nil { + return nil + } + var t = *iPtr + return &t +} + +func copyString(sPtr *string) *string { + if sPtr == nil { + return nil + } + var t = *sPtr + return &t +} + +func copyTime(tPtr *time.Time) *time.Time { + if tPtr == nil { + return nil + } + var t = *tPtr + return &t +} diff --git a/vendor/github.com/linode/linodego/domain_records.go b/vendor/github.com/linode/linodego/domain_records.go new file mode 100644 index 0000000000..215ac80045 --- /dev/null +++ b/vendor/github.com/linode/linodego/domain_records.go @@ -0,0 +1,195 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// DomainRecord represents a DomainRecord object +type DomainRecord struct { + ID int `json:"id"` + Type DomainRecordType `json:"type"` + Name string `json:"name"` + Target string `json:"target"` + Priority int `json:"priority"` + Weight int `json:"weight"` + Port int `json:"port"` + Service *string `json:"service"` + Protocol *string `json:"protocol"` + TTLSec int `json:"ttl_sec"` + Tag *string `json:"tag"` +} + +// DomainRecordCreateOptions fields are those accepted by CreateDomainRecord +type DomainRecordCreateOptions struct { + Type DomainRecordType `json:"type"` + Name string `json:"name"` + Target string `json:"target"` + Priority *int `json:"priority,omitempty"` + Weight *int `json:"weight,omitempty"` + Port *int `json:"port,omitempty"` + Service *string `json:"service,omitempty"` + Protocol *string `json:"protocol,omitempty"` + TTLSec int `json:"ttl_sec,omitempty"` // 0 is not accepted by Linode, so can be omitted + Tag *string `json:"tag,omitempty"` +} + +// DomainRecordUpdateOptions fields are those accepted by UpdateDomainRecord +type DomainRecordUpdateOptions struct { + Type DomainRecordType `json:"type,omitempty"` + Name string `json:"name,omitempty"` + Target string `json:"target,omitempty"` + Priority *int `json:"priority,omitempty"` // 0 is valid, so omit only nil values + Weight *int `json:"weight,omitempty"` // 0 is valid, so omit only nil values + Port *int `json:"port,omitempty"` // 0 is valid to spec, so omit only nil values + Service *string `json:"service,omitempty"` + Protocol *string `json:"protocol,omitempty"` + TTLSec int `json:"ttl_sec,omitempty"` // 0 is not accepted by Linode, so can be omitted + Tag *string `json:"tag,omitempty"` +} + +// DomainRecordType constants start with RecordType and include Linode API Domain Record Types +type DomainRecordType string + +// DomainRecordType contants are the DNS record types a DomainRecord can assign +const ( + RecordTypeA DomainRecordType = "A" + RecordTypeAAAA DomainRecordType = "AAAA" + RecordTypeNS DomainRecordType = "NS" + RecordTypeMX DomainRecordType = "MX" + RecordTypeCNAME DomainRecordType = "CNAME" + RecordTypeTXT DomainRecordType = "TXT" + RecordTypeSRV DomainRecordType = "SRV" + RecordTypePTR DomainRecordType = "PTR" + RecordTypeCAA DomainRecordType = "CAA" +) + +// GetUpdateOptions converts a DomainRecord to DomainRecordUpdateOptions for use in UpdateDomainRecord +func (d DomainRecord) GetUpdateOptions() (du DomainRecordUpdateOptions) { + du.Type = d.Type + du.Name = d.Name + du.Target = d.Target + du.Priority = copyInt(&d.Priority) + du.Weight = copyInt(&d.Weight) + du.Port = copyInt(&d.Port) + du.Service = copyString(d.Service) + du.Protocol = copyString(d.Protocol) + du.TTLSec = d.TTLSec + du.Tag = copyString(d.Tag) + return +} + +// DomainRecordsPagedResponse represents a paginated DomainRecord API response +type DomainRecordsPagedResponse struct { + *PageOptions + Data []DomainRecord `json:"data"` +} + +// endpoint gets the endpoint URL for InstanceConfig +func (DomainRecordsPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.DomainRecords.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends DomainRecords when processing paginated DomainRecord responses +func (resp *DomainRecordsPagedResponse) appendData(r *DomainRecordsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListDomainRecords lists DomainRecords +func (c *Client) ListDomainRecords(ctx context.Context, domainID int, opts *ListOptions) ([]DomainRecord, error) { + response := DomainRecordsPagedResponse{} + err := c.listHelperWithID(ctx, &response, domainID, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (d *DomainRecord) fixDates() *DomainRecord { + return d +} + +// GetDomainRecord gets the domainrecord with the provided ID +func (c *Client) GetDomainRecord(ctx context.Context, domainID int, id int) (*DomainRecord, error) { + e, err := c.DomainRecords.endpointWithID(domainID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&DomainRecord{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*DomainRecord), nil +} + +// CreateDomainRecord creates a DomainRecord +func (c *Client) CreateDomainRecord(ctx context.Context, domainID int, domainrecord DomainRecordCreateOptions) (*DomainRecord, error) { + var body string + e, err := c.DomainRecords.endpointWithID(domainID) + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&DomainRecord{}) + + bodyData, err := json.Marshal(domainrecord) + if err != nil { + return nil, NewError(err) + } + body = string(bodyData) + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*DomainRecord).fixDates(), nil +} + +// UpdateDomainRecord updates the DomainRecord with the specified id +func (c *Client) UpdateDomainRecord(ctx context.Context, domainID int, id int, domainrecord DomainRecordUpdateOptions) (*DomainRecord, error) { + var body string + e, err := c.DomainRecords.endpointWithID(domainID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&DomainRecord{}) + + if bodyData, err := json.Marshal(domainrecord); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*DomainRecord).fixDates(), nil +} + +// DeleteDomainRecord deletes the DomainRecord with the specified id +func (c *Client) DeleteDomainRecord(ctx context.Context, domainID int, id int) error { + e, err := c.DomainRecords.endpointWithID(domainID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/domains.go b/vendor/github.com/linode/linodego/domains.go new file mode 100644 index 0000000000..43e4a65f5e --- /dev/null +++ b/vendor/github.com/linode/linodego/domains.go @@ -0,0 +1,295 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// Domain represents a Domain object +type Domain struct { + // This Domain's unique ID + ID int `json:"id"` + + // The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain. + Domain string `json:"domain"` + + // If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave). + Type DomainType `json:"type"` // Enum:"master" "slave" + + // Deprecated: The group this Domain belongs to. This is for display purposes only. + Group string `json:"group"` + + // Used to control whether this Domain is currently being rendered. + Status DomainStatus `json:"status"` // Enum:"disabled" "active" "edit_mode" "has_errors" + + // A description for this Domain. This is for display purposes only. + Description string `json:"description"` + + // Start of Authority email address. This is required for master Domains. + SOAEmail string `json:"soa_email"` + + // The interval, in seconds, at which a failed refresh should be retried. + // Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RetrySec int `json:"retry_sec"` + + // The IP addresses representing the master DNS for this Domain. + MasterIPs []string `json:"master_ips"` + + // The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it. + AXfrIPs []string `json:"axfr_ips"` + + // An array of tags applied to this object. Tags are for organizational purposes only. + Tags []string `json:"tags"` + + // The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + ExpireSec int `json:"expire_sec"` + + // The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RefreshSec int `json:"refresh_sec"` + + // "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + TTLSec int `json:"ttl_sec"` +} + +// DomainCreateOptions fields are those accepted by CreateDomain +type DomainCreateOptions struct { + // The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain. + Domain string `json:"domain"` + + // If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave). + // Enum:"master" "slave" + Type DomainType `json:"type"` + + // Deprecated: The group this Domain belongs to. This is for display purposes only. + Group string `json:"group,omitempty"` + + // Used to control whether this Domain is currently being rendered. + // Enum:"disabled" "active" "edit_mode" "has_errors" + Status DomainStatus `json:"status,omitempty"` + + // A description for this Domain. This is for display purposes only. + Description string `json:"description,omitempty"` + + // Start of Authority email address. This is required for master Domains. + SOAEmail string `json:"soa_email,omitempty"` + + // The interval, in seconds, at which a failed refresh should be retried. + // Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RetrySec int `json:"retry_sec,omitempty"` + + // The IP addresses representing the master DNS for this Domain. + MasterIPs []string `json:"master_ips,omitempty"` + + // The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it. + AXfrIPs []string `json:"axfr_ips,omitempty"` + + // An array of tags applied to this object. Tags are for organizational purposes only. + Tags []string `json:"tags"` + + // The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + ExpireSec int `json:"expire_sec,omitempty"` + + // The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RefreshSec int `json:"refresh_sec,omitempty"` + + // "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + TTLSec int `json:"ttl_sec,omitempty"` +} + +// DomainUpdateOptions converts a Domain to DomainUpdateOptions for use in UpdateDomain +type DomainUpdateOptions struct { + // The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain. + Domain string `json:"domain,omitempty"` + + // If this Domain represents the authoritative source of information for the domain it describes, or if it is a read-only copy of a master (also called a slave). + // Enum:"master" "slave" + Type DomainType `json:"type,omitempty"` + + // Deprecated: The group this Domain belongs to. This is for display purposes only. + Group string `json:"group,omitempty"` + + // Used to control whether this Domain is currently being rendered. + // Enum:"disabled" "active" "edit_mode" "has_errors" + Status DomainStatus `json:"status,omitempty"` + + // A description for this Domain. This is for display purposes only. + Description string `json:"description,omitempty"` + + // Start of Authority email address. This is required for master Domains. + SOAEmail string `json:"soa_email,omitempty"` + + // The interval, in seconds, at which a failed refresh should be retried. + // Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RetrySec int `json:"retry_sec,omitempty"` + + // The IP addresses representing the master DNS for this Domain. + MasterIPs []string `json:"master_ips,omitempty"` + + // The list of IPs that may perform a zone transfer for this Domain. This is potentially dangerous, and should be set to an empty list unless you intend to use it. + AXfrIPs []string `json:"axfr_ips,omitempty"` + + // An array of tags applied to this object. Tags are for organizational purposes only. + Tags []string `json:"tags"` + + // The amount of time in seconds that may pass before this Domain is no longer authoritative. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + ExpireSec int `json:"expire_sec,omitempty"` + + // The amount of time in seconds before this Domain should be refreshed. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + RefreshSec int `json:"refresh_sec,omitempty"` + + // "Time to Live" - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers. Valid values are 300, 3600, 7200, 14400, 28800, 57600, 86400, 172800, 345600, 604800, 1209600, and 2419200 - any other value will be rounded to the nearest valid value. + TTLSec int `json:"ttl_sec,omitempty"` +} + +// DomainType constants start with DomainType and include Linode API Domain Type values +type DomainType string + +// DomainType constants reflect the DNS zone type of a Domain +const ( + DomainTypeMaster DomainType = "master" + DomainTypeSlave DomainType = "slave" +) + +// DomainStatus constants start with DomainStatus and include Linode API Domain Status values +type DomainStatus string + +// DomainStatus constants reflect the current status of a Domain +const ( + DomainStatusDisabled DomainStatus = "disabled" + DomainStatusActive DomainStatus = "active" + DomainStatusEditMode DomainStatus = "edit_mode" + DomainStatusHasErrors DomainStatus = "has_errors" +) + +// GetUpdateOptions converts a Domain to DomainUpdateOptions for use in UpdateDomain +func (d Domain) GetUpdateOptions() (du DomainUpdateOptions) { + du.Domain = d.Domain + du.Type = d.Type + du.Group = d.Group + du.Status = d.Status + du.Description = d.Description + du.SOAEmail = d.SOAEmail + du.RetrySec = d.RetrySec + du.MasterIPs = d.MasterIPs + du.AXfrIPs = d.AXfrIPs + du.Tags = d.Tags + du.ExpireSec = d.ExpireSec + du.RefreshSec = d.RefreshSec + du.TTLSec = d.TTLSec + return +} + +// DomainsPagedResponse represents a paginated Domain API response +type DomainsPagedResponse struct { + *PageOptions + Data []Domain `json:"data"` +} + +// endpoint gets the endpoint URL for Domain +func (DomainsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Domains.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Domains when processing paginated Domain responses +func (resp *DomainsPagedResponse) appendData(r *DomainsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListDomains lists Domains +func (c *Client) ListDomains(ctx context.Context, opts *ListOptions) ([]Domain, error) { + response := DomainsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (d *Domain) fixDates() *Domain { + return d +} + +// GetDomain gets the domain with the provided ID +func (c *Client) GetDomain(ctx context.Context, id int) (*Domain, error) { + e, err := c.Domains.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Domain{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Domain).fixDates(), nil +} + +// CreateDomain creates a Domain +func (c *Client) CreateDomain(ctx context.Context, domain DomainCreateOptions) (*Domain, error) { + var body string + e, err := c.Domains.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Domain{}) + + bodyData, err := json.Marshal(domain) + if err != nil { + return nil, NewError(err) + } + body = string(bodyData) + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Domain).fixDates(), nil +} + +// UpdateDomain updates the Domain with the specified id +func (c *Client) UpdateDomain(ctx context.Context, id int, domain DomainUpdateOptions) (*Domain, error) { + var body string + e, err := c.Domains.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Domain{}) + + if bodyData, err := json.Marshal(domain); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Domain).fixDates(), nil +} + +// DeleteDomain deletes the Domain with the specified id +func (c *Client) DeleteDomain(ctx context.Context, id int) error { + e, err := c.Domains.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/env.sample b/vendor/github.com/linode/linodego/env.sample new file mode 100644 index 0000000000..b1c9d18034 --- /dev/null +++ b/vendor/github.com/linode/linodego/env.sample @@ -0,0 +1,2 @@ +LINODE_TOKEN= +LINODE_DEBUG=0 diff --git a/vendor/github.com/linode/linodego/errors.go b/vendor/github.com/linode/linodego/errors.go new file mode 100644 index 0000000000..9ceb881a21 --- /dev/null +++ b/vendor/github.com/linode/linodego/errors.go @@ -0,0 +1,109 @@ +package linodego + +import ( + "fmt" + "log" + "net/http" + "strings" + + "gopkg.in/resty.v1" +) + +const ( + // ErrorFromString is the Code identifying Errors created by string types + ErrorFromString = 1 + // ErrorFromError is the Code identifying Errors created by error types + ErrorFromError = 2 + // ErrorFromStringer is the Code identifying Errors created by fmt.Stringer types + ErrorFromStringer = 3 +) + +// Error wraps the LinodeGo error with the relevant http.Response +type Error struct { + Response *http.Response + Code int + Message string +} + +// APIErrorReason is an individual invalid request message returned by the Linode API +type APIErrorReason struct { + Reason string `json:"reason"` + Field string `json:"field"` +} + +func (r APIErrorReason) Error() string { + if len(r.Field) == 0 { + return r.Reason + } + return fmt.Sprintf("[%s] %s", r.Field, r.Reason) +} + +// APIError is the error-set returned by the Linode API when presented with an invalid request +type APIError struct { + Errors []APIErrorReason `json:"errors"` +} + +func coupleAPIErrors(r *resty.Response, err error) (*resty.Response, error) { + if err != nil { + return nil, NewError(err) + } + + if r.Error() != nil { + apiError, ok := r.Error().(*APIError) + if !ok || (ok && len(apiError.Errors) == 0) { + return r, nil + } + return nil, NewError(r) + } + + return r, nil +} + +func (e APIError) Error() string { + var x []string + for _, msg := range e.Errors { + x = append(x, msg.Error()) + } + return strings.Join(x, "; ") +} + +func (g Error) Error() string { + return fmt.Sprintf("[%03d] %s", g.Code, g.Message) +} + +// NewError creates a linodego.Error with a Code identifying the source err type, +// - ErrorFromString (1) from a string +// - ErrorFromError (2) for an error +// - ErrorFromStringer (3) for a Stringer +// - HTTP Status Codes (100-600) for a resty.Response object +func NewError(err interface{}) *Error { + if err == nil { + return nil + } + + switch e := err.(type) { + case *Error: + return e + case *resty.Response: + apiError, ok := e.Error().(*APIError) + + if !ok { + log.Fatalln("Unexpected Resty Error Response") + } + + return &Error{ + Code: e.RawResponse.StatusCode, + Message: apiError.Error(), + Response: e.RawResponse, + } + case error: + return &Error{Code: ErrorFromError, Message: e.Error()} + case string: + return &Error{Code: ErrorFromString, Message: e} + case fmt.Stringer: + return &Error{Code: ErrorFromStringer, Message: e.String()} + default: + log.Fatalln("Unsupported type to linodego.NewError") + panic(err) + } +} diff --git a/vendor/github.com/linode/linodego/images.go b/vendor/github.com/linode/linodego/images.go new file mode 100644 index 0000000000..979ce2ed10 --- /dev/null +++ b/vendor/github.com/linode/linodego/images.go @@ -0,0 +1,168 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// Image represents a deployable Image object for use with Linode Instances +type Image struct { + CreatedStr string `json:"created"` + ExpiryStr string `json:"expiry"` + ID string `json:"id"` + CreatedBy string `json:"created_by"` + Label string `json:"label"` + Description string `json:"description"` + Type string `json:"type"` + Vendor string `json:"vendor"` + Size int `json:"size"` + IsPublic bool `json:"is_public"` + Deprecated bool `json:"deprecated"` + + Created *time.Time `json:"-"` + Expiry *time.Time `json:"-"` +} + +// ImageCreateOptions fields are those accepted by CreateImage +type ImageCreateOptions struct { + DiskID int `json:"disk_id"` + Label string `json:"label"` + Description string `json:"description,omitempty"` +} + +// ImageUpdateOptions fields are those accepted by UpdateImage +type ImageUpdateOptions struct { + Label string `json:"label,omitempty"` + Description *string `json:"description,omitempty"` +} + +func (i *Image) fixDates() *Image { + i.Created, _ = parseDates(i.CreatedStr) + + if len(i.ExpiryStr) > 0 { + i.Expiry, _ = parseDates(i.ExpiryStr) + } else { + i.Expiry = nil + } + return i +} + +// GetUpdateOptions converts an Image to ImageUpdateOptions for use in UpdateImage +func (i Image) GetUpdateOptions() (iu ImageUpdateOptions) { + iu.Label = i.Label + iu.Description = copyString(&i.Description) + return +} + +// ImagesPagedResponse represents a linode API response for listing of images +type ImagesPagedResponse struct { + *PageOptions + Data []Image `json:"data"` +} + +func (ImagesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Images.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +func (resp *ImagesPagedResponse) appendData(r *ImagesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListImages lists Images +func (c *Client) ListImages(ctx context.Context, opts *ListOptions) ([]Image, error) { + response := ImagesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil + +} + +// GetImage gets the Image with the provided ID +func (c *Client) GetImage(ctx context.Context, id string) (*Image, error) { + e, err := c.Images.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.Images.R(ctx).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Image).fixDates(), nil +} + +// CreateImage creates a Image +func (c *Client) CreateImage(ctx context.Context, createOpts ImageCreateOptions) (*Image, error) { + var body string + e, err := c.Images.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Image{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Image).fixDates(), nil +} + +// UpdateImage updates the Image with the specified id +func (c *Client) UpdateImage(ctx context.Context, id string, updateOpts ImageUpdateOptions) (*Image, error) { + var body string + e, err := c.Images.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + + req := c.R(ctx).SetResult(&Image{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Image).fixDates(), nil +} + +// DeleteImage deletes the Image with the specified id +func (c *Client) DeleteImage(ctx context.Context, id string) error { + e, err := c.Images.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%s", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/instance_configs.go b/vendor/github.com/linode/linodego/instance_configs.go new file mode 100644 index 0000000000..979a27495c --- /dev/null +++ b/vendor/github.com/linode/linodego/instance_configs.go @@ -0,0 +1,246 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// InstanceConfig represents all of the settings that control the boot and run configuration of a Linode Instance +type InstanceConfig struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + + ID int `json:"id"` + Label string `json:"label"` + Comments string `json:"comments"` + Devices *InstanceConfigDeviceMap `json:"devices"` + Helpers *InstanceConfigHelpers `json:"helpers"` + MemoryLimit int `json:"memory_limit"` + Kernel string `json:"kernel"` + InitRD *int `json:"init_rd"` + RootDevice string `json:"root_device"` + RunLevel string `json:"run_level"` + VirtMode string `json:"virt_mode"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` +} + +// InstanceConfigDevice contains either the DiskID or VolumeID assigned to a Config Device +type InstanceConfigDevice struct { + DiskID int `json:"disk_id,omitempty"` + VolumeID int `json:"volume_id,omitempty"` +} + +// InstanceConfigDeviceMap contains SDA-SDH InstanceConfigDevice settings +type InstanceConfigDeviceMap struct { + SDA *InstanceConfigDevice `json:"sda,omitempty"` + SDB *InstanceConfigDevice `json:"sdb,omitempty"` + SDC *InstanceConfigDevice `json:"sdc,omitempty"` + SDD *InstanceConfigDevice `json:"sdd,omitempty"` + SDE *InstanceConfigDevice `json:"sde,omitempty"` + SDF *InstanceConfigDevice `json:"sdf,omitempty"` + SDG *InstanceConfigDevice `json:"sdg,omitempty"` + SDH *InstanceConfigDevice `json:"sdh,omitempty"` +} + +// InstanceConfigHelpers are Instance Config options that control Linux distribution specific tweaks +type InstanceConfigHelpers struct { + UpdateDBDisabled bool `json:"updatedb_disabled"` + Distro bool `json:"distro"` + ModulesDep bool `json:"modules_dep"` + Network bool `json:"network"` + DevTmpFsAutomount bool `json:"devtmpfs_automount"` +} + +// InstanceConfigsPagedResponse represents a paginated InstanceConfig API response +type InstanceConfigsPagedResponse struct { + *PageOptions + Data []InstanceConfig `json:"data"` +} + +// InstanceConfigCreateOptions are InstanceConfig settings that can be used at creation +type InstanceConfigCreateOptions struct { + Label string `json:"label,omitempty"` + Comments string `json:"comments,omitempty"` + Devices InstanceConfigDeviceMap `json:"devices"` + Helpers *InstanceConfigHelpers `json:"helpers,omitempty"` + MemoryLimit int `json:"memory_limit,omitempty"` + Kernel string `json:"kernel,omitempty"` + InitRD int `json:"init_rd,omitempty"` + RootDevice *string `json:"root_device,omitempty"` + RunLevel string `json:"run_level,omitempty"` + VirtMode string `json:"virt_mode,omitempty"` +} + +// InstanceConfigUpdateOptions are InstanceConfig settings that can be used in updates +type InstanceConfigUpdateOptions struct { + Label string `json:"label,omitempty"` + Comments string `json:"comments"` + Devices *InstanceConfigDeviceMap `json:"devices,omitempty"` + Helpers *InstanceConfigHelpers `json:"helpers,omitempty"` + // MemoryLimit 0 means unlimitted, this is not omitted + MemoryLimit int `json:"memory_limit"` + Kernel string `json:"kernel,omitempty"` + // InitRD is nullable, permit the sending of null + InitRD *int `json:"init_rd"` + RootDevice string `json:"root_device,omitempty"` + RunLevel string `json:"run_level,omitempty"` + VirtMode string `json:"virt_mode,omitempty"` +} + +// GetCreateOptions converts a InstanceConfig to InstanceConfigCreateOptions for use in CreateInstanceConfig +func (i InstanceConfig) GetCreateOptions() InstanceConfigCreateOptions { + initrd := 0 + if i.InitRD != nil { + initrd = *i.InitRD + } + return InstanceConfigCreateOptions{ + Label: i.Label, + Comments: i.Comments, + Devices: *i.Devices, + Helpers: i.Helpers, + MemoryLimit: i.MemoryLimit, + Kernel: i.Kernel, + InitRD: initrd, + RootDevice: copyString(&i.RootDevice), + RunLevel: i.RunLevel, + VirtMode: i.VirtMode, + } +} + +// GetUpdateOptions converts a InstanceConfig to InstanceConfigUpdateOptions for use in UpdateInstanceConfig +func (i InstanceConfig) GetUpdateOptions() InstanceConfigUpdateOptions { + return InstanceConfigUpdateOptions{ + Label: i.Label, + Comments: i.Comments, + Devices: i.Devices, + Helpers: i.Helpers, + MemoryLimit: i.MemoryLimit, + Kernel: i.Kernel, + InitRD: copyInt(i.InitRD), + RootDevice: i.RootDevice, + RunLevel: i.RunLevel, + VirtMode: i.VirtMode, + } +} + +// endpointWithID gets the endpoint URL for InstanceConfigs of a given Instance +func (InstanceConfigsPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.InstanceConfigs.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends InstanceConfigs when processing paginated InstanceConfig responses +func (resp *InstanceConfigsPagedResponse) appendData(r *InstanceConfigsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInstanceConfigs lists InstanceConfigs +func (c *Client) ListInstanceConfigs(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceConfig, error) { + response := InstanceConfigsPagedResponse{} + err := c.listHelperWithID(ctx, &response, linodeID, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *InstanceConfig) fixDates() *InstanceConfig { + i.Created, _ = parseDates(i.CreatedStr) + i.Updated, _ = parseDates(i.UpdatedStr) + return i +} + +// GetInstanceConfig gets the template with the provided ID +func (c *Client) GetInstanceConfig(ctx context.Context, linodeID int, configID int) (*InstanceConfig, error) { + e, err := c.InstanceConfigs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, configID) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceConfig{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceConfig).fixDates(), nil +} + +// CreateInstanceConfig creates a new InstanceConfig for the given Instance +func (c *Client) CreateInstanceConfig(ctx context.Context, linodeID int, createOpts InstanceConfigCreateOptions) (*InstanceConfig, error) { + var body string + e, err := c.InstanceConfigs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&InstanceConfig{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, err + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceConfig).fixDates(), nil +} + +// UpdateInstanceConfig update an InstanceConfig for the given Instance +func (c *Client) UpdateInstanceConfig(ctx context.Context, linodeID int, configID int, updateOpts InstanceConfigUpdateOptions) (*InstanceConfig, error) { + var body string + e, err := c.InstanceConfigs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, configID) + req := c.R(ctx).SetResult(&InstanceConfig{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, err + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceConfig).fixDates(), nil +} + +// RenameInstanceConfig renames an InstanceConfig +func (c *Client) RenameInstanceConfig(ctx context.Context, linodeID int, configID int, label string) (*InstanceConfig, error) { + return c.UpdateInstanceConfig(ctx, linodeID, configID, InstanceConfigUpdateOptions{Label: label}) +} + +// DeleteInstanceConfig deletes a Linode InstanceConfig +func (c *Client) DeleteInstanceConfig(ctx context.Context, linodeID int, configID int) error { + e, err := c.InstanceConfigs.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, configID) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/instance_disks.go b/vendor/github.com/linode/linodego/instance_disks.go new file mode 100644 index 0000000000..9b43d6b8d9 --- /dev/null +++ b/vendor/github.com/linode/linodego/instance_disks.go @@ -0,0 +1,251 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// InstanceDisk represents an Instance Disk object +type InstanceDisk struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + + ID int `json:"id"` + Label string `json:"label"` + Status DiskStatus `json:"status"` + Size int `json:"size"` + Filesystem DiskFilesystem `json:"filesystem"` + Created time.Time `json:"-"` + Updated time.Time `json:"-"` +} + +// DiskFilesystem constants start with Filesystem and include Linode API Filesystems +type DiskFilesystem string + +// DiskFilesystem constants represent the filesystems types an Instance Disk may use +const ( + FilesystemRaw DiskFilesystem = "raw" + FilesystemSwap DiskFilesystem = "swap" + FilesystemExt3 DiskFilesystem = "ext3" + FilesystemExt4 DiskFilesystem = "ext4" + FilesystemInitrd DiskFilesystem = "initrd" +) + +// DiskStatus constants have the prefix "Disk" and include Linode API Instance Disk Status +type DiskStatus string + +// DiskStatus constants represent the status values an Instance Disk may have +const ( + DiskReady DiskStatus = "ready" + DiskNotReady DiskStatus = "not ready" + DiskDeleting DiskStatus = "deleting" +) + +// InstanceDisksPagedResponse represents a paginated InstanceDisk API response +type InstanceDisksPagedResponse struct { + *PageOptions + Data []InstanceDisk `json:"data"` +} + +// InstanceDiskCreateOptions are InstanceDisk settings that can be used at creation +type InstanceDiskCreateOptions struct { + Label string `json:"label"` + Size int `json:"size"` + + // Image is optional, but requires RootPass if provided + Image string `json:"image,omitempty"` + RootPass string `json:"root_pass,omitempty"` + + Filesystem string `json:"filesystem,omitempty"` + AuthorizedKeys []string `json:"authorized_keys,omitempty"` + AuthorizedUsers []string `json:"authorized_users,omitempty"` + ReadOnly bool `json:"read_only,omitempty"` + StackscriptID int `json:"stackscript_id,omitempty"` + StackscriptData map[string]string `json:"stackscript_data,omitempty"` +} + +// InstanceDiskUpdateOptions are InstanceDisk settings that can be used in updates +type InstanceDiskUpdateOptions struct { + Label string `json:"label"` + ReadOnly bool `json:"read_only"` +} + +// endpointWithID gets the endpoint URL for InstanceDisks of a given Instance +func (InstanceDisksPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.InstanceDisks.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends InstanceDisks when processing paginated InstanceDisk responses +func (resp *InstanceDisksPagedResponse) appendData(r *InstanceDisksPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInstanceDisks lists InstanceDisks +func (c *Client) ListInstanceDisks(ctx context.Context, linodeID int, opts *ListOptions) ([]InstanceDisk, error) { + response := InstanceDisksPagedResponse{} + err := c.listHelperWithID(ctx, &response, linodeID, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *InstanceDisk) fixDates() *InstanceDisk { + if created, err := parseDates(v.CreatedStr); err == nil { + v.Created = *created + } + if updated, err := parseDates(v.UpdatedStr); err == nil { + v.Updated = *updated + } + return v +} + +// GetInstanceDisk gets the template with the provided ID +func (c *Client) GetInstanceDisk(ctx context.Context, linodeID int, configID int) (*InstanceDisk, error) { + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, configID) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceDisk{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceDisk).fixDates(), nil +} + +// CreateInstanceDisk creates a new InstanceDisk for the given Instance +func (c *Client) CreateInstanceDisk(ctx context.Context, linodeID int, createOpts InstanceDiskCreateOptions) (*InstanceDisk, error) { + var body string + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&InstanceDisk{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceDisk).fixDates(), nil +} + +// UpdateInstanceDisk creates a new InstanceDisk for the given Instance +func (c *Client) UpdateInstanceDisk(ctx context.Context, linodeID int, diskID int, updateOpts InstanceDiskUpdateOptions) (*InstanceDisk, error) { + var body string + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, diskID) + + req := c.R(ctx).SetResult(&InstanceDisk{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceDisk).fixDates(), nil +} + +// RenameInstanceDisk renames an InstanceDisk +func (c *Client) RenameInstanceDisk(ctx context.Context, linodeID int, diskID int, label string) (*InstanceDisk, error) { + return c.UpdateInstanceDisk(ctx, linodeID, diskID, InstanceDiskUpdateOptions{Label: label}) +} + +// ResizeInstanceDisk resizes the size of the Instance disk +func (c *Client) ResizeInstanceDisk(ctx context.Context, linodeID int, diskID int, size int) error { + var body string + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/resize", e, diskID) + + req := c.R(ctx).SetResult(&InstanceDisk{}) + updateOpts := map[string]interface{}{ + "size": size, + } + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return NewError(err) + } + + _, err = coupleAPIErrors(req. + SetBody(body). + Post(e)) + + return err +} + +// PasswordResetInstanceDisk resets the "root" account password on the Instance disk +func (c *Client) PasswordResetInstanceDisk(ctx context.Context, linodeID int, diskID int, password string) error { + var body string + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/password", e, diskID) + + req := c.R(ctx).SetResult(&InstanceDisk{}) + updateOpts := map[string]interface{}{ + "password": password, + } + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return NewError(err) + } + + _, err = coupleAPIErrors(req. + SetBody(body). + Post(e)) + + return err +} + +// DeleteInstanceDisk deletes a Linode Instance Disk +func (c *Client) DeleteInstanceDisk(ctx context.Context, linodeID int, diskID int) error { + e, err := c.InstanceDisks.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, diskID) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/instance_ips.go b/vendor/github.com/linode/linodego/instance_ips.go new file mode 100644 index 0000000000..a30d04f16d --- /dev/null +++ b/vendor/github.com/linode/linodego/instance_ips.go @@ -0,0 +1,106 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// InstanceIPAddressResponse contains the IPv4 and IPv6 details for an Instance +type InstanceIPAddressResponse struct { + IPv4 *InstanceIPv4Response `json:"ipv4"` + IPv6 *InstanceIPv6Response `json:"ipv6"` +} + +// InstanceIPv4Response contains the details of all IPv4 addresses associated with an Instance +type InstanceIPv4Response struct { + Public []*InstanceIP `json:"public"` + Private []*InstanceIP `json:"private"` + Shared []*InstanceIP `json:"shared"` +} + +// InstanceIP represents an Instance IP with additional DNS and networking details +type InstanceIP struct { + Address string `json:"address"` + Gateway string `json:"gateway"` + SubnetMask string `json:"subnet_mask"` + Prefix int `json:"prefix"` + Type string `json:"type"` + Public bool `json:"public"` + RDNS string `json:"rdns"` + LinodeID int `json:"linode_id"` + Region string `json:"region"` +} + +// InstanceIPv6Response contains the IPv6 addresses and ranges for an Instance +type InstanceIPv6Response struct { + LinkLocal *InstanceIP `json:"link_local"` + SLAAC *InstanceIP `json:"slaac"` + Global []*IPv6Range `json:"global"` +} + +// IPv6Range represents a range of IPv6 addresses routed to a single Linode in a given Region +type IPv6Range struct { + Range string `json:"range"` + Region string `json:"region"` +} + +// GetInstanceIPAddresses gets the IPAddresses for a Linode instance +func (c *Client) GetInstanceIPAddresses(ctx context.Context, linodeID int) (*InstanceIPAddressResponse, error) { + e, err := c.InstanceIPs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceIPAddressResponse{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceIPAddressResponse), nil +} + +// GetInstanceIPAddress gets the IPAddress for a Linode instance matching a supplied IP address +func (c *Client) GetInstanceIPAddress(ctx context.Context, linodeID int, ipaddress string) (*InstanceIP, error) { + e, err := c.InstanceIPs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, ipaddress) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceIP{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceIP), nil +} + +// AddInstanceIPAddress adds a public or private IP to a Linode instance +func (c *Client) AddInstanceIPAddress(ctx context.Context, linodeID int, public bool) (*InstanceIP, error) { + var body string + e, err := c.InstanceIPs.endpointWithID(linodeID) + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&InstanceIP{}) + + instanceipRequest := struct { + Type string `json:"type"` + Public bool `json:"public"` + }{"ipv4", public} + + if bodyData, err := json.Marshal(instanceipRequest); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetHeader("Content-Type", "application/json"). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceIP), nil +} diff --git a/vendor/github.com/linode/linodego/instance_snapshots.go b/vendor/github.com/linode/linodego/instance_snapshots.go new file mode 100644 index 0000000000..7933507dce --- /dev/null +++ b/vendor/github.com/linode/linodego/instance_snapshots.go @@ -0,0 +1,188 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// InstanceBackupsResponse response struct for backup snapshot +type InstanceBackupsResponse struct { + Automatic []*InstanceSnapshot `json:"automatic"` + Snapshot *InstanceBackupSnapshotResponse `json:"snapshot"` +} + +// InstanceBackupSnapshotResponse fields are those representing Instance Backup Snapshots +type InstanceBackupSnapshotResponse struct { + Current *InstanceSnapshot `json:"current"` + InProgress *InstanceSnapshot `json:"in_progress"` +} + +// RestoreInstanceOptions fields are those accepted by InstanceRestore +type RestoreInstanceOptions struct { + LinodeID int `json:"linode_id"` + Overwrite bool `json:"overwrite"` +} + +// InstanceSnapshot represents a linode backup snapshot +type InstanceSnapshot struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + FinishedStr string `json:"finished"` + + ID int `json:"id"` + Label string `json:"label"` + Status InstanceSnapshotStatus `json:"status"` + Type string `json:"type"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` + Finished *time.Time `json:"-"` + Configs []string `json:"configs"` + Disks []*InstanceSnapshotDisk `json:"disks"` +} + +// InstanceSnapshotDisk fields represent the source disk of a Snapshot +type InstanceSnapshotDisk struct { + Label string `json:"label"` + Size int `json:"size"` + Filesystem string `json:"filesystem"` +} + +// InstanceSnapshotStatus constants start with Snapshot and include Linode API Instance Backup Snapshot status values +type InstanceSnapshotStatus string + +// InstanceSnapshotStatus constants reflect the current status of an Instance Snapshot +var ( + SnapshotPaused InstanceSnapshotStatus = "paused" + SnapshotPending InstanceSnapshotStatus = "pending" + SnapshotRunning InstanceSnapshotStatus = "running" + SnapshotNeedsPostProcessing InstanceSnapshotStatus = "needsPostProcessing" + SnapshotSuccessful InstanceSnapshotStatus = "successful" + SnapshotFailed InstanceSnapshotStatus = "failed" + SnapshotUserAborted InstanceSnapshotStatus = "userAborted" +) + +func (l *InstanceSnapshot) fixDates() *InstanceSnapshot { + l.Created, _ = parseDates(l.CreatedStr) + l.Updated, _ = parseDates(l.UpdatedStr) + l.Finished, _ = parseDates(l.FinishedStr) + return l +} + +// GetInstanceSnapshot gets the snapshot with the provided ID +func (c *Client) GetInstanceSnapshot(ctx context.Context, linodeID int, snapshotID int) (*InstanceSnapshot, error) { + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, snapshotID) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceSnapshot{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceSnapshot).fixDates(), nil +} + +// CreateInstanceSnapshot Creates or Replaces the snapshot Backup of a Linode. If a previous snapshot exists for this Linode, it will be deleted. +func (c *Client) CreateInstanceSnapshot(ctx context.Context, linodeID int, label string) (*InstanceSnapshot, error) { + o, err := json.Marshal(map[string]string{"label": label}) + if err != nil { + return nil, err + } + body := string(o) + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return nil, err + } + + r, err := coupleAPIErrors(c.R(ctx). + SetBody(body). + SetResult(&InstanceSnapshot{}). + Post(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*InstanceSnapshot).fixDates(), nil +} + +// GetInstanceBackups gets the Instance's available Backups. +// This is not called ListInstanceBackups because a single object is returned, matching the API response. +func (c *Client) GetInstanceBackups(ctx context.Context, linodeID int) (*InstanceBackupsResponse, error) { + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return nil, err + } + r, err := coupleAPIErrors(c.R(ctx). + SetResult(&InstanceBackupsResponse{}). + Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceBackupsResponse).fixDates(), nil +} + +// EnableInstanceBackups Enables backups for the specified Linode. +func (c *Client) EnableInstanceBackups(ctx context.Context, linodeID int) error { + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/enable", e) + + _, err = coupleAPIErrors(c.R(ctx).Post(e)) + return err +} + +// CancelInstanceBackups Cancels backups for the specified Linode. +func (c *Client) CancelInstanceBackups(ctx context.Context, linodeID int) error { + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/cancel", e) + + _, err = coupleAPIErrors(c.R(ctx).Post(e)) + return err +} + +// RestoreInstanceBackup Restores a Linode's Backup to the specified Linode. +func (c *Client) RestoreInstanceBackup(ctx context.Context, linodeID int, backupID int, opts RestoreInstanceOptions) error { + o, err := json.Marshal(opts) + if err != nil { + return NewError(err) + } + body := string(o) + e, err := c.InstanceSnapshots.endpointWithID(linodeID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/restore", e, backupID) + + _, err = coupleAPIErrors(c.R(ctx).SetBody(body).Post(e)) + + return err + +} + +func (l *InstanceBackupSnapshotResponse) fixDates() *InstanceBackupSnapshotResponse { + if l.Current != nil { + l.Current.fixDates() + } + if l.InProgress != nil { + l.InProgress.fixDates() + } + return l +} + +func (l *InstanceBackupsResponse) fixDates() *InstanceBackupsResponse { + for i := range l.Automatic { + l.Automatic[i].fixDates() + } + if l.Snapshot != nil { + l.Snapshot.fixDates() + } + return l +} diff --git a/vendor/github.com/linode/linodego/instance_volumes.go b/vendor/github.com/linode/linodego/instance_volumes.go new file mode 100644 index 0000000000..b6c9a9ae05 --- /dev/null +++ b/vendor/github.com/linode/linodego/instance_volumes.go @@ -0,0 +1,38 @@ +package linodego + +import ( + "context" +) + +// InstanceVolumesPagedResponse represents a paginated InstanceVolume API response +type InstanceVolumesPagedResponse struct { + *PageOptions + Data []Volume `json:"data"` +} + +// endpoint gets the endpoint URL for InstanceVolume +func (InstanceVolumesPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.InstanceVolumes.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends InstanceVolumes when processing paginated InstanceVolume responses +func (resp *InstanceVolumesPagedResponse) appendData(r *InstanceVolumesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInstanceVolumes lists InstanceVolumes +func (c *Client) ListInstanceVolumes(ctx context.Context, linodeID int, opts *ListOptions) ([]Volume, error) { + response := InstanceVolumesPagedResponse{} + err := c.listHelperWithID(ctx, &response, linodeID, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} diff --git a/vendor/github.com/linode/linodego/instances.go b/vendor/github.com/linode/linodego/instances.go new file mode 100644 index 0000000000..85775508a0 --- /dev/null +++ b/vendor/github.com/linode/linodego/instances.go @@ -0,0 +1,454 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "net" + "time" +) + +/* + * https://developers.linode.com/v4/reference/endpoints/linode/instances + */ + +// InstanceStatus constants start with Instance and include Linode API Instance Status values +type InstanceStatus string + +// InstanceStatus constants reflect the current status of an Instance +const ( + InstanceBooting InstanceStatus = "booting" + InstanceRunning InstanceStatus = "running" + InstanceOffline InstanceStatus = "offline" + InstanceShuttingDown InstanceStatus = "shutting_down" + InstanceRebooting InstanceStatus = "rebooting" + InstanceProvisioning InstanceStatus = "provisioning" + InstanceDeleting InstanceStatus = "deleting" + InstanceMigrating InstanceStatus = "migrating" + InstanceRebuilding InstanceStatus = "rebuilding" + InstanceCloning InstanceStatus = "cloning" + InstanceRestoring InstanceStatus = "restoring" + InstanceResizing InstanceStatus = "resizing" +) + +// Instance represents a linode object +type Instance struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + + ID int `json:"id"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` + Region string `json:"region"` + Alerts *InstanceAlert `json:"alerts"` + Backups *InstanceBackup `json:"backups"` + Image string `json:"image"` + Group string `json:"group"` + IPv4 []*net.IP `json:"ipv4"` + IPv6 string `json:"ipv6"` + Label string `json:"label"` + Type string `json:"type"` + Status InstanceStatus `json:"status"` + Hypervisor string `json:"hypervisor"` + Specs *InstanceSpec `json:"specs"` + WatchdogEnabled bool `json:"watchdog_enabled"` + Tags []string `json:"tags"` +} + +// InstanceSpec represents a linode spec +type InstanceSpec struct { + Disk int `json:"disk"` + Memory int `json:"memory"` + VCPUs int `json:"vcpus"` + Transfer int `json:"transfer"` +} + +// InstanceAlert represents a metric alert +type InstanceAlert struct { + CPU int `json:"cpu"` + IO int `json:"io"` + NetworkIn int `json:"network_in"` + NetworkOut int `json:"network_out"` + TransferQuota int `json:"transfer_quota"` +} + +// InstanceBackup represents backup settings for an instance +type InstanceBackup struct { + Enabled bool `json:"enabled"` + Schedule struct { + Day string `json:"day,omitempty"` + Window string `json:"window,omitempty"` + } +} + +// InstanceCreateOptions require only Region and Type +type InstanceCreateOptions struct { + Region string `json:"region"` + Type string `json:"type"` + Label string `json:"label,omitempty"` + Group string `json:"group,omitempty"` + RootPass string `json:"root_pass,omitempty"` + AuthorizedKeys []string `json:"authorized_keys,omitempty"` + AuthorizedUsers []string `json:"authorized_users,omitempty"` + StackScriptID int `json:"stackscript_id,omitempty"` + StackScriptData map[string]string `json:"stackscript_data,omitempty"` + BackupID int `json:"backup_id,omitempty"` + Image string `json:"image,omitempty"` + BackupsEnabled bool `json:"backups_enabled,omitempty"` + PrivateIP bool `json:"private_ip,omitempty"` + Tags []string `json:"tags,omitempty"` + + // Creation fields that need to be set explicitly false, "", or 0 use pointers + SwapSize *int `json:"swap_size,omitempty"` + Booted *bool `json:"booted,omitempty"` +} + +// InstanceUpdateOptions is an options struct used when Updating an Instance +type InstanceUpdateOptions struct { + Label string `json:"label,omitempty"` + Group string `json:"group,omitempty"` + Backups *InstanceBackup `json:"backups,omitempty"` + Alerts *InstanceAlert `json:"alerts,omitempty"` + WatchdogEnabled *bool `json:"watchdog_enabled,omitempty"` + Tags *[]string `json:"tags,omitempty"` +} + +// GetUpdateOptions converts an Instance to InstanceUpdateOptions for use in UpdateInstance +func (l *Instance) GetUpdateOptions() InstanceUpdateOptions { + return InstanceUpdateOptions{ + Label: l.Label, + Group: l.Group, + Backups: l.Backups, + Alerts: l.Alerts, + WatchdogEnabled: &l.WatchdogEnabled, + Tags: &l.Tags, + } +} + +// InstanceCloneOptions is an options struct sent when Cloning an Instance +type InstanceCloneOptions struct { + Region string `json:"region,omitempty"` + Type string `json:"type,omitempty"` + + // LinodeID is an optional existing instance to use as the target of the clone + LinodeID int `json:"linode_id,omitempty"` + Label string `json:"label,omitempty"` + Group string `json:"group,omitempty"` + BackupsEnabled bool `json:"backups_enabled"` + Disks []int `json:"disks,omitempty"` + Configs []int `json:"configs,omitempty"` +} + +func (l *Instance) fixDates() *Instance { + l.Created, _ = parseDates(l.CreatedStr) + l.Updated, _ = parseDates(l.UpdatedStr) + return l +} + +// InstancesPagedResponse represents a linode API response for listing +type InstancesPagedResponse struct { + *PageOptions + Data []Instance `json:"data"` +} + +// endpoint gets the endpoint URL for Instance +func (InstancesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Instances.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Instances when processing paginated Instance responses +func (resp *InstancesPagedResponse) appendData(r *InstancesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListInstances lists linode instances +func (c *Client) ListInstances(ctx context.Context, opts *ListOptions) ([]Instance, error) { + response := InstancesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetInstance gets the instance with the provided ID +func (c *Client) GetInstance(ctx context.Context, linodeID int) (*Instance, error) { + e, err := c.Instances.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, linodeID) + r, err := coupleAPIErrors(c.R(ctx). + SetResult(Instance{}). + Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Instance).fixDates(), nil +} + +// CreateInstance creates a Linode instance +func (c *Client) CreateInstance(ctx context.Context, instance InstanceCreateOptions) (*Instance, error) { + var body string + e, err := c.Instances.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Instance{}) + + if bodyData, err := json.Marshal(instance); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Instance).fixDates(), nil +} + +// UpdateInstance creates a Linode instance +func (c *Client) UpdateInstance(ctx context.Context, id int, instance InstanceUpdateOptions) (*Instance, error) { + var body string + e, err := c.Instances.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Instance{}) + + if bodyData, err := json.Marshal(instance); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Instance).fixDates(), nil +} + +// RenameInstance renames an Instance +func (c *Client) RenameInstance(ctx context.Context, linodeID int, label string) (*Instance, error) { + return c.UpdateInstance(ctx, linodeID, InstanceUpdateOptions{Label: label}) +} + +// DeleteInstance deletes a Linode instance +func (c *Client) DeleteInstance(ctx context.Context, id int) error { + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} + +// BootInstance will boot a Linode instance +// A configID of 0 will cause Linode to choose the last/best config +func (c *Client) BootInstance(ctx context.Context, id int, configID int) error { + bodyStr := "" + + if configID != 0 { + bodyMap := map[string]int{"config_id": configID} + bodyJSON, err := json.Marshal(bodyMap) + if err != nil { + return NewError(err) + } + bodyStr = string(bodyJSON) + } + + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + + e = fmt.Sprintf("%s/%d/boot", e, id) + _, err = coupleAPIErrors(c.R(ctx). + SetBody(bodyStr). + Post(e)) + + return err +} + +// CloneInstance clone an existing Instances Disks and Configuration profiles to another Linode Instance +func (c *Client) CloneInstance(ctx context.Context, id int, options InstanceCloneOptions) (*Instance, error) { + var body string + e, err := c.Instances.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d/clone", e, id) + + req := c.R(ctx).SetResult(&Instance{}) + + if bodyData, err := json.Marshal(options); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return r.Result().(*Instance).fixDates(), nil +} + +// RebootInstance reboots a Linode instance +// A configID of 0 will cause Linode to choose the last/best config +func (c *Client) RebootInstance(ctx context.Context, id int, configID int) error { + bodyStr := "{}" + + if configID != 0 { + bodyMap := map[string]int{"config_id": configID} + bodyJSON, err := json.Marshal(bodyMap) + if err != nil { + return NewError(err) + } + bodyStr = string(bodyJSON) + } + + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + + e = fmt.Sprintf("%s/%d/reboot", e, id) + + _, err = coupleAPIErrors(c.R(ctx). + SetBody(bodyStr). + Post(e)) + + return err +} + +// RebuildInstanceOptions is a struct representing the options to send to the rebuild linode endpoint +type RebuildInstanceOptions struct { + Image string `json:"image"` + RootPass string `json:"root_pass"` + AuthorizedKeys []string `json:"authorized_keys"` + AuthorizedUsers []string `json:"authorized_users"` + StackscriptID int `json:"stackscript_id"` + StackscriptData map[string]string `json:"stackscript_data"` + Booted bool `json:"booted"` +} + +// RebuildInstance Deletes all Disks and Configs on this Linode, +// then deploys a new Image to this Linode with the given attributes. +func (c *Client) RebuildInstance(ctx context.Context, id int, opts RebuildInstanceOptions) (*Instance, error) { + o, err := json.Marshal(opts) + if err != nil { + return nil, NewError(err) + } + b := string(o) + e, err := c.Instances.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d/rebuild", e, id) + r, err := coupleAPIErrors(c.R(ctx). + SetBody(b). + SetResult(&Instance{}). + Post(e)) + if err != nil { + return nil, err + } + return r.Result().(*Instance).fixDates(), nil +} + +// RescueInstanceOptions fields are those accepted by RescueInstance +type RescueInstanceOptions struct { + Devices InstanceConfigDeviceMap `json:"devices"` +} + +// RescueInstance reboots an instance into a safe environment for performing many system recovery and disk management tasks. +// Rescue Mode is based on the Finnix recovery distribution, a self-contained and bootable Linux distribution. +// You can also use Rescue Mode for tasks other than disaster recovery, such as formatting disks to use different filesystems, +// copying data between disks, and downloading files from a disk via SSH and SFTP. +func (c *Client) RescueInstance(ctx context.Context, id int, opts RescueInstanceOptions) error { + o, err := json.Marshal(opts) + if err != nil { + return NewError(err) + } + b := string(o) + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/rescue", e, id) + + _, err = coupleAPIErrors(c.R(ctx). + SetBody(b). + Post(e)) + + return err +} + +// ResizeInstance resizes an instance to new Linode type +func (c *Client) ResizeInstance(ctx context.Context, id int, linodeType string) error { + body := fmt.Sprintf("{\"type\":\"%s\"}", linodeType) + + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/resize", e, id) + + _, err = coupleAPIErrors(c.R(ctx). + SetBody(body). + Post(e)) + + return err +} + +// ShutdownInstance - Shutdown an instance +func (c *Client) ShutdownInstance(ctx context.Context, id int) error { + return c.simpleInstanceAction(ctx, "shutdown", id) +} + +// MutateInstance Upgrades a Linode to its next generation. +func (c *Client) MutateInstance(ctx context.Context, id int) error { + return c.simpleInstanceAction(ctx, "mutate", id) +} + +// MigrateInstance - Migrate an instance +func (c *Client) MigrateInstance(ctx context.Context, id int) error { + return c.simpleInstanceAction(ctx, "migrate", id) +} + +// simpleInstanceAction is a helper for Instance actions that take no parameters +// and return empty responses `{}` unless they return a standard error +func (c *Client) simpleInstanceAction(ctx context.Context, action string, id int) error { + e, err := c.Instances.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d/%s", e, id, action) + _, err = coupleAPIErrors(c.R(ctx).Post(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/kernels.go b/vendor/github.com/linode/linodego/kernels.go new file mode 100644 index 0000000000..233a38db54 --- /dev/null +++ b/vendor/github.com/linode/linodego/kernels.go @@ -0,0 +1,61 @@ +package linodego + +import ( + "context" + "fmt" +) + +// LinodeKernel represents a Linode Instance kernel object +type LinodeKernel struct { + ID string `json:"id"` + Label string `json:"label"` + Version string `json:"version"` + Architecture string `json:"architecture"` + KVM bool `json:"kvm"` + XEN bool `json:"xen"` + PVOPS bool `json:"pvops"` +} + +// LinodeKernelsPagedResponse represents a Linode kernels API response for listing +type LinodeKernelsPagedResponse struct { + *PageOptions + Data []LinodeKernel `json:"data"` +} + +// ListKernels lists linode kernels +func (c *Client) ListKernels(ctx context.Context, opts *ListOptions) ([]LinodeKernel, error) { + response := LinodeKernelsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +func (LinodeKernelsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Kernels.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +func (resp *LinodeKernelsPagedResponse) appendData(r *LinodeKernelsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// GetKernel gets the kernel with the provided ID +func (c *Client) GetKernel(ctx context.Context, kernelID string) (*LinodeKernel, error) { + e, err := c.Kernels.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, kernelID) + r, err := c.R(ctx). + SetResult(&LinodeKernel{}). + Get(e) + if err != nil { + return nil, err + } + return r.Result().(*LinodeKernel), nil +} diff --git a/vendor/github.com/linode/linodego/longview.go b/vendor/github.com/linode/linodego/longview.go new file mode 100644 index 0000000000..524af67768 --- /dev/null +++ b/vendor/github.com/linode/linodego/longview.go @@ -0,0 +1,67 @@ +package linodego + +import ( + "context" + "fmt" +) + +// LongviewClient represents a LongviewClient object +type LongviewClient struct { + ID int `json:"id"` + // UpdatedStr string `json:"updated"` + // Updated *time.Time `json:"-"` +} + +// LongviewClientsPagedResponse represents a paginated LongviewClient API response +type LongviewClientsPagedResponse struct { + *PageOptions + Data []LongviewClient `json:"data"` +} + +// endpoint gets the endpoint URL for LongviewClient +func (LongviewClientsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.LongviewClients.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends LongviewClients when processing paginated LongviewClient responses +func (resp *LongviewClientsPagedResponse) appendData(r *LongviewClientsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListLongviewClients lists LongviewClients +func (c *Client) ListLongviewClients(ctx context.Context, opts *ListOptions) ([]LongviewClient, error) { + response := LongviewClientsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *LongviewClient) fixDates() *LongviewClient { + // v.Created, _ = parseDates(v.CreatedStr) + // v.Updated, _ = parseDates(v.UpdatedStr) + return v +} + +// GetLongviewClient gets the template with the provided ID +func (c *Client) GetLongviewClient(ctx context.Context, id string) (*LongviewClient, error) { + e, err := c.LongviewClients.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := c.R(ctx).SetResult(&LongviewClient{}).Get(e) + if err != nil { + return nil, err + } + return r.Result().(*LongviewClient).fixDates(), nil +} diff --git a/vendor/github.com/linode/linodego/longview_subscriptions.go b/vendor/github.com/linode/linodego/longview_subscriptions.go new file mode 100644 index 0000000000..253316599a --- /dev/null +++ b/vendor/github.com/linode/linodego/longview_subscriptions.go @@ -0,0 +1,70 @@ +package linodego + +import ( + "context" + "fmt" +) + +// LongviewSubscription represents a LongviewSubscription object +type LongviewSubscription struct { + ID string `json:"id"` + Label string `json:"label"` + ClientsIncluded int `json:"clients_included"` + Price *LinodePrice `json:"price"` + // UpdatedStr string `json:"updated"` + // Updated *time.Time `json:"-"` +} + +// LongviewSubscriptionsPagedResponse represents a paginated LongviewSubscription API response +type LongviewSubscriptionsPagedResponse struct { + *PageOptions + Data []LongviewSubscription `json:"data"` +} + +// endpoint gets the endpoint URL for LongviewSubscription +func (LongviewSubscriptionsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.LongviewSubscriptions.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends LongviewSubscriptions when processing paginated LongviewSubscription responses +func (resp *LongviewSubscriptionsPagedResponse) appendData(r *LongviewSubscriptionsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListLongviewSubscriptions lists LongviewSubscriptions +func (c *Client) ListLongviewSubscriptions(ctx context.Context, opts *ListOptions) ([]LongviewSubscription, error) { + response := LongviewSubscriptionsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *LongviewSubscription) fixDates() *LongviewSubscription { + // v.Created, _ = parseDates(v.CreatedStr) + // v.Updated, _ = parseDates(v.UpdatedStr) + return v +} + +// GetLongviewSubscription gets the template with the provided ID +func (c *Client) GetLongviewSubscription(ctx context.Context, id string) (*LongviewSubscription, error) { + e, err := c.LongviewSubscriptions.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := c.R(ctx).SetResult(&LongviewSubscription{}).Get(e) + if err != nil { + return nil, err + } + return r.Result().(*LongviewSubscription).fixDates(), nil +} diff --git a/vendor/github.com/linode/linodego/managed.go b/vendor/github.com/linode/linodego/managed.go new file mode 100644 index 0000000000..1523612928 --- /dev/null +++ b/vendor/github.com/linode/linodego/managed.go @@ -0,0 +1 @@ +package linodego diff --git a/vendor/github.com/linode/linodego/network_ips.go b/vendor/github.com/linode/linodego/network_ips.go new file mode 100644 index 0000000000..01dd5c1d3b --- /dev/null +++ b/vendor/github.com/linode/linodego/network_ips.go @@ -0,0 +1,90 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// IPAddressesPagedResponse represents a paginated IPAddress API response +type IPAddressesPagedResponse struct { + *PageOptions + Data []InstanceIP `json:"data"` +} + +// IPAddressUpdateOptions fields are those accepted by UpdateToken +type IPAddressUpdateOptions struct { + // The reverse DNS assigned to this address. For public IPv4 addresses, this will be set to a default value provided by Linode if set to nil. + RDNS *string `json:"rdns"` +} + +// GetUpdateOptions converts a IPAddress to IPAddressUpdateOptions for use in UpdateIPAddress +func (i InstanceIP) GetUpdateOptions() (o IPAddressUpdateOptions) { + o.RDNS = copyString(&i.RDNS) + return +} + +// endpoint gets the endpoint URL for IPAddress +func (IPAddressesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.IPAddresses.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends IPAddresses when processing paginated InstanceIPAddress responses +func (resp *IPAddressesPagedResponse) appendData(r *IPAddressesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListIPAddresses lists IPAddresses +func (c *Client) ListIPAddresses(ctx context.Context, opts *ListOptions) ([]InstanceIP, error) { + response := IPAddressesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetIPAddress gets the template with the provided ID +func (c *Client) GetIPAddress(ctx context.Context, id string) (*InstanceIP, error) { + e, err := c.IPAddresses.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&InstanceIP{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*InstanceIP), nil +} + +// UpdateIPAddress updates the IPAddress with the specified id +func (c *Client) UpdateIPAddress(ctx context.Context, id string, updateOpts IPAddressUpdateOptions) (*InstanceIP, error) { + var body string + e, err := c.IPAddresses.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + + req := c.R(ctx).SetResult(&InstanceIP{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*InstanceIP), nil +} diff --git a/vendor/github.com/linode/linodego/network_pools.go b/vendor/github.com/linode/linodego/network_pools.go new file mode 100644 index 0000000000..03085923c2 --- /dev/null +++ b/vendor/github.com/linode/linodego/network_pools.go @@ -0,0 +1,50 @@ +package linodego + +import ( + "context" + "fmt" +) + +// IPv6PoolsPagedResponse represents a paginated IPv6Pool API response +type IPv6PoolsPagedResponse struct { + *PageOptions + Data []IPv6Range `json:"data"` +} + +// endpoint gets the endpoint URL for IPv6Pool +func (IPv6PoolsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.IPv6Pools.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends IPv6Pools when processing paginated IPv6Pool responses +func (resp *IPv6PoolsPagedResponse) appendData(r *IPv6PoolsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListIPv6Pools lists IPv6Pools +func (c *Client) ListIPv6Pools(ctx context.Context, opts *ListOptions) ([]IPv6Range, error) { + response := IPv6PoolsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetIPv6Pool gets the template with the provided ID +func (c *Client) GetIPv6Pool(ctx context.Context, id string) (*IPv6Range, error) { + e, err := c.IPv6Pools.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&IPv6Range{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*IPv6Range), nil +} diff --git a/vendor/github.com/linode/linodego/network_ranges.go b/vendor/github.com/linode/linodego/network_ranges.go new file mode 100644 index 0000000000..0c0ba15a37 --- /dev/null +++ b/vendor/github.com/linode/linodego/network_ranges.go @@ -0,0 +1,50 @@ +package linodego + +import ( + "context" + "fmt" +) + +// IPv6RangesPagedResponse represents a paginated IPv6Range API response +type IPv6RangesPagedResponse struct { + *PageOptions + Data []IPv6Range `json:"data"` +} + +// endpoint gets the endpoint URL for IPv6Range +func (IPv6RangesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.IPv6Ranges.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends IPv6Ranges when processing paginated IPv6Range responses +func (resp *IPv6RangesPagedResponse) appendData(r *IPv6RangesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListIPv6Ranges lists IPv6Ranges +func (c *Client) ListIPv6Ranges(ctx context.Context, opts *ListOptions) ([]IPv6Range, error) { + response := IPv6RangesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetIPv6Range gets the template with the provided ID +func (c *Client) GetIPv6Range(ctx context.Context, id string) (*IPv6Range, error) { + e, err := c.IPv6Ranges.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&IPv6Range{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*IPv6Range), nil +} diff --git a/vendor/github.com/linode/linodego/nodebalancer.go b/vendor/github.com/linode/linodego/nodebalancer.go new file mode 100644 index 0000000000..a8d797d240 --- /dev/null +++ b/vendor/github.com/linode/linodego/nodebalancer.go @@ -0,0 +1,199 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// NodeBalancer represents a NodeBalancer object +type NodeBalancer struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + // This NodeBalancer's unique ID. + ID int `json:"id"` + // This NodeBalancer's label. These must be unique on your Account. + Label *string `json:"label"` + // The Region where this NodeBalancer is located. NodeBalancers only support backends in the same Region. + Region string `json:"region"` + // This NodeBalancer's hostname, ending with .nodebalancer.linode.com + Hostname *string `json:"hostname"` + // This NodeBalancer's public IPv4 address. + IPv4 *string `json:"ipv4"` + // This NodeBalancer's public IPv6 address. + IPv6 *string `json:"ipv6"` + // Throttle connections per second (0-20). Set to 0 (zero) to disable throttling. + ClientConnThrottle int `json:"client_conn_throttle"` + // Information about the amount of transfer this NodeBalancer has had so far this month. + Transfer NodeBalancerTransfer `json:"transfer"` + + // An array of tags applied to this object. Tags are for organizational purposes only. + Tags []string `json:"tags"` + + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` +} + +// NodeBalancerTransfer contains information about the amount of transfer a NodeBalancer has had in the current month +type NodeBalancerTransfer struct { + // The total transfer, in MB, used by this NodeBalancer this month. + Total *float64 `json:"total"` + // The total inbound transfer, in MB, used for this NodeBalancer this month. + Out *float64 `json:"out"` + // The total outbound transfer, in MB, used for this NodeBalancer this month. + In *float64 `json:"in"` +} + +// NodeBalancerCreateOptions are the options permitted for CreateNodeBalancer +type NodeBalancerCreateOptions struct { + Label *string `json:"label,omitempty"` + Region string `json:"region,omitempty"` + ClientConnThrottle *int `json:"client_conn_throttle,omitempty"` + Configs []*NodeBalancerConfigCreateOptions `json:"configs,omitempty"` + Tags []string `json:"tags"` +} + +// NodeBalancerUpdateOptions are the options permitted for UpdateNodeBalancer +type NodeBalancerUpdateOptions struct { + Label *string `json:"label,omitempty"` + ClientConnThrottle *int `json:"client_conn_throttle,omitempty"` + Tags *[]string `json:"tags,omitempty"` +} + +// GetCreateOptions converts a NodeBalancer to NodeBalancerCreateOptions for use in CreateNodeBalancer +func (i NodeBalancer) GetCreateOptions() NodeBalancerCreateOptions { + return NodeBalancerCreateOptions{ + Label: i.Label, + Region: i.Region, + ClientConnThrottle: &i.ClientConnThrottle, + Tags: i.Tags, + } +} + +// GetUpdateOptions converts a NodeBalancer to NodeBalancerUpdateOptions for use in UpdateNodeBalancer +func (i NodeBalancer) GetUpdateOptions() NodeBalancerUpdateOptions { + return NodeBalancerUpdateOptions{ + Label: i.Label, + ClientConnThrottle: &i.ClientConnThrottle, + Tags: &i.Tags, + } +} + +// NodeBalancersPagedResponse represents a paginated NodeBalancer API response +type NodeBalancersPagedResponse struct { + *PageOptions + Data []NodeBalancer `json:"data"` +} + +func (NodeBalancersPagedResponse) endpoint(c *Client) string { + endpoint, err := c.NodeBalancers.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +func (resp *NodeBalancersPagedResponse) appendData(r *NodeBalancersPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListNodeBalancers lists NodeBalancers +func (c *Client) ListNodeBalancers(ctx context.Context, opts *ListOptions) ([]NodeBalancer, error) { + response := NodeBalancersPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *NodeBalancer) fixDates() *NodeBalancer { + i.Created, _ = parseDates(i.CreatedStr) + i.Updated, _ = parseDates(i.UpdatedStr) + return i +} + +// GetNodeBalancer gets the NodeBalancer with the provided ID +func (c *Client) GetNodeBalancer(ctx context.Context, id int) (*NodeBalancer, error) { + e, err := c.NodeBalancers.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx). + SetResult(&NodeBalancer{}). + Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancer).fixDates(), nil +} + +// CreateNodeBalancer creates a NodeBalancer +func (c *Client) CreateNodeBalancer(ctx context.Context, nodebalancer NodeBalancerCreateOptions) (*NodeBalancer, error) { + var body string + e, err := c.NodeBalancers.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&NodeBalancer{}) + + if bodyData, err := json.Marshal(nodebalancer); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetHeader("Content-Type", "application/json"). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancer).fixDates(), nil +} + +// UpdateNodeBalancer updates the NodeBalancer with the specified id +func (c *Client) UpdateNodeBalancer(ctx context.Context, id int, updateOpts NodeBalancerUpdateOptions) (*NodeBalancer, error) { + var body string + e, err := c.NodeBalancers.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&NodeBalancer{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancer).fixDates(), nil +} + +// DeleteNodeBalancer deletes the NodeBalancer with the specified id +func (c *Client) DeleteNodeBalancer(ctx context.Context, id int) error { + e, err := c.NodeBalancers.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + + return err +} diff --git a/vendor/github.com/linode/linodego/nodebalancer_config_nodes.go b/vendor/github.com/linode/linodego/nodebalancer_config_nodes.go new file mode 100644 index 0000000000..e1ca55cb54 --- /dev/null +++ b/vendor/github.com/linode/linodego/nodebalancer_config_nodes.go @@ -0,0 +1,186 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// NodeBalancerNode objects represent a backend that can accept traffic for a NodeBalancer Config +type NodeBalancerNode struct { + ID int `json:"id"` + Address string `json:"address"` + Label string `json:"label"` + Status string `json:"status"` + Weight int `json:"weight"` + Mode NodeMode `json:"mode"` + ConfigID int `json:"config_id"` + NodeBalancerID int `json:"nodebalancer_id"` +} + +// NodeMode is the mode a NodeBalancer should use when sending traffic to a NodeBalancer Node +type NodeMode string + +var ( + // ModeAccept is the NodeMode indicating a NodeBalancer Node is accepting traffic + ModeAccept NodeMode = "accept" + + // ModeReject is the NodeMode indicating a NodeBalancer Node is not receiving traffic + ModeReject NodeMode = "reject" + + // ModeDrain is the NodeMode indicating a NodeBalancer Node is not receiving new traffic, but may continue receiving traffic from pinned connections + ModeDrain NodeMode = "drain" +) + +// NodeBalancerNodeCreateOptions fields are those accepted by CreateNodeBalancerNode +type NodeBalancerNodeCreateOptions struct { + Address string `json:"address"` + Label string `json:"label"` + Weight int `json:"weight,omitempty"` + Mode NodeMode `json:"mode,omitempty"` +} + +// NodeBalancerNodeUpdateOptions fields are those accepted by UpdateNodeBalancerNode +type NodeBalancerNodeUpdateOptions struct { + Address string `json:"address,omitempty"` + Label string `json:"label,omitempty"` + Weight int `json:"weight,omitempty"` + Mode NodeMode `json:"mode,omitempty"` +} + +// GetCreateOptions converts a NodeBalancerNode to NodeBalancerNodeCreateOptions for use in CreateNodeBalancerNode +func (i NodeBalancerNode) GetCreateOptions() NodeBalancerNodeCreateOptions { + return NodeBalancerNodeCreateOptions{ + Address: i.Address, + Label: i.Label, + Weight: i.Weight, + Mode: i.Mode, + } +} + +// GetUpdateOptions converts a NodeBalancerNode to NodeBalancerNodeUpdateOptions for use in UpdateNodeBalancerNode +func (i NodeBalancerNode) GetUpdateOptions() NodeBalancerNodeUpdateOptions { + return NodeBalancerNodeUpdateOptions{ + Address: i.Address, + Label: i.Label, + Weight: i.Weight, + Mode: i.Mode, + } +} + +// NodeBalancerNodesPagedResponse represents a paginated NodeBalancerNode API response +type NodeBalancerNodesPagedResponse struct { + *PageOptions + Data []NodeBalancerNode `json:"data"` +} + +// endpoint gets the endpoint URL for NodeBalancerNode +func (NodeBalancerNodesPagedResponse) endpointWithTwoIDs(c *Client, nodebalancerID int, configID int) string { + endpoint, err := c.NodeBalancerNodes.endpointWithID(nodebalancerID, configID) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends NodeBalancerNodes when processing paginated NodeBalancerNode responses +func (resp *NodeBalancerNodesPagedResponse) appendData(r *NodeBalancerNodesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListNodeBalancerNodes lists NodeBalancerNodes +func (c *Client) ListNodeBalancerNodes(ctx context.Context, nodebalancerID int, configID int, opts *ListOptions) ([]NodeBalancerNode, error) { + response := NodeBalancerNodesPagedResponse{} + err := c.listHelperWithTwoIDs(ctx, &response, nodebalancerID, configID, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *NodeBalancerNode) fixDates() *NodeBalancerNode { + return i +} + +// GetNodeBalancerNode gets the template with the provided ID +func (c *Client) GetNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, nodeID int) (*NodeBalancerNode, error) { + e, err := c.NodeBalancerNodes.endpointWithID(nodebalancerID, configID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, nodeID) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&NodeBalancerNode{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerNode).fixDates(), nil +} + +// CreateNodeBalancerNode creates a NodeBalancerNode +func (c *Client) CreateNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, createOpts NodeBalancerNodeCreateOptions) (*NodeBalancerNode, error) { + var body string + e, err := c.NodeBalancerNodes.endpointWithID(nodebalancerID, configID) + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&NodeBalancerNode{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerNode).fixDates(), nil +} + +// UpdateNodeBalancerNode updates the NodeBalancerNode with the specified id +func (c *Client) UpdateNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, nodeID int, updateOpts NodeBalancerNodeUpdateOptions) (*NodeBalancerNode, error) { + var body string + e, err := c.NodeBalancerNodes.endpointWithID(nodebalancerID, configID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, nodeID) + + req := c.R(ctx).SetResult(&NodeBalancerNode{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerNode).fixDates(), nil +} + +// DeleteNodeBalancerNode deletes the NodeBalancerNode with the specified id +func (c *Client) DeleteNodeBalancerNode(ctx context.Context, nodebalancerID int, configID int, nodeID int) error { + e, err := c.NodeBalancerNodes.endpointWithID(nodebalancerID, configID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, nodeID) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/nodebalancer_configs.go b/vendor/github.com/linode/linodego/nodebalancer_configs.go new file mode 100644 index 0000000000..aa87019c58 --- /dev/null +++ b/vendor/github.com/linode/linodego/nodebalancer_configs.go @@ -0,0 +1,334 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" +) + +// NodeBalancerConfig objects allow a NodeBalancer to accept traffic on a new port +type NodeBalancerConfig struct { + ID int `json:"id"` + Port int `json:"port"` + Protocol ConfigProtocol `json:"protocol"` + Algorithm ConfigAlgorithm `json:"algorithm"` + Stickiness ConfigStickiness `json:"stickiness"` + Check ConfigCheck `json:"check"` + CheckInterval int `json:"check_interval"` + CheckAttempts int `json:"check_attempts"` + CheckPath string `json:"check_path"` + CheckBody string `json:"check_body"` + CheckPassive bool `json:"check_passive"` + CheckTimeout int `json:"check_timeout"` + CipherSuite ConfigCipher `json:"cipher_suite"` + NodeBalancerID int `json:"nodebalancer_id"` + SSLCommonName string `json:"ssl_commonname"` + SSLFingerprint string `json:"ssl_fingerprint"` + SSLCert string `json:"ssl_cert"` + SSLKey string `json:"ssl_key"` + NodesStatus *NodeBalancerNodeStatus `json:"nodes_status"` +} + +// ConfigAlgorithm constants start with Algorithm and include Linode API NodeBalancer Config Algorithms +type ConfigAlgorithm string + +// ConfigAlgorithm constants reflect the NodeBalancer Config Algorithm +const ( + AlgorithmRoundRobin ConfigAlgorithm = "roundrobin" + AlgorithmLeastConn ConfigAlgorithm = "leastconn" + AlgorithmSource ConfigAlgorithm = "source" +) + +// ConfigStickiness constants start with Stickiness and include Linode API NodeBalancer Config Stickiness +type ConfigStickiness string + +// ConfigStickiness constants reflect the node stickiness method for a NodeBalancer Config +const ( + StickinessNone ConfigStickiness = "none" + StickinessTable ConfigStickiness = "table" + StickinessHTTPCookie ConfigStickiness = "http_cookie" +) + +// ConfigCheck constants start with Check and include Linode API NodeBalancer Config Check methods +type ConfigCheck string + +// ConfigCheck constants reflect the node health status checking method for a NodeBalancer Config +const ( + CheckNone ConfigCheck = "none" + CheckConnection ConfigCheck = "connection" + CheckHTTP ConfigCheck = "http" + CheckHTTPBody ConfigCheck = "http_body" +) + +// ConfigProtocol constants start with Protocol and include Linode API Nodebalancer Config protocols +type ConfigProtocol string + +// ConfigProtocol constants reflect the protocol used by a NodeBalancer Config +const ( + ProtocolHTTP ConfigProtocol = "http" + ProtocolHTTPS ConfigProtocol = "https" + ProtocolTCP ConfigProtocol = "tcp" +) + +// ConfigCipher constants start with Cipher and include Linode API NodeBalancer Config Cipher values +type ConfigCipher string + +// ConfigCipher constants reflect the preferred cipher set for a NodeBalancer Config +const ( + CipherRecommended ConfigCipher = "recommended" + CipherLegacy ConfigCipher = "legacy" +) + +// NodeBalancerNodeStatus represents the total number of nodes whose status is Up or Down +type NodeBalancerNodeStatus struct { + Up int `json:"up"` + Down int `json:"down"` +} + +// NodeBalancerConfigCreateOptions are permitted by CreateNodeBalancerConfig +type NodeBalancerConfigCreateOptions struct { + Port int `json:"port"` + Protocol ConfigProtocol `json:"protocol,omitempty"` + Algorithm ConfigAlgorithm `json:"algorithm,omitempty"` + Stickiness ConfigStickiness `json:"stickiness,omitempty"` + Check ConfigCheck `json:"check,omitempty"` + CheckInterval int `json:"check_interval,omitempty"` + CheckAttempts int `json:"check_attempts,omitempty"` + CheckPath string `json:"check_path,omitempty"` + CheckBody string `json:"check_body,omitempty"` + CheckPassive *bool `json:"check_passive,omitempty"` + CheckTimeout int `json:"check_timeout,omitempty"` + CipherSuite ConfigCipher `json:"cipher_suite,omitempty"` + SSLCert string `json:"ssl_cert,omitempty"` + SSLKey string `json:"ssl_key,omitempty"` + Nodes []NodeBalancerNodeCreateOptions `json:"nodes,omitempty"` +} + +// NodeBalancerConfigRebuildOptions used by RebuildNodeBalancerConfig +type NodeBalancerConfigRebuildOptions struct { + Port int `json:"port"` + Protocol ConfigProtocol `json:"protocol,omitempty"` + Algorithm ConfigAlgorithm `json:"algorithm,omitempty"` + Stickiness ConfigStickiness `json:"stickiness,omitempty"` + Check ConfigCheck `json:"check,omitempty"` + CheckInterval int `json:"check_interval,omitempty"` + CheckAttempts int `json:"check_attempts,omitempty"` + CheckPath string `json:"check_path,omitempty"` + CheckBody string `json:"check_body,omitempty"` + CheckPassive *bool `json:"check_passive,omitempty"` + CheckTimeout int `json:"check_timeout,omitempty"` + CipherSuite ConfigCipher `json:"cipher_suite,omitempty"` + SSLCert string `json:"ssl_cert,omitempty"` + SSLKey string `json:"ssl_key,omitempty"` + Nodes []NodeBalancerNodeCreateOptions `json:"nodes"` +} + +// NodeBalancerConfigUpdateOptions are permitted by UpdateNodeBalancerConfig +type NodeBalancerConfigUpdateOptions NodeBalancerConfigCreateOptions + +// GetCreateOptions converts a NodeBalancerConfig to NodeBalancerConfigCreateOptions for use in CreateNodeBalancerConfig +func (i NodeBalancerConfig) GetCreateOptions() NodeBalancerConfigCreateOptions { + return NodeBalancerConfigCreateOptions{ + Port: i.Port, + Protocol: i.Protocol, + Algorithm: i.Algorithm, + Stickiness: i.Stickiness, + Check: i.Check, + CheckInterval: i.CheckInterval, + CheckAttempts: i.CheckAttempts, + CheckTimeout: i.CheckTimeout, + CheckPath: i.CheckPath, + CheckBody: i.CheckBody, + CheckPassive: copyBool(&i.CheckPassive), + CipherSuite: i.CipherSuite, + SSLCert: i.SSLCert, + SSLKey: i.SSLKey, + } +} + +// GetUpdateOptions converts a NodeBalancerConfig to NodeBalancerConfigUpdateOptions for use in UpdateNodeBalancerConfig +func (i NodeBalancerConfig) GetUpdateOptions() NodeBalancerConfigUpdateOptions { + return NodeBalancerConfigUpdateOptions{ + Port: i.Port, + Protocol: i.Protocol, + Algorithm: i.Algorithm, + Stickiness: i.Stickiness, + Check: i.Check, + CheckInterval: i.CheckInterval, + CheckAttempts: i.CheckAttempts, + CheckPath: i.CheckPath, + CheckBody: i.CheckBody, + CheckPassive: copyBool(&i.CheckPassive), + CheckTimeout: i.CheckTimeout, + CipherSuite: i.CipherSuite, + SSLCert: i.SSLCert, + SSLKey: i.SSLKey, + } +} + +// GetRebuildOptions converts a NodeBalancerConfig to NodeBalancerConfigRebuildOptions for use in RebuildNodeBalancerConfig +func (i NodeBalancerConfig) GetRebuildOptions() NodeBalancerConfigRebuildOptions { + return NodeBalancerConfigRebuildOptions{ + Port: i.Port, + Protocol: i.Protocol, + Algorithm: i.Algorithm, + Stickiness: i.Stickiness, + Check: i.Check, + CheckInterval: i.CheckInterval, + CheckAttempts: i.CheckAttempts, + CheckTimeout: i.CheckTimeout, + CheckPath: i.CheckPath, + CheckBody: i.CheckBody, + CheckPassive: copyBool(&i.CheckPassive), + CipherSuite: i.CipherSuite, + SSLCert: i.SSLCert, + SSLKey: i.SSLKey, + Nodes: make([]NodeBalancerNodeCreateOptions, 0), + } +} + +// NodeBalancerConfigsPagedResponse represents a paginated NodeBalancerConfig API response +type NodeBalancerConfigsPagedResponse struct { + *PageOptions + Data []NodeBalancerConfig `json:"data"` +} + +// endpointWithID gets the endpoint URL for NodeBalancerConfig +func (NodeBalancerConfigsPagedResponse) endpointWithID(c *Client, id int) string { + endpoint, err := c.NodeBalancerConfigs.endpointWithID(id) + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends NodeBalancerConfigs when processing paginated NodeBalancerConfig responses +func (resp *NodeBalancerConfigsPagedResponse) appendData(r *NodeBalancerConfigsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListNodeBalancerConfigs lists NodeBalancerConfigs +func (c *Client) ListNodeBalancerConfigs(ctx context.Context, nodebalancerID int, opts *ListOptions) ([]NodeBalancerConfig, error) { + response := NodeBalancerConfigsPagedResponse{} + err := c.listHelperWithID(ctx, &response, nodebalancerID, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *NodeBalancerConfig) fixDates() *NodeBalancerConfig { + return i +} + +// GetNodeBalancerConfig gets the template with the provided ID +func (c *Client) GetNodeBalancerConfig(ctx context.Context, nodebalancerID int, configID int) (*NodeBalancerConfig, error) { + e, err := c.NodeBalancerConfigs.endpointWithID(nodebalancerID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, configID) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&NodeBalancerConfig{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerConfig).fixDates(), nil +} + +// CreateNodeBalancerConfig creates a NodeBalancerConfig +func (c *Client) CreateNodeBalancerConfig(ctx context.Context, nodebalancerID int, nodebalancerConfig NodeBalancerConfigCreateOptions) (*NodeBalancerConfig, error) { + var body string + e, err := c.NodeBalancerConfigs.endpointWithID(nodebalancerID) + + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&NodeBalancerConfig{}) + + if bodyData, err := json.Marshal(nodebalancerConfig); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetHeader("Content-Type", "application/json"). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerConfig).fixDates(), nil +} + +// UpdateNodeBalancerConfig updates the NodeBalancerConfig with the specified id +func (c *Client) UpdateNodeBalancerConfig(ctx context.Context, nodebalancerID int, configID int, updateOpts NodeBalancerConfigUpdateOptions) (*NodeBalancerConfig, error) { + var body string + e, err := c.NodeBalancerConfigs.endpointWithID(nodebalancerID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, configID) + + req := c.R(ctx).SetResult(&NodeBalancerConfig{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerConfig).fixDates(), nil +} + +// DeleteNodeBalancerConfig deletes the NodeBalancerConfig with the specified id +func (c *Client) DeleteNodeBalancerConfig(ctx context.Context, nodebalancerID int, configID int) error { + e, err := c.NodeBalancerConfigs.endpointWithID(nodebalancerID) + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, configID) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} + +// RebuildNodeBalancerConfig updates the NodeBalancer with the specified id +func (c *Client) RebuildNodeBalancerConfig(ctx context.Context, nodeBalancerID int, configID int, rebuildOpts NodeBalancerConfigRebuildOptions) (*NodeBalancerConfig, error) { + var body string + e, err := c.NodeBalancerConfigs.endpointWithID(nodeBalancerID) + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d/rebuild", e, configID) + + req := c.R(ctx).SetResult(&NodeBalancerConfig{}) + + if bodyData, err := json.Marshal(rebuildOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*NodeBalancerConfig).fixDates(), nil +} diff --git a/vendor/github.com/linode/linodego/pagination.go b/vendor/github.com/linode/linodego/pagination.go new file mode 100644 index 0000000000..bfe6de3b7d --- /dev/null +++ b/vendor/github.com/linode/linodego/pagination.go @@ -0,0 +1,430 @@ +package linodego + +/** + * Pagination and Filtering types and helpers + */ + +import ( + "context" + "fmt" + "log" + "strconv" + + "gopkg.in/resty.v1" +) + +// PageOptions are the pagination parameters for List endpoints +type PageOptions struct { + Page int `url:"page,omitempty" json:"page"` + Pages int `url:"pages,omitempty" json:"pages"` + Results int `url:"results,omitempty" json:"results"` +} + +// ListOptions are the pagination and filtering (TODO) parameters for endpoints +type ListOptions struct { + *PageOptions + Filter string +} + +// NewListOptions simplified construction of ListOptions using only +// the two writable properties, Page and Filter +func NewListOptions(Page int, Filter string) *ListOptions { + return &ListOptions{PageOptions: &PageOptions{Page: Page}, Filter: Filter} + +} + +// listHelper abstracts fetching and pagination for GET endpoints that +// do not require any Ids (top level endpoints). +// When opts (or opts.Page) is nil, all pages will be fetched and +// returned in a single (endpoint-specific)PagedResponse +// opts.results and opts.pages will be updated from the API response +func (c *Client) listHelper(ctx context.Context, i interface{}, opts *ListOptions) error { + req := c.R(ctx) + if opts != nil && opts.PageOptions != nil && opts.Page > 0 { + req.SetQueryParam("page", strconv.Itoa(opts.Page)) + } + + var ( + err error + pages int + results int + r *resty.Response + ) + + if opts != nil && len(opts.Filter) > 0 { + req.SetHeader("X-Filter", opts.Filter) + } + + switch v := i.(type) { + case *LinodeKernelsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(LinodeKernelsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*LinodeKernelsPagedResponse).Pages + results = r.Result().(*LinodeKernelsPagedResponse).Results + v.appendData(r.Result().(*LinodeKernelsPagedResponse)) + } + case *LinodeTypesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(LinodeTypesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*LinodeTypesPagedResponse).Pages + results = r.Result().(*LinodeTypesPagedResponse).Results + v.appendData(r.Result().(*LinodeTypesPagedResponse)) + } + case *ImagesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(ImagesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*ImagesPagedResponse).Pages + results = r.Result().(*ImagesPagedResponse).Results + v.appendData(r.Result().(*ImagesPagedResponse)) + } + case *StackscriptsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(StackscriptsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*StackscriptsPagedResponse).Pages + results = r.Result().(*StackscriptsPagedResponse).Results + v.appendData(r.Result().(*StackscriptsPagedResponse)) + } + case *InstancesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InstancesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*InstancesPagedResponse).Pages + results = r.Result().(*InstancesPagedResponse).Results + v.appendData(r.Result().(*InstancesPagedResponse)) + } + case *RegionsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(RegionsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*RegionsPagedResponse).Pages + results = r.Result().(*RegionsPagedResponse).Results + v.appendData(r.Result().(*RegionsPagedResponse)) + } + case *VolumesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(VolumesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*VolumesPagedResponse).Pages + results = r.Result().(*VolumesPagedResponse).Results + v.appendData(r.Result().(*VolumesPagedResponse)) + } + case *DomainsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(DomainsPagedResponse{}).Get(v.endpoint(c))); err == nil { + response, ok := r.Result().(*DomainsPagedResponse) + if !ok { + return fmt.Errorf("Response is not a *DomainsPagedResponse") + } + pages = response.Pages + results = response.Results + v.appendData(response) + } + case *EventsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(EventsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*EventsPagedResponse).Pages + results = r.Result().(*EventsPagedResponse).Results + v.appendData(r.Result().(*EventsPagedResponse)) + } + case *LongviewSubscriptionsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(LongviewSubscriptionsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*LongviewSubscriptionsPagedResponse).Pages + results = r.Result().(*LongviewSubscriptionsPagedResponse).Results + v.appendData(r.Result().(*LongviewSubscriptionsPagedResponse)) + } + case *LongviewClientsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(LongviewClientsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*LongviewClientsPagedResponse).Pages + results = r.Result().(*LongviewClientsPagedResponse).Results + v.appendData(r.Result().(*LongviewClientsPagedResponse)) + } + case *IPAddressesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(IPAddressesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*IPAddressesPagedResponse).Pages + results = r.Result().(*IPAddressesPagedResponse).Results + v.appendData(r.Result().(*IPAddressesPagedResponse)) + } + case *IPv6PoolsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(IPv6PoolsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*IPv6PoolsPagedResponse).Pages + results = r.Result().(*IPv6PoolsPagedResponse).Results + v.appendData(r.Result().(*IPv6PoolsPagedResponse)) + } + case *IPv6RangesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(IPv6RangesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*IPv6RangesPagedResponse).Pages + results = r.Result().(*IPv6RangesPagedResponse).Results + v.appendData(r.Result().(*IPv6RangesPagedResponse)) + // @TODO consolidate this type with IPv6PoolsPagedResponse? + } + case *SSHKeysPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(SSHKeysPagedResponse{}).Get(v.endpoint(c))); err == nil { + response, ok := r.Result().(*SSHKeysPagedResponse) + if !ok { + return fmt.Errorf("Response is not a *SSHKeysPagedResponse") + } + pages = response.Pages + results = response.Results + v.appendData(response) + } + case *TicketsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(TicketsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*TicketsPagedResponse).Pages + results = r.Result().(*TicketsPagedResponse).Results + v.appendData(r.Result().(*TicketsPagedResponse)) + } + case *InvoicesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InvoicesPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*InvoicesPagedResponse).Pages + results = r.Result().(*InvoicesPagedResponse).Results + v.appendData(r.Result().(*InvoicesPagedResponse)) + } + case *NotificationsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(NotificationsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*NotificationsPagedResponse).Pages + results = r.Result().(*NotificationsPagedResponse).Results + v.appendData(r.Result().(*NotificationsPagedResponse)) + } + case *NodeBalancersPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(NodeBalancersPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*NodeBalancersPagedResponse).Pages + results = r.Result().(*NodeBalancersPagedResponse).Results + v.appendData(r.Result().(*NodeBalancersPagedResponse)) + } + case *TagsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(TagsPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*TagsPagedResponse).Pages + results = r.Result().(*TagsPagedResponse).Results + v.appendData(r.Result().(*TagsPagedResponse)) + } + case *TokensPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(TokensPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*TokensPagedResponse).Pages + results = r.Result().(*TokensPagedResponse).Results + v.appendData(r.Result().(*TokensPagedResponse)) + } + case *UsersPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(UsersPagedResponse{}).Get(v.endpoint(c))); err == nil { + pages = r.Result().(*UsersPagedResponse).Pages + results = r.Result().(*UsersPagedResponse).Results + v.appendData(r.Result().(*UsersPagedResponse)) + } + /** + case AccountOauthClientsPagedResponse: + case AccountPaymentsPagedResponse: + case ProfileAppsPagedResponse: + case ProfileWhitelistPagedResponse: + case ManagedContactsPagedResponse: + case ManagedCredentialsPagedResponse: + case ManagedIssuesPagedResponse: + case ManagedLinodeSettingsPagedResponse: + case ManagedServicesPagedResponse: + **/ + default: + log.Fatalf("listHelper interface{} %+v used", i) + } + + if err != nil { + return err + } + + if opts == nil { + for page := 2; page <= pages; page = page + 1 { + if err := c.listHelper(ctx, i, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil { + return err + } + } + } else { + if opts.PageOptions == nil { + opts.PageOptions = &PageOptions{} + } + + if opts.Page == 0 { + for page := 2; page <= pages; page = page + 1 { + opts.Page = page + if err := c.listHelper(ctx, i, opts); err != nil { + return err + } + } + } + opts.Results = results + opts.Pages = pages + } + + return nil +} + +// listHelperWithID abstracts fetching and pagination for GET endpoints that +// require an Id (second level endpoints). +// When opts (or opts.Page) is nil, all pages will be fetched and +// returned in a single (endpoint-specific)PagedResponse +// opts.results and opts.pages will be updated from the API response +func (c *Client) listHelperWithID(ctx context.Context, i interface{}, idRaw interface{}, opts *ListOptions) error { + req := c.R(ctx) + if opts != nil && opts.Page > 0 { + req.SetQueryParam("page", strconv.Itoa(opts.Page)) + } + + var ( + err error + pages int + results int + r *resty.Response + ) + + id, _ := idRaw.(int) + + if opts != nil && len(opts.Filter) > 0 { + req.SetHeader("X-Filter", opts.Filter) + } + + switch v := i.(type) { + case *InvoiceItemsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InvoiceItemsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + pages = r.Result().(*InvoiceItemsPagedResponse).Pages + results = r.Result().(*InvoiceItemsPagedResponse).Results + v.appendData(r.Result().(*InvoiceItemsPagedResponse)) + } + case *DomainRecordsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(DomainRecordsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + response, ok := r.Result().(*DomainRecordsPagedResponse) + if !ok { + return fmt.Errorf("Response is not a *DomainRecordsPagedResponse") + } + pages = response.Pages + results = response.Results + v.appendData(response) + } + case *InstanceConfigsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InstanceConfigsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + pages = r.Result().(*InstanceConfigsPagedResponse).Pages + results = r.Result().(*InstanceConfigsPagedResponse).Results + v.appendData(r.Result().(*InstanceConfigsPagedResponse)) + } + case *InstanceDisksPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InstanceDisksPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + pages = r.Result().(*InstanceDisksPagedResponse).Pages + results = r.Result().(*InstanceDisksPagedResponse).Results + v.appendData(r.Result().(*InstanceDisksPagedResponse)) + } + case *NodeBalancerConfigsPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(NodeBalancerConfigsPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + pages = r.Result().(*NodeBalancerConfigsPagedResponse).Pages + results = r.Result().(*NodeBalancerConfigsPagedResponse).Results + v.appendData(r.Result().(*NodeBalancerConfigsPagedResponse)) + } + case *InstanceVolumesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(InstanceVolumesPagedResponse{}).Get(v.endpointWithID(c, id))); err == nil { + pages = r.Result().(*InstanceVolumesPagedResponse).Pages + results = r.Result().(*InstanceVolumesPagedResponse).Results + v.appendData(r.Result().(*InstanceVolumesPagedResponse)) + } + case *TaggedObjectsPagedResponse: + idStr := idRaw.(string) + + if r, err = coupleAPIErrors(req.SetResult(TaggedObjectsPagedResponse{}).Get(v.endpointWithID(c, idStr))); err == nil { + pages = r.Result().(*TaggedObjectsPagedResponse).Pages + results = r.Result().(*TaggedObjectsPagedResponse).Results + v.appendData(r.Result().(*TaggedObjectsPagedResponse)) + } + /** + case TicketAttachmentsPagedResponse: + if r, err = req.SetResult(v).Get(v.endpoint(c)); r.Error() != nil { + return NewError(r) + } else if err == nil { + pages = r.Result().(*TicketAttachmentsPagedResponse).Pages + results = r.Result().(*TicketAttachmentsPagedResponse).Results + v.appendData(r.Result().(*TicketAttachmentsPagedResponse)) + } + case TicketRepliesPagedResponse: + if r, err = req.SetResult(v).Get(v.endpoint(c)); r.Error() != nil { + return NewError(r) + } else if err == nil { + pages = r.Result().(*TicketRepliesPagedResponse).Pages + results = r.Result().(*TicketRepliesPagedResponse).Results + v.appendData(r.Result().(*TicketRepliesPagedResponse)) + } + **/ + default: + log.Fatalf("Unknown listHelperWithID interface{} %T used", i) + } + + if err != nil { + return err + } + + if opts == nil { + for page := 2; page <= pages; page = page + 1 { + if err := c.listHelperWithID(ctx, i, id, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil { + return err + } + } + } else { + if opts.PageOptions == nil { + opts.PageOptions = &PageOptions{} + } + if opts.Page == 0 { + for page := 2; page <= pages; page = page + 1 { + opts.Page = page + if err := c.listHelperWithID(ctx, i, id, opts); err != nil { + return err + } + } + } + opts.Results = results + opts.Pages = pages + } + + return nil +} + +// listHelperWithTwoIDs abstracts fetching and pagination for GET endpoints that +// require twos IDs (third level endpoints). +// When opts (or opts.Page) is nil, all pages will be fetched and +// returned in a single (endpoint-specific)PagedResponse +// opts.results and opts.pages will be updated from the API response +func (c *Client) listHelperWithTwoIDs(ctx context.Context, i interface{}, firstID, secondID int, opts *ListOptions) error { + req := c.R(ctx) + if opts != nil && opts.Page > 0 { + req.SetQueryParam("page", strconv.Itoa(opts.Page)) + } + + var ( + err error + pages int + results int + r *resty.Response + ) + + if opts != nil && len(opts.Filter) > 0 { + req.SetHeader("X-Filter", opts.Filter) + } + + switch v := i.(type) { + case *NodeBalancerNodesPagedResponse: + if r, err = coupleAPIErrors(req.SetResult(NodeBalancerNodesPagedResponse{}).Get(v.endpointWithTwoIDs(c, firstID, secondID))); err == nil { + pages = r.Result().(*NodeBalancerNodesPagedResponse).Pages + results = r.Result().(*NodeBalancerNodesPagedResponse).Results + v.appendData(r.Result().(*NodeBalancerNodesPagedResponse)) + } + + default: + log.Fatalf("Unknown listHelperWithTwoIDs interface{} %T used", i) + } + + if err != nil { + return err + } + + if opts == nil { + for page := 2; page <= pages; page = page + 1 { + if err := c.listHelper(ctx, i, &ListOptions{PageOptions: &PageOptions{Page: page}}); err != nil { + return err + } + } + } else { + if opts.PageOptions == nil { + opts.PageOptions = &PageOptions{} + } + if opts.Page == 0 { + for page := 2; page <= pages; page = page + 1 { + opts.Page = page + if err := c.listHelperWithTwoIDs(ctx, i, firstID, secondID, opts); err != nil { + return err + } + } + } + opts.Results = results + opts.Pages = pages + } + + return nil +} diff --git a/vendor/github.com/linode/linodego/profile.go b/vendor/github.com/linode/linodego/profile.go new file mode 100644 index 0000000000..3d29b2a524 --- /dev/null +++ b/vendor/github.com/linode/linodego/profile.go @@ -0,0 +1,117 @@ +package linodego + +/* + - copy profile_test.go and do the same + - When updating Profile structs, + - use pointers where ever null'able would have a different meaning if the wrapper + supplied "" or 0 instead + - Add "NameOfResource" to client.go, resources.go, pagination.go +*/ + +import ( + "context" + "encoding/json" +) + +// LishAuthMethod constants start with AuthMethod and include Linode API Lish Authentication Methods +type LishAuthMethod string + +// LishAuthMethod constants are the methods of authentication allowed when connecting via Lish +const ( + AuthMethodPasswordKeys LishAuthMethod = "password_keys" + AuthMethodKeysOnly LishAuthMethod = "keys_only" + AuthMethodDisabled LishAuthMethod = "disabled" +) + +// ProfileReferrals represent a User's status in the Referral Program +type ProfileReferrals struct { + Total int `json:"total"` + Completed int `json:"completed"` + Pending int `json:"pending"` + Credit float64 `json:"credit"` + Code string `json:"code"` + URL string `json:"url"` +} + +// Profile represents a Profile object +type Profile struct { + UID int `json:"uid"` + Username string `json:"username"` + Email string `json:"email"` + Timezone string `json:"timezone"` + EmailNotifications bool `json:"email_notifications"` + IPWhitelistEnabled bool `json:"ip_whitelist_enabled"` + TwoFactorAuth bool `json:"two_factor_auth"` + Restricted bool `json:"restricted"` + LishAuthMethod LishAuthMethod `json:"lish_auth_method"` + Referrals ProfileReferrals `json:"referrals"` + AuthorizedKeys []string `json:"authorized_keys"` +} + +// ProfileUpdateOptions fields are those accepted by UpdateProfile +type ProfileUpdateOptions struct { + Email string `json:"email,omitempty"` + Timezone string `json:"timezone,omitempty"` + EmailNotifications *bool `json:"email_notifications,omitempty"` + IPWhitelistEnabled *bool `json:"ip_whitelist_enabled,omitempty"` + LishAuthMethod LishAuthMethod `json:"lish_auth_method,omitempty"` + AuthorizedKeys *[]string `json:"authorized_keys,omitempty"` + TwoFactorAuth *bool `json:"two_factor_auth,omitempty"` + Restricted *bool `json:"restricted,omitempty"` +} + +// GetUpdateOptions converts a Profile to ProfileUpdateOptions for use in UpdateProfile +func (i Profile) GetUpdateOptions() (o ProfileUpdateOptions) { + o.Email = i.Email + o.Timezone = i.Timezone + o.EmailNotifications = copyBool(&i.EmailNotifications) + o.IPWhitelistEnabled = copyBool(&i.IPWhitelistEnabled) + o.LishAuthMethod = i.LishAuthMethod + authorizedKeys := make([]string, len(i.AuthorizedKeys)) + copy(authorizedKeys, i.AuthorizedKeys) + o.AuthorizedKeys = &authorizedKeys + o.TwoFactorAuth = copyBool(&i.TwoFactorAuth) + o.Restricted = copyBool(&i.Restricted) + + return +} + +// GetProfile gets the profile with the provided ID +func (c *Client) GetProfile(ctx context.Context) (*Profile, error) { + e, err := c.Profile.Endpoint() + if err != nil { + return nil, err + } + + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Profile{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Profile), nil +} + +// UpdateProfile updates the Profile with the specified id +func (c *Client) UpdateProfile(ctx context.Context, updateOpts ProfileUpdateOptions) (*Profile, error) { + var body string + e, err := c.Profile.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Profile{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Profile), nil +} diff --git a/vendor/github.com/linode/linodego/profile_sshkeys.go b/vendor/github.com/linode/linodego/profile_sshkeys.go new file mode 100644 index 0000000000..2ec4d4f715 --- /dev/null +++ b/vendor/github.com/linode/linodego/profile_sshkeys.go @@ -0,0 +1,160 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// SSHKey represents a SSHKey object +type SSHKey struct { + ID int `json:"id"` + Label string `json:"label"` + SSHKey string `json:"ssh_key"` + CreatedStr string `json:"created"` + Created *time.Time `json:"-"` +} + +// SSHKeyCreateOptions fields are those accepted by CreateSSHKey +type SSHKeyCreateOptions struct { + Label string `json:"label"` + SSHKey string `json:"ssh_key"` +} + +// SSHKeyUpdateOptions fields are those accepted by UpdateSSHKey +type SSHKeyUpdateOptions struct { + Label string `json:"label"` +} + +// GetCreateOptions converts a SSHKey to SSHKeyCreateOptions for use in CreateSSHKey +func (i SSHKey) GetCreateOptions() (o SSHKeyCreateOptions) { + o.Label = i.Label + o.SSHKey = i.SSHKey + return +} + +// GetUpdateOptions converts a SSHKey to SSHKeyCreateOptions for use in UpdateSSHKey +func (i SSHKey) GetUpdateOptions() (o SSHKeyUpdateOptions) { + o.Label = i.Label + return +} + +// SSHKeysPagedResponse represents a paginated SSHKey API response +type SSHKeysPagedResponse struct { + *PageOptions + Data []SSHKey `json:"data"` +} + +// endpoint gets the endpoint URL for SSHKey +func (SSHKeysPagedResponse) endpoint(c *Client) string { + endpoint, err := c.SSHKeys.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends SSHKeys when processing paginated SSHKey responses +func (resp *SSHKeysPagedResponse) appendData(r *SSHKeysPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListSSHKeys lists SSHKeys +func (c *Client) ListSSHKeys(ctx context.Context, opts *ListOptions) ([]SSHKey, error) { + response := SSHKeysPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *SSHKey) fixDates() *SSHKey { + i.Created, _ = parseDates(i.CreatedStr) + return i +} + +// GetSSHKey gets the sshkey with the provided ID +func (c *Client) GetSSHKey(ctx context.Context, id int) (*SSHKey, error) { + e, err := c.SSHKeys.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&SSHKey{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*SSHKey).fixDates(), nil +} + +// CreateSSHKey creates a SSHKey +func (c *Client) CreateSSHKey(ctx context.Context, createOpts SSHKeyCreateOptions) (*SSHKey, error) { + var body string + e, err := c.SSHKeys.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&SSHKey{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*SSHKey).fixDates(), nil +} + +// UpdateSSHKey updates the SSHKey with the specified id +func (c *Client) UpdateSSHKey(ctx context.Context, id int, updateOpts SSHKeyUpdateOptions) (*SSHKey, error) { + var body string + e, err := c.SSHKeys.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&SSHKey{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*SSHKey).fixDates(), nil +} + +// DeleteSSHKey deletes the SSHKey with the specified id +func (c *Client) DeleteSSHKey(ctx context.Context, id int) error { + e, err := c.SSHKeys.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err + +} diff --git a/vendor/github.com/linode/linodego/profile_tokens.go b/vendor/github.com/linode/linodego/profile_tokens.go new file mode 100644 index 0000000000..bd95dfe05b --- /dev/null +++ b/vendor/github.com/linode/linodego/profile_tokens.go @@ -0,0 +1,195 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// Token represents a Token object +type Token struct { + // This token's unique ID, which can be used to revoke it. + ID int `json:"id"` + + // The scopes this token was created with. These define what parts of the Account the token can be used to access. Many command-line tools, such as the Linode CLI, require tokens with access to *. Tokens with more restrictive scopes are generally more secure. + Scopes string `json:"scopes"` + + // This token's label. This is for display purposes only, but can be used to more easily track what you're using each token for. (1-100 Characters) + Label string `json:"label"` + + // The token used to access the API. When the token is created, the full token is returned here. Otherwise, only the first 16 characters are returned. + Token string `json:"token"` + + // The date and time this token was created. + Created *time.Time `json:"-"` + CreatedStr string `json:"created"` + + // When this token will expire. Personal Access Tokens cannot be renewed, so after this time the token will be completely unusable and a new token will need to be generated. Tokens may be created with "null" as their expiry and will never expire unless revoked. + Expiry *time.Time `json:"-"` + ExpiryStr string `json:"expiry"` +} + +// TokenCreateOptions fields are those accepted by CreateToken +type TokenCreateOptions struct { + // The scopes this token was created with. These define what parts of the Account the token can be used to access. Many command-line tools, such as the Linode CLI, require tokens with access to *. Tokens with more restrictive scopes are generally more secure. + Scopes string `json:"scopes"` + + // This token's label. This is for display purposes only, but can be used to more easily track what you're using each token for. (1-100 Characters) + Label string `json:"label"` + + // When this token will expire. Personal Access Tokens cannot be renewed, so after this time the token will be completely unusable and a new token will need to be generated. Tokens may be created with "null" as their expiry and will never expire unless revoked. + Expiry *time.Time `json:"expiry"` +} + +// TokenUpdateOptions fields are those accepted by UpdateToken +type TokenUpdateOptions struct { + // This token's label. This is for display purposes only, but can be used to more easily track what you're using each token for. (1-100 Characters) + Label string `json:"label"` +} + +// GetCreateOptions converts a Token to TokenCreateOptions for use in CreateToken +func (i Token) GetCreateOptions() (o TokenCreateOptions) { + o.Label = i.Label + o.Expiry = copyTime(i.Expiry) + o.Scopes = i.Scopes + return +} + +// GetUpdateOptions converts a Token to TokenUpdateOptions for use in UpdateToken +func (i Token) GetUpdateOptions() (o TokenUpdateOptions) { + o.Label = i.Label + return +} + +// TokensPagedResponse represents a paginated Token API response +type TokensPagedResponse struct { + *PageOptions + Data []Token `json:"data"` +} + +// endpoint gets the endpoint URL for Token +func (TokensPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Tokens.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Tokens when processing paginated Token responses +func (resp *TokensPagedResponse) appendData(r *TokensPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListTokens lists Tokens +func (c *Client) ListTokens(ctx context.Context, opts *ListOptions) ([]Token, error) { + response := TokensPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *Token) fixDates() *Token { + i.Created, _ = parseDates(i.CreatedStr) + i.Expiry, _ = parseDates(i.ExpiryStr) + return i +} + +// GetToken gets the token with the provided ID +func (c *Client) GetToken(ctx context.Context, id int) (*Token, error) { + e, err := c.Tokens.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Token{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Token).fixDates(), nil +} + +// CreateToken creates a Token +func (c *Client) CreateToken(ctx context.Context, createOpts TokenCreateOptions) (*Token, error) { + var body string + e, err := c.Tokens.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Token{}) + + // Format the Time as a string to meet the ISO8601 requirement + createOptsFixed := struct { + Label string `json:"label"` + Scopes string `json:"scopes"` + Expiry *string `json:"expiry"` + }{} + createOptsFixed.Label = createOpts.Label + createOptsFixed.Scopes = createOpts.Scopes + if createOpts.Expiry != nil { + iso8601Expiry := createOpts.Expiry.UTC().Format("2006-01-02T15:04:05") + createOptsFixed.Expiry = &iso8601Expiry + } + + if bodyData, err := json.Marshal(createOptsFixed); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Token).fixDates(), nil +} + +// UpdateToken updates the Token with the specified id +func (c *Client) UpdateToken(ctx context.Context, id int, updateOpts TokenUpdateOptions) (*Token, error) { + var body string + e, err := c.Tokens.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Token{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Token).fixDates(), nil +} + +// DeleteToken deletes the Token with the specified id +func (c *Client) DeleteToken(ctx context.Context, id int) error { + e, err := c.Tokens.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/regions.go b/vendor/github.com/linode/linodego/regions.go new file mode 100644 index 0000000000..b13b996ea2 --- /dev/null +++ b/vendor/github.com/linode/linodego/regions.go @@ -0,0 +1,64 @@ +package linodego + +import ( + "context" + "fmt" +) + +// Region represents a linode region object +type Region struct { + ID string `json:"id"` + Country string `json:"country"` +} + +// RegionsPagedResponse represents a linode API response for listing +type RegionsPagedResponse struct { + *PageOptions + Data []Region `json:"data"` +} + +// endpoint gets the endpoint URL for Region +func (RegionsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Regions.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Regions when processing paginated Region responses +func (resp *RegionsPagedResponse) appendData(r *RegionsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListRegions lists Regions +func (c *Client) ListRegions(ctx context.Context, opts *ListOptions) ([]Region, error) { + response := RegionsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *Region) fixDates() *Region { + return v +} + +// GetRegion gets the template with the provided ID +func (c *Client) GetRegion(ctx context.Context, id string) (*Region, error) { + e, err := c.Regions.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Region{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Region).fixDates(), nil +} diff --git a/vendor/github.com/linode/linodego/resources.go b/vendor/github.com/linode/linodego/resources.go new file mode 100644 index 0000000000..fe0c258cf6 --- /dev/null +++ b/vendor/github.com/linode/linodego/resources.go @@ -0,0 +1,162 @@ +package linodego + +import ( + "bytes" + "context" + "fmt" + "text/template" + + "gopkg.in/resty.v1" +) + +const ( + stackscriptsName = "stackscripts" + imagesName = "images" + instancesName = "instances" + instanceDisksName = "disks" + instanceConfigsName = "configs" + instanceIPsName = "ips" + instanceSnapshotsName = "snapshots" + instanceVolumesName = "instancevolumes" + ipaddressesName = "ipaddresses" + ipv6poolsName = "ipv6pools" + ipv6rangesName = "ipv6ranges" + regionsName = "regions" + volumesName = "volumes" + kernelsName = "kernels" + typesName = "types" + domainsName = "domains" + domainRecordsName = "records" + longviewName = "longview" + longviewclientsName = "longviewclients" + longviewsubscriptionsName = "longviewsubscriptions" + nodebalancersName = "nodebalancers" + nodebalancerconfigsName = "nodebalancerconfigs" + nodebalancernodesName = "nodebalancernodes" + notificationsName = "notifications" + sshkeysName = "sshkeys" + ticketsName = "tickets" + tokensName = "tokens" + accountName = "account" + eventsName = "events" + invoicesName = "invoices" + invoiceItemsName = "invoiceitems" + profileName = "profile" + managedName = "managed" + tagsName = "tags" + usersName = "users" + // notificationsName = "notifications" + + stackscriptsEndpoint = "linode/stackscripts" + imagesEndpoint = "images" + instancesEndpoint = "linode/instances" + instanceConfigsEndpoint = "linode/instances/{{ .ID }}/configs" + instanceDisksEndpoint = "linode/instances/{{ .ID }}/disks" + instanceSnapshotsEndpoint = "linode/instances/{{ .ID }}/backups" + instanceIPsEndpoint = "linode/instances/{{ .ID }}/ips" + instanceVolumesEndpoint = "linode/instances/{{ .ID }}/volumes" + ipaddressesEndpoint = "networking/ips" + ipv6poolsEndpoint = "networking/ipv6/pools" + ipv6rangesEndpoint = "networking/ipv6/ranges" + regionsEndpoint = "regions" + volumesEndpoint = "volumes" + kernelsEndpoint = "linode/kernels" + typesEndpoint = "linode/types" + domainsEndpoint = "domains" + domainRecordsEndpoint = "domains/{{ .ID }}/records" + longviewEndpoint = "longview" + longviewclientsEndpoint = "longview/clients" + longviewsubscriptionsEndpoint = "longview/subscriptions" + nodebalancersEndpoint = "nodebalancers" + // @TODO we can't use these nodebalancer endpoints unless we include these templated fields + // The API seems inconsistent about including parent IDs in objects, (compare instance configs to nb configs) + // Parent IDs would be immutable for updates and are ignored in create requests .. + // Should we include these fields in CreateOpts and UpdateOpts? + nodebalancerconfigsEndpoint = "nodebalancers/{{ .ID }}/configs" + nodebalancernodesEndpoint = "nodebalancers/{{ .ID }}/configs/{{ .SecondID }}/nodes" + sshkeysEndpoint = "profile/sshkeys" + ticketsEndpoint = "support/tickets" + tokensEndpoint = "profile/tokens" + accountEndpoint = "account" + eventsEndpoint = "account/events" + invoicesEndpoint = "account/invoices" + invoiceItemsEndpoint = "account/invoices/{{ .ID }}/items" + profileEndpoint = "profile" + managedEndpoint = "managed" + tagsEndpoint = "tags" + usersEndpoint = "account/users" + notificationsEndpoint = "account/notifications" +) + +// Resource represents a linode API resource +type Resource struct { + name string + endpoint string + isTemplate bool + endpointTemplate *template.Template + R func(ctx context.Context) *resty.Request + PR func(ctx context.Context) *resty.Request +} + +// NewResource is the factory to create a new Resource struct. If it has a template string the useTemplate bool must be set. +func NewResource(client *Client, name string, endpoint string, useTemplate bool, singleType interface{}, pagedType interface{}) *Resource { + var tmpl *template.Template + + if useTemplate { + tmpl = template.Must(template.New(name).Parse(endpoint)) + } + + r := func(ctx context.Context) *resty.Request { + return client.R(ctx).SetResult(singleType) + } + + pr := func(ctx context.Context) *resty.Request { + return client.R(ctx).SetResult(pagedType) + } + + return &Resource{name, endpoint, useTemplate, tmpl, r, pr} +} + +func (r Resource) render(data ...interface{}) (string, error) { + if data == nil { + return "", NewError("Cannot template endpoint with data") + } + out := "" + buf := bytes.NewBufferString(out) + + var substitutions interface{} + if len(data) == 1 { + substitutions = struct{ ID interface{} }{data[0]} + } else if len(data) == 2 { + substitutions = struct { + ID interface{} + SecondID interface{} + }{data[0], data[1]} + } else { + return "", NewError("Too many arguments to render template (expected 1 or 2)") + } + if err := r.endpointTemplate.Execute(buf, substitutions); err != nil { + return "", NewError(err) + } + return buf.String(), nil +} + +// endpointWithID will return the rendered endpoint string for the resource with provided id +func (r Resource) endpointWithID(id ...int) (string, error) { + if !r.isTemplate { + return r.endpoint, nil + } + data := make([]interface{}, len(id)) + for i, v := range id { + data[i] = v + } + return r.render(data...) +} + +// Endpoint will return the non-templated endpoint string for resource +func (r Resource) Endpoint() (string, error) { + if r.isTemplate { + return "", NewError(fmt.Sprintf("Tried to get endpoint for %s without providing data for template", r.name)) + } + return r.endpoint, nil +} diff --git a/vendor/github.com/linode/linodego/stackscripts.go b/vendor/github.com/linode/linodego/stackscripts.go new file mode 100644 index 0000000000..daf339b2ff --- /dev/null +++ b/vendor/github.com/linode/linodego/stackscripts.go @@ -0,0 +1,208 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// Stackscript represents a Linode StackScript +type Stackscript struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + + ID int `json:"id"` + Username string `json:"username"` + Label string `json:"label"` + Description string `json:"description"` + Images []string `json:"images"` + DeploymentsTotal int `json:"deployments_total"` + DeploymentsActive int `json:"deployments_active"` + IsPublic bool `json:"is_public"` + Created *time.Time `json:"-"` + Updated *time.Time `json:"-"` + RevNote string `json:"rev_note"` + Script string `json:"script"` + UserDefinedFields *[]StackscriptUDF `json:"user_defined_fields"` + UserGravatarID string `json:"user_gravatar_id"` +} + +// StackscriptUDF define a single variable that is accepted by a Stackscript +type StackscriptUDF struct { + // A human-readable label for the field that will serve as the input prompt for entering the value during deployment. + Label string `json:"label"` + + // The name of the field. + Name string `json:"name"` + + // An example value for the field. + Example string `json:"example"` + + // A list of acceptable single values for the field. + OneOf string `json:"oneOf,omitempty"` + + // A list of acceptable values for the field in any quantity, combination or order. + ManyOf string `json:"manyOf,omitempty"` + + // The default value. If not specified, this value will be used. + Default string `json:"default,omitempty"` +} + +// StackscriptCreateOptions fields are those accepted by CreateStackscript +type StackscriptCreateOptions struct { + Label string `json:"label"` + Description string `json:"description"` + Images []string `json:"images"` + IsPublic bool `json:"is_public"` + RevNote string `json:"rev_note"` + Script string `json:"script"` +} + +// StackscriptUpdateOptions fields are those accepted by UpdateStackscript +type StackscriptUpdateOptions StackscriptCreateOptions + +// GetCreateOptions converts a Stackscript to StackscriptCreateOptions for use in CreateStackscript +func (i Stackscript) GetCreateOptions() StackscriptCreateOptions { + return StackscriptCreateOptions{ + Label: i.Label, + Description: i.Description, + Images: i.Images, + IsPublic: i.IsPublic, + RevNote: i.RevNote, + Script: i.Script, + } +} + +// GetUpdateOptions converts a Stackscript to StackscriptUpdateOptions for use in UpdateStackscript +func (i Stackscript) GetUpdateOptions() StackscriptUpdateOptions { + return StackscriptUpdateOptions{ + Label: i.Label, + Description: i.Description, + Images: i.Images, + IsPublic: i.IsPublic, + RevNote: i.RevNote, + Script: i.Script, + } +} + +// StackscriptsPagedResponse represents a paginated Stackscript API response +type StackscriptsPagedResponse struct { + *PageOptions + Data []Stackscript `json:"data"` +} + +// endpoint gets the endpoint URL for Stackscript +func (StackscriptsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.StackScripts.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Stackscripts when processing paginated Stackscript responses +func (resp *StackscriptsPagedResponse) appendData(r *StackscriptsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListStackscripts lists Stackscripts +func (c *Client) ListStackscripts(ctx context.Context, opts *ListOptions) ([]Stackscript, error) { + response := StackscriptsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *Stackscript) fixDates() *Stackscript { + i.Created, _ = parseDates(i.CreatedStr) + i.Updated, _ = parseDates(i.UpdatedStr) + return i +} + +// GetStackscript gets the Stackscript with the provided ID +func (c *Client) GetStackscript(ctx context.Context, id int) (*Stackscript, error) { + e, err := c.StackScripts.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx). + SetResult(&Stackscript{}). + Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Stackscript).fixDates(), nil +} + +// CreateStackscript creates a StackScript +func (c *Client) CreateStackscript(ctx context.Context, createOpts StackscriptCreateOptions) (*Stackscript, error) { + var body string + e, err := c.StackScripts.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Stackscript{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Stackscript).fixDates(), nil +} + +// UpdateStackscript updates the StackScript with the specified id +func (c *Client) UpdateStackscript(ctx context.Context, id int, updateOpts StackscriptUpdateOptions) (*Stackscript, error) { + var body string + e, err := c.StackScripts.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Stackscript{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Stackscript).fixDates(), nil +} + +// DeleteStackscript deletes the StackScript with the specified id +func (c *Client) DeleteStackscript(ctx context.Context, id int) error { + e, err := c.StackScripts.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/support.go b/vendor/github.com/linode/linodego/support.go new file mode 100644 index 0000000000..6c72a4adf3 --- /dev/null +++ b/vendor/github.com/linode/linodego/support.go @@ -0,0 +1,88 @@ +package linodego + +import ( + "context" + "fmt" + "time" +) + +// Ticket represents a support ticket object +type Ticket struct { + ID int `json:"id"` + Attachments []string `json:"attachments"` + Closed *time.Time `json:"-"` + Description string `json:"description"` + Entity *TicketEntity `json:"entity"` + GravatarID string `json:"gravatar_id"` + Opened *time.Time `json:"-"` + OpenedBy string `json:"opened_by"` + Status TicketStatus `json:"status"` + Summary string `json:"summary"` + Updated *time.Time `json:"-"` + UpdatedBy string `json:"updated_by"` +} + +// TicketEntity refers a ticket to a specific entity +type TicketEntity struct { + ID int `json:"id"` + Label string `json:"label"` + Type string `json:"type"` + URL string `json:"url"` +} + +// TicketStatus constants start with Ticket and include Linode API Ticket Status values +type TicketStatus string + +// TicketStatus constants reflect the current status of a Ticket +const ( + TicketNew TicketStatus = "new" + TicketClosed TicketStatus = "closed" + TicketOpen TicketStatus = "open" +) + +// TicketsPagedResponse represents a paginated ticket API response +type TicketsPagedResponse struct { + *PageOptions + Data []Ticket `json:"data"` +} + +func (TicketsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Tickets.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +func (resp *TicketsPagedResponse) appendData(r *TicketsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListTickets returns a collection of Support Tickets on the Account. Support Tickets +// can be both tickets opened with Linode for support, as well as tickets generated by +// Linode regarding the Account. This collection includes all Support Tickets generated +// on the Account, with open tickets returned first. +func (c *Client) ListTickets(ctx context.Context, opts *ListOptions) ([]Ticket, error) { + response := TicketsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetTicket gets a Support Ticket on the Account with the specified ID +func (c *Client) GetTicket(ctx context.Context, id int) (*Ticket, error) { + e, err := c.Tickets.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx). + SetResult(&Ticket{}). + Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Ticket), nil +} diff --git a/vendor/github.com/linode/linodego/tags.go b/vendor/github.com/linode/linodego/tags.go new file mode 100644 index 0000000000..2cb44272b2 --- /dev/null +++ b/vendor/github.com/linode/linodego/tags.go @@ -0,0 +1,219 @@ +package linodego + +import ( + "context" + "encoding/json" + "errors" + "fmt" +) + +// Tag represents a Tag object +type Tag struct { + Label string `json:"label"` +} + +// TaggedObject represents a Tagged Object object +type TaggedObject struct { + Type string `json:"type"` + RawData json.RawMessage `json:"data"` + Data interface{} `json:"-"` +} + +// SortedObjects currently only includes Instances +type SortedObjects struct { + Instances []Instance + Domains []Domain + Volumes []Volume + NodeBalancers []NodeBalancer + /* + StackScripts []Stackscript + */ +} + +// TaggedObjectList are a list of TaggedObjects, as returning by ListTaggedObjects +type TaggedObjectList []TaggedObject + +// TagCreateOptions fields are those accepted by CreateTag +type TagCreateOptions struct { + Label string `json:"label"` + Linodes []int `json:"linodes,omitempty"` + Domains []int `json:"domains,omitempty"` + Volumes []int `json:"volumes,omitempty"` + NodeBalancers []int `json:"nodebalancers,omitempty"` +} + +// GetCreateOptions converts a Tag to TagCreateOptions for use in CreateTag +func (i Tag) GetCreateOptions() (o TagCreateOptions) { + o.Label = i.Label + return +} + +// TaggedObjectsPagedResponse represents a paginated Tag API response +type TaggedObjectsPagedResponse struct { + *PageOptions + Data []TaggedObject `json:"data"` +} + +// TagsPagedResponse represents a paginated Tag API response +type TagsPagedResponse struct { + *PageOptions + Data []Tag `json:"data"` +} + +// endpoint gets the endpoint URL for Tag +func (TagsPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Tags.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// endpoint gets the endpoint URL for Tag +func (TaggedObjectsPagedResponse) endpointWithID(c *Client, id string) string { + endpoint, err := c.Tags.Endpoint() + if err != nil { + panic(err) + } + endpoint = fmt.Sprintf("%s/%s", endpoint, id) + return endpoint +} + +// appendData appends Tags when processing paginated Tag responses +func (resp *TagsPagedResponse) appendData(r *TagsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// appendData appends TaggedObjects when processing paginated TaggedObjects responses +func (resp *TaggedObjectsPagedResponse) appendData(r *TaggedObjectsPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListTags lists Tags +func (c *Client) ListTags(ctx context.Context, opts *ListOptions) ([]Tag, error) { + response := TagsPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixData stores an object of the type defined by Type in Data using RawData +func (i *TaggedObject) fixData() (*TaggedObject, error) { + switch i.Type { + case "linode": + obj := Instance{} + if err := json.Unmarshal(i.RawData, &obj); err != nil { + return nil, err + } + i.Data = obj + case "nodebalancer": + obj := NodeBalancer{} + if err := json.Unmarshal(i.RawData, &obj); err != nil { + return nil, err + } + i.Data = obj + case "domain": + obj := Domain{} + if err := json.Unmarshal(i.RawData, &obj); err != nil { + return nil, err + } + i.Data = obj + case "volume": + obj := Volume{} + if err := json.Unmarshal(i.RawData, &obj); err != nil { + return nil, err + } + i.Data = obj + } + + return i, nil +} + +// ListTaggedObjects lists Tagged Objects +func (c *Client) ListTaggedObjects(ctx context.Context, label string, opts *ListOptions) (TaggedObjectList, error) { + response := TaggedObjectsPagedResponse{} + err := c.listHelperWithID(ctx, &response, label, opts) + if err != nil { + return nil, err + } + for i := range response.Data { + if _, err := response.Data[i].fixData(); err != nil { + return nil, err + } + } + return response.Data, nil +} + +// SortedObjects converts a list of TaggedObjects into a Sorted Objects struct, for easier access +func (t TaggedObjectList) SortedObjects() (SortedObjects, error) { + so := SortedObjects{} + for _, o := range t { + switch o.Type { + case "linode": + if instance, ok := o.Data.(Instance); ok { + so.Instances = append(so.Instances, instance) + } else { + return so, errors.New("Expected an Instance when Type was \"linode\"") + } + case "domain": + if domain, ok := o.Data.(Domain); ok { + so.Domains = append(so.Domains, domain) + } else { + return so, errors.New("Expected a Domain when Type was \"domain\"") + } + case "volume": + if volume, ok := o.Data.(Volume); ok { + so.Volumes = append(so.Volumes, volume) + } else { + return so, errors.New("Expected an Volume when Type was \"volume\"") + } + case "nodebalancer": + if nodebalancer, ok := o.Data.(NodeBalancer); ok { + so.NodeBalancers = append(so.NodeBalancers, nodebalancer) + } else { + return so, errors.New("Expected an NodeBalancer when Type was \"nodebalancer\"") + } + } + } + return so, nil +} + +// CreateTag creates a Tag +func (c *Client) CreateTag(ctx context.Context, createOpts TagCreateOptions) (*Tag, error) { + var body string + e, err := c.Tags.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Tag{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Tag), nil +} + +// DeleteTag deletes the Tag with the specified id +func (c *Client) DeleteTag(ctx context.Context, label string) error { + e, err := c.Tags.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%s", e, label) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/template.go b/vendor/github.com/linode/linodego/template.go new file mode 100644 index 0000000000..ed0616837a --- /dev/null +++ b/vendor/github.com/linode/linodego/template.go @@ -0,0 +1,167 @@ +// +build ignore + +package linodego + +/* + - replace "Template" with "NameOfResource" + - replace "template" with "nameOfResource" + - copy template_test.go and do the same + - When updating Template structs, + - use pointers where ever null'able would have a different meaning if the wrapper + supplied "" or 0 instead + - Add "NameOfResource" to client.go, resources.go, pagination.go +*/ + +import ( + "context" + "encoding/json" + "fmt" +) + +// Template represents a Template object +type Template struct { + ID int `json:"id"` + // UpdatedStr string `json:"updated"` + // Updated *time.Time `json:"-"` +} + +// TemplateCreateOptions fields are those accepted by CreateTemplate +type TemplateCreateOptions struct { +} + +// TemplateUpdateOptions fields are those accepted by UpdateTemplate +type TemplateUpdateOptions struct { +} + +// GetCreateOptions converts a Template to TemplateCreateOptions for use in CreateTemplate +func (i Template) GetCreateOptions() (o TemplateCreateOptions) { + // o.Label = i.Label + // o.Description = copyString(i.Description) + return +} + +// GetUpdateOptions converts a Template to TemplateUpdateOptions for use in UpdateTemplate +func (i Template) GetUpdateOptions() (o TemplateUpdateOptions) { + // o.Label = i.Label + // o.Description = copyString(i.Description) + return +} + +// TemplatesPagedResponse represents a paginated Template API response +type TemplatesPagedResponse struct { + *PageOptions + Data []Template `json:"data"` +} + +// endpoint gets the endpoint URL for Template +func (TemplatesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Templates.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Templates when processing paginated Template responses +func (resp *TemplatesPagedResponse) appendData(r *TemplatesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListTemplates lists Templates +func (c *Client) ListTemplates(ctx context.Context, opts *ListOptions) ([]Template, error) { + response := TemplatesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (i *Template) fixDates() *Template { + // i.Created, _ = parseDates(i.CreatedStr) + // i.Updated, _ = parseDates(i.UpdatedStr) + return i +} + +// GetTemplate gets the template with the provided ID +func (c *Client) GetTemplate(ctx context.Context, id int) (*Template, error) { + e, err := c.Templates.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Template{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Template).fixDates(), nil +} + +// CreateTemplate creates a Template +func (c *Client) CreateTemplate(ctx context.Context, createOpts TemplateCreateOptions) (*Template, error) { + var body string + e, err := c.Templates.Endpoint() + if err != nil { + return nil, err + } + + req := c.R(ctx).SetResult(&Template{}) + + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Template).fixDates(), nil +} + +// UpdateTemplate updates the Template with the specified id +func (c *Client) UpdateTemplate(ctx context.Context, id int, updateOpts TemplateUpdateOptions) (*Template, error) { + var body string + e, err := c.Templates.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Template{}) + + if bodyData, err := json.Marshal(updateOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Template).fixDates(), nil +} + +// DeleteTemplate deletes the Template with the specified id +func (c *Client) DeleteTemplate(ctx context.Context, id int) error { + e, err := c.Templates.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/types.go b/vendor/github.com/linode/linodego/types.go new file mode 100644 index 0000000000..d1ffbafef9 --- /dev/null +++ b/vendor/github.com/linode/linodego/types.go @@ -0,0 +1,90 @@ +package linodego + +import ( + "context" + "fmt" +) + +// LinodeType represents a linode type object +type LinodeType struct { + ID string `json:"id"` + Disk int `json:"disk"` + Class LinodeTypeClass `json:"class"` // enum: nanode, standard, highmem, dedicated + Price *LinodePrice `json:"price"` + Label string `json:"label"` + Addons *LinodeAddons `json:"addons"` + NetworkOut int `json:"network_out"` + Memory int `json:"memory"` + Transfer int `json:"transfer"` + VCPUs int `json:"vcpus"` +} + +// LinodePrice represents a linode type price object +type LinodePrice struct { + Hourly float32 `json:"hourly"` + Monthly float32 `json:"monthly"` +} + +// LinodeBackupsAddon represents a linode backups addon object +type LinodeBackupsAddon struct { + Price *LinodePrice `json:"price"` +} + +// LinodeAddons represent the linode addons object +type LinodeAddons struct { + Backups *LinodeBackupsAddon `json:"backups"` +} + +// LinodeTypeClass constants start with Class and include Linode API Instance Type Classes +type LinodeTypeClass string + +// LinodeTypeClass contants are the Instance Type Classes that an Instance Type can be assigned +const ( + ClassNanode LinodeTypeClass = "nanode" + ClassStandard LinodeTypeClass = "standard" + ClassHighmem LinodeTypeClass = "highmem" + ClassDedicated LinodeTypeClass = "dedicated" +) + +// LinodeTypesPagedResponse represents a linode types API response for listing +type LinodeTypesPagedResponse struct { + *PageOptions + Data []LinodeType `json:"data"` +} + +func (LinodeTypesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Types.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +func (resp *LinodeTypesPagedResponse) appendData(r *LinodeTypesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListTypes lists linode types +func (c *Client) ListTypes(ctx context.Context, opts *ListOptions) ([]LinodeType, error) { + response := LinodeTypesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + if err != nil { + return nil, err + } + return response.Data, nil +} + +// GetType gets the type with the provided ID +func (c *Client) GetType(ctx context.Context, typeID string) (*LinodeType, error) { + e, err := c.Types.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%s", e, typeID) + + r, err := coupleAPIErrors(c.Types.R(ctx).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*LinodeType), nil +} diff --git a/vendor/github.com/linode/linodego/util.go b/vendor/github.com/linode/linodego/util.go new file mode 100644 index 0000000000..a37a304e4a --- /dev/null +++ b/vendor/github.com/linode/linodego/util.go @@ -0,0 +1,15 @@ +package linodego + +import "time" + +const ( + dateLayout = "2006-01-02T15:04:05" +) + +func parseDates(dateStr string) (*time.Time, error) { + d, err := time.Parse(dateLayout, dateStr) + if err != nil { + return nil, err + } + return &d, nil +} diff --git a/vendor/github.com/linode/linodego/volumes.go b/vendor/github.com/linode/linodego/volumes.go new file mode 100644 index 0000000000..0a528b5452 --- /dev/null +++ b/vendor/github.com/linode/linodego/volumes.go @@ -0,0 +1,299 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "time" +) + +// VolumeStatus indicates the status of the Volume +type VolumeStatus string + +const ( + // VolumeCreating indicates the Volume is being created and is not yet available for use + VolumeCreating VolumeStatus = "creating" + + // VolumeActive indicates the Volume is online and available for use + VolumeActive VolumeStatus = "active" + + // VolumeResizing indicates the Volume is in the process of upgrading its current capacity + VolumeResizing VolumeStatus = "resizing" + + // VolumeContactSupport indicates there is a problem with the Volume. A support ticket must be opened to resolve the issue + VolumeContactSupport VolumeStatus = "contact_support" +) + +// Volume represents a linode volume object +type Volume struct { + CreatedStr string `json:"created"` + UpdatedStr string `json:"updated"` + + ID int `json:"id"` + Label string `json:"label"` + Status VolumeStatus `json:"status"` + Region string `json:"region"` + Size int `json:"size"` + LinodeID *int `json:"linode_id"` + FilesystemPath string `json:"filesystem_path"` + Tags []string `json:"tags"` + Created time.Time `json:"-"` + Updated time.Time `json:"-"` +} + +// VolumeCreateOptions fields are those accepted by CreateVolume +type VolumeCreateOptions struct { + Label string `json:"label,omitempty"` + Region string `json:"region,omitempty"` + LinodeID int `json:"linode_id,omitempty"` + ConfigID int `json:"config_id,omitempty"` + // The Volume's size, in GiB. Minimum size is 10GiB, maximum size is 10240GiB. A "0" value will result in the default size. + Size int `json:"size,omitempty"` + // An array of tags applied to this object. Tags are for organizational purposes only. + Tags []string `json:"tags"` +} + +// VolumeUpdateOptions fields are those accepted by UpdateVolume +type VolumeUpdateOptions struct { + Label string `json:"label,omitempty"` + Tags *[]string `json:"tags,omitempty"` +} + +// VolumeAttachOptions fields are those accepted by AttachVolume +type VolumeAttachOptions struct { + LinodeID int `json:"linode_id"` + ConfigID int `json:"config_id,omitempty"` +} + +// VolumesPagedResponse represents a linode API response for listing of volumes +type VolumesPagedResponse struct { + *PageOptions + Data []Volume `json:"data"` +} + +// GetUpdateOptions converts a Volume to VolumeUpdateOptions for use in UpdateVolume +func (v Volume) GetUpdateOptions() (updateOpts VolumeUpdateOptions) { + updateOpts.Label = v.Label + updateOpts.Tags = &v.Tags + return +} + +// GetCreateOptions converts a Volume to VolumeCreateOptions for use in CreateVolume +func (v Volume) GetCreateOptions() (createOpts VolumeCreateOptions) { + createOpts.Label = v.Label + createOpts.Tags = v.Tags + createOpts.Region = v.Region + createOpts.Size = v.Size + if v.LinodeID != nil && *v.LinodeID > 0 { + createOpts.LinodeID = *v.LinodeID + } + return +} + +// endpoint gets the endpoint URL for Volume +func (VolumesPagedResponse) endpoint(c *Client) string { + endpoint, err := c.Volumes.Endpoint() + if err != nil { + panic(err) + } + return endpoint +} + +// appendData appends Volumes when processing paginated Volume responses +func (resp *VolumesPagedResponse) appendData(r *VolumesPagedResponse) { + resp.Data = append(resp.Data, r.Data...) +} + +// ListVolumes lists Volumes +func (c *Client) ListVolumes(ctx context.Context, opts *ListOptions) ([]Volume, error) { + response := VolumesPagedResponse{} + err := c.listHelper(ctx, &response, opts) + for i := range response.Data { + response.Data[i].fixDates() + } + if err != nil { + return nil, err + } + return response.Data, nil +} + +// fixDates converts JSON timestamps to Go time.Time values +func (v *Volume) fixDates() *Volume { + if parsed, err := parseDates(v.CreatedStr); err != nil { + v.Created = *parsed + } + if parsed, err := parseDates(v.UpdatedStr); err != nil { + v.Updated = *parsed + } + return v +} + +// GetVolume gets the template with the provided ID +func (c *Client) GetVolume(ctx context.Context, id int) (*Volume, error) { + e, err := c.Volumes.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + r, err := coupleAPIErrors(c.R(ctx).SetResult(&Volume{}).Get(e)) + if err != nil { + return nil, err + } + return r.Result().(*Volume).fixDates(), nil +} + +// AttachVolume attaches a volume to a Linode instance +func (c *Client) AttachVolume(ctx context.Context, id int, options *VolumeAttachOptions) (*Volume, error) { + body := "" + if bodyData, err := json.Marshal(options); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + e, err := c.Volumes.Endpoint() + if err != nil { + return nil, NewError(err) + } + + e = fmt.Sprintf("%s/%d/attach", e, id) + resp, err := coupleAPIErrors(c.R(ctx). + SetResult(&Volume{}). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return resp.Result().(*Volume).fixDates(), nil +} + +// CreateVolume creates a Linode Volume +func (c *Client) CreateVolume(ctx context.Context, createOpts VolumeCreateOptions) (*Volume, error) { + body := "" + if bodyData, err := json.Marshal(createOpts); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + e, err := c.Volumes.Endpoint() + if err != nil { + return nil, NewError(err) + } + + resp, err := coupleAPIErrors(c.R(ctx). + SetResult(&Volume{}). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return resp.Result().(*Volume).fixDates(), nil +} + +// RenameVolume renames the label of a Linode volume +// DEPRECATED: use UpdateVolume +func (c *Client) RenameVolume(ctx context.Context, id int, label string) (*Volume, error) { + updateOpts := VolumeUpdateOptions{Label: label} + return c.UpdateVolume(ctx, id, updateOpts) +} + +// UpdateVolume updates the Volume with the specified id +func (c *Client) UpdateVolume(ctx context.Context, id int, volume VolumeUpdateOptions) (*Volume, error) { + var body string + e, err := c.Volumes.Endpoint() + if err != nil { + return nil, err + } + e = fmt.Sprintf("%s/%d", e, id) + + req := c.R(ctx).SetResult(&Volume{}) + + if bodyData, err := json.Marshal(volume); err == nil { + body = string(bodyData) + } else { + return nil, NewError(err) + } + + r, err := coupleAPIErrors(req. + SetBody(body). + Put(e)) + + if err != nil { + return nil, err + } + return r.Result().(*Volume).fixDates(), nil +} + +// CloneVolume clones a Linode volume +func (c *Client) CloneVolume(ctx context.Context, id int, label string) (*Volume, error) { + body := fmt.Sprintf("{\"label\":\"%s\"}", label) + + e, err := c.Volumes.Endpoint() + if err != nil { + return nil, NewError(err) + } + e = fmt.Sprintf("%s/%d/clone", e, id) + + resp, err := coupleAPIErrors(c.R(ctx). + SetResult(&Volume{}). + SetBody(body). + Post(e)) + + if err != nil { + return nil, err + } + + return resp.Result().(*Volume).fixDates(), nil +} + +// DetachVolume detaches a Linode volume +func (c *Client) DetachVolume(ctx context.Context, id int) error { + body := "" + + e, err := c.Volumes.Endpoint() + if err != nil { + return NewError(err) + } + + e = fmt.Sprintf("%s/%d/detach", e, id) + + _, err = coupleAPIErrors(c.R(ctx). + SetBody(body). + Post(e)) + + return err +} + +// ResizeVolume resizes an instance to new Linode type +func (c *Client) ResizeVolume(ctx context.Context, id int, size int) error { + body := fmt.Sprintf("{\"size\": %d}", size) + + e, err := c.Volumes.Endpoint() + if err != nil { + return NewError(err) + } + e = fmt.Sprintf("%s/%d/resize", e, id) + + _, err = coupleAPIErrors(c.R(ctx). + SetBody(body). + Post(e)) + + return err +} + +// DeleteVolume deletes the Volume with the specified id +func (c *Client) DeleteVolume(ctx context.Context, id int) error { + e, err := c.Volumes.Endpoint() + if err != nil { + return err + } + e = fmt.Sprintf("%s/%d", e, id) + + _, err = coupleAPIErrors(c.R(ctx).Delete(e)) + return err +} diff --git a/vendor/github.com/linode/linodego/waitfor.go b/vendor/github.com/linode/linodego/waitfor.go new file mode 100644 index 0000000000..8f29a41505 --- /dev/null +++ b/vendor/github.com/linode/linodego/waitfor.go @@ -0,0 +1,273 @@ +package linodego + +import ( + "context" + "encoding/json" + "fmt" + "log" + "strconv" + "strings" + "time" +) + +// WaitForInstanceStatus waits for the Linode instance to reach the desired state +// before returning. It will timeout with an error after timeoutSeconds. +func (client Client) WaitForInstanceStatus(ctx context.Context, instanceID int, status InstanceStatus, timeoutSeconds int) (*Instance, error) { + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + instance, err := client.GetInstance(ctx, instanceID) + if err != nil { + return instance, err + } + complete := (instance.Status == status) + + if complete { + return instance, nil + } + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Instance %d status %s: %s", instanceID, status, ctx.Err()) + } + } +} + +// WaitForInstanceDiskStatus waits for the Linode instance disk to reach the desired state +// before returning. It will timeout with an error after timeoutSeconds. +func (client Client) WaitForInstanceDiskStatus(ctx context.Context, instanceID int, diskID int, status DiskStatus, timeoutSeconds int) (*InstanceDisk, error) { + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + // GetInstanceDisk will 404 on newly created disks. use List instead. + // disk, err := client.GetInstanceDisk(ctx, instanceID, diskID) + disks, err := client.ListInstanceDisks(ctx, instanceID, nil) + if err != nil { + return nil, err + } + for _, disk := range disks { + if disk.ID == diskID { + complete := (disk.Status == status) + if complete { + return &disk, nil + } + break + } + } + + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Instance %d Disk %d status %s: %s", instanceID, diskID, status, ctx.Err()) + } + } +} + +// WaitForVolumeStatus waits for the Volume to reach the desired state +// before returning. It will timeout with an error after timeoutSeconds. +func (client Client) WaitForVolumeStatus(ctx context.Context, volumeID int, status VolumeStatus, timeoutSeconds int) (*Volume, error) { + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + volume, err := client.GetVolume(ctx, volumeID) + if err != nil { + return volume, err + } + complete := (volume.Status == status) + + if complete { + return volume, nil + } + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Volume %d status %s: %s", volumeID, status, ctx.Err()) + } + } +} + +// WaitForSnapshotStatus waits for the Snapshot to reach the desired state +// before returning. It will timeout with an error after timeoutSeconds. +func (client Client) WaitForSnapshotStatus(ctx context.Context, instanceID int, snapshotID int, status InstanceSnapshotStatus, timeoutSeconds int) (*InstanceSnapshot, error) { + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + snapshot, err := client.GetInstanceSnapshot(ctx, instanceID, snapshotID) + if err != nil { + return snapshot, err + } + complete := (snapshot.Status == status) + + if complete { + return snapshot, nil + } + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Instance %d Snapshot %d status %s: %s", instanceID, snapshotID, status, ctx.Err()) + } + } +} + +// WaitForVolumeLinodeID waits for the Volume to match the desired LinodeID +// before returning. An active Instance will not immediately attach or detach a volume, so the +// the LinodeID must be polled to determine volume readiness from the API. +// WaitForVolumeLinodeID will timeout with an error after timeoutSeconds. +func (client Client) WaitForVolumeLinodeID(ctx context.Context, volumeID int, linodeID *int, timeoutSeconds int) (*Volume, error) { + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + volume, err := client.GetVolume(ctx, volumeID) + if err != nil { + return volume, err + } + + if linodeID == nil && volume.LinodeID == nil { + return volume, nil + } else if linodeID == nil || volume.LinodeID == nil { + // continue waiting + } else if *volume.LinodeID == *linodeID { + return volume, nil + } + + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Volume %d to have Instance %v: %s", volumeID, linodeID, ctx.Err()) + } + } +} + +// WaitForEventFinished waits for an entity action to reach the 'finished' state +// before returning. It will timeout with an error after timeoutSeconds. +// If the event indicates a failure both the failed event and the error will be returned. +func (client Client) WaitForEventFinished(ctx context.Context, id interface{}, entityType EntityType, action EventAction, minStart time.Time, timeoutSeconds int) (*Event, error) { + titledEntityType := strings.Title(string(entityType)) + filter, _ := json.Marshal(map[string]interface{}{ + // Entity is not filtered by the API + // Perhaps one day they will permit Entity ID/Type filtering. + // We'll have to verify these values manually, for now. + //"entity": map[string]interface{}{ + // "id": fmt.Sprintf("%v", id), + // "type": entityType, + //}, + + // Nor is action + //"action": action, + + // Created is not correctly filtered by the API + // We'll have to verify these values manually, for now. + //"created": map[string]interface{}{ + // "+gte": minStart.Format(time.RFC3339), + //}, + + // With potentially 1000+ events coming back, we should filter on something + "seen": false, + + // Float the latest events to page 1 + "+order_by": "created", + "+order": "desc", + }) + + // Optimistically restrict results to page 1. We should remove this when more + // precise filtering options exist. + listOptions := NewListOptions(1, string(filter)) + + ctx, cancel := context.WithTimeout(ctx, time.Duration(timeoutSeconds)*time.Second) + defer cancel() + + if deadline, ok := ctx.Deadline(); ok { + duration := time.Until(deadline) + log.Printf("[INFO] Waiting %d seconds for %s events since %v for %s %v", int(duration.Seconds()), action, minStart, titledEntityType, id) + } + + ticker := time.NewTicker(client.millisecondsPerPoll * time.Millisecond) + defer ticker.Stop() + for { + select { + case <-ticker.C: + + events, err := client.ListEvents(ctx, listOptions) + if err != nil { + return nil, err + } + + // If there are events for this instance + action, inspect them + for _, event := range events { + if event.Action != action { + // log.Println("action mismatch", event.Action, action) + continue + } + if event.Entity == nil || event.Entity.Type != entityType { + // log.Println("type mismatch", event.Entity.Type, entityType) + continue + } + + var entID string + + switch event.Entity.ID.(type) { + case float64, float32: + entID = fmt.Sprintf("%.f", event.Entity.ID) + case int: + entID = strconv.Itoa(event.Entity.ID.(int)) + default: + entID = fmt.Sprintf("%v", event.Entity.ID) + } + + var findID string + switch id.(type) { + case float64, float32: + findID = fmt.Sprintf("%.f", id) + case int: + findID = strconv.Itoa(id.(int)) + default: + findID = fmt.Sprintf("%v", id) + } + + if entID != findID { + // log.Println("id mismatch", entID, findID) + continue + } + + // @TODO(displague) This event.Created check shouldn't be needed, but it appears + // that the ListEvents method is not populating it correctly + if event.Created == nil { + log.Printf("[WARN] event.Created is nil when API returned: %#+v", event.CreatedStr) + } else if *event.Created != minStart && !event.Created.After(minStart) { + // Not the event we were looking for + // log.Println(event.Created, "is not >=", minStart) + continue + + } + + if event.Status == EventFailed { + return &event, fmt.Errorf("%s %v action %s failed", titledEntityType, id, action) + } else if event.Status == EventScheduled { + log.Printf("[INFO] %s %v action %s is scheduled", titledEntityType, id, action) + } else if event.Status == EventFinished { + log.Printf("[INFO] %s %v action %s is finished", titledEntityType, id, action) + return &event, nil + } + // TODO(displague) can we bump the ticker to TimeRemaining/2 (>=1) when non-nil? + log.Printf("[INFO] %s %v action %s is %s", titledEntityType, id, action, event.Status) + } + case <-ctx.Done(): + return nil, fmt.Errorf("Error waiting for Event Status '%s' of %s %v action '%s': %s", EventFinished, titledEntityType, id, action, ctx.Err()) + } + } +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/LICENSE b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/LICENSE new file mode 100644 index 0000000000..efc75a2253 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright (c) 2017-2018 Tencent Ltd. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go new file mode 100644 index 0000000000..96a9644b1c --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/client.go @@ -0,0 +1,264 @@ +package common + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "log" + "net/http" + "net/http/httputil" + "strconv" + "strings" + "time" + + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" +) + +type Client struct { + region string + httpClient *http.Client + httpProfile *profile.HttpProfile + profile *profile.ClientProfile + credential *Credential + signMethod string + unsignedPayload bool + debug bool +} + +func (c *Client) Send(request tchttp.Request, response tchttp.Response) (err error) { + if request.GetDomain() == "" { + domain := c.httpProfile.Endpoint + if domain == "" { + domain = tchttp.GetServiceDomain(request.GetService()) + } + request.SetDomain(domain) + } + + if request.GetHttpMethod() == "" { + request.SetHttpMethod(c.httpProfile.ReqMethod) + } + + tchttp.CompleteCommonParams(request, c.GetRegion()) + + if c.signMethod == "HmacSHA1" || c.signMethod == "HmacSHA256" { + return c.sendWithSignatureV1(request, response) + } else { + return c.sendWithSignatureV3(request, response) + } +} + +func (c *Client) sendWithSignatureV1(request tchttp.Request, response tchttp.Response) (err error) { + // TODO: not an elegant way, it should be done in common params, but finally it need to refactor + request.GetParams()["Language"] = c.profile.Language + err = tchttp.ConstructParams(request) + if err != nil { + return err + } + err = signRequest(request, c.credential, c.signMethod) + if err != nil { + return err + } + httpRequest, err := http.NewRequest(request.GetHttpMethod(), request.GetUrl(), request.GetBodyReader()) + if err != nil { + return err + } + if request.GetHttpMethod() == "POST" { + httpRequest.Header["Content-Type"] = []string{"application/x-www-form-urlencoded"} + } + if c.debug { + outbytes, err := httputil.DumpRequest(httpRequest, true) + if err != nil { + log.Printf("[ERROR] dump request failed because %s", err) + return err + } + log.Printf("[DEBUG] http request = %s", outbytes) + } + httpResponse, err := c.httpClient.Do(httpRequest) + if err != nil { + msg := fmt.Sprintf("Fail to get response because %s", err) + return errors.NewTencentCloudSDKError("ClientError.NetworkError", msg, "") + } + err = tchttp.ParseFromHttpResponse(httpResponse, response) + return err +} + +func (c *Client) sendWithSignatureV3(request tchttp.Request, response tchttp.Response) (err error) { + headers := map[string]string{ + "Host": request.GetDomain(), + "X-TC-Action": request.GetAction(), + "X-TC-Version": request.GetVersion(), + "X-TC-Timestamp": request.GetParams()["Timestamp"], + "X-TC-RequestClient": request.GetParams()["RequestClient"], + "X-TC-Language": c.profile.Language, + } + if c.region != "" { + headers["X-TC-Region"] = c.region + } + if c.credential.Token != "" { + headers["X-TC-Token"] = c.credential.Token + } + if request.GetHttpMethod() == "GET" { + headers["Content-Type"] = "application/x-www-form-urlencoded" + } else { + headers["Content-Type"] = "application/json" + } + + // start signature v3 process + + // build canonical request string + httpRequestMethod := request.GetHttpMethod() + canonicalURI := "/" + canonicalQueryString := "" + if httpRequestMethod == "GET" { + err = tchttp.ConstructParams(request) + if err != nil { + return err + } + params := make(map[string]string) + for key, value := range request.GetParams() { + params[key] = value + } + delete(params, "Action") + delete(params, "Version") + delete(params, "Nonce") + delete(params, "Region") + delete(params, "RequestClient") + delete(params, "Timestamp") + canonicalQueryString = tchttp.GetUrlQueriesEncoded(params) + } + canonicalHeaders := fmt.Sprintf("content-type:%s\nhost:%s\n", headers["Content-Type"], headers["Host"]) + signedHeaders := "content-type;host" + requestPayload := "" + if httpRequestMethod == "POST" { + b, err := json.Marshal(request) + if err != nil { + return err + } + requestPayload = string(b) + } + hashedRequestPayload := "" + if c.unsignedPayload { + hashedRequestPayload = sha256hex("UNSIGNED-PAYLOAD") + headers["X-TC-Content-SHA256"] = "UNSIGNED-PAYLOAD" + } else { + hashedRequestPayload = sha256hex(requestPayload) + } + canonicalRequest := fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s", + httpRequestMethod, + canonicalURI, + canonicalQueryString, + canonicalHeaders, + signedHeaders, + hashedRequestPayload) + //log.Println("canonicalRequest:", canonicalRequest) + + // build string to sign + algorithm := "TC3-HMAC-SHA256" + requestTimestamp := headers["X-TC-Timestamp"] + timestamp, _ := strconv.ParseInt(requestTimestamp, 10, 64) + t := time.Unix(timestamp, 0).UTC() + // must be the format 2006-01-02, ref to package time for more info + date := t.Format("2006-01-02") + credentialScope := fmt.Sprintf("%s/%s/tc3_request", date, request.GetService()) + hashedCanonicalRequest := sha256hex(canonicalRequest) + string2sign := fmt.Sprintf("%s\n%s\n%s\n%s", + algorithm, + requestTimestamp, + credentialScope, + hashedCanonicalRequest) + //log.Println("string2sign", string2sign) + + // sign string + secretDate := hmacsha256(date, "TC3"+c.credential.SecretKey) + secretService := hmacsha256(request.GetService(), secretDate) + secretKey := hmacsha256("tc3_request", secretService) + signature := hex.EncodeToString([]byte(hmacsha256(string2sign, secretKey))) + //log.Println("signature", signature) + + // build authorization + authorization := fmt.Sprintf("%s Credential=%s/%s, SignedHeaders=%s, Signature=%s", + algorithm, + c.credential.SecretId, + credentialScope, + signedHeaders, + signature) + //log.Println("authorization", authorization) + + headers["Authorization"] = authorization + url := "https://" + request.GetDomain() + request.GetPath() + if canonicalQueryString != "" { + url = url + "?" + canonicalQueryString + } + httpRequest, err := http.NewRequest(httpRequestMethod, url, strings.NewReader(requestPayload)) + if err != nil { + return err + } + for k, v := range headers { + httpRequest.Header[k] = []string{v} + } + if c.debug { + outbytes, err := httputil.DumpRequest(httpRequest, true) + if err != nil { + log.Printf("[ERROR] dump request failed because %s", err) + return err + } + log.Printf("[DEBUG] http request = %s", outbytes) + } + httpResponse, err := c.httpClient.Do(httpRequest) + if err != nil { + msg := fmt.Sprintf("Fail to get response because %s", err) + return errors.NewTencentCloudSDKError("ClientError.NetworkError", msg, "") + } + err = tchttp.ParseFromHttpResponse(httpResponse, response) + return err +} + +func (c *Client) GetRegion() string { + return c.region +} + +func (c *Client) Init(region string) *Client { + c.httpClient = &http.Client{} + c.region = region + c.signMethod = "TC3-HMAC-SHA256" + c.debug = false + log.SetFlags(log.LstdFlags | log.Lshortfile) + return c +} + +func (c *Client) WithSecretId(secretId, secretKey string) *Client { + c.credential = NewCredential(secretId, secretKey) + return c +} + +func (c *Client) WithCredential(cred *Credential) *Client { + c.credential = cred + return c +} + +func (c *Client) WithProfile(clientProfile *profile.ClientProfile) *Client { + c.profile = clientProfile + c.signMethod = clientProfile.SignMethod + c.unsignedPayload = clientProfile.UnsignedPayload + c.httpProfile = clientProfile.HttpProfile + c.httpClient.Timeout = time.Duration(c.httpProfile.ReqTimeout) * time.Second + return c +} + +func (c *Client) WithSignatureMethod(method string) *Client { + c.signMethod = method + return c +} + +func (c *Client) WithHttpTransport(transport http.RoundTripper) *Client { + c.httpClient.Transport = transport + return c +} + +func NewClientWithSecretId(secretId, secretKey, region string) (client *Client, err error) { + client = &Client{} + client.Init(region).WithSecretId(secretId, secretKey) + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/credentials.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/credentials.go new file mode 100644 index 0000000000..b734c13734 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/credentials.go @@ -0,0 +1,58 @@ +package common + +type Credential struct { + SecretId string + SecretKey string + Token string +} + +func NewCredential(secretId, secretKey string) *Credential { + return &Credential{ + SecretId: secretId, + SecretKey: secretKey, + } +} + +func NewTokenCredential(secretId, secretKey, token string) *Credential { + return &Credential{ + SecretId: secretId, + SecretKey: secretKey, + Token: token, + } +} + +func (c *Credential) GetCredentialParams() map[string]string { + p := map[string]string{ + "SecretId": c.SecretId, + } + if c.Token != "" { + p["Token"] = c.Token + } + return p +} + +// Nowhere use them and we haven't well designed these structures and +// underlying method, which leads to the situation that it is hard to +// refactor it to interfaces. +// Hence they are removed and merged into Credential. + +//type TokenCredential struct { +// SecretId string +// SecretKey string +// Token string +//} + +//func NewTokenCredential(secretId, secretKey, token string) *TokenCredential { +// return &TokenCredential{ +// SecretId: secretId, +// SecretKey: secretKey, +// Token: token, +// } +//} + +//func (c *TokenCredential) GetCredentialParams() map[string]string { +// return map[string]string{ +// "SecretId": c.SecretId, +// "Token": c.Token, +// } +//} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors/errors.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors/errors.go new file mode 100644 index 0000000000..27589e59a1 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors/errors.go @@ -0,0 +1,35 @@ +package errors + +import ( + "fmt" +) + +type TencentCloudSDKError struct { + Code string + Message string + RequestId string +} + +func (e *TencentCloudSDKError) Error() string { + return fmt.Sprintf("[TencentCloudSDKError] Code=%s, Message=%s, RequestId=%s", e.Code, e.Message, e.RequestId) +} + +func NewTencentCloudSDKError(code, message, requestId string) error { + return &TencentCloudSDKError{ + Code: code, + Message: message, + RequestId: requestId, + } +} + +func (e *TencentCloudSDKError) GetCode() string { + return e.Code +} + +func (e *TencentCloudSDKError) GetMessage() string { + return e.Message +} + +func (e *TencentCloudSDKError) GetRequestId() string { + return e.RequestId +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go new file mode 100644 index 0000000000..6a1ff56695 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go @@ -0,0 +1,233 @@ +package common + +import ( + "io" + //"log" + "math/rand" + "net/url" + "reflect" + "strconv" + "strings" + "time" +) + +const ( + POST = "POST" + GET = "GET" + + RootDomain = "tencentcloudapi.com" + Path = "/" +) + +type Request interface { + GetAction() string + GetBodyReader() io.Reader + GetDomain() string + GetHttpMethod() string + GetParams() map[string]string + GetPath() string + GetService() string + GetUrl() string + GetVersion() string + SetDomain(string) + SetHttpMethod(string) +} + +type BaseRequest struct { + httpMethod string + domain string + path string + params map[string]string + formParams map[string]string + + service string + version string + action string +} + +func (r *BaseRequest) GetAction() string { + return r.action +} + +func (r *BaseRequest) GetHttpMethod() string { + return r.httpMethod +} + +func (r *BaseRequest) GetParams() map[string]string { + return r.params +} + +func (r *BaseRequest) GetPath() string { + return r.path +} + +func (r *BaseRequest) GetDomain() string { + return r.domain +} + +func (r *BaseRequest) SetDomain(domain string) { + r.domain = domain +} + +func (r *BaseRequest) SetHttpMethod(method string) { + switch strings.ToUpper(method) { + case POST: + { + r.httpMethod = POST + } + case GET: + { + r.httpMethod = GET + } + default: + { + r.httpMethod = GET + } + } +} + +func (r *BaseRequest) GetService() string { + return r.service +} + +func (r *BaseRequest) GetUrl() string { + if r.httpMethod == GET { + return "https://" + r.domain + r.path + "?" + GetUrlQueriesEncoded(r.params) + } else if r.httpMethod == POST { + return "https://" + r.domain + r.path + } else { + return "" + } +} + +func (r *BaseRequest) GetVersion() string { + return r.version +} + +func GetUrlQueriesEncoded(params map[string]string) string { + values := url.Values{} + for key, value := range params { + if value != "" { + values.Add(key, value) + } + } + return values.Encode() +} + +func (r *BaseRequest) GetBodyReader() io.Reader { + if r.httpMethod == POST { + s := GetUrlQueriesEncoded(r.params) + return strings.NewReader(s) + } else { + return strings.NewReader("") + } +} + +func (r *BaseRequest) Init() *BaseRequest { + r.domain = "" + r.path = Path + r.params = make(map[string]string) + r.formParams = make(map[string]string) + return r +} + +func (r *BaseRequest) WithApiInfo(service, version, action string) *BaseRequest { + r.service = service + r.version = version + r.action = action + return r +} + +func GetServiceDomain(service string) (domain string) { + domain = service + "." + RootDomain + return +} + +func CompleteCommonParams(request Request, region string) { + params := request.GetParams() + params["Region"] = region + if request.GetVersion() != "" { + params["Version"] = request.GetVersion() + } + params["Action"] = request.GetAction() + params["Timestamp"] = strconv.FormatInt(time.Now().Unix(), 10) + params["Nonce"] = strconv.Itoa(rand.Int()) + params["RequestClient"] = "SDK_GO_3.0.83" +} + +func ConstructParams(req Request) (err error) { + value := reflect.ValueOf(req).Elem() + err = flatStructure(value, req, "") + //log.Printf("[DEBUG] params=%s", req.GetParams()) + return +} + +func flatStructure(value reflect.Value, request Request, prefix string) (err error) { + //log.Printf("[DEBUG] reflect value: %v", value.Type()) + valueType := value.Type() + for i := 0; i < valueType.NumField(); i++ { + tag := valueType.Field(i).Tag + nameTag, hasNameTag := tag.Lookup("name") + if !hasNameTag { + continue + } + field := value.Field(i) + kind := field.Kind() + if kind == reflect.Ptr && field.IsNil() { + continue + } + if kind == reflect.Ptr { + field = field.Elem() + kind = field.Kind() + } + key := prefix + nameTag + if kind == reflect.String { + s := field.String() + if s != "" { + request.GetParams()[key] = s + } + } else if kind == reflect.Bool { + request.GetParams()[key] = strconv.FormatBool(field.Bool()) + } else if kind == reflect.Int || kind == reflect.Int64 { + request.GetParams()[key] = strconv.FormatInt(field.Int(), 10) + } else if kind == reflect.Uint || kind == reflect.Uint64 { + request.GetParams()[key] = strconv.FormatUint(field.Uint(), 10) + } else if kind == reflect.Float64 { + request.GetParams()[key] = strconv.FormatFloat(field.Float(), 'f', -1, 64) + } else if kind == reflect.Slice { + list := value.Field(i) + for j := 0; j < list.Len(); j++ { + vj := list.Index(j) + key := prefix + nameTag + "." + strconv.Itoa(j) + kind = vj.Kind() + if kind == reflect.Ptr && vj.IsNil() { + continue + } + if kind == reflect.Ptr { + vj = vj.Elem() + kind = vj.Kind() + } + if kind == reflect.String { + request.GetParams()[key] = vj.String() + } else if kind == reflect.Bool { + request.GetParams()[key] = strconv.FormatBool(vj.Bool()) + } else if kind == reflect.Int || kind == reflect.Int64 { + request.GetParams()[key] = strconv.FormatInt(vj.Int(), 10) + } else if kind == reflect.Uint || kind == reflect.Uint64 { + request.GetParams()[key] = strconv.FormatUint(vj.Uint(), 10) + } else if kind == reflect.Float64 { + request.GetParams()[key] = strconv.FormatFloat(vj.Float(), 'f', -1, 64) + } else { + if err = flatStructure(vj, request, key+"."); err != nil { + return + } + } + } + } else { + if err = flatStructure(reflect.ValueOf(field.Interface()), request, prefix+nameTag+"."); err != nil { + return + } + } + } + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/response.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/response.go new file mode 100644 index 0000000000..288f21bdf6 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/response.go @@ -0,0 +1,81 @@ +package common + +import ( + "encoding/json" + "fmt" + "io/ioutil" + //"log" + "net/http" + + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" +) + +type Response interface { + ParseErrorFromHTTPResponse(body []byte) error +} + +type BaseResponse struct { +} + +type ErrorResponse struct { + Response struct { + Error struct { + Code string `json:"Code"` + Message string `json:"Message"` + } `json:"Error" omitempty` + RequestId string `json:"RequestId"` + } `json:"Response"` +} + +type DeprecatedAPIErrorResponse struct { + Code int `json:"code"` + Message string `json:"message"` + CodeDesc string `json:"codeDesc"` +} + +func (r *BaseResponse) ParseErrorFromHTTPResponse(body []byte) (err error) { + resp := &ErrorResponse{} + err = json.Unmarshal(body, resp) + if err != nil { + msg := fmt.Sprintf("Fail to parse json content: %s, because: %s", body, err) + return errors.NewTencentCloudSDKError("ClientError.ParseJsonError", msg, "") + } + if resp.Response.Error.Code != "" { + return errors.NewTencentCloudSDKError(resp.Response.Error.Code, resp.Response.Error.Message, resp.Response.RequestId) + } + + deprecated := &DeprecatedAPIErrorResponse{} + err = json.Unmarshal(body, deprecated) + if err != nil { + msg := fmt.Sprintf("Fail to parse json content: %s, because: %s", body, err) + return errors.NewTencentCloudSDKError("ClientError.ParseJsonError", msg, "") + } + if deprecated.Code != 0 { + return errors.NewTencentCloudSDKError(deprecated.CodeDesc, deprecated.Message, "") + } + return nil +} + +func ParseFromHttpResponse(hr *http.Response, response Response) (err error) { + defer hr.Body.Close() + body, err := ioutil.ReadAll(hr.Body) + if err != nil { + msg := fmt.Sprintf("Fail to read response body because %s", err) + return errors.NewTencentCloudSDKError("ClientError.IOError", msg, "") + } + if hr.StatusCode != 200 { + msg := fmt.Sprintf("Request fail with http status code: %s, with body: %s", hr.Status, body) + return errors.NewTencentCloudSDKError("ClientError.HttpStatusCodeError", msg, "") + } + //log.Printf("[DEBUG] Response Body=%s", body) + err = response.ParseErrorFromHTTPResponse(body) + if err != nil { + return + } + err = json.Unmarshal(body, &response) + if err != nil { + msg := fmt.Sprintf("Fail to parse json content: %s, because: %s", body, err) + return errors.NewTencentCloudSDKError("ClientError.ParseJsonError", msg, "") + } + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/client_profile.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/client_profile.go new file mode 100644 index 0000000000..21069ff99d --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/client_profile.go @@ -0,0 +1,21 @@ +package profile + +type ClientProfile struct { + HttpProfile *HttpProfile + // Valid choices: HmacSHA1, HmacSHA256, TC3-HMAC-SHA256. + // Default value is TC3-HMAC-SHA256. + SignMethod string + UnsignedPayload bool + // Valid choices: zh-CN, en-US. + // Default value is zh-CN. + Language string +} + +func NewClientProfile() *ClientProfile { + return &ClientProfile{ + HttpProfile: NewHttpProfile(), + SignMethod: "TC3-HMAC-SHA256", + UnsignedPayload: false, + Language: "zh-CN", + } +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/http_profile.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/http_profile.go new file mode 100644 index 0000000000..8d4bf8f57b --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile/http_profile.go @@ -0,0 +1,17 @@ +package profile + +type HttpProfile struct { + ReqMethod string + ReqTimeout int + Endpoint string + Protocol string +} + +func NewHttpProfile() *HttpProfile { + return &HttpProfile{ + ReqMethod: "POST", + ReqTimeout: 60, + Endpoint: "", + Protocol: "HTTPS", + } +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go new file mode 100644 index 0000000000..0aa7b73557 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/sign.go @@ -0,0 +1,94 @@ +package common + +import ( + "bytes" + "crypto/hmac" + "crypto/sha1" + "crypto/sha256" + "encoding/base64" + "encoding/hex" + "sort" + + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" +) + +const ( + SHA256 = "HmacSHA256" + SHA1 = "HmacSHA1" +) + +func Sign(s, secretKey, method string) string { + hashed := hmac.New(sha1.New, []byte(secretKey)) + if method == SHA256 { + hashed = hmac.New(sha256.New, []byte(secretKey)) + } + hashed.Write([]byte(s)) + + return base64.StdEncoding.EncodeToString(hashed.Sum(nil)) +} + +func sha256hex(s string) string { + b := sha256.Sum256([]byte(s)) + return hex.EncodeToString(b[:]) +} + +func hmacsha256(s, key string) string { + hashed := hmac.New(sha256.New, []byte(key)) + hashed.Write([]byte(s)) + return string(hashed.Sum(nil)) +} + +func signRequest(request tchttp.Request, credential *Credential, method string) (err error) { + if method != SHA256 { + method = SHA1 + } + checkAuthParams(request, credential, method) + s := getStringToSign(request) + signature := Sign(s, credential.SecretKey, method) + request.GetParams()["Signature"] = signature + return +} + +func checkAuthParams(request tchttp.Request, credential *Credential, method string) { + params := request.GetParams() + credentialParams := credential.GetCredentialParams() + for key, value := range credentialParams { + params[key] = value + } + params["SignatureMethod"] = method + delete(params, "Signature") +} + +func getStringToSign(request tchttp.Request) string { + method := request.GetHttpMethod() + domain := request.GetDomain() + path := request.GetPath() + + var buf bytes.Buffer + buf.WriteString(method) + buf.WriteString(domain) + buf.WriteString(path) + buf.WriteString("?") + + params := request.GetParams() + // sort params + keys := make([]string, 0, len(params)) + for k, _ := range params { + keys = append(keys, k) + } + sort.Strings(keys) + + for i := range keys { + k := keys[i] + // TODO: check if server side allows empty value in url. + if params[k] == "" { + continue + } + buf.WriteString(k) + buf.WriteString("=") + buf.WriteString(params[k]) + buf.WriteString("&") + } + buf.Truncate(buf.Len() - 1) + return buf.String() +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/types.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/types.go new file mode 100644 index 0000000000..ec2c786dbf --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/types.go @@ -0,0 +1,47 @@ +package common + +func IntPtr(v int) *int { + return &v +} + +func Int64Ptr(v int64) *int64 { + return &v +} + +func UintPtr(v uint) *uint { + return &v +} + +func Uint64Ptr(v uint64) *uint64 { + return &v +} + +func Float64Ptr(v float64) *float64 { + return &v +} + +func StringPtr(v string) *string { + return &v +} + +func StringValues(ptrs []*string) []string { + values := make([]string, len(ptrs)) + for i := 0; i < len(ptrs); i++ { + if ptrs[i] != nil { + values[i] = *ptrs[i] + } + } + return values +} + +func StringPtrs(vals []string) []*string { + ptrs := make([]*string, len(vals)) + for i := 0; i < len(vals); i++ { + ptrs[i] = &vals[i] + } + return ptrs +} + +func BoolPtr(v bool) *bool { + return &v +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/client.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/client.go new file mode 100644 index 0000000000..da06118ed8 --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/client.go @@ -0,0 +1,1758 @@ +// Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v20170312 + +import ( + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" +) + +const APIVersion = "2017-03-12" + +type Client struct { + common.Client +} + +// Deprecated +func NewClientWithSecretId(secretId, secretKey, region string) (client *Client, err error) { + cpf := profile.NewClientProfile() + client = &Client{} + client.Init(region).WithSecretId(secretId, secretKey).WithProfile(cpf) + return +} + +func NewClient(credential *common.Credential, region string, clientProfile *profile.ClientProfile) (client *Client, err error) { + client = &Client{} + client.Init(region). + WithCredential(credential). + WithProfile(clientProfile) + return +} + + +func NewAllocateHostsRequest() (request *AllocateHostsRequest) { + request = &AllocateHostsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "AllocateHosts") + return +} + +func NewAllocateHostsResponse() (response *AllocateHostsResponse) { + response = &AllocateHostsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (AllocateHosts) 用于创建一个或多个指定配置的CDH实例。 +// * 当HostChargeType为PREPAID时,必须指定HostChargePrepaid参数。 +func (c *Client) AllocateHosts(request *AllocateHostsRequest) (response *AllocateHostsResponse, err error) { + if request == nil { + request = NewAllocateHostsRequest() + } + response = NewAllocateHostsResponse() + err = c.Send(request, response) + return +} + +func NewAssociateInstancesKeyPairsRequest() (request *AssociateInstancesKeyPairsRequest) { + request = &AssociateInstancesKeyPairsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "AssociateInstancesKeyPairs") + return +} + +func NewAssociateInstancesKeyPairsResponse() (response *AssociateInstancesKeyPairsResponse) { + response = &AssociateInstancesKeyPairsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (AssociateInstancesKeyPairs) 用于将密钥绑定到实例上。 +// +// * 将密钥的公钥写入到实例的`SSH`配置当中,用户就可以通过该密钥的私钥来登录实例。 +// * 如果实例原来绑定过密钥,那么原来的密钥将失效。 +// * 如果实例原来是通过密码登录,绑定密钥后无法使用密码登录。 +// * 支持批量操作。每次请求批量实例的上限为100。如果批量实例存在不允许操作的实例,操作会以特定错误码返回。 +func (c *Client) AssociateInstancesKeyPairs(request *AssociateInstancesKeyPairsRequest) (response *AssociateInstancesKeyPairsResponse, err error) { + if request == nil { + request = NewAssociateInstancesKeyPairsRequest() + } + response = NewAssociateInstancesKeyPairsResponse() + err = c.Send(request, response) + return +} + +func NewAssociateSecurityGroupsRequest() (request *AssociateSecurityGroupsRequest) { + request = &AssociateSecurityGroupsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "AssociateSecurityGroups") + return +} + +func NewAssociateSecurityGroupsResponse() (response *AssociateSecurityGroupsResponse) { + response = &AssociateSecurityGroupsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (AssociateSecurityGroups) 用于绑定安全组到指定实例。 +func (c *Client) AssociateSecurityGroups(request *AssociateSecurityGroupsRequest) (response *AssociateSecurityGroupsResponse, err error) { + if request == nil { + request = NewAssociateSecurityGroupsRequest() + } + response = NewAssociateSecurityGroupsResponse() + err = c.Send(request, response) + return +} + +func NewCreateDisasterRecoverGroupRequest() (request *CreateDisasterRecoverGroupRequest) { + request = &CreateDisasterRecoverGroupRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "CreateDisasterRecoverGroup") + return +} + +func NewCreateDisasterRecoverGroupResponse() (response *CreateDisasterRecoverGroupResponse) { + response = &CreateDisasterRecoverGroupResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (CreateDisasterRecoverGroup)用于创建[分散置放群组](https://cloud.tencent.com/document/product/213/15486)。创建好的置放群组,可在[创建实例](https://cloud.tencent.com/document/api/213/15730)时指定。 +func (c *Client) CreateDisasterRecoverGroup(request *CreateDisasterRecoverGroupRequest) (response *CreateDisasterRecoverGroupResponse, err error) { + if request == nil { + request = NewCreateDisasterRecoverGroupRequest() + } + response = NewCreateDisasterRecoverGroupResponse() + err = c.Send(request, response) + return +} + +func NewCreateImageRequest() (request *CreateImageRequest) { + request = &CreateImageRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "CreateImage") + return +} + +func NewCreateImageResponse() (response *CreateImageResponse) { + response = &CreateImageResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(CreateImage)用于将实例的系统盘制作为新镜像,创建后的镜像可以用于创建实例。 +func (c *Client) CreateImage(request *CreateImageRequest) (response *CreateImageResponse, err error) { + if request == nil { + request = NewCreateImageRequest() + } + response = NewCreateImageResponse() + err = c.Send(request, response) + return +} + +func NewCreateKeyPairRequest() (request *CreateKeyPairRequest) { + request = &CreateKeyPairRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "CreateKeyPair") + return +} + +func NewCreateKeyPairResponse() (response *CreateKeyPairResponse) { + response = &CreateKeyPairResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (CreateKeyPair) 用于创建一个 `OpenSSH RSA` 密钥对,可以用于登录 `Linux` 实例。 +// +// * 开发者只需指定密钥对名称,即可由系统自动创建密钥对,并返回所生成的密钥对的 `ID` 及其公钥、私钥的内容。 +// * 密钥对名称不能和已经存在的密钥对的名称重复。 +// * 私钥的内容可以保存到文件中作为 `SSH` 的一种认证方式。 +// * 腾讯云不会保存用户的私钥,请妥善保管。 +func (c *Client) CreateKeyPair(request *CreateKeyPairRequest) (response *CreateKeyPairResponse, err error) { + if request == nil { + request = NewCreateKeyPairRequest() + } + response = NewCreateKeyPairResponse() + err = c.Send(request, response) + return +} + +func NewDeleteDisasterRecoverGroupsRequest() (request *DeleteDisasterRecoverGroupsRequest) { + request = &DeleteDisasterRecoverGroupsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DeleteDisasterRecoverGroups") + return +} + +func NewDeleteDisasterRecoverGroupsResponse() (response *DeleteDisasterRecoverGroupsResponse) { + response = &DeleteDisasterRecoverGroupsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DeleteDisasterRecoverGroups)用于删除[分散置放群组](https://cloud.tencent.com/document/product/213/15486)。只有空的置放群组才能被删除,非空的群组需要先销毁组内所有云主机,才能执行删除操作,不然会产生删除置放群组失败的错误。 +func (c *Client) DeleteDisasterRecoverGroups(request *DeleteDisasterRecoverGroupsRequest) (response *DeleteDisasterRecoverGroupsResponse, err error) { + if request == nil { + request = NewDeleteDisasterRecoverGroupsRequest() + } + response = NewDeleteDisasterRecoverGroupsResponse() + err = c.Send(request, response) + return +} + +func NewDeleteImagesRequest() (request *DeleteImagesRequest) { + request = &DeleteImagesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DeleteImages") + return +} + +func NewDeleteImagesResponse() (response *DeleteImagesResponse) { + response = &DeleteImagesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DeleteImages)用于删除一个或多个镜像。 +// +// * 当[镜像状态](https://cloud.tencent.com/document/api/213/9452#image_state)为`创建中`和`使用中`时, 不允许删除。镜像状态可以通过[DescribeImages](https://cloud.tencent.com/document/api/213/9418)获取。 +// * 每个地域最多只支持创建10个自定义镜像,删除镜像可以释放账户的配额。 +// * 当镜像正在被其它账户分享时,不允许删除。 +func (c *Client) DeleteImages(request *DeleteImagesRequest) (response *DeleteImagesResponse, err error) { + if request == nil { + request = NewDeleteImagesRequest() + } + response = NewDeleteImagesResponse() + err = c.Send(request, response) + return +} + +func NewDeleteKeyPairsRequest() (request *DeleteKeyPairsRequest) { + request = &DeleteKeyPairsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DeleteKeyPairs") + return +} + +func NewDeleteKeyPairsResponse() (response *DeleteKeyPairsResponse) { + response = &DeleteKeyPairsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DeleteKeyPairs) 用于删除已在腾讯云托管的密钥对。 +// +// * 可以同时删除多个密钥对。 +// * 不能删除已被实例或镜像引用的密钥对,所以需要独立判断是否所有密钥对都被成功删除。 +func (c *Client) DeleteKeyPairs(request *DeleteKeyPairsRequest) (response *DeleteKeyPairsResponse, err error) { + if request == nil { + request = NewDeleteKeyPairsRequest() + } + response = NewDeleteKeyPairsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDisasterRecoverGroupQuotaRequest() (request *DescribeDisasterRecoverGroupQuotaRequest) { + request = &DescribeDisasterRecoverGroupQuotaRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeDisasterRecoverGroupQuota") + return +} + +func NewDescribeDisasterRecoverGroupQuotaResponse() (response *DescribeDisasterRecoverGroupQuotaResponse) { + response = &DescribeDisasterRecoverGroupQuotaResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeDisasterRecoverGroupQuota)用于查询[分散置放群组](https://cloud.tencent.com/document/product/213/15486)配额。 +func (c *Client) DescribeDisasterRecoverGroupQuota(request *DescribeDisasterRecoverGroupQuotaRequest) (response *DescribeDisasterRecoverGroupQuotaResponse, err error) { + if request == nil { + request = NewDescribeDisasterRecoverGroupQuotaRequest() + } + response = NewDescribeDisasterRecoverGroupQuotaResponse() + err = c.Send(request, response) + return +} + +func NewDescribeDisasterRecoverGroupsRequest() (request *DescribeDisasterRecoverGroupsRequest) { + request = &DescribeDisasterRecoverGroupsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeDisasterRecoverGroups") + return +} + +func NewDescribeDisasterRecoverGroupsResponse() (response *DescribeDisasterRecoverGroupsResponse) { + response = &DescribeDisasterRecoverGroupsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeDisasterRecoverGroups)用于查询[分散置放群组](https://cloud.tencent.com/document/product/213/15486)信息。 +func (c *Client) DescribeDisasterRecoverGroups(request *DescribeDisasterRecoverGroupsRequest) (response *DescribeDisasterRecoverGroupsResponse, err error) { + if request == nil { + request = NewDescribeDisasterRecoverGroupsRequest() + } + response = NewDescribeDisasterRecoverGroupsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeHostsRequest() (request *DescribeHostsRequest) { + request = &DescribeHostsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeHosts") + return +} + +func NewDescribeHostsResponse() (response *DescribeHostsResponse) { + response = &DescribeHostsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeHosts) 用于获取一个或多个CDH实例的详细信息。 +func (c *Client) DescribeHosts(request *DescribeHostsRequest) (response *DescribeHostsResponse, err error) { + if request == nil { + request = NewDescribeHostsRequest() + } + response = NewDescribeHostsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeImageQuotaRequest() (request *DescribeImageQuotaRequest) { + request = &DescribeImageQuotaRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeImageQuota") + return +} + +func NewDescribeImageQuotaResponse() (response *DescribeImageQuotaResponse) { + response = &DescribeImageQuotaResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeImageQuota)用于查询用户帐号的镜像配额。 +func (c *Client) DescribeImageQuota(request *DescribeImageQuotaRequest) (response *DescribeImageQuotaResponse, err error) { + if request == nil { + request = NewDescribeImageQuotaRequest() + } + response = NewDescribeImageQuotaResponse() + err = c.Send(request, response) + return +} + +func NewDescribeImageSharePermissionRequest() (request *DescribeImageSharePermissionRequest) { + request = &DescribeImageSharePermissionRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeImageSharePermission") + return +} + +func NewDescribeImageSharePermissionResponse() (response *DescribeImageSharePermissionResponse) { + response = &DescribeImageSharePermissionResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeImageSharePermission)用于查询镜像分享信息。 +func (c *Client) DescribeImageSharePermission(request *DescribeImageSharePermissionRequest) (response *DescribeImageSharePermissionResponse, err error) { + if request == nil { + request = NewDescribeImageSharePermissionRequest() + } + response = NewDescribeImageSharePermissionResponse() + err = c.Send(request, response) + return +} + +func NewDescribeImagesRequest() (request *DescribeImagesRequest) { + request = &DescribeImagesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeImages") + return +} + +func NewDescribeImagesResponse() (response *DescribeImagesResponse) { + response = &DescribeImagesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeImages) 用于查看镜像列表。 +// +// * 可以通过指定镜像ID来查询指定镜像的详细信息,或通过设定过滤器来查询满足过滤条件的镜像的详细信息。 +// * 指定偏移(Offset)和限制(Limit)来选择结果中的一部分,默认返回满足条件的前20个镜像信息。 +func (c *Client) DescribeImages(request *DescribeImagesRequest) (response *DescribeImagesResponse, err error) { + if request == nil { + request = NewDescribeImagesRequest() + } + response = NewDescribeImagesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeImportImageOsRequest() (request *DescribeImportImageOsRequest) { + request = &DescribeImportImageOsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeImportImageOs") + return +} + +func NewDescribeImportImageOsResponse() (response *DescribeImportImageOsResponse) { + response = &DescribeImportImageOsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 查看可以导入的镜像操作系统信息。 +func (c *Client) DescribeImportImageOs(request *DescribeImportImageOsRequest) (response *DescribeImportImageOsResponse, err error) { + if request == nil { + request = NewDescribeImportImageOsRequest() + } + response = NewDescribeImportImageOsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstanceFamilyConfigsRequest() (request *DescribeInstanceFamilyConfigsRequest) { + request = &DescribeInstanceFamilyConfigsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstanceFamilyConfigs") + return +} + +func NewDescribeInstanceFamilyConfigsResponse() (response *DescribeInstanceFamilyConfigsResponse) { + response = &DescribeInstanceFamilyConfigsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeInstanceFamilyConfigs)查询当前用户和地域所支持的机型族列表信息。 +func (c *Client) DescribeInstanceFamilyConfigs(request *DescribeInstanceFamilyConfigsRequest) (response *DescribeInstanceFamilyConfigsResponse, err error) { + if request == nil { + request = NewDescribeInstanceFamilyConfigsRequest() + } + response = NewDescribeInstanceFamilyConfigsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstanceInternetBandwidthConfigsRequest() (request *DescribeInstanceInternetBandwidthConfigsRequest) { + request = &DescribeInstanceInternetBandwidthConfigsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstanceInternetBandwidthConfigs") + return +} + +func NewDescribeInstanceInternetBandwidthConfigsResponse() (response *DescribeInstanceInternetBandwidthConfigsResponse) { + response = &DescribeInstanceInternetBandwidthConfigsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeInstanceInternetBandwidthConfigs) 用于查询实例带宽配置。 +// +// * 只支持查询`BANDWIDTH_PREPAID`计费模式的带宽配置。 +// * 接口返回实例的所有带宽配置信息(包含历史的带宽配置信息)。 +func (c *Client) DescribeInstanceInternetBandwidthConfigs(request *DescribeInstanceInternetBandwidthConfigsRequest) (response *DescribeInstanceInternetBandwidthConfigsResponse, err error) { + if request == nil { + request = NewDescribeInstanceInternetBandwidthConfigsRequest() + } + response = NewDescribeInstanceInternetBandwidthConfigsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstanceTypeConfigsRequest() (request *DescribeInstanceTypeConfigsRequest) { + request = &DescribeInstanceTypeConfigsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstanceTypeConfigs") + return +} + +func NewDescribeInstanceTypeConfigsResponse() (response *DescribeInstanceTypeConfigsResponse) { + response = &DescribeInstanceTypeConfigsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeInstanceTypeConfigs) 用于查询实例机型配置。 +// +// * 可以根据`zone`、`instance-family`来查询实例机型配置。过滤条件详见过滤器`Filter`。 +// * 如果参数为空,返回指定地域的所有实例机型配置。 +func (c *Client) DescribeInstanceTypeConfigs(request *DescribeInstanceTypeConfigsRequest) (response *DescribeInstanceTypeConfigsResponse, err error) { + if request == nil { + request = NewDescribeInstanceTypeConfigsRequest() + } + response = NewDescribeInstanceTypeConfigsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstanceVncUrlRequest() (request *DescribeInstanceVncUrlRequest) { + request = &DescribeInstanceVncUrlRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstanceVncUrl") + return +} + +func NewDescribeInstanceVncUrlResponse() (response *DescribeInstanceVncUrlResponse) { + response = &DescribeInstanceVncUrlResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 ( DescribeInstanceVncUrl ) 用于查询实例管理终端地址。 +// +// * 处于 `STOPPED` 状态的机器无法使用此功能。 +// * 管理终端地址的有效期为 15 秒,调用接口成功后如果 15 秒内不使用该链接进行访问,管理终端地址自动失效,您需要重新查询。 +// * 管理终端地址一旦被访问,将自动失效,您需要重新查询。 +// * 如果连接断开,每分钟内重新连接的次数不能超过 30 次。 +// * 获取到 `InstanceVncUrl` 后,您需要在在链接 末尾加上参数 `InstanceVncUrl=xxxx` 。 +// - 参数 `InstanceVncUrl` :调用接口成功后会返回的 `InstanceVncUrl` 的值。 +// +// 最后组成的 URL 格式如下: +// +// ``` +// https://img.qcloud.com/qcloud/app/active_vnc/index.html?InstanceVncUrl=wss%3A%2F%2Fbjvnc.qcloud.com%3A26789%2Fvnc%3Fs%3DaHpjWnRVMFNhYmxKdDM5MjRHNlVTSVQwajNUSW0wb2tBbmFtREFCTmFrcy8vUUNPMG0wSHZNOUUxRm5PMmUzWmFDcWlOdDJIbUJxSTZDL0RXcHZxYnZZMmRkWWZWcEZia2lyb09XMzdKNmM9 +// ``` +func (c *Client) DescribeInstanceVncUrl(request *DescribeInstanceVncUrlRequest) (response *DescribeInstanceVncUrlResponse, err error) { + if request == nil { + request = NewDescribeInstanceVncUrlRequest() + } + response = NewDescribeInstanceVncUrlResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstancesRequest() (request *DescribeInstancesRequest) { + request = &DescribeInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstances") + return +} + +func NewDescribeInstancesResponse() (response *DescribeInstancesResponse) { + response = &DescribeInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeInstances) 用于查询一个或多个实例的详细信息。 +// +// * 可以根据实例`ID`、实例名称或者实例计费模式等信息来查询实例的详细信息。过滤信息详细请见过滤器`Filter`。 +// * 如果参数为空,返回当前用户一定数量(`Limit`所指定的数量,默认为20)的实例。 +func (c *Client) DescribeInstances(request *DescribeInstancesRequest) (response *DescribeInstancesResponse, err error) { + if request == nil { + request = NewDescribeInstancesRequest() + } + response = NewDescribeInstancesResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstancesOperationLimitRequest() (request *DescribeInstancesOperationLimitRequest) { + request = &DescribeInstancesOperationLimitRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstancesOperationLimit") + return +} + +func NewDescribeInstancesOperationLimitResponse() (response *DescribeInstancesOperationLimitResponse) { + response = &DescribeInstancesOperationLimitResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeInstancesOperationLimit)用于查询实例操作限制。 +// +// * 目前支持调整配置操作限制次数查询。 +func (c *Client) DescribeInstancesOperationLimit(request *DescribeInstancesOperationLimitRequest) (response *DescribeInstancesOperationLimitResponse, err error) { + if request == nil { + request = NewDescribeInstancesOperationLimitRequest() + } + response = NewDescribeInstancesOperationLimitResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInstancesStatusRequest() (request *DescribeInstancesStatusRequest) { + request = &DescribeInstancesStatusRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInstancesStatus") + return +} + +func NewDescribeInstancesStatusResponse() (response *DescribeInstancesStatusResponse) { + response = &DescribeInstancesStatusResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeInstancesStatus) 用于查询一个或多个实例的状态。 +// +// * 可以根据实例`ID`来查询实例的状态。 +// * 如果参数为空,返回当前用户一定数量(Limit所指定的数量,默认为20)的实例状态。 +func (c *Client) DescribeInstancesStatus(request *DescribeInstancesStatusRequest) (response *DescribeInstancesStatusResponse, err error) { + if request == nil { + request = NewDescribeInstancesStatusRequest() + } + response = NewDescribeInstancesStatusResponse() + err = c.Send(request, response) + return +} + +func NewDescribeInternetChargeTypeConfigsRequest() (request *DescribeInternetChargeTypeConfigsRequest) { + request = &DescribeInternetChargeTypeConfigsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeInternetChargeTypeConfigs") + return +} + +func NewDescribeInternetChargeTypeConfigsResponse() (response *DescribeInternetChargeTypeConfigsResponse) { + response = &DescribeInternetChargeTypeConfigsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeInternetChargeTypeConfigs)用于查询网络的计费类型。 +func (c *Client) DescribeInternetChargeTypeConfigs(request *DescribeInternetChargeTypeConfigsRequest) (response *DescribeInternetChargeTypeConfigsResponse, err error) { + if request == nil { + request = NewDescribeInternetChargeTypeConfigsRequest() + } + response = NewDescribeInternetChargeTypeConfigsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeKeyPairsRequest() (request *DescribeKeyPairsRequest) { + request = &DescribeKeyPairsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeKeyPairs") + return +} + +func NewDescribeKeyPairsResponse() (response *DescribeKeyPairsResponse) { + response = &DescribeKeyPairsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DescribeKeyPairs) 用于查询密钥对信息。 +// +// * 密钥对是通过一种算法生成的一对密钥,在生成的密钥对中,一个向外界公开,称为公钥;另一个用户自己保留,称为私钥。密钥对的公钥内容可以通过这个接口查询,但私钥内容系统不保留。 +func (c *Client) DescribeKeyPairs(request *DescribeKeyPairsRequest) (response *DescribeKeyPairsResponse, err error) { + if request == nil { + request = NewDescribeKeyPairsRequest() + } + response = NewDescribeKeyPairsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeRegionsRequest() (request *DescribeRegionsRequest) { + request = &DescribeRegionsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeRegions") + return +} + +func NewDescribeRegionsResponse() (response *DescribeRegionsResponse) { + response = &DescribeRegionsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeRegions)用于查询地域信息。 +func (c *Client) DescribeRegions(request *DescribeRegionsRequest) (response *DescribeRegionsResponse, err error) { + if request == nil { + request = NewDescribeRegionsRequest() + } + response = NewDescribeRegionsResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZoneInstanceConfigInfosRequest() (request *DescribeZoneInstanceConfigInfosRequest) { + request = &DescribeZoneInstanceConfigInfosRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeZoneInstanceConfigInfos") + return +} + +func NewDescribeZoneInstanceConfigInfosResponse() (response *DescribeZoneInstanceConfigInfosResponse) { + response = &DescribeZoneInstanceConfigInfosResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeZoneInstanceConfigInfos) 获取可用区的机型信息。 +func (c *Client) DescribeZoneInstanceConfigInfos(request *DescribeZoneInstanceConfigInfosRequest) (response *DescribeZoneInstanceConfigInfosResponse, err error) { + if request == nil { + request = NewDescribeZoneInstanceConfigInfosRequest() + } + response = NewDescribeZoneInstanceConfigInfosResponse() + err = c.Send(request, response) + return +} + +func NewDescribeZonesRequest() (request *DescribeZonesRequest) { + request = &DescribeZonesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DescribeZones") + return +} + +func NewDescribeZonesResponse() (response *DescribeZonesResponse) { + response = &DescribeZonesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(DescribeZones)用于查询可用区信息。 +func (c *Client) DescribeZones(request *DescribeZonesRequest) (response *DescribeZonesResponse, err error) { + if request == nil { + request = NewDescribeZonesRequest() + } + response = NewDescribeZonesResponse() + err = c.Send(request, response) + return +} + +func NewDisassociateInstancesKeyPairsRequest() (request *DisassociateInstancesKeyPairsRequest) { + request = &DisassociateInstancesKeyPairsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DisassociateInstancesKeyPairs") + return +} + +func NewDisassociateInstancesKeyPairsResponse() (response *DisassociateInstancesKeyPairsResponse) { + response = &DisassociateInstancesKeyPairsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DisassociateInstancesKeyPairs) 用于解除实例的密钥绑定关系。 +// +// * 只支持[`STOPPED`](https://cloud.tencent.com/document/api/213/9452#INSTANCE_STATE)状态的`Linux`操作系统的实例。 +// * 解绑密钥后,实例可以通过原来设置的密码登录。 +// * 如果原来没有设置密码,解绑后将无法使用 `SSH` 登录。可以调用 [ResetInstancesPassword](https://cloud.tencent.com/document/api/213/15736) 接口来设置登录密码。 +// * 支持批量操作。每次请求批量实例的上限为100。如果批量实例存在不允许操作的实例,操作会以特定错误码返回。 +func (c *Client) DisassociateInstancesKeyPairs(request *DisassociateInstancesKeyPairsRequest) (response *DisassociateInstancesKeyPairsResponse, err error) { + if request == nil { + request = NewDisassociateInstancesKeyPairsRequest() + } + response = NewDisassociateInstancesKeyPairsResponse() + err = c.Send(request, response) + return +} + +func NewDisassociateSecurityGroupsRequest() (request *DisassociateSecurityGroupsRequest) { + request = &DisassociateSecurityGroupsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "DisassociateSecurityGroups") + return +} + +func NewDisassociateSecurityGroupsResponse() (response *DisassociateSecurityGroupsResponse) { + response = &DisassociateSecurityGroupsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (DisassociateSecurityGroups) 用于解绑实例的指定安全组。 +func (c *Client) DisassociateSecurityGroups(request *DisassociateSecurityGroupsRequest) (response *DisassociateSecurityGroupsResponse, err error) { + if request == nil { + request = NewDisassociateSecurityGroupsRequest() + } + response = NewDisassociateSecurityGroupsResponse() + err = c.Send(request, response) + return +} + +func NewImportImageRequest() (request *ImportImageRequest) { + request = &ImportImageRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ImportImage") + return +} + +func NewImportImageResponse() (response *ImportImageResponse) { + response = &ImportImageResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(ImportImage)用于导入镜像,导入后的镜像可用于创建实例。 +func (c *Client) ImportImage(request *ImportImageRequest) (response *ImportImageResponse, err error) { + if request == nil { + request = NewImportImageRequest() + } + response = NewImportImageResponse() + err = c.Send(request, response) + return +} + +func NewImportKeyPairRequest() (request *ImportKeyPairRequest) { + request = &ImportKeyPairRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ImportKeyPair") + return +} + +func NewImportKeyPairResponse() (response *ImportKeyPairResponse) { + response = &ImportKeyPairResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ImportKeyPair) 用于导入密钥对。 +// +// * 本接口的功能是将密钥对导入到用户账户,并不会自动绑定到实例。如需绑定可以使用[AssociasteInstancesKeyPair](https://cloud.tencent.com/document/api/213/9404)接口。 +// * 需指定密钥对名称以及该密钥对的公钥文本。 +// * 如果用户只有私钥,可以通过 `SSL` 工具将私钥转换成公钥后再导入。 +func (c *Client) ImportKeyPair(request *ImportKeyPairRequest) (response *ImportKeyPairResponse, err error) { + if request == nil { + request = NewImportKeyPairRequest() + } + response = NewImportKeyPairResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceModifyInstancesChargeTypeRequest() (request *InquiryPriceModifyInstancesChargeTypeRequest) { + request = &InquiryPriceModifyInstancesChargeTypeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceModifyInstancesChargeType") + return +} + +func NewInquiryPriceModifyInstancesChargeTypeResponse() (response *InquiryPriceModifyInstancesChargeTypeResponse) { + response = &InquiryPriceModifyInstancesChargeTypeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceModifyInstancesChargeType) 用于切换实例的计费模式询价。 +// +// * 只支持从 `POSTPAID_BY_HOUR` 计费模式切换为`PREPAID`计费模式。 +// * 关机不收费的实例、`BC1`和`BS1`机型族的实例、设置定时销毁的实例不支持该操作。 +func (c *Client) InquiryPriceModifyInstancesChargeType(request *InquiryPriceModifyInstancesChargeTypeRequest) (response *InquiryPriceModifyInstancesChargeTypeResponse, err error) { + if request == nil { + request = NewInquiryPriceModifyInstancesChargeTypeRequest() + } + response = NewInquiryPriceModifyInstancesChargeTypeResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceRenewInstancesRequest() (request *InquiryPriceRenewInstancesRequest) { + request = &InquiryPriceRenewInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceRenewInstances") + return +} + +func NewInquiryPriceRenewInstancesResponse() (response *InquiryPriceRenewInstancesResponse) { + response = &InquiryPriceRenewInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceRenewInstances) 用于续费包年包月实例询价。 +// +// * 只支持查询包年包月实例的续费价格。 +func (c *Client) InquiryPriceRenewInstances(request *InquiryPriceRenewInstancesRequest) (response *InquiryPriceRenewInstancesResponse, err error) { + if request == nil { + request = NewInquiryPriceRenewInstancesRequest() + } + response = NewInquiryPriceRenewInstancesResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceResetInstanceRequest() (request *InquiryPriceResetInstanceRequest) { + request = &InquiryPriceResetInstanceRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceResetInstance") + return +} + +func NewInquiryPriceResetInstanceResponse() (response *InquiryPriceResetInstanceResponse) { + response = &InquiryPriceResetInstanceResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceResetInstance) 用于重装实例询价。* 如果指定了`ImageId`参数,则使用指定的镜像进行重装询价;否则按照当前实例使用的镜像进行重装询价。* 目前只支持[系统盘类型](/document/api/213/9452#block_device)是`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`类型的实例使用该接口实现`Linux`和`Windows`操作系统切换的重装询价。* 目前不支持海外地域的实例使用该接口实现`Linux`和`Windows`操作系统切换的重装询价。 +func (c *Client) InquiryPriceResetInstance(request *InquiryPriceResetInstanceRequest) (response *InquiryPriceResetInstanceResponse, err error) { + if request == nil { + request = NewInquiryPriceResetInstanceRequest() + } + response = NewInquiryPriceResetInstanceResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceResetInstancesInternetMaxBandwidthRequest() (request *InquiryPriceResetInstancesInternetMaxBandwidthRequest) { + request = &InquiryPriceResetInstancesInternetMaxBandwidthRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceResetInstancesInternetMaxBandwidth") + return +} + +func NewInquiryPriceResetInstancesInternetMaxBandwidthResponse() (response *InquiryPriceResetInstancesInternetMaxBandwidthResponse) { + response = &InquiryPriceResetInstancesInternetMaxBandwidthResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceResetInstancesInternetMaxBandwidth) 用于调整实例公网带宽上限询价。 +// +// * 不同机型带宽上限范围不一致,具体限制详见[购买网络带宽](https://cloud.tencent.com/document/product/213/509)。 +// * 对于`BANDWIDTH_PREPAID`计费方式的带宽,需要输入参数`StartTime`和`EndTime`,指定调整后的带宽的生效时间段。在这种场景下目前不支持调小带宽,会涉及扣费,请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +// * 对于 `TRAFFIC_POSTPAID_BY_HOUR`、 `BANDWIDTH_POSTPAID_BY_HOUR` 和 `BANDWIDTH_PACKAGE` 计费方式的带宽,使用该接口调整带宽上限是实时生效的,可以在带宽允许的范围内调大或者调小带宽,不支持输入参数 `StartTime` 和 `EndTime` 。 +// * 接口不支持调整`BANDWIDTH_POSTPAID_BY_MONTH`计费方式的带宽。 +// * 接口不支持批量调整 `BANDWIDTH_PREPAID` 和 `BANDWIDTH_POSTPAID_BY_HOUR` 计费方式的带宽。 +// * 接口不支持批量调整混合计费方式的带宽。例如不支持同时调整`TRAFFIC_POSTPAID_BY_HOUR`和`BANDWIDTH_PACKAGE`计费方式的带宽。 +func (c *Client) InquiryPriceResetInstancesInternetMaxBandwidth(request *InquiryPriceResetInstancesInternetMaxBandwidthRequest) (response *InquiryPriceResetInstancesInternetMaxBandwidthResponse, err error) { + if request == nil { + request = NewInquiryPriceResetInstancesInternetMaxBandwidthRequest() + } + response = NewInquiryPriceResetInstancesInternetMaxBandwidthResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceResetInstancesTypeRequest() (request *InquiryPriceResetInstancesTypeRequest) { + request = &InquiryPriceResetInstancesTypeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceResetInstancesType") + return +} + +func NewInquiryPriceResetInstancesTypeResponse() (response *InquiryPriceResetInstancesTypeResponse) { + response = &InquiryPriceResetInstancesTypeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceResetInstancesType) 用于调整实例的机型询价。 +// +// * 目前只支持[系统盘类型](https://cloud.tencent.com/document/api/213/9452#block_device)是`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`类型的实例使用该接口进行调整机型询价。 +// * 目前不支持[CDH](https://cloud.tencent.com/document/product/416)实例使用该接口调整机型询价。 +// * 对于包年包月实例,使用该接口会涉及扣费,请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +func (c *Client) InquiryPriceResetInstancesType(request *InquiryPriceResetInstancesTypeRequest) (response *InquiryPriceResetInstancesTypeResponse, err error) { + if request == nil { + request = NewInquiryPriceResetInstancesTypeRequest() + } + response = NewInquiryPriceResetInstancesTypeResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceResizeInstanceDisksRequest() (request *InquiryPriceResizeInstanceDisksRequest) { + request = &InquiryPriceResizeInstanceDisksRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceResizeInstanceDisks") + return +} + +func NewInquiryPriceResizeInstanceDisksResponse() (response *InquiryPriceResizeInstanceDisksResponse) { + response = &InquiryPriceResizeInstanceDisksResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (InquiryPriceResizeInstanceDisks) 用于扩容实例的数据盘询价。 +// +// * 目前只支持扩容非弹性数据盘([`DescribeDisks`](https://cloud.tencent.com/document/api/362/16315)接口返回值中的`Portable`为`false`表示非弹性)询价,且[数据盘类型](/document/api/213/9452#block_device)为:`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`。 +// * 目前不支持[CDH](https://cloud.tencent.com/document/product/416)实例使用该接口扩容数据盘询价。* 仅支持包年包月实例随机器购买的数据盘。* 目前只支持扩容一块数据盘询价。 +func (c *Client) InquiryPriceResizeInstanceDisks(request *InquiryPriceResizeInstanceDisksRequest) (response *InquiryPriceResizeInstanceDisksResponse, err error) { + if request == nil { + request = NewInquiryPriceResizeInstanceDisksRequest() + } + response = NewInquiryPriceResizeInstanceDisksResponse() + err = c.Send(request, response) + return +} + +func NewInquiryPriceRunInstancesRequest() (request *InquiryPriceRunInstancesRequest) { + request = &InquiryPriceRunInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "InquiryPriceRunInstances") + return +} + +func NewInquiryPriceRunInstancesResponse() (response *InquiryPriceRunInstancesResponse) { + response = &InquiryPriceRunInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(InquiryPriceRunInstances)用于创建实例询价。本接口仅允许针对购买限制范围内的实例配置进行询价, 详见:[创建实例](https://cloud.tencent.com/document/api/213/15730)。 +func (c *Client) InquiryPriceRunInstances(request *InquiryPriceRunInstancesRequest) (response *InquiryPriceRunInstancesResponse, err error) { + if request == nil { + request = NewInquiryPriceRunInstancesRequest() + } + response = NewInquiryPriceRunInstancesResponse() + err = c.Send(request, response) + return +} + +func NewModifyDisasterRecoverGroupAttributeRequest() (request *ModifyDisasterRecoverGroupAttributeRequest) { + request = &ModifyDisasterRecoverGroupAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyDisasterRecoverGroupAttribute") + return +} + +func NewModifyDisasterRecoverGroupAttributeResponse() (response *ModifyDisasterRecoverGroupAttributeResponse) { + response = &ModifyDisasterRecoverGroupAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyDisasterRecoverGroupAttribute)用于修改[分散置放群组](https://cloud.tencent.com/document/product/213/15486)属性。 +func (c *Client) ModifyDisasterRecoverGroupAttribute(request *ModifyDisasterRecoverGroupAttributeRequest) (response *ModifyDisasterRecoverGroupAttributeResponse, err error) { + if request == nil { + request = NewModifyDisasterRecoverGroupAttributeRequest() + } + response = NewModifyDisasterRecoverGroupAttributeResponse() + err = c.Send(request, response) + return +} + +func NewModifyHostsAttributeRequest() (request *ModifyHostsAttributeRequest) { + request = &ModifyHostsAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyHostsAttribute") + return +} + +func NewModifyHostsAttributeResponse() (response *ModifyHostsAttributeResponse) { + response = &ModifyHostsAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(ModifyHostsAttribute)用于修改CDH实例的属性,如实例名称和续费标记等。参数HostName和RenewFlag必须设置其中一个,但不能同时设置。 +func (c *Client) ModifyHostsAttribute(request *ModifyHostsAttributeRequest) (response *ModifyHostsAttributeResponse, err error) { + if request == nil { + request = NewModifyHostsAttributeRequest() + } + response = NewModifyHostsAttributeResponse() + err = c.Send(request, response) + return +} + +func NewModifyImageAttributeRequest() (request *ModifyImageAttributeRequest) { + request = &ModifyImageAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyImageAttribute") + return +} + +func NewModifyImageAttributeResponse() (response *ModifyImageAttributeResponse) { + response = &ModifyImageAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(ModifyImageAttribute)用于修改镜像属性。 +// +// * 已分享的镜像无法修改属性。 +func (c *Client) ModifyImageAttribute(request *ModifyImageAttributeRequest) (response *ModifyImageAttributeResponse, err error) { + if request == nil { + request = NewModifyImageAttributeRequest() + } + response = NewModifyImageAttributeResponse() + err = c.Send(request, response) + return +} + +func NewModifyImageSharePermissionRequest() (request *ModifyImageSharePermissionRequest) { + request = &ModifyImageSharePermissionRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyImageSharePermission") + return +} + +func NewModifyImageSharePermissionResponse() (response *ModifyImageSharePermissionResponse) { + response = &ModifyImageSharePermissionResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(ModifyImageSharePermission)用于修改镜像分享信息。 +// +// * 分享镜像后,被分享账户可以通过该镜像创建实例。 +// * 每个自定义镜像最多可共享给50个账户。 +// * 分享镜像无法更改名称,描述,仅可用于创建实例。 +// * 只支持分享到对方账户相同地域。 +func (c *Client) ModifyImageSharePermission(request *ModifyImageSharePermissionRequest) (response *ModifyImageSharePermissionResponse, err error) { + if request == nil { + request = NewModifyImageSharePermissionRequest() + } + response = NewModifyImageSharePermissionResponse() + err = c.Send(request, response) + return +} + +func NewModifyInstancesAttributeRequest() (request *ModifyInstancesAttributeRequest) { + request = &ModifyInstancesAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyInstancesAttribute") + return +} + +func NewModifyInstancesAttributeResponse() (response *ModifyInstancesAttributeResponse) { + response = &ModifyInstancesAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyInstancesAttribute) 用于修改实例的属性(目前只支持修改实例的名称和关联的安全组)。 +// +// * “实例名称”仅为方便用户自己管理之用,腾讯云并不以此名称作为提交工单或是进行实例管理操作的依据。 +// * 支持批量操作。每次请求批量实例的上限为100。 +// * 修改关联安全组时,子机原来关联的安全组会被解绑。 +func (c *Client) ModifyInstancesAttribute(request *ModifyInstancesAttributeRequest) (response *ModifyInstancesAttributeResponse, err error) { + if request == nil { + request = NewModifyInstancesAttributeRequest() + } + response = NewModifyInstancesAttributeResponse() + err = c.Send(request, response) + return +} + +func NewModifyInstancesChargeTypeRequest() (request *ModifyInstancesChargeTypeRequest) { + request = &ModifyInstancesChargeTypeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyInstancesChargeType") + return +} + +func NewModifyInstancesChargeTypeResponse() (response *ModifyInstancesChargeTypeResponse) { + response = &ModifyInstancesChargeTypeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyInstancesChargeType) 用于切换实例的计费模式。 +// +// * 只支持从 `POSTPAID_BY_HOUR` 计费模式切换为`PREPAID`计费模式。 +// * 关机不收费的实例、`BC1`和`BS1`机型族的实例、设置定时销毁的实例不支持该操作。 +func (c *Client) ModifyInstancesChargeType(request *ModifyInstancesChargeTypeRequest) (response *ModifyInstancesChargeTypeResponse, err error) { + if request == nil { + request = NewModifyInstancesChargeTypeRequest() + } + response = NewModifyInstancesChargeTypeResponse() + err = c.Send(request, response) + return +} + +func NewModifyInstancesProjectRequest() (request *ModifyInstancesProjectRequest) { + request = &ModifyInstancesProjectRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyInstancesProject") + return +} + +func NewModifyInstancesProjectResponse() (response *ModifyInstancesProjectResponse) { + response = &ModifyInstancesProjectResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyInstancesProject) 用于修改实例所属项目。 +// +// * 项目为一个虚拟概念,用户可以在一个账户下面建立多个项目,每个项目中管理不同的资源;将多个不同实例分属到不同项目中,后续使用 [`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口查询实例,项目ID可用于过滤结果。 +// * 绑定负载均衡的实例不支持修改实例所属项目,请先使用[`DeregisterInstancesFromLoadBalancer`](https://cloud.tencent.com/document/api/214/1258)接口解绑负载均衡。 +// * 修改实例所属项目会自动解关联实例原来关联的安全组,修改完成后可能使用[`ModifySecurityGroupsOfInstance`](https://cloud.tencent.com/document/api/213/1367)接口关联安全组。 +// * 支持批量操作。每次请求批量实例的上限为100。 +func (c *Client) ModifyInstancesProject(request *ModifyInstancesProjectRequest) (response *ModifyInstancesProjectResponse, err error) { + if request == nil { + request = NewModifyInstancesProjectRequest() + } + response = NewModifyInstancesProjectResponse() + err = c.Send(request, response) + return +} + +func NewModifyInstancesRenewFlagRequest() (request *ModifyInstancesRenewFlagRequest) { + request = &ModifyInstancesRenewFlagRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyInstancesRenewFlag") + return +} + +func NewModifyInstancesRenewFlagResponse() (response *ModifyInstancesRenewFlagResponse) { + response = &ModifyInstancesRenewFlagResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyInstancesRenewFlag) 用于修改包年包月实例续费标识。 +// +// * 实例被标识为自动续费后,每次在实例到期时,会自动续费一个月。 +// * 支持批量操作。每次请求批量实例的上限为100。 +func (c *Client) ModifyInstancesRenewFlag(request *ModifyInstancesRenewFlagRequest) (response *ModifyInstancesRenewFlagResponse, err error) { + if request == nil { + request = NewModifyInstancesRenewFlagRequest() + } + response = NewModifyInstancesRenewFlagResponse() + err = c.Send(request, response) + return +} + +func NewModifyInstancesVpcAttributeRequest() (request *ModifyInstancesVpcAttributeRequest) { + request = &ModifyInstancesVpcAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyInstancesVpcAttribute") + return +} + +func NewModifyInstancesVpcAttributeResponse() (response *ModifyInstancesVpcAttributeResponse) { + response = &ModifyInstancesVpcAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(ModifyInstancesVpcAttribute)用于修改实例vpc属性,如私有网络ip。 +// * 此操作默认会关闭实例,完成后再启动。 +// * 当指定私有网络ID和子网ID(子网必须在实例所在的可用区)与指定实例所在私有网络不一致时,会将实例迁移至指定的私有网络的子网下。执行此操作前请确保指定的实例上没有绑定[弹性网卡](https://cloud.tencent.com/document/product/576)和[负载均衡](https://cloud.tencent.com/document/product/214)。 +func (c *Client) ModifyInstancesVpcAttribute(request *ModifyInstancesVpcAttributeRequest) (response *ModifyInstancesVpcAttributeResponse, err error) { + if request == nil { + request = NewModifyInstancesVpcAttributeRequest() + } + response = NewModifyInstancesVpcAttributeResponse() + err = c.Send(request, response) + return +} + +func NewModifyKeyPairAttributeRequest() (request *ModifyKeyPairAttributeRequest) { + request = &ModifyKeyPairAttributeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ModifyKeyPairAttribute") + return +} + +func NewModifyKeyPairAttributeResponse() (response *ModifyKeyPairAttributeResponse) { + response = &ModifyKeyPairAttributeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ModifyKeyPairAttribute) 用于修改密钥对属性。 +// +// * 修改密钥对ID所指定的密钥对的名称和描述信息。 +// * 密钥对名称不能和已经存在的密钥对的名称重复。 +// * 密钥对ID是密钥对的唯一标识,不可修改。 +func (c *Client) ModifyKeyPairAttribute(request *ModifyKeyPairAttributeRequest) (response *ModifyKeyPairAttributeResponse, err error) { + if request == nil { + request = NewModifyKeyPairAttributeRequest() + } + response = NewModifyKeyPairAttributeResponse() + err = c.Send(request, response) + return +} + +func NewRebootInstancesRequest() (request *RebootInstancesRequest) { + request = &RebootInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "RebootInstances") + return +} + +func NewRebootInstancesResponse() (response *RebootInstancesResponse) { + response = &RebootInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (RebootInstances) 用于重启实例。 +// +// * 只有状态为`RUNNING`的实例才可以进行此操作。 +// * 接口调用成功时,实例会进入`REBOOTING`状态;重启实例成功时,实例会进入`RUNNING`状态。 +// * 支持强制重启。强制重启的效果等同于关闭物理计算机的电源开关再重新启动。强制重启可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常重启时使用。 +// * 支持批量操作,每次请求批量实例的上限为100。 +func (c *Client) RebootInstances(request *RebootInstancesRequest) (response *RebootInstancesResponse, err error) { + if request == nil { + request = NewRebootInstancesRequest() + } + response = NewRebootInstancesResponse() + err = c.Send(request, response) + return +} + +func NewRenewHostsRequest() (request *RenewHostsRequest) { + request = &RenewHostsRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "RenewHosts") + return +} + +func NewRenewHostsResponse() (response *RenewHostsResponse) { + response = &RenewHostsResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (RenewHosts) 用于续费包年包月CDH实例。 +// +// * 只支持操作包年包月实例,否则操作会以特定[错误码](#4.-.E9.94.99.E8.AF.AF.E7.A0.81)返回。 +// * 续费时请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +func (c *Client) RenewHosts(request *RenewHostsRequest) (response *RenewHostsResponse, err error) { + if request == nil { + request = NewRenewHostsRequest() + } + response = NewRenewHostsResponse() + err = c.Send(request, response) + return +} + +func NewRenewInstancesRequest() (request *RenewInstancesRequest) { + request = &RenewInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "RenewInstances") + return +} + +func NewRenewInstancesResponse() (response *RenewInstancesResponse) { + response = &RenewInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (RenewInstances) 用于续费包年包月实例。 +// +// * 只支持操作包年包月实例。 +// * 续费时请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +func (c *Client) RenewInstances(request *RenewInstancesRequest) (response *RenewInstancesResponse, err error) { + if request == nil { + request = NewRenewInstancesRequest() + } + response = NewRenewInstancesResponse() + err = c.Send(request, response) + return +} + +func NewResetInstanceRequest() (request *ResetInstanceRequest) { + request = &ResetInstanceRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ResetInstance") + return +} + +func NewResetInstanceResponse() (response *ResetInstanceResponse) { + response = &ResetInstanceResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ResetInstance) 用于重装指定实例上的操作系统。 +// +// * 如果指定了`ImageId`参数,则使用指定的镜像重装;否则按照当前实例使用的镜像进行重装。 +// * 系统盘将会被格式化,并重置;请确保系统盘中无重要文件。 +// * `Linux`和`Windows`系统互相切换时,该实例系统盘`ID`将发生变化,系统盘关联快照将无法回滚、恢复数据。 +// * 密码不指定将会通过站内信下发随机密码。 +// * 目前只支持[系统盘类型](https://cloud.tencent.com/document/api/213/9452#block_device)是`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`类型的实例使用该接口实现`Linux`和`Windows`操作系统切换。 +// * 目前不支持海外地域的实例使用该接口实现`Linux`和`Windows`操作系统切换。 +func (c *Client) ResetInstance(request *ResetInstanceRequest) (response *ResetInstanceResponse, err error) { + if request == nil { + request = NewResetInstanceRequest() + } + response = NewResetInstanceResponse() + err = c.Send(request, response) + return +} + +func NewResetInstancesInternetMaxBandwidthRequest() (request *ResetInstancesInternetMaxBandwidthRequest) { + request = &ResetInstancesInternetMaxBandwidthRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ResetInstancesInternetMaxBandwidth") + return +} + +func NewResetInstancesInternetMaxBandwidthResponse() (response *ResetInstancesInternetMaxBandwidthResponse) { + response = &ResetInstancesInternetMaxBandwidthResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ResetInstancesInternetMaxBandwidth) 用于调整实例公网带宽上限。 +// +// * 不同机型带宽上限范围不一致,具体限制详见[购买网络带宽](https://cloud.tencent.com/document/product/213/509)。 +// * 对于 `BANDWIDTH_PREPAID` 计费方式的带宽,需要输入参数 `StartTime` 和 `EndTime` ,指定调整后的带宽的生效时间段。在这种场景下目前不支持调小带宽,会涉及扣费,请确保账户余额充足。可通过 [`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397) 接口查询账户余额。 +// * 对于 `TRAFFIC_POSTPAID_BY_HOUR` 、 `BANDWIDTH_POSTPAID_BY_HOUR` 和 `BANDWIDTH_PACKAGE` 计费方式的带宽,使用该接口调整带宽上限是实时生效的,可以在带宽允许的范围内调大或者调小带宽,不支持输入参数 `StartTime` 和 `EndTime` 。 +// * 接口不支持调整 `BANDWIDTH_POSTPAID_BY_MONTH` 计费方式的带宽。 +// * 接口不支持批量调整 `BANDWIDTH_PREPAID` 和 `BANDWIDTH_POSTPAID_BY_HOUR` 计费方式的带宽。 +// * 接口不支持批量调整混合计费方式的带宽。例如不支持同时调整 `TRAFFIC_POSTPAID_BY_HOUR` 和 `BANDWIDTH_PACKAGE` 计费方式的带宽。 +func (c *Client) ResetInstancesInternetMaxBandwidth(request *ResetInstancesInternetMaxBandwidthRequest) (response *ResetInstancesInternetMaxBandwidthResponse, err error) { + if request == nil { + request = NewResetInstancesInternetMaxBandwidthRequest() + } + response = NewResetInstancesInternetMaxBandwidthResponse() + err = c.Send(request, response) + return +} + +func NewResetInstancesPasswordRequest() (request *ResetInstancesPasswordRequest) { + request = &ResetInstancesPasswordRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ResetInstancesPassword") + return +} + +func NewResetInstancesPasswordResponse() (response *ResetInstancesPasswordResponse) { + response = &ResetInstancesPasswordResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ResetInstancesPassword) 用于将实例操作系统的密码重置为用户指定的密码。 +// +// * 只修改管理员帐号的密码。实例的操作系统不同,管理员帐号也会不一样(`Windows`为`Administrator`,`Ubuntu`为`ubuntu`,其它系统为`root`)。 +// * 重置处于运行中状态的实例,需要显式指定强制关机参数`ForceStop`。如果没有显式指定强制关机参数,则只有处于关机状态的实例才允许执行重置密码操作。 +// * 支持批量操作。将多个实例操作系统的密码重置为相同的密码。每次请求批量实例的上限为100。 +func (c *Client) ResetInstancesPassword(request *ResetInstancesPasswordRequest) (response *ResetInstancesPasswordResponse, err error) { + if request == nil { + request = NewResetInstancesPasswordRequest() + } + response = NewResetInstancesPasswordResponse() + err = c.Send(request, response) + return +} + +func NewResetInstancesTypeRequest() (request *ResetInstancesTypeRequest) { + request = &ResetInstancesTypeRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ResetInstancesType") + return +} + +func NewResetInstancesTypeResponse() (response *ResetInstancesTypeResponse) { + response = &ResetInstancesTypeResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ResetInstancesType) 用于调整实例的机型。 +// * 目前只支持[系统盘类型](/document/api/213/9452#block_device)是`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`类型的实例使用该接口进行机型调整。 +// * 目前不支持[CDH](https://cloud.tencent.com/document/product/416)实例使用该接口调整机型。对于包年包月实例,使用该接口会涉及扣费,请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +func (c *Client) ResetInstancesType(request *ResetInstancesTypeRequest) (response *ResetInstancesTypeResponse, err error) { + if request == nil { + request = NewResetInstancesTypeRequest() + } + response = NewResetInstancesTypeResponse() + err = c.Send(request, response) + return +} + +func NewResizeInstanceDisksRequest() (request *ResizeInstanceDisksRequest) { + request = &ResizeInstanceDisksRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "ResizeInstanceDisks") + return +} + +func NewResizeInstanceDisksResponse() (response *ResizeInstanceDisksResponse) { + response = &ResizeInstanceDisksResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (ResizeInstanceDisks) 用于扩容实例的数据盘。 +// +// * 目前只支持扩容非弹性数据盘([`DescribeDisks`](https://cloud.tencent.com/document/api/362/16315)接口返回值中的`Portable`为`false`表示非弹性),且[数据盘类型](/document/api/213/9452#block_device)为:`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`。 +// * 目前不支持[CDH](https://cloud.tencent.com/document/product/416)实例使用该接口扩容数据盘。 +// * 对于包年包月实例,使用该接口会涉及扣费,请确保账户余额充足。可通过[`DescribeAccountBalance`](https://cloud.tencent.com/document/product/378/4397)接口查询账户余额。 +// * 目前只支持扩容一块数据盘。 +func (c *Client) ResizeInstanceDisks(request *ResizeInstanceDisksRequest) (response *ResizeInstanceDisksResponse, err error) { + if request == nil { + request = NewResizeInstanceDisksRequest() + } + response = NewResizeInstanceDisksResponse() + err = c.Send(request, response) + return +} + +func NewRunInstancesRequest() (request *RunInstancesRequest) { + request = &RunInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "RunInstances") + return +} + +func NewRunInstancesResponse() (response *RunInstancesResponse) { + response = &RunInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (RunInstances) 用于创建一个或多个指定配置的实例。 +// +// * 实例创建成功后将自动开机启动,[实例状态](/document/api/213/9452#instance_state)变为“运行中”。 +// * 预付费实例的购买会预先扣除本次实例购买所需金额,按小时后付费实例购买会预先冻结本次实例购买一小时内所需金额,在调用本接口前请确保账户余额充足。 +// * 本接口允许购买的实例数量遵循[CVM实例购买限制](https://cloud.tencent.com/document/product/213/2664),所创建的实例和官网入口创建的实例共用配额。 +// * 本接口为异步接口,当创建请求下发成功后会返回一个实例`ID`列表,此时实例的创建并立即未完成。在此期间实例的状态将会处于“准备中”,可以通过调用 [DescribeInstances](https://cloud.tencent.com/document/api/213/15728) 接口查询对应实例的状态,来判断创建有没有最终成功。如果实例的状态由“准备中”变为“运行中”,则为创建成功。 +func (c *Client) RunInstances(request *RunInstancesRequest) (response *RunInstancesResponse, err error) { + if request == nil { + request = NewRunInstancesRequest() + } + response = NewRunInstancesResponse() + err = c.Send(request, response) + return +} + +func NewStartInstancesRequest() (request *StartInstancesRequest) { + request = &StartInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "StartInstances") + return +} + +func NewStartInstancesResponse() (response *StartInstancesResponse) { + response = &StartInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (StartInstances) 用于启动一个或多个实例。 +// +// * 只有状态为`STOPPED`的实例才可以进行此操作。 +// * 接口调用成功时,实例会进入`STARTING`状态;启动实例成功时,实例会进入`RUNNING`状态。 +// * 支持批量操作。每次请求批量实例的上限为100。 +func (c *Client) StartInstances(request *StartInstancesRequest) (response *StartInstancesResponse, err error) { + if request == nil { + request = NewStartInstancesRequest() + } + response = NewStartInstancesResponse() + err = c.Send(request, response) + return +} + +func NewStopInstancesRequest() (request *StopInstancesRequest) { + request = &StopInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "StopInstances") + return +} + +func NewStopInstancesResponse() (response *StopInstancesResponse) { + response = &StopInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (StopInstances) 用于关闭一个或多个实例。 +// +// * 只有状态为`RUNNING`的实例才可以进行此操作。 +// * 接口调用成功时,实例会进入`STOPPING`状态;关闭实例成功时,实例会进入`STOPPED`状态。 +// * 支持强制关闭。强制关机的效果等同于关闭物理计算机的电源开关。强制关机可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常关机时使用。 +// * 支持批量操作。每次请求批量实例的上限为100。 +func (c *Client) StopInstances(request *StopInstancesRequest) (response *StopInstancesResponse, err error) { + if request == nil { + request = NewStopInstancesRequest() + } + response = NewStopInstancesResponse() + err = c.Send(request, response) + return +} + +func NewSyncImagesRequest() (request *SyncImagesRequest) { + request = &SyncImagesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "SyncImages") + return +} + +func NewSyncImagesResponse() (response *SyncImagesResponse) { + response = &SyncImagesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口(SyncImages)用于将自定义镜像同步到其它地区。 +// +// * 该接口每次调用只支持同步一个镜像。 +// * 该接口支持多个同步地域。 +// * 单个帐号在每个地域最多支持存在10个自定义镜像。 +func (c *Client) SyncImages(request *SyncImagesRequest) (response *SyncImagesResponse, err error) { + if request == nil { + request = NewSyncImagesRequest() + } + response = NewSyncImagesResponse() + err = c.Send(request, response) + return +} + +func NewTerminateInstancesRequest() (request *TerminateInstancesRequest) { + request = &TerminateInstancesRequest{ + BaseRequest: &tchttp.BaseRequest{}, + } + request.Init().WithApiInfo("cvm", APIVersion, "TerminateInstances") + return +} + +func NewTerminateInstancesResponse() (response *TerminateInstancesResponse) { + response = &TerminateInstancesResponse{ + BaseResponse: &tchttp.BaseResponse{}, + } + return +} + +// 本接口 (TerminateInstances) 用于主动退还实例。 +// +// * 不再使用的实例,可通过本接口主动退还。 +// * 按量计费的实例通过本接口可直接退还;包年包月实例如符合[退还规则](https://cloud.tencent.com/document/product/213/9711),也可通过本接口主动退还。 +// * 支持批量操作,每次请求批量实例的上限为100。 +func (c *Client) TerminateInstances(request *TerminateInstancesRequest) (response *TerminateInstancesResponse, err error) { + if request == nil { + request = NewTerminateInstancesRequest() + } + response = NewTerminateInstancesResponse() + err = c.Send(request, response) + return +} diff --git a/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/models.go b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/models.go new file mode 100644 index 0000000000..b985b8a7ea --- /dev/null +++ b/vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312/models.go @@ -0,0 +1,3490 @@ +// Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package v20170312 + +import ( + "encoding/json" + + tchttp "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http" +) + +type ActionTimer struct { + + // 扩展数据 + Externals *Externals `json:"Externals,omitempty" name:"Externals"` + + // 定时器名称,目前仅支持销毁一个值:TerminateInstances。 + TimerAction *string `json:"TimerAction,omitempty" name:"TimerAction"` + + // 执行时间,格式形如:2018-5-29 11:26:40,执行时间必须大于当前时间5分钟。 + ActionTime *string `json:"ActionTime,omitempty" name:"ActionTime"` +} + +type AllocateHostsRequest struct { + *tchttp.BaseRequest + + // 实例所在的位置。通过该参数可以指定实例所属可用区,所属项目等属性。 + Placement *Placement `json:"Placement,omitempty" name:"Placement"` + + // 用于保证请求幂等性的字符串。 + ClientToken *string `json:"ClientToken,omitempty" name:"ClientToken"` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长、是否设置自动续费等属性。若指定实例的付费模式为预付费则该参数必传。 + HostChargePrepaid *ChargePrepaid `json:"HostChargePrepaid,omitempty" name:"HostChargePrepaid"` + + // 实例计费类型。目前仅支持:PREPAID(预付费,即包年包月模式)。 + HostChargeType *string `json:"HostChargeType,omitempty" name:"HostChargeType"` + + // CDH实例机型,默认为:'HS1'。 + HostType *string `json:"HostType,omitempty" name:"HostType"` + + // 购买CDH实例数量。 + HostCount *uint64 `json:"HostCount,omitempty" name:"HostCount"` + + // 标签描述列表。通过指定该参数可以同时绑定标签到相应的资源实例。 + TagSpecification []*TagSpecification `json:"TagSpecification,omitempty" name:"TagSpecification" list` +} + +func (r *AllocateHostsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AllocateHostsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type AllocateHostsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 新创建云子机的实例id列表。 + HostIdSet []*string `json:"HostIdSet,omitempty" name:"HostIdSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *AllocateHostsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AllocateHostsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type AssociateInstancesKeyPairsRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID,每次请求批量实例的上限为100。
可以通过以下方式获取可用的实例ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/index)查询实例ID。
  • 通过调用接口 [DescribeInstances](https://cloud.tencent.com/document/api/213/15728) ,取返回信息中的`InstanceId`获取实例ID。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 一个或多个待操作的密钥对ID,每次请求批量密钥对的上限为100。密钥对ID形如:`skey-3glfot13`。
    可以通过以下方式获取可用的密钥ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/sshkey)查询密钥ID。
  • 通过调用接口 [DescribeKeyPairs](https://cloud.tencent.com/document/api/213/15699) ,取返回信息中的`KeyId`获取密钥对ID。 + KeyIds []*string `json:"KeyIds,omitempty" name:"KeyIds" list` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再绑定密钥。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机。
  • FALSE:表示在正常关机失败后不进行强制关机。
    默认取值:FALSE。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *AssociateInstancesKeyPairsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AssociateInstancesKeyPairsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type AssociateInstancesKeyPairsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *AssociateInstancesKeyPairsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AssociateInstancesKeyPairsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type AssociateSecurityGroupsRequest struct { + *tchttp.BaseRequest + + // 要绑定的`安全组ID`,类似sg-efil73jd,只支持绑定单个安全组。 + SecurityGroupIds []*string `json:"SecurityGroupIds,omitempty" name:"SecurityGroupIds" list` + + // 被绑定的`实例ID`,类似ins-lesecurk,支持指定多个实例。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` +} + +func (r *AssociateSecurityGroupsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AssociateSecurityGroupsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type AssociateSecurityGroupsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *AssociateSecurityGroupsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *AssociateSecurityGroupsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ChargePrepaid struct { + + // 购买实例的时长,单位:月。取值范围:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36。 + Period *uint64 `json:"Period,omitempty" name:"Period"` + + // 自动续费标识。取值范围:
  • NOTIFY_AND_AUTO_RENEW:通知过期且自动续费
  • NOTIFY_AND_MANUAL_RENEW:通知过期不自动续费
  • DISABLE_NOTIFY_AND_MANUAL_RENEW:不通知过期不自动续费

    默认取值:NOTIFY_AND_AUTO_RENEW。若该参数指定为NOTIFY_AND_AUTO_RENEW,在账户余额充足的情况下,实例到期后将按月自动续费。 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` +} + +type CreateDisasterRecoverGroupRequest struct { + *tchttp.BaseRequest + + // 分散置放群组名称,长度1-60个字符,支持中、英文。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 分散置放群组类型,取值范围:
  • HOST:物理机
  • SW:交换机
  • RACK:机架 + Type *string `json:"Type,omitempty" name:"Type"` + + // 用于保证请求幂等性的字符串。该字符串由客户生成,需保证不同请求之间唯一,最大值不超过64个ASCII字符。若不指定该参数,则无法保证请求的幂等性。
    更多详细信息请参阅:如何保证幂等性。 + ClientToken *string `json:"ClientToken,omitempty" name:"ClientToken"` +} + +func (r *CreateDisasterRecoverGroupRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateDisasterRecoverGroupRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type CreateDisasterRecoverGroupResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 分散置放群组ID列表。 + DisasterRecoverGroupId *string `json:"DisasterRecoverGroupId,omitempty" name:"DisasterRecoverGroupId"` + + // 分散置放群组类型,取值范围:
  • HOST:物理机
  • SW:交换机
  • RACK:机架 + Type *string `json:"Type,omitempty" name:"Type"` + + // 分散置放群组名称,长度1-60个字符,支持中、英文。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 置放群组内可容纳的云主机数量。 + CvmQuotaTotal *int64 `json:"CvmQuotaTotal,omitempty" name:"CvmQuotaTotal"` + + // 置放群组内已有的云主机数量。 + CurrentNum *int64 `json:"CurrentNum,omitempty" name:"CurrentNum"` + + // 置放群组创建时间。 + CreateTime *string `json:"CreateTime,omitempty" name:"CreateTime"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *CreateDisasterRecoverGroupResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateDisasterRecoverGroupResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type CreateImageRequest struct { + *tchttp.BaseRequest + + // 镜像名称 + ImageName *string `json:"ImageName,omitempty" name:"ImageName"` + + // 需要制作镜像的实例ID + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 镜像描述 + ImageDescription *string `json:"ImageDescription,omitempty" name:"ImageDescription"` + + // 软关机失败时是否执行强制关机以制作镜像 + ForcePoweroff *string `json:"ForcePoweroff,omitempty" name:"ForcePoweroff"` + + // 创建Windows镜像时是否启用Sysprep + Sysprep *string `json:"Sysprep,omitempty" name:"Sysprep"` + + // 实例处于运行中时,是否允许关机执行制作镜像任务。 + Reboot *string `json:"Reboot,omitempty" name:"Reboot"` + + // 实例需要制作镜像的数据盘Id + DataDiskIds []*string `json:"DataDiskIds,omitempty" name:"DataDiskIds" list` + + // 需要制作镜像的快照Id,必须包含一个系统盘快照 + SnapshotIds []*string `json:"SnapshotIds,omitempty" name:"SnapshotIds" list` + + // 检测请求的合法性,但不会对操作的资源产生任何影响 + DryRun *bool `json:"DryRun,omitempty" name:"DryRun"` +} + +func (r *CreateImageRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateImageRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type CreateImageResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *CreateImageResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateImageResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type CreateKeyPairRequest struct { + *tchttp.BaseRequest + + // 密钥对名称,可由数字,字母和下划线组成,长度不超过25个字符。 + KeyName *string `json:"KeyName,omitempty" name:"KeyName"` + + // 密钥对创建后所属的项目ID。 + // 可以通过以下方式获取项目ID: + //
  • 通过项目列表查询项目ID。 + //
  • 通过调用接口DescribeProject,取返回信息中的`projectId `获取项目ID。 + ProjectId *int64 `json:"ProjectId,omitempty" name:"ProjectId"` +} + +func (r *CreateKeyPairRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateKeyPairRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type CreateKeyPairResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 密钥对信息。 + KeyPair *KeyPair `json:"KeyPair,omitempty" name:"KeyPair"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *CreateKeyPairResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *CreateKeyPairResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DataDisk struct { + + // 数据盘大小,单位:GB。最小调整步长为10G,不同数据盘类型取值范围不同,具体限制详见:[CVM实例配置](/document/product/213/2177)。默认值为0,表示不购买数据盘。更多限制详见产品文档。 + DiskSize *int64 `json:"DiskSize,omitempty" name:"DiskSize"` + + // 数据盘类型。数据盘类型限制详见[CVM实例配置](/document/product/213/2177)。取值范围:
  • LOCAL_BASIC:本地硬盘
  • LOCAL_SSD:本地SSD硬盘
  • CLOUD_BASIC:普通云硬盘
  • CLOUD_PREMIUM:高性能云硬盘
  • CLOUD_SSD:SSD云硬盘

    默认取值:LOCAL_BASIC。

    该参数对`ResizeInstanceDisk`接口无效。 + DiskType *string `json:"DiskType,omitempty" name:"DiskType"` + + // 数据盘ID。LOCAL_BASIC 和 LOCAL_SSD 类型没有ID。暂时不支持该参数。 + DiskId *string `json:"DiskId,omitempty" name:"DiskId"` + + // 数据盘是否随子机销毁。取值范围: + //
  • TRUE:子机销毁时,销毁数据盘,只支持按小时后付费云盘 + //
  • FALSE:子机销毁时,保留数据盘
    + // 默认取值:TRUE
    + // 该参数目前仅用于 `RunInstances` 接口。 + // 注意:此字段可能返回 null,表示取不到有效值。 + DeleteWithInstance *bool `json:"DeleteWithInstance,omitempty" name:"DeleteWithInstance"` + + // 数据盘快照ID。选择的数据盘快照大小需小于数据盘大小。 + // 注意:此字段可能返回 null,表示取不到有效值。 + SnapshotId *string `json:"SnapshotId,omitempty" name:"SnapshotId"` +} + +type DeleteDisasterRecoverGroupsRequest struct { + *tchttp.BaseRequest + + // 分散置放群组ID列表,可通过[DescribeDisasterRecoverGroups](https://cloud.tencent.com/document/api/213/17810)接口获取。 + DisasterRecoverGroupIds []*string `json:"DisasterRecoverGroupIds,omitempty" name:"DisasterRecoverGroupIds" list` +} + +func (r *DeleteDisasterRecoverGroupsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteDisasterRecoverGroupsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DeleteDisasterRecoverGroupsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DeleteDisasterRecoverGroupsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteDisasterRecoverGroupsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DeleteImagesRequest struct { + *tchttp.BaseRequest + + // 准备删除的镜像Id列表 + ImageIds []*string `json:"ImageIds,omitempty" name:"ImageIds" list` +} + +func (r *DeleteImagesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteImagesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DeleteImagesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DeleteImagesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteImagesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DeleteKeyPairsRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的密钥对ID。每次请求批量密钥对的上限为100。
    可以通过以下方式获取可用的密钥ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/sshkey)查询密钥ID。
  • 通过调用接口 [DescribeKeyPairs](https://cloud.tencent.com/document/api/213/15699) ,取返回信息中的 `KeyId` 获取密钥对ID。 + KeyIds []*string `json:"KeyIds,omitempty" name:"KeyIds" list` +} + +func (r *DeleteKeyPairsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteKeyPairsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DeleteKeyPairsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DeleteKeyPairsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DeleteKeyPairsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeDisasterRecoverGroupQuotaRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeDisasterRecoverGroupQuotaRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeDisasterRecoverGroupQuotaRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeDisasterRecoverGroupQuotaResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 可创建置放群组数量的上限。 + GroupQuota *int64 `json:"GroupQuota,omitempty" name:"GroupQuota"` + + // 当前用户已经创建的置放群组数量。 + CurrentNum *int64 `json:"CurrentNum,omitempty" name:"CurrentNum"` + + // 物理机类型容灾组内实例的配额数。 + CvmInHostGroupQuota *int64 `json:"CvmInHostGroupQuota,omitempty" name:"CvmInHostGroupQuota"` + + // 交换机类型容灾组内实例的配额数。 + CvmInSwGroupQuota *int64 `json:"CvmInSwGroupQuota,omitempty" name:"CvmInSwGroupQuota"` + + // 机架类型容灾组内实例的配额数。 + CvmInRackGroupQuota *int64 `json:"CvmInRackGroupQuota,omitempty" name:"CvmInRackGroupQuota"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeDisasterRecoverGroupQuotaResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeDisasterRecoverGroupQuotaResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeDisasterRecoverGroupsRequest struct { + *tchttp.BaseRequest + + // 分散置放群组ID列表。 + DisasterRecoverGroupIds []*string `json:"DisasterRecoverGroupIds,omitempty" name:"DisasterRecoverGroupIds" list` + + // 分散置放群组名称,支持模糊匹配。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 偏移量,默认为0。关于`Offset`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Offset *int64 `json:"Offset,omitempty" name:"Offset"` + + // 返回数量,默认为20,最大值为100。关于`Limit`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Limit *int64 `json:"Limit,omitempty" name:"Limit"` +} + +func (r *DescribeDisasterRecoverGroupsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeDisasterRecoverGroupsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeDisasterRecoverGroupsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 分散置放群组信息列表。 + DisasterRecoverGroupSet []*DisasterRecoverGroup `json:"DisasterRecoverGroupSet,omitempty" name:"DisasterRecoverGroupSet" list` + + // 用户置放群组总量。 + TotalCount *int64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeDisasterRecoverGroupsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeDisasterRecoverGroupsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeHostsRequest struct { + *tchttp.BaseRequest + + // 过滤条件。 + //
  • zone - String - 是否必填:否 - (过滤条件)按照可用区过滤。
  • + //
  • project-id - Integer - 是否必填:否 - (过滤条件)按照项目ID过滤。可通过调用 DescribeProject 查询已创建的项目列表或登录控制台进行查看;也可以调用 AddProject 创建新的项目。
  • + //
  • host-id - String - 是否必填:否 - (过滤条件)按照CDH ID过滤。CDH ID形如:host-11112222。
  • + //
  • host-name - String - 是否必填:否 - (过滤条件)按照CDH实例名称过滤。
  • + //
  • host-state - String - 是否必填:否 - (过滤条件)按照CDH实例状态进行过滤。(PENDING:创建中|LAUNCH_FAILURE:创建失败|RUNNING:运行中|EXPIRED:已过期)
  • + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` + + // 偏移量,默认为0。 + Offset *uint64 `json:"Offset,omitempty" name:"Offset"` + + // 返回数量,默认为20,最大值为100。 + Limit *uint64 `json:"Limit,omitempty" name:"Limit"` +} + +func (r *DescribeHostsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeHostsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeHostsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 符合查询条件的cdh实例总数 + TotalCount *uint64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // cdh实例详细信息列表 + HostSet []*HostItem `json:"HostSet,omitempty" name:"HostSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeHostsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeHostsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImageQuotaRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeImageQuotaRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImageQuotaRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImageQuotaResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 账户的镜像配额 + ImageNumQuota *int64 `json:"ImageNumQuota,omitempty" name:"ImageNumQuota"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeImageQuotaResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImageQuotaResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImageSharePermissionRequest struct { + *tchttp.BaseRequest + + // 需要共享的镜像Id + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` +} + +func (r *DescribeImageSharePermissionRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImageSharePermissionRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImageSharePermissionResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 镜像共享信息 + SharePermissionSet []*SharePermission `json:"SharePermissionSet,omitempty" name:"SharePermissionSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeImageSharePermissionResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImageSharePermissionResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImagesRequest struct { + *tchttp.BaseRequest + + // 镜像ID列表 。镜像ID如:`img-gvbnzy6f`。array型参数的格式可以参考[API简介](https://cloud.tencent.com/document/api/213/15688)。镜像ID可以通过如下方式获取:
  • 通过[DescribeImages](https://cloud.tencent.com/document/api/213/15715)接口返回的`ImageId`获取。
  • 通过[镜像控制台](https://console.cloud.tencent.com/cvm/image)获取。 + ImageIds []*string `json:"ImageIds,omitempty" name:"ImageIds" list` + + // 过滤条件,每次请求的`Filters`的上限为0,`Filters.Values`的上限为5。参数不可以同时指定`ImageIds`和`Filters`。详细的过滤条件如下: + //
  • image-id - String - 是否必填: 否 - (过滤条件)按照镜像ID进行过滤
  • + //
  • image-type - String - 是否必填: 否 - (过滤条件)按照镜像类型进行过滤。取值范围: + // PRIVATE_IMAGE: 私有镜像 (本帐户创建的镜像) + // PUBLIC_IMAGE: 公共镜像 (腾讯云官方镜像) + // MARKET_IMAGE: 服务市场 (服务市场提供的镜像) + // SHARED_IMAGE: 共享镜像(其他账户共享给本帐户的镜像) 。
  • + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` + + // 偏移量,默认为0。关于Offset详见[API简介](/document/api/213/568#.E8.BE.93.E5.85.A5.E5.8F.82.E6.95.B0.E4.B8.8E.E8.BF.94.E5.9B.9E.E5.8F.82.E6.95.B0.E9.87.8A.E4.B9.89)。 + Offset *uint64 `json:"Offset,omitempty" name:"Offset"` + + // 数量限制,默认为20,最大值为100。关于Limit详见[API简介](/document/api/213/568#.E8.BE.93.E5.85.A5.E5.8F.82.E6.95.B0.E4.B8.8E.E8.BF.94.E5.9B.9E.E5.8F.82.E6.95.B0.E9.87.8A.E4.B9.89)。 + Limit *uint64 `json:"Limit,omitempty" name:"Limit"` + + // 实例类型,如 `S1.SMALL1` + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` +} + +func (r *DescribeImagesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImagesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImagesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 一个关于镜像详细信息的结构体,主要包括镜像的主要状态与属性。 + ImageSet []*Image `json:"ImageSet,omitempty" name:"ImageSet" list` + + // 符合要求的镜像数量。 + TotalCount *int64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeImagesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImagesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImportImageOsRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeImportImageOsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImportImageOsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeImportImageOsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 支持的导入镜像的操作系统类型。 + ImportImageOsListSupported *ImageOsList `json:"ImportImageOsListSupported,omitempty" name:"ImportImageOsListSupported"` + + // 支持的导入镜像的操作系统版本。 + ImportImageOsVersionSet []*OsVersion `json:"ImportImageOsVersionSet,omitempty" name:"ImportImageOsVersionSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeImportImageOsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeImportImageOsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceFamilyConfigsRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeInstanceFamilyConfigsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceFamilyConfigsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceFamilyConfigsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 实例机型组配置的列表信息 + InstanceFamilyConfigSet []*InstanceFamilyConfig `json:"InstanceFamilyConfigSet,omitempty" name:"InstanceFamilyConfigSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstanceFamilyConfigsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceFamilyConfigsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceInternetBandwidthConfigsRequest struct { + *tchttp.BaseRequest + + // 待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` +} + +func (r *DescribeInstanceInternetBandwidthConfigsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceInternetBandwidthConfigsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceInternetBandwidthConfigsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 带宽配置信息列表。 + InternetBandwidthConfigSet []*InternetBandwidthConfig `json:"InternetBandwidthConfigSet,omitempty" name:"InternetBandwidthConfigSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstanceInternetBandwidthConfigsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceInternetBandwidthConfigsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceTypeConfigsRequest struct { + *tchttp.BaseRequest + + // 过滤条件。 + //
  • zone - String - 是否必填:否 -(过滤条件)按照[可用区](https://cloud.tencent.com/document/api/213/9452#zone)过滤。
  • + //
  • instance-family - String - 是否必填:否 -(过滤条件)按照实例机型系列过滤。实例机型系列形如:S1、I1、M1等。
  • + // 每次请求的`Filters`的上限为10,`Filter.Values`的上限为1。 + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` +} + +func (r *DescribeInstanceTypeConfigsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceTypeConfigsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceTypeConfigsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 实例机型配置列表。 + InstanceTypeConfigSet []*InstanceTypeConfig `json:"InstanceTypeConfigSet,omitempty" name:"InstanceTypeConfigSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstanceTypeConfigsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceTypeConfigsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceVncUrlRequest struct { + *tchttp.BaseRequest + + // 一个操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728) API返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` +} + +func (r *DescribeInstanceVncUrlRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceVncUrlRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstanceVncUrlResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 实例的管理终端地址。 + InstanceVncUrl *string `json:"InstanceVncUrl,omitempty" name:"InstanceVncUrl"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstanceVncUrlResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstanceVncUrlResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesOperationLimitRequest struct { + *tchttp.BaseRequest + + // 按照一个或者多个实例ID查询,可通过[DescribeInstances](https://cloud.tencent.com/document/api/213/9388)API返回值中的InstanceId获取。实例ID形如:ins-xxxxxxxx。(此参数的具体格式可参考API[简介](https://cloud.tencent.com/document/api/213/15688)的id.N一节)。每次请求的实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例操作。 + //
  • INSTANCE_DEGRADE:实例降配操作
  • + Operation *string `json:"Operation,omitempty" name:"Operation"` +} + +func (r *DescribeInstancesOperationLimitRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesOperationLimitRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesOperationLimitResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示调整配置操作(降配)限制次数查询。 + InstanceOperationLimitSet []*OperationCountLimit `json:"InstanceOperationLimitSet,omitempty" name:"InstanceOperationLimitSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstancesOperationLimitResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesOperationLimitResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesRequest struct { + *tchttp.BaseRequest + + // 按照一个或者多个实例ID查询。实例ID形如:`ins-xxxxxxxx`。(此参数的具体格式可参考API[简介](https://cloud.tencent.com/document/api/213/15688)的`id.N`一节)。每次请求的实例的上限为100。参数不支持同时指定`InstanceIds`和`Filters`。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 过滤条件。 + //
  • zone - String - 是否必填:否 -(过滤条件)按照可用区过滤。
  • + //
  • project-id - Integer - 是否必填:否 -(过滤条件)按照项目ID过滤。可通过调用[DescribeProject](https://cloud.tencent.com/document/api/378/4400)查询已创建的项目列表或登录[控制台](https://console.cloud.tencent.com/cvm/index)进行查看;也可以调用[AddProject](https://cloud.tencent.com/document/api/378/4398)创建新的项目。
  • + //
  • host-id - String - 是否必填:否 - (过滤条件)按照[CDH](https://cloud.tencent.com/document/product/416) ID过滤。[CDH](https://cloud.tencent.com/document/product/416) ID形如:host-xxxxxxxx。
  • + //
  • vpc-id - String - 是否必填:否 - (过滤条件)按照VPC ID进行过滤。VPC ID形如:vpc-xxxxxxxx。
  • + //
  • subnet-id - String - 是否必填:否 - (过滤条件)按照子网ID进行过滤。子网ID形如:subnet-xxxxxxxx。
  • + //
  • instance-id - String - 是否必填:否 - (过滤条件)按照实例ID过滤。实例ID形如:ins-xxxxxxxx。
  • + //
  • security-group-id - String - 是否必填:否 - (过滤条件)按照安全组ID过滤,安全组ID形如: sg-8jlk3f3r。
  • + //
  • instance-name - String - 是否必填:否 - (过滤条件)按照实例名称过滤。
  • + //
  • instance-charge-type - String - 是否必填:否 -(过滤条件)按照实例计费模式过滤。 (PREPAID:表示预付费,即包年包月 | POSTPAID_BY_HOUR:表示后付费,即按量计费 | CDHPAID:表示[CDH](https://cloud.tencent.com/document/product/416)付费,即只对[CDH](https://cloud.tencent.com/document/product/416)计费,不对[CDH](https://cloud.tencent.com/document/product/416)上的实例计费。 )
  • + //
  • private-ip-address - String - 是否必填:否 - (过滤条件)按照实例主网卡的内网IP过滤。
  • + //
  • public-ip-address - String - 是否必填:否 - (过滤条件)按照实例主网卡的公网IP过滤,包含实例创建时自动分配的IP和实例创建后手动绑定的弹性IP。
  • + //
  • tag-key - String - 是否必填:否 - (过滤条件)按照标签键进行过滤。
  • + //
  • tag-value - String - 是否必填:否 - (过滤条件)按照标签值进行过滤。
  • + //
  • tag:tag-key - String - 是否必填:否 - (过滤条件)按照标签键值对进行过滤。 tag-key使用具体的标签键进行替换。使用请参考示例2。
  • + // 每次请求的`Filters`的上限为10,`Filter.Values`的上限为5。参数不支持同时指定`InstanceIds`和`Filters`。 + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` + + // 偏移量,默认为0。关于`Offset`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Offset *int64 `json:"Offset,omitempty" name:"Offset"` + + // 返回数量,默认为20,最大值为100。关于`Limit`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Limit *int64 `json:"Limit,omitempty" name:"Limit"` +} + +func (r *DescribeInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 符合条件的实例数量。 + TotalCount *int64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 实例详细信息列表。 + InstanceSet []*Instance `json:"InstanceSet,omitempty" name:"InstanceSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesStatusRequest struct { + *tchttp.BaseRequest + + // 按照一个或者多个实例ID查询。实例ID形如:`ins-11112222`。此参数的具体格式可参考API[简介](https://cloud.tencent.com/document/api/213/15688)的`id.N`一节)。每次请求的实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 偏移量,默认为0。关于`Offset`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Offset *int64 `json:"Offset,omitempty" name:"Offset"` + + // 返回数量,默认为20,最大值为100。关于`Limit`的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Limit *int64 `json:"Limit,omitempty" name:"Limit"` +} + +func (r *DescribeInstancesStatusRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesStatusRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInstancesStatusResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 符合条件的实例状态数量。 + TotalCount *int64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // [实例状态](https://cloud.tencent.com/document/api/213/15738) 列表。 + InstanceStatusSet []*InstanceStatus `json:"InstanceStatusSet,omitempty" name:"InstanceStatusSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInstancesStatusResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInstancesStatusResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInternetChargeTypeConfigsRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeInternetChargeTypeConfigsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInternetChargeTypeConfigsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeInternetChargeTypeConfigsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 网络计费类型配置。 + InternetChargeTypeConfigSet []*InternetChargeTypeConfig `json:"InternetChargeTypeConfigSet,omitempty" name:"InternetChargeTypeConfigSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeInternetChargeTypeConfigsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeInternetChargeTypeConfigsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeKeyPairsRequest struct { + *tchttp.BaseRequest + + // 密钥对ID,密钥对ID形如:`skey-11112222`(此接口支持同时传入多个ID进行过滤。此参数的具体格式可参考 API [简介](https://cloud.tencent.com/document/api/213/15688)的 `id.N` 一节)。参数不支持同时指定 `KeyIds` 和 `Filters`。密钥对ID可以通过登录[控制台](https://console.cloud.tencent.com/cvm/index)查询。 + KeyIds []*string `json:"KeyIds,omitempty" name:"KeyIds" list` + + // 过滤条件。 + //
  • project-id - Integer - 是否必填:否 -(过滤条件)按照项目ID过滤。可以通过[项目列表](https://console.cloud.tencent.com/project)查询项目ID,或者调用接口 [DescribeProject](https://cloud.tencent.com/document/api/378/4400),取返回信息中的projectId获取项目ID。
  • + //
  • key-name - String - 是否必填:否 -(过滤条件)按照密钥对名称过滤。
  • 参数不支持同时指定 `KeyIds` 和 `Filters`。 + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` + + // 偏移量,默认为0。关于 `Offset` 的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。返回数量,默认为20,最大值为100。关于 `Limit` 的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Offset *int64 `json:"Offset,omitempty" name:"Offset"` + + // 返回数量,默认为20,最大值为100。关于 `Limit` 的更进一步介绍请参考 API [简介](https://cloud.tencent.com/document/api/213/15688)中的相关小节。 + Limit *int64 `json:"Limit,omitempty" name:"Limit"` +} + +func (r *DescribeKeyPairsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeKeyPairsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeKeyPairsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 符合条件的密钥对数量。 + TotalCount *int64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 密钥对详细信息列表。 + KeyPairSet []*KeyPair `json:"KeyPairSet,omitempty" name:"KeyPairSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeKeyPairsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeKeyPairsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeRegionsRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeRegionsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeRegionsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeRegionsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 地域数量 + TotalCount *uint64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 地域列表信息 + RegionSet []*RegionInfo `json:"RegionSet,omitempty" name:"RegionSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeRegionsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeRegionsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeZoneInstanceConfigInfosRequest struct { + *tchttp.BaseRequest + + // 过滤条件。 + // + //
  • zone - String - 是否必填:否 -(过滤条件)按照可用区过滤。
  • + // + //
  • instance-family String - 是否必填:否 -(过滤条件)按照机型系列过滤。按照实例机型系列过滤。实例机型系列形如:S1、I1、M1等。
  • + // + //
  • instance-type - String - 是否必填:否 - (过滤条件)按照机型过滤。按照实例机型过滤。不同实例机型指定了不同的资源规格,具体取值可通过调用接口 DescribeInstanceTypeConfigs 来获得最新的规格表或参见实例类型描述。若不指定该参数,则默认机型为S1.SMALL1。
  • + // + //
  • instance-charge-type - String - 是否必填:否 -(过滤条件)按照实例计费模式过滤。 (PREPAID:表示预付费,即包年包月 | POSTPAID_BY_HOUR:表示后付费,即按量计费 | CDHPAID:表示CDH付费,即只对CDH计费,不对CDH上的实例计费。 )
  • + Filters []*Filter `json:"Filters,omitempty" name:"Filters" list` +} + +func (r *DescribeZoneInstanceConfigInfosRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeZoneInstanceConfigInfosRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeZoneInstanceConfigInfosResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 可用区机型配置列表。 + InstanceTypeQuotaSet []*InstanceTypeQuotaItem `json:"InstanceTypeQuotaSet,omitempty" name:"InstanceTypeQuotaSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeZoneInstanceConfigInfosResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeZoneInstanceConfigInfosResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeZonesRequest struct { + *tchttp.BaseRequest +} + +func (r *DescribeZonesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeZonesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DescribeZonesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 可用区数量。 + TotalCount *uint64 `json:"TotalCount,omitempty" name:"TotalCount"` + + // 可用区列表信息。 + ZoneSet []*ZoneInfo `json:"ZoneSet,omitempty" name:"ZoneSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DescribeZonesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DescribeZonesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DisassociateInstancesKeyPairsRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID,每次请求批量实例的上限为100。

    可以通过以下方式获取可用的实例ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/index)查询实例ID。
  • 通过调用接口 [DescribeInstances](https://cloud.tencent.com/document/api/213/15728) ,取返回信息中的 `InstanceId` 获取实例ID。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 密钥对ID列表,每次请求批量密钥对的上限为100。密钥对ID形如:`skey-11112222`。

    可以通过以下方式获取可用的密钥ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/sshkey)查询密钥ID。
  • 通过调用接口 [DescribeKeyPairs](https://cloud.tencent.com/document/api/213/15699) ,取返回信息中的 `KeyId` 获取密钥对ID。 + KeyIds []*string `json:"KeyIds,omitempty" name:"KeyIds" list` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再解绑密钥。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机。
  • FALSE:表示在正常关机失败后不进行强制关机。

    默认取值:FALSE。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *DisassociateInstancesKeyPairsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DisassociateInstancesKeyPairsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DisassociateInstancesKeyPairsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DisassociateInstancesKeyPairsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DisassociateInstancesKeyPairsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DisassociateSecurityGroupsRequest struct { + *tchttp.BaseRequest + + // 要解绑的`安全组ID`,类似sg-efil73jd,只支持解绑单个安全组。 + SecurityGroupIds []*string `json:"SecurityGroupIds,omitempty" name:"SecurityGroupIds" list` + + // 被解绑的`实例ID`,类似ins-lesecurk,支持指定多个实例 。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` +} + +func (r *DisassociateSecurityGroupsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DisassociateSecurityGroupsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DisassociateSecurityGroupsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *DisassociateSecurityGroupsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *DisassociateSecurityGroupsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type DisasterRecoverGroup struct { + + // 分散置放群组id。 + DisasterRecoverGroupId *string `json:"DisasterRecoverGroupId,omitempty" name:"DisasterRecoverGroupId"` + + // 分散置放群组名称,长度1-60个字符。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 分散置放群组类型,取值范围:
  • HOST:物理机
  • SW:交换机
  • RACK:机架 + Type *string `json:"Type,omitempty" name:"Type"` + + // 分散置放群组内最大容纳云主机数量。 + CvmQuotaTotal *int64 `json:"CvmQuotaTotal,omitempty" name:"CvmQuotaTotal"` + + // 分散置放群组内云主机当前数量。 + CurrentNum *int64 `json:"CurrentNum,omitempty" name:"CurrentNum"` + + // 分散置放群组内,云主机id列表。 + // 注意:此字段可能返回 null,表示取不到有效值。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 分散置放群组创建时间。 + // 注意:此字段可能返回 null,表示取不到有效值。 + CreateTime *string `json:"CreateTime,omitempty" name:"CreateTime"` +} + +type EnhancedService struct { + + // 开启云安全服务。若不指定该参数,则默认开启云安全服务。 + SecurityService *RunSecurityServiceEnabled `json:"SecurityService,omitempty" name:"SecurityService"` + + // 开启云监控服务。若不指定该参数,则默认开启云监控服务。 + MonitorService *RunMonitorServiceEnabled `json:"MonitorService,omitempty" name:"MonitorService"` +} + +type Externals struct { + + // 释放地址 + // 注意:此字段可能返回 null,表示取不到有效值。 + ReleaseAddress *bool `json:"ReleaseAddress,omitempty" name:"ReleaseAddress"` + + // 不支持的网络类型 + // 注意:此字段可能返回 null,表示取不到有效值。 + UnsupportNetworks []*string `json:"UnsupportNetworks,omitempty" name:"UnsupportNetworks" list` + + // HDD本地存储属性 + // 注意:此字段可能返回 null,表示取不到有效值。 + StorageBlockAttr *StorageBlock `json:"StorageBlockAttr,omitempty" name:"StorageBlockAttr"` +} + +type Filter struct { + + // 需要过滤的字段。 + Name *string `json:"Name,omitempty" name:"Name"` + + // 字段的过滤值。 + Values []*string `json:"Values,omitempty" name:"Values" list` +} + +type HostItem struct { + + // cdh实例所在的位置。通过该参数可以指定实例所属可用区,所属项目等属性。 + Placement *Placement `json:"Placement,omitempty" name:"Placement"` + + // cdh实例id + HostId *string `json:"HostId,omitempty" name:"HostId"` + + // cdh实例类型 + HostType *string `json:"HostType,omitempty" name:"HostType"` + + // cdh实例名称 + HostName *string `json:"HostName,omitempty" name:"HostName"` + + // cdh实例付费模式 + HostChargeType *string `json:"HostChargeType,omitempty" name:"HostChargeType"` + + // cdh实例自动续费标记 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` + + // cdh实例创建时间 + CreatedTime *string `json:"CreatedTime,omitempty" name:"CreatedTime"` + + // cdh实例过期时间 + ExpiredTime *string `json:"ExpiredTime,omitempty" name:"ExpiredTime"` + + // cdh实例上已创建云子机的实例id列表 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // cdh实例状态 + HostState *string `json:"HostState,omitempty" name:"HostState"` + + // cdh实例ip + HostIp *string `json:"HostIp,omitempty" name:"HostIp"` + + // cdh实例资源信息 + HostResource *HostResource `json:"HostResource,omitempty" name:"HostResource"` + + // 专用宿主机所属的围笼ID。该字段仅对金融专区围笼内的专用宿主机有效。 + // 注意:此字段可能返回 null,表示取不到有效值。 + CageId *string `json:"CageId,omitempty" name:"CageId"` +} + +type HostResource struct { + + // cdh实例总cpu核数 + CpuTotal *uint64 `json:"CpuTotal,omitempty" name:"CpuTotal"` + + // cdh实例可用cpu核数 + CpuAvailable *uint64 `json:"CpuAvailable,omitempty" name:"CpuAvailable"` + + // cdh实例总内存大小(单位为:GiB) + MemTotal *float64 `json:"MemTotal,omitempty" name:"MemTotal"` + + // cdh实例可用内存大小(单位为:GiB) + MemAvailable *float64 `json:"MemAvailable,omitempty" name:"MemAvailable"` + + // cdh实例总磁盘大小(单位为:GiB) + DiskTotal *uint64 `json:"DiskTotal,omitempty" name:"DiskTotal"` + + // cdh实例可用磁盘大小(单位为:GiB) + DiskAvailable *uint64 `json:"DiskAvailable,omitempty" name:"DiskAvailable"` +} + +type Image struct { + + // 镜像ID + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 镜像操作系统 + OsName *string `json:"OsName,omitempty" name:"OsName"` + + // 镜像类型 + ImageType *string `json:"ImageType,omitempty" name:"ImageType"` + + // 镜像创建时间 + CreatedTime *string `json:"CreatedTime,omitempty" name:"CreatedTime"` + + // 镜像名称 + ImageName *string `json:"ImageName,omitempty" name:"ImageName"` + + // 镜像描述 + ImageDescription *string `json:"ImageDescription,omitempty" name:"ImageDescription"` + + // 镜像大小 + ImageSize *int64 `json:"ImageSize,omitempty" name:"ImageSize"` + + // 镜像架构 + Architecture *string `json:"Architecture,omitempty" name:"Architecture"` + + // 镜像状态 + ImageState *string `json:"ImageState,omitempty" name:"ImageState"` + + // 镜像来源平台 + Platform *string `json:"Platform,omitempty" name:"Platform"` + + // 镜像创建者 + ImageCreator *string `json:"ImageCreator,omitempty" name:"ImageCreator"` + + // 镜像来源 + ImageSource *string `json:"ImageSource,omitempty" name:"ImageSource"` + + // 同步百分比 + // 注意:此字段可能返回 null,表示取不到有效值。 + SyncPercent *int64 `json:"SyncPercent,omitempty" name:"SyncPercent"` + + // 镜像是否支持cloud-init + // 注意:此字段可能返回 null,表示取不到有效值。 + IsSupportCloudinit *bool `json:"IsSupportCloudinit,omitempty" name:"IsSupportCloudinit"` + + // 镜像关联的快照信息 + // 注意:此字段可能返回 null,表示取不到有效值。 + SnapshotSet []*Snapshot `json:"SnapshotSet,omitempty" name:"SnapshotSet" list` +} + +type ImageOsList struct { + + // 支持的windows操作系统。 + // 注意:此字段可能返回 null,表示取不到有效值。 + Windows []*string `json:"Windows,omitempty" name:"Windows" list` + + // 支持的linux操作系统 + // 注意:此字段可能返回 null,表示取不到有效值。 + Linux []*string `json:"Linux,omitempty" name:"Linux" list` +} + +type ImportImageRequest struct { + *tchttp.BaseRequest + + // 导入镜像的操作系统架构,`x86_64` 或 `i386` + Architecture *string `json:"Architecture,omitempty" name:"Architecture"` + + // 导入镜像的操作系统类型,通过`DescribeImportImageOs`获取 + OsType *string `json:"OsType,omitempty" name:"OsType"` + + // 导入镜像的操作系统版本,通过`DescribeImportImageOs`获取 + OsVersion *string `json:"OsVersion,omitempty" name:"OsVersion"` + + // 导入镜像存放的cos地址 + ImageUrl *string `json:"ImageUrl,omitempty" name:"ImageUrl"` + + // 镜像名称 + ImageName *string `json:"ImageName,omitempty" name:"ImageName"` + + // 镜像描述 + ImageDescription *string `json:"ImageDescription,omitempty" name:"ImageDescription"` + + // 只检查参数,不执行任务 + DryRun *bool `json:"DryRun,omitempty" name:"DryRun"` + + // 是否强制导入,参考[强制导入镜像](https://cloud.tencent.com/document/product/213/12849) + Force *bool `json:"Force,omitempty" name:"Force"` +} + +func (r *ImportImageRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ImportImageRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ImportImageResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ImportImageResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ImportImageResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ImportKeyPairRequest struct { + *tchttp.BaseRequest + + // 密钥对名称,可由数字,字母和下划线组成,长度不超过25个字符。 + KeyName *string `json:"KeyName,omitempty" name:"KeyName"` + + // 密钥对创建后所属的[项目](/document/product/378/10863)ID。

    可以通过以下方式获取项目ID:
  • 通过[项目列表](https://console.cloud.tencent.com/project)查询项目ID。
  • 通过调用接口 [DescribeProject](https://cloud.tencent.com/document/api/378/4400),取返回信息中的 `projectId ` 获取项目ID。 + // + // 如果是默认项目,直接填0就可以。 + ProjectId *int64 `json:"ProjectId,omitempty" name:"ProjectId"` + + // 密钥对的公钥内容,`OpenSSH RSA` 格式。 + PublicKey *string `json:"PublicKey,omitempty" name:"PublicKey"` +} + +func (r *ImportKeyPairRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ImportKeyPairRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ImportKeyPairResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 密钥对ID。 + KeyId *string `json:"KeyId,omitempty" name:"KeyId"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ImportKeyPairResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ImportKeyPairResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceModifyInstancesChargeTypeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例[计费类型](https://cloud.tencent.com/document/product/213/2180)。
  • PREPAID:预付费,即包年包月。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的续费时长、是否设置自动续费等属性。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` +} + +func (r *InquiryPriceModifyInstancesChargeTypeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceModifyInstancesChargeTypeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceModifyInstancesChargeTypeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示对应配置实例转换计费模式的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceModifyInstancesChargeTypeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceModifyInstancesChargeTypeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceRenewInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的续费时长、是否设置自动续费等属性。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` + + // 试运行。 + DryRun *bool `json:"DryRun,omitempty" name:"DryRun"` + + // 是否续费弹性数据盘。取值范围:
  • TRUE:表示续费包年包月实例同时续费其挂载的弹性数据盘
  • FALSE:表示续费包年包月实例同时不再续费其挂载的弹性数据盘

    默认取值:TRUE。 + RenewPortableDataDisk *bool `json:"RenewPortableDataDisk,omitempty" name:"RenewPortableDataDisk"` +} + +func (r *InquiryPriceRenewInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceRenewInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceRenewInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示对应配置实例的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceRenewInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceRenewInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstanceRequest struct { + *tchttp.BaseRequest + + // 实例ID。可通过 [DescribeInstances](https://cloud.tencent.com/document/api/213/15728) API返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 指定有效的[镜像](/document/product/213/4940)ID,格式形如`img-xxx`。镜像类型分为四种:
  • 公共镜像
  • 自定义镜像
  • 共享镜像
  • 服务市场镜像

  • 可通过以下方式获取可用的镜像ID:
  • `公共镜像`、`自定义镜像`、`共享镜像`的镜像ID可通过登录[控制台](https://console.cloud.tencent.com/cvm/image?rid=1&imageType=PUBLIC_IMAGE)查询;`服务镜像市场`的镜像ID可通过[云市场](https://market.cloud.tencent.com/list)查询。
  • 通过调用接口 [DescribeImages](https://cloud.tencent.com/document/api/213/15715) ,取返回信息中的`ImageId`字段。
  • + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 实例系统盘配置信息。系统盘为云盘的实例可以通过该参数指定重装后的系统盘大小来实现对系统盘的扩容操作,若不指定则默认系统盘大小保持不变。系统盘大小只支持扩容不支持缩容;重装只支持修改系统盘的大小,不能修改系统盘的类型。 + SystemDisk *SystemDisk `json:"SystemDisk,omitempty" name:"SystemDisk"` + + // 实例登录设置。通过该参数可以设置实例的登录方式密码、密钥或保持镜像的原始登录设置。默认情况下会随机生成密码,并以站内信方式知会到用户。 + LoginSettings *LoginSettings `json:"LoginSettings,omitempty" name:"LoginSettings"` + + // 增强服务。通过该参数可以指定是否开启云安全、云监控等服务。若不指定该参数,则默认开启云监控、云安全服务。 + EnhancedService *EnhancedService `json:"EnhancedService,omitempty" name:"EnhancedService"` +} + +func (r *InquiryPriceResetInstanceRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstanceRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstanceResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示重装成对应配置实例的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceResetInstanceResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstanceResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstancesInternetMaxBandwidthRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。当调整 `BANDWIDTH_PREPAID` 和 `BANDWIDTH_POSTPAID_BY_HOUR` 计费方式的带宽时,只支持一个实例。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 公网出带宽配置。不同机型带宽上限范围不一致,具体限制详见带宽限制对账表。暂时只支持`InternetMaxBandwidthOut`参数。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` + + // 带宽生效的起始时间。格式:`YYYY-MM-DD`,例如:`2016-10-30`。起始时间不能早于当前时间。如果起始时间是今天则新设置的带宽立即生效。该参数只对包年包月带宽有效,其他模式带宽不支持该参数,否则接口会以相应错误码返回。 + StartTime *string `json:"StartTime,omitempty" name:"StartTime"` + + // 带宽生效的终止时间。格式:`YYYY-MM-DD`,例如:`2016-10-30`。新设置的带宽的有效期包含终止时间此日期。终止时间不能晚于包年包月实例的到期时间。实例的到期时间可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`ExpiredTime`获取。该参数只对包年包月带宽有效,其他模式带宽不支持该参数,否则接口会以相应错误码返回。 + EndTime *string `json:"EndTime,omitempty" name:"EndTime"` +} + +func (r *InquiryPriceResetInstancesInternetMaxBandwidthRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstancesInternetMaxBandwidthRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstancesInternetMaxBandwidthResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示带宽调整为对应大小之后的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceResetInstancesInternetMaxBandwidthResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstancesInternetMaxBandwidthResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstancesTypeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为1。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例机型。不同实例机型指定了不同的资源规格,具体取值可参见附表实例资源规格对照表,也可以调用查询实例资源规格列表接口获得最新的规格表。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` +} + +func (r *InquiryPriceResetInstancesTypeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstancesTypeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResetInstancesTypeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示调整成对应机型实例的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceResetInstancesTypeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResetInstancesTypeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResizeInstanceDisksRequest struct { + *tchttp.BaseRequest + + // 待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 待扩容的数据盘配置信息。只支持扩容非弹性数据盘([`DescribeDisks`](https://cloud.tencent.com/document/api/362/16315)接口返回值中的`Portable`为`false`表示非弹性),且[数据盘类型](/document/api/213/9452#block_device)为:`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`。数据盘容量单位:GB。最小扩容步长:10G。关于数据盘类型的选择请参考硬盘产品简介。可选数据盘类型受到实例类型`InstanceType`限制。另外允许扩容的最大容量也因数据盘类型的不同而有所差异。 + DataDisks []*DataDisk `json:"DataDisks,omitempty" name:"DataDisks" list` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再重置用户密码。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机
  • FALSE:表示在正常关机失败后不进行强制关机

    默认取值:FALSE。

    强制关机的效果等同于关闭物理计算机的电源开关。强制关机可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常关机时使用。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *InquiryPriceResizeInstanceDisksRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResizeInstanceDisksRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceResizeInstanceDisksResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示磁盘扩容成对应配置的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceResizeInstanceDisksResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceResizeInstanceDisksResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceRunInstancesRequest struct { + *tchttp.BaseRequest + + // 实例所在的位置。通过该参数可以指定实例所属可用区,所属项目等属性。 + Placement *Placement `json:"Placement,omitempty" name:"Placement"` + + // 指定有效的[镜像](https://cloud.tencent.com/document/product/213/4940)ID,格式形如`img-xxx`。镜像类型分为四种:
  • 公共镜像
  • 自定义镜像
  • 共享镜像
  • 服务市场镜像

  • 可通过以下方式获取可用的镜像ID:
  • `公共镜像`、`自定义镜像`、`共享镜像`的镜像ID可通过登录[控制台](https://console.cloud.tencent.com/cvm/image?rid=1&imageType=PUBLIC_IMAGE)查询;`服务镜像市场`的镜像ID可通过[云市场](https://market.cloud.tencent.com/list)查询。
  • 通过调用接口 [DescribeImages](https://cloud.tencent.com/document/api/213/15715) ,取返回信息中的`ImageId`字段。
  • + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 实例[计费类型](https://cloud.tencent.com/document/product/213/2180)。
  • PREPAID:预付费,即包年包月
  • POSTPAID_BY_HOUR:按小时后付费
    默认值:POSTPAID_BY_HOUR。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长、是否设置自动续费等属性。若指定实例的付费模式为预付费则该参数必传。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` + + // 实例机型。不同实例机型指定了不同的资源规格,具体取值可通过调用接口[DescribeInstanceTypeConfigs](https://cloud.tencent.com/document/api/213/15749)来获得最新的规格表或参见[CVM实例配置](https://cloud.tencent.com/document/product/213/2177)描述。若不指定该参数,则默认机型为S1.SMALL1。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 实例系统盘配置信息。若不指定该参数,则按照系统默认值进行分配。 + SystemDisk *SystemDisk `json:"SystemDisk,omitempty" name:"SystemDisk"` + + // 实例数据盘配置信息。若不指定该参数,则默认不购买数据盘。支持购买的时候指定11块数据盘,其中最多包含1块LOCAL_BASIC数据盘或者LOCAL_SSD数据盘,最多包含10块CLOUD_BASIC数据盘、CLOUD_PREMIUM数据盘或者CLOUD_SSD数据盘。 + DataDisks []*DataDisk `json:"DataDisks,omitempty" name:"DataDisks" list` + + // 私有网络相关信息配置。通过该参数可以指定私有网络的ID,子网ID等信息。若不指定该参数,则默认使用基础网络。若在此参数中指定了私有网络ip,那么InstanceCount参数只能为1。 + VirtualPrivateCloud *VirtualPrivateCloud `json:"VirtualPrivateCloud,omitempty" name:"VirtualPrivateCloud"` + + // 公网带宽相关信息设置。若不指定该参数,则默认公网带宽为0Mbps。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` + + // 购买实例数量。取值范围:[1,100]。默认取值:1。指定购买实例的数量不能超过用户所能购买的剩余配额数量,具体配额相关限制详见[CVM实例购买限制](https://cloud.tencent.com/document/product/213/2664)。 + InstanceCount *int64 `json:"InstanceCount,omitempty" name:"InstanceCount"` + + // 实例显示名称。
  • 不指定实例显示名称则默认显示‘未命名’。
  • 购买多台实例,如果指定模式串`{R:x}`,表示生成数字`[x, x+n-1]`,其中`n`表示购买实例的数量,例如`server_{R:3}`,购买1台时,实例显示名称为`server_3`;购买2台时,实例显示名称分别为`server_3`,`server_4`。支持指定多个模式串`{R:x}`。
  • 购买多台实例,如果不指定模式串,则在实例显示名称添加后缀`1、2...n`,其中`n`表示购买实例的数量,例如`server_`,购买2台时,实例显示名称分别为`server_1`,`server_2`。 + InstanceName *string `json:"InstanceName,omitempty" name:"InstanceName"` + + // 实例登录设置。通过该参数可以设置实例的登录方式密码、密钥或保持镜像的原始登录设置。默认情况下会随机生成密码,并以站内信方式知会到用户。 + LoginSettings *LoginSettings `json:"LoginSettings,omitempty" name:"LoginSettings"` + + // 实例所属安全组。该参数可以通过调用 [DescribeSecurityGroups](https://cloud.tencent.com/document/api/215/15808) 的返回值中的sgId字段来获取。若不指定该参数,则默认不绑定安全组。 + SecurityGroupIds []*string `json:"SecurityGroupIds,omitempty" name:"SecurityGroupIds" list` + + // 增强服务。通过该参数可以指定是否开启云安全、云监控等服务。若不指定该参数,则默认开启云监控、云安全服务。 + EnhancedService *EnhancedService `json:"EnhancedService,omitempty" name:"EnhancedService"` + + // 用于保证请求幂等性的字符串。该字符串由客户生成,需保证不同请求之间唯一,最大值不超过64个ASCII字符。若不指定该参数,则无法保证请求的幂等性。
    更多详细信息请参阅:如何保证幂等性。 + ClientToken *string `json:"ClientToken,omitempty" name:"ClientToken"` + + // 云服务器的主机名。
  • 点号(.)和短横线(-)不能作为 HostName 的首尾字符,不能连续使用。
  • Windows 实例:名字符长度为[2, 15],允许字母(不限制大小写)、数字和短横线(-)组成,不支持点号(.),不能全是数字。
  • 其他类型(Linux 等)实例:字符长度为[2, 30],允许支持多个点号,点之间为一段,每段允许字母(不限制大小写)、数字和短横线(-)组成。 + HostName *string `json:"HostName,omitempty" name:"HostName"` + + // 标签描述列表。通过指定该参数可以同时绑定标签到相应的资源实例,当前仅支持绑定标签到云主机实例。 + TagSpecification []*TagSpecification `json:"TagSpecification,omitempty" name:"TagSpecification" list` + + // 实例的市场相关选项,如竞价实例相关参数 + InstanceMarketOptions *InstanceMarketOptionsRequest `json:"InstanceMarketOptions,omitempty" name:"InstanceMarketOptions"` +} + +func (r *InquiryPriceRunInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceRunInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InquiryPriceRunInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 该参数表示对应配置实例的价格。 + Price *Price `json:"Price,omitempty" name:"Price"` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *InquiryPriceRunInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InquiryPriceRunInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type Instance struct { + + // 实例所在的位置。 + Placement *Placement `json:"Placement,omitempty" name:"Placement"` + + // 实例`ID`。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 实例机型。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 实例的CPU核数,单位:核。 + CPU *int64 `json:"CPU,omitempty" name:"CPU"` + + // 实例内存容量,单位:`GB`。 + Memory *int64 `json:"Memory,omitempty" name:"Memory"` + + // 实例业务状态。取值范围:
  • NORMAL:表示正常状态的实例
  • EXPIRED:表示过期的实例
  • PROTECTIVELY_ISOLATED:表示被安全隔离的实例。 + RestrictState *string `json:"RestrictState,omitempty" name:"RestrictState"` + + // 实例名称。 + InstanceName *string `json:"InstanceName,omitempty" name:"InstanceName"` + + // 实例计费模式。取值范围:
  • `PREPAID`:表示预付费,即包年包月
  • `POSTPAID_BY_HOUR`:表示后付费,即按量计费
  • `CDHPAID`:`CDH`付费,即只对`CDH`计费,不对`CDH`上的实例计费。
  • `SPOTPAID`:表示竞价实例付费。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 实例系统盘信息。 + SystemDisk *SystemDisk `json:"SystemDisk,omitempty" name:"SystemDisk"` + + // 实例数据盘信息。只包含随实例购买的数据盘。 + DataDisks []*DataDisk `json:"DataDisks,omitempty" name:"DataDisks" list` + + // 实例主网卡的内网`IP`列表。 + PrivateIpAddresses []*string `json:"PrivateIpAddresses,omitempty" name:"PrivateIpAddresses" list` + + // 实例主网卡的公网`IP`列表。 + // 注意:此字段可能返回 null,表示取不到有效值。 + PublicIpAddresses []*string `json:"PublicIpAddresses,omitempty" name:"PublicIpAddresses" list` + + // 实例带宽信息。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` + + // 实例所属虚拟私有网络信息。 + VirtualPrivateCloud *VirtualPrivateCloud `json:"VirtualPrivateCloud,omitempty" name:"VirtualPrivateCloud"` + + // 生产实例所使用的镜像`ID`。 + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 自动续费标识。取值范围:
  • `NOTIFY_AND_MANUAL_RENEW`:表示通知即将过期,但不自动续费
  • `NOTIFY_AND_AUTO_RENEW`:表示通知即将过期,而且自动续费
  • `DISABLE_NOTIFY_AND_MANUAL_RENEW`:表示不通知即将过期,也不自动续费。 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` + + // 创建时间。按照`ISO8601`标准表示,并且使用`UTC`时间。格式为:`YYYY-MM-DDThh:mm:ssZ`。 + CreatedTime *string `json:"CreatedTime,omitempty" name:"CreatedTime"` + + // 到期时间。按照`ISO8601`标准表示,并且使用`UTC`时间。格式为:`YYYY-MM-DDThh:mm:ssZ`。 + ExpiredTime *string `json:"ExpiredTime,omitempty" name:"ExpiredTime"` + + // 操作系统名称。 + OsName *string `json:"OsName,omitempty" name:"OsName"` + + // 实例所属安全组。该参数可以通过调用 [DescribeSecurityGroups](https://cloud.tencent.com/document/api/215/15808) 的返回值中的sgId字段来获取。 + SecurityGroupIds []*string `json:"SecurityGroupIds,omitempty" name:"SecurityGroupIds" list` + + // 实例登录设置。目前只返回实例所关联的密钥。 + LoginSettings *LoginSettings `json:"LoginSettings,omitempty" name:"LoginSettings"` + + // 实例状态。取值范围:
  • PENDING:表示创建中
  • LAUNCH_FAILED:表示创建失败
  • RUNNING:表示运行中
  • STOPPED:表示关机
  • STARTING:表示开机中
  • STOPPING:表示关机中
  • REBOOTING:表示重启中
  • SHUTDOWN:表示停止待销毁
  • TERMINATING:表示销毁中。
  • + InstanceState *string `json:"InstanceState,omitempty" name:"InstanceState"` + + // 实例关联的标签列表。 + Tags []*Tag `json:"Tags,omitempty" name:"Tags" list` + + // 实例的关机计费模式。 + // 取值范围:
  • KEEP_CHARGING:关机继续收费
  • STOP_CHARGING:关机停止收费
  • NOT_APPLICABLE:实例处于非关机状态或者不适用关机停止计费的条件
    + StopChargingMode *string `json:"StopChargingMode,omitempty" name:"StopChargingMode"` +} + +type InstanceChargePrepaid struct { + + // 购买实例的时长,单位:月。取值范围:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36。 + Period *int64 `json:"Period,omitempty" name:"Period"` + + // 自动续费标识。取值范围:
  • NOTIFY_AND_AUTO_RENEW:通知过期且自动续费
  • NOTIFY_AND_MANUAL_RENEW:通知过期不自动续费
  • DISABLE_NOTIFY_AND_MANUAL_RENEW:不通知过期不自动续费

    默认取值:NOTIFY_AND_MANUAL_RENEW。若该参数指定为NOTIFY_AND_AUTO_RENEW,在账户余额充足的情况下,实例到期后将按月自动续费。 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` +} + +type InstanceFamilyConfig struct { + + // 机型族名称的中文全称。 + InstanceFamilyName *string `json:"InstanceFamilyName,omitempty" name:"InstanceFamilyName"` + + // 机型族名称的英文简称。 + InstanceFamily *string `json:"InstanceFamily,omitempty" name:"InstanceFamily"` +} + +type InstanceMarketOptionsRequest struct { + *tchttp.BaseRequest + + // 竞价相关选项 + SpotOptions *SpotMarketOptions `json:"SpotOptions,omitempty" name:"SpotOptions"` + + // 市场选项类型,当前只支持取值:spot + MarketType *string `json:"MarketType,omitempty" name:"MarketType"` +} + +func (r *InstanceMarketOptionsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *InstanceMarketOptionsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type InstanceStatus struct { + + // 实例`ID`。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // [实例状态](/document/api/213/9452#INSTANCE_STATE)。 + InstanceState *string `json:"InstanceState,omitempty" name:"InstanceState"` +} + +type InstanceTypeConfig struct { + + // 可用区。 + Zone *string `json:"Zone,omitempty" name:"Zone"` + + // 实例机型。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 实例机型系列。 + InstanceFamily *string `json:"InstanceFamily,omitempty" name:"InstanceFamily"` + + // GPU核数,单位:核。 + GPU *int64 `json:"GPU,omitempty" name:"GPU"` + + // CPU核数,单位:核。 + CPU *int64 `json:"CPU,omitempty" name:"CPU"` + + // 内存容量,单位:`GB`。 + Memory *int64 `json:"Memory,omitempty" name:"Memory"` +} + +type InstanceTypeQuotaItem struct { + + // 可用区。 + Zone *string `json:"Zone,omitempty" name:"Zone"` + + // 实例机型。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 实例计费模式。取值范围:
  • PREPAID:表示预付费,即包年包月
  • POSTPAID_BY_HOUR:表示后付费,即按量计费
  • CDHPAID:表示[CDH](https://cloud.tencent.com/document/product/416)付费,即只对CDH计费,不对CDH上的实例计费。
  • `SPOTPAID`:表示竞价实例付费。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 网卡类型,例如:25代表25G网卡 + NetworkCard *int64 `json:"NetworkCard,omitempty" name:"NetworkCard"` + + // 扩展属性。 + // 注意:此字段可能返回 null,表示取不到有效值。 + Externals *Externals `json:"Externals,omitempty" name:"Externals"` + + // 实例的CPU核数,单位:核。 + Cpu *int64 `json:"Cpu,omitempty" name:"Cpu"` + + // 实例内存容量,单位:`GB`。 + Memory *int64 `json:"Memory,omitempty" name:"Memory"` + + // 实例机型系列。 + InstanceFamily *string `json:"InstanceFamily,omitempty" name:"InstanceFamily"` + + // 机型名称。 + TypeName *string `json:"TypeName,omitempty" name:"TypeName"` + + // 本地磁盘规格列表。当该参数返回为空值时,表示当前情况下无法创建本地盘。 + LocalDiskTypeList []*LocalDiskType `json:"LocalDiskTypeList,omitempty" name:"LocalDiskTypeList" list` + + // 实例是否售卖。取值范围:
  • SELL:表示实例可购买
  • SOLD_OUT:表示实例已售罄。 + Status *string `json:"Status,omitempty" name:"Status"` + + // 实例的售卖价格。 + Price *ItemPrice `json:"Price,omitempty" name:"Price"` +} + +type InternetAccessible struct { + + // 网络计费类型。取值范围:
  • BANDWIDTH_PREPAID:预付费按带宽结算
  • TRAFFIC_POSTPAID_BY_HOUR:流量按小时后付费
  • BANDWIDTH_POSTPAID_BY_HOUR:带宽按小时后付费
  • BANDWIDTH_PACKAGE:带宽包用户
    默认取值:非带宽包用户默认与子机付费类型保持一致。 + InternetChargeType *string `json:"InternetChargeType,omitempty" name:"InternetChargeType"` + + // 公网出带宽上限,单位:Mbps。默认值:0Mbps。不同机型带宽上限范围不一致,具体限制详见[购买网络带宽](/document/product/213/509)。 + InternetMaxBandwidthOut *int64 `json:"InternetMaxBandwidthOut,omitempty" name:"InternetMaxBandwidthOut"` + + // 是否分配公网IP。取值范围:
  • TRUE:表示分配公网IP
  • FALSE:表示不分配公网IP

    当公网带宽大于0Mbps时,可自由选择开通与否,默认开通公网IP;当公网带宽为0,则不允许分配公网IP。 + PublicIpAssigned *bool `json:"PublicIpAssigned,omitempty" name:"PublicIpAssigned"` + + // 带宽包ID。可通过[`DescribeBandwidthPackages`](https://cloud.tencent.com/document/api/215/19209)接口返回值中的`BandwidthPackageId`获取。 + BandwidthPackageId *string `json:"BandwidthPackageId,omitempty" name:"BandwidthPackageId"` +} + +type InternetBandwidthConfig struct { + + // 开始时间。按照`ISO8601`标准表示,并且使用`UTC`时间。格式为:`YYYY-MM-DDThh:mm:ssZ`。 + StartTime *string `json:"StartTime,omitempty" name:"StartTime"` + + // 结束时间。按照`ISO8601`标准表示,并且使用`UTC`时间。格式为:`YYYY-MM-DDThh:mm:ssZ`。 + EndTime *string `json:"EndTime,omitempty" name:"EndTime"` + + // 实例带宽信息。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` +} + +type InternetChargeTypeConfig struct { + + // 网络计费模式。 + InternetChargeType *string `json:"InternetChargeType,omitempty" name:"InternetChargeType"` + + // 网络计费模式描述信息。 + Description *string `json:"Description,omitempty" name:"Description"` +} + +type ItemPrice struct { + + // 后续单价,单位:元。 + // 注意:此字段可能返回 null,表示取不到有效值。 + UnitPrice *float64 `json:"UnitPrice,omitempty" name:"UnitPrice"` + + // 后续计价单元,可取值范围:
  • HOUR:表示计价单元是按每小时来计算。当前涉及该计价单元的场景有:实例按小时后付费(POSTPAID_BY_HOUR)、带宽按小时后付费(BANDWIDTH_POSTPAID_BY_HOUR):
  • GB:表示计价单元是按每GB来计算。当前涉及该计价单元的场景有:流量按小时后付费(TRAFFIC_POSTPAID_BY_HOUR)。 + // 注意:此字段可能返回 null,表示取不到有效值。 + ChargeUnit *string `json:"ChargeUnit,omitempty" name:"ChargeUnit"` + + // 预支费用的原价,单位:元。 + // 注意:此字段可能返回 null,表示取不到有效值。 + OriginalPrice *float64 `json:"OriginalPrice,omitempty" name:"OriginalPrice"` + + // 预支费用的折扣价,单位:元。 + // 注意:此字段可能返回 null,表示取不到有效值。 + DiscountPrice *float64 `json:"DiscountPrice,omitempty" name:"DiscountPrice"` +} + +type KeyPair struct { + + // 密钥对的`ID`,是密钥对的唯一标识。 + KeyId *string `json:"KeyId,omitempty" name:"KeyId"` + + // 密钥对名称。 + KeyName *string `json:"KeyName,omitempty" name:"KeyName"` + + // 密钥对所属的项目`ID`。 + ProjectId *int64 `json:"ProjectId,omitempty" name:"ProjectId"` + + // 密钥对描述信息。 + Description *string `json:"Description,omitempty" name:"Description"` + + // 密钥对的纯文本公钥。 + PublicKey *string `json:"PublicKey,omitempty" name:"PublicKey"` + + // 密钥对的纯文本私钥。腾讯云不会保管私钥,请用户自行妥善保存。 + PrivateKey *string `json:"PrivateKey,omitempty" name:"PrivateKey"` + + // 密钥关联的实例`ID`列表。 + AssociatedInstanceIds []*string `json:"AssociatedInstanceIds,omitempty" name:"AssociatedInstanceIds" list` + + // 创建时间。按照`ISO8601`标准表示,并且使用`UTC`时间。格式为:`YYYY-MM-DDThh:mm:ssZ`。 + CreatedTime *string `json:"CreatedTime,omitempty" name:"CreatedTime"` +} + +type LocalDiskType struct { + + // 本地磁盘类型。 + Type *string `json:"Type,omitempty" name:"Type"` + + // 本地磁盘属性。 + PartitionType *string `json:"PartitionType,omitempty" name:"PartitionType"` + + // 本地磁盘最小值。 + MinSize *int64 `json:"MinSize,omitempty" name:"MinSize"` + + // 本地磁盘最大值。 + MaxSize *int64 `json:"MaxSize,omitempty" name:"MaxSize"` +} + +type LoginSettings struct { + + // 实例登录密码。不同操作系统类型密码复杂度限制不一样,具体如下:
  • Linux实例密码必须8到16位,至少包括两项[a-z,A-Z]、[0-9] 和 [( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ' , . ? / ]中的特殊符号。
  • Windows实例密码必须12到16位,至少包括三项[a-z],[A-Z],[0-9] 和 [( ) ` ~ ! @ # $ % ^ & * - + = { } [ ] : ; ' , . ? /]中的特殊符号。

    若不指定该参数,则由系统随机生成密码,并通过站内信方式通知到用户。 + // 注意:此字段可能返回 null,表示取不到有效值。 + Password *string `json:"Password,omitempty" name:"Password"` + + // 密钥ID列表。关联密钥后,就可以通过对应的私钥来访问实例;KeyId可通过接口DescribeKeyPairs获取,密钥与密码不能同时指定,同时Windows操作系统不支持指定密钥。当前仅支持购买的时候指定一个密钥。 + // 注意:此字段可能返回 null,表示取不到有效值。 + KeyIds []*string `json:"KeyIds,omitempty" name:"KeyIds" list` + + // 保持镜像的原始设置。该参数与Password或KeyIds.N不能同时指定。只有使用自定义镜像、共享镜像或外部导入镜像创建实例时才能指定该参数为TRUE。取值范围:
  • TRUE:表示保持镜像的登录设置
  • FALSE:表示不保持镜像的登录设置

    默认取值:FALSE。 + // 注意:此字段可能返回 null,表示取不到有效值。 + KeepImageLogin *string `json:"KeepImageLogin,omitempty" name:"KeepImageLogin"` +} + +type ModifyDisasterRecoverGroupAttributeRequest struct { + *tchttp.BaseRequest + + // 分散置放群组ID,可使用[DescribeDisasterRecoverGroups](https://cloud.tencent.com/document/api/213/17810)接口获取。 + DisasterRecoverGroupId *string `json:"DisasterRecoverGroupId,omitempty" name:"DisasterRecoverGroupId"` + + // 分散置放群组名称,长度1-60个字符,支持中、英文。 + Name *string `json:"Name,omitempty" name:"Name"` +} + +func (r *ModifyDisasterRecoverGroupAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyDisasterRecoverGroupAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyDisasterRecoverGroupAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyDisasterRecoverGroupAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyDisasterRecoverGroupAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyHostsAttributeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的CDH实例ID。 + HostIds []*string `json:"HostIds,omitempty" name:"HostIds" list` + + // CDH实例显示名称。可任意命名,但不得超过60个字符。 + HostName *string `json:"HostName,omitempty" name:"HostName"` + + // 自动续费标识。取值范围:
  • NOTIFY_AND_AUTO_RENEW:通知过期且自动续费
  • NOTIFY_AND_MANUAL_RENEW:通知过期不自动续费
  • DISABLE_NOTIFY_AND_MANUAL_RENEW:不通知过期不自动续费

    若该参数指定为NOTIFY_AND_AUTO_RENEW,在账户余额充足的情况下,实例到期后将按月自动续费。 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` +} + +func (r *ModifyHostsAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyHostsAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyHostsAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyHostsAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyHostsAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyImageAttributeRequest struct { + *tchttp.BaseRequest + + // 镜像ID,形如`img-gvbnzy6f`。镜像ID可以通过如下方式获取:
  • 通过[DescribeImages](https://cloud.tencent.com/document/api/213/15715)接口返回的`ImageId`获取。
  • 通过[镜像控制台](https://console.cloud.tencent.com/cvm/image)获取。 + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 设置新的镜像名称;必须满足下列限制:
  • 不得超过20个字符。
  • 镜像名称不能与已有镜像重复。 + ImageName *string `json:"ImageName,omitempty" name:"ImageName"` + + // 设置新的镜像描述;必须满足下列限制:
  • 不得超过60个字符。 + ImageDescription *string `json:"ImageDescription,omitempty" name:"ImageDescription"` +} + +func (r *ModifyImageAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyImageAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyImageAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyImageAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyImageAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyImageSharePermissionRequest struct { + *tchttp.BaseRequest + + // 镜像ID,形如`img-gvbnzy6f`。镜像Id可以通过如下方式获取:
  • 通过[DescribeImages](https://cloud.tencent.com/document/api/213/15715)接口返回的`ImageId`获取。
  • 通过[镜像控制台](https://console.cloud.tencent.com/cvm/image)获取。
    镜像ID必须指定为状态为`NORMAL`的镜像。镜像状态请参考[镜像数据表](/document/api/213/9452#image_state)。 + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 接收分享镜像的账号Id列表,array型参数的格式可以参考[API简介](/document/api/213/568)。帐号ID不同于QQ号,查询用户帐号ID请查看[帐号信息](https://console.cloud.tencent.com/developer)中的帐号ID栏。 + AccountIds []*string `json:"AccountIds,omitempty" name:"AccountIds" list` + + // 操作,包括 `SHARE`,`CANCEL`。其中`SHARE`代表分享操作,`CANCEL`代表取消分享操作。 + Permission *string `json:"Permission,omitempty" name:"Permission"` +} + +func (r *ModifyImageSharePermissionRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyImageSharePermissionRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyImageSharePermissionResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyImageSharePermissionResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyImageSharePermissionResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesAttributeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388) API返回值中的`InstanceId`获取。每次请求允许操作的实例数量上限是100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例名称。可任意命名,但不得超过60个字符。 + InstanceName *string `json:"InstanceName,omitempty" name:"InstanceName"` + + // 指定实例的安全组Id列表,子机将重新关联指定列表的安全组,原本关联的安全组会被解绑。 + SecurityGroups []*string `json:"SecurityGroups,omitempty" name:"SecurityGroups" list` +} + +func (r *ModifyInstancesAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyInstancesAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesChargeTypeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例[计费类型](https://cloud.tencent.com/document/product/213/2180)。
  • PREPAID:预付费,即包年包月。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长、是否设置自动续费等属性。若指定实例的付费模式为预付费则该参数必传。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` +} + +func (r *ModifyInstancesChargeTypeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesChargeTypeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesChargeTypeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyInstancesChargeTypeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesChargeTypeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesProjectRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388) API返回值中的`InstanceId`获取。每次请求允许操作的实例数量上限是100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 项目ID。项目可以使用[AddProject](https://cloud.tencent.com/doc/api/403/4398)接口创建。后续使用[DescribeInstances](https://cloud.tencent.com/document/api/213/9388)接口查询实例时,项目ID可用于过滤结果。 + ProjectId *int64 `json:"ProjectId,omitempty" name:"ProjectId"` +} + +func (r *ModifyInstancesProjectRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesProjectRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesProjectResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyInstancesProjectResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesProjectResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesRenewFlagRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388) API返回值中的`InstanceId`获取。每次请求允许操作的实例数量上限是100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 自动续费标识。取值范围:
  • NOTIFY_AND_AUTO_RENEW:通知过期且自动续费
  • NOTIFY_AND_MANUAL_RENEW:通知过期不自动续费
  • DISABLE_NOTIFY_AND_MANUAL_RENEW:不通知过期不自动续费

    若该参数指定为NOTIFY_AND_AUTO_RENEW,在账户余额充足的情况下,实例到期后将按月自动续费。 + RenewFlag *string `json:"RenewFlag,omitempty" name:"RenewFlag"` +} + +func (r *ModifyInstancesRenewFlagRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesRenewFlagRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesRenewFlagResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyInstancesRenewFlagResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesRenewFlagResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesVpcAttributeRequest struct { + *tchttp.BaseRequest + + // 待操作的实例ID数组。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 私有网络相关信息配置。通过该参数指定私有网络的ID,子网ID,私有网络ip等信息。当指定私有网络ID和子网ID(子网必须在实例所在的可用区)与指定实例所在私有网络不一致时,会将实例迁移至指定的私有网络的子网下。可通过`PrivateIpAddresses`指定私有网络子网IP,若需指定则所有已指定的实例均需要指定子网IP,此时`InstanceIds`与`PrivateIpAddresses`一一对应。不指定`PrivateIpAddresses`时随机分配私有网络子网IP。 + VirtualPrivateCloud *VirtualPrivateCloud `json:"VirtualPrivateCloud,omitempty" name:"VirtualPrivateCloud"` + + // 是否对运行中的实例选择强制关机。默认为TRUE。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` + + // 是否保留主机名。默认为FALSE。 + ReserveHostName *bool `json:"ReserveHostName,omitempty" name:"ReserveHostName"` +} + +func (r *ModifyInstancesVpcAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesVpcAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyInstancesVpcAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyInstancesVpcAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyInstancesVpcAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyKeyPairAttributeRequest struct { + *tchttp.BaseRequest + + // 密钥对ID,密钥对ID形如:`skey-xxxxxxxx`。

    可以通过以下方式获取可用的密钥 ID:
  • 通过登录[控制台](https://console.cloud.tencent.com/cvm/sshkey)查询密钥 ID。
  • 通过调用接口 [DescribeKeyPairs](https://cloud.tencent.com/document/api/213/9403) ,取返回信息中的 `KeyId` 获取密钥对 ID。 + KeyId *string `json:"KeyId,omitempty" name:"KeyId"` + + // 修改后的密钥对名称,可由数字,字母和下划线组成,长度不超过25个字符。 + KeyName *string `json:"KeyName,omitempty" name:"KeyName"` + + // 修改后的密钥对描述信息。可任意命名,但不得超过60个字符。 + Description *string `json:"Description,omitempty" name:"Description"` +} + +func (r *ModifyKeyPairAttributeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyKeyPairAttributeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ModifyKeyPairAttributeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ModifyKeyPairAttributeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ModifyKeyPairAttributeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type OperationCountLimit struct { + + // 实例操作。 + Operation *string `json:"Operation,omitempty" name:"Operation"` + + // 实例ID。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 当前已使用次数,如果返回值为-1表示该操作无次数限制。 + CurrentCount *int64 `json:"CurrentCount,omitempty" name:"CurrentCount"` + + // 操作次数最高额度,如果返回值为-1表示该操作无次数限制,如果返回值为0表示不支持调整配置。 + LimitCount *int64 `json:"LimitCount,omitempty" name:"LimitCount"` +} + +type OsVersion struct { + + // 操作系统类型 + OsName *string `json:"OsName,omitempty" name:"OsName"` + + // 支持的操作系统版本 + OsVersions []*string `json:"OsVersions,omitempty" name:"OsVersions" list` + + // 支持的操作系统架构 + Architecture []*string `json:"Architecture,omitempty" name:"Architecture" list` +} + +type Placement struct { + + // 实例所属的[可用区](/document/product/213/9452#zone)ID。该参数也可以通过调用 [DescribeZones](/document/api/213/9455) 的返回值中的Zone字段来获取。 + Zone *string `json:"Zone,omitempty" name:"Zone"` + + // 实例所属项目ID。该参数可以通过调用 [DescribeProject](/document/api/378/4400) 的返回值中的 projectId 字段来获取。不填为默认项目。 + ProjectId *int64 `json:"ProjectId,omitempty" name:"ProjectId"` + + // 实例所属的专用宿主机ID列表。如果您有购买专用宿主机并且指定了该参数,则您购买的实例就会随机的部署在这些专用宿主机上。 + HostIds []*string `json:"HostIds,omitempty" name:"HostIds" list` + + // 指定母机ip生产子机 + HostIps []*string `json:"HostIps,omitempty" name:"HostIps" list` +} + +type Price struct { + + // 描述了实例价格。 + InstancePrice *ItemPrice `json:"InstancePrice,omitempty" name:"InstancePrice"` + + // 描述了网络价格。 + BandwidthPrice *ItemPrice `json:"BandwidthPrice,omitempty" name:"BandwidthPrice"` +} + +type RebootInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 是否在正常重启失败后选择强制重启实例。取值范围:
  • TRUE:表示在正常重启失败后进行强制重启
  • FALSE:表示在正常重启失败后不进行强制重启

    默认取值:FALSE。 + ForceReboot *bool `json:"ForceReboot,omitempty" name:"ForceReboot"` + + // 关机类型。取值范围:
  • SOFT:表示软关机
  • HARD:表示硬关机
  • SOFT_FIRST:表示优先软关机,失败再执行硬关机

    默认取值:SOFT。 + StopType *string `json:"StopType,omitempty" name:"StopType"` +} + +func (r *RebootInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RebootInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RebootInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *RebootInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RebootInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RegionInfo struct { + + // 地域名称,例如,ap-guangzhou + Region *string `json:"Region,omitempty" name:"Region"` + + // 地域描述,例如,华南地区(广州) + RegionName *string `json:"RegionName,omitempty" name:"RegionName"` + + // 地域是否可用状态 + RegionState *string `json:"RegionState,omitempty" name:"RegionState"` +} + +type RenewHostsRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的CDH实例ID。 + HostIds []*string `json:"HostIds,omitempty" name:"HostIds" list` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长、是否设置自动续费等属性。若指定实例的付费模式为预付费则该参数必传。 + HostChargePrepaid *ChargePrepaid `json:"HostChargePrepaid,omitempty" name:"HostChargePrepaid"` +} + +func (r *RenewHostsRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RenewHostsRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RenewHostsResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *RenewHostsResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RenewHostsResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RenewInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的续费时长、是否设置自动续费等属性。包年包月实例该参数为必传参数。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` + + // 是否续费弹性数据盘。取值范围:
  • TRUE:表示续费包年包月实例同时续费其挂载的弹性数据盘
  • FALSE:表示续费包年包月实例同时不再续费其挂载的弹性数据盘

    默认取值:TRUE。 + RenewPortableDataDisk *bool `json:"RenewPortableDataDisk,omitempty" name:"RenewPortableDataDisk"` +} + +func (r *RenewInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RenewInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RenewInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *RenewInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RenewInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstanceRequest struct { + *tchttp.BaseRequest + + // 实例ID。可通过 [DescribeInstances](https://cloud.tencent.com/document/api/213/9388) API返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 指定有效的[镜像](https://cloud.tencent.com/document/product/213/4940)ID,格式形如`img-xxx`。镜像类型分为四种:
  • 公共镜像
  • 自定义镜像
  • 共享镜像
  • 服务市场镜像

  • 可通过以下方式获取可用的镜像ID:
  • `公共镜像`、`自定义镜像`、`共享镜像`的镜像ID可通过登录[控制台](https://console.cloud.tencent.com/cvm/image?rid=1&imageType=PUBLIC_IMAGE)查询;`服务镜像市场`的镜像ID可通过[云市场](https://market.cloud.tencent.com/list)查询。
  • 通过调用接口 [DescribeImages](https://cloud.tencent.com/document/api/213/9418) ,取返回信息中的`ImageId`字段。
  • + //
    默认取值:默认使用当前镜像。 + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 实例系统盘配置信息。系统盘为云盘的实例可以通过该参数指定重装后的系统盘大小来实现对系统盘的扩容操作,若不指定则默认系统盘大小保持不变。系统盘大小只支持扩容不支持缩容;重装只支持修改系统盘的大小,不能修改系统盘的类型。 + SystemDisk *SystemDisk `json:"SystemDisk,omitempty" name:"SystemDisk"` + + // 实例登录设置。通过该参数可以设置实例的登录方式密码、密钥或保持镜像的原始登录设置。默认情况下会随机生成密码,并以站内信方式知会到用户。 + LoginSettings *LoginSettings `json:"LoginSettings,omitempty" name:"LoginSettings"` + + // 增强服务。通过该参数可以指定是否开启云安全、云监控等服务。若不指定该参数,则默认开启云监控、云安全服务。 + EnhancedService *EnhancedService `json:"EnhancedService,omitempty" name:"EnhancedService"` + + // 重装系统时,可以指定修改实例的HostName。 + HostName *string `json:"HostName,omitempty" name:"HostName"` +} + +func (r *ResetInstanceRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstanceRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstanceResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ResetInstanceResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstanceResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesInternetMaxBandwidthRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口返回值中的 `InstanceId` 获取。 每次请求批量实例的上限为100。当调整 `BANDWIDTH_PREPAID` 和 `BANDWIDTH_POSTPAID_BY_HOUR` 计费方式的带宽时,只支持一个实例。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 公网出带宽配置。不同机型带宽上限范围不一致,具体限制详见带宽限制对账表。暂时只支持 `InternetMaxBandwidthOut` 参数。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` + + // 带宽生效的起始时间。格式:`YYYY-MM-DD`,例如:`2016-10-30`。起始时间不能早于当前时间。如果起始时间是今天则新设置的带宽立即生效。该参数只对包年包月带宽有效,其他模式带宽不支持该参数,否则接口会以相应错误码返回。 + StartTime *string `json:"StartTime,omitempty" name:"StartTime"` + + // 带宽生效的终止时间。格式: `YYYY-MM-DD` ,例如:`2016-10-30` 。新设置的带宽的有效期包含终止时间此日期。终止时间不能晚于包年包月实例的到期时间。实例的到期时间可通过 [`DescribeInstances`](https://cloud.tencent.com/document/api/213/9388)接口返回值中的`ExpiredTime`获取。该参数只对包年包月带宽有效,其他模式带宽不支持该参数,否则接口会以相应错误码返回。 + EndTime *string `json:"EndTime,omitempty" name:"EndTime"` +} + +func (r *ResetInstancesInternetMaxBandwidthRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesInternetMaxBandwidthRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesInternetMaxBandwidthResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ResetInstancesInternetMaxBandwidthResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesInternetMaxBandwidthResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesPasswordRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728) API返回值中的`InstanceId`获取。每次请求允许操作的实例数量上限是100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例登录密码。不同操作系统类型密码复杂度限制不一样,具体如下: + // Linux实例密码必须8-30位,推荐使用12位以上密码,不能以“/”开头,至少包含以下字符中的三种不同字符,字符种类:
  • 小写字母:[a-z]
  • 大写字母:[A-Z]
  • 数字:0-9
  • 特殊字符: ()\`~!@#$%^&\*-+=\_|{}[]:;'<>,.?/: + // Windows实例密码必须12~30位,不能以“/”开头且不包括用户名,至少包含以下字符中的三种不同字符
  • 小写字母:[a-z]
  • 大写字母:[A-Z]
  • 数字: 0-9
  • 特殊字符:()\`~!@#$%^&\*-+=\_|{}[]:;' <>,.?/:
  • 如果实例即包含`Linux`实例又包含`Windows`实例,则密码复杂度限制按照`Windows`实例的限制。 + Password *string `json:"Password,omitempty" name:"Password"` + + // 待重置密码的实例操作系统用户名。不得超过64个字符。 + UserName *string `json:"UserName,omitempty" name:"UserName"` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再重置用户密码。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机
  • FALSE:表示在正常关机失败后不进行强制关机

    默认取值:FALSE。

    强制关机的效果等同于关闭物理计算机的电源开关。强制关机可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常关机时使用。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *ResetInstancesPasswordRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesPasswordRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesPasswordResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ResetInstancesPasswordResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesPasswordResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesTypeRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为1。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 实例机型。不同实例机型指定了不同的资源规格,具体取值可通过调用接口[`DescribeInstanceTypeConfigs`](https://cloud.tencent.com/document/api/213/15749)来获得最新的规格表或参见[实例类型](https://cloud.tencent.com/document/product/213/11518)描述。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再重置用户密码。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机
  • FALSE:表示在正常关机失败后不进行强制关机

    默认取值:FALSE。

    强制关机的效果等同于关闭物理计算机的电源开关。强制关机可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常关机时使用。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *ResetInstancesTypeRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesTypeRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResetInstancesTypeResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ResetInstancesTypeResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResetInstancesTypeResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResizeInstanceDisksRequest struct { + *tchttp.BaseRequest + + // 待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。 + InstanceId *string `json:"InstanceId,omitempty" name:"InstanceId"` + + // 待扩容的数据盘配置信息。只支持扩容非弹性数据盘([`DescribeDisks`](https://cloud.tencent.com/document/api/362/16315)接口返回值中的`Portable`为`false`表示非弹性),且[数据盘类型](/document/api/213/9452#block_device)为:`CLOUD_BASIC`、`CLOUD_PREMIUM`、`CLOUD_SSD`。数据盘容量单位:GB。最小扩容步长:10G。关于数据盘类型的选择请参考硬盘产品简介。可选数据盘类型受到实例类型`InstanceType`限制。另外允许扩容的最大容量也因数据盘类型的不同而有所差异。 + DataDisks []*DataDisk `json:"DataDisks,omitempty" name:"DataDisks" list` + + // 是否对运行中的实例选择强制关机。建议对运行中的实例先手动关机,然后再重置用户密码。取值范围:
  • TRUE:表示在正常关机失败后进行强制关机
  • FALSE:表示在正常关机失败后不进行强制关机

    默认取值:FALSE。

    强制关机的效果等同于关闭物理计算机的电源开关。强制关机可能会导致数据丢失或文件系统损坏,请仅在服务器不能正常关机时使用。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` +} + +func (r *ResizeInstanceDisksRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResizeInstanceDisksRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type ResizeInstanceDisksResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *ResizeInstanceDisksResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *ResizeInstanceDisksResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RunInstancesRequest struct { + *tchttp.BaseRequest + + // 实例所在的位置。通过该参数可以指定实例所属可用区,所属项目,所属宿主机(在专用宿主机上创建子机时指定)等属性。 + Placement *Placement `json:"Placement,omitempty" name:"Placement"` + + // 指定有效的[镜像](https://cloud.tencent.com/document/product/213/4940)ID,格式形如`img-xxx`。镜像类型分为四种:
  • 公共镜像
  • 自定义镜像
  • 共享镜像
  • 服务市场镜像

  • 可通过以下方式获取可用的镜像ID:
  • `公共镜像`、`自定义镜像`、`共享镜像`的镜像ID可通过登录[控制台](https://console.cloud.tencent.com/cvm/image?rid=1&imageType=PUBLIC_IMAGE)查询;`服务镜像市场`的镜像ID可通过[云市场](https://market.cloud.tencent.com/list)查询。
  • 通过调用接口 [DescribeImages](https://cloud.tencent.com/document/api/213/15715) ,取返回信息中的`ImageId`字段。
  • + ImageId *string `json:"ImageId,omitempty" name:"ImageId"` + + // 实例[计费类型](https://cloud.tencent.com/document/product/213/2180)。
  • PREPAID:预付费,即包年包月
  • POSTPAID_BY_HOUR:按小时后付费
  • CDHPAID:独享子机(基于专用宿主机创建,宿主机部分的资源不收费)
  • SPOTPAID:竞价付费
    默认值:POSTPAID_BY_HOUR。 + InstanceChargeType *string `json:"InstanceChargeType,omitempty" name:"InstanceChargeType"` + + // 预付费模式,即包年包月相关参数设置。通过该参数可以指定包年包月实例的购买时长、是否设置自动续费等属性。若指定实例的付费模式为预付费则该参数必传。 + InstanceChargePrepaid *InstanceChargePrepaid `json:"InstanceChargePrepaid,omitempty" name:"InstanceChargePrepaid"` + + // 实例机型。不同实例机型指定了不同的资源规格。 + //
  • 对于付费模式为PREPAID或POSTPAID\_BY\_HOUR的实例创建,具体取值可通过调用接口[DescribeInstanceTypeConfigs](https://cloud.tencent.com/document/api/213/15749)来获得最新的规格表或参见[实例类型](https://cloud.tencent.com/document/product/213/11518)描述。若不指定该参数,则默认机型为S1.SMALL1。
  • 对于付费模式为CDHPAID的实例创建,该参数以"CDH_"为前缀,根据cpu和内存配置生成,具体形式为:CDH_XCXG,例如对于创建cpu为1核,内存为1G大小的专用宿主机的实例,该参数应该为CDH_1C1G。 + InstanceType *string `json:"InstanceType,omitempty" name:"InstanceType"` + + // 实例系统盘配置信息。若不指定该参数,则按照系统默认值进行分配。 + SystemDisk *SystemDisk `json:"SystemDisk,omitempty" name:"SystemDisk"` + + // 实例数据盘配置信息。若不指定该参数,则默认不购买数据盘。支持购买的时候指定11块数据盘,其中最多包含1块LOCAL_BASIC数据盘或者LOCAL_SSD数据盘,最多包含10块CLOUD_BASIC数据盘、CLOUD_PREMIUM数据盘或者CLOUD_SSD数据盘。 + DataDisks []*DataDisk `json:"DataDisks,omitempty" name:"DataDisks" list` + + // 私有网络相关信息配置。通过该参数可以指定私有网络的ID,子网ID等信息。若不指定该参数,则默认使用基础网络。若在此参数中指定了私有网络ip,表示每个实例的主网卡ip,而且InstanceCount参数必须与私有网络ip的个数一致。 + VirtualPrivateCloud *VirtualPrivateCloud `json:"VirtualPrivateCloud,omitempty" name:"VirtualPrivateCloud"` + + // 公网带宽相关信息设置。若不指定该参数,则默认公网带宽为0Mbps。 + InternetAccessible *InternetAccessible `json:"InternetAccessible,omitempty" name:"InternetAccessible"` + + // 购买实例数量。包年包月实例取值范围:[1,300],按量计费实例取值范围:[1,100]。默认取值:1。指定购买实例的数量不能超过用户所能购买的剩余配额数量,具体配额相关限制详见[CVM实例购买限制](https://cloud.tencent.com/document/product/213/2664)。 + InstanceCount *int64 `json:"InstanceCount,omitempty" name:"InstanceCount"` + + // 实例显示名称。
  • 不指定实例显示名称则默认显示‘未命名’。
  • 购买多台实例,如果指定模式串`{R:x}`,表示生成数字`[x, x+n-1]`,其中`n`表示购买实例的数量,例如`server_{R:3}`,购买1台时,实例显示名称为`server_3`;购买2台时,实例显示名称分别为`server_3`,`server_4`。支持指定多个模式串`{R:x}`。
  • 购买多台实例,如果不指定模式串,则在实例显示名称添加后缀`1、2...n`,其中`n`表示购买实例的数量,例如`server_`,购买2台时,实例显示名称分别为`server_1`,`server_2`。 + InstanceName *string `json:"InstanceName,omitempty" name:"InstanceName"` + + // 实例登录设置。通过该参数可以设置实例的登录方式密码、密钥或保持镜像的原始登录设置。默认情况下会随机生成密码,并以站内信方式知会到用户。 + LoginSettings *LoginSettings `json:"LoginSettings,omitempty" name:"LoginSettings"` + + // 实例所属安全组。该参数可以通过调用 [DescribeSecurityGroups](https://cloud.tencent.com/document/api/215/15808) 的返回值中的sgId字段来获取。若不指定该参数,则绑定默认安全组。 + SecurityGroupIds []*string `json:"SecurityGroupIds,omitempty" name:"SecurityGroupIds" list` + + // 增强服务。通过该参数可以指定是否开启云安全、云监控等服务。若不指定该参数,则默认开启云监控、云安全服务。 + EnhancedService *EnhancedService `json:"EnhancedService,omitempty" name:"EnhancedService"` + + // 用于保证请求幂等性的字符串。该字符串由客户生成,需保证不同请求之间唯一,最大值不超过64个ASCII字符。若不指定该参数,则无法保证请求的幂等性。
    更多详细信息请参阅:如何保证幂等性。 + ClientToken *string `json:"ClientToken,omitempty" name:"ClientToken"` + + // 云服务器的主机名。
  • 点号(.)和短横线(-)不能作为 HostName 的首尾字符,不能连续使用。
  • Windows 实例:名字符长度为[2, 15],允许字母(不限制大小写)、数字和短横线(-)组成,不支持点号(.),不能全是数字。
  • 其他类型(Linux 等)实例:字符长度为[2, 60],允许支持多个点号,点之间为一段,每段允许字母(不限制大小写)、数字和短横线(-)组成。 + HostName *string `json:"HostName,omitempty" name:"HostName"` + + // 定时任务。通过该参数可以为实例指定定时任务,目前仅支持定时销毁。 + ActionTimer *ActionTimer `json:"ActionTimer,omitempty" name:"ActionTimer"` + + // 置放群组id,仅支持指定一个。 + DisasterRecoverGroupIds []*string `json:"DisasterRecoverGroupIds,omitempty" name:"DisasterRecoverGroupIds" list` + + // 标签描述列表。通过指定该参数可以同时绑定标签到相应的资源实例,当前仅支持绑定标签到云主机实例。 + TagSpecification []*TagSpecification `json:"TagSpecification,omitempty" name:"TagSpecification" list` + + // 实例的市场相关选项,如竞价实例相关参数,若指定实例的付费模式为竞价付费则该参数必传。 + InstanceMarketOptions *InstanceMarketOptionsRequest `json:"InstanceMarketOptions,omitempty" name:"InstanceMarketOptions"` + + // 提供给实例使用的用户数据,需要以 base64 方式编码,支持的最大数据大小为 16KB。关于获取此参数的详细介绍,请参阅[Windows](https://cloud.tencent.com/document/product/213/17526)和[Linux](https://cloud.tencent.com/document/product/213/17525)启动时运行命令。 + UserData *string `json:"UserData,omitempty" name:"UserData"` + + // 是否只预检此次请求。 + // true:发送检查请求,不会创建实例。检查项包括是否填写了必需参数,请求格式,业务限制和云服务器库存。 + // 如果检查不通过,则返回对应错误码; + // 如果检查通过,则返回RequestId. + // false(默认):发送正常请求,通过检查后直接创建实例 + DryRun *bool `json:"DryRun,omitempty" name:"DryRun"` +} + +func (r *RunInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RunInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RunInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 当通过本接口来创建实例时会返回该参数,表示一个或多个实例`ID`。返回实例`ID`列表并不代表实例创建成功,可根据 [DescribeInstances](https://cloud.tencent.com/document/api/213/15728) 接口查询返回的InstancesSet中对应实例的`ID`的状态来判断创建是否完成;如果实例状态由“准备中”变为“正在运行”,则为创建成功。 + InstanceIdSet []*string `json:"InstanceIdSet,omitempty" name:"InstanceIdSet" list` + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *RunInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *RunInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type RunMonitorServiceEnabled struct { + + // 是否开启[云监控](/document/product/248)服务。取值范围:
  • TRUE:表示开启云监控服务
  • FALSE:表示不开启云监控服务

    默认取值:TRUE。 + Enabled *bool `json:"Enabled,omitempty" name:"Enabled"` +} + +type RunSecurityServiceEnabled struct { + + // 是否开启[云安全](/document/product/296)服务。取值范围:
  • TRUE:表示开启云安全服务
  • FALSE:表示不开启云安全服务

    默认取值:TRUE。 + Enabled *bool `json:"Enabled,omitempty" name:"Enabled"` +} + +type SharePermission struct { + + // 镜像分享时间 + CreatedTime *string `json:"CreatedTime,omitempty" name:"CreatedTime"` + + // 镜像分享的账户ID + AccountId *string `json:"AccountId,omitempty" name:"AccountId"` +} + +type Snapshot struct { + + // 快照Id。 + SnapshotId *string `json:"SnapshotId,omitempty" name:"SnapshotId"` + + // 创建此快照的云硬盘类型。取值范围: + // SYSTEM_DISK:系统盘 + // DATA_DISK:数据盘。 + DiskUsage *string `json:"DiskUsage,omitempty" name:"DiskUsage"` + + // 创建此快照的云硬盘大小,单位GB。 + DiskSize *int64 `json:"DiskSize,omitempty" name:"DiskSize"` +} + +type SpotMarketOptions struct { + + // 竞价出价 + MaxPrice *string `json:"MaxPrice,omitempty" name:"MaxPrice"` + + // 竞价请求类型,当前仅支持类型:one-time + SpotInstanceType *string `json:"SpotInstanceType,omitempty" name:"SpotInstanceType"` +} + +type StartInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` +} + +func (r *StartInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *StartInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type StartInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *StartInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *StartInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type StopInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` + + // 是否在正常关闭失败后选择强制关闭实例。取值范围:
  • TRUE:表示在正常关闭失败后进行强制关闭
  • FALSE:表示在正常关闭失败后不进行强制关闭

    默认取值:FALSE。 + ForceStop *bool `json:"ForceStop,omitempty" name:"ForceStop"` + + // 实例的关闭模式。取值范围:
  • SOFT_FIRST:表示在正常关闭失败后进行强制关闭
  • HARD:直接强制关闭
  • SOFT:仅软关机
    默认取值:SOFT。 + StopType *string `json:"StopType,omitempty" name:"StopType"` + + // 按量计费实例关机收费模式。 + // 取值范围:
  • KEEP_CHARGING:关机继续收费
  • STOP_CHARGING:关机停止收费
    默认取值:KEEP_CHARGING。 + // 该参数只针对部分按量计费云硬盘实例生效,详情参考[按量计费实例关机不收费说明](https://cloud.tencent.com/document/product/213/19918) + StoppedMode *string `json:"StoppedMode,omitempty" name:"StoppedMode"` +} + +func (r *StopInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *StopInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type StopInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *StopInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *StopInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type StorageBlock struct { + + // HDD本地存储类型,值为:LOCAL_PRO. + // 注意:此字段可能返回 null,表示取不到有效值。 + Type *string `json:"Type,omitempty" name:"Type"` + + // HDD本地存储的最小容量 + // 注意:此字段可能返回 null,表示取不到有效值。 + MinSize *int64 `json:"MinSize,omitempty" name:"MinSize"` + + // HDD本地存储的最大容量 + // 注意:此字段可能返回 null,表示取不到有效值。 + MaxSize *int64 `json:"MaxSize,omitempty" name:"MaxSize"` +} + +type SyncImagesRequest struct { + *tchttp.BaseRequest + + // 镜像ID列表 ,镜像ID可以通过如下方式获取:
  • 通过[DescribeImages](https://cloud.tencent.com/document/api/213/15715)接口返回的`ImageId`获取。
  • 通过[镜像控制台](https://console.cloud.tencent.com/cvm/image)获取。
    镜像ID必须满足限制:
  • 镜像ID对应的镜像状态必须为`NORMAL`。
  • 镜像大小小于50GB。
    镜像状态请参考[镜像数据表](/document/api/213/9452#image_state)。 + ImageIds []*string `json:"ImageIds,omitempty" name:"ImageIds" list` + + // 目的同步地域列表;必须满足限制:
  • 不能为源地域,
  • 必须是一个合法的Region。
  • 暂不支持部分地域同步。
    具体地域参数请参考[Region](https://cloud.tencent.com/document/product/213/6091)。 + DestinationRegions []*string `json:"DestinationRegions,omitempty" name:"DestinationRegions" list` +} + +func (r *SyncImagesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *SyncImagesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type SyncImagesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *SyncImagesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *SyncImagesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type SystemDisk struct { + + // 系统盘类型。系统盘类型限制详见[CVM实例配置](/document/product/213/2177)。取值范围:
  • LOCAL_BASIC:本地硬盘
  • LOCAL_SSD:本地SSD硬盘
  • CLOUD_BASIC:普通云硬盘
  • CLOUD_SSD:SSD云硬盘
  • CLOUD_PREMIUM:高性能云硬盘

    默认取值:CLOUD_BASIC。 + DiskType *string `json:"DiskType,omitempty" name:"DiskType"` + + // 系统盘ID。LOCAL_BASIC 和 LOCAL_SSD 类型没有ID。暂时不支持该参数。 + DiskId *string `json:"DiskId,omitempty" name:"DiskId"` + + // 系统盘大小,单位:GB。默认值为 50 + DiskSize *int64 `json:"DiskSize,omitempty" name:"DiskSize"` +} + +type Tag struct { + + // 标签键 + Key *string `json:"Key,omitempty" name:"Key"` + + // 标签值 + Value *string `json:"Value,omitempty" name:"Value"` +} + +type TagSpecification struct { + + // 标签绑定的资源类型,当前支持类型:"instance"和"host" + ResourceType *string `json:"ResourceType,omitempty" name:"ResourceType"` + + // 标签对列表 + Tags []*Tag `json:"Tags,omitempty" name:"Tags" list` +} + +type TerminateInstancesRequest struct { + *tchttp.BaseRequest + + // 一个或多个待操作的实例ID。可通过[`DescribeInstances`](https://cloud.tencent.com/document/api/213/15728)接口返回值中的`InstanceId`获取。每次请求批量实例的上限为100。 + InstanceIds []*string `json:"InstanceIds,omitempty" name:"InstanceIds" list` +} + +func (r *TerminateInstancesRequest) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *TerminateInstancesRequest) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type TerminateInstancesResponse struct { + *tchttp.BaseResponse + Response *struct { + + // 唯一请求 ID,每次请求都会返回。定位问题时需要提供该次请求的 RequestId。 + RequestId *string `json:"RequestId,omitempty" name:"RequestId"` + } `json:"Response"` +} + +func (r *TerminateInstancesResponse) ToJsonString() string { + b, _ := json.Marshal(r) + return string(b) +} + +func (r *TerminateInstancesResponse) FromJsonString(s string) error { + return json.Unmarshal([]byte(s), &r) +} + +type VirtualPrivateCloud struct { + + // 私有网络ID,形如`vpc-xxx`。有效的VpcId可通过登录[控制台](https://console.cloud.tencent.com/vpc/vpc?rid=1)查询;也可以调用接口 [DescribeVpcEx](/document/api/215/1372) ,从接口返回中的`unVpcId`字段获取。若在创建子机时VpcId与SubnetId同时传入`DEFAULT`,则强制使用默认vpc网络。 + VpcId *string `json:"VpcId,omitempty" name:"VpcId"` + + // 私有网络子网ID,形如`subnet-xxx`。有效的私有网络子网ID可通过登录[控制台](https://console.cloud.tencent.com/vpc/subnet?rid=1)查询;也可以调用接口 [DescribeSubnets](/document/api/215/15784) ,从接口返回中的`unSubnetId`字段获取。若在创建子机时SubnetId与VpcId同时传入`DEFAULT`,则强制使用默认vpc网络。 + SubnetId *string `json:"SubnetId,omitempty" name:"SubnetId"` + + // 是否用作公网网关。公网网关只有在实例拥有公网IP以及处于私有网络下时才能正常使用。取值范围:
  • TRUE:表示用作公网网关
  • FALSE:表示不用作公网网关

    默认取值:FALSE。 + AsVpcGateway *bool `json:"AsVpcGateway,omitempty" name:"AsVpcGateway"` + + // 私有网络子网 IP 数组,在创建实例、修改实例vpc属性操作中可使用此参数。当前仅批量创建多台实例时支持传入相同子网的多个 IP。 + PrivateIpAddresses []*string `json:"PrivateIpAddresses,omitempty" name:"PrivateIpAddresses" list` +} + +type ZoneInfo struct { + + // 可用区名称,例如,ap-guangzhou-3 + // 全网可用区名称如下: + //
  • ap-chongqing-1
  • + //
  • ap-seoul-1
  • + //
  • ap-chengdu-1
  • + //
  • ap-chengdu-2
  • + //
  • ap-hongkong-1
  • + //
  • ap-hongkong-2
  • + //
  • ap-shenzhen-fsi-1
  • + //
  • ap-shenzhen-fsi-2
  • + //
  • ap-shenzhen-fsi-3
  • + //
  • ap-guangzhou-1(售罄)
  • + //
  • ap-guangzhou-2(售罄)
  • + //
  • ap-guangzhou-3
  • + //
  • ap-guangzhou-4
  • + //
  • ap-tokyo-1
  • + //
  • ap-singapore-1
  • + //
  • ap-shanghai-fsi-1
  • + //
  • ap-shanghai-fsi-2
  • + //
  • ap-shanghai-fsi-3
  • + //
  • ap-bangkok-1
  • + //
  • ap-shanghai-1(售罄)
  • + //
  • ap-shanghai-2
  • + //
  • ap-shanghai-3
  • + //
  • ap-shanghai-4
  • + //
  • ap-mumbai-1
  • + //
  • ap-mumbai-2
  • + //
  • eu-moscow-1
  • + //
  • ap-beijing-1
  • + //
  • ap-beijing-2
  • + //
  • ap-beijing-3
  • + //
  • ap-beijing-4
  • + //
  • na-siliconvalley-1
  • + //
  • na-siliconvalley-2
  • + //
  • eu-frankfurt-1
  • + //
  • na-toronto-1
  • + //
  • na-ashburn-1
  • + //
  • na-ashburn-2
  • + Zone *string `json:"Zone,omitempty" name:"Zone"` + + // 可用区描述,例如,广州三区 + ZoneName *string `json:"ZoneName,omitempty" name:"ZoneName"` + + // 可用区ID + ZoneId *string `json:"ZoneId,omitempty" name:"ZoneId"` + + // 可用区状态,包含AVAILABLE和UNAVAILABLE。AVAILABLE代表可用,UNAVAILABLE代表不可用。 + ZoneState *string `json:"ZoneState,omitempty" name:"ZoneState"` +} diff --git a/vendor/golang.org/x/crypto/pkcs12/bmp-string.go b/vendor/golang.org/x/crypto/pkcs12/bmp-string.go new file mode 100644 index 0000000000..233b8b62cc --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/bmp-string.go @@ -0,0 +1,50 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import ( + "errors" + "unicode/utf16" +) + +// bmpString returns s encoded in UCS-2 with a zero terminator. +func bmpString(s string) ([]byte, error) { + // References: + // https://tools.ietf.org/html/rfc7292#appendix-B.1 + // https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane + // - non-BMP characters are encoded in UTF 16 by using a surrogate pair of 16-bit codes + // EncodeRune returns 0xfffd if the rune does not need special encoding + // - the above RFC provides the info that BMPStrings are NULL terminated. + + ret := make([]byte, 0, 2*len(s)+2) + + for _, r := range s { + if t, _ := utf16.EncodeRune(r); t != 0xfffd { + return nil, errors.New("pkcs12: string contains characters that cannot be encoded in UCS-2") + } + ret = append(ret, byte(r/256), byte(r%256)) + } + + return append(ret, 0, 0), nil +} + +func decodeBMPString(bmpString []byte) (string, error) { + if len(bmpString)%2 != 0 { + return "", errors.New("pkcs12: odd-length BMP string") + } + + // strip terminator if present + if l := len(bmpString); l >= 2 && bmpString[l-1] == 0 && bmpString[l-2] == 0 { + bmpString = bmpString[:l-2] + } + + s := make([]uint16, 0, len(bmpString)/2) + for len(bmpString) > 0 { + s = append(s, uint16(bmpString[0])<<8+uint16(bmpString[1])) + bmpString = bmpString[2:] + } + + return string(utf16.Decode(s)), nil +} diff --git a/vendor/golang.org/x/crypto/pkcs12/crypto.go b/vendor/golang.org/x/crypto/pkcs12/crypto.go new file mode 100644 index 0000000000..484ca51b71 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/crypto.go @@ -0,0 +1,131 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import ( + "bytes" + "crypto/cipher" + "crypto/des" + "crypto/x509/pkix" + "encoding/asn1" + "errors" + + "golang.org/x/crypto/pkcs12/internal/rc2" +) + +var ( + oidPBEWithSHAAnd3KeyTripleDESCBC = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 3}) + oidPBEWithSHAAnd40BitRC2CBC = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 1, 6}) +) + +// pbeCipher is an abstraction of a PKCS#12 cipher. +type pbeCipher interface { + // create returns a cipher.Block given a key. + create(key []byte) (cipher.Block, error) + // deriveKey returns a key derived from the given password and salt. + deriveKey(salt, password []byte, iterations int) []byte + // deriveKey returns an IV derived from the given password and salt. + deriveIV(salt, password []byte, iterations int) []byte +} + +type shaWithTripleDESCBC struct{} + +func (shaWithTripleDESCBC) create(key []byte) (cipher.Block, error) { + return des.NewTripleDESCipher(key) +} + +func (shaWithTripleDESCBC) deriveKey(salt, password []byte, iterations int) []byte { + return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 1, 24) +} + +func (shaWithTripleDESCBC) deriveIV(salt, password []byte, iterations int) []byte { + return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 2, 8) +} + +type shaWith40BitRC2CBC struct{} + +func (shaWith40BitRC2CBC) create(key []byte) (cipher.Block, error) { + return rc2.New(key, len(key)*8) +} + +func (shaWith40BitRC2CBC) deriveKey(salt, password []byte, iterations int) []byte { + return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 1, 5) +} + +func (shaWith40BitRC2CBC) deriveIV(salt, password []byte, iterations int) []byte { + return pbkdf(sha1Sum, 20, 64, salt, password, iterations, 2, 8) +} + +type pbeParams struct { + Salt []byte + Iterations int +} + +func pbDecrypterFor(algorithm pkix.AlgorithmIdentifier, password []byte) (cipher.BlockMode, int, error) { + var cipherType pbeCipher + + switch { + case algorithm.Algorithm.Equal(oidPBEWithSHAAnd3KeyTripleDESCBC): + cipherType = shaWithTripleDESCBC{} + case algorithm.Algorithm.Equal(oidPBEWithSHAAnd40BitRC2CBC): + cipherType = shaWith40BitRC2CBC{} + default: + return nil, 0, NotImplementedError("algorithm " + algorithm.Algorithm.String() + " is not supported") + } + + var params pbeParams + if err := unmarshal(algorithm.Parameters.FullBytes, ¶ms); err != nil { + return nil, 0, err + } + + key := cipherType.deriveKey(params.Salt, password, params.Iterations) + iv := cipherType.deriveIV(params.Salt, password, params.Iterations) + + block, err := cipherType.create(key) + if err != nil { + return nil, 0, err + } + + return cipher.NewCBCDecrypter(block, iv), block.BlockSize(), nil +} + +func pbDecrypt(info decryptable, password []byte) (decrypted []byte, err error) { + cbc, blockSize, err := pbDecrypterFor(info.Algorithm(), password) + if err != nil { + return nil, err + } + + encrypted := info.Data() + if len(encrypted) == 0 { + return nil, errors.New("pkcs12: empty encrypted data") + } + if len(encrypted)%blockSize != 0 { + return nil, errors.New("pkcs12: input is not a multiple of the block size") + } + decrypted = make([]byte, len(encrypted)) + cbc.CryptBlocks(decrypted, encrypted) + + psLen := int(decrypted[len(decrypted)-1]) + if psLen == 0 || psLen > blockSize { + return nil, ErrDecryption + } + + if len(decrypted) < psLen { + return nil, ErrDecryption + } + ps := decrypted[len(decrypted)-psLen:] + decrypted = decrypted[:len(decrypted)-psLen] + if bytes.Compare(ps, bytes.Repeat([]byte{byte(psLen)}, psLen)) != 0 { + return nil, ErrDecryption + } + + return +} + +// decryptable abstracts an object that contains ciphertext. +type decryptable interface { + Algorithm() pkix.AlgorithmIdentifier + Data() []byte +} diff --git a/vendor/golang.org/x/crypto/pkcs12/errors.go b/vendor/golang.org/x/crypto/pkcs12/errors.go new file mode 100644 index 0000000000..7377ce6fb2 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/errors.go @@ -0,0 +1,23 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import "errors" + +var ( + // ErrDecryption represents a failure to decrypt the input. + ErrDecryption = errors.New("pkcs12: decryption error, incorrect padding") + + // ErrIncorrectPassword is returned when an incorrect password is detected. + // Usually, P12/PFX data is signed to be able to verify the password. + ErrIncorrectPassword = errors.New("pkcs12: decryption password incorrect") +) + +// NotImplementedError indicates that the input is not currently supported. +type NotImplementedError string + +func (e NotImplementedError) Error() string { + return "pkcs12: " + string(e) +} diff --git a/vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2.go b/vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2.go new file mode 100644 index 0000000000..7499e3fb69 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/internal/rc2/rc2.go @@ -0,0 +1,271 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package rc2 implements the RC2 cipher +/* +https://www.ietf.org/rfc/rfc2268.txt +http://people.csail.mit.edu/rivest/pubs/KRRR98.pdf + +This code is licensed under the MIT license. +*/ +package rc2 + +import ( + "crypto/cipher" + "encoding/binary" +) + +// The rc2 block size in bytes +const BlockSize = 8 + +type rc2Cipher struct { + k [64]uint16 +} + +// New returns a new rc2 cipher with the given key and effective key length t1 +func New(key []byte, t1 int) (cipher.Block, error) { + // TODO(dgryski): error checking for key length + return &rc2Cipher{ + k: expandKey(key, t1), + }, nil +} + +func (*rc2Cipher) BlockSize() int { return BlockSize } + +var piTable = [256]byte{ + 0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, 0x28, 0xe9, 0xfd, 0x79, 0x4a, 0xa0, 0xd8, 0x9d, + 0xc6, 0x7e, 0x37, 0x83, 0x2b, 0x76, 0x53, 0x8e, 0x62, 0x4c, 0x64, 0x88, 0x44, 0x8b, 0xfb, 0xa2, + 0x17, 0x9a, 0x59, 0xf5, 0x87, 0xb3, 0x4f, 0x13, 0x61, 0x45, 0x6d, 0x8d, 0x09, 0x81, 0x7d, 0x32, + 0xbd, 0x8f, 0x40, 0xeb, 0x86, 0xb7, 0x7b, 0x0b, 0xf0, 0x95, 0x21, 0x22, 0x5c, 0x6b, 0x4e, 0x82, + 0x54, 0xd6, 0x65, 0x93, 0xce, 0x60, 0xb2, 0x1c, 0x73, 0x56, 0xc0, 0x14, 0xa7, 0x8c, 0xf1, 0xdc, + 0x12, 0x75, 0xca, 0x1f, 0x3b, 0xbe, 0xe4, 0xd1, 0x42, 0x3d, 0xd4, 0x30, 0xa3, 0x3c, 0xb6, 0x26, + 0x6f, 0xbf, 0x0e, 0xda, 0x46, 0x69, 0x07, 0x57, 0x27, 0xf2, 0x1d, 0x9b, 0xbc, 0x94, 0x43, 0x03, + 0xf8, 0x11, 0xc7, 0xf6, 0x90, 0xef, 0x3e, 0xe7, 0x06, 0xc3, 0xd5, 0x2f, 0xc8, 0x66, 0x1e, 0xd7, + 0x08, 0xe8, 0xea, 0xde, 0x80, 0x52, 0xee, 0xf7, 0x84, 0xaa, 0x72, 0xac, 0x35, 0x4d, 0x6a, 0x2a, + 0x96, 0x1a, 0xd2, 0x71, 0x5a, 0x15, 0x49, 0x74, 0x4b, 0x9f, 0xd0, 0x5e, 0x04, 0x18, 0xa4, 0xec, + 0xc2, 0xe0, 0x41, 0x6e, 0x0f, 0x51, 0xcb, 0xcc, 0x24, 0x91, 0xaf, 0x50, 0xa1, 0xf4, 0x70, 0x39, + 0x99, 0x7c, 0x3a, 0x85, 0x23, 0xb8, 0xb4, 0x7a, 0xfc, 0x02, 0x36, 0x5b, 0x25, 0x55, 0x97, 0x31, + 0x2d, 0x5d, 0xfa, 0x98, 0xe3, 0x8a, 0x92, 0xae, 0x05, 0xdf, 0x29, 0x10, 0x67, 0x6c, 0xba, 0xc9, + 0xd3, 0x00, 0xe6, 0xcf, 0xe1, 0x9e, 0xa8, 0x2c, 0x63, 0x16, 0x01, 0x3f, 0x58, 0xe2, 0x89, 0xa9, + 0x0d, 0x38, 0x34, 0x1b, 0xab, 0x33, 0xff, 0xb0, 0xbb, 0x48, 0x0c, 0x5f, 0xb9, 0xb1, 0xcd, 0x2e, + 0xc5, 0xf3, 0xdb, 0x47, 0xe5, 0xa5, 0x9c, 0x77, 0x0a, 0xa6, 0x20, 0x68, 0xfe, 0x7f, 0xc1, 0xad, +} + +func expandKey(key []byte, t1 int) [64]uint16 { + + l := make([]byte, 128) + copy(l, key) + + var t = len(key) + var t8 = (t1 + 7) / 8 + var tm = byte(255 % uint(1<<(8+uint(t1)-8*uint(t8)))) + + for i := len(key); i < 128; i++ { + l[i] = piTable[l[i-1]+l[uint8(i-t)]] + } + + l[128-t8] = piTable[l[128-t8]&tm] + + for i := 127 - t8; i >= 0; i-- { + l[i] = piTable[l[i+1]^l[i+t8]] + } + + var k [64]uint16 + + for i := range k { + k[i] = uint16(l[2*i]) + uint16(l[2*i+1])*256 + } + + return k +} + +func rotl16(x uint16, b uint) uint16 { + return (x >> (16 - b)) | (x << b) +} + +func (c *rc2Cipher) Encrypt(dst, src []byte) { + + r0 := binary.LittleEndian.Uint16(src[0:]) + r1 := binary.LittleEndian.Uint16(src[2:]) + r2 := binary.LittleEndian.Uint16(src[4:]) + r3 := binary.LittleEndian.Uint16(src[6:]) + + var j int + + for j <= 16 { + // mix r0 + r0 = r0 + c.k[j] + (r3 & r2) + ((^r3) & r1) + r0 = rotl16(r0, 1) + j++ + + // mix r1 + r1 = r1 + c.k[j] + (r0 & r3) + ((^r0) & r2) + r1 = rotl16(r1, 2) + j++ + + // mix r2 + r2 = r2 + c.k[j] + (r1 & r0) + ((^r1) & r3) + r2 = rotl16(r2, 3) + j++ + + // mix r3 + r3 = r3 + c.k[j] + (r2 & r1) + ((^r2) & r0) + r3 = rotl16(r3, 5) + j++ + + } + + r0 = r0 + c.k[r3&63] + r1 = r1 + c.k[r0&63] + r2 = r2 + c.k[r1&63] + r3 = r3 + c.k[r2&63] + + for j <= 40 { + // mix r0 + r0 = r0 + c.k[j] + (r3 & r2) + ((^r3) & r1) + r0 = rotl16(r0, 1) + j++ + + // mix r1 + r1 = r1 + c.k[j] + (r0 & r3) + ((^r0) & r2) + r1 = rotl16(r1, 2) + j++ + + // mix r2 + r2 = r2 + c.k[j] + (r1 & r0) + ((^r1) & r3) + r2 = rotl16(r2, 3) + j++ + + // mix r3 + r3 = r3 + c.k[j] + (r2 & r1) + ((^r2) & r0) + r3 = rotl16(r3, 5) + j++ + + } + + r0 = r0 + c.k[r3&63] + r1 = r1 + c.k[r0&63] + r2 = r2 + c.k[r1&63] + r3 = r3 + c.k[r2&63] + + for j <= 60 { + // mix r0 + r0 = r0 + c.k[j] + (r3 & r2) + ((^r3) & r1) + r0 = rotl16(r0, 1) + j++ + + // mix r1 + r1 = r1 + c.k[j] + (r0 & r3) + ((^r0) & r2) + r1 = rotl16(r1, 2) + j++ + + // mix r2 + r2 = r2 + c.k[j] + (r1 & r0) + ((^r1) & r3) + r2 = rotl16(r2, 3) + j++ + + // mix r3 + r3 = r3 + c.k[j] + (r2 & r1) + ((^r2) & r0) + r3 = rotl16(r3, 5) + j++ + } + + binary.LittleEndian.PutUint16(dst[0:], r0) + binary.LittleEndian.PutUint16(dst[2:], r1) + binary.LittleEndian.PutUint16(dst[4:], r2) + binary.LittleEndian.PutUint16(dst[6:], r3) +} + +func (c *rc2Cipher) Decrypt(dst, src []byte) { + + r0 := binary.LittleEndian.Uint16(src[0:]) + r1 := binary.LittleEndian.Uint16(src[2:]) + r2 := binary.LittleEndian.Uint16(src[4:]) + r3 := binary.LittleEndian.Uint16(src[6:]) + + j := 63 + + for j >= 44 { + // unmix r3 + r3 = rotl16(r3, 16-5) + r3 = r3 - c.k[j] - (r2 & r1) - ((^r2) & r0) + j-- + + // unmix r2 + r2 = rotl16(r2, 16-3) + r2 = r2 - c.k[j] - (r1 & r0) - ((^r1) & r3) + j-- + + // unmix r1 + r1 = rotl16(r1, 16-2) + r1 = r1 - c.k[j] - (r0 & r3) - ((^r0) & r2) + j-- + + // unmix r0 + r0 = rotl16(r0, 16-1) + r0 = r0 - c.k[j] - (r3 & r2) - ((^r3) & r1) + j-- + } + + r3 = r3 - c.k[r2&63] + r2 = r2 - c.k[r1&63] + r1 = r1 - c.k[r0&63] + r0 = r0 - c.k[r3&63] + + for j >= 20 { + // unmix r3 + r3 = rotl16(r3, 16-5) + r3 = r3 - c.k[j] - (r2 & r1) - ((^r2) & r0) + j-- + + // unmix r2 + r2 = rotl16(r2, 16-3) + r2 = r2 - c.k[j] - (r1 & r0) - ((^r1) & r3) + j-- + + // unmix r1 + r1 = rotl16(r1, 16-2) + r1 = r1 - c.k[j] - (r0 & r3) - ((^r0) & r2) + j-- + + // unmix r0 + r0 = rotl16(r0, 16-1) + r0 = r0 - c.k[j] - (r3 & r2) - ((^r3) & r1) + j-- + + } + + r3 = r3 - c.k[r2&63] + r2 = r2 - c.k[r1&63] + r1 = r1 - c.k[r0&63] + r0 = r0 - c.k[r3&63] + + for j >= 0 { + // unmix r3 + r3 = rotl16(r3, 16-5) + r3 = r3 - c.k[j] - (r2 & r1) - ((^r2) & r0) + j-- + + // unmix r2 + r2 = rotl16(r2, 16-3) + r2 = r2 - c.k[j] - (r1 & r0) - ((^r1) & r3) + j-- + + // unmix r1 + r1 = rotl16(r1, 16-2) + r1 = r1 - c.k[j] - (r0 & r3) - ((^r0) & r2) + j-- + + // unmix r0 + r0 = rotl16(r0, 16-1) + r0 = r0 - c.k[j] - (r3 & r2) - ((^r3) & r1) + j-- + + } + + binary.LittleEndian.PutUint16(dst[0:], r0) + binary.LittleEndian.PutUint16(dst[2:], r1) + binary.LittleEndian.PutUint16(dst[4:], r2) + binary.LittleEndian.PutUint16(dst[6:], r3) +} diff --git a/vendor/golang.org/x/crypto/pkcs12/mac.go b/vendor/golang.org/x/crypto/pkcs12/mac.go new file mode 100644 index 0000000000..5f38aa7de8 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/mac.go @@ -0,0 +1,45 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import ( + "crypto/hmac" + "crypto/sha1" + "crypto/x509/pkix" + "encoding/asn1" +) + +type macData struct { + Mac digestInfo + MacSalt []byte + Iterations int `asn1:"optional,default:1"` +} + +// from PKCS#7: +type digestInfo struct { + Algorithm pkix.AlgorithmIdentifier + Digest []byte +} + +var ( + oidSHA1 = asn1.ObjectIdentifier([]int{1, 3, 14, 3, 2, 26}) +) + +func verifyMac(macData *macData, message, password []byte) error { + if !macData.Mac.Algorithm.Algorithm.Equal(oidSHA1) { + return NotImplementedError("unknown digest algorithm: " + macData.Mac.Algorithm.Algorithm.String()) + } + + key := pbkdf(sha1Sum, 20, 64, macData.MacSalt, password, macData.Iterations, 3, 20) + + mac := hmac.New(sha1.New, key) + mac.Write(message) + expectedMAC := mac.Sum(nil) + + if !hmac.Equal(macData.Mac.Digest, expectedMAC) { + return ErrIncorrectPassword + } + return nil +} diff --git a/vendor/golang.org/x/crypto/pkcs12/pbkdf.go b/vendor/golang.org/x/crypto/pkcs12/pbkdf.go new file mode 100644 index 0000000000..5c419d41e3 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/pbkdf.go @@ -0,0 +1,170 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import ( + "bytes" + "crypto/sha1" + "math/big" +) + +var ( + one = big.NewInt(1) +) + +// sha1Sum returns the SHA-1 hash of in. +func sha1Sum(in []byte) []byte { + sum := sha1.Sum(in) + return sum[:] +} + +// fillWithRepeats returns v*ceiling(len(pattern) / v) bytes consisting of +// repeats of pattern. +func fillWithRepeats(pattern []byte, v int) []byte { + if len(pattern) == 0 { + return nil + } + outputLen := v * ((len(pattern) + v - 1) / v) + return bytes.Repeat(pattern, (outputLen+len(pattern)-1)/len(pattern))[:outputLen] +} + +func pbkdf(hash func([]byte) []byte, u, v int, salt, password []byte, r int, ID byte, size int) (key []byte) { + // implementation of https://tools.ietf.org/html/rfc7292#appendix-B.2 , RFC text verbatim in comments + + // Let H be a hash function built around a compression function f: + + // Z_2^u x Z_2^v -> Z_2^u + + // (that is, H has a chaining variable and output of length u bits, and + // the message input to the compression function of H is v bits). The + // values for u and v are as follows: + + // HASH FUNCTION VALUE u VALUE v + // MD2, MD5 128 512 + // SHA-1 160 512 + // SHA-224 224 512 + // SHA-256 256 512 + // SHA-384 384 1024 + // SHA-512 512 1024 + // SHA-512/224 224 1024 + // SHA-512/256 256 1024 + + // Furthermore, let r be the iteration count. + + // We assume here that u and v are both multiples of 8, as are the + // lengths of the password and salt strings (which we denote by p and s, + // respectively) and the number n of pseudorandom bits required. In + // addition, u and v are of course non-zero. + + // For information on security considerations for MD5 [19], see [25] and + // [1], and on those for MD2, see [18]. + + // The following procedure can be used to produce pseudorandom bits for + // a particular "purpose" that is identified by a byte called "ID". + // This standard specifies 3 different values for the ID byte: + + // 1. If ID=1, then the pseudorandom bits being produced are to be used + // as key material for performing encryption or decryption. + + // 2. If ID=2, then the pseudorandom bits being produced are to be used + // as an IV (Initial Value) for encryption or decryption. + + // 3. If ID=3, then the pseudorandom bits being produced are to be used + // as an integrity key for MACing. + + // 1. Construct a string, D (the "diversifier"), by concatenating v/8 + // copies of ID. + var D []byte + for i := 0; i < v; i++ { + D = append(D, ID) + } + + // 2. Concatenate copies of the salt together to create a string S of + // length v(ceiling(s/v)) bits (the final copy of the salt may be + // truncated to create S). Note that if the salt is the empty + // string, then so is S. + + S := fillWithRepeats(salt, v) + + // 3. Concatenate copies of the password together to create a string P + // of length v(ceiling(p/v)) bits (the final copy of the password + // may be truncated to create P). Note that if the password is the + // empty string, then so is P. + + P := fillWithRepeats(password, v) + + // 4. Set I=S||P to be the concatenation of S and P. + I := append(S, P...) + + // 5. Set c=ceiling(n/u). + c := (size + u - 1) / u + + // 6. For i=1, 2, ..., c, do the following: + A := make([]byte, c*20) + var IjBuf []byte + for i := 0; i < c; i++ { + // A. Set A2=H^r(D||I). (i.e., the r-th hash of D||1, + // H(H(H(... H(D||I)))) + Ai := hash(append(D, I...)) + for j := 1; j < r; j++ { + Ai = hash(Ai) + } + copy(A[i*20:], Ai[:]) + + if i < c-1 { // skip on last iteration + // B. Concatenate copies of Ai to create a string B of length v + // bits (the final copy of Ai may be truncated to create B). + var B []byte + for len(B) < v { + B = append(B, Ai[:]...) + } + B = B[:v] + + // C. Treating I as a concatenation I_0, I_1, ..., I_(k-1) of v-bit + // blocks, where k=ceiling(s/v)+ceiling(p/v), modify I by + // setting I_j=(I_j+B+1) mod 2^v for each j. + { + Bbi := new(big.Int).SetBytes(B) + Ij := new(big.Int) + + for j := 0; j < len(I)/v; j++ { + Ij.SetBytes(I[j*v : (j+1)*v]) + Ij.Add(Ij, Bbi) + Ij.Add(Ij, one) + Ijb := Ij.Bytes() + // We expect Ijb to be exactly v bytes, + // if it is longer or shorter we must + // adjust it accordingly. + if len(Ijb) > v { + Ijb = Ijb[len(Ijb)-v:] + } + if len(Ijb) < v { + if IjBuf == nil { + IjBuf = make([]byte, v) + } + bytesShort := v - len(Ijb) + for i := 0; i < bytesShort; i++ { + IjBuf[i] = 0 + } + copy(IjBuf[bytesShort:], Ijb) + Ijb = IjBuf + } + copy(I[j*v:(j+1)*v], Ijb) + } + } + } + } + // 7. Concatenate A_1, A_2, ..., A_c together to form a pseudorandom + // bit string, A. + + // 8. Use the first n bits of A as the output of this entire process. + return A[:size] + + // If the above process is being used to generate a DES key, the process + // should be used to create 64 random bits, and the key's parity bits + // should be set after the 64 bits have been produced. Similar concerns + // hold for 2-key and 3-key triple-DES keys, for CDMF keys, and for any + // similar keys with parity bits "built into them". +} diff --git a/vendor/golang.org/x/crypto/pkcs12/pkcs12.go b/vendor/golang.org/x/crypto/pkcs12/pkcs12.go new file mode 100644 index 0000000000..55f7691d48 --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/pkcs12.go @@ -0,0 +1,349 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package pkcs12 implements some of PKCS#12. +// +// This implementation is distilled from https://tools.ietf.org/html/rfc7292 +// and referenced documents. It is intended for decoding P12/PFX-stored +// certificates and keys for use with the crypto/tls package. +// +// This package is frozen. If it's missing functionality you need, consider +// an alternative like software.sslmate.com/src/go-pkcs12. +package pkcs12 + +import ( + "crypto/ecdsa" + "crypto/rsa" + "crypto/x509" + "crypto/x509/pkix" + "encoding/asn1" + "encoding/hex" + "encoding/pem" + "errors" +) + +var ( + oidDataContentType = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 7, 1}) + oidEncryptedDataContentType = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 7, 6}) + + oidFriendlyName = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 20}) + oidLocalKeyID = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 21}) + oidMicrosoftCSPName = asn1.ObjectIdentifier([]int{1, 3, 6, 1, 4, 1, 311, 17, 1}) +) + +type pfxPdu struct { + Version int + AuthSafe contentInfo + MacData macData `asn1:"optional"` +} + +type contentInfo struct { + ContentType asn1.ObjectIdentifier + Content asn1.RawValue `asn1:"tag:0,explicit,optional"` +} + +type encryptedData struct { + Version int + EncryptedContentInfo encryptedContentInfo +} + +type encryptedContentInfo struct { + ContentType asn1.ObjectIdentifier + ContentEncryptionAlgorithm pkix.AlgorithmIdentifier + EncryptedContent []byte `asn1:"tag:0,optional"` +} + +func (i encryptedContentInfo) Algorithm() pkix.AlgorithmIdentifier { + return i.ContentEncryptionAlgorithm +} + +func (i encryptedContentInfo) Data() []byte { return i.EncryptedContent } + +type safeBag struct { + Id asn1.ObjectIdentifier + Value asn1.RawValue `asn1:"tag:0,explicit"` + Attributes []pkcs12Attribute `asn1:"set,optional"` +} + +type pkcs12Attribute struct { + Id asn1.ObjectIdentifier + Value asn1.RawValue `asn1:"set"` +} + +type encryptedPrivateKeyInfo struct { + AlgorithmIdentifier pkix.AlgorithmIdentifier + EncryptedData []byte +} + +func (i encryptedPrivateKeyInfo) Algorithm() pkix.AlgorithmIdentifier { + return i.AlgorithmIdentifier +} + +func (i encryptedPrivateKeyInfo) Data() []byte { + return i.EncryptedData +} + +// PEM block types +const ( + certificateType = "CERTIFICATE" + privateKeyType = "PRIVATE KEY" +) + +// unmarshal calls asn1.Unmarshal, but also returns an error if there is any +// trailing data after unmarshaling. +func unmarshal(in []byte, out interface{}) error { + trailing, err := asn1.Unmarshal(in, out) + if err != nil { + return err + } + if len(trailing) != 0 { + return errors.New("pkcs12: trailing data found") + } + return nil +} + +// ToPEM converts all "safe bags" contained in pfxData to PEM blocks. +func ToPEM(pfxData []byte, password string) ([]*pem.Block, error) { + encodedPassword, err := bmpString(password) + if err != nil { + return nil, ErrIncorrectPassword + } + + bags, encodedPassword, err := getSafeContents(pfxData, encodedPassword) + + if err != nil { + return nil, err + } + + blocks := make([]*pem.Block, 0, len(bags)) + for _, bag := range bags { + block, err := convertBag(&bag, encodedPassword) + if err != nil { + return nil, err + } + blocks = append(blocks, block) + } + + return blocks, nil +} + +func convertBag(bag *safeBag, password []byte) (*pem.Block, error) { + block := &pem.Block{ + Headers: make(map[string]string), + } + + for _, attribute := range bag.Attributes { + k, v, err := convertAttribute(&attribute) + if err != nil { + return nil, err + } + block.Headers[k] = v + } + + switch { + case bag.Id.Equal(oidCertBag): + block.Type = certificateType + certsData, err := decodeCertBag(bag.Value.Bytes) + if err != nil { + return nil, err + } + block.Bytes = certsData + case bag.Id.Equal(oidPKCS8ShroundedKeyBag): + block.Type = privateKeyType + + key, err := decodePkcs8ShroudedKeyBag(bag.Value.Bytes, password) + if err != nil { + return nil, err + } + + switch key := key.(type) { + case *rsa.PrivateKey: + block.Bytes = x509.MarshalPKCS1PrivateKey(key) + case *ecdsa.PrivateKey: + block.Bytes, err = x509.MarshalECPrivateKey(key) + if err != nil { + return nil, err + } + default: + return nil, errors.New("found unknown private key type in PKCS#8 wrapping") + } + default: + return nil, errors.New("don't know how to convert a safe bag of type " + bag.Id.String()) + } + return block, nil +} + +func convertAttribute(attribute *pkcs12Attribute) (key, value string, err error) { + isString := false + + switch { + case attribute.Id.Equal(oidFriendlyName): + key = "friendlyName" + isString = true + case attribute.Id.Equal(oidLocalKeyID): + key = "localKeyId" + case attribute.Id.Equal(oidMicrosoftCSPName): + // This key is chosen to match OpenSSL. + key = "Microsoft CSP Name" + isString = true + default: + return "", "", errors.New("pkcs12: unknown attribute with OID " + attribute.Id.String()) + } + + if isString { + if err := unmarshal(attribute.Value.Bytes, &attribute.Value); err != nil { + return "", "", err + } + if value, err = decodeBMPString(attribute.Value.Bytes); err != nil { + return "", "", err + } + } else { + var id []byte + if err := unmarshal(attribute.Value.Bytes, &id); err != nil { + return "", "", err + } + value = hex.EncodeToString(id) + } + + return key, value, nil +} + +// Decode extracts a certificate and private key from pfxData. This function +// assumes that there is only one certificate and only one private key in the +// pfxData; if there are more use ToPEM instead. +func Decode(pfxData []byte, password string) (privateKey interface{}, certificate *x509.Certificate, err error) { + encodedPassword, err := bmpString(password) + if err != nil { + return nil, nil, err + } + + bags, encodedPassword, err := getSafeContents(pfxData, encodedPassword) + if err != nil { + return nil, nil, err + } + + if len(bags) != 2 { + err = errors.New("pkcs12: expected exactly two safe bags in the PFX PDU") + return + } + + for _, bag := range bags { + switch { + case bag.Id.Equal(oidCertBag): + if certificate != nil { + err = errors.New("pkcs12: expected exactly one certificate bag") + } + + certsData, err := decodeCertBag(bag.Value.Bytes) + if err != nil { + return nil, nil, err + } + certs, err := x509.ParseCertificates(certsData) + if err != nil { + return nil, nil, err + } + if len(certs) != 1 { + err = errors.New("pkcs12: expected exactly one certificate in the certBag") + return nil, nil, err + } + certificate = certs[0] + + case bag.Id.Equal(oidPKCS8ShroundedKeyBag): + if privateKey != nil { + err = errors.New("pkcs12: expected exactly one key bag") + } + + if privateKey, err = decodePkcs8ShroudedKeyBag(bag.Value.Bytes, encodedPassword); err != nil { + return nil, nil, err + } + } + } + + if certificate == nil { + return nil, nil, errors.New("pkcs12: certificate missing") + } + if privateKey == nil { + return nil, nil, errors.New("pkcs12: private key missing") + } + + return +} + +func getSafeContents(p12Data, password []byte) (bags []safeBag, updatedPassword []byte, err error) { + pfx := new(pfxPdu) + if err := unmarshal(p12Data, pfx); err != nil { + return nil, nil, errors.New("pkcs12: error reading P12 data: " + err.Error()) + } + + if pfx.Version != 3 { + return nil, nil, NotImplementedError("can only decode v3 PFX PDU's") + } + + if !pfx.AuthSafe.ContentType.Equal(oidDataContentType) { + return nil, nil, NotImplementedError("only password-protected PFX is implemented") + } + + // unmarshal the explicit bytes in the content for type 'data' + if err := unmarshal(pfx.AuthSafe.Content.Bytes, &pfx.AuthSafe.Content); err != nil { + return nil, nil, err + } + + if len(pfx.MacData.Mac.Algorithm.Algorithm) == 0 { + return nil, nil, errors.New("pkcs12: no MAC in data") + } + + if err := verifyMac(&pfx.MacData, pfx.AuthSafe.Content.Bytes, password); err != nil { + if err == ErrIncorrectPassword && len(password) == 2 && password[0] == 0 && password[1] == 0 { + // some implementations use an empty byte array + // for the empty string password try one more + // time with empty-empty password + password = nil + err = verifyMac(&pfx.MacData, pfx.AuthSafe.Content.Bytes, password) + } + if err != nil { + return nil, nil, err + } + } + + var authenticatedSafe []contentInfo + if err := unmarshal(pfx.AuthSafe.Content.Bytes, &authenticatedSafe); err != nil { + return nil, nil, err + } + + if len(authenticatedSafe) != 2 { + return nil, nil, NotImplementedError("expected exactly two items in the authenticated safe") + } + + for _, ci := range authenticatedSafe { + var data []byte + + switch { + case ci.ContentType.Equal(oidDataContentType): + if err := unmarshal(ci.Content.Bytes, &data); err != nil { + return nil, nil, err + } + case ci.ContentType.Equal(oidEncryptedDataContentType): + var encryptedData encryptedData + if err := unmarshal(ci.Content.Bytes, &encryptedData); err != nil { + return nil, nil, err + } + if encryptedData.Version != 0 { + return nil, nil, NotImplementedError("only version 0 of EncryptedData is supported") + } + if data, err = pbDecrypt(encryptedData.EncryptedContentInfo, password); err != nil { + return nil, nil, err + } + default: + return nil, nil, NotImplementedError("only data and encryptedData content types are supported in authenticated safe") + } + + var safeContents []safeBag + if err := unmarshal(data, &safeContents); err != nil { + return nil, nil, err + } + bags = append(bags, safeContents...) + } + + return bags, password, nil +} diff --git a/vendor/golang.org/x/crypto/pkcs12/safebags.go b/vendor/golang.org/x/crypto/pkcs12/safebags.go new file mode 100644 index 0000000000..def1f7b98d --- /dev/null +++ b/vendor/golang.org/x/crypto/pkcs12/safebags.go @@ -0,0 +1,57 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkcs12 + +import ( + "crypto/x509" + "encoding/asn1" + "errors" +) + +var ( + // see https://tools.ietf.org/html/rfc7292#appendix-D + oidCertTypeX509Certificate = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 9, 22, 1}) + oidPKCS8ShroundedKeyBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 2}) + oidCertBag = asn1.ObjectIdentifier([]int{1, 2, 840, 113549, 1, 12, 10, 1, 3}) +) + +type certBag struct { + Id asn1.ObjectIdentifier + Data []byte `asn1:"tag:0,explicit"` +} + +func decodePkcs8ShroudedKeyBag(asn1Data, password []byte) (privateKey interface{}, err error) { + pkinfo := new(encryptedPrivateKeyInfo) + if err = unmarshal(asn1Data, pkinfo); err != nil { + return nil, errors.New("pkcs12: error decoding PKCS#8 shrouded key bag: " + err.Error()) + } + + pkData, err := pbDecrypt(pkinfo, password) + if err != nil { + return nil, errors.New("pkcs12: error decrypting PKCS#8 shrouded key bag: " + err.Error()) + } + + ret := new(asn1.RawValue) + if err = unmarshal(pkData, ret); err != nil { + return nil, errors.New("pkcs12: error unmarshaling decrypted private key: " + err.Error()) + } + + if privateKey, err = x509.ParsePKCS8PrivateKey(pkData); err != nil { + return nil, errors.New("pkcs12: error parsing PKCS#8 private key: " + err.Error()) + } + + return privateKey, nil +} + +func decodeCertBag(asn1Data []byte) (x509Certificates []byte, err error) { + bag := new(certBag) + if err := unmarshal(asn1Data, bag); err != nil { + return nil, errors.New("pkcs12: error decoding cert bag: " + err.Error()) + } + if !bag.Id.Equal(oidCertTypeX509Certificate) { + return nil, NotImplementedError("only X509 certificates are supported") + } + return bag.Data, nil +} diff --git a/vendor/golang.org/x/net/publicsuffix/gen.go b/vendor/golang.org/x/net/publicsuffix/gen.go new file mode 100644 index 0000000000..372ffbb24c --- /dev/null +++ b/vendor/golang.org/x/net/publicsuffix/gen.go @@ -0,0 +1,717 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build ignore + +package main + +// This program generates table.go and table_test.go based on the authoritative +// public suffix list at https://publicsuffix.org/list/effective_tld_names.dat +// +// The version is derived from +// https://api.github.com/repos/publicsuffix/list/commits?path=public_suffix_list.dat +// and a human-readable form is at +// https://github.com/publicsuffix/list/commits/master/public_suffix_list.dat +// +// To fetch a particular git revision, such as 5c70ccd250, pass +// -url "https://raw.githubusercontent.com/publicsuffix/list/5c70ccd250/public_suffix_list.dat" +// and -version "an explicit version string". + +import ( + "bufio" + "bytes" + "flag" + "fmt" + "go/format" + "io" + "io/ioutil" + "net/http" + "os" + "regexp" + "sort" + "strings" + + "golang.org/x/net/idna" +) + +const ( + // These sum of these four values must be no greater than 32. + nodesBitsChildren = 10 + nodesBitsICANN = 1 + nodesBitsTextOffset = 15 + nodesBitsTextLength = 6 + + // These sum of these four values must be no greater than 32. + childrenBitsWildcard = 1 + childrenBitsNodeType = 2 + childrenBitsHi = 14 + childrenBitsLo = 14 +) + +var ( + maxChildren int + maxTextOffset int + maxTextLength int + maxHi uint32 + maxLo uint32 +) + +func max(a, b int) int { + if a < b { + return b + } + return a +} + +func u32max(a, b uint32) uint32 { + if a < b { + return b + } + return a +} + +const ( + nodeTypeNormal = 0 + nodeTypeException = 1 + nodeTypeParentOnly = 2 + numNodeType = 3 +) + +func nodeTypeStr(n int) string { + switch n { + case nodeTypeNormal: + return "+" + case nodeTypeException: + return "!" + case nodeTypeParentOnly: + return "o" + } + panic("unreachable") +} + +const ( + defaultURL = "https://publicsuffix.org/list/effective_tld_names.dat" + gitCommitURL = "https://api.github.com/repos/publicsuffix/list/commits?path=public_suffix_list.dat" +) + +var ( + labelEncoding = map[string]uint32{} + labelsList = []string{} + labelsMap = map[string]bool{} + rules = []string{} + numICANNRules = 0 + + // validSuffixRE is used to check that the entries in the public suffix + // list are in canonical form (after Punycode encoding). Specifically, + // capital letters are not allowed. + validSuffixRE = regexp.MustCompile(`^[a-z0-9_\!\*\-\.]+$`) + + shaRE = regexp.MustCompile(`"sha":"([^"]+)"`) + dateRE = regexp.MustCompile(`"committer":{[^{]+"date":"([^"]+)"`) + + comments = flag.Bool("comments", false, "generate table.go comments, for debugging") + subset = flag.Bool("subset", false, "generate only a subset of the full table, for debugging") + url = flag.String("url", defaultURL, "URL of the publicsuffix.org list. If empty, stdin is read instead") + v = flag.Bool("v", false, "verbose output (to stderr)") + version = flag.String("version", "", "the effective_tld_names.dat version") +) + +func main() { + if err := main1(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func main1() error { + flag.Parse() + if nodesBitsTextLength+nodesBitsTextOffset+nodesBitsICANN+nodesBitsChildren > 32 { + return fmt.Errorf("not enough bits to encode the nodes table") + } + if childrenBitsLo+childrenBitsHi+childrenBitsNodeType+childrenBitsWildcard > 32 { + return fmt.Errorf("not enough bits to encode the children table") + } + if *version == "" { + if *url != defaultURL { + return fmt.Errorf("-version was not specified, and the -url is not the default one") + } + sha, date, err := gitCommit() + if err != nil { + return err + } + *version = fmt.Sprintf("publicsuffix.org's public_suffix_list.dat, git revision %s (%s)", sha, date) + } + var r io.Reader = os.Stdin + if *url != "" { + res, err := http.Get(*url) + if err != nil { + return err + } + if res.StatusCode != http.StatusOK { + return fmt.Errorf("bad GET status for %s: %d", *url, res.Status) + } + r = res.Body + defer res.Body.Close() + } + + var root node + icann := false + br := bufio.NewReader(r) + for { + s, err := br.ReadString('\n') + if err != nil { + if err == io.EOF { + break + } + return err + } + s = strings.TrimSpace(s) + if strings.Contains(s, "BEGIN ICANN DOMAINS") { + if len(rules) != 0 { + return fmt.Errorf(`expected no rules before "BEGIN ICANN DOMAINS"`) + } + icann = true + continue + } + if strings.Contains(s, "END ICANN DOMAINS") { + icann, numICANNRules = false, len(rules) + continue + } + if s == "" || strings.HasPrefix(s, "//") { + continue + } + s, err = idna.ToASCII(s) + if err != nil { + return err + } + if !validSuffixRE.MatchString(s) { + return fmt.Errorf("bad publicsuffix.org list data: %q", s) + } + + if *subset { + switch { + case s == "ac.jp" || strings.HasSuffix(s, ".ac.jp"): + case s == "ak.us" || strings.HasSuffix(s, ".ak.us"): + case s == "ao" || strings.HasSuffix(s, ".ao"): + case s == "ar" || strings.HasSuffix(s, ".ar"): + case s == "arpa" || strings.HasSuffix(s, ".arpa"): + case s == "cy" || strings.HasSuffix(s, ".cy"): + case s == "dyndns.org" || strings.HasSuffix(s, ".dyndns.org"): + case s == "jp": + case s == "kobe.jp" || strings.HasSuffix(s, ".kobe.jp"): + case s == "kyoto.jp" || strings.HasSuffix(s, ".kyoto.jp"): + case s == "om" || strings.HasSuffix(s, ".om"): + case s == "uk" || strings.HasSuffix(s, ".uk"): + case s == "uk.com" || strings.HasSuffix(s, ".uk.com"): + case s == "tw" || strings.HasSuffix(s, ".tw"): + case s == "zw" || strings.HasSuffix(s, ".zw"): + case s == "xn--p1ai" || strings.HasSuffix(s, ".xn--p1ai"): + // xn--p1ai is Russian-Cyrillic "рф". + default: + continue + } + } + + rules = append(rules, s) + + nt, wildcard := nodeTypeNormal, false + switch { + case strings.HasPrefix(s, "*."): + s, nt = s[2:], nodeTypeParentOnly + wildcard = true + case strings.HasPrefix(s, "!"): + s, nt = s[1:], nodeTypeException + } + labels := strings.Split(s, ".") + for n, i := &root, len(labels)-1; i >= 0; i-- { + label := labels[i] + n = n.child(label) + if i == 0 { + if nt != nodeTypeParentOnly && n.nodeType == nodeTypeParentOnly { + n.nodeType = nt + } + n.icann = n.icann && icann + n.wildcard = n.wildcard || wildcard + } + labelsMap[label] = true + } + } + labelsList = make([]string, 0, len(labelsMap)) + for label := range labelsMap { + labelsList = append(labelsList, label) + } + sort.Strings(labelsList) + + if err := generate(printReal, &root, "table.go"); err != nil { + return err + } + if err := generate(printTest, &root, "table_test.go"); err != nil { + return err + } + return nil +} + +func generate(p func(io.Writer, *node) error, root *node, filename string) error { + buf := new(bytes.Buffer) + if err := p(buf, root); err != nil { + return err + } + b, err := format.Source(buf.Bytes()) + if err != nil { + return err + } + return ioutil.WriteFile(filename, b, 0644) +} + +func gitCommit() (sha, date string, retErr error) { + res, err := http.Get(gitCommitURL) + if err != nil { + return "", "", err + } + if res.StatusCode != http.StatusOK { + return "", "", fmt.Errorf("bad GET status for %s: %d", gitCommitURL, res.Status) + } + defer res.Body.Close() + b, err := ioutil.ReadAll(res.Body) + if err != nil { + return "", "", err + } + if m := shaRE.FindSubmatch(b); m != nil { + sha = string(m[1]) + } + if m := dateRE.FindSubmatch(b); m != nil { + date = string(m[1]) + } + if sha == "" || date == "" { + retErr = fmt.Errorf("could not find commit SHA and date in %s", gitCommitURL) + } + return sha, date, retErr +} + +func printTest(w io.Writer, n *node) error { + fmt.Fprintf(w, "// generated by go run gen.go; DO NOT EDIT\n\n") + fmt.Fprintf(w, "package publicsuffix\n\nconst numICANNRules = %d\n\nvar rules = [...]string{\n", numICANNRules) + for _, rule := range rules { + fmt.Fprintf(w, "%q,\n", rule) + } + fmt.Fprintf(w, "}\n\nvar nodeLabels = [...]string{\n") + if err := n.walk(w, printNodeLabel); err != nil { + return err + } + fmt.Fprintf(w, "}\n") + return nil +} + +func printReal(w io.Writer, n *node) error { + const header = `// generated by go run gen.go; DO NOT EDIT + +package publicsuffix + +const version = %q + +const ( + nodesBitsChildren = %d + nodesBitsICANN = %d + nodesBitsTextOffset = %d + nodesBitsTextLength = %d + + childrenBitsWildcard = %d + childrenBitsNodeType = %d + childrenBitsHi = %d + childrenBitsLo = %d +) + +const ( + nodeTypeNormal = %d + nodeTypeException = %d + nodeTypeParentOnly = %d +) + +// numTLD is the number of top level domains. +const numTLD = %d + +` + fmt.Fprintf(w, header, *version, + nodesBitsChildren, nodesBitsICANN, nodesBitsTextOffset, nodesBitsTextLength, + childrenBitsWildcard, childrenBitsNodeType, childrenBitsHi, childrenBitsLo, + nodeTypeNormal, nodeTypeException, nodeTypeParentOnly, len(n.children)) + + text := combineText(labelsList) + if text == "" { + return fmt.Errorf("internal error: makeText returned no text") + } + for _, label := range labelsList { + offset, length := strings.Index(text, label), len(label) + if offset < 0 { + return fmt.Errorf("internal error: could not find %q in text %q", label, text) + } + maxTextOffset, maxTextLength = max(maxTextOffset, offset), max(maxTextLength, length) + if offset >= 1<= 1< 64 { + n, plus = 64, " +" + } + fmt.Fprintf(w, "%q%s\n", text[:n], plus) + text = text[n:] + } + + if err := n.walk(w, assignIndexes); err != nil { + return err + } + + fmt.Fprintf(w, ` + +// nodes is the list of nodes. Each node is represented as a uint32, which +// encodes the node's children, wildcard bit and node type (as an index into +// the children array), ICANN bit and text. +// +// If the table was generated with the -comments flag, there is a //-comment +// after each node's data. In it is the nodes-array indexes of the children, +// formatted as (n0x1234-n0x1256), with * denoting the wildcard bit. The +// nodeType is printed as + for normal, ! for exception, and o for parent-only +// nodes that have children but don't match a domain label in their own right. +// An I denotes an ICANN domain. +// +// The layout within the uint32, from MSB to LSB, is: +// [%2d bits] unused +// [%2d bits] children index +// [%2d bits] ICANN bit +// [%2d bits] text index +// [%2d bits] text length +var nodes = [...]uint32{ +`, + 32-nodesBitsChildren-nodesBitsICANN-nodesBitsTextOffset-nodesBitsTextLength, + nodesBitsChildren, nodesBitsICANN, nodesBitsTextOffset, nodesBitsTextLength) + if err := n.walk(w, printNode); err != nil { + return err + } + fmt.Fprintf(w, `} + +// children is the list of nodes' children, the parent's wildcard bit and the +// parent's node type. If a node has no children then their children index +// will be in the range [0, 6), depending on the wildcard bit and node type. +// +// The layout within the uint32, from MSB to LSB, is: +// [%2d bits] unused +// [%2d bits] wildcard bit +// [%2d bits] node type +// [%2d bits] high nodes index (exclusive) of children +// [%2d bits] low nodes index (inclusive) of children +var children=[...]uint32{ +`, + 32-childrenBitsWildcard-childrenBitsNodeType-childrenBitsHi-childrenBitsLo, + childrenBitsWildcard, childrenBitsNodeType, childrenBitsHi, childrenBitsLo) + for i, c := range childrenEncoding { + s := "---------------" + lo := c & (1<> childrenBitsLo) & (1<>(childrenBitsLo+childrenBitsHi)) & (1<>(childrenBitsLo+childrenBitsHi+childrenBitsNodeType) != 0 + if *comments { + fmt.Fprintf(w, "0x%08x, // c0x%04x (%s)%s %s\n", + c, i, s, wildcardStr(wildcard), nodeTypeStr(nodeType)) + } else { + fmt.Fprintf(w, "0x%x,\n", c) + } + } + fmt.Fprintf(w, "}\n\n") + fmt.Fprintf(w, "// max children %d (capacity %d)\n", maxChildren, 1<= 1<= 1<= 1< 0 && ss[0] == "" { + ss = ss[1:] + } + return ss +} + +// crush combines a list of strings, taking advantage of overlaps. It returns a +// single string that contains each input string as a substring. +func crush(ss []string) string { + maxLabelLen := 0 + for _, s := range ss { + if maxLabelLen < len(s) { + maxLabelLen = len(s) + } + } + + for prefixLen := maxLabelLen; prefixLen > 0; prefixLen-- { + prefixes := makePrefixMap(ss, prefixLen) + for i, s := range ss { + if len(s) <= prefixLen { + continue + } + mergeLabel(ss, i, prefixLen, prefixes) + } + } + + return strings.Join(ss, "") +} + +// mergeLabel merges the label at ss[i] with the first available matching label +// in prefixMap, where the last "prefixLen" characters in ss[i] match the first +// "prefixLen" characters in the matching label. +// It will merge ss[i] repeatedly until no more matches are available. +// All matching labels merged into ss[i] are replaced by "". +func mergeLabel(ss []string, i, prefixLen int, prefixes prefixMap) { + s := ss[i] + suffix := s[len(s)-prefixLen:] + for _, j := range prefixes[suffix] { + // Empty strings mean "already used." Also avoid merging with self. + if ss[j] == "" || i == j { + continue + } + if *v { + fmt.Fprintf(os.Stderr, "%d-length overlap at (%4d,%4d): %q and %q share %q\n", + prefixLen, i, j, ss[i], ss[j], suffix) + } + ss[i] += ss[j][prefixLen:] + ss[j] = "" + // ss[i] has a new suffix, so merge again if possible. + // Note: we only have to merge again at the same prefix length. Shorter + // prefix lengths will be handled in the next iteration of crush's for loop. + // Can there be matches for longer prefix lengths, introduced by the merge? + // I believe that any such matches would by necessity have been eliminated + // during substring removal or merged at a higher prefix length. For + // instance, in crush("abc", "cde", "bcdef"), combining "abc" and "cde" + // would yield "abcde", which could be merged with "bcdef." However, in + // practice "cde" would already have been elimintated by removeSubstrings. + mergeLabel(ss, i, prefixLen, prefixes) + return + } +} + +// prefixMap maps from a prefix to a list of strings containing that prefix. The +// list of strings is represented as indexes into a slice of strings stored +// elsewhere. +type prefixMap map[string][]int + +// makePrefixMap constructs a prefixMap from a slice of strings. +func makePrefixMap(ss []string, prefixLen int) prefixMap { + prefixes := make(prefixMap) + for i, s := range ss { + // We use < rather than <= because if a label matches on a prefix equal to + // its full length, that's actually a substring match handled by + // removeSubstrings. + if prefixLen < len(s) { + prefix := s[:prefixLen] + prefixes[prefix] = append(prefixes[prefix], i) + } + } + + return prefixes +} diff --git a/vendor/golang.org/x/net/publicsuffix/list.go b/vendor/golang.org/x/net/publicsuffix/list.go new file mode 100644 index 0000000000..200617ea86 --- /dev/null +++ b/vendor/golang.org/x/net/publicsuffix/list.go @@ -0,0 +1,181 @@ +// Copyright 2012 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:generate go run gen.go + +// Package publicsuffix provides a public suffix list based on data from +// https://publicsuffix.org/ +// +// A public suffix is one under which Internet users can directly register +// names. It is related to, but different from, a TLD (top level domain). +// +// "com" is a TLD (top level domain). Top level means it has no dots. +// +// "com" is also a public suffix. Amazon and Google have registered different +// siblings under that domain: "amazon.com" and "google.com". +// +// "au" is another TLD, again because it has no dots. But it's not "amazon.au". +// Instead, it's "amazon.com.au". +// +// "com.au" isn't an actual TLD, because it's not at the top level (it has +// dots). But it is an eTLD (effective TLD), because that's the branching point +// for domain name registrars. +// +// Another name for "an eTLD" is "a public suffix". Often, what's more of +// interest is the eTLD+1, or one more label than the public suffix. For +// example, browsers partition read/write access to HTTP cookies according to +// the eTLD+1. Web pages served from "amazon.com.au" can't read cookies from +// "google.com.au", but web pages served from "maps.google.com" can share +// cookies from "www.google.com", so you don't have to sign into Google Maps +// separately from signing into Google Web Search. Note that all four of those +// domains have 3 labels and 2 dots. The first two domains are each an eTLD+1, +// the last two are not (but share the same eTLD+1: "google.com"). +// +// All of these domains have the same eTLD+1: +// - "www.books.amazon.co.uk" +// - "books.amazon.co.uk" +// - "amazon.co.uk" +// Specifically, the eTLD+1 is "amazon.co.uk", because the eTLD is "co.uk". +// +// There is no closed form algorithm to calculate the eTLD of a domain. +// Instead, the calculation is data driven. This package provides a +// pre-compiled snapshot of Mozilla's PSL (Public Suffix List) data at +// https://publicsuffix.org/ +package publicsuffix // import "golang.org/x/net/publicsuffix" + +// TODO: specify case sensitivity and leading/trailing dot behavior for +// func PublicSuffix and func EffectiveTLDPlusOne. + +import ( + "fmt" + "net/http/cookiejar" + "strings" +) + +// List implements the cookiejar.PublicSuffixList interface by calling the +// PublicSuffix function. +var List cookiejar.PublicSuffixList = list{} + +type list struct{} + +func (list) PublicSuffix(domain string) string { + ps, _ := PublicSuffix(domain) + return ps +} + +func (list) String() string { + return version +} + +// PublicSuffix returns the public suffix of the domain using a copy of the +// publicsuffix.org database compiled into the library. +// +// icann is whether the public suffix is managed by the Internet Corporation +// for Assigned Names and Numbers. If not, the public suffix is either a +// privately managed domain (and in practice, not a top level domain) or an +// unmanaged top level domain (and not explicitly mentioned in the +// publicsuffix.org list). For example, "foo.org" and "foo.co.uk" are ICANN +// domains, "foo.dyndns.org" and "foo.blogspot.co.uk" are private domains and +// "cromulent" is an unmanaged top level domain. +// +// Use cases for distinguishing ICANN domains like "foo.com" from private +// domains like "foo.appspot.com" can be found at +// https://wiki.mozilla.org/Public_Suffix_List/Use_Cases +func PublicSuffix(domain string) (publicSuffix string, icann bool) { + lo, hi := uint32(0), uint32(numTLD) + s, suffix, icannNode, wildcard := domain, len(domain), false, false +loop: + for { + dot := strings.LastIndex(s, ".") + if wildcard { + icann = icannNode + suffix = 1 + dot + } + if lo == hi { + break + } + f := find(s[1+dot:], lo, hi) + if f == notFound { + break + } + + u := nodes[f] >> (nodesBitsTextOffset + nodesBitsTextLength) + icannNode = u&(1<>= nodesBitsICANN + u = children[u&(1<>= childrenBitsLo + hi = u & (1<>= childrenBitsHi + switch u & (1<>= childrenBitsNodeType + wildcard = u&(1<>= nodesBitsTextLength + offset := x & (1< + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/gopkg.in/resty.v1/README.md b/vendor/gopkg.in/resty.v1/README.md new file mode 100644 index 0000000000..8305734db8 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/README.md @@ -0,0 +1,741 @@ +

    +

    Resty

    +

    Simple HTTP and REST client library for Go (inspired by Ruby rest-client)

    +

    Features section describes in detail about Resty capabilities

    +

    +

    +

    Build Status Code Coverage Go Report Card Release Version GoDoc License

    +

    +

    +

    Resty Communication Channels

    +

    Chat on Gitter - Resty Community Twitter @go_resty

    +

    + +## News + + * Resty `v2` development is in-progress :smile: + * v1.12.0 [released](https://github.com/go-resty/resty/releases/tag/v1.12.0) and tagged on Feb 27, 2019. + * v1.11.0 [released](https://github.com/go-resty/resty/releases/tag/v1.11.0) and tagged on Jan 06, 2019. + * v1.10.3 [released](https://github.com/go-resty/resty/releases/tag/v1.10.3) and tagged on Dec 04, 2018. + * v1.0 released and tagged on Sep 25, 2017. - Resty's first version was released on Sep 15, 2015 then it grew gradually as a very handy and helpful library. Its been a two years since first release. I'm very thankful to Resty users and its [contributors](https://github.com/go-resty/resty/graphs/contributors). + +## Features + + * GET, POST, PUT, DELETE, HEAD, PATCH, OPTIONS, etc. + * Simple and chainable methods for settings and request + * Request Body can be `string`, `[]byte`, `struct`, `map`, `slice` and `io.Reader` too + * Auto detects `Content-Type` + * Buffer less processing for `io.Reader` + * [Response](https://godoc.org/gopkg.in/resty.v1#Response) object gives you more possibility + * Access as `[]byte` array - `response.Body()` OR Access as `string` - `response.String()` + * Know your `response.Time()` and when we `response.ReceivedAt()` + * Automatic marshal and unmarshal for `JSON` and `XML` content type + * Default is `JSON`, if you supply `struct/map` without header `Content-Type` + * For auto-unmarshal, refer to - + - Success scenario [Request.SetResult()](https://godoc.org/gopkg.in/resty.v1#Request.SetResult) and [Response.Result()](https://godoc.org/gopkg.in/resty.v1#Response.Result). + - Error scenario [Request.SetError()](https://godoc.org/gopkg.in/resty.v1#Request.SetError) and [Response.Error()](https://godoc.org/gopkg.in/resty.v1#Response.Error). + - Supports [RFC7807](https://tools.ietf.org/html/rfc7807) - `application/problem+json` & `application/problem+xml` + * Easy to upload one or more file(s) via `multipart/form-data` + * Auto detects file content type + * Request URL [Path Params (aka URI Params)](https://godoc.org/gopkg.in/resty.v1#Request.SetPathParams) + * Backoff Retry Mechanism with retry condition function [reference](retry_test.go) + * resty client HTTP & REST [Request](https://godoc.org/gopkg.in/resty.v1#Client.OnBeforeRequest) and [Response](https://godoc.org/gopkg.in/resty.v1#Client.OnAfterResponse) middlewares + * `Request.SetContext` supported `go1.7` and above + * Authorization option of `BasicAuth` and `Bearer` token + * Set request `ContentLength` value for all request or particular request + * Choose between HTTP and REST mode. Default is `REST` + * `HTTP` - default up to 10 redirects and no automatic response unmarshal + * `REST` - defaults to no redirects and automatic response marshal/unmarshal for `JSON` & `XML` + * Custom [Root Certificates](https://godoc.org/gopkg.in/resty.v1#Client.SetRootCertificate) and Client [Certificates](https://godoc.org/gopkg.in/resty.v1#Client.SetCertificates) + * Download/Save HTTP response directly into File, like `curl -o` flag. See [SetOutputDirectory](https://godoc.org/gopkg.in/resty.v1#Client.SetOutputDirectory) & [SetOutput](https://godoc.org/gopkg.in/resty.v1#Request.SetOutput). + * Cookies for your request and CookieJar support + * SRV Record based request instead of Host URL + * Client settings like `Timeout`, `RedirectPolicy`, `Proxy`, `TLSClientConfig`, `Transport`, etc. + * Optionally allows GET request with payload, see [SetAllowGetMethodPayload](https://godoc.org/gopkg.in/resty.v1#Client.SetAllowGetMethodPayload) + * Supports registering external JSON library into resty, see [how to use](https://github.com/go-resty/resty/issues/76#issuecomment-314015250) + * Exposes Response reader without reading response (no auto-unmarshaling) if need be, see [how to use](https://github.com/go-resty/resty/issues/87#issuecomment-322100604) + * Option to specify expected `Content-Type` when response `Content-Type` header missing. Refer to [#92](https://github.com/go-resty/resty/issues/92) + * Resty design + * Have client level settings & options and also override at Request level if you want to + * Request and Response middlewares + * Create Multiple clients if you want to `resty.New()` + * Supports `http.RoundTripper` implementation, see [SetTransport](https://godoc.org/gopkg.in/resty.v1#Client.SetTransport) + * goroutine concurrent safe + * REST and HTTP modes + * Debug mode - clean and informative logging presentation + * Gzip - Go does it automatically also resty has fallback handling too + * Works fine with `HTTP/2` and `HTTP/1.1` + * [Bazel support](#bazel-support) + * Easily mock resty for testing, [for e.g.](#mocking-http-requests-using-httpmock-library) + * Well tested client library + +Resty works with `go1.3` and above. + +### Included Batteries + + * Redirect Policies - see [how to use](#redirect-policy) + * NoRedirectPolicy + * FlexibleRedirectPolicy + * DomainCheckRedirectPolicy + * etc. [more info](redirect.go) + * Retry Mechanism [how to use](#retries) + * Backoff Retry + * Conditional Retry + * SRV Record based request instead of Host URL [how to use](resty_test.go#L1412) + * etc (upcoming - throw your idea's [here](https://github.com/go-resty/resty/issues)). + +## Installation + +#### Stable Version - Production Ready + +Please refer section [Versioning](#versioning) for detailed info. + +##### go.mod + +```bash +require gopkg.in/resty.v1 v1.12.0 +``` + +##### go get +```bash +go get -u gopkg.in/resty.v1 +``` + +#### Heads up for upcoming Resty v2 + +Resty v2 release will be moving away from `gopkg.in` proxy versioning. It will completely follow and adpating Go Mod versioning recommendation. For e.g.: module definition would be `module github.com/go-resty/resty/v2`. + + +## It might be beneficial for your project :smile: + +Resty author also published following projects for Go Community. + + * [aah framework](https://aahframework.org) - A secure, flexible, rapid Go web framework. + * [THUMBAI](https://thumbai.app), [Source Code](https://github.com/thumbai/thumbai) - Go Mod Repository, Go Vanity Service and Simple Proxy Server. + * [go-model](https://github.com/jeevatkm/go-model) - Robust & Easy to use model mapper and utility methods for Go `struct`. + +## Usage + +The following samples will assist you to become as comfortable as possible with resty library. Resty comes with ready to use DefaultClient. + +Import resty into your code and refer it as `resty`. + +```go +import "gopkg.in/resty.v1" +``` + +#### Simple GET + +```go +// GET request +resp, err := resty.R().Get("http://httpbin.org/get") + +// explore response object +fmt.Printf("\nError: %v", err) +fmt.Printf("\nResponse Status Code: %v", resp.StatusCode()) +fmt.Printf("\nResponse Status: %v", resp.Status()) +fmt.Printf("\nResponse Time: %v", resp.Time()) +fmt.Printf("\nResponse Received At: %v", resp.ReceivedAt()) +fmt.Printf("\nResponse Body: %v", resp) // or resp.String() or string(resp.Body()) +// more... + +/* Output +Error: +Response Status Code: 200 +Response Status: 200 OK +Response Time: 160.1151ms +Response Received At: 2018-10-16 16:28:34.8595663 -0700 PDT m=+0.166119401 +Response Body: { + "args": {}, + "headers": { + "Accept-Encoding": "gzip", + "Connection": "close", + "Host": "httpbin.org", + "User-Agent": "go-resty/1.10.0 (https://github.com/go-resty/resty)" + }, + "origin": "0.0.0.0", + "url": "http://httpbin.org/get" +} +*/ +``` + +#### Enhanced GET + +```go +resp, err := resty.R(). + SetQueryParams(map[string]string{ + "page_no": "1", + "limit": "20", + "sort":"name", + "order": "asc", + "random":strconv.FormatInt(time.Now().Unix(), 10), + }). + SetHeader("Accept", "application/json"). + SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F"). + Get("/search_result") + + +// Sample of using Request.SetQueryString method +resp, err := resty.R(). + SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more"). + SetHeader("Accept", "application/json"). + SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F"). + Get("/show_product") +``` + +#### Various POST method combinations + +```go +// POST JSON string +// No need to set content type, if you have client level setting +resp, err := resty.R(). + SetHeader("Content-Type", "application/json"). + SetBody(`{"username":"testuser", "password":"testpass"}`). + SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). + Post("https://myapp.com/login") + +// POST []byte array +// No need to set content type, if you have client level setting +resp, err := resty.R(). + SetHeader("Content-Type", "application/json"). + SetBody([]byte(`{"username":"testuser", "password":"testpass"}`)). + SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). + Post("https://myapp.com/login") + +// POST Struct, default is JSON content type. No need to set one +resp, err := resty.R(). + SetBody(User{Username: "testuser", Password: "testpass"}). + SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). + SetError(&AuthError{}). // or SetError(AuthError{}). + Post("https://myapp.com/login") + +// POST Map, default is JSON content type. No need to set one +resp, err := resty.R(). + SetBody(map[string]interface{}{"username": "testuser", "password": "testpass"}). + SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). + SetError(&AuthError{}). // or SetError(AuthError{}). + Post("https://myapp.com/login") + +// POST of raw bytes for file upload. For example: upload file to Dropbox +fileBytes, _ := ioutil.ReadFile("/Users/jeeva/mydocument.pdf") + +// See we are not setting content-type header, since go-resty automatically detects Content-Type for you +resp, err := resty.R(). + SetBody(fileBytes). + SetContentLength(true). // Dropbox expects this value + SetAuthToken(""). + SetError(&DropboxError{}). // or SetError(DropboxError{}). + Post("https://content.dropboxapi.com/1/files_put/auto/resty/mydocument.pdf") // for upload Dropbox supports PUT too + +// Note: resty detects Content-Type for request body/payload if content type header is not set. +// * For struct and map data type defaults to 'application/json' +// * Fallback is plain text content type +``` + +#### Sample PUT + +You can use various combinations of `PUT` method call like demonstrated for `POST`. + +```go +// Note: This is one sample of PUT method usage, refer POST for more combination + +// Request goes as JSON content type +// No need to set auth token, error, if you have client level settings +resp, err := resty.R(). + SetBody(Article{ + Title: "go-resty", + Content: "This is my article content, oh ya!", + Author: "Jeevanandam M", + Tags: []string{"article", "sample", "resty"}, + }). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + SetError(&Error{}). // or SetError(Error{}). + Put("https://myapp.com/article/1234") +``` + +#### Sample PATCH + +You can use various combinations of `PATCH` method call like demonstrated for `POST`. + +```go +// Note: This is one sample of PUT method usage, refer POST for more combination + +// Request goes as JSON content type +// No need to set auth token, error, if you have client level settings +resp, err := resty.R(). + SetBody(Article{ + Tags: []string{"new tag1", "new tag2"}, + }). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + SetError(&Error{}). // or SetError(Error{}). + Patch("https://myapp.com/articles/1234") +``` + +#### Sample DELETE, HEAD, OPTIONS + +```go +// DELETE a article +// No need to set auth token, error, if you have client level settings +resp, err := resty.R(). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + SetError(&Error{}). // or SetError(Error{}). + Delete("https://myapp.com/articles/1234") + +// DELETE a articles with payload/body as a JSON string +// No need to set auth token, error, if you have client level settings +resp, err := resty.R(). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + SetError(&Error{}). // or SetError(Error{}). + SetHeader("Content-Type", "application/json"). + SetBody(`{article_ids: [1002, 1006, 1007, 87683, 45432] }`). + Delete("https://myapp.com/articles") + +// HEAD of resource +// No need to set auth token, if you have client level settings +resp, err := resty.R(). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + Head("https://myapp.com/videos/hi-res-video") + +// OPTIONS of resource +// No need to set auth token, if you have client level settings +resp, err := resty.R(). + SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). + Options("https://myapp.com/servers/nyc-dc-01") +``` + +### Multipart File(s) upload + +#### Using io.Reader + +```go +profileImgBytes, _ := ioutil.ReadFile("/Users/jeeva/test-img.png") +notesBytes, _ := ioutil.ReadFile("/Users/jeeva/text-file.txt") + +resp, err := resty.R(). + SetFileReader("profile_img", "test-img.png", bytes.NewReader(profileImgBytes)). + SetFileReader("notes", "text-file.txt", bytes.NewReader(notesBytes)). + SetFormData(map[string]string{ + "first_name": "Jeevanandam", + "last_name": "M", + }). + Post("http://myapp.com/upload") +``` + +#### Using File directly from Path + +```go +// Single file scenario +resp, err := resty.R(). + SetFile("profile_img", "/Users/jeeva/test-img.png"). + Post("http://myapp.com/upload") + +// Multiple files scenario +resp, err := resty.R(). + SetFiles(map[string]string{ + "profile_img": "/Users/jeeva/test-img.png", + "notes": "/Users/jeeva/text-file.txt", + }). + Post("http://myapp.com/upload") + +// Multipart of form fields and files +resp, err := resty.R(). + SetFiles(map[string]string{ + "profile_img": "/Users/jeeva/test-img.png", + "notes": "/Users/jeeva/text-file.txt", + }). + SetFormData(map[string]string{ + "first_name": "Jeevanandam", + "last_name": "M", + "zip_code": "00001", + "city": "my city", + "access_token": "C6A79608-782F-4ED0-A11D-BD82FAD829CD", + }). + Post("http://myapp.com/profile") +``` + +#### Sample Form submission + +```go +// just mentioning about POST as an example with simple flow +// User Login +resp, err := resty.R(). + SetFormData(map[string]string{ + "username": "jeeva", + "password": "mypass", + }). + Post("http://myapp.com/login") + +// Followed by profile update +resp, err := resty.R(). + SetFormData(map[string]string{ + "first_name": "Jeevanandam", + "last_name": "M", + "zip_code": "00001", + "city": "new city update", + }). + Post("http://myapp.com/profile") + +// Multi value form data +criteria := url.Values{ + "search_criteria": []string{"book", "glass", "pencil"}, +} +resp, err := resty.R(). + SetMultiValueFormData(criteria). + Post("http://myapp.com/search") +``` + +#### Save HTTP Response into File + +```go +// Setting output directory path, If directory not exists then resty creates one! +// This is optional one, if you're planning using absoule path in +// `Request.SetOutput` and can used together. +resty.SetOutputDirectory("/Users/jeeva/Downloads") + +// HTTP response gets saved into file, similar to curl -o flag +_, err := resty.R(). + SetOutput("plugin/ReplyWithHeader-v5.1-beta.zip"). + Get("http://bit.ly/1LouEKr") + +// OR using absolute path +// Note: output directory path is not used for absoulte path +_, err := resty.R(). + SetOutput("/MyDownloads/plugin/ReplyWithHeader-v5.1-beta.zip"). + Get("http://bit.ly/1LouEKr") +``` + +#### Request URL Path Params + +Resty provides easy to use dynamic request URL path params. Params can be set at client and request level. Client level params value can be overridden at request level. + +```go +resty.R().SetPathParams(map[string]string{ + "userId": "sample@sample.com", + "subAccountId": "100002", +}). +Get("/v1/users/{userId}/{subAccountId}/details") + +// Result: +// Composed URL - /v1/users/sample@sample.com/100002/details +``` + +#### Request and Response Middleware + +Resty provides middleware ability to manipulate for Request and Response. It is more flexible than callback approach. + +```go +// Registering Request Middleware +resty.OnBeforeRequest(func(c *resty.Client, req *resty.Request) error { + // Now you have access to Client and current Request object + // manipulate it as per your need + + return nil // if its success otherwise return error + }) + +// Registering Response Middleware +resty.OnAfterResponse(func(c *resty.Client, resp *resty.Response) error { + // Now you have access to Client and current Response object + // manipulate it as per your need + + return nil // if its success otherwise return error + }) +``` + +#### Redirect Policy + +Resty provides few ready to use redirect policy(s) also it supports multiple policies together. + +```go +// Assign Client Redirect Policy. Create one as per you need +resty.SetRedirectPolicy(resty.FlexibleRedirectPolicy(15)) + +// Wanna multiple policies such as redirect count, domain name check, etc +resty.SetRedirectPolicy(resty.FlexibleRedirectPolicy(20), + resty.DomainCheckRedirectPolicy("host1.com", "host2.org", "host3.net")) +``` + +##### Custom Redirect Policy + +Implement [RedirectPolicy](redirect.go#L20) interface and register it with resty client. Have a look [redirect.go](redirect.go) for more information. + +```go +// Using raw func into resty.SetRedirectPolicy +resty.SetRedirectPolicy(resty.RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { + // Implement your logic here + + // return nil for continue redirect otherwise return error to stop/prevent redirect + return nil +})) + +//--------------------------------------------------- + +// Using struct create more flexible redirect policy +type CustomRedirectPolicy struct { + // variables goes here +} + +func (c *CustomRedirectPolicy) Apply(req *http.Request, via []*http.Request) error { + // Implement your logic here + + // return nil for continue redirect otherwise return error to stop/prevent redirect + return nil +} + +// Registering in resty +resty.SetRedirectPolicy(CustomRedirectPolicy{/* initialize variables */}) +``` + +#### Custom Root Certificates and Client Certificates + +```go +// Custom Root certificates, just supply .pem file. +// you can add one or more root certificates, its get appended +resty.SetRootCertificate("/path/to/root/pemFile1.pem") +resty.SetRootCertificate("/path/to/root/pemFile2.pem") +// ... and so on! + +// Adding Client Certificates, you add one or more certificates +// Sample for creating certificate object +// Parsing public/private key pair from a pair of files. The files must contain PEM encoded data. +cert1, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key") +if err != nil { + log.Fatalf("ERROR client certificate: %s", err) +} +// ... + +// You add one or more certificates +resty.SetCertificates(cert1, cert2, cert3) +``` + +#### Proxy Settings - Client as well as at Request Level + +Default `Go` supports Proxy via environment variable `HTTP_PROXY`. Resty provides support via `SetProxy` & `RemoveProxy`. +Choose as per your need. + +**Client Level Proxy** settings applied to all the request + +```go +// Setting a Proxy URL and Port +resty.SetProxy("http://proxyserver:8888") + +// Want to remove proxy setting +resty.RemoveProxy() +``` + +#### Retries + +Resty uses [backoff](http://www.awsarchitectureblog.com/2015/03/backoff.html) +to increase retry intervals after each attempt. + +Usage example: + +```go +// Retries are configured per client +resty. + // Set retry count to non zero to enable retries + SetRetryCount(3). + // You can override initial retry wait time. + // Default is 100 milliseconds. + SetRetryWaitTime(5 * time.Second). + // MaxWaitTime can be overridden as well. + // Default is 2 seconds. + SetRetryMaxWaitTime(20 * time.Second) +``` + +Above setup will result in resty retrying requests returned non nil error up to +3 times with delay increased after each attempt. + +You can optionally provide client with custom retry conditions: + +```go +resty.AddRetryCondition( + // Condition function will be provided with *resty.Response as a + // parameter. It is expected to return (bool, error) pair. Resty will retry + // in case condition returns true or non nil error. + func(r *resty.Response) (bool, error) { + return r.StatusCode() == http.StatusTooManyRequests, nil + }, +) +``` + +Above example will make resty retry requests ended with `429 Too Many Requests` +status code. + +Multiple retry conditions can be added. + +It is also possible to use `resty.Backoff(...)` to get arbitrary retry scenarios +implemented. [Reference](retry_test.go). + +#### Choose REST or HTTP mode + +```go +// REST mode. This is Default. +resty.SetRESTMode() + +// HTTP mode +resty.SetHTTPMode() +``` + +#### Allow GET request with Payload + +```go +// Allow GET request with Payload. This is disabled by default. +resty.SetAllowGetMethodPayload(true) +``` + +#### Wanna Multiple Clients + +```go +// Here you go! +// Client 1 +client1 := resty.New() +client1.R().Get("http://httpbin.org") +// ... + +// Client 2 +client2 := resty.New() +client2.R().Head("http://httpbin.org") +// ... + +// Bend it as per your need!!! +``` + +#### Remaining Client Settings & its Options + +```go +// Unique settings at Client level +//-------------------------------- +// Enable debug mode +resty.SetDebug(true) + +// Using you custom log writer +logFile, _ := os.OpenFile("/Users/jeeva/go-resty.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) +resty.SetLogger(logFile) + +// Assign Client TLSClientConfig +// One can set custom root-certificate. Refer: http://golang.org/pkg/crypto/tls/#example_Dial +resty.SetTLSClientConfig(&tls.Config{ RootCAs: roots }) + +// or One can disable security check (https) +resty.SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true }) + +// Set client timeout as per your need +resty.SetTimeout(1 * time.Minute) + + +// You can override all below settings and options at request level if you want to +//-------------------------------------------------------------------------------- +// Host URL for all request. So you can use relative URL in the request +resty.SetHostURL("http://httpbin.org") + +// Headers for all request +resty.SetHeader("Accept", "application/json") +resty.SetHeaders(map[string]string{ + "Content-Type": "application/json", + "User-Agent": "My custom User Agent String", + }) + +// Cookies for all request +resty.SetCookie(&http.Cookie{ + Name:"go-resty", + Value:"This is cookie value", + Path: "/", + Domain: "sample.com", + MaxAge: 36000, + HttpOnly: true, + Secure: false, + }) +resty.SetCookies(cookies) + +// URL query parameters for all request +resty.SetQueryParam("user_id", "00001") +resty.SetQueryParams(map[string]string{ // sample of those who use this manner + "api_key": "api-key-here", + "api_secert": "api-secert", + }) +resty.R().SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more") + +// Form data for all request. Typically used with POST and PUT +resty.SetFormData(map[string]string{ + "access_token": "BC594900-518B-4F7E-AC75-BD37F019E08F", + }) + +// Basic Auth for all request +resty.SetBasicAuth("myuser", "mypass") + +// Bearer Auth Token for all request +resty.SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F") + +// Enabling Content length value for all request +resty.SetContentLength(true) + +// Registering global Error object structure for JSON/XML request +resty.SetError(&Error{}) // or resty.SetError(Error{}) +``` + +#### Unix Socket + +```go +unixSocket := "/var/run/my_socket.sock" + +// Create a Go's http.Transport so we can set it in resty. +transport := http.Transport{ + Dial: func(_, _ string) (net.Conn, error) { + return net.Dial("unix", unixSocket) + }, +} + +// Set the previous transport that we created, set the scheme of the communication to the +// socket and set the unixSocket as the HostURL. +r := resty.New().SetTransport(&transport).SetScheme("http").SetHostURL(unixSocket) + +// No need to write the host's URL on the request, just the path. +r.R().Get("/index.html") +``` + +#### Bazel support + +Resty can be built, tested and depended upon via [Bazel](https://bazel.build). +For example, to run all tests: + +```shell +bazel test :go_default_test +``` + +#### Mocking http requests using [httpmock](https://github.com/jarcoal/httpmock) library + +In order to mock the http requests when testing your application you +could use the `httpmock` library. + +When using the default resty client, you should pass the client to the library as follow: + +```go +httpmock.ActivateNonDefault(resty.DefaultClient.GetClient()) +``` + +More detailed example of mocking resty http requests using ginko could be found [here](https://github.com/jarcoal/httpmock#ginkgo--resty-example). + +## Versioning + +resty releases versions according to [Semantic Versioning](http://semver.org) + + * `gopkg.in/resty.vX` points to appropriate tagged versions; `X` denotes version series number and it's a stable release for production use. For e.g. `gopkg.in/resty.v0`. + * Development takes place at the master branch. Although the code in master should always compile and test successfully, it might break API's. I aim to maintain backwards compatibility, but sometimes API's and behavior might be changed to fix a bug. + +## Contribution + +I would welcome your contribution! If you find any improvement or issue you want to fix, feel free to send a pull request, I like pull requests that include test cases for fix/enhancement. I have done my best to bring pretty good code coverage. Feel free to write tests. + +BTW, I'd like to know what you think about `Resty`. Kindly open an issue or send me an email; it'd mean a lot to me. + +## Creator + +[Jeevanandam M.](https://github.com/jeevatkm) (jeeva@myjeeva.com) + +## Contributors + +Have a look on [Contributors](https://github.com/go-resty/resty/graphs/contributors) page. + +## License + +Resty released under MIT license, refer [LICENSE](LICENSE) file. diff --git a/vendor/gopkg.in/resty.v1/WORKSPACE b/vendor/gopkg.in/resty.v1/WORKSPACE new file mode 100644 index 0000000000..5459d63218 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/WORKSPACE @@ -0,0 +1,27 @@ +workspace(name = "resty") + +git_repository( + name = "io_bazel_rules_go", + remote = "https://github.com/bazelbuild/rules_go.git", + tag = "0.13.0", +) + +git_repository( + name = "bazel_gazelle", + remote = "https://github.com/bazelbuild/bazel-gazelle.git", + tag = "0.13.0", +) + +load( + "@io_bazel_rules_go//go:def.bzl", + "go_rules_dependencies", + "go_register_toolchains", +) + +go_rules_dependencies() + +go_register_toolchains() + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") + +gazelle_dependencies() diff --git a/vendor/gopkg.in/resty.v1/client.go b/vendor/gopkg.in/resty.v1/client.go new file mode 100644 index 0000000000..68d447fa69 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/client.go @@ -0,0 +1,926 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "bytes" + "compress/gzip" + "crypto/tls" + "crypto/x509" + "errors" + "fmt" + "io" + "io/ioutil" + "log" + "net/http" + "net/url" + "reflect" + "regexp" + "strings" + "sync" + "time" +) + +const ( + // MethodGet HTTP method + MethodGet = "GET" + + // MethodPost HTTP method + MethodPost = "POST" + + // MethodPut HTTP method + MethodPut = "PUT" + + // MethodDelete HTTP method + MethodDelete = "DELETE" + + // MethodPatch HTTP method + MethodPatch = "PATCH" + + // MethodHead HTTP method + MethodHead = "HEAD" + + // MethodOptions HTTP method + MethodOptions = "OPTIONS" +) + +var ( + hdrUserAgentKey = http.CanonicalHeaderKey("User-Agent") + hdrAcceptKey = http.CanonicalHeaderKey("Accept") + hdrContentTypeKey = http.CanonicalHeaderKey("Content-Type") + hdrContentLengthKey = http.CanonicalHeaderKey("Content-Length") + hdrContentEncodingKey = http.CanonicalHeaderKey("Content-Encoding") + hdrAuthorizationKey = http.CanonicalHeaderKey("Authorization") + + plainTextType = "text/plain; charset=utf-8" + jsonContentType = "application/json; charset=utf-8" + formContentType = "application/x-www-form-urlencoded" + + jsonCheck = regexp.MustCompile(`(?i:(application|text)/(json|.*\+json|json\-.*)(;|$))`) + xmlCheck = regexp.MustCompile(`(?i:(application|text)/(xml|.*\+xml)(;|$))`) + + hdrUserAgentValue = "go-resty/%s (https://github.com/go-resty/resty)" + bufPool = &sync.Pool{New: func() interface{} { return &bytes.Buffer{} }} +) + +// Client type is used for HTTP/RESTful global values +// for all request raised from the client +type Client struct { + HostURL string + QueryParam url.Values + FormData url.Values + Header http.Header + UserInfo *User + Token string + Cookies []*http.Cookie + Error reflect.Type + Debug bool + DisableWarn bool + AllowGetMethodPayload bool + Log *log.Logger + RetryCount int + RetryWaitTime time.Duration + RetryMaxWaitTime time.Duration + RetryConditions []RetryConditionFunc + JSONMarshal func(v interface{}) ([]byte, error) + JSONUnmarshal func(data []byte, v interface{}) error + + jsonEscapeHTML bool + httpClient *http.Client + setContentLength bool + isHTTPMode bool + outputDirectory string + scheme string + proxyURL *url.URL + closeConnection bool + notParseResponse bool + debugBodySizeLimit int64 + logPrefix string + pathParams map[string]string + beforeRequest []func(*Client, *Request) error + udBeforeRequest []func(*Client, *Request) error + preReqHook func(*Client, *Request) error + afterResponse []func(*Client, *Response) error + requestLog func(*RequestLog) error + responseLog func(*ResponseLog) error +} + +// User type is to hold an username and password information +type User struct { + Username, Password string +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Client methods +//___________________________________ + +// SetHostURL method is to set Host URL in the client instance. It will be used with request +// raised from this client with relative URL +// // Setting HTTP address +// resty.SetHostURL("http://myjeeva.com") +// +// // Setting HTTPS address +// resty.SetHostURL("https://myjeeva.com") +// +func (c *Client) SetHostURL(url string) *Client { + c.HostURL = strings.TrimRight(url, "/") + return c +} + +// SetHeader method sets a single header field and its value in the client instance. +// These headers will be applied to all requests raised from this client instance. +// Also it can be overridden at request level header options, see `resty.R().SetHeader` +// or `resty.R().SetHeaders`. +// +// Example: To set `Content-Type` and `Accept` as `application/json` +// +// resty. +// SetHeader("Content-Type", "application/json"). +// SetHeader("Accept", "application/json") +// +func (c *Client) SetHeader(header, value string) *Client { + c.Header.Set(header, value) + return c +} + +// SetHeaders method sets multiple headers field and its values at one go in the client instance. +// These headers will be applied to all requests raised from this client instance. Also it can be +// overridden at request level headers options, see `resty.R().SetHeaders` or `resty.R().SetHeader`. +// +// Example: To set `Content-Type` and `Accept` as `application/json` +// +// resty.SetHeaders(map[string]string{ +// "Content-Type": "application/json", +// "Accept": "application/json", +// }) +// +func (c *Client) SetHeaders(headers map[string]string) *Client { + for h, v := range headers { + c.Header.Set(h, v) + } + + return c +} + +// SetCookieJar method sets custom http.CookieJar in the resty client. Its way to override default. +// Example: sometimes we don't want to save cookies in api contacting, we can remove the default +// CookieJar in resty client. +// +// resty.SetCookieJar(nil) +// +func (c *Client) SetCookieJar(jar http.CookieJar) *Client { + c.httpClient.Jar = jar + return c +} + +// SetCookie method appends a single cookie in the client instance. +// These cookies will be added to all the request raised from this client instance. +// resty.SetCookie(&http.Cookie{ +// Name:"go-resty", +// Value:"This is cookie value", +// Path: "/", +// Domain: "sample.com", +// MaxAge: 36000, +// HttpOnly: true, +// Secure: false, +// }) +// +func (c *Client) SetCookie(hc *http.Cookie) *Client { + c.Cookies = append(c.Cookies, hc) + return c +} + +// SetCookies method sets an array of cookies in the client instance. +// These cookies will be added to all the request raised from this client instance. +// cookies := make([]*http.Cookie, 0) +// +// cookies = append(cookies, &http.Cookie{ +// Name:"go-resty-1", +// Value:"This is cookie 1 value", +// Path: "/", +// Domain: "sample.com", +// MaxAge: 36000, +// HttpOnly: true, +// Secure: false, +// }) +// +// cookies = append(cookies, &http.Cookie{ +// Name:"go-resty-2", +// Value:"This is cookie 2 value", +// Path: "/", +// Domain: "sample.com", +// MaxAge: 36000, +// HttpOnly: true, +// Secure: false, +// }) +// +// // Setting a cookies into resty +// resty.SetCookies(cookies) +// +func (c *Client) SetCookies(cs []*http.Cookie) *Client { + c.Cookies = append(c.Cookies, cs...) + return c +} + +// SetQueryParam method sets single parameter and its value in the client instance. +// It will be formed as query string for the request. For example: `search=kitchen%20papers&size=large` +// in the URL after `?` mark. These query params will be added to all the request raised from +// this client instance. Also it can be overridden at request level Query Param options, +// see `resty.R().SetQueryParam` or `resty.R().SetQueryParams`. +// resty. +// SetQueryParam("search", "kitchen papers"). +// SetQueryParam("size", "large") +// +func (c *Client) SetQueryParam(param, value string) *Client { + c.QueryParam.Set(param, value) + return c +} + +// SetQueryParams method sets multiple parameters and their values at one go in the client instance. +// It will be formed as query string for the request. For example: `search=kitchen%20papers&size=large` +// in the URL after `?` mark. These query params will be added to all the request raised from this +// client instance. Also it can be overridden at request level Query Param options, +// see `resty.R().SetQueryParams` or `resty.R().SetQueryParam`. +// resty.SetQueryParams(map[string]string{ +// "search": "kitchen papers", +// "size": "large", +// }) +// +func (c *Client) SetQueryParams(params map[string]string) *Client { + for p, v := range params { + c.SetQueryParam(p, v) + } + + return c +} + +// SetFormData method sets Form parameters and their values in the client instance. +// It's applicable only HTTP method `POST` and `PUT` and requets content type would be set as +// `application/x-www-form-urlencoded`. These form data will be added to all the request raised from +// this client instance. Also it can be overridden at request level form data, see `resty.R().SetFormData`. +// resty.SetFormData(map[string]string{ +// "access_token": "BC594900-518B-4F7E-AC75-BD37F019E08F", +// "user_id": "3455454545", +// }) +// +func (c *Client) SetFormData(data map[string]string) *Client { + for k, v := range data { + c.FormData.Set(k, v) + } + + return c +} + +// SetBasicAuth method sets the basic authentication header in the HTTP request. Example: +// Authorization: Basic +// +// Example: To set the header for username "go-resty" and password "welcome" +// resty.SetBasicAuth("go-resty", "welcome") +// +// This basic auth information gets added to all the request rasied from this client instance. +// Also it can be overridden or set one at the request level is supported, see `resty.R().SetBasicAuth`. +// +func (c *Client) SetBasicAuth(username, password string) *Client { + c.UserInfo = &User{Username: username, Password: password} + return c +} + +// SetAuthToken method sets bearer auth token header in the HTTP request. Example: +// Authorization: Bearer +// +// Example: To set auth token BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F +// +// resty.SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F") +// +// This bearer auth token gets added to all the request rasied from this client instance. +// Also it can be overridden or set one at the request level is supported, see `resty.R().SetAuthToken`. +// +func (c *Client) SetAuthToken(token string) *Client { + c.Token = token + return c +} + +// R method creates a request instance, its used for Get, Post, Put, Delete, Patch, Head and Options. +func (c *Client) R() *Request { + r := &Request{ + QueryParam: url.Values{}, + FormData: url.Values{}, + Header: http.Header{}, + + client: c, + multipartFiles: []*File{}, + multipartFields: []*MultipartField{}, + pathParams: map[string]string{}, + jsonEscapeHTML: true, + } + + return r +} + +// NewRequest is an alias for R(). Creates a request instance, its used for +// Get, Post, Put, Delete, Patch, Head and Options. +func (c *Client) NewRequest() *Request { + return c.R() +} + +// OnBeforeRequest method appends request middleware into the before request chain. +// Its gets applied after default `go-resty` request middlewares and before request +// been sent from `go-resty` to host server. +// resty.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error { +// // Now you have access to Client and Request instance +// // manipulate it as per your need +// +// return nil // if its success otherwise return error +// }) +// +func (c *Client) OnBeforeRequest(m func(*Client, *Request) error) *Client { + c.udBeforeRequest = append(c.udBeforeRequest, m) + return c +} + +// OnAfterResponse method appends response middleware into the after response chain. +// Once we receive response from host server, default `go-resty` response middleware +// gets applied and then user assigened response middlewares applied. +// resty.OnAfterResponse(func(c *resty.Client, r *resty.Response) error { +// // Now you have access to Client and Response instance +// // manipulate it as per your need +// +// return nil // if its success otherwise return error +// }) +// +func (c *Client) OnAfterResponse(m func(*Client, *Response) error) *Client { + c.afterResponse = append(c.afterResponse, m) + return c +} + +// SetPreRequestHook method sets the given pre-request function into resty client. +// It is called right before the request is fired. +// +// Note: Only one pre-request hook can be registered. Use `resty.OnBeforeRequest` for mutilple. +func (c *Client) SetPreRequestHook(h func(*Client, *Request) error) *Client { + if c.preReqHook != nil { + c.Log.Printf("Overwriting an existing pre-request hook: %s", functionName(h)) + } + c.preReqHook = h + return c +} + +// SetDebug method enables the debug mode on `go-resty` client. Client logs details of every request and response. +// For `Request` it logs information such as HTTP verb, Relative URL path, Host, Headers, Body if it has one. +// For `Response` it logs information such as Status, Response Time, Headers, Body if it has one. +// resty.SetDebug(true) +// +func (c *Client) SetDebug(d bool) *Client { + c.Debug = d + return c +} + +// SetDebugBodyLimit sets the maximum size for which the response body will be logged in debug mode. +// resty.SetDebugBodyLimit(1000000) +// +func (c *Client) SetDebugBodyLimit(sl int64) *Client { + c.debugBodySizeLimit = sl + return c +} + +// OnRequestLog method used to set request log callback into resty. Registered callback gets +// called before the resty actually logs the information. +func (c *Client) OnRequestLog(rl func(*RequestLog) error) *Client { + if c.requestLog != nil { + c.Log.Printf("Overwriting an existing on-request-log callback from=%s to=%s", functionName(c.requestLog), functionName(rl)) + } + c.requestLog = rl + return c +} + +// OnResponseLog method used to set response log callback into resty. Registered callback gets +// called before the resty actually logs the information. +func (c *Client) OnResponseLog(rl func(*ResponseLog) error) *Client { + if c.responseLog != nil { + c.Log.Printf("Overwriting an existing on-response-log callback from=%s to=%s", functionName(c.responseLog), functionName(rl)) + } + c.responseLog = rl + return c +} + +// SetDisableWarn method disables the warning message on `go-resty` client. +// For example: go-resty warns the user when BasicAuth used on HTTP mode. +// resty.SetDisableWarn(true) +// +func (c *Client) SetDisableWarn(d bool) *Client { + c.DisableWarn = d + return c +} + +// SetAllowGetMethodPayload method allows the GET method with payload on `go-resty` client. +// For example: go-resty allows the user sends request with a payload on HTTP GET method. +// resty.SetAllowGetMethodPayload(true) +// +func (c *Client) SetAllowGetMethodPayload(a bool) *Client { + c.AllowGetMethodPayload = a + return c +} + +// SetLogger method sets given writer for logging go-resty request and response details. +// Default is os.Stderr +// file, _ := os.OpenFile("/Users/jeeva/go-resty.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) +// +// resty.SetLogger(file) +// +func (c *Client) SetLogger(w io.Writer) *Client { + c.Log = getLogger(w) + return c +} + +// SetContentLength method enables the HTTP header `Content-Length` value for every request. +// By default go-resty won't set `Content-Length`. +// resty.SetContentLength(true) +// +// Also you have an option to enable for particular request. See `resty.R().SetContentLength` +// +func (c *Client) SetContentLength(l bool) *Client { + c.setContentLength = l + return c +} + +// SetTimeout method sets timeout for request raised from client. +// resty.SetTimeout(time.Duration(1 * time.Minute)) +// +func (c *Client) SetTimeout(timeout time.Duration) *Client { + c.httpClient.Timeout = timeout + return c +} + +// SetError method is to register the global or client common `Error` object into go-resty. +// It is used for automatic unmarshalling if response status code is greater than 399 and +// content type either JSON or XML. Can be pointer or non-pointer. +// resty.SetError(&Error{}) +// // OR +// resty.SetError(Error{}) +// +func (c *Client) SetError(err interface{}) *Client { + c.Error = typeOf(err) + return c +} + +// SetRedirectPolicy method sets the client redirect poilicy. go-resty provides ready to use +// redirect policies. Wanna create one for yourself refer `redirect.go`. +// +// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20)) +// +// // Need multiple redirect policies together +// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20), DomainCheckRedirectPolicy("host1.com", "host2.net")) +// +func (c *Client) SetRedirectPolicy(policies ...interface{}) *Client { + for _, p := range policies { + if _, ok := p.(RedirectPolicy); !ok { + c.Log.Printf("ERORR: %v does not implement resty.RedirectPolicy (missing Apply method)", + functionName(p)) + } + } + + c.httpClient.CheckRedirect = func(req *http.Request, via []*http.Request) error { + for _, p := range policies { + if err := p.(RedirectPolicy).Apply(req, via); err != nil { + return err + } + } + return nil // looks good, go ahead + } + + return c +} + +// SetRetryCount method enables retry on `go-resty` client and allows you +// to set no. of retry count. Resty uses a Backoff mechanism. +func (c *Client) SetRetryCount(count int) *Client { + c.RetryCount = count + return c +} + +// SetRetryWaitTime method sets default wait time to sleep before retrying +// request. +// Default is 100 milliseconds. +func (c *Client) SetRetryWaitTime(waitTime time.Duration) *Client { + c.RetryWaitTime = waitTime + return c +} + +// SetRetryMaxWaitTime method sets max wait time to sleep before retrying +// request. +// Default is 2 seconds. +func (c *Client) SetRetryMaxWaitTime(maxWaitTime time.Duration) *Client { + c.RetryMaxWaitTime = maxWaitTime + return c +} + +// AddRetryCondition method adds a retry condition function to array of functions +// that are checked to determine if the request is retried. The request will +// retry if any of the functions return true and error is nil. +func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client { + c.RetryConditions = append(c.RetryConditions, condition) + return c +} + +// SetHTTPMode method sets go-resty mode to 'http' +func (c *Client) SetHTTPMode() *Client { + return c.SetMode("http") +} + +// SetRESTMode method sets go-resty mode to 'rest' +func (c *Client) SetRESTMode() *Client { + return c.SetMode("rest") +} + +// SetMode method sets go-resty client mode to given value such as 'http' & 'rest'. +// 'rest': +// - No Redirect +// - Automatic response unmarshal if it is JSON or XML +// 'http': +// - Up to 10 Redirects +// - No automatic unmarshall. Response will be treated as `response.String()` +// +// If you want more redirects, use FlexibleRedirectPolicy +// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20)) +// +func (c *Client) SetMode(mode string) *Client { + // HTTP + if mode == "http" { + c.isHTTPMode = true + c.SetRedirectPolicy(FlexibleRedirectPolicy(10)) + c.afterResponse = []func(*Client, *Response) error{ + responseLogger, + saveResponseIntoFile, + } + return c + } + + // RESTful + c.isHTTPMode = false + c.SetRedirectPolicy(NoRedirectPolicy()) + c.afterResponse = []func(*Client, *Response) error{ + responseLogger, + parseResponseBody, + saveResponseIntoFile, + } + return c +} + +// Mode method returns the current client mode. Typically its a "http" or "rest". +// Default is "rest" +func (c *Client) Mode() string { + if c.isHTTPMode { + return "http" + } + return "rest" +} + +// SetTLSClientConfig method sets TLSClientConfig for underling client Transport. +// +// Example: +// // One can set custom root-certificate. Refer: http://golang.org/pkg/crypto/tls/#example_Dial +// resty.SetTLSClientConfig(&tls.Config{ RootCAs: roots }) +// +// // or One can disable security check (https) +// resty.SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true }) +// Note: This method overwrites existing `TLSClientConfig`. +// +func (c *Client) SetTLSClientConfig(config *tls.Config) *Client { + transport, err := c.getTransport() + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + transport.TLSClientConfig = config + return c +} + +// SetProxy method sets the Proxy URL and Port for resty client. +// resty.SetProxy("http://proxyserver:8888") +// +// Alternatives: At request level proxy, see `Request.SetProxy`. OR Without this `SetProxy` method, +// you can also set Proxy via environment variable. By default `Go` uses setting from `HTTP_PROXY`. +// +func (c *Client) SetProxy(proxyURL string) *Client { + transport, err := c.getTransport() + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + + if pURL, err := url.Parse(proxyURL); err == nil { + c.proxyURL = pURL + transport.Proxy = http.ProxyURL(c.proxyURL) + } else { + c.Log.Printf("ERROR %v", err) + c.RemoveProxy() + } + return c +} + +// RemoveProxy method removes the proxy configuration from resty client +// resty.RemoveProxy() +// +func (c *Client) RemoveProxy() *Client { + transport, err := c.getTransport() + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + c.proxyURL = nil + transport.Proxy = nil + return c +} + +// SetCertificates method helps to set client certificates into resty conveniently. +// +func (c *Client) SetCertificates(certs ...tls.Certificate) *Client { + config, err := c.getTLSConfig() + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + config.Certificates = append(config.Certificates, certs...) + return c +} + +// SetRootCertificate method helps to add one or more root certificates into resty client +// resty.SetRootCertificate("/path/to/root/pemFile.pem") +// +func (c *Client) SetRootCertificate(pemFilePath string) *Client { + rootPemData, err := ioutil.ReadFile(pemFilePath) + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + + config, err := c.getTLSConfig() + if err != nil { + c.Log.Printf("ERROR %v", err) + return c + } + if config.RootCAs == nil { + config.RootCAs = x509.NewCertPool() + } + + config.RootCAs.AppendCertsFromPEM(rootPemData) + + return c +} + +// SetOutputDirectory method sets output directory for saving HTTP response into file. +// If the output directory not exists then resty creates one. This setting is optional one, +// if you're planning using absoule path in `Request.SetOutput` and can used together. +// resty.SetOutputDirectory("/save/http/response/here") +// +func (c *Client) SetOutputDirectory(dirPath string) *Client { + c.outputDirectory = dirPath + return c +} + +// SetTransport method sets custom `*http.Transport` or any `http.RoundTripper` +// compatible interface implementation in the resty client. +// +// NOTE: +// +// - If transport is not type of `*http.Transport` then you may not be able to +// take advantage of some of the `resty` client settings. +// +// - It overwrites the resty client transport instance and it's configurations. +// +// transport := &http.Transport{ +// // somthing like Proxying to httptest.Server, etc... +// Proxy: func(req *http.Request) (*url.URL, error) { +// return url.Parse(server.URL) +// }, +// } +// +// resty.SetTransport(transport) +// +func (c *Client) SetTransport(transport http.RoundTripper) *Client { + if transport != nil { + c.httpClient.Transport = transport + } + return c +} + +// SetScheme method sets custom scheme in the resty client. It's way to override default. +// resty.SetScheme("http") +// +func (c *Client) SetScheme(scheme string) *Client { + if !IsStringEmpty(scheme) { + c.scheme = scheme + } + + return c +} + +// SetCloseConnection method sets variable `Close` in http request struct with the given +// value. More info: https://golang.org/src/net/http/request.go +func (c *Client) SetCloseConnection(close bool) *Client { + c.closeConnection = close + return c +} + +// SetDoNotParseResponse method instructs `Resty` not to parse the response body automatically. +// Resty exposes the raw response body as `io.ReadCloser`. Also do not forget to close the body, +// otherwise you might get into connection leaks, no connection reuse. +// +// Please Note: Response middlewares are not applicable, if you use this option. Basically you have +// taken over the control of response parsing from `Resty`. +func (c *Client) SetDoNotParseResponse(parse bool) *Client { + c.notParseResponse = parse + return c +} + +// SetLogPrefix method sets the Resty logger prefix value. +func (c *Client) SetLogPrefix(prefix string) *Client { + c.logPrefix = prefix + c.Log.SetPrefix(prefix) + return c +} + +// SetPathParams method sets multiple URL path key-value pairs at one go in the +// resty client instance. +// resty.SetPathParams(map[string]string{ +// "userId": "sample@sample.com", +// "subAccountId": "100002", +// }) +// +// Result: +// URL - /v1/users/{userId}/{subAccountId}/details +// Composed URL - /v1/users/sample@sample.com/100002/details +// It replace the value of the key while composing request URL. Also it can be +// overridden at request level Path Params options, see `Request.SetPathParams`. +func (c *Client) SetPathParams(params map[string]string) *Client { + for p, v := range params { + c.pathParams[p] = v + } + return c +} + +// SetJSONEscapeHTML method is to enable/disable the HTML escape on JSON marshal. +// +// NOTE: This option only applicable to standard JSON Marshaller. +func (c *Client) SetJSONEscapeHTML(b bool) *Client { + c.jsonEscapeHTML = b + return c +} + +// IsProxySet method returns the true if proxy is set on client otherwise false. +func (c *Client) IsProxySet() bool { + return c.proxyURL != nil +} + +// GetClient method returns the current http.Client used by the resty client. +func (c *Client) GetClient() *http.Client { + return c.httpClient +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Client Unexported methods +//___________________________________ + +// executes the given `Request` object and returns response +func (c *Client) execute(req *Request) (*Response, error) { + defer releaseBuffer(req.bodyBuf) + // Apply Request middleware + var err error + + // user defined on before request methods + // to modify the *resty.Request object + for _, f := range c.udBeforeRequest { + if err = f(c, req); err != nil { + return nil, err + } + } + + // resty middlewares + for _, f := range c.beforeRequest { + if err = f(c, req); err != nil { + return nil, err + } + } + + // call pre-request if defined + if c.preReqHook != nil { + if err = c.preReqHook(c, req); err != nil { + return nil, err + } + } + + if hostHeader := req.Header.Get("Host"); hostHeader != "" { + req.RawRequest.Host = hostHeader + } + + if err = requestLogger(c, req); err != nil { + return nil, err + } + + req.Time = time.Now() + resp, err := c.httpClient.Do(req.RawRequest) + + response := &Response{ + Request: req, + RawResponse: resp, + receivedAt: time.Now(), + } + + if err != nil || req.notParseResponse || c.notParseResponse { + return response, err + } + + if !req.isSaveResponse { + defer closeq(resp.Body) + body := resp.Body + + // GitHub #142 & #187 + if strings.EqualFold(resp.Header.Get(hdrContentEncodingKey), "gzip") && resp.ContentLength != 0 { + if _, ok := body.(*gzip.Reader); !ok { + body, err = gzip.NewReader(body) + if err != nil { + return response, err + } + defer closeq(body) + } + } + + if response.body, err = ioutil.ReadAll(body); err != nil { + return response, err + } + + response.size = int64(len(response.body)) + } + + // Apply Response middleware + for _, f := range c.afterResponse { + if err = f(c, response); err != nil { + break + } + } + + return response, err +} + +// enables a log prefix +func (c *Client) enableLogPrefix() { + c.Log.SetFlags(log.LstdFlags) + c.Log.SetPrefix(c.logPrefix) +} + +// disables a log prefix +func (c *Client) disableLogPrefix() { + c.Log.SetFlags(0) + c.Log.SetPrefix("") +} + +// getting TLS client config if not exists then create one +func (c *Client) getTLSConfig() (*tls.Config, error) { + transport, err := c.getTransport() + if err != nil { + return nil, err + } + if transport.TLSClientConfig == nil { + transport.TLSClientConfig = &tls.Config{} + } + return transport.TLSClientConfig, nil +} + +// returns `*http.Transport` currently in use or error +// in case currently used `transport` is not an `*http.Transport` +func (c *Client) getTransport() (*http.Transport, error) { + if c.httpClient.Transport == nil { + c.SetTransport(new(http.Transport)) + } + + if transport, ok := c.httpClient.Transport.(*http.Transport); ok { + return transport, nil + } + return nil, errors.New("current transport is not an *http.Transport instance") +} + +// +// File +// + +// File represent file information for multipart request +type File struct { + Name string + ParamName string + io.Reader +} + +// String returns string value of current file details +func (f *File) String() string { + return fmt.Sprintf("ParamName: %v; FileName: %v", f.ParamName, f.Name) +} + +// MultipartField represent custom data part for multipart request +type MultipartField struct { + Param string + FileName string + ContentType string + io.Reader +} diff --git a/vendor/gopkg.in/resty.v1/default.go b/vendor/gopkg.in/resty.v1/default.go new file mode 100644 index 0000000000..cc6ae478cf --- /dev/null +++ b/vendor/gopkg.in/resty.v1/default.go @@ -0,0 +1,327 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "crypto/tls" + "encoding/json" + "io" + "math" + "net/http" + "net/http/cookiejar" + "net/url" + "os" + "time" + + "golang.org/x/net/publicsuffix" +) + +// DefaultClient of resty +var DefaultClient *Client + +// New method creates a new go-resty client. +func New() *Client { + cookieJar, _ := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) + return createClient(&http.Client{Jar: cookieJar}) +} + +// NewWithClient method create a new go-resty client with given `http.Client`. +func NewWithClient(hc *http.Client) *Client { + return createClient(hc) +} + +// R creates a new resty request object, it is used form a HTTP/RESTful request +// such as GET, POST, PUT, DELETE, HEAD, PATCH and OPTIONS. +func R() *Request { + return DefaultClient.R() +} + +// NewRequest is an alias for R(). Creates a new resty request object, it is used form a HTTP/RESTful request +// such as GET, POST, PUT, DELETE, HEAD, PATCH and OPTIONS. +func NewRequest() *Request { + return R() +} + +// SetHostURL sets Host URL. See `Client.SetHostURL for more information. +func SetHostURL(url string) *Client { + return DefaultClient.SetHostURL(url) +} + +// SetHeader sets single header. See `Client.SetHeader` for more information. +func SetHeader(header, value string) *Client { + return DefaultClient.SetHeader(header, value) +} + +// SetHeaders sets multiple headers. See `Client.SetHeaders` for more information. +func SetHeaders(headers map[string]string) *Client { + return DefaultClient.SetHeaders(headers) +} + +// SetCookieJar sets custom http.CookieJar. See `Client.SetCookieJar` for more information. +func SetCookieJar(jar http.CookieJar) *Client { + return DefaultClient.SetCookieJar(jar) +} + +// SetCookie sets single cookie object. See `Client.SetCookie` for more information. +func SetCookie(hc *http.Cookie) *Client { + return DefaultClient.SetCookie(hc) +} + +// SetCookies sets multiple cookie object. See `Client.SetCookies` for more information. +func SetCookies(cs []*http.Cookie) *Client { + return DefaultClient.SetCookies(cs) +} + +// SetQueryParam method sets single parameter and its value. See `Client.SetQueryParam` for more information. +func SetQueryParam(param, value string) *Client { + return DefaultClient.SetQueryParam(param, value) +} + +// SetQueryParams method sets multiple parameters and its value. See `Client.SetQueryParams` for more information. +func SetQueryParams(params map[string]string) *Client { + return DefaultClient.SetQueryParams(params) +} + +// SetFormData method sets Form parameters and its values. See `Client.SetFormData` for more information. +func SetFormData(data map[string]string) *Client { + return DefaultClient.SetFormData(data) +} + +// SetBasicAuth method sets the basic authentication header. See `Client.SetBasicAuth` for more information. +func SetBasicAuth(username, password string) *Client { + return DefaultClient.SetBasicAuth(username, password) +} + +// SetAuthToken method sets bearer auth token header. See `Client.SetAuthToken` for more information. +func SetAuthToken(token string) *Client { + return DefaultClient.SetAuthToken(token) +} + +// OnBeforeRequest method sets request middleware. See `Client.OnBeforeRequest` for more information. +func OnBeforeRequest(m func(*Client, *Request) error) *Client { + return DefaultClient.OnBeforeRequest(m) +} + +// OnAfterResponse method sets response middleware. See `Client.OnAfterResponse` for more information. +func OnAfterResponse(m func(*Client, *Response) error) *Client { + return DefaultClient.OnAfterResponse(m) +} + +// SetPreRequestHook method sets the pre-request hook. See `Client.SetPreRequestHook` for more information. +func SetPreRequestHook(h func(*Client, *Request) error) *Client { + return DefaultClient.SetPreRequestHook(h) +} + +// SetDebug method enables the debug mode. See `Client.SetDebug` for more information. +func SetDebug(d bool) *Client { + return DefaultClient.SetDebug(d) +} + +// SetDebugBodyLimit method sets the response body limit for debug mode. See `Client.SetDebugBodyLimit` for more information. +func SetDebugBodyLimit(sl int64) *Client { + return DefaultClient.SetDebugBodyLimit(sl) +} + +// SetAllowGetMethodPayload method allows the GET method with payload. See `Client.SetAllowGetMethodPayload` for more information. +func SetAllowGetMethodPayload(a bool) *Client { + return DefaultClient.SetAllowGetMethodPayload(a) +} + +// SetRetryCount method sets the retry count. See `Client.SetRetryCount` for more information. +func SetRetryCount(count int) *Client { + return DefaultClient.SetRetryCount(count) +} + +// SetRetryWaitTime method sets the retry wait time. See `Client.SetRetryWaitTime` for more information. +func SetRetryWaitTime(waitTime time.Duration) *Client { + return DefaultClient.SetRetryWaitTime(waitTime) +} + +// SetRetryMaxWaitTime method sets the retry max wait time. See `Client.SetRetryMaxWaitTime` for more information. +func SetRetryMaxWaitTime(maxWaitTime time.Duration) *Client { + return DefaultClient.SetRetryMaxWaitTime(maxWaitTime) +} + +// AddRetryCondition method appends check function for retry. See `Client.AddRetryCondition` for more information. +func AddRetryCondition(condition RetryConditionFunc) *Client { + return DefaultClient.AddRetryCondition(condition) +} + +// SetDisableWarn method disables warning comes from `go-resty` client. See `Client.SetDisableWarn` for more information. +func SetDisableWarn(d bool) *Client { + return DefaultClient.SetDisableWarn(d) +} + +// SetLogger method sets given writer for logging. See `Client.SetLogger` for more information. +func SetLogger(w io.Writer) *Client { + return DefaultClient.SetLogger(w) +} + +// SetContentLength method enables `Content-Length` value. See `Client.SetContentLength` for more information. +func SetContentLength(l bool) *Client { + return DefaultClient.SetContentLength(l) +} + +// SetError method is to register the global or client common `Error` object. See `Client.SetError` for more information. +func SetError(err interface{}) *Client { + return DefaultClient.SetError(err) +} + +// SetRedirectPolicy method sets the client redirect poilicy. See `Client.SetRedirectPolicy` for more information. +func SetRedirectPolicy(policies ...interface{}) *Client { + return DefaultClient.SetRedirectPolicy(policies...) +} + +// SetHTTPMode method sets go-resty mode into HTTP. See `Client.SetMode` for more information. +func SetHTTPMode() *Client { + return DefaultClient.SetHTTPMode() +} + +// SetRESTMode method sets go-resty mode into RESTful. See `Client.SetMode` for more information. +func SetRESTMode() *Client { + return DefaultClient.SetRESTMode() +} + +// Mode method returns the current client mode. See `Client.Mode` for more information. +func Mode() string { + return DefaultClient.Mode() +} + +// SetTLSClientConfig method sets TLSClientConfig for underling client Transport. See `Client.SetTLSClientConfig` for more information. +func SetTLSClientConfig(config *tls.Config) *Client { + return DefaultClient.SetTLSClientConfig(config) +} + +// SetTimeout method sets timeout for request. See `Client.SetTimeout` for more information. +func SetTimeout(timeout time.Duration) *Client { + return DefaultClient.SetTimeout(timeout) +} + +// SetProxy method sets Proxy for request. See `Client.SetProxy` for more information. +func SetProxy(proxyURL string) *Client { + return DefaultClient.SetProxy(proxyURL) +} + +// RemoveProxy method removes the proxy configuration. See `Client.RemoveProxy` for more information. +func RemoveProxy() *Client { + return DefaultClient.RemoveProxy() +} + +// SetCertificates method helps to set client certificates into resty conveniently. +// See `Client.SetCertificates` for more information and example. +func SetCertificates(certs ...tls.Certificate) *Client { + return DefaultClient.SetCertificates(certs...) +} + +// SetRootCertificate method helps to add one or more root certificates into resty client. +// See `Client.SetRootCertificate` for more information. +func SetRootCertificate(pemFilePath string) *Client { + return DefaultClient.SetRootCertificate(pemFilePath) +} + +// SetOutputDirectory method sets output directory. See `Client.SetOutputDirectory` for more information. +func SetOutputDirectory(dirPath string) *Client { + return DefaultClient.SetOutputDirectory(dirPath) +} + +// SetTransport method sets custom `*http.Transport` or any `http.RoundTripper` +// compatible interface implementation in the resty client. +// See `Client.SetTransport` for more information. +func SetTransport(transport http.RoundTripper) *Client { + return DefaultClient.SetTransport(transport) +} + +// SetScheme method sets custom scheme in the resty client. +// See `Client.SetScheme` for more information. +func SetScheme(scheme string) *Client { + return DefaultClient.SetScheme(scheme) +} + +// SetCloseConnection method sets close connection value in the resty client. +// See `Client.SetCloseConnection` for more information. +func SetCloseConnection(close bool) *Client { + return DefaultClient.SetCloseConnection(close) +} + +// SetDoNotParseResponse method instructs `Resty` not to parse the response body automatically. +// See `Client.SetDoNotParseResponse` for more information. +func SetDoNotParseResponse(parse bool) *Client { + return DefaultClient.SetDoNotParseResponse(parse) +} + +// SetPathParams method sets the Request path parameter key-value pairs. See +// `Client.SetPathParams` for more information. +func SetPathParams(params map[string]string) *Client { + return DefaultClient.SetPathParams(params) +} + +// IsProxySet method returns the true if proxy is set on client otherwise false. +// See `Client.IsProxySet` for more information. +func IsProxySet() bool { + return DefaultClient.IsProxySet() +} + +// GetClient method returns the current `http.Client` used by the default resty client. +func GetClient() *http.Client { + return DefaultClient.httpClient +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Unexported methods +//___________________________________ + +func createClient(hc *http.Client) *Client { + c := &Client{ + HostURL: "", + QueryParam: url.Values{}, + FormData: url.Values{}, + Header: http.Header{}, + UserInfo: nil, + Token: "", + Cookies: make([]*http.Cookie, 0), + Debug: false, + Log: getLogger(os.Stderr), + RetryCount: 0, + RetryWaitTime: defaultWaitTime, + RetryMaxWaitTime: defaultMaxWaitTime, + JSONMarshal: json.Marshal, + JSONUnmarshal: json.Unmarshal, + jsonEscapeHTML: true, + httpClient: hc, + debugBodySizeLimit: math.MaxInt32, + pathParams: make(map[string]string), + } + + // Log Prefix + c.SetLogPrefix("RESTY ") + + // Default redirect policy + c.SetRedirectPolicy(NoRedirectPolicy()) + + // default before request middlewares + c.beforeRequest = []func(*Client, *Request) error{ + parseRequestURL, + parseRequestHeader, + parseRequestBody, + createHTTPRequest, + addCredentials, + } + + // user defined request middlewares + c.udBeforeRequest = []func(*Client, *Request) error{} + + // default after response middlewares + c.afterResponse = []func(*Client, *Response) error{ + responseLogger, + parseResponseBody, + saveResponseIntoFile, + } + + return c +} + +func init() { + DefaultClient = New() +} diff --git a/vendor/gopkg.in/resty.v1/go.mod b/vendor/gopkg.in/resty.v1/go.mod new file mode 100644 index 0000000000..61341be87b --- /dev/null +++ b/vendor/gopkg.in/resty.v1/go.mod @@ -0,0 +1,3 @@ +module gopkg.in/resty.v1 + +require golang.org/x/net v0.0.0-20181220203305-927f97764cc3 diff --git a/vendor/gopkg.in/resty.v1/middleware.go b/vendor/gopkg.in/resty.v1/middleware.go new file mode 100644 index 0000000000..9b6f102ed6 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/middleware.go @@ -0,0 +1,469 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "bytes" + "encoding/xml" + "errors" + "fmt" + "io" + "mime/multipart" + "net/http" + "net/url" + "os" + "path/filepath" + "reflect" + "strings" + "time" +) + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Request Middleware(s) +//___________________________________ + +func parseRequestURL(c *Client, r *Request) error { + // GitHub #103 Path Params + if len(r.pathParams) > 0 { + for p, v := range r.pathParams { + r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1) + } + } + if len(c.pathParams) > 0 { + for p, v := range c.pathParams { + r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1) + } + } + + // Parsing request URL + reqURL, err := url.Parse(r.URL) + if err != nil { + return err + } + + // If Request.URL is relative path then added c.HostURL into + // the request URL otherwise Request.URL will be used as-is + if !reqURL.IsAbs() { + r.URL = reqURL.String() + if len(r.URL) > 0 && r.URL[0] != '/' { + r.URL = "/" + r.URL + } + + reqURL, err = url.Parse(c.HostURL + r.URL) + if err != nil { + return err + } + } + + // Adding Query Param + query := make(url.Values) + for k, v := range c.QueryParam { + for _, iv := range v { + query.Add(k, iv) + } + } + + for k, v := range r.QueryParam { + // remove query param from client level by key + // since overrides happens for that key in the request + query.Del(k) + + for _, iv := range v { + query.Add(k, iv) + } + } + + // GitHub #123 Preserve query string order partially. + // Since not feasible in `SetQuery*` resty methods, because + // standard package `url.Encode(...)` sorts the query params + // alphabetically + if len(query) > 0 { + if IsStringEmpty(reqURL.RawQuery) { + reqURL.RawQuery = query.Encode() + } else { + reqURL.RawQuery = reqURL.RawQuery + "&" + query.Encode() + } + } + + r.URL = reqURL.String() + + return nil +} + +func parseRequestHeader(c *Client, r *Request) error { + hdr := make(http.Header) + for k := range c.Header { + hdr[k] = append(hdr[k], c.Header[k]...) + } + + for k := range r.Header { + hdr.Del(k) + hdr[k] = append(hdr[k], r.Header[k]...) + } + + if IsStringEmpty(hdr.Get(hdrUserAgentKey)) { + hdr.Set(hdrUserAgentKey, fmt.Sprintf(hdrUserAgentValue, Version)) + } + + ct := hdr.Get(hdrContentTypeKey) + if IsStringEmpty(hdr.Get(hdrAcceptKey)) && !IsStringEmpty(ct) && + (IsJSONType(ct) || IsXMLType(ct)) { + hdr.Set(hdrAcceptKey, hdr.Get(hdrContentTypeKey)) + } + + r.Header = hdr + + return nil +} + +func parseRequestBody(c *Client, r *Request) (err error) { + if isPayloadSupported(r.Method, c.AllowGetMethodPayload) { + // Handling Multipart + if r.isMultiPart && !(r.Method == MethodPatch) { + if err = handleMultipart(c, r); err != nil { + return + } + + goto CL + } + + // Handling Form Data + if len(c.FormData) > 0 || len(r.FormData) > 0 { + handleFormData(c, r) + + goto CL + } + + // Handling Request body + if r.Body != nil { + handleContentType(c, r) + + if err = handleRequestBody(c, r); err != nil { + return + } + } + } + +CL: + // by default resty won't set content length, you can if you want to :) + if (c.setContentLength || r.setContentLength) && r.bodyBuf != nil { + r.Header.Set(hdrContentLengthKey, fmt.Sprintf("%d", r.bodyBuf.Len())) + } + + return +} + +func createHTTPRequest(c *Client, r *Request) (err error) { + if r.bodyBuf == nil { + if reader, ok := r.Body.(io.Reader); ok { + r.RawRequest, err = http.NewRequest(r.Method, r.URL, reader) + } else { + r.RawRequest, err = http.NewRequest(r.Method, r.URL, nil) + } + } else { + r.RawRequest, err = http.NewRequest(r.Method, r.URL, r.bodyBuf) + } + + if err != nil { + return + } + + // Assign close connection option + r.RawRequest.Close = c.closeConnection + + // Add headers into http request + r.RawRequest.Header = r.Header + + // Add cookies into http request + for _, cookie := range c.Cookies { + r.RawRequest.AddCookie(cookie) + } + + // it's for non-http scheme option + if r.RawRequest.URL != nil && r.RawRequest.URL.Scheme == "" { + r.RawRequest.URL.Scheme = c.scheme + r.RawRequest.URL.Host = r.URL + } + + // Use context if it was specified + r.addContextIfAvailable() + + return +} + +func addCredentials(c *Client, r *Request) error { + var isBasicAuth bool + // Basic Auth + if r.UserInfo != nil { // takes precedence + r.RawRequest.SetBasicAuth(r.UserInfo.Username, r.UserInfo.Password) + isBasicAuth = true + } else if c.UserInfo != nil { + r.RawRequest.SetBasicAuth(c.UserInfo.Username, c.UserInfo.Password) + isBasicAuth = true + } + + if !c.DisableWarn { + if isBasicAuth && !strings.HasPrefix(r.URL, "https") { + c.Log.Println("WARNING - Using Basic Auth in HTTP mode is not secure.") + } + } + + // Token Auth + if !IsStringEmpty(r.Token) { // takes precedence + r.RawRequest.Header.Set(hdrAuthorizationKey, "Bearer "+r.Token) + } else if !IsStringEmpty(c.Token) { + r.RawRequest.Header.Set(hdrAuthorizationKey, "Bearer "+c.Token) + } + + return nil +} + +func requestLogger(c *Client, r *Request) error { + if c.Debug { + rr := r.RawRequest + rl := &RequestLog{Header: copyHeaders(rr.Header), Body: r.fmtBodyString()} + if c.requestLog != nil { + if err := c.requestLog(rl); err != nil { + return err + } + } + + reqLog := "\n---------------------- REQUEST LOG -----------------------\n" + + fmt.Sprintf("%s %s %s\n", r.Method, rr.URL.RequestURI(), rr.Proto) + + fmt.Sprintf("HOST : %s\n", rr.URL.Host) + + fmt.Sprintf("HEADERS:\n") + + composeHeaders(rl.Header) + "\n" + + fmt.Sprintf("BODY :\n%v\n", rl.Body) + + "----------------------------------------------------------\n" + + c.Log.Print(reqLog) + } + + return nil +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Response Middleware(s) +//___________________________________ + +func responseLogger(c *Client, res *Response) error { + if c.Debug { + rl := &ResponseLog{Header: copyHeaders(res.Header()), Body: res.fmtBodyString(c.debugBodySizeLimit)} + if c.responseLog != nil { + if err := c.responseLog(rl); err != nil { + return err + } + } + + resLog := "\n---------------------- RESPONSE LOG -----------------------\n" + + fmt.Sprintf("STATUS : %s\n", res.Status()) + + fmt.Sprintf("RECEIVED AT : %v\n", res.ReceivedAt().Format(time.RFC3339Nano)) + + fmt.Sprintf("RESPONSE TIME : %v\n", res.Time()) + + "HEADERS:\n" + + composeHeaders(rl.Header) + "\n" + if res.Request.isSaveResponse { + resLog += fmt.Sprintf("BODY :\n***** RESPONSE WRITTEN INTO FILE *****\n") + } else { + resLog += fmt.Sprintf("BODY :\n%v\n", rl.Body) + } + resLog += "----------------------------------------------------------\n" + + c.Log.Print(resLog) + } + + return nil +} + +func parseResponseBody(c *Client, res *Response) (err error) { + if res.StatusCode() == http.StatusNoContent { + return + } + // Handles only JSON or XML content type + ct := firstNonEmpty(res.Header().Get(hdrContentTypeKey), res.Request.fallbackContentType) + if IsJSONType(ct) || IsXMLType(ct) { + // HTTP status code > 199 and < 300, considered as Result + if res.IsSuccess() { + if res.Request.Result != nil { + err = Unmarshalc(c, ct, res.body, res.Request.Result) + return + } + } + + // HTTP status code > 399, considered as Error + if res.IsError() { + // global error interface + if res.Request.Error == nil && c.Error != nil { + res.Request.Error = reflect.New(c.Error).Interface() + } + + if res.Request.Error != nil { + err = Unmarshalc(c, ct, res.body, res.Request.Error) + } + } + } + + return +} + +func handleMultipart(c *Client, r *Request) (err error) { + r.bodyBuf = acquireBuffer() + w := multipart.NewWriter(r.bodyBuf) + + for k, v := range c.FormData { + for _, iv := range v { + if err = w.WriteField(k, iv); err != nil { + return err + } + } + } + + for k, v := range r.FormData { + for _, iv := range v { + if strings.HasPrefix(k, "@") { // file + err = addFile(w, k[1:], iv) + if err != nil { + return + } + } else { // form value + if err = w.WriteField(k, iv); err != nil { + return err + } + } + } + } + + // #21 - adding io.Reader support + if len(r.multipartFiles) > 0 { + for _, f := range r.multipartFiles { + err = addFileReader(w, f) + if err != nil { + return + } + } + } + + // GitHub #130 adding multipart field support with content type + if len(r.multipartFields) > 0 { + for _, mf := range r.multipartFields { + if err = addMultipartFormField(w, mf); err != nil { + return + } + } + } + + r.Header.Set(hdrContentTypeKey, w.FormDataContentType()) + err = w.Close() + + return +} + +func handleFormData(c *Client, r *Request) { + formData := url.Values{} + + for k, v := range c.FormData { + for _, iv := range v { + formData.Add(k, iv) + } + } + + for k, v := range r.FormData { + // remove form data field from client level by key + // since overrides happens for that key in the request + formData.Del(k) + + for _, iv := range v { + formData.Add(k, iv) + } + } + + r.bodyBuf = bytes.NewBuffer([]byte(formData.Encode())) + r.Header.Set(hdrContentTypeKey, formContentType) + r.isFormData = true +} + +func handleContentType(c *Client, r *Request) { + contentType := r.Header.Get(hdrContentTypeKey) + if IsStringEmpty(contentType) { + contentType = DetectContentType(r.Body) + r.Header.Set(hdrContentTypeKey, contentType) + } +} + +func handleRequestBody(c *Client, r *Request) (err error) { + var bodyBytes []byte + contentType := r.Header.Get(hdrContentTypeKey) + kind := kindOf(r.Body) + r.bodyBuf = nil + + if reader, ok := r.Body.(io.Reader); ok { + if c.setContentLength || r.setContentLength { // keep backward compability + r.bodyBuf = acquireBuffer() + _, err = r.bodyBuf.ReadFrom(reader) + r.Body = nil + } else { + // Otherwise buffer less processing for `io.Reader`, sounds good. + return + } + } else if b, ok := r.Body.([]byte); ok { + bodyBytes = b + } else if s, ok := r.Body.(string); ok { + bodyBytes = []byte(s) + } else if IsJSONType(contentType) && + (kind == reflect.Struct || kind == reflect.Map || kind == reflect.Slice) { + bodyBytes, err = jsonMarshal(c, r, r.Body) + } else if IsXMLType(contentType) && (kind == reflect.Struct) { + bodyBytes, err = xml.Marshal(r.Body) + } + + if bodyBytes == nil && r.bodyBuf == nil { + err = errors.New("unsupported 'Body' type/value") + } + + // if any errors during body bytes handling, return it + if err != nil { + return + } + + // []byte into Buffer + if bodyBytes != nil && r.bodyBuf == nil { + r.bodyBuf = acquireBuffer() + _, _ = r.bodyBuf.Write(bodyBytes) + } + + return +} + +func saveResponseIntoFile(c *Client, res *Response) error { + if res.Request.isSaveResponse { + file := "" + + if len(c.outputDirectory) > 0 && !filepath.IsAbs(res.Request.outputFile) { + file += c.outputDirectory + string(filepath.Separator) + } + + file = filepath.Clean(file + res.Request.outputFile) + if err := createDirectory(filepath.Dir(file)); err != nil { + return err + } + + outFile, err := os.Create(file) + if err != nil { + return err + } + defer closeq(outFile) + + // io.Copy reads maximum 32kb size, it is perfect for large file download too + defer closeq(res.RawResponse.Body) + + written, err := io.Copy(outFile, res.RawResponse.Body) + if err != nil { + return err + } + + res.size = written + } + + return nil +} diff --git a/vendor/gopkg.in/resty.v1/redirect.go b/vendor/gopkg.in/resty.v1/redirect.go new file mode 100644 index 0000000000..b426134ad4 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/redirect.go @@ -0,0 +1,99 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "errors" + "fmt" + "net" + "net/http" + "strings" +) + +type ( + // RedirectPolicy to regulate the redirects in the resty client. + // Objects implementing the RedirectPolicy interface can be registered as + // + // Apply function should return nil to continue the redirect jounery, otherwise + // return error to stop the redirect. + RedirectPolicy interface { + Apply(req *http.Request, via []*http.Request) error + } + + // The RedirectPolicyFunc type is an adapter to allow the use of ordinary functions as RedirectPolicy. + // If f is a function with the appropriate signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls f. + RedirectPolicyFunc func(*http.Request, []*http.Request) error +) + +// Apply calls f(req, via). +func (f RedirectPolicyFunc) Apply(req *http.Request, via []*http.Request) error { + return f(req, via) +} + +// NoRedirectPolicy is used to disable redirects in the HTTP client +// resty.SetRedirectPolicy(NoRedirectPolicy()) +func NoRedirectPolicy() RedirectPolicy { + return RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { + return errors.New("auto redirect is disabled") + }) +} + +// FlexibleRedirectPolicy is convenient method to create No of redirect policy for HTTP client. +// resty.SetRedirectPolicy(FlexibleRedirectPolicy(20)) +func FlexibleRedirectPolicy(noOfRedirect int) RedirectPolicy { + return RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { + if len(via) >= noOfRedirect { + return fmt.Errorf("stopped after %d redirects", noOfRedirect) + } + + checkHostAndAddHeaders(req, via[0]) + + return nil + }) +} + +// DomainCheckRedirectPolicy is convenient method to define domain name redirect rule in resty client. +// Redirect is allowed for only mentioned host in the policy. +// resty.SetRedirectPolicy(DomainCheckRedirectPolicy("host1.com", "host2.org", "host3.net")) +func DomainCheckRedirectPolicy(hostnames ...string) RedirectPolicy { + hosts := make(map[string]bool) + for _, h := range hostnames { + hosts[strings.ToLower(h)] = true + } + + fn := RedirectPolicyFunc(func(req *http.Request, via []*http.Request) error { + if ok := hosts[getHostname(req.URL.Host)]; !ok { + return errors.New("redirect is not allowed as per DomainCheckRedirectPolicy") + } + + return nil + }) + + return fn +} + +func getHostname(host string) (hostname string) { + if strings.Index(host, ":") > 0 { + host, _, _ = net.SplitHostPort(host) + } + hostname = strings.ToLower(host) + return +} + +// By default Golang will not redirect request headers +// after go throughing various discussion comments from thread +// https://github.com/golang/go/issues/4800 +// go-resty will add all the headers during a redirect for the same host +func checkHostAndAddHeaders(cur *http.Request, pre *http.Request) { + curHostname := getHostname(cur.URL.Host) + preHostname := getHostname(pre.URL.Host) + if strings.EqualFold(curHostname, preHostname) { + for key, val := range pre.Header { + cur.Header[key] = val + } + } else { // only library User-Agent header is added + cur.Header.Set(hdrUserAgentKey, fmt.Sprintf(hdrUserAgentValue, Version)) + } +} diff --git a/vendor/gopkg.in/resty.v1/request.go b/vendor/gopkg.in/resty.v1/request.go new file mode 100644 index 0000000000..c6adff3dd8 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/request.go @@ -0,0 +1,586 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "encoding/base64" + "encoding/json" + "encoding/xml" + "fmt" + "io" + "net" + "net/url" + "reflect" + "strings" +) + +// SRVRecord holds the data to query the SRV record for the following service +type SRVRecord struct { + Service string + Domain string +} + +// SetHeader method is to set a single header field and its value in the current request. +// Example: To set `Content-Type` and `Accept` as `application/json`. +// resty.R(). +// SetHeader("Content-Type", "application/json"). +// SetHeader("Accept", "application/json") +// +// Also you can override header value, which was set at client instance level. +// +func (r *Request) SetHeader(header, value string) *Request { + r.Header.Set(header, value) + return r +} + +// SetHeaders method sets multiple headers field and its values at one go in the current request. +// Example: To set `Content-Type` and `Accept` as `application/json` +// +// resty.R(). +// SetHeaders(map[string]string{ +// "Content-Type": "application/json", +// "Accept": "application/json", +// }) +// Also you can override header value, which was set at client instance level. +// +func (r *Request) SetHeaders(headers map[string]string) *Request { + for h, v := range headers { + r.SetHeader(h, v) + } + + return r +} + +// SetQueryParam method sets single parameter and its value in the current request. +// It will be formed as query string for the request. +// Example: `search=kitchen%20papers&size=large` in the URL after `?` mark. +// resty.R(). +// SetQueryParam("search", "kitchen papers"). +// SetQueryParam("size", "large") +// Also you can override query params value, which was set at client instance level +// +func (r *Request) SetQueryParam(param, value string) *Request { + r.QueryParam.Set(param, value) + return r +} + +// SetQueryParams method sets multiple parameters and its values at one go in the current request. +// It will be formed as query string for the request. +// Example: `search=kitchen%20papers&size=large` in the URL after `?` mark. +// resty.R(). +// SetQueryParams(map[string]string{ +// "search": "kitchen papers", +// "size": "large", +// }) +// Also you can override query params value, which was set at client instance level +// +func (r *Request) SetQueryParams(params map[string]string) *Request { + for p, v := range params { + r.SetQueryParam(p, v) + } + + return r +} + +// SetMultiValueQueryParams method appends multiple parameters with multi-value +// at one go in the current request. It will be formed as query string for the request. +// Example: `status=pending&status=approved&status=open` in the URL after `?` mark. +// resty.R(). +// SetMultiValueQueryParams(url.Values{ +// "status": []string{"pending", "approved", "open"}, +// }) +// Also you can override query params value, which was set at client instance level +// +func (r *Request) SetMultiValueQueryParams(params url.Values) *Request { + for p, v := range params { + for _, pv := range v { + r.QueryParam.Add(p, pv) + } + } + + return r +} + +// SetQueryString method provides ability to use string as an input to set URL query string for the request. +// +// Using String as an input +// resty.R(). +// SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more") +// +func (r *Request) SetQueryString(query string) *Request { + params, err := url.ParseQuery(strings.TrimSpace(query)) + if err == nil { + for p, v := range params { + for _, pv := range v { + r.QueryParam.Add(p, pv) + } + } + } else { + r.client.Log.Printf("ERROR %v", err) + } + return r +} + +// SetFormData method sets Form parameters and their values in the current request. +// It's applicable only HTTP method `POST` and `PUT` and requests content type would be set as +// `application/x-www-form-urlencoded`. +// resty.R(). +// SetFormData(map[string]string{ +// "access_token": "BC594900-518B-4F7E-AC75-BD37F019E08F", +// "user_id": "3455454545", +// }) +// Also you can override form data value, which was set at client instance level +// +func (r *Request) SetFormData(data map[string]string) *Request { + for k, v := range data { + r.FormData.Set(k, v) + } + + return r +} + +// SetMultiValueFormData method appends multiple form parameters with multi-value +// at one go in the current request. +// resty.R(). +// SetMultiValueFormData(url.Values{ +// "search_criteria": []string{"book", "glass", "pencil"}, +// }) +// Also you can override form data value, which was set at client instance level +// +func (r *Request) SetMultiValueFormData(params url.Values) *Request { + for k, v := range params { + for _, kv := range v { + r.FormData.Add(k, kv) + } + } + + return r +} + +// SetBody method sets the request body for the request. It supports various realtime needs as easy. +// We can say its quite handy or powerful. Supported request body data types is `string`, +// `[]byte`, `struct`, `map`, `slice` and `io.Reader`. Body value can be pointer or non-pointer. +// Automatic marshalling for JSON and XML content type, if it is `struct`, `map`, or `slice`. +// +// Note: `io.Reader` is processed as bufferless mode while sending request. +// +// Example: +// +// Struct as a body input, based on content type, it will be marshalled. +// resty.R(). +// SetBody(User{ +// Username: "jeeva@myjeeva.com", +// Password: "welcome2resty", +// }) +// +// Map as a body input, based on content type, it will be marshalled. +// resty.R(). +// SetBody(map[string]interface{}{ +// "username": "jeeva@myjeeva.com", +// "password": "welcome2resty", +// "address": &Address{ +// Address1: "1111 This is my street", +// Address2: "Apt 201", +// City: "My City", +// State: "My State", +// ZipCode: 00000, +// }, +// }) +// +// String as a body input. Suitable for any need as a string input. +// resty.R(). +// SetBody(`{ +// "username": "jeeva@getrightcare.com", +// "password": "admin" +// }`) +// +// []byte as a body input. Suitable for raw request such as file upload, serialize & deserialize, etc. +// resty.R(). +// SetBody([]byte("This is my raw request, sent as-is")) +// +func (r *Request) SetBody(body interface{}) *Request { + r.Body = body + return r +} + +// SetResult method is to register the response `Result` object for automatic unmarshalling in the RESTful mode +// if response status code is between 200 and 299 and content type either JSON or XML. +// +// Note: Result object can be pointer or non-pointer. +// resty.R().SetResult(&AuthToken{}) +// // OR +// resty.R().SetResult(AuthToken{}) +// +// Accessing a result value +// response.Result().(*AuthToken) +// +func (r *Request) SetResult(res interface{}) *Request { + r.Result = getPointer(res) + return r +} + +// SetError method is to register the request `Error` object for automatic unmarshalling in the RESTful mode +// if response status code is greater than 399 and content type either JSON or XML. +// +// Note: Error object can be pointer or non-pointer. +// resty.R().SetError(&AuthError{}) +// // OR +// resty.R().SetError(AuthError{}) +// +// Accessing a error value +// response.Error().(*AuthError) +// +func (r *Request) SetError(err interface{}) *Request { + r.Error = getPointer(err) + return r +} + +// SetFile method is to set single file field name and its path for multipart upload. +// resty.R(). +// SetFile("my_file", "/Users/jeeva/Gas Bill - Sep.pdf") +// +func (r *Request) SetFile(param, filePath string) *Request { + r.isMultiPart = true + r.FormData.Set("@"+param, filePath) + return r +} + +// SetFiles method is to set multiple file field name and its path for multipart upload. +// resty.R(). +// SetFiles(map[string]string{ +// "my_file1": "/Users/jeeva/Gas Bill - Sep.pdf", +// "my_file2": "/Users/jeeva/Electricity Bill - Sep.pdf", +// "my_file3": "/Users/jeeva/Water Bill - Sep.pdf", +// }) +// +func (r *Request) SetFiles(files map[string]string) *Request { + r.isMultiPart = true + + for f, fp := range files { + r.FormData.Set("@"+f, fp) + } + + return r +} + +// SetFileReader method is to set single file using io.Reader for multipart upload. +// resty.R(). +// SetFileReader("profile_img", "my-profile-img.png", bytes.NewReader(profileImgBytes)). +// SetFileReader("notes", "user-notes.txt", bytes.NewReader(notesBytes)) +// +func (r *Request) SetFileReader(param, fileName string, reader io.Reader) *Request { + r.isMultiPart = true + r.multipartFiles = append(r.multipartFiles, &File{ + Name: fileName, + ParamName: param, + Reader: reader, + }) + return r +} + +// SetMultipartField method is to set custom data using io.Reader for multipart upload. +func (r *Request) SetMultipartField(param, fileName, contentType string, reader io.Reader) *Request { + r.isMultiPart = true + r.multipartFields = append(r.multipartFields, &MultipartField{ + Param: param, + FileName: fileName, + ContentType: contentType, + Reader: reader, + }) + return r +} + +// SetMultipartFields method is to set multiple data fields using io.Reader for multipart upload. +// Example: +// resty.R().SetMultipartFields( +// &resty.MultipartField{ +// Param: "uploadManifest1", +// FileName: "upload-file-1.json", +// ContentType: "application/json", +// Reader: strings.NewReader(`{"input": {"name": "Uploaded document 1", "_filename" : ["file1.txt"]}}`), +// }, +// &resty.MultipartField{ +// Param: "uploadManifest2", +// FileName: "upload-file-2.json", +// ContentType: "application/json", +// Reader: strings.NewReader(`{"input": {"name": "Uploaded document 2", "_filename" : ["file2.txt"]}}`), +// }) +// +// If you have slice already, then simply call- +// resty.R().SetMultipartFields(fields...) +func (r *Request) SetMultipartFields(fields ...*MultipartField) *Request { + r.isMultiPart = true + r.multipartFields = append(r.multipartFields, fields...) + return r +} + +// SetContentLength method sets the HTTP header `Content-Length` value for current request. +// By default go-resty won't set `Content-Length`. Also you have an option to enable for every +// request. See `resty.SetContentLength` +// resty.R().SetContentLength(true) +// +func (r *Request) SetContentLength(l bool) *Request { + r.setContentLength = true + return r +} + +// SetBasicAuth method sets the basic authentication header in the current HTTP request. +// For Header example: +// Authorization: Basic +// +// To set the header for username "go-resty" and password "welcome" +// resty.R().SetBasicAuth("go-resty", "welcome") +// +// This method overrides the credentials set by method `resty.SetBasicAuth`. +// +func (r *Request) SetBasicAuth(username, password string) *Request { + r.UserInfo = &User{Username: username, Password: password} + return r +} + +// SetAuthToken method sets bearer auth token header in the current HTTP request. Header example: +// Authorization: Bearer +// +// Example: To set auth token BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F +// +// resty.R().SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F") +// +// This method overrides the Auth token set by method `resty.SetAuthToken`. +// +func (r *Request) SetAuthToken(token string) *Request { + r.Token = token + return r +} + +// SetOutput method sets the output file for current HTTP request. Current HTTP response will be +// saved into given file. It is similar to `curl -o` flag. Absolute path or relative path can be used. +// If is it relative path then output file goes under the output directory, as mentioned +// in the `Client.SetOutputDirectory`. +// resty.R(). +// SetOutput("/Users/jeeva/Downloads/ReplyWithHeader-v5.1-beta.zip"). +// Get("http://bit.ly/1LouEKr") +// +// Note: In this scenario `Response.Body` might be nil. +func (r *Request) SetOutput(file string) *Request { + r.outputFile = file + r.isSaveResponse = true + return r +} + +// SetSRV method sets the details to query the service SRV record and execute the +// request. +// resty.R(). +// SetSRV(SRVRecord{"web", "testservice.com"}). +// Get("/get") +func (r *Request) SetSRV(srv *SRVRecord) *Request { + r.SRV = srv + return r +} + +// SetDoNotParseResponse method instructs `Resty` not to parse the response body automatically. +// Resty exposes the raw response body as `io.ReadCloser`. Also do not forget to close the body, +// otherwise you might get into connection leaks, no connection reuse. +// +// Please Note: Response middlewares are not applicable, if you use this option. Basically you have +// taken over the control of response parsing from `Resty`. +func (r *Request) SetDoNotParseResponse(parse bool) *Request { + r.notParseResponse = parse + return r +} + +// SetPathParams method sets multiple URL path key-value pairs at one go in the +// resty current request instance. +// resty.R().SetPathParams(map[string]string{ +// "userId": "sample@sample.com", +// "subAccountId": "100002", +// }) +// +// Result: +// URL - /v1/users/{userId}/{subAccountId}/details +// Composed URL - /v1/users/sample@sample.com/100002/details +// It replace the value of the key while composing request URL. Also you can +// override Path Params value, which was set at client instance level. +func (r *Request) SetPathParams(params map[string]string) *Request { + for p, v := range params { + r.pathParams[p] = v + } + return r +} + +// ExpectContentType method allows to provide fallback `Content-Type` for automatic unmarshalling +// when `Content-Type` response header is unavailable. +func (r *Request) ExpectContentType(contentType string) *Request { + r.fallbackContentType = contentType + return r +} + +// SetJSONEscapeHTML method is to enable/disable the HTML escape on JSON marshal. +// +// NOTE: This option only applicable to standard JSON Marshaller. +func (r *Request) SetJSONEscapeHTML(b bool) *Request { + r.jsonEscapeHTML = b + return r +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// HTTP verb method starts here +//___________________________________ + +// Get method does GET HTTP request. It's defined in section 4.3.1 of RFC7231. +func (r *Request) Get(url string) (*Response, error) { + return r.Execute(MethodGet, url) +} + +// Head method does HEAD HTTP request. It's defined in section 4.3.2 of RFC7231. +func (r *Request) Head(url string) (*Response, error) { + return r.Execute(MethodHead, url) +} + +// Post method does POST HTTP request. It's defined in section 4.3.3 of RFC7231. +func (r *Request) Post(url string) (*Response, error) { + return r.Execute(MethodPost, url) +} + +// Put method does PUT HTTP request. It's defined in section 4.3.4 of RFC7231. +func (r *Request) Put(url string) (*Response, error) { + return r.Execute(MethodPut, url) +} + +// Delete method does DELETE HTTP request. It's defined in section 4.3.5 of RFC7231. +func (r *Request) Delete(url string) (*Response, error) { + return r.Execute(MethodDelete, url) +} + +// Options method does OPTIONS HTTP request. It's defined in section 4.3.7 of RFC7231. +func (r *Request) Options(url string) (*Response, error) { + return r.Execute(MethodOptions, url) +} + +// Patch method does PATCH HTTP request. It's defined in section 2 of RFC5789. +func (r *Request) Patch(url string) (*Response, error) { + return r.Execute(MethodPatch, url) +} + +// Execute method performs the HTTP request with given HTTP method and URL +// for current `Request`. +// resp, err := resty.R().Execute(resty.GET, "http://httpbin.org/get") +// +func (r *Request) Execute(method, url string) (*Response, error) { + var addrs []*net.SRV + var err error + + if r.isMultiPart && !(method == MethodPost || method == MethodPut) { + return nil, fmt.Errorf("multipart content is not allowed in HTTP verb [%v]", method) + } + + if r.SRV != nil { + _, addrs, err = net.LookupSRV(r.SRV.Service, "tcp", r.SRV.Domain) + if err != nil { + return nil, err + } + } + + r.Method = method + r.URL = r.selectAddr(addrs, url, 0) + + if r.client.RetryCount == 0 { + return r.client.execute(r) + } + + var resp *Response + attempt := 0 + _ = Backoff( + func() (*Response, error) { + attempt++ + + r.URL = r.selectAddr(addrs, url, attempt) + + resp, err = r.client.execute(r) + if err != nil { + r.client.Log.Printf("ERROR %v, Attempt %v", err, attempt) + if r.isContextCancelledIfAvailable() { + // stop Backoff from retrying request if request has been + // canceled by context + return resp, nil + } + } + + return resp, err + }, + Retries(r.client.RetryCount), + WaitTime(r.client.RetryWaitTime), + MaxWaitTime(r.client.RetryMaxWaitTime), + RetryConditions(r.client.RetryConditions), + ) + + return resp, err +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Request Unexported methods +//___________________________________ + +func (r *Request) fmtBodyString() (body string) { + body = "***** NO CONTENT *****" + if isPayloadSupported(r.Method, r.client.AllowGetMethodPayload) { + if _, ok := r.Body.(io.Reader); ok { + body = "***** BODY IS io.Reader *****" + return + } + + // multipart or form-data + if r.isMultiPart || r.isFormData { + body = r.bodyBuf.String() + return + } + + // request body data + if r.Body == nil { + return + } + var prtBodyBytes []byte + var err error + + contentType := r.Header.Get(hdrContentTypeKey) + kind := kindOf(r.Body) + if canJSONMarshal(contentType, kind) { + prtBodyBytes, err = json.MarshalIndent(&r.Body, "", " ") + } else if IsXMLType(contentType) && (kind == reflect.Struct) { + prtBodyBytes, err = xml.MarshalIndent(&r.Body, "", " ") + } else if b, ok := r.Body.(string); ok { + if IsJSONType(contentType) { + bodyBytes := []byte(b) + out := acquireBuffer() + defer releaseBuffer(out) + if err = json.Indent(out, bodyBytes, "", " "); err == nil { + prtBodyBytes = out.Bytes() + } + } else { + body = b + return + } + } else if b, ok := r.Body.([]byte); ok { + body = base64.StdEncoding.EncodeToString(b) + } + + if prtBodyBytes != nil && err == nil { + body = string(prtBodyBytes) + } + } + + return +} + +func (r *Request) selectAddr(addrs []*net.SRV, path string, attempt int) string { + if addrs == nil { + return path + } + + idx := attempt % len(addrs) + domain := strings.TrimRight(addrs[idx].Target, ".") + path = strings.TrimLeft(path, "/") + + return fmt.Sprintf("%s://%s:%d/%s", r.client.scheme, domain, addrs[idx].Port, path) +} diff --git a/vendor/gopkg.in/resty.v1/request16.go b/vendor/gopkg.in/resty.v1/request16.go new file mode 100644 index 0000000000..079ecfca74 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/request16.go @@ -0,0 +1,63 @@ +// +build !go1.7 + +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com) +// 2016 Andrew Grigorev (https://github.com/ei-grad) +// All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "bytes" + "encoding/json" + "net/http" + "net/url" + "time" +) + +// Request type is used to compose and send individual request from client +// go-resty is provide option override client level settings such as +// Auth Token, Basic Auth credentials, Header, Query Param, Form Data, Error object +// and also you can add more options for that particular request +type Request struct { + URL string + Method string + Token string + QueryParam url.Values + FormData url.Values + Header http.Header + Time time.Time + Body interface{} + Result interface{} + Error interface{} + RawRequest *http.Request + SRV *SRVRecord + UserInfo *User + + isMultiPart bool + isFormData bool + setContentLength bool + isSaveResponse bool + notParseResponse bool + jsonEscapeHTML bool + outputFile string + fallbackContentType string + pathParams map[string]string + client *Client + bodyBuf *bytes.Buffer + multipartFiles []*File + multipartFields []*MultipartField +} + +func (r *Request) addContextIfAvailable() { + // nothing to do for golang<1.7 +} + +func (r *Request) isContextCancelledIfAvailable() bool { + // just always return false golang<1.7 + return false +} + +// for !go1.7 +var noescapeJSONMarshal = json.Marshal diff --git a/vendor/gopkg.in/resty.v1/request17.go b/vendor/gopkg.in/resty.v1/request17.go new file mode 100644 index 0000000000..0629a114c0 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/request17.go @@ -0,0 +1,96 @@ +// +build go1.7 go1.8 + +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com) +// 2016 Andrew Grigorev (https://github.com/ei-grad) +// All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "bytes" + "context" + "encoding/json" + "net/http" + "net/url" + "time" +) + +// Request type is used to compose and send individual request from client +// go-resty is provide option override client level settings such as +// Auth Token, Basic Auth credentials, Header, Query Param, Form Data, Error object +// and also you can add more options for that particular request +type Request struct { + URL string + Method string + Token string + QueryParam url.Values + FormData url.Values + Header http.Header + Time time.Time + Body interface{} + Result interface{} + Error interface{} + RawRequest *http.Request + SRV *SRVRecord + UserInfo *User + + isMultiPart bool + isFormData bool + setContentLength bool + isSaveResponse bool + notParseResponse bool + jsonEscapeHTML bool + outputFile string + fallbackContentType string + ctx context.Context + pathParams map[string]string + client *Client + bodyBuf *bytes.Buffer + multipartFiles []*File + multipartFields []*MultipartField +} + +// Context method returns the Context if its already set in request +// otherwise it creates new one using `context.Background()`. +func (r *Request) Context() context.Context { + if r.ctx == nil { + return context.Background() + } + return r.ctx +} + +// SetContext method sets the context.Context for current Request. It allows +// to interrupt the request execution if ctx.Done() channel is closed. +// See https://blog.golang.org/context article and the "context" package +// documentation. +func (r *Request) SetContext(ctx context.Context) *Request { + r.ctx = ctx + return r +} + +func (r *Request) addContextIfAvailable() { + if r.ctx != nil { + r.RawRequest = r.RawRequest.WithContext(r.ctx) + } +} + +func (r *Request) isContextCancelledIfAvailable() bool { + if r.ctx != nil { + if r.ctx.Err() != nil { + return true + } + } + return false +} + +// for go1.7+ +var noescapeJSONMarshal = func(v interface{}) ([]byte, error) { + buf := acquireBuffer() + defer releaseBuffer(buf) + encoder := json.NewEncoder(buf) + encoder.SetEscapeHTML(false) + err := encoder.Encode(v) + return buf.Bytes(), err +} diff --git a/vendor/gopkg.in/resty.v1/response.go b/vendor/gopkg.in/resty.v1/response.go new file mode 100644 index 0000000000..ea2a027a53 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/response.go @@ -0,0 +1,150 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "encoding/json" + "fmt" + "io" + "net/http" + "strings" + "time" +) + +// Response is an object represents executed request and its values. +type Response struct { + Request *Request + RawResponse *http.Response + + body []byte + size int64 + receivedAt time.Time +} + +// Body method returns HTTP response as []byte array for the executed request. +// Note: `Response.Body` might be nil, if `Request.SetOutput` is used. +func (r *Response) Body() []byte { + if r.RawResponse == nil { + return []byte{} + } + return r.body +} + +// Status method returns the HTTP status string for the executed request. +// Example: 200 OK +func (r *Response) Status() string { + if r.RawResponse == nil { + return "" + } + + return r.RawResponse.Status +} + +// StatusCode method returns the HTTP status code for the executed request. +// Example: 200 +func (r *Response) StatusCode() int { + if r.RawResponse == nil { + return 0 + } + + return r.RawResponse.StatusCode +} + +// Result method returns the response value as an object if it has one +func (r *Response) Result() interface{} { + return r.Request.Result +} + +// Error method returns the error object if it has one +func (r *Response) Error() interface{} { + return r.Request.Error +} + +// Header method returns the response headers +func (r *Response) Header() http.Header { + if r.RawResponse == nil { + return http.Header{} + } + + return r.RawResponse.Header +} + +// Cookies method to access all the response cookies +func (r *Response) Cookies() []*http.Cookie { + if r.RawResponse == nil { + return make([]*http.Cookie, 0) + } + + return r.RawResponse.Cookies() +} + +// String method returns the body of the server response as String. +func (r *Response) String() string { + if r.body == nil { + return "" + } + + return strings.TrimSpace(string(r.body)) +} + +// Time method returns the time of HTTP response time that from request we sent and received a request. +// See `response.ReceivedAt` to know when client recevied response and see `response.Request.Time` to know +// when client sent a request. +func (r *Response) Time() time.Duration { + return r.receivedAt.Sub(r.Request.Time) +} + +// ReceivedAt method returns when response got recevied from server for the request. +func (r *Response) ReceivedAt() time.Time { + return r.receivedAt +} + +// Size method returns the HTTP response size in bytes. Ya, you can relay on HTTP `Content-Length` header, +// however it won't be good for chucked transfer/compressed response. Since Resty calculates response size +// at the client end. You will get actual size of the http response. +func (r *Response) Size() int64 { + return r.size +} + +// RawBody method exposes the HTTP raw response body. Use this method in-conjunction with `SetDoNotParseResponse` +// option otherwise you get an error as `read err: http: read on closed response body`. +// +// Do not forget to close the body, otherwise you might get into connection leaks, no connection reuse. +// Basically you have taken over the control of response parsing from `Resty`. +func (r *Response) RawBody() io.ReadCloser { + if r.RawResponse == nil { + return nil + } + return r.RawResponse.Body +} + +// IsSuccess method returns true if HTTP status code >= 200 and <= 299 otherwise false. +func (r *Response) IsSuccess() bool { + return r.StatusCode() > 199 && r.StatusCode() < 300 +} + +// IsError method returns true if HTTP status code >= 400 otherwise false. +func (r *Response) IsError() bool { + return r.StatusCode() > 399 +} + +func (r *Response) fmtBodyString(sl int64) string { + if r.body != nil { + if int64(len(r.body)) > sl { + return fmt.Sprintf("***** RESPONSE TOO LARGE (size - %d) *****", len(r.body)) + } + ct := r.Header().Get(hdrContentTypeKey) + if IsJSONType(ct) { + out := acquireBuffer() + defer releaseBuffer(out) + if err := json.Indent(out, r.body, "", " "); err == nil { + return out.String() + } + } + return r.String() + } + + return "***** NO CONTENT *****" +} diff --git a/vendor/gopkg.in/resty.v1/resty.go b/vendor/gopkg.in/resty.v1/resty.go new file mode 100644 index 0000000000..9a32463d73 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/resty.go @@ -0,0 +1,9 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +// Package resty provides Simple HTTP and REST client library for Go. +package resty + +// Version # of resty +const Version = "1.12.0" diff --git a/vendor/gopkg.in/resty.v1/retry.go b/vendor/gopkg.in/resty.v1/retry.go new file mode 100644 index 0000000000..4ed9b6d606 --- /dev/null +++ b/vendor/gopkg.in/resty.v1/retry.go @@ -0,0 +1,118 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "math" + "math/rand" + "time" +) + +const ( + defaultMaxRetries = 3 + defaultWaitTime = time.Duration(100) * time.Millisecond + defaultMaxWaitTime = time.Duration(2000) * time.Millisecond +) + +type ( + // Option is to create convenient retry options like wait time, max retries, etc. + Option func(*Options) + + // RetryConditionFunc type is for retry condition function + RetryConditionFunc func(*Response) (bool, error) + + // Options to hold go-resty retry values + Options struct { + maxRetries int + waitTime time.Duration + maxWaitTime time.Duration + retryConditions []RetryConditionFunc + } +) + +// Retries sets the max number of retries +func Retries(value int) Option { + return func(o *Options) { + o.maxRetries = value + } +} + +// WaitTime sets the default wait time to sleep between requests +func WaitTime(value time.Duration) Option { + return func(o *Options) { + o.waitTime = value + } +} + +// MaxWaitTime sets the max wait time to sleep between requests +func MaxWaitTime(value time.Duration) Option { + return func(o *Options) { + o.maxWaitTime = value + } +} + +// RetryConditions sets the conditions that will be checked for retry. +func RetryConditions(conditions []RetryConditionFunc) Option { + return func(o *Options) { + o.retryConditions = conditions + } +} + +// Backoff retries with increasing timeout duration up until X amount of retries +// (Default is 3 attempts, Override with option Retries(n)) +func Backoff(operation func() (*Response, error), options ...Option) error { + // Defaults + opts := Options{ + maxRetries: defaultMaxRetries, + waitTime: defaultWaitTime, + maxWaitTime: defaultMaxWaitTime, + retryConditions: []RetryConditionFunc{}, + } + + for _, o := range options { + o(&opts) + } + + var ( + resp *Response + err error + ) + base := float64(opts.waitTime) // Time to wait between each attempt + capLevel := float64(opts.maxWaitTime) // Maximum amount of wait time for the retry + for attempt := 0; attempt < opts.maxRetries; attempt++ { + resp, err = operation() + + var needsRetry bool + var conditionErr error + for _, condition := range opts.retryConditions { + needsRetry, conditionErr = condition(resp) + if needsRetry || conditionErr != nil { + break + } + } + + // If the operation returned no error, there was no condition satisfied and + // there was no error caused by the conditional functions. + if err == nil && !needsRetry && conditionErr == nil { + return nil + } + // Adding capped exponential backup with jitter + // See the following article... + // http://www.awsarchitectureblog.com/2015/03/backoff.html + temp := math.Min(capLevel, base*math.Exp2(float64(attempt))) + ri := int(temp / 2) + if ri <= 0 { + ri = 1<<31 - 1 // max int for arch 386 + } + sleepDuration := time.Duration(math.Abs(float64(ri + rand.Intn(ri)))) + + if sleepDuration < opts.waitTime { + sleepDuration = opts.waitTime + } + time.Sleep(sleepDuration) + } + + return err +} diff --git a/vendor/gopkg.in/resty.v1/util.go b/vendor/gopkg.in/resty.v1/util.go new file mode 100644 index 0000000000..997cd1009e --- /dev/null +++ b/vendor/gopkg.in/resty.v1/util.go @@ -0,0 +1,281 @@ +// Copyright (c) 2015-2019 Jeevanandam M (jeeva@myjeeva.com), All rights reserved. +// resty source code and usage is governed by a MIT style +// license that can be found in the LICENSE file. + +package resty + +import ( + "bytes" + "encoding/json" + "encoding/xml" + "fmt" + "io" + "log" + "mime/multipart" + "net/http" + "net/textproto" + "os" + "path/filepath" + "reflect" + "runtime" + "sort" + "strings" +) + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Package Helper methods +//___________________________________ + +// IsStringEmpty method tells whether given string is empty or not +func IsStringEmpty(str string) bool { + return len(strings.TrimSpace(str)) == 0 +} + +// DetectContentType method is used to figure out `Request.Body` content type for request header +func DetectContentType(body interface{}) string { + contentType := plainTextType + kind := kindOf(body) + switch kind { + case reflect.Struct, reflect.Map: + contentType = jsonContentType + case reflect.String: + contentType = plainTextType + default: + if b, ok := body.([]byte); ok { + contentType = http.DetectContentType(b) + } else if kind == reflect.Slice { + contentType = jsonContentType + } + } + + return contentType +} + +// IsJSONType method is to check JSON content type or not +func IsJSONType(ct string) bool { + return jsonCheck.MatchString(ct) +} + +// IsXMLType method is to check XML content type or not +func IsXMLType(ct string) bool { + return xmlCheck.MatchString(ct) +} + +// Unmarshal content into object from JSON or XML +// Deprecated: kept for backward compatibility +func Unmarshal(ct string, b []byte, d interface{}) (err error) { + if IsJSONType(ct) { + err = json.Unmarshal(b, d) + } else if IsXMLType(ct) { + err = xml.Unmarshal(b, d) + } + + return +} + +// Unmarshalc content into object from JSON or XML +func Unmarshalc(c *Client, ct string, b []byte, d interface{}) (err error) { + if IsJSONType(ct) { + err = c.JSONUnmarshal(b, d) + } else if IsXMLType(ct) { + err = xml.Unmarshal(b, d) + } + + return +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// RequestLog and ResponseLog type +//___________________________________ + +// RequestLog struct is used to collected information from resty request +// instance for debug logging. It sent to request log callback before resty +// actually logs the information. +type RequestLog struct { + Header http.Header + Body string +} + +// ResponseLog struct is used to collected information from resty response +// instance for debug logging. It sent to response log callback before resty +// actually logs the information. +type ResponseLog struct { + Header http.Header + Body string +} + +//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ +// Package Unexported methods +//___________________________________ + +// way to disable the HTML escape as opt-in +func jsonMarshal(c *Client, r *Request, d interface{}) ([]byte, error) { + if !r.jsonEscapeHTML { + return noescapeJSONMarshal(d) + } else if !c.jsonEscapeHTML { + return noescapeJSONMarshal(d) + } + return c.JSONMarshal(d) +} + +func firstNonEmpty(v ...string) string { + for _, s := range v { + if !IsStringEmpty(s) { + return s + } + } + return "" +} + +func getLogger(w io.Writer) *log.Logger { + return log.New(w, "RESTY ", log.LstdFlags) +} + +var quoteEscaper = strings.NewReplacer("\\", "\\\\", `"`, "\\\"") + +func escapeQuotes(s string) string { + return quoteEscaper.Replace(s) +} + +func createMultipartHeader(param, fileName, contentType string) textproto.MIMEHeader { + hdr := make(textproto.MIMEHeader) + hdr.Set("Content-Disposition", fmt.Sprintf(`form-data; name="%s"; filename="%s"`, + escapeQuotes(param), escapeQuotes(fileName))) + hdr.Set("Content-Type", contentType) + return hdr +} + +func addMultipartFormField(w *multipart.Writer, mf *MultipartField) error { + partWriter, err := w.CreatePart(createMultipartHeader(mf.Param, mf.FileName, mf.ContentType)) + if err != nil { + return err + } + + _, err = io.Copy(partWriter, mf.Reader) + return err +} + +func writeMultipartFormFile(w *multipart.Writer, fieldName, fileName string, r io.Reader) error { + // Auto detect actual multipart content type + cbuf := make([]byte, 512) + size, err := r.Read(cbuf) + if err != nil { + return err + } + + partWriter, err := w.CreatePart(createMultipartHeader(fieldName, fileName, http.DetectContentType(cbuf))) + if err != nil { + return err + } + + if _, err = partWriter.Write(cbuf[:size]); err != nil { + return err + } + + _, err = io.Copy(partWriter, r) + return err +} + +func addFile(w *multipart.Writer, fieldName, path string) error { + file, err := os.Open(path) + if err != nil { + return err + } + defer closeq(file) + return writeMultipartFormFile(w, fieldName, filepath.Base(path), file) +} + +func addFileReader(w *multipart.Writer, f *File) error { + return writeMultipartFormFile(w, f.ParamName, f.Name, f.Reader) +} + +func getPointer(v interface{}) interface{} { + vv := valueOf(v) + if vv.Kind() == reflect.Ptr { + return v + } + return reflect.New(vv.Type()).Interface() +} + +func isPayloadSupported(m string, allowMethodGet bool) bool { + return !(m == MethodHead || m == MethodOptions || (m == MethodGet && !allowMethodGet)) +} + +func typeOf(i interface{}) reflect.Type { + return indirect(valueOf(i)).Type() +} + +func valueOf(i interface{}) reflect.Value { + return reflect.ValueOf(i) +} + +func indirect(v reflect.Value) reflect.Value { + return reflect.Indirect(v) +} + +func kindOf(v interface{}) reflect.Kind { + return typeOf(v).Kind() +} + +func createDirectory(dir string) (err error) { + if _, err = os.Stat(dir); err != nil { + if os.IsNotExist(err) { + if err = os.MkdirAll(dir, 0755); err != nil { + return + } + } + } + return +} + +func canJSONMarshal(contentType string, kind reflect.Kind) bool { + return IsJSONType(contentType) && (kind == reflect.Struct || kind == reflect.Map || kind == reflect.Slice) +} + +func functionName(i interface{}) string { + return runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name() +} + +func acquireBuffer() *bytes.Buffer { + return bufPool.Get().(*bytes.Buffer) +} + +func releaseBuffer(buf *bytes.Buffer) { + if buf != nil { + buf.Reset() + bufPool.Put(buf) + } +} + +func closeq(v interface{}) { + if c, ok := v.(io.Closer); ok { + sliently(c.Close()) + } +} + +func sliently(_ ...interface{}) {} + +func composeHeaders(hdrs http.Header) string { + var str []string + for _, k := range sortHeaderKeys(hdrs) { + str = append(str, fmt.Sprintf("%25s: %s", k, strings.Join(hdrs[k], ", "))) + } + return strings.Join(str, "\n") +} + +func sortHeaderKeys(hdrs http.Header) []string { + var keys []string + for key := range hdrs { + keys = append(keys, key) + } + sort.Strings(keys) + return keys +} + +func copyHeaders(hdrs http.Header) http.Header { + nh := http.Header{} + for k, v := range hdrs { + nh[k] = v + } + return nh +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 49a33ae8e9..026dea6910 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -5,10 +5,11 @@ github.com/Azure/azure-sdk-for-go/services/network/mgmt/2015-06-15/network github.com/Azure/azure-sdk-for-go/version # github.com/Azure/go-autorest v10.15.3+incompatible github.com/Azure/go-autorest/autorest -github.com/Azure/go-autorest/autorest/adal +github.com/Azure/go-autorest/autorest/azure/auth github.com/Azure/go-autorest/autorest/azure github.com/Azure/go-autorest/autorest/to github.com/Azure/go-autorest/autorest/validation +github.com/Azure/go-autorest/autorest/adal github.com/Azure/go-autorest/logger github.com/Azure/go-autorest/version github.com/Azure/go-autorest/autorest/date @@ -29,7 +30,7 @@ github.com/armon/go-metrics/datadog github.com/armon/go-metrics/prometheus # github.com/armon/go-radix v1.0.0 github.com/armon/go-radix -# github.com/aws/aws-sdk-go v1.25.32 +# github.com/aws/aws-sdk-go v1.25.41 github.com/aws/aws-sdk-go/aws github.com/aws/aws-sdk-go/aws/awserr github.com/aws/aws-sdk-go/aws/session @@ -91,6 +92,8 @@ github.com/denverdino/aliyungo/util github.com/dgrijalva/jwt-go # github.com/digitalocean/godo v1.10.0 github.com/digitalocean/godo +# github.com/dimchansky/utfbom v1.1.0 +github.com/dimchansky/utfbom # github.com/docker/go-connections v0.3.0 github.com/docker/go-connections/sockets # github.com/elazarl/go-bindata-assetfs v0.0.0-20160803192304-e1a2a7ec64b0 @@ -174,7 +177,7 @@ github.com/hashicorp/go-bexpr github.com/hashicorp/go-checkpoint # github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-cleanhttp -# github.com/hashicorp/go-discover v0.0.0-20190403160810-22221edb15cd +# github.com/hashicorp/go-discover v0.0.0-20191202160150-7ec2cfbda7a2 github.com/hashicorp/go-discover github.com/hashicorp/go-discover/provider/k8s github.com/hashicorp/go-discover/provider/aliyun @@ -182,11 +185,13 @@ github.com/hashicorp/go-discover/provider/aws github.com/hashicorp/go-discover/provider/azure github.com/hashicorp/go-discover/provider/digitalocean github.com/hashicorp/go-discover/provider/gce +github.com/hashicorp/go-discover/provider/linode github.com/hashicorp/go-discover/provider/mdns github.com/hashicorp/go-discover/provider/os github.com/hashicorp/go-discover/provider/packet github.com/hashicorp/go-discover/provider/scaleway github.com/hashicorp/go-discover/provider/softlayer +github.com/hashicorp/go-discover/provider/tencentcloud github.com/hashicorp/go-discover/provider/triton github.com/hashicorp/go-discover/provider/vsphere # github.com/hashicorp/go-hclog v0.9.2 @@ -274,6 +279,8 @@ github.com/joyent/triton-go/errors github.com/json-iterator/go # github.com/kr/text v0.1.0 github.com/kr/text +# github.com/linode/linodego v0.7.1 +github.com/linode/linodego # github.com/mattn/go-colorable v0.0.9 github.com/mattn/go-colorable # github.com/mattn/go-isatty v0.0.3 @@ -370,6 +377,12 @@ github.com/stretchr/objx github.com/stretchr/testify/mock github.com/stretchr/testify/require github.com/stretchr/testify/assert +# github.com/tencentcloud/tencentcloud-sdk-go v3.0.83+incompatible +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312 +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors +github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http # github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 github.com/tv42/httpunix # github.com/vmware/govmomi v0.18.0 @@ -395,8 +408,10 @@ golang.org/x/crypto/ed25519 golang.org/x/crypto/ssh/terminal golang.org/x/crypto/ed25519/internal/edwards25519 golang.org/x/crypto/pbkdf2 +golang.org/x/crypto/pkcs12 golang.org/x/crypto/ssh golang.org/x/crypto/ssh/agent +golang.org/x/crypto/pkcs12/internal/rc2 golang.org/x/crypto/curve25519 golang.org/x/crypto/internal/chacha20 golang.org/x/crypto/poly1305 @@ -417,6 +432,7 @@ golang.org/x/net/internal/socket golang.org/x/net/internal/timeseries golang.org/x/net/internal/socks golang.org/x/net/context/ctxhttp +golang.org/x/net/publicsuffix # golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be golang.org/x/oauth2 golang.org/x/oauth2/google @@ -498,6 +514,8 @@ google.golang.org/grpc/binarylog/grpc_binarylog_v1 google.golang.org/grpc/internal/syscall # gopkg.in/inf.v0 v0.9.1 gopkg.in/inf.v0 +# gopkg.in/resty.v1 v1.12.0 +gopkg.in/resty.v1 # gopkg.in/square/go-jose.v2 v2.3.1 gopkg.in/square/go-jose.v2/jwt gopkg.in/square/go-jose.v2