mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
DIGITAL OCEAN: Update github.com/digitalocean/godo (#513)
This commit is contained in:
119
vendor/github.com/digitalocean/godo/CHANGELOG.md
generated
vendored
119
vendor/github.com/digitalocean/godo/CHANGELOG.md
generated
vendored
@ -1,5 +1,124 @@
|
||||
# Change Log
|
||||
|
||||
## [v1.17.0] - 2019-06-21
|
||||
|
||||
- #238 Add support for Redis eviction policy in Databases @mikejholly
|
||||
|
||||
## [v1.16.0] - 2019-06-04
|
||||
|
||||
- #233 Add Kubernetes DeleteNode method, deprecate RecycleNodePoolNodes @bouk
|
||||
|
||||
## [v1.15.0] - 2019-05-13
|
||||
|
||||
- #231 Add private connection fields to Databases - @mikejholly
|
||||
- #223 Introduce Go modules - @andreiavrammsd
|
||||
|
||||
## [v1.14.0] - 2019-05-13
|
||||
|
||||
- #229 Add support for upgrading Kubernetes clusters - @adamwg
|
||||
|
||||
## [v1.13.0] - 2019-04-19
|
||||
|
||||
- #213 Add tagging support for volume snapshots - @jcodybaker
|
||||
|
||||
## [v1.12.0] - 2019-04-18
|
||||
|
||||
- #224 Add maintenance window support for Kubernetes- @fatih
|
||||
|
||||
## [v1.11.1] - 2019-04-04
|
||||
|
||||
- #222 Fix Create Database Pools json fields - @sunny-b
|
||||
|
||||
## [v1.11.0] - 2019-04-03
|
||||
|
||||
- #220 roll out vpc functionality - @jheimann
|
||||
|
||||
## [v1.10.1] - 2019-03-27
|
||||
|
||||
- #219 Fix Database Pools json field - @sunny-b
|
||||
|
||||
## [v1.10.0] - 2019-03-20
|
||||
|
||||
- #215 Add support for Databases - @mikejholly
|
||||
|
||||
## [v1.9.0] - 2019-03-18
|
||||
|
||||
- #214 add support for enable_proxy_protocol. - @mregmi
|
||||
|
||||
## [v1.8.0] - 2019-03-13
|
||||
|
||||
- #210 Expose tags on storage volume create/list/get. - @jcodybaker
|
||||
|
||||
## [v1.7.5] - 2019-03-04
|
||||
|
||||
- #207 Add support for custom subdomains for Spaces CDN [beta] - @xornivore
|
||||
|
||||
## [v1.7.4] - 2019-02-08
|
||||
|
||||
- #202 Allow tagging volumes - @mchitten
|
||||
|
||||
## [v1.7.3] - 2018-12-18
|
||||
|
||||
- #196 Expose tag support for creating Load Balancers.
|
||||
|
||||
## [v1.7.2] - 2018-12-04
|
||||
|
||||
- #192 Exposes more options for Kubernetes clusters.
|
||||
|
||||
## [v1.7.1] - 2018-11-27
|
||||
|
||||
- #190 Expose constants for the state of Kubernetes clusters.
|
||||
|
||||
## [v1.7.0] - 2018-11-13
|
||||
|
||||
- #188 Kubernetes support [beta] - @aybabtme
|
||||
|
||||
## [v1.6.0] - 2018-10-16
|
||||
|
||||
- #185 Projects support [beta] - @mchitten
|
||||
|
||||
## [v1.5.0] - 2018-10-01
|
||||
|
||||
- #181 Adding tagging images support - @hugocorbucci
|
||||
|
||||
## [v1.4.2] - 2018-08-30
|
||||
|
||||
- #178 Allowing creating domain records with weight of 0 - @TFaga
|
||||
- #177 Adding `VolumeLimit` to account - @lxfontes
|
||||
|
||||
## [v1.4.1] - 2018-08-23
|
||||
|
||||
- #176 Fix cdn flush cache API endpoint - @sunny-b
|
||||
|
||||
## [v1.4.0] - 2018-08-22
|
||||
|
||||
- #175 Add support for Spaces CDN - @sunny-b
|
||||
|
||||
## [v1.3.0] - 2018-05-24
|
||||
|
||||
- #170 Add support for volume formatting - @adamwg
|
||||
|
||||
## [v1.2.0] - 2018-05-08
|
||||
|
||||
- #166 Remove support for Go 1.6 - @iheanyi
|
||||
- #165 Add support for Let's Encrypt Certificates - @viola
|
||||
|
||||
## [v1.1.3] - 2018-03-07
|
||||
|
||||
- #156 Handle non-json errors from the API - @aknuds1
|
||||
- #158 Update droplet example to use latest instance type - @dan-v
|
||||
|
||||
## [v1.1.2] - 2018-03-06
|
||||
|
||||
- #157 storage: list volumes should handle only name or only region params - @andrewsykim
|
||||
- #154 docs: replace first example with fully-runnable example - @xmudrii
|
||||
- #152 Handle flags & tag properties of domain record - @jaymecd
|
||||
|
||||
## [v1.1.1] - 2017-09-29
|
||||
|
||||
- #151 Following user agent field recommendations - @joonas
|
||||
- #148 AsRequest method to create load balancers requests - @lukegb
|
||||
|
||||
## [v1.1.0] - 2017-06-06
|
||||
|
||||
### Added
|
||||
|
31
vendor/github.com/digitalocean/godo/CONTRIBUTING.md
generated
vendored
31
vendor/github.com/digitalocean/godo/CONTRIBUTING.md
generated
vendored
@ -12,6 +12,13 @@ Assuming your `$GOPATH` is set up according to your desires, run:
|
||||
|
||||
```sh
|
||||
go get github.com/digitalocean/godo
|
||||
go get -u github.com/stretchr/testify/assert
|
||||
```
|
||||
|
||||
If outside `$GOPATH`, just clone the repository:
|
||||
|
||||
```sh
|
||||
git clone github.com/digitalocean/godo
|
||||
```
|
||||
|
||||
## Running tests
|
||||
@ -21,3 +28,27 @@ When working on code in this repository, tests can be run via:
|
||||
```sh
|
||||
go test .
|
||||
```
|
||||
|
||||
## Versioning
|
||||
|
||||
Godo follows [semver](https://www.semver.org) versioning semantics. New functionality should be accompanied by increment to the minor version number. The current strategy is to release often. Any code which is complete, tested, reviewed, and merged to master is worthy of release.
|
||||
|
||||
## Releasing
|
||||
|
||||
Releasing a new version of godo is currently a manual process.
|
||||
|
||||
1. Update the `CHANGELOG.md` with your changes. If a version header for the next (unreleased) version does not exist, create one. Include one bullet point for each piece of new functionality in the release, including the pull request ID, description, and author(s).
|
||||
|
||||
```
|
||||
## [v1.8.0] - 2019-03-13
|
||||
|
||||
- #210 Expose tags on storage volume create/list/get. - @jcodybaker
|
||||
- #123 Update test dependencies - @digitalocean
|
||||
```
|
||||
|
||||
2. Update the `libraryVersion` number in `godo.go`.
|
||||
3. Make a pull request with these changes. This PR should be separate from the PR containing the godo changes.
|
||||
4. Once the pull request has been merged, [draft a new release](https://github.com/digitalocean/godo/releases/new).
|
||||
5. Update the `Tag version` and `Release title` field with the new godo version. Be sure the version has a `v` prefixed in both places. Ex `v1.8.0`.
|
||||
6. Copy the changelog bullet points to the description field.
|
||||
7. Publish the release.
|
||||
|
52
vendor/github.com/digitalocean/godo/README.md
generated
vendored
52
vendor/github.com/digitalocean/godo/README.md
generated
vendored
@ -8,6 +8,18 @@ You can view the client API docs here: [http://godoc.org/github.com/digitalocean
|
||||
|
||||
You can view DigitalOcean API docs here: [https://developers.digitalocean.com/documentation/v2/](https://developers.digitalocean.com/documentation/v2/)
|
||||
|
||||
## Install
|
||||
```sh
|
||||
go get github.com/digitalocean/godo@vX.Y.Z
|
||||
```
|
||||
|
||||
where X.Y.Z is the [version](https://github.com/digitalocean/godo/releases) you need.
|
||||
|
||||
or
|
||||
```sh
|
||||
go get github.com/digitalocean/godo
|
||||
```
|
||||
for non Go modules usage or latest version.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -27,25 +39,37 @@ at the DigitalOcean Control Panel [Applications Page](https://cloud.digitalocean
|
||||
You can then use your token to create a new client:
|
||||
|
||||
```go
|
||||
import "golang.org/x/oauth2"
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/digitalocean/godo"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
pat = "mytoken"
|
||||
)
|
||||
|
||||
pat := "mytoken"
|
||||
type TokenSource struct {
|
||||
AccessToken string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func (t *TokenSource) Token() (*oauth2.Token, error) {
|
||||
token := &oauth2.Token{
|
||||
AccessToken: t.AccessToken,
|
||||
}
|
||||
return token, nil
|
||||
token := &oauth2.Token{
|
||||
AccessToken: t.AccessToken,
|
||||
}
|
||||
return token, nil
|
||||
}
|
||||
|
||||
tokenSource := &TokenSource{
|
||||
AccessToken: pat,
|
||||
func main() {
|
||||
tokenSource := &TokenSource{
|
||||
AccessToken: pat,
|
||||
}
|
||||
|
||||
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
|
||||
client := godo.NewClient(oauthClient)
|
||||
}
|
||||
oauthClient := oauth2.NewClient(context.Background(), tokenSource)
|
||||
client := godo.NewClient(oauthClient)
|
||||
```
|
||||
|
||||
## Examples
|
||||
@ -59,7 +83,7 @@ dropletName := "super-cool-droplet"
|
||||
createRequest := &godo.DropletCreateRequest{
|
||||
Name: dropletName,
|
||||
Region: "nyc3",
|
||||
Size: "512mb",
|
||||
Size: "s-1vcpu-1gb",
|
||||
Image: godo.DropletCreateImage{
|
||||
Slug: "ubuntu-14-04-x64",
|
||||
},
|
||||
@ -119,10 +143,6 @@ func DropletList(ctx context.Context, client *godo.Client) ([]godo.Droplet, erro
|
||||
|
||||
Each version of the client is tagged and the version is updated accordingly.
|
||||
|
||||
Since Go does not have a built-in versioning, a package management tool is
|
||||
recommended - a good one that works with git tags is
|
||||
[gopkg.in](http://labix.org/gopkg.in).
|
||||
|
||||
To see the list of past versions, run `git tag`.
|
||||
|
||||
|
||||
|
4
vendor/github.com/digitalocean/godo/account.go
generated
vendored
4
vendor/github.com/digitalocean/godo/account.go
generated
vendored
@ -1,9 +1,8 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// AccountService is an interface for interfacing with the Account
|
||||
@ -25,6 +24,7 @@ var _ AccountService = &AccountServiceOp{}
|
||||
type Account struct {
|
||||
DropletLimit int `json:"droplet_limit,omitempty"`
|
||||
FloatingIPLimit int `json:"floating_ip_limit,omitempty"`
|
||||
VolumeLimit int `json:"volume_limit,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
UUID string `json:"uuid,omitempty"`
|
||||
EmailVerified bool `json:"email_verified,omitempty"`
|
||||
|
3
vendor/github.com/digitalocean/godo/action.go
generated
vendored
3
vendor/github.com/digitalocean/godo/action.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const (
|
||||
|
214
vendor/github.com/digitalocean/godo/cdn.go
generated
vendored
Normal file
214
vendor/github.com/digitalocean/godo/cdn.go
generated
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const cdnBasePath = "v2/cdn/endpoints"
|
||||
|
||||
// CDNService is an interface for managing Spaces CDN with the DigitalOcean API.
|
||||
type CDNService interface {
|
||||
List(context.Context, *ListOptions) ([]CDN, *Response, error)
|
||||
Get(context.Context, string) (*CDN, *Response, error)
|
||||
Create(context.Context, *CDNCreateRequest) (*CDN, *Response, error)
|
||||
UpdateTTL(context.Context, string, *CDNUpdateTTLRequest) (*CDN, *Response, error)
|
||||
UpdateCustomDomain(context.Context, string, *CDNUpdateCustomDomainRequest) (*CDN, *Response, error)
|
||||
FlushCache(context.Context, string, *CDNFlushCacheRequest) (*Response, error)
|
||||
Delete(context.Context, string) (*Response, error)
|
||||
}
|
||||
|
||||
// CDNServiceOp handles communication with the CDN related methods of the
|
||||
// DigitalOcean API.
|
||||
type CDNServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ CDNService = &CDNServiceOp{}
|
||||
|
||||
// CDN represents a DigitalOcean CDN
|
||||
type CDN struct {
|
||||
ID string `json:"id"`
|
||||
Origin string `json:"origin"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
CertificateID string `json:"certificate_id,omitempty"`
|
||||
CustomDomain string `json:"custom_domain,omitempty"`
|
||||
}
|
||||
|
||||
// CDNRoot represents a response from the DigitalOcean API
|
||||
type cdnRoot struct {
|
||||
Endpoint *CDN `json:"endpoint"`
|
||||
}
|
||||
|
||||
type cdnsRoot struct {
|
||||
Endpoints []CDN `json:"endpoints"`
|
||||
Links *Links `json:"links"`
|
||||
}
|
||||
|
||||
// CDNCreateRequest represents a request to create a CDN.
|
||||
type CDNCreateRequest struct {
|
||||
Origin string `json:"origin"`
|
||||
TTL uint32 `json:"ttl"`
|
||||
CustomDomain string `json:"custom_domain,omitempty"`
|
||||
CertificateID string `json:"certificate_id,omitempty"`
|
||||
}
|
||||
|
||||
// CDNUpdateTTLRequest represents a request to update the ttl of a CDN.
|
||||
type CDNUpdateTTLRequest struct {
|
||||
TTL uint32 `json:"ttl"`
|
||||
}
|
||||
|
||||
// CDNUpdateCustomDomainRequest represents a request to update the custom domain of a CDN.
|
||||
type CDNUpdateCustomDomainRequest struct {
|
||||
CustomDomain string `json:"custom_domain"`
|
||||
CertificateID string `json:"certificate_id"`
|
||||
}
|
||||
|
||||
// CDNFlushCacheRequest represents a request to flush cache of a CDN.
|
||||
type CDNFlushCacheRequest struct {
|
||||
Files []string `json:"files"`
|
||||
}
|
||||
|
||||
// List all CDN endpoints
|
||||
func (c CDNServiceOp) List(ctx context.Context, opt *ListOptions) ([]CDN, *Response, error) {
|
||||
path, err := addOptions(cdnBasePath, opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(cdnsRoot)
|
||||
resp, err := c.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if l := root.Links; l != nil {
|
||||
resp.Links = l
|
||||
}
|
||||
|
||||
return root.Endpoints, resp, err
|
||||
}
|
||||
|
||||
// Get individual CDN. It requires a non-empty cdn id.
|
||||
func (c CDNServiceOp) Get(ctx context.Context, id string) (*CDN, *Response, error) {
|
||||
if len(id) == 0 {
|
||||
return nil, nil, NewArgError("id", "cannot be an empty string")
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/%s", cdnBasePath, id)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(cdnRoot)
|
||||
resp, err := c.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Endpoint, resp, err
|
||||
}
|
||||
|
||||
// Create a new CDN
|
||||
func (c CDNServiceOp) Create(ctx context.Context, createRequest *CDNCreateRequest) (*CDN, *Response, error) {
|
||||
if createRequest == nil {
|
||||
return nil, nil, NewArgError("createRequest", "cannot be nil")
|
||||
}
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodPost, cdnBasePath, createRequest)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(cdnRoot)
|
||||
resp, err := c.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Endpoint, resp, err
|
||||
}
|
||||
|
||||
// UpdateTTL updates the ttl of an individual CDN
|
||||
func (c CDNServiceOp) UpdateTTL(ctx context.Context, id string, updateRequest *CDNUpdateTTLRequest) (*CDN, *Response, error) {
|
||||
return c.update(ctx, id, updateRequest)
|
||||
}
|
||||
|
||||
// UpdateCustomDomain sets or removes the custom domain of an individual CDN
|
||||
func (c CDNServiceOp) UpdateCustomDomain(ctx context.Context, id string, updateRequest *CDNUpdateCustomDomainRequest) (*CDN, *Response, error) {
|
||||
return c.update(ctx, id, updateRequest)
|
||||
}
|
||||
|
||||
func (c CDNServiceOp) update(ctx context.Context, id string, updateRequest interface{}) (*CDN, *Response, error) {
|
||||
if updateRequest == nil {
|
||||
return nil, nil, NewArgError("updateRequest", "cannot be nil")
|
||||
}
|
||||
|
||||
if len(id) == 0 {
|
||||
return nil, nil, NewArgError("id", "cannot be an empty string")
|
||||
}
|
||||
path := fmt.Sprintf("%s/%s", cdnBasePath, id)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodPut, path, updateRequest)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(cdnRoot)
|
||||
resp, err := c.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Endpoint, resp, err
|
||||
}
|
||||
|
||||
// FlushCache flushes the cache of an individual CDN. Requires a non-empty slice of file paths and/or wildcards
|
||||
func (c CDNServiceOp) FlushCache(ctx context.Context, id string, flushCacheRequest *CDNFlushCacheRequest) (*Response, error) {
|
||||
if flushCacheRequest == nil {
|
||||
return nil, NewArgError("flushCacheRequest", "cannot be nil")
|
||||
}
|
||||
|
||||
if len(id) == 0 {
|
||||
return nil, NewArgError("id", "cannot be an empty string")
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/%s/cache", cdnBasePath, id)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodDelete, path, flushCacheRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(ctx, req, nil)
|
||||
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// Delete an individual CDN
|
||||
func (c CDNServiceOp) Delete(ctx context.Context, id string) (*Response, error) {
|
||||
if len(id) == 0 {
|
||||
return nil, NewArgError("id", "cannot be an empty string")
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/%s", cdnBasePath, id)
|
||||
|
||||
req, err := c.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := c.client.Do(ctx, req, nil)
|
||||
|
||||
return resp, err
|
||||
}
|
26
vendor/github.com/digitalocean/godo/certificates.go
generated
vendored
26
vendor/github.com/digitalocean/godo/certificates.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const certificatesBasePath = "/v2/certificates"
|
||||
@ -20,19 +19,24 @@ type CertificatesService interface {
|
||||
|
||||
// Certificate represents a DigitalOcean certificate configuration.
|
||||
type Certificate struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
NotAfter string `json:"not_after,omitempty"`
|
||||
SHA1Fingerprint string `json:"sha1_fingerprint,omitempty"`
|
||||
Created string `json:"created_at,omitempty"`
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
DNSNames []string `json:"dns_names,omitempty"`
|
||||
NotAfter string `json:"not_after,omitempty"`
|
||||
SHA1Fingerprint string `json:"sha1_fingerprint,omitempty"`
|
||||
Created string `json:"created_at,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
// CertificateRequest represents configuration for a new certificate.
|
||||
type CertificateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
PrivateKey string `json:"private_key,omitempty"`
|
||||
LeafCertificate string `json:"leaf_certificate,omitempty"`
|
||||
CertificateChain string `json:"certificate_chain,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
DNSNames []string `json:"dns_names,omitempty"`
|
||||
PrivateKey string `json:"private_key,omitempty"`
|
||||
LeafCertificate string `json:"leaf_certificate,omitempty"`
|
||||
CertificateChain string `json:"certificate_chain,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type certificateRoot struct {
|
||||
|
664
vendor/github.com/digitalocean/godo/databases.go
generated
vendored
Normal file
664
vendor/github.com/digitalocean/godo/databases.go
generated
vendored
Normal file
@ -0,0 +1,664 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
databaseBasePath = "/v2/databases"
|
||||
databaseSinglePath = databaseBasePath + "/%s"
|
||||
databaseResizePath = databaseBasePath + "/%s/resize"
|
||||
databaseMigratePath = databaseBasePath + "/%s/migrate"
|
||||
databaseMaintenancePath = databaseBasePath + "/%s/maintenance"
|
||||
databaseBackupsPath = databaseBasePath + "/%s/backups"
|
||||
databaseUsersPath = databaseBasePath + "/%s/users"
|
||||
databaseUserPath = databaseBasePath + "/%s/users/%s"
|
||||
databaseDBPath = databaseBasePath + "/%s/dbs/%s"
|
||||
databaseDBsPath = databaseBasePath + "/%s/dbs"
|
||||
databasePoolPath = databaseBasePath + "/%s/pools/%s"
|
||||
databasePoolsPath = databaseBasePath + "/%s/pools"
|
||||
databaseReplicaPath = databaseBasePath + "/%s/replicas/%s"
|
||||
databaseReplicasPath = databaseBasePath + "/%s/replicas"
|
||||
evictionPolicyPath = databaseBasePath + "/%s/eviction_policy"
|
||||
)
|
||||
|
||||
// DatabasesService is an interface for interfacing with the databases endpoints
|
||||
// of the DigitalOcean API.
|
||||
// See: https://developers.digitalocean.com/documentation/v2#databases
|
||||
type DatabasesService interface {
|
||||
List(context.Context, *ListOptions) ([]Database, *Response, error)
|
||||
Get(context.Context, string) (*Database, *Response, error)
|
||||
Create(context.Context, *DatabaseCreateRequest) (*Database, *Response, error)
|
||||
Delete(context.Context, string) (*Response, error)
|
||||
Resize(context.Context, string, *DatabaseResizeRequest) (*Response, error)
|
||||
Migrate(context.Context, string, *DatabaseMigrateRequest) (*Response, error)
|
||||
UpdateMaintenance(context.Context, string, *DatabaseUpdateMaintenanceRequest) (*Response, error)
|
||||
ListBackups(context.Context, string, *ListOptions) ([]DatabaseBackup, *Response, error)
|
||||
GetUser(context.Context, string, string) (*DatabaseUser, *Response, error)
|
||||
ListUsers(context.Context, string, *ListOptions) ([]DatabaseUser, *Response, error)
|
||||
CreateUser(context.Context, string, *DatabaseCreateUserRequest) (*DatabaseUser, *Response, error)
|
||||
DeleteUser(context.Context, string, string) (*Response, error)
|
||||
ListDBs(context.Context, string, *ListOptions) ([]DatabaseDB, *Response, error)
|
||||
CreateDB(context.Context, string, *DatabaseCreateDBRequest) (*DatabaseDB, *Response, error)
|
||||
GetDB(context.Context, string, string) (*DatabaseDB, *Response, error)
|
||||
DeleteDB(context.Context, string, string) (*Response, error)
|
||||
ListPools(context.Context, string, *ListOptions) ([]DatabasePool, *Response, error)
|
||||
CreatePool(context.Context, string, *DatabaseCreatePoolRequest) (*DatabasePool, *Response, error)
|
||||
GetPool(context.Context, string, string) (*DatabasePool, *Response, error)
|
||||
DeletePool(context.Context, string, string) (*Response, error)
|
||||
GetReplica(context.Context, string, string) (*DatabaseReplica, *Response, error)
|
||||
ListReplicas(context.Context, string, *ListOptions) ([]DatabaseReplica, *Response, error)
|
||||
CreateReplica(context.Context, string, *DatabaseCreateReplicaRequest) (*DatabaseReplica, *Response, error)
|
||||
DeleteReplica(context.Context, string, string) (*Response, error)
|
||||
GetEvictionPolicy(context.Context, string) (string, *Response, error)
|
||||
SetEvictionPolicy(context.Context, string, string) (*Response, error)
|
||||
}
|
||||
|
||||
// DatabasesServiceOp handles communication with the Databases related methods
|
||||
// of the DigitalOcean API.
|
||||
type DatabasesServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
var _ DatabasesService = &DatabasesServiceOp{}
|
||||
|
||||
// Database represents a DigitalOcean managed database product. These managed databases
|
||||
// are usually comprised of a cluster of database nodes, a primary and 0 or more replicas.
|
||||
// The EngineSlug is a string which indicates the type of database service. Some examples are
|
||||
// "pg", "mysql" or "redis". A Database also includes connection information and other
|
||||
// properties of the service like region, size and current status.
|
||||
type Database struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
EngineSlug string `json:"engine,omitempty"`
|
||||
VersionSlug string `json:"version,omitempty"`
|
||||
Connection *DatabaseConnection `json:"connection,omitempty"`
|
||||
PrivateConnection *DatabaseConnection `json:"private_connection,omitempty"`
|
||||
Users []DatabaseUser `json:"users,omitempty"`
|
||||
NumNodes int `json:"num_nodes,omitempty"`
|
||||
SizeSlug string `json:"size,omitempty"`
|
||||
DBNames []string `json:"db_names,omitempty"`
|
||||
RegionSlug string `json:"region,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
MaintenanceWindow *DatabaseMaintenanceWindow `json:"maintenance_window,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
PrivateNetworkUUID string `json:"private_network_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseConnection represents a database connection
|
||||
type DatabaseConnection struct {
|
||||
URI string `json:"uri,omitempty"`
|
||||
Database string `json:"database,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
User string `json:"user,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
SSL bool `json:"ssl,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseUser represents a user in the database
|
||||
type DatabaseUser struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseMaintenanceWindow represents the maintenance_window of a database
|
||||
// cluster
|
||||
type DatabaseMaintenanceWindow struct {
|
||||
Day string `json:"day,omitempty"`
|
||||
Hour string `json:"hour,omitempty"`
|
||||
Pending bool `json:"pending,omitempty"`
|
||||
Description []string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseBackup represents a database backup.
|
||||
type DatabaseBackup struct {
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
SizeGigabytes float64 `json:"size_gigabytes,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseCreateRequest represents a request to create a database cluster
|
||||
type DatabaseCreateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
EngineSlug string `json:"engine,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
SizeSlug string `json:"size,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
NumNodes int `json:"num_nodes,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseResizeRequest can be used to initiate a database resize operation.
|
||||
type DatabaseResizeRequest struct {
|
||||
SizeSlug string `json:"size,omitempty"`
|
||||
NumNodes int `json:"num_nodes,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseMigrateRequest can be used to initiate a database migrate operation.
|
||||
type DatabaseMigrateRequest struct {
|
||||
Region string `json:"region,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseUpdateMaintenanceRequest can be used to update the database's maintenance window.
|
||||
type DatabaseUpdateMaintenanceRequest struct {
|
||||
Day string `json:"day,omitempty"`
|
||||
Hour string `json:"hour,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseDB represents an engine-specific database created within a database cluster. For SQL
|
||||
// databases like PostgreSQL or MySQL, a "DB" refers to a database created on the RDBMS. For instance,
|
||||
// a PostgreSQL database server can contain many database schemas, each with it's own settings, access
|
||||
// permissions and data. ListDBs will return all databases present on the server.
|
||||
type DatabaseDB struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// DatabaseReplica represents a read-only replica of a particular database
|
||||
type DatabaseReplica struct {
|
||||
Name string `json:"name"`
|
||||
Connection *DatabaseConnection `json:"connection"`
|
||||
PrivateConnection *DatabaseConnection `json:"private_connection,omitempty"`
|
||||
Region string `json:"region"`
|
||||
Status string `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
PrivateNetworkUUID string `json:"private_network_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// DatabasePool represents a database connection pool
|
||||
type DatabasePool struct {
|
||||
User string `json:"user"`
|
||||
Name string `json:"name"`
|
||||
Size int `json:"size"`
|
||||
Database string `json:"db"`
|
||||
Mode string `json:"mode"`
|
||||
Connection *DatabaseConnection `json:"connection"`
|
||||
PrivateConnection *DatabaseConnection `json:"private_connection,omitempty"`
|
||||
}
|
||||
|
||||
// DatabaseCreatePoolRequest is used to create a new database connection pool
|
||||
type DatabaseCreatePoolRequest struct {
|
||||
User string `json:"user"`
|
||||
Name string `json:"name"`
|
||||
Size int `json:"size"`
|
||||
Database string `json:"db"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
// DatabaseCreateUserRequest is used to create a new database user
|
||||
type DatabaseCreateUserRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// DatabaseCreateDBRequest is used to create a new engine-specific database within the cluster
|
||||
type DatabaseCreateDBRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// DatabaseCreateReplicaRequest is used to create a new read-only replica
|
||||
type DatabaseCreateReplicaRequest struct {
|
||||
Name string `json:"name"`
|
||||
Region string `json:"region"`
|
||||
Size string `json:"size"`
|
||||
}
|
||||
|
||||
type databaseUserRoot struct {
|
||||
User *DatabaseUser `json:"user"`
|
||||
}
|
||||
|
||||
type databaseUsersRoot struct {
|
||||
Users []DatabaseUser `json:"users"`
|
||||
}
|
||||
|
||||
type databaseDBRoot struct {
|
||||
DB *DatabaseDB `json:"db"`
|
||||
}
|
||||
|
||||
type databaseDBsRoot struct {
|
||||
DBs []DatabaseDB `json:"dbs"`
|
||||
}
|
||||
|
||||
type databasesRoot struct {
|
||||
Databases []Database `json:"databases"`
|
||||
}
|
||||
|
||||
type databaseRoot struct {
|
||||
Database *Database `json:"database"`
|
||||
}
|
||||
|
||||
type databaseBackupsRoot struct {
|
||||
Backups []DatabaseBackup `json:"backups"`
|
||||
}
|
||||
|
||||
type databasePoolRoot struct {
|
||||
Pool *DatabasePool `json:"pool"`
|
||||
}
|
||||
|
||||
type databasePoolsRoot struct {
|
||||
Pools []DatabasePool `json:"pools"`
|
||||
}
|
||||
|
||||
type databaseReplicaRoot struct {
|
||||
Replica *DatabaseReplica `json:"replica"`
|
||||
}
|
||||
|
||||
type databaseReplicasRoot struct {
|
||||
Replicas []DatabaseReplica `json:"replicas"`
|
||||
}
|
||||
|
||||
type evictionPolicyRoot struct {
|
||||
EvictionPolicy string `json:"eviction_policy"`
|
||||
}
|
||||
|
||||
func (d Database) URN() string {
|
||||
return ToURN("dbaas", d.ID)
|
||||
}
|
||||
|
||||
// List returns a list of the Databases visible with the caller's API token
|
||||
func (svc *DatabasesServiceOp) List(ctx context.Context, opts *ListOptions) ([]Database, *Response, error) {
|
||||
path := databaseBasePath
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databasesRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Databases, resp, nil
|
||||
}
|
||||
|
||||
// Get retrieves the details of a database cluster
|
||||
func (svc *DatabasesServiceOp) Get(ctx context.Context, databaseID string) (*Database, *Response, error) {
|
||||
path := fmt.Sprintf(databaseSinglePath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Database, resp, nil
|
||||
}
|
||||
|
||||
// Create creates a database cluster
|
||||
func (svc *DatabasesServiceOp) Create(ctx context.Context, create *DatabaseCreateRequest) (*Database, *Response, error) {
|
||||
path := databaseBasePath
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, create)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Database, resp, nil
|
||||
}
|
||||
|
||||
// Delete deletes a database cluster. There is no way to recover a cluster once
|
||||
// it has been destroyed.
|
||||
func (svc *DatabasesServiceOp) Delete(ctx context.Context, databaseID string) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s", databaseBasePath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Resize resizes a database cluster by number of nodes or size
|
||||
func (svc *DatabasesServiceOp) Resize(ctx context.Context, databaseID string, resize *DatabaseResizeRequest) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseResizePath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, resize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Migrate migrates a database cluster to a new region
|
||||
func (svc *DatabasesServiceOp) Migrate(ctx context.Context, databaseID string, migrate *DatabaseMigrateRequest) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseMigratePath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, migrate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// UpdateMaintenance updates the maintenance window on a cluster
|
||||
func (svc *DatabasesServiceOp) UpdateMaintenance(ctx context.Context, databaseID string, maintenance *DatabaseUpdateMaintenanceRequest) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseMaintenancePath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, maintenance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ListBackups returns a list of the current backups of a database
|
||||
func (svc *DatabasesServiceOp) ListBackups(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseBackup, *Response, error) {
|
||||
path := fmt.Sprintf(databaseBackupsPath, databaseID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseBackupsRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Backups, resp, nil
|
||||
}
|
||||
|
||||
// GetUser returns the database user identified by userID
|
||||
func (svc *DatabasesServiceOp) GetUser(ctx context.Context, databaseID, userID string) (*DatabaseUser, *Response, error) {
|
||||
path := fmt.Sprintf(databaseUserPath, databaseID, userID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseUserRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.User, resp, nil
|
||||
}
|
||||
|
||||
// ListUsers returns all database users for the database
|
||||
func (svc *DatabasesServiceOp) ListUsers(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseUser, *Response, error) {
|
||||
path := fmt.Sprintf(databaseUsersPath, databaseID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseUsersRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Users, resp, nil
|
||||
}
|
||||
|
||||
// CreateUser will create a new database user
|
||||
func (svc *DatabasesServiceOp) CreateUser(ctx context.Context, databaseID string, createUser *DatabaseCreateUserRequest) (*DatabaseUser, *Response, error) {
|
||||
path := fmt.Sprintf(databaseUsersPath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createUser)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseUserRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.User, resp, nil
|
||||
}
|
||||
|
||||
// DeleteUser will delete an existing database user
|
||||
func (svc *DatabasesServiceOp) DeleteUser(ctx context.Context, databaseID, userID string) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseUserPath, databaseID, userID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ListDBs returns all databases for a given database cluster
|
||||
func (svc *DatabasesServiceOp) ListDBs(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseDB, *Response, error) {
|
||||
path := fmt.Sprintf(databaseDBsPath, databaseID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseDBsRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.DBs, resp, nil
|
||||
}
|
||||
|
||||
// GetDB returns a single database by name
|
||||
func (svc *DatabasesServiceOp) GetDB(ctx context.Context, databaseID, name string) (*DatabaseDB, *Response, error) {
|
||||
path := fmt.Sprintf(databaseDBPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseDBRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.DB, resp, nil
|
||||
}
|
||||
|
||||
// CreateDB will create a new database
|
||||
func (svc *DatabasesServiceOp) CreateDB(ctx context.Context, databaseID string, createDB *DatabaseCreateDBRequest) (*DatabaseDB, *Response, error) {
|
||||
path := fmt.Sprintf(databaseDBsPath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createDB)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseDBRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.DB, resp, nil
|
||||
}
|
||||
|
||||
// DeleteDB will delete an existing database
|
||||
func (svc *DatabasesServiceOp) DeleteDB(ctx context.Context, databaseID, name string) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseDBPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ListPools returns all connection pools for a given database cluster
|
||||
func (svc *DatabasesServiceOp) ListPools(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabasePool, *Response, error) {
|
||||
path := fmt.Sprintf(databasePoolsPath, databaseID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databasePoolsRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Pools, resp, nil
|
||||
}
|
||||
|
||||
// GetPool returns a single database connection pool by name
|
||||
func (svc *DatabasesServiceOp) GetPool(ctx context.Context, databaseID, name string) (*DatabasePool, *Response, error) {
|
||||
path := fmt.Sprintf(databasePoolPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databasePoolRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Pool, resp, nil
|
||||
}
|
||||
|
||||
// CreatePool will create a new database connection pool
|
||||
func (svc *DatabasesServiceOp) CreatePool(ctx context.Context, databaseID string, createPool *DatabaseCreatePoolRequest) (*DatabasePool, *Response, error) {
|
||||
path := fmt.Sprintf(databasePoolsPath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createPool)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databasePoolRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Pool, resp, nil
|
||||
}
|
||||
|
||||
// DeletePool will delete an existing database connection pool
|
||||
func (svc *DatabasesServiceOp) DeletePool(ctx context.Context, databaseID, name string) (*Response, error) {
|
||||
path := fmt.Sprintf(databasePoolPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetReplica returns a single database replica
|
||||
func (svc *DatabasesServiceOp) GetReplica(ctx context.Context, databaseID, name string) (*DatabaseReplica, *Response, error) {
|
||||
path := fmt.Sprintf(databaseReplicaPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseReplicaRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Replica, resp, nil
|
||||
}
|
||||
|
||||
// ListReplicas returns all read-only replicas for a given database cluster
|
||||
func (svc *DatabasesServiceOp) ListReplicas(ctx context.Context, databaseID string, opts *ListOptions) ([]DatabaseReplica, *Response, error) {
|
||||
path := fmt.Sprintf(databaseReplicasPath, databaseID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseReplicasRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Replicas, resp, nil
|
||||
}
|
||||
|
||||
// CreateReplica will create a new database connection pool
|
||||
func (svc *DatabasesServiceOp) CreateReplica(ctx context.Context, databaseID string, createReplica *DatabaseCreateReplicaRequest) (*DatabaseReplica, *Response, error) {
|
||||
path := fmt.Sprintf(databaseReplicasPath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, createReplica)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(databaseReplicaRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Replica, resp, nil
|
||||
}
|
||||
|
||||
// DeleteReplica will delete an existing database replica
|
||||
func (svc *DatabasesServiceOp) DeleteReplica(ctx context.Context, databaseID, name string) (*Response, error) {
|
||||
path := fmt.Sprintf(databaseReplicaPath, databaseID, name)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetEvictionPolicy loads the eviction policy for a given Redis cluster.
|
||||
func (svc *DatabasesServiceOp) GetEvictionPolicy(ctx context.Context, databaseID string) (string, *Response, error) {
|
||||
path := fmt.Sprintf(evictionPolicyPath, databaseID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
root := new(evictionPolicyRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return "", resp, err
|
||||
}
|
||||
return root.EvictionPolicy, resp, nil
|
||||
}
|
||||
|
||||
// SetEvictionPolicy updates the eviction policy for a given Redis cluster.
|
||||
func (svc *DatabasesServiceOp) SetEvictionPolicy(ctx context.Context, databaseID, policy string) (*Response, error) {
|
||||
path := fmt.Sprintf(evictionPolicyPath, databaseID)
|
||||
root := &evictionPolicyRoot{EvictionPolicy: policy}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, root)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
9
vendor/github.com/digitalocean/godo/doc.go
generated
vendored
9
vendor/github.com/digitalocean/godo/doc.go
generated
vendored
@ -1,2 +1,11 @@
|
||||
// Package godo is the DigtalOcean API v2 client for Go
|
||||
//
|
||||
// Databases
|
||||
//
|
||||
// The Databases service provides access to the DigitalOcean managed database
|
||||
// suite of products. Customers can create new database clusters, migrate them
|
||||
// between regions, create replicas and interact with their configurations.
|
||||
// Each database service is refered to as a Database. A SQL database service
|
||||
// can have multiple databases residing in the system. To help make these
|
||||
// entities distinct from Databases in godo, we refer to them here as DatabaseDBs.
|
||||
package godo
|
||||
|
29
vendor/github.com/digitalocean/godo/domains.go
generated
vendored
29
vendor/github.com/digitalocean/godo/domains.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const domainsBasePath = "v2/domains"
|
||||
@ -53,7 +52,7 @@ type domainsRoot struct {
|
||||
// DomainCreateRequest respresents a request to create a domain.
|
||||
type DomainCreateRequest struct {
|
||||
Name string `json:"name"`
|
||||
IPAddress string `json:"ip_address"`
|
||||
IPAddress string `json:"ip_address,omitempty"`
|
||||
}
|
||||
|
||||
// DomainRecordRoot is the root of an individual Domain Record response
|
||||
@ -73,10 +72,12 @@ type DomainRecord struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
Priority int `json:"priority,omitempty"`
|
||||
Priority int `json:"priority"`
|
||||
Port int `json:"port,omitempty"`
|
||||
TTL int `json:"ttl,omitempty"`
|
||||
Weight int `json:"weight,omitempty"`
|
||||
Weight int `json:"weight"`
|
||||
Flags int `json:"flags"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
}
|
||||
|
||||
// DomainRecordEditRequest represents a request to update a domain record.
|
||||
@ -84,16 +85,22 @@ type DomainRecordEditRequest struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Data string `json:"data,omitempty"`
|
||||
Priority int `json:"priority,omitempty"`
|
||||
Priority int `json:"priority"`
|
||||
Port int `json:"port,omitempty"`
|
||||
TTL int `json:"ttl,omitempty"`
|
||||
Weight int `json:"weight,omitempty"`
|
||||
Weight int `json:"weight"`
|
||||
Flags int `json:"flags"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
}
|
||||
|
||||
func (d Domain) String() string {
|
||||
return Stringify(d)
|
||||
}
|
||||
|
||||
func (d Domain) URN() string {
|
||||
return ToURN("Domain", d.Name)
|
||||
}
|
||||
|
||||
// List all domains.
|
||||
func (s DomainsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Domain, *Response, error) {
|
||||
path := domainsBasePath
|
||||
@ -287,18 +294,18 @@ func (s *DomainsServiceOp) EditRecord(ctx context.Context,
|
||||
|
||||
path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id)
|
||||
|
||||
req, err := s.client.NewRequest(ctx, "PUT", path, editRequest)
|
||||
req, err := s.client.NewRequest(ctx, http.MethodPut, path, editRequest)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
d := new(DomainRecord)
|
||||
resp, err := s.client.Do(ctx, req, d)
|
||||
root := new(domainRecordRoot)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return d, resp, err
|
||||
return root.DomainRecord, resp, err
|
||||
}
|
||||
|
||||
// CreateRecord creates a record using a DomainRecordEditRequest
|
||||
|
10
vendor/github.com/digitalocean/godo/droplet_actions.go
generated
vendored
10
vendor/github.com/digitalocean/godo/droplet_actions.go
generated
vendored
@ -1,11 +1,10 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// ActionRequest reprents DigitalOcean Action Request
|
||||
@ -41,7 +40,6 @@ type DropletActionsService interface {
|
||||
EnableIPv6ByTag(context.Context, string) ([]Action, *Response, error)
|
||||
EnablePrivateNetworking(context.Context, int) (*Action, *Response, error)
|
||||
EnablePrivateNetworkingByTag(context.Context, string) ([]Action, *Response, error)
|
||||
Upgrade(context.Context, int) (*Action, *Response, error)
|
||||
Get(context.Context, int, int) (*Action, *Response, error)
|
||||
GetByURI(context.Context, string) (*Action, *Response, error)
|
||||
}
|
||||
@ -231,12 +229,6 @@ func (s *DropletActionsServiceOp) EnablePrivateNetworkingByTag(ctx context.Conte
|
||||
return s.doActionByTag(ctx, tag, request)
|
||||
}
|
||||
|
||||
// Upgrade a Droplet.
|
||||
func (s *DropletActionsServiceOp) Upgrade(ctx context.Context, id int) (*Action, *Response, error) {
|
||||
request := &ActionRequest{"type": "upgrade"}
|
||||
return s.doAction(ctx, id, request)
|
||||
}
|
||||
|
||||
func (s *DropletActionsServiceOp) doAction(ctx context.Context, id int, request *ActionRequest) (*Action, *Response, error) {
|
||||
if id < 1 {
|
||||
return nil, nil, NewArgError("id", "cannot be less than 1")
|
||||
|
10
vendor/github.com/digitalocean/godo/droplets.go
generated
vendored
10
vendor/github.com/digitalocean/godo/droplets.go
generated
vendored
@ -1,12 +1,11 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const dropletBasePath = "v2/droplets"
|
||||
@ -61,6 +60,7 @@ type Droplet struct {
|
||||
Kernel *Kernel `json:"kernel,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
VolumeIDs []string `json:"volume_ids"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// PublicIPv4 returns the public IPv4 address for the Droplet.
|
||||
@ -126,6 +126,10 @@ func (d Droplet) String() string {
|
||||
return Stringify(d)
|
||||
}
|
||||
|
||||
func (d Droplet) URN() string {
|
||||
return ToURN("Droplet", d.ID)
|
||||
}
|
||||
|
||||
// DropletRoot represents a Droplet root
|
||||
type dropletRoot struct {
|
||||
Droplet *Droplet `json:"droplet"`
|
||||
@ -219,6 +223,7 @@ type DropletCreateRequest struct {
|
||||
UserData string `json:"user_data,omitempty"`
|
||||
Volumes []DropletCreateVolume `json:"volumes,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// DropletMultiCreateRequest is a request to create multiple Droplets.
|
||||
@ -234,6 +239,7 @@ type DropletMultiCreateRequest struct {
|
||||
Monitoring bool `json:"monitoring"`
|
||||
UserData string `json:"user_data,omitempty"`
|
||||
Tags []string `json:"tags"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
}
|
||||
|
||||
func (d DropletCreateRequest) String() string {
|
||||
|
9
vendor/github.com/digitalocean/godo/firewalls.go
generated
vendored
9
vendor/github.com/digitalocean/godo/firewalls.go
generated
vendored
@ -1,17 +1,16 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path"
|
||||
"strconv"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const firewallsBasePath = "/v2/firewalls"
|
||||
|
||||
// FirewallsService is an interface for managing Firewalls with the DigitalOcean API.
|
||||
// See: https://developers.digitalocean.com/documentation/documentation/v2/#firewalls
|
||||
// See: https://developers.digitalocean.com/documentation/v2/#firewalls
|
||||
type FirewallsService interface {
|
||||
Get(context.Context, string) (*Firewall, *Response, error)
|
||||
Create(context.Context, *FirewallRequest) (*Firewall, *Response, error)
|
||||
@ -50,6 +49,10 @@ func (fw Firewall) String() string {
|
||||
return Stringify(fw)
|
||||
}
|
||||
|
||||
func (fw Firewall) URN() string {
|
||||
return ToURN("Firewall", fw.ID)
|
||||
}
|
||||
|
||||
// FirewallRequest represents the configuration to be applied to an existing or a new Firewall.
|
||||
type FirewallRequest struct {
|
||||
Name string `json:"name"`
|
||||
|
7
vendor/github.com/digitalocean/godo/floating_ips.go
generated
vendored
7
vendor/github.com/digitalocean/godo/floating_ips.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const floatingBasePath = "v2/floating_ips"
|
||||
@ -38,6 +37,10 @@ func (f FloatingIP) String() string {
|
||||
return Stringify(f)
|
||||
}
|
||||
|
||||
func (f FloatingIP) URN() string {
|
||||
return ToURN("FloatingIP", f.IP)
|
||||
}
|
||||
|
||||
type floatingIPsRoot struct {
|
||||
FloatingIPs []FloatingIP `json:"floating_ips"`
|
||||
Links *Links `json:"links"`
|
||||
|
3
vendor/github.com/digitalocean/godo/floating_ips_actions.go
generated
vendored
3
vendor/github.com/digitalocean/godo/floating_ips_actions.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// FloatingIPActionsService is an interface for interfacing with the
|
||||
|
9
vendor/github.com/digitalocean/godo/go.mod
generated
vendored
Normal file
9
vendor/github.com/digitalocean/godo/go.mod
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
module github.com/digitalocean/godo
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/google/go-querystring v1.0.0
|
||||
github.com/stretchr/testify v1.3.0
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a
|
||||
)
|
19
vendor/github.com/digitalocean/godo/go.sum
generated
vendored
Normal file
19
vendor/github.com/digitalocean/godo/go.sum
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a h1:tImsplftrFpALCYumobsd0K86vlAs/eXGFms2txfJfA=
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
64
vendor/github.com/digitalocean/godo/godo.go
generated
vendored
64
vendor/github.com/digitalocean/godo/godo.go
generated
vendored
@ -2,6 +2,7 @@ package godo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -13,13 +14,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-querystring/query"
|
||||
headerLink "github.com/tent/http-link-go"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const (
|
||||
libraryVersion = "1.1.0"
|
||||
libraryVersion = "1.17.0"
|
||||
defaultBaseURL = "https://api.digitalocean.com/"
|
||||
userAgent = "godo/" + libraryVersion
|
||||
mediaType = "application/json"
|
||||
@ -47,6 +45,7 @@ type Client struct {
|
||||
// Services used for communicating with the API
|
||||
Account AccountService
|
||||
Actions ActionsService
|
||||
CDNs CDNService
|
||||
Domains DomainsService
|
||||
Droplets DropletsService
|
||||
DropletActions DropletActionsService
|
||||
@ -64,6 +63,10 @@ type Client struct {
|
||||
LoadBalancers LoadBalancersService
|
||||
Certificates CertificatesService
|
||||
Firewalls FirewallsService
|
||||
Projects ProjectsService
|
||||
Kubernetes KubernetesService
|
||||
Databases DatabasesService
|
||||
VPCs VPCsService
|
||||
|
||||
// Optional function called after every successful request made to the DO APIs
|
||||
onRequestCompleted RequestCompletionCallback
|
||||
@ -158,23 +161,28 @@ func NewClient(httpClient *http.Client) *Client {
|
||||
c := &Client{client: httpClient, BaseURL: baseURL, UserAgent: userAgent}
|
||||
c.Account = &AccountServiceOp{client: c}
|
||||
c.Actions = &ActionsServiceOp{client: c}
|
||||
c.CDNs = &CDNServiceOp{client: c}
|
||||
c.Certificates = &CertificatesServiceOp{client: c}
|
||||
c.Domains = &DomainsServiceOp{client: c}
|
||||
c.Droplets = &DropletsServiceOp{client: c}
|
||||
c.DropletActions = &DropletActionsServiceOp{client: c}
|
||||
c.Firewalls = &FirewallsServiceOp{client: c}
|
||||
c.FloatingIPs = &FloatingIPsServiceOp{client: c}
|
||||
c.FloatingIPActions = &FloatingIPActionsServiceOp{client: c}
|
||||
c.Images = &ImagesServiceOp{client: c}
|
||||
c.ImageActions = &ImageActionsServiceOp{client: c}
|
||||
c.Keys = &KeysServiceOp{client: c}
|
||||
c.LoadBalancers = &LoadBalancersServiceOp{client: c}
|
||||
c.Projects = &ProjectsServiceOp{client: c}
|
||||
c.Regions = &RegionsServiceOp{client: c}
|
||||
c.Snapshots = &SnapshotsServiceOp{client: c}
|
||||
c.Sizes = &SizesServiceOp{client: c}
|
||||
c.Snapshots = &SnapshotsServiceOp{client: c}
|
||||
c.Storage = &StorageServiceOp{client: c}
|
||||
c.StorageActions = &StorageActionsServiceOp{client: c}
|
||||
c.Tags = &TagsServiceOp{client: c}
|
||||
c.LoadBalancers = &LoadBalancersServiceOp{client: c}
|
||||
c.Certificates = &CertificatesServiceOp{client: c}
|
||||
c.Firewalls = &FirewallsServiceOp{client: c}
|
||||
c.Kubernetes = &KubernetesServiceOp{client: c}
|
||||
c.Databases = &DatabasesServiceOp{client: c}
|
||||
c.VPCs = &VPCsServiceOp{client: c}
|
||||
|
||||
return c
|
||||
}
|
||||
@ -210,7 +218,7 @@ func SetBaseURL(bu string) ClientOpt {
|
||||
// SetUserAgent is a client option for setting the user agent.
|
||||
func SetUserAgent(ua string) ClientOpt {
|
||||
return func(c *Client) error {
|
||||
c.UserAgent = fmt.Sprintf("%s+%s", ua, c.UserAgent)
|
||||
c.UserAgent = fmt.Sprintf("%s %s", ua, c.UserAgent)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -258,25 +266,6 @@ func newResponse(r *http.Response) *Response {
|
||||
return &response
|
||||
}
|
||||
|
||||
func (r *Response) links() (map[string]headerLink.Link, error) {
|
||||
if linkText, ok := r.Response.Header["Link"]; ok {
|
||||
links, err := headerLink.Parse(linkText[0])
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
linkMap := map[string]headerLink.Link{}
|
||||
for _, link := range links {
|
||||
linkMap[link.Rel] = link
|
||||
}
|
||||
|
||||
return linkMap, nil
|
||||
}
|
||||
|
||||
return map[string]headerLink.Link{}, nil
|
||||
}
|
||||
|
||||
// populateRate parses the rate related headers and populates the response Rate.
|
||||
func (r *Response) populateRate() {
|
||||
if limit := r.Header.Get(headerRateLimit); limit != "" {
|
||||
@ -296,7 +285,7 @@ func (r *Response) populateRate() {
|
||||
// pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface,
|
||||
// the raw response will be written to v, without attempting to decode it.
|
||||
func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error) {
|
||||
resp, err := context.DoRequestWithClient(ctx, c.client, req)
|
||||
resp, err := DoRequestWithClient(ctx, c.client, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -334,6 +323,21 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
|
||||
|
||||
return response, err
|
||||
}
|
||||
|
||||
// DoRequest submits an HTTP request.
|
||||
func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
|
||||
return DoRequestWithClient(ctx, http.DefaultClient, req)
|
||||
}
|
||||
|
||||
// DoRequestWithClient submits an HTTP request using the specified client.
|
||||
func DoRequestWithClient(
|
||||
ctx context.Context,
|
||||
client *http.Client,
|
||||
req *http.Request) (*http.Response, error) {
|
||||
req = req.WithContext(ctx)
|
||||
return client.Do(req)
|
||||
}
|
||||
|
||||
func (r *ErrorResponse) Error() string {
|
||||
if r.RequestID != "" {
|
||||
return fmt.Sprintf("%v %v: %d (request %q) %v",
|
||||
@ -356,7 +360,7 @@ func CheckResponse(r *http.Response) error {
|
||||
if err == nil && len(data) > 0 {
|
||||
err := json.Unmarshal(data, errorResponse)
|
||||
if err != nil {
|
||||
return err
|
||||
errorResponse.Message = string(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
3
vendor/github.com/digitalocean/godo/image_actions.go
generated
vendored
3
vendor/github.com/digitalocean/godo/image_actions.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// ImageActionsService is an interface for interfacing with the image actions
|
||||
|
66
vendor/github.com/digitalocean/godo/images.go
generated
vendored
66
vendor/github.com/digitalocean/godo/images.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const imageBasePath = "v2/images"
|
||||
@ -17,8 +16,10 @@ type ImagesService interface {
|
||||
ListDistribution(ctx context.Context, opt *ListOptions) ([]Image, *Response, error)
|
||||
ListApplication(ctx context.Context, opt *ListOptions) ([]Image, *Response, error)
|
||||
ListUser(ctx context.Context, opt *ListOptions) ([]Image, *Response, error)
|
||||
ListByTag(ctx context.Context, tag string, opt *ListOptions) ([]Image, *Response, error)
|
||||
GetByID(context.Context, int) (*Image, *Response, error)
|
||||
GetBySlug(context.Context, string) (*Image, *Response, error)
|
||||
Create(context.Context, *CustomImageCreateRequest) (*Image, *Response, error)
|
||||
Update(context.Context, int, *ImageUpdateRequest) (*Image, *Response, error)
|
||||
Delete(context.Context, int) (*Response, error)
|
||||
}
|
||||
@ -33,15 +34,20 @@ var _ ImagesService = &ImagesServiceOp{}
|
||||
|
||||
// Image represents a DigitalOcean Image
|
||||
type Image struct {
|
||||
ID int `json:"id,float64,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Distribution string `json:"distribution,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
Public bool `json:"public,omitempty"`
|
||||
Regions []string `json:"regions,omitempty"`
|
||||
MinDiskSize int `json:"min_disk_size,omitempty"`
|
||||
Created string `json:"created_at,omitempty"`
|
||||
ID int `json:"id,float64,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Distribution string `json:"distribution,omitempty"`
|
||||
Slug string `json:"slug,omitempty"`
|
||||
Public bool `json:"public,omitempty"`
|
||||
Regions []string `json:"regions,omitempty"`
|
||||
MinDiskSize int `json:"min_disk_size,omitempty"`
|
||||
SizeGigaBytes float64 `json:"size_gigabytes,omitempty"`
|
||||
Created string `json:"created_at,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
ErrorMessage string `json:"error_message,omitempty"`
|
||||
}
|
||||
|
||||
// ImageUpdateRequest represents a request to update an image.
|
||||
@ -49,6 +55,16 @@ type ImageUpdateRequest struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// CustomImageCreateRequest represents a request to create a custom image.
|
||||
type CustomImageCreateRequest struct {
|
||||
Name string `json:"name"`
|
||||
Url string `json:"url"`
|
||||
Region string `json:"region"`
|
||||
Distribution string `json:"distribution,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
type imageRoot struct {
|
||||
Image *Image
|
||||
}
|
||||
@ -61,6 +77,7 @@ type imagesRoot struct {
|
||||
type listImageOptions struct {
|
||||
Private bool `url:"private,omitempty"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Tag string `url:"tag_name,omitempty"`
|
||||
}
|
||||
|
||||
func (i Image) String() string {
|
||||
@ -90,6 +107,12 @@ func (s *ImagesServiceOp) ListUser(ctx context.Context, opt *ListOptions) ([]Ima
|
||||
return s.list(ctx, opt, &listOpt)
|
||||
}
|
||||
|
||||
// ListByTag lists all images with a specific tag applied.
|
||||
func (s *ImagesServiceOp) ListByTag(ctx context.Context, tag string, opt *ListOptions) ([]Image, *Response, error) {
|
||||
listOpt := listImageOptions{Tag: tag}
|
||||
return s.list(ctx, opt, &listOpt)
|
||||
}
|
||||
|
||||
// GetByID retrieves an image by id.
|
||||
func (s *ImagesServiceOp) GetByID(ctx context.Context, imageID int) (*Image, *Response, error) {
|
||||
if imageID < 1 {
|
||||
@ -108,6 +131,25 @@ func (s *ImagesServiceOp) GetBySlug(ctx context.Context, slug string) (*Image, *
|
||||
return s.get(ctx, interface{}(slug))
|
||||
}
|
||||
|
||||
func (s *ImagesServiceOp) Create(ctx context.Context, createRequest *CustomImageCreateRequest) (*Image, *Response, error) {
|
||||
if createRequest == nil {
|
||||
return nil, nil, NewArgError("createRequest", "cannot be nil")
|
||||
}
|
||||
|
||||
req, err := s.client.NewRequest(ctx, http.MethodPost, imageBasePath, createRequest)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(imageRoot)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Image, resp, err
|
||||
}
|
||||
|
||||
// Update an image name.
|
||||
func (s *ImagesServiceOp) Update(ctx context.Context, imageID int, updateRequest *ImageUpdateRequest) (*Image, *Response, error) {
|
||||
if imageID < 1 {
|
||||
@ -119,7 +161,7 @@ func (s *ImagesServiceOp) Update(ctx context.Context, imageID int, updateRequest
|
||||
}
|
||||
|
||||
path := fmt.Sprintf("%s/%d", imageBasePath, imageID)
|
||||
req, err := s.client.NewRequest(ctx, "PUT", path, updateRequest)
|
||||
req, err := s.client.NewRequest(ctx, http.MethodPut, path, updateRequest)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
3
vendor/github.com/digitalocean/godo/keys.go
generated
vendored
3
vendor/github.com/digitalocean/godo/keys.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const keysBasePath = "v2/account/keys"
|
||||
|
612
vendor/github.com/digitalocean/godo/kubernetes.go
generated
vendored
Normal file
612
vendor/github.com/digitalocean/godo/kubernetes.go
generated
vendored
Normal file
@ -0,0 +1,612 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
kubernetesBasePath = "/v2/kubernetes"
|
||||
kubernetesClustersPath = kubernetesBasePath + "/clusters"
|
||||
kubernetesOptionsPath = kubernetesBasePath + "/options"
|
||||
)
|
||||
|
||||
// KubernetesService is an interface for interfacing with the Kubernetes endpoints
|
||||
// of the DigitalOcean API.
|
||||
// See: https://developers.digitalocean.com/documentation/v2#kubernetes
|
||||
type KubernetesService interface {
|
||||
Create(context.Context, *KubernetesClusterCreateRequest) (*KubernetesCluster, *Response, error)
|
||||
Get(context.Context, string) (*KubernetesCluster, *Response, error)
|
||||
GetUpgrades(context.Context, string) ([]*KubernetesVersion, *Response, error)
|
||||
GetKubeConfig(context.Context, string) (*KubernetesClusterConfig, *Response, error)
|
||||
List(context.Context, *ListOptions) ([]*KubernetesCluster, *Response, error)
|
||||
Update(context.Context, string, *KubernetesClusterUpdateRequest) (*KubernetesCluster, *Response, error)
|
||||
Upgrade(context.Context, string, *KubernetesClusterUpgradeRequest) (*Response, error)
|
||||
Delete(context.Context, string) (*Response, error)
|
||||
|
||||
CreateNodePool(ctx context.Context, clusterID string, req *KubernetesNodePoolCreateRequest) (*KubernetesNodePool, *Response, error)
|
||||
GetNodePool(ctx context.Context, clusterID, poolID string) (*KubernetesNodePool, *Response, error)
|
||||
ListNodePools(ctx context.Context, clusterID string, opts *ListOptions) ([]*KubernetesNodePool, *Response, error)
|
||||
UpdateNodePool(ctx context.Context, clusterID, poolID string, req *KubernetesNodePoolUpdateRequest) (*KubernetesNodePool, *Response, error)
|
||||
// RecycleNodePoolNodes is DEPRECATED please use DeleteNode
|
||||
// The method will be removed in godo 2.0.
|
||||
RecycleNodePoolNodes(ctx context.Context, clusterID, poolID string, req *KubernetesNodePoolRecycleNodesRequest) (*Response, error)
|
||||
DeleteNodePool(ctx context.Context, clusterID, poolID string) (*Response, error)
|
||||
DeleteNode(ctx context.Context, clusterID, poolID, nodeID string, req *KubernetesNodeDeleteRequest) (*Response, error)
|
||||
|
||||
GetOptions(context.Context) (*KubernetesOptions, *Response, error)
|
||||
}
|
||||
|
||||
var _ KubernetesService = &KubernetesServiceOp{}
|
||||
|
||||
// KubernetesServiceOp handles communication with Kubernetes methods of the DigitalOcean API.
|
||||
type KubernetesServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// KubernetesClusterCreateRequest represents a request to create a Kubernetes cluster.
|
||||
type KubernetesClusterCreateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
RegionSlug string `json:"region,omitempty"`
|
||||
VersionSlug string `json:"version,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
|
||||
NodePools []*KubernetesNodePoolCreateRequest `json:"node_pools,omitempty"`
|
||||
|
||||
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"`
|
||||
AutoUpgrade bool `json:"auto_upgrade"`
|
||||
}
|
||||
|
||||
// KubernetesClusterUpdateRequest represents a request to update a Kubernetes cluster.
|
||||
type KubernetesClusterUpdateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"`
|
||||
AutoUpgrade bool `json:"auto_upgrade"`
|
||||
}
|
||||
|
||||
// KubernetesClusterUpgradeRequest represents a request to upgrade a Kubernetes cluster.
|
||||
type KubernetesClusterUpgradeRequest struct {
|
||||
VersionSlug string `json:"version,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodePoolCreateRequest represents a request to create a node pool for a
|
||||
// Kubernetes cluster.
|
||||
type KubernetesNodePoolCreateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Size string `json:"size,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodePoolUpdateRequest represents a request to update a node pool in a
|
||||
// Kubernetes cluster.
|
||||
type KubernetesNodePoolUpdateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodePoolRecycleNodesRequest is DEPRECATED please use DeleteNode
|
||||
// The type will be removed in godo 2.0.
|
||||
type KubernetesNodePoolRecycleNodesRequest struct {
|
||||
Nodes []string `json:"nodes,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodeDeleteRequest is a request to delete a specific node in a node pool.
|
||||
type KubernetesNodeDeleteRequest struct {
|
||||
// Replace will cause a new node to be created to replace the deleted node.
|
||||
Replace bool `json:"replace,omitempty"`
|
||||
|
||||
// SkipDrain skips draining the node before deleting it.
|
||||
SkipDrain bool `json:"skip_drain,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesCluster represents a Kubernetes cluster.
|
||||
type KubernetesCluster struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
RegionSlug string `json:"region,omitempty"`
|
||||
VersionSlug string `json:"version,omitempty"`
|
||||
ClusterSubnet string `json:"cluster_subnet,omitempty"`
|
||||
ServiceSubnet string `json:"service_subnet,omitempty"`
|
||||
IPv4 string `json:"ipv4,omitempty"`
|
||||
Endpoint string `json:"endpoint,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
|
||||
NodePools []*KubernetesNodePool `json:"node_pools,omitempty"`
|
||||
|
||||
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"`
|
||||
AutoUpgrade bool `json:"auto_upgrade,omitempty"`
|
||||
|
||||
Status *KubernetesClusterStatus `json:"status,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesMaintenancePolicy is a configuration to set the maintenance window
|
||||
// of a cluster
|
||||
type KubernetesMaintenancePolicy struct {
|
||||
StartTime string `json:"start_time"`
|
||||
Duration string `json:"duration"`
|
||||
Day KubernetesMaintenancePolicyDay `json:"day"`
|
||||
}
|
||||
|
||||
// KubernetesMaintenancePolicyDay represents the possible days of a maintenance
|
||||
// window
|
||||
type KubernetesMaintenancePolicyDay int
|
||||
|
||||
const (
|
||||
KubernetesMaintenanceDayAny KubernetesMaintenancePolicyDay = iota
|
||||
KubernetesMaintenanceDayMonday
|
||||
KubernetesMaintenanceDayTuesday
|
||||
KubernetesMaintenanceDayWednesday
|
||||
KubernetesMaintenanceDayThursday
|
||||
KubernetesMaintenanceDayFriday
|
||||
KubernetesMaintenanceDaySaturday
|
||||
KubernetesMaintenanceDaySunday
|
||||
)
|
||||
|
||||
var (
|
||||
days = [...]string{
|
||||
"any",
|
||||
"monday",
|
||||
"tuesday",
|
||||
"wednesday",
|
||||
"thursday",
|
||||
"friday",
|
||||
"saturday",
|
||||
"sunday",
|
||||
}
|
||||
|
||||
toDay = map[string]KubernetesMaintenancePolicyDay{
|
||||
"any": KubernetesMaintenanceDayAny,
|
||||
"monday": KubernetesMaintenanceDayMonday,
|
||||
"tuesday": KubernetesMaintenanceDayTuesday,
|
||||
"wednesday": KubernetesMaintenanceDayWednesday,
|
||||
"thursday": KubernetesMaintenanceDayThursday,
|
||||
"friday": KubernetesMaintenanceDayFriday,
|
||||
"saturday": KubernetesMaintenanceDaySaturday,
|
||||
"sunday": KubernetesMaintenanceDaySunday,
|
||||
}
|
||||
)
|
||||
|
||||
// KubernetesMaintenanceToDay returns the appropriate KubernetesMaintenancePolicyDay for the given string.
|
||||
func KubernetesMaintenanceToDay(day string) (KubernetesMaintenancePolicyDay, error) {
|
||||
d, ok := toDay[day]
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unknown day: %q", day)
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (k KubernetesMaintenancePolicyDay) String() string {
|
||||
if KubernetesMaintenanceDayAny <= k && k <= KubernetesMaintenanceDaySunday {
|
||||
return days[k]
|
||||
}
|
||||
return fmt.Sprintf("%d !Weekday", k)
|
||||
|
||||
}
|
||||
|
||||
func (k *KubernetesMaintenancePolicyDay) UnmarshalJSON(data []byte) error {
|
||||
var val string
|
||||
if err := json.Unmarshal(data, &val); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
parsed, err := KubernetesMaintenanceToDay(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*k = parsed
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k KubernetesMaintenancePolicyDay) MarshalJSON() ([]byte, error) {
|
||||
if KubernetesMaintenanceDayAny <= k && k <= KubernetesMaintenanceDaySunday {
|
||||
return json.Marshal(days[k])
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("invalid day: %d", k)
|
||||
}
|
||||
|
||||
// Possible states for a cluster.
|
||||
const (
|
||||
KubernetesClusterStatusProvisioning = KubernetesClusterStatusState("provisioning")
|
||||
KubernetesClusterStatusRunning = KubernetesClusterStatusState("running")
|
||||
KubernetesClusterStatusDegraded = KubernetesClusterStatusState("degraded")
|
||||
KubernetesClusterStatusError = KubernetesClusterStatusState("error")
|
||||
KubernetesClusterStatusDeleted = KubernetesClusterStatusState("deleted")
|
||||
KubernetesClusterStatusUpgrading = KubernetesClusterStatusState("upgrading")
|
||||
KubernetesClusterStatusInvalid = KubernetesClusterStatusState("invalid")
|
||||
)
|
||||
|
||||
// KubernetesClusterStatusState represents states for a cluster.
|
||||
type KubernetesClusterStatusState string
|
||||
|
||||
var _ encoding.TextUnmarshaler = (*KubernetesClusterStatusState)(nil)
|
||||
|
||||
// UnmarshalText unmarshals the state.
|
||||
func (s *KubernetesClusterStatusState) UnmarshalText(text []byte) error {
|
||||
switch KubernetesClusterStatusState(strings.ToLower(string(text))) {
|
||||
case KubernetesClusterStatusProvisioning:
|
||||
*s = KubernetesClusterStatusProvisioning
|
||||
case KubernetesClusterStatusRunning:
|
||||
*s = KubernetesClusterStatusRunning
|
||||
case KubernetesClusterStatusDegraded:
|
||||
*s = KubernetesClusterStatusDegraded
|
||||
case KubernetesClusterStatusError:
|
||||
*s = KubernetesClusterStatusError
|
||||
case KubernetesClusterStatusDeleted:
|
||||
*s = KubernetesClusterStatusDeleted
|
||||
case KubernetesClusterStatusUpgrading:
|
||||
*s = KubernetesClusterStatusUpgrading
|
||||
case "", KubernetesClusterStatusInvalid:
|
||||
*s = KubernetesClusterStatusInvalid
|
||||
default:
|
||||
return fmt.Errorf("unknown cluster state %q", string(text))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// KubernetesClusterStatus describes the status of a cluster.
|
||||
type KubernetesClusterStatus struct {
|
||||
State KubernetesClusterStatusState `json:"state,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodePool represents a node pool in a Kubernetes cluster.
|
||||
type KubernetesNodePool struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Size string `json:"size,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
|
||||
Nodes []*KubernetesNode `json:"nodes,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNode represents a Node in a node pool in a Kubernetes cluster.
|
||||
type KubernetesNode struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Status *KubernetesNodeStatus `json:"status,omitempty"`
|
||||
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodeStatus represents the status of a particular Node in a Kubernetes cluster.
|
||||
type KubernetesNodeStatus struct {
|
||||
State string `json:"state,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesOptions represents options available for creating Kubernetes clusters.
|
||||
type KubernetesOptions struct {
|
||||
Versions []*KubernetesVersion `json:"versions,omitempty"`
|
||||
Regions []*KubernetesRegion `json:"regions,omitempty"`
|
||||
Sizes []*KubernetesNodeSize `json:"sizes,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesVersion is a DigitalOcean Kubernetes release.
|
||||
type KubernetesVersion struct {
|
||||
Slug string `json:"slug,omitempty"`
|
||||
KubernetesVersion string `json:"kubernetes_version,omitempty"`
|
||||
}
|
||||
|
||||
// KubernetesNodeSize is a node sizes supported for Kubernetes clusters.
|
||||
type KubernetesNodeSize struct {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
|
||||
// KubernetesRegion is a region usable by Kubernetes clusters.
|
||||
type KubernetesRegion struct {
|
||||
Name string `json:"name"`
|
||||
Slug string `json:"slug"`
|
||||
}
|
||||
|
||||
type kubernetesClustersRoot struct {
|
||||
Clusters []*KubernetesCluster `json:"kubernetes_clusters,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
type kubernetesClusterRoot struct {
|
||||
Cluster *KubernetesCluster `json:"kubernetes_cluster,omitempty"`
|
||||
}
|
||||
|
||||
type kubernetesNodePoolRoot struct {
|
||||
NodePool *KubernetesNodePool `json:"node_pool,omitempty"`
|
||||
}
|
||||
|
||||
type kubernetesNodePoolsRoot struct {
|
||||
NodePools []*KubernetesNodePool `json:"node_pools,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
type kubernetesUpgradesRoot struct {
|
||||
AvailableUpgradeVersions []*KubernetesVersion `json:"available_upgrade_versions,omitempty"`
|
||||
}
|
||||
|
||||
// Get retrieves the details of a Kubernetes cluster.
|
||||
func (svc *KubernetesServiceOp) Get(ctx context.Context, clusterID string) (*KubernetesCluster, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesClusterRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Cluster, resp, nil
|
||||
}
|
||||
|
||||
// GetUpgrades retrieves versions a Kubernetes cluster can be upgraded to. An
|
||||
// upgrade can be requested using `Upgrade`.
|
||||
func (svc *KubernetesServiceOp) GetUpgrades(ctx context.Context, clusterID string) ([]*KubernetesVersion, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/upgrades", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesUpgradesRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return root.AvailableUpgradeVersions, resp, nil
|
||||
}
|
||||
|
||||
// Create creates a Kubernetes cluster.
|
||||
func (svc *KubernetesServiceOp) Create(ctx context.Context, create *KubernetesClusterCreateRequest) (*KubernetesCluster, *Response, error) {
|
||||
path := kubernetesClustersPath
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, create)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesClusterRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Cluster, resp, nil
|
||||
}
|
||||
|
||||
// Delete deletes a Kubernetes cluster. There is no way to recover a cluster
|
||||
// once it has been destroyed.
|
||||
func (svc *KubernetesServiceOp) Delete(ctx context.Context, clusterID string) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// List returns a list of the Kubernetes clusters visible with the caller's API token.
|
||||
func (svc *KubernetesServiceOp) List(ctx context.Context, opts *ListOptions) ([]*KubernetesCluster, *Response, error) {
|
||||
path := kubernetesClustersPath
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesClustersRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Clusters, resp, nil
|
||||
}
|
||||
|
||||
// KubernetesClusterConfig is the content of a Kubernetes config file, which can be
|
||||
// used to interact with your Kubernetes cluster using `kubectl`.
|
||||
// See: https://kubernetes.io/docs/tasks/tools/install-kubectl/
|
||||
type KubernetesClusterConfig struct {
|
||||
KubeconfigYAML []byte
|
||||
}
|
||||
|
||||
// GetKubeConfig returns a Kubernetes config file for the specified cluster.
|
||||
func (svc *KubernetesServiceOp) GetKubeConfig(ctx context.Context, clusterID string) (*KubernetesClusterConfig, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/kubeconfig", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
configBytes := bytes.NewBuffer(nil)
|
||||
resp, err := svc.client.Do(ctx, req, configBytes)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
res := &KubernetesClusterConfig{
|
||||
KubeconfigYAML: configBytes.Bytes(),
|
||||
}
|
||||
return res, resp, nil
|
||||
}
|
||||
|
||||
// Update updates a Kubernetes cluster's properties.
|
||||
func (svc *KubernetesServiceOp) Update(ctx context.Context, clusterID string, update *KubernetesClusterUpdateRequest) (*KubernetesCluster, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, update)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesClusterRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Cluster, resp, nil
|
||||
}
|
||||
|
||||
// Upgrade upgrades a Kubernetes cluster to a new version. Valid upgrade
|
||||
// versions for a given cluster can be retrieved with `GetUpgrades`.
|
||||
func (svc *KubernetesServiceOp) Upgrade(ctx context.Context, clusterID string, upgrade *KubernetesClusterUpgradeRequest) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/upgrade", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, upgrade)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return svc.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// CreateNodePool creates a new node pool in an existing Kubernetes cluster.
|
||||
func (svc *KubernetesServiceOp) CreateNodePool(ctx context.Context, clusterID string, create *KubernetesNodePoolCreateRequest) (*KubernetesNodePool, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools", kubernetesClustersPath, clusterID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, create)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesNodePoolRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.NodePool, resp, nil
|
||||
}
|
||||
|
||||
// GetNodePool retrieves an existing node pool in a Kubernetes cluster.
|
||||
func (svc *KubernetesServiceOp) GetNodePool(ctx context.Context, clusterID, poolID string) (*KubernetesNodePool, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools/%s", kubernetesClustersPath, clusterID, poolID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesNodePoolRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.NodePool, resp, nil
|
||||
}
|
||||
|
||||
// ListNodePools lists all the node pools found in a Kubernetes cluster.
|
||||
func (svc *KubernetesServiceOp) ListNodePools(ctx context.Context, clusterID string, opts *ListOptions) ([]*KubernetesNodePool, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools", kubernetesClustersPath, clusterID)
|
||||
path, err := addOptions(path, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesNodePoolsRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.NodePools, resp, nil
|
||||
}
|
||||
|
||||
// UpdateNodePool updates the details of an existing node pool.
|
||||
func (svc *KubernetesServiceOp) UpdateNodePool(ctx context.Context, clusterID, poolID string, update *KubernetesNodePoolUpdateRequest) (*KubernetesNodePool, *Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools/%s", kubernetesClustersPath, clusterID, poolID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, update)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesNodePoolRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.NodePool, resp, nil
|
||||
}
|
||||
|
||||
// RecycleNodePoolNodes is DEPRECATED please use DeleteNode
|
||||
// The method will be removed in godo 2.0.
|
||||
func (svc *KubernetesServiceOp) RecycleNodePoolNodes(ctx context.Context, clusterID, poolID string, recycle *KubernetesNodePoolRecycleNodesRequest) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools/%s/recycle", kubernetesClustersPath, clusterID, poolID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodPost, path, recycle)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// DeleteNodePool deletes a node pool, and subsequently all the nodes in that pool.
|
||||
func (svc *KubernetesServiceOp) DeleteNodePool(ctx context.Context, clusterID, poolID string) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools/%s", kubernetesClustersPath, clusterID, poolID)
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// DeleteNode deletes a specific node in a node pool.
|
||||
func (svc *KubernetesServiceOp) DeleteNode(ctx context.Context, clusterID, poolID, nodeID string, deleteReq *KubernetesNodeDeleteRequest) (*Response, error) {
|
||||
path := fmt.Sprintf("%s/%s/node_pools/%s/nodes/%s", kubernetesClustersPath, clusterID, poolID, nodeID)
|
||||
if deleteReq != nil {
|
||||
v := make(url.Values)
|
||||
if deleteReq.SkipDrain {
|
||||
v.Set("skip_drain", "1")
|
||||
}
|
||||
if deleteReq.Replace {
|
||||
v.Set("replace", "1")
|
||||
}
|
||||
if query := v.Encode(); query != "" {
|
||||
path = path + "?" + query
|
||||
}
|
||||
}
|
||||
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := svc.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
type kubernetesOptionsRoot struct {
|
||||
Options *KubernetesOptions `json:"options,omitempty"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
// GetOptions returns options about the Kubernetes service, such as the versions available for
|
||||
// cluster creation.
|
||||
func (svc *KubernetesServiceOp) GetOptions(ctx context.Context) (*KubernetesOptions, *Response, error) {
|
||||
path := kubernetesOptionsPath
|
||||
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
root := new(kubernetesOptionsRoot)
|
||||
resp, err := svc.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
return root.Options, resp, nil
|
||||
}
|
3
vendor/github.com/digitalocean/godo/links.go
generated
vendored
3
vendor/github.com/digitalocean/godo/links.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// Links manages links that are returned along with a List
|
||||
|
43
vendor/github.com/digitalocean/godo/load_balancers.go
generated
vendored
43
vendor/github.com/digitalocean/godo/load_balancers.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const loadBalancersBasePath = "/v2/load_balancers"
|
||||
@ -27,6 +26,7 @@ type LoadBalancersService interface {
|
||||
}
|
||||
|
||||
// LoadBalancer represents a DigitalOcean load balancer configuration.
|
||||
// Tags can only be provided upon the creation of a Load Balancer.
|
||||
type LoadBalancer struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
@ -40,7 +40,10 @@ type LoadBalancer struct {
|
||||
Region *Region `json:"region,omitempty"`
|
||||
DropletIDs []int `json:"droplet_ids,omitempty"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
RedirectHttpToHttps bool `json:"redirect_http_to_https,omitempty"`
|
||||
EnableProxyProtocol bool `json:"enable_proxy_protocol,omitempty"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// String creates a human-readable description of a LoadBalancer.
|
||||
@ -48,6 +51,39 @@ func (l LoadBalancer) String() string {
|
||||
return Stringify(l)
|
||||
}
|
||||
|
||||
func (l LoadBalancer) URN() string {
|
||||
return ToURN("LoadBalancer", l.ID)
|
||||
}
|
||||
|
||||
// AsRequest creates a LoadBalancerRequest that can be submitted to Update with the current values of the LoadBalancer.
|
||||
// Modifying the returned LoadBalancerRequest will not modify the original LoadBalancer.
|
||||
func (l LoadBalancer) AsRequest() *LoadBalancerRequest {
|
||||
r := LoadBalancerRequest{
|
||||
Name: l.Name,
|
||||
Algorithm: l.Algorithm,
|
||||
ForwardingRules: append([]ForwardingRule(nil), l.ForwardingRules...),
|
||||
DropletIDs: append([]int(nil), l.DropletIDs...),
|
||||
Tag: l.Tag,
|
||||
RedirectHttpToHttps: l.RedirectHttpToHttps,
|
||||
EnableProxyProtocol: l.EnableProxyProtocol,
|
||||
HealthCheck: l.HealthCheck,
|
||||
VPCUUID: l.VPCUUID,
|
||||
}
|
||||
|
||||
if l.HealthCheck != nil {
|
||||
r.HealthCheck = &HealthCheck{}
|
||||
*r.HealthCheck = *l.HealthCheck
|
||||
}
|
||||
if l.StickySessions != nil {
|
||||
r.StickySessions = &StickySessions{}
|
||||
*r.StickySessions = *l.StickySessions
|
||||
}
|
||||
if l.Region != nil {
|
||||
r.Region = l.Region.Slug
|
||||
}
|
||||
return &r
|
||||
}
|
||||
|
||||
// ForwardingRule represents load balancer forwarding rules.
|
||||
type ForwardingRule struct {
|
||||
EntryProtocol string `json:"entry_protocol,omitempty"`
|
||||
@ -101,7 +137,10 @@ type LoadBalancerRequest struct {
|
||||
StickySessions *StickySessions `json:"sticky_sessions,omitempty"`
|
||||
DropletIDs []int `json:"droplet_ids,omitempty"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
RedirectHttpToHttps bool `json:"redirect_http_to_https,omitempty"`
|
||||
EnableProxyProtocol bool `json:"enable_proxy_protocol,omitempty"`
|
||||
VPCUUID string `json:"vpc_uuid,omitempty"`
|
||||
}
|
||||
|
||||
// String creates a human-readable description of a LoadBalancerRequest.
|
||||
|
302
vendor/github.com/digitalocean/godo/projects.go
generated
vendored
Normal file
302
vendor/github.com/digitalocean/godo/projects.go
generated
vendored
Normal file
@ -0,0 +1,302 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultProject is the ID you should use if you are working with your
|
||||
// default project.
|
||||
DefaultProject = "default"
|
||||
|
||||
projectsBasePath = "/v2/projects"
|
||||
)
|
||||
|
||||
// ProjectsService is an interface for creating and managing Projects with the DigitalOcean API.
|
||||
// See: https://developers.digitalocean.com/documentation/v2/#projects
|
||||
type ProjectsService interface {
|
||||
List(context.Context, *ListOptions) ([]Project, *Response, error)
|
||||
GetDefault(context.Context) (*Project, *Response, error)
|
||||
Get(context.Context, string) (*Project, *Response, error)
|
||||
Create(context.Context, *CreateProjectRequest) (*Project, *Response, error)
|
||||
Update(context.Context, string, *UpdateProjectRequest) (*Project, *Response, error)
|
||||
Delete(context.Context, string) (*Response, error)
|
||||
|
||||
ListResources(context.Context, string, *ListOptions) ([]ProjectResource, *Response, error)
|
||||
AssignResources(context.Context, string, ...interface{}) ([]ProjectResource, *Response, error)
|
||||
}
|
||||
|
||||
// ProjectsServiceOp handles communication with Projects methods of the DigitalOcean API.
|
||||
type ProjectsServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// Project represents a DigitalOcean Project configuration.
|
||||
type Project struct {
|
||||
ID string `json:"id"`
|
||||
OwnerUUID string `json:"owner_uuid"`
|
||||
OwnerID uint64 `json:"owner_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Purpose string `json:"purpose"`
|
||||
Environment string `json:"environment"`
|
||||
IsDefault bool `json:"is_default"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
// String creates a human-readable description of a Project.
|
||||
func (p Project) String() string {
|
||||
return Stringify(p)
|
||||
}
|
||||
|
||||
// CreateProjectRequest represents the request to create a new project.
|
||||
type CreateProjectRequest struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Purpose string `json:"purpose"`
|
||||
Environment string `json:"environment"`
|
||||
}
|
||||
|
||||
// UpdateProjectRequest represents the request to update project information.
|
||||
// This type expects certain attribute types, but is built this way to allow
|
||||
// nil values as well. See `updateProjectRequest` for the "real" types.
|
||||
type UpdateProjectRequest struct {
|
||||
Name interface{}
|
||||
Description interface{}
|
||||
Purpose interface{}
|
||||
Environment interface{}
|
||||
IsDefault interface{}
|
||||
}
|
||||
|
||||
type updateProjectRequest struct {
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
Purpose *string `json:"purpose"`
|
||||
Environment *string `json:"environment"`
|
||||
IsDefault *bool `json:"is_default"`
|
||||
}
|
||||
|
||||
// MarshalJSON takes an UpdateRequest and converts it to the "typed" request
|
||||
// which is sent to the projects API. This is a PATCH request, which allows
|
||||
// partial attributes, so `null` values are OK.
|
||||
func (upr *UpdateProjectRequest) MarshalJSON() ([]byte, error) {
|
||||
d := &updateProjectRequest{}
|
||||
if str, ok := upr.Name.(string); ok {
|
||||
d.Name = &str
|
||||
}
|
||||
if str, ok := upr.Description.(string); ok {
|
||||
d.Description = &str
|
||||
}
|
||||
if str, ok := upr.Purpose.(string); ok {
|
||||
d.Purpose = &str
|
||||
}
|
||||
if str, ok := upr.Environment.(string); ok {
|
||||
d.Environment = &str
|
||||
}
|
||||
if val, ok := upr.IsDefault.(bool); ok {
|
||||
d.IsDefault = &val
|
||||
}
|
||||
|
||||
return json.Marshal(d)
|
||||
}
|
||||
|
||||
type assignResourcesRequest struct {
|
||||
Resources []string `json:"resources"`
|
||||
}
|
||||
|
||||
// ProjectResource is the projects API's representation of a resource.
|
||||
type ProjectResource struct {
|
||||
URN string `json:"urn"`
|
||||
AssignedAt string `json:"assigned_at"`
|
||||
Links *ProjectResourceLinks `json:"links"`
|
||||
Status string `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// ProjetResourceLinks specify the link for more information about the resource.
|
||||
type ProjectResourceLinks struct {
|
||||
Self string `json:"self"`
|
||||
}
|
||||
|
||||
type projectsRoot struct {
|
||||
Projects []Project `json:"projects"`
|
||||
Links *Links `json:"links"`
|
||||
}
|
||||
|
||||
type projectRoot struct {
|
||||
Project *Project `json:"project"`
|
||||
}
|
||||
|
||||
type projectResourcesRoot struct {
|
||||
Resources []ProjectResource `json:"resources"`
|
||||
Links *Links `json:"links,omitempty"`
|
||||
}
|
||||
|
||||
var _ ProjectsService = &ProjectsServiceOp{}
|
||||
|
||||
// List Projects.
|
||||
func (p *ProjectsServiceOp) List(ctx context.Context, opts *ListOptions) ([]Project, *Response, error) {
|
||||
path, err := addOptions(projectsBasePath, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req, err := p.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectsRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if l := root.Links; l != nil {
|
||||
resp.Links = l
|
||||
}
|
||||
|
||||
return root.Projects, resp, err
|
||||
}
|
||||
|
||||
// GetDefault project.
|
||||
func (p *ProjectsServiceOp) GetDefault(ctx context.Context) (*Project, *Response, error) {
|
||||
return p.getHelper(ctx, "default")
|
||||
}
|
||||
|
||||
// Get retrieves a single project by its ID.
|
||||
func (p *ProjectsServiceOp) Get(ctx context.Context, projectID string) (*Project, *Response, error) {
|
||||
return p.getHelper(ctx, projectID)
|
||||
}
|
||||
|
||||
// Create a new project.
|
||||
func (p *ProjectsServiceOp) Create(ctx context.Context, cr *CreateProjectRequest) (*Project, *Response, error) {
|
||||
req, err := p.client.NewRequest(ctx, http.MethodPost, projectsBasePath, cr)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Project, resp, err
|
||||
}
|
||||
|
||||
// Update an existing project.
|
||||
func (p *ProjectsServiceOp) Update(ctx context.Context, projectID string, ur *UpdateProjectRequest) (*Project, *Response, error) {
|
||||
path := path.Join(projectsBasePath, projectID)
|
||||
req, err := p.client.NewRequest(ctx, http.MethodPatch, path, ur)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Project, resp, err
|
||||
}
|
||||
|
||||
// Delete an existing project. You cannot have any resources in a project
|
||||
// before deleting it. See the API documentation for more details.
|
||||
func (p *ProjectsServiceOp) Delete(ctx context.Context, projectID string) (*Response, error) {
|
||||
path := path.Join(projectsBasePath, projectID)
|
||||
req, err := p.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// ListResources lists all resources in a project.
|
||||
func (p *ProjectsServiceOp) ListResources(ctx context.Context, projectID string, opts *ListOptions) ([]ProjectResource, *Response, error) {
|
||||
basePath := path.Join(projectsBasePath, projectID, "resources")
|
||||
path, err := addOptions(basePath, opts)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
req, err := p.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectResourcesRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if l := root.Links; l != nil {
|
||||
resp.Links = l
|
||||
}
|
||||
|
||||
return root.Resources, resp, err
|
||||
}
|
||||
|
||||
// AssignResources assigns one or more resources to a project. AssignResources
|
||||
// accepts resources in two possible formats:
|
||||
|
||||
// 1. The resource type, like `&Droplet{ID: 1}` or `&FloatingIP{IP: "1.2.3.4"}`
|
||||
// 2. A valid DO URN as a string, like "do:droplet:1234"
|
||||
//
|
||||
// There is no unassign. To move a resource to another project, just assign
|
||||
// it to that other project.
|
||||
func (p *ProjectsServiceOp) AssignResources(ctx context.Context, projectID string, resources ...interface{}) ([]ProjectResource, *Response, error) {
|
||||
path := path.Join(projectsBasePath, projectID, "resources")
|
||||
|
||||
ar := &assignResourcesRequest{
|
||||
Resources: make([]string, len(resources)),
|
||||
}
|
||||
|
||||
for i, resource := range resources {
|
||||
switch resource := resource.(type) {
|
||||
case ResourceWithURN:
|
||||
ar.Resources[i] = resource.URN()
|
||||
case string:
|
||||
ar.Resources[i] = resource
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("%T must either be a string or have a valid URN method", resource)
|
||||
}
|
||||
}
|
||||
req, err := p.client.NewRequest(ctx, http.MethodPost, path, ar)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectResourcesRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if l := root.Links; l != nil {
|
||||
resp.Links = l
|
||||
}
|
||||
|
||||
return root.Resources, resp, err
|
||||
}
|
||||
|
||||
func (p *ProjectsServiceOp) getHelper(ctx context.Context, projectID string) (*Project, *Response, error) {
|
||||
path := path.Join(projectsBasePath, projectID)
|
||||
|
||||
req, err := p.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(projectRoot)
|
||||
resp, err := p.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Project, resp, err
|
||||
}
|
3
vendor/github.com/digitalocean/godo/regions.go
generated
vendored
3
vendor/github.com/digitalocean/godo/regions.go
generated
vendored
@ -1,9 +1,8 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// RegionsService is an interface for interfacing with the regions
|
||||
|
3
vendor/github.com/digitalocean/godo/sizes.go
generated
vendored
3
vendor/github.com/digitalocean/godo/sizes.go
generated
vendored
@ -1,9 +1,8 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// SizesService is an interface for interfacing with the size
|
||||
|
4
vendor/github.com/digitalocean/godo/snapshots.go
generated
vendored
4
vendor/github.com/digitalocean/godo/snapshots.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const snapshotBasePath = "v2/snapshots"
|
||||
@ -38,6 +37,7 @@ type Snapshot struct {
|
||||
MinDiskSize int `json:"min_disk_size,omitempty"`
|
||||
SizeGigaBytes float64 `json:"size_gigabytes,omitempty"`
|
||||
Created string `json:"created_at,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
type snapshotRoot struct {
|
||||
|
51
vendor/github.com/digitalocean/godo/storage.go
generated
vendored
51
vendor/github.com/digitalocean/godo/storage.go
generated
vendored
@ -1,12 +1,10 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -46,19 +44,26 @@ var _ StorageService = &StorageServiceOp{}
|
||||
|
||||
// Volume represents a Digital Ocean block store volume.
|
||||
type Volume struct {
|
||||
ID string `json:"id"`
|
||||
Region *Region `json:"region"`
|
||||
Name string `json:"name"`
|
||||
SizeGigaBytes int64 `json:"size_gigabytes"`
|
||||
Description string `json:"description"`
|
||||
DropletIDs []int `json:"droplet_ids"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID string `json:"id"`
|
||||
Region *Region `json:"region"`
|
||||
Name string `json:"name"`
|
||||
SizeGigaBytes int64 `json:"size_gigabytes"`
|
||||
Description string `json:"description"`
|
||||
DropletIDs []int `json:"droplet_ids"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
FilesystemType string `json:"filesystem_type"`
|
||||
FilesystemLabel string `json:"filesystem_label"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
func (f Volume) String() string {
|
||||
return Stringify(f)
|
||||
}
|
||||
|
||||
func (f Volume) URN() string {
|
||||
return ToURN("Volume", f.ID)
|
||||
}
|
||||
|
||||
type storageVolumesRoot struct {
|
||||
Volumes []Volume `json:"volumes"`
|
||||
Links *Links `json:"links"`
|
||||
@ -72,11 +77,14 @@ type storageVolumeRoot struct {
|
||||
// VolumeCreateRequest represents a request to create a block store
|
||||
// volume.
|
||||
type VolumeCreateRequest struct {
|
||||
Region string `json:"region"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
SizeGigaBytes int64 `json:"size_gigabytes"`
|
||||
SnapshotID string `json:"snapshot_id"`
|
||||
Region string `json:"region"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
SizeGigaBytes int64 `json:"size_gigabytes"`
|
||||
SnapshotID string `json:"snapshot_id"`
|
||||
FilesystemType string `json:"filesystem_type"`
|
||||
FilesystemLabel string `json:"filesystem_label"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
// ListVolumes lists all storage volumes.
|
||||
@ -85,6 +93,10 @@ func (svc *StorageServiceOp) ListVolumes(ctx context.Context, params *ListVolume
|
||||
if params != nil {
|
||||
if params.Region != "" && params.Name != "" {
|
||||
path = fmt.Sprintf("%s?name=%s®ion=%s", path, params.Name, params.Region)
|
||||
} else if params.Region != "" {
|
||||
path = fmt.Sprintf("%s?region=%s", path, params.Region)
|
||||
} else if params.Name != "" {
|
||||
path = fmt.Sprintf("%s?name=%s", path, params.Name)
|
||||
}
|
||||
|
||||
if params.ListOptions != nil {
|
||||
@ -163,9 +175,10 @@ func (svc *StorageServiceOp) DeleteVolume(ctx context.Context, id string) (*Resp
|
||||
// SnapshotCreateRequest represents a request to create a block store
|
||||
// volume.
|
||||
type SnapshotCreateRequest struct {
|
||||
VolumeID string `json:"volume_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
VolumeID string `json:"volume_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Tags []string `json:"tags"`
|
||||
}
|
||||
|
||||
// ListSnapshots lists all snapshots related to a storage volume.
|
||||
|
3
vendor/github.com/digitalocean/godo/storage_actions.go
generated
vendored
3
vendor/github.com/digitalocean/godo/storage_actions.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
// StorageActionsService is an interface for interfacing with the
|
||||
|
10
vendor/github.com/digitalocean/godo/strings.go
generated
vendored
10
vendor/github.com/digitalocean/godo/strings.go
generated
vendored
@ -5,10 +5,20 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var timestampType = reflect.TypeOf(Timestamp{})
|
||||
|
||||
type ResourceWithURN interface {
|
||||
URN() string
|
||||
}
|
||||
|
||||
// ToURN converts the resource type and ID to a valid DO API URN.
|
||||
func ToURN(resourceType string, id interface{}) string {
|
||||
return fmt.Sprintf("%s:%s:%v", "do", strings.ToLower(resourceType), id)
|
||||
}
|
||||
|
||||
// Stringify attempts to create a string representation of DigitalOcean types
|
||||
func Stringify(message interface{}) string {
|
||||
var buf bytes.Buffer
|
||||
|
40
vendor/github.com/digitalocean/godo/tags.go
generated
vendored
40
vendor/github.com/digitalocean/godo/tags.go
generated
vendored
@ -1,10 +1,9 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/digitalocean/godo/context"
|
||||
)
|
||||
|
||||
const tagsBasePath = "v2/tags"
|
||||
@ -34,27 +33,52 @@ var _ TagsService = &TagsServiceOp{}
|
||||
type ResourceType string
|
||||
|
||||
const (
|
||||
//DropletResourceType holds the string representing our ResourceType of Droplet.
|
||||
// DropletResourceType holds the string representing our ResourceType of Droplet.
|
||||
DropletResourceType ResourceType = "droplet"
|
||||
// ImageResourceType holds the string representing our ResourceType of Image.
|
||||
ImageResourceType ResourceType = "image"
|
||||
// VolumeResourceType holds the string representing our ResourceType of Volume.
|
||||
VolumeResourceType ResourceType = "volume"
|
||||
// LoadBalancerResourceType holds the string representing our ResourceType of LoadBalancer.
|
||||
LoadBalancerResourceType ResourceType = "load_balancer"
|
||||
// VolumeSnapshotResourceType holds the string representing our ResourceType for storage Snapshots.
|
||||
VolumeSnapshotResourceType ResourceType = "volumesnapshot"
|
||||
)
|
||||
|
||||
// Resource represent a single resource for associating/disassociating with tags
|
||||
type Resource struct {
|
||||
ID string `json:"resource_id,omit_empty"`
|
||||
Type ResourceType `json:"resource_type,omit_empty"`
|
||||
ID string `json:"resource_id,omitempty"`
|
||||
Type ResourceType `json:"resource_type,omitempty"`
|
||||
}
|
||||
|
||||
// TaggedResources represent the set of resources a tag is attached to
|
||||
type TaggedResources struct {
|
||||
Droplets *TaggedDropletsResources `json:"droplets,omitempty"`
|
||||
Count int `json:"count"`
|
||||
LastTaggedURI string `json:"last_tagged_uri,omitempty"`
|
||||
Droplets *TaggedDropletsResources `json:"droplets,omitempty"`
|
||||
Images *TaggedImagesResources `json:"images"`
|
||||
Volumes *TaggedVolumesResources `json:"volumes"`
|
||||
}
|
||||
|
||||
// TaggedDropletsResources represent the droplet resources a tag is attached to
|
||||
type TaggedDropletsResources struct {
|
||||
Count int `json:"count,float64,omitempty"`
|
||||
LastTagged *Droplet `json:"last_tagged,omitempty"`
|
||||
Count int `json:"count,float64,omitempty"`
|
||||
LastTagged *Droplet `json:"last_tagged,omitempty"`
|
||||
LastTaggedURI string `json:"last_tagged_uri,omitempty"`
|
||||
}
|
||||
|
||||
// TaggedResourcesData represent the generic resources a tag is attached to
|
||||
type TaggedResourcesData struct {
|
||||
Count int `json:"count,float64,omitempty"`
|
||||
LastTaggedURI string `json:"last_tagged_uri,omitempty"`
|
||||
}
|
||||
|
||||
// TaggedImagesResources represent the image resources a tag is attached to
|
||||
type TaggedImagesResources TaggedResourcesData
|
||||
|
||||
// TaggedVolumesResources represent the volume resources a tag is attached to
|
||||
type TaggedVolumesResources TaggedResourcesData
|
||||
|
||||
// Tag represent DigitalOcean tag
|
||||
type Tag struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
|
183
vendor/github.com/digitalocean/godo/vpcs.go
generated
vendored
Normal file
183
vendor/github.com/digitalocean/godo/vpcs.go
generated
vendored
Normal file
@ -0,0 +1,183 @@
|
||||
package godo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const vpcsBasePath = "/v2/vpcs"
|
||||
|
||||
// VPCsService is an interface for managing Virtual Private Cloud configurations with the
|
||||
// DigitalOcean API.
|
||||
// See: https://developers.digitalocean.com/documentation/v2#vpcs
|
||||
type VPCsService interface {
|
||||
Create(context.Context, *VPCCreateRequest) (*VPC, *Response, error)
|
||||
Get(context.Context, string) (*VPC, *Response, error)
|
||||
List(context.Context, *ListOptions) ([]*VPC, *Response, error)
|
||||
Update(context.Context, string, *VPCUpdateRequest) (*VPC, *Response, error)
|
||||
Set(context.Context, string, ...VPCSetField) (*VPC, *Response, error)
|
||||
Delete(context.Context, string) (*Response, error)
|
||||
}
|
||||
|
||||
var _ VPCsService = &VPCsServiceOp{}
|
||||
|
||||
// VPCsServiceOp interfaces with VPC endpoints in the DigitalOcean API.
|
||||
type VPCsServiceOp struct {
|
||||
client *Client
|
||||
}
|
||||
|
||||
// VPCCreateRequest represents a request to create a Virtual Private Cloud.
|
||||
type VPCCreateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
RegionSlug string `json:"region,omitempty"`
|
||||
}
|
||||
|
||||
// VPCUpdateRequest represents a request to update a Virtual Private Cloud.
|
||||
type VPCUpdateRequest struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
// VPCSetField allows one to set individual fields within a VPC configuration.
|
||||
type VPCSetField interface {
|
||||
vpcSetField(map[string]interface{})
|
||||
}
|
||||
|
||||
// VPCSetName is used when one want to set the `name` field of a VPC.
|
||||
// Ex.: VPCs.Set(..., VPCSetName("new-name"))
|
||||
type VPCSetName string
|
||||
|
||||
// VPC represents a DigitalOcean Virtual Private Cloud configuration.
|
||||
type VPC struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
RegionSlug string `json:"region,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
Default bool `json:"default,omitempty"`
|
||||
}
|
||||
|
||||
type vpcRoot struct {
|
||||
VPC *VPC `json:"vpc"`
|
||||
}
|
||||
|
||||
type vpcsRoot struct {
|
||||
VPCs []*VPC `json:"vpcs"`
|
||||
Links *Links `json:"links"`
|
||||
}
|
||||
|
||||
// Get returns the details of a Virtual Private Cloud.
|
||||
func (v *VPCsServiceOp) Get(ctx context.Context, id string) (*VPC, *Response, error) {
|
||||
path := vpcsBasePath + "/" + id
|
||||
req, err := v.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(vpcRoot)
|
||||
resp, err := v.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.VPC, resp, nil
|
||||
}
|
||||
|
||||
// Create creates a new Virtual Private Cloud.
|
||||
func (v *VPCsServiceOp) Create(ctx context.Context, create *VPCCreateRequest) (*VPC, *Response, error) {
|
||||
path := vpcsBasePath
|
||||
req, err := v.client.NewRequest(ctx, http.MethodPost, path, create)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(vpcRoot)
|
||||
resp, err := v.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.VPC, resp, nil
|
||||
}
|
||||
|
||||
// List returns a list of the caller's VPCs, with optional pagination.
|
||||
func (v *VPCsServiceOp) List(ctx context.Context, opt *ListOptions) ([]*VPC, *Response, error) {
|
||||
path, err := addOptions(vpcsBasePath, opt)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
req, err := v.client.NewRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(vpcsRoot)
|
||||
resp, err := v.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
if l := root.Links; l != nil {
|
||||
resp.Links = l
|
||||
}
|
||||
|
||||
return root.VPCs, resp, nil
|
||||
}
|
||||
|
||||
// Update updates a Virtual Private Cloud's properties.
|
||||
func (v *VPCsServiceOp) Update(ctx context.Context, id string, update *VPCUpdateRequest) (*VPC, *Response, error) {
|
||||
path := vpcsBasePath + "/" + id
|
||||
req, err := v.client.NewRequest(ctx, http.MethodPut, path, update)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(vpcRoot)
|
||||
resp, err := v.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.VPC, resp, nil
|
||||
}
|
||||
|
||||
func (n VPCSetName) vpcSetField(in map[string]interface{}) {
|
||||
in["name"] = n
|
||||
}
|
||||
|
||||
// Set updates specific properties of a Virtual Private Cloud.
|
||||
func (v *VPCsServiceOp) Set(ctx context.Context, id string, fields ...VPCSetField) (*VPC, *Response, error) {
|
||||
path := vpcsBasePath + "/" + id
|
||||
update := make(map[string]interface{}, len(fields))
|
||||
for _, field := range fields {
|
||||
field.vpcSetField(update)
|
||||
}
|
||||
|
||||
req, err := v.client.NewRequest(ctx, http.MethodPatch, path, update)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(vpcRoot)
|
||||
resp, err := v.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.VPC, resp, nil
|
||||
}
|
||||
|
||||
// Delete deletes a Virtual Private Cloud. There is no way to recover a VPC once it has been
|
||||
// destroyed.
|
||||
func (v *VPCsServiceOp) Delete(ctx context.Context, id string) (*Response, error) {
|
||||
path := vpcsBasePath + "/" + id
|
||||
req, err := v.client.NewRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := v.client.Do(ctx, req, nil)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
@ -206,10 +206,10 @@
|
||||
"revisionTime": "2017-09-15T21:01:58Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "cGY7ZInpebRCbyfMs9IZbUBHcgE=",
|
||||
"checksumSHA1": "Huhc3bTHV4ge7vij7Sui3NBIqm0=",
|
||||
"path": "github.com/digitalocean/godo",
|
||||
"revision": "34840385860db94c88d044571153b6a200ca40b2",
|
||||
"revisionTime": "2017-07-06T20:03:01Z"
|
||||
"revision": "3ec0b9ce8cdefa757e34b8cab427786f9b1684af",
|
||||
"revisionTime": "2019-06-25T19:28:27Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "YpWoCsk+u9H5ctWNKKSVPf4b2as=",
|
||||
|
Reference in New Issue
Block a user