Update digitalocean module (#622)

Related #619
This commit is contained in:
Juho Teperi 2020-02-14 13:40:14 +02:00 committed by GitHub
parent 0f07d91f54
commit 737c8b5616
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 695 additions and 84 deletions

2
go.mod
View file

@ -15,7 +15,7 @@ require (
github.com/cenkalti/backoff v2.1.1+incompatible // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible // indirect
github.com/digitalocean/godo v1.17.1-0.20190625192827-3ec0b9ce8cde
github.com/digitalocean/godo v1.30.0
github.com/dnsimple/dnsimple-go v0.20.1-0.20181001130357-234ec949d37c
github.com/exoscale/egoscale v0.10.5
github.com/go-acme/lego v2.7.2-0.20190727050804-58d6d9f4767a+incompatible

4
go.sum
View file

@ -61,8 +61,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible h1:4jGdduO4ceTJFKf0IhgaB8NJapGqKHwC2b4xQ/cXujM=
github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/digitalocean/godo v1.17.1-0.20190625192827-3ec0b9ce8cde h1:RH/BMr8Gop3JI8AKuk53pgXaoZz9k8eDe7c7p+YzN8k=
github.com/digitalocean/godo v1.17.1-0.20190625192827-3ec0b9ce8cde/go.mod h1:AAPQ+tiM4st79QHlEBTg8LM7JQNre4SAQCbn56wEyKY=
github.com/digitalocean/godo v1.30.0 h1:4Zb+xBlKMXKg772eyQk6px3sk9RhWj/CR75tQ375A/U=
github.com/digitalocean/godo v1.30.0/go.mod h1:iJnN9rVu6K5LioLxLimlq0uRI+y/eAQjROUmeU/r0hY=
github.com/dimchansky/utfbom v1.1.0 h1:FcM3g+nofKgUteL8dm/UpdRXNC9KmADgTpLKsu0TRo4=
github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8=
github.com/dnsimple/dnsimple-go v0.20.1-0.20181001130357-234ec949d37c h1:Llo2tjvv1SspjFXiM8NJyxirMPTZvNPk3lLCPf61COo=

View file

@ -1,8 +1,15 @@
language: go
go:
- 1.7
- 1.8
- 1.9
- "1.10"
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
- tip
matrix:
allow_failures:
- go: tip

8
vendor/github.com/digitalocean/godo/.whitesource generated vendored Normal file
View file

@ -0,0 +1,8 @@
{
"checkRunSettings": {
"vulnerableCheckRunConclusionLevel": "failure"
},
"issueSettings": {
"minSeverityLevel": "LOW"
}
}

View file

@ -1,5 +1,78 @@
# Change Log
## [v1.30.0] - 2020-02-03
- #295 registry: support the created_at field - @adamwg
- #293 doks: node pool labels - @snormore
## [v1.29.0] - 2019-12-13
- #288 Add Balance Get method - @rbutler
- #286,#289 Deserialize meta field - @timoreimann
## [v1.28.0] - 2019-12-04
- #282 Add valid Redis eviction policy constants - @bentranter
- #281 Remove databases info from top-level godoc string - @bentranter
- #280 Fix VolumeSnapshotResourceType value volumesnapshot -> volume_snapshot - @aqche
## [v1.27.0] - 2019-11-18
- #278 add mysql user auth settings for database users - @gregmankes
## [v1.26.0] - 2019-11-13
- #272 dbaas: get and set mysql sql mode - @mikejholly
## [v1.25.0] - 2019-11-13
- #275 registry/docker-credentials: add support for the read/write parameter - @kamaln7
- #273 implement the registry/docker-credentials endpoint - @kamaln7
- #271 Add registry resource - @snormore
## [v1.24.1] - 2019-11-04
- #264 Update isLast to check p.Next - @aqche
## [v1.24.0] - 2019-10-30
- #267 Return []DatabaseFirewallRule in addition to raw response. - @andrewsomething
## [v1.23.1] - 2019-10-30
- #265 add support for getting/setting firewall rules - @gregmankes
- #262 remove ResolveReference call - @mdanzinger
- #261 Update CONTRIBUTING.md - @mdanzinger
## [v1.22.0] - 2019-09-24
- #259 Add Kubernetes GetCredentials method - @snormore
## [v1.21.1] - 2019-09-19
- #257 Upgrade to Go 1.13 - @bentranter
## [v1.21.0] - 2019-09-16
- #255 Add DropletID to Kubernetes Node instance - @snormore
- #254 Add tags to Database, DatabaseReplica - @Zyqsempai
## [v1.20.0] - 2019-09-06
- #252 Add Kubernetes autoscale config fields - @snormore
- #251 Support unset fields on Kubernetes cluster and node pool updates - @snormore
- #250 Add Kubernetes GetUser method - @snormore
## [v1.19.0] - 2019-07-19
- #244 dbaas: add private-network-uuid field to create request
## [v1.18.0] - 2019-07-17
- #241 Databases: support for custom VPC UUID on migrate @mikejholly
- #240 Add the ability to get URN for a Database @stack72
- #236 Fix omitempty typos in JSON struct tags @amccarthy1
## [v1.17.0] - 2019-06-21
- #238 Add support for Redis eviction policy in Databases @mikejholly

View file

@ -18,7 +18,7 @@ go get -u github.com/stretchr/testify/assert
If outside `$GOPATH`, just clone the repository:
```sh
git clone github.com/digitalocean/godo
git clone https://github.com/digitalocean/godo
```
## Running tests

View file

@ -1,7 +1,8 @@
[![Build Status](https://travis-ci.org/digitalocean/godo.svg)](https://travis-ci.org/digitalocean/godo)
# Godo
[![Build Status](https://travis-ci.org/digitalocean/godo.svg)](https://travis-ci.org/digitalocean/godo)
[![GoDoc](https://godoc.org/github.com/digitalocean/godo?status.svg)](https://godoc.org/github.com/digitalocean/godo)
Godo is a Go client library for accessing the DigitalOcean V2 API.
You can view the client API docs here: [http://godoc.org/github.com/digitalocean/godo](http://godoc.org/github.com/digitalocean/godo)

View file

@ -34,6 +34,7 @@ var _ ActionsService = &ActionsServiceOp{}
type actionsRoot struct {
Actions []Action `json:"actions"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type actionRoot struct {
@ -74,6 +75,9 @@ func (s *ActionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Action
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Actions, resp, err
}

52
vendor/github.com/digitalocean/godo/balance.go generated vendored Normal file
View file

@ -0,0 +1,52 @@
package godo
import (
"context"
"net/http"
"time"
)
// BalanceService is an interface for interfacing with the Balance
// endpoints of the DigitalOcean API
// See: https://developers.digitalocean.com/documentation/v2/#balance
type BalanceService interface {
Get(context.Context) (*Balance, *Response, error)
}
// BalanceServiceOp handles communication with the Balance related methods of
// the DigitalOcean API.
type BalanceServiceOp struct {
client *Client
}
var _ BalanceService = &BalanceServiceOp{}
// Balance represents a DigitalOcean Balance
type Balance struct {
MonthToDateBalance string `json:"month_to_date_balance"`
AccountBalance string `json:"account_balance"`
MonthToDateUsage string `json:"month_to_date_usage"`
GeneratedAt time.Time `json:"generated_at"`
}
func (r Balance) String() string {
return Stringify(r)
}
// Get DigitalOcean balance info
func (s *BalanceServiceOp) Get(ctx context.Context) (*Balance, *Response, error) {
path := "v2/customers/my/balance"
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(Balance)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root, resp, err
}

View file

@ -47,6 +47,7 @@ type cdnRoot struct {
type cdnsRoot struct {
Endpoints []CDN `json:"endpoints"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// CDNCreateRequest represents a request to create a CDN.
@ -93,6 +94,9 @@ func (c CDNServiceOp) List(ctx context.Context, opt *ListOptions) ([]CDN, *Respo
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Endpoints, resp, err
}

View file

@ -46,6 +46,7 @@ type certificateRoot struct {
type certificatesRoot struct {
Certificates []Certificate `json:"certificates"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// CertificatesServiceOp handles communication with certificates methods of the DigitalOcean API.
@ -93,6 +94,9 @@ func (c *CertificatesServiceOp) List(ctx context.Context, opt *ListOptions) ([]C
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Certificates, resp, nil
}

View file

@ -4,29 +4,88 @@ import (
"context"
"fmt"
"net/http"
"strings"
"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"
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"
databaseEvictionPolicyPath = databaseBasePath + "/%s/eviction_policy"
databaseSQLModePath = databaseBasePath + "/%s/sql_mode"
databaseFirewallRulesPath = databaseBasePath + "/%s/firewall"
)
// DatabasesService is an interface for interfacing with the databases endpoints
// of the DigitalOcean API.
// SQL Mode constants allow for MySQL-specific SQL flavor configuration.
const (
SQLModeAllowInvalidDates = "ALLOW_INVALID_DATES"
SQLModeANSIQuotes = "ANSI_QUOTES"
SQLModeHighNotPrecedence = "HIGH_NOT_PRECEDENCE"
SQLModeIgnoreSpace = "IGNORE_SPACE"
SQLModeNoAuthCreateUser = "NO_AUTO_CREATE_USER"
SQLModeNoAutoValueOnZero = "NO_AUTO_VALUE_ON_ZERO"
SQLModeNoBackslashEscapes = "NO_BACKSLASH_ESCAPES"
SQLModeNoDirInCreate = "NO_DIR_IN_CREATE"
SQLModeNoEngineSubstitution = "NO_ENGINE_SUBSTITUTION"
SQLModeNoFieldOptions = "NO_FIELD_OPTIONS"
SQLModeNoKeyOptions = "NO_KEY_OPTIONS"
SQLModeNoTableOptions = "NO_TABLE_OPTIONS"
SQLModeNoUnsignedSubtraction = "NO_UNSIGNED_SUBTRACTION"
SQLModeNoZeroDate = "NO_ZERO_DATE"
SQLModeNoZeroInDate = "NO_ZERO_IN_DATE"
SQLModeOnlyFullGroupBy = "ONLY_FULL_GROUP_BY"
SQLModePadCharToFullLength = "PAD_CHAR_TO_FULL_LENGTH"
SQLModePipesAsConcat = "PIPES_AS_CONCAT"
SQLModeRealAsFloat = "REAL_AS_FLOAT"
SQLModeStrictAllTables = "STRICT_ALL_TABLES"
SQLModeStrictTransTables = "STRICT_TRANS_TABLES"
SQLModeANSI = "ANSI"
SQLModeDB2 = "DB2"
SQLModeMaxDB = "MAXDB"
SQLModeMSSQL = "MSSQL"
SQLModeMYSQL323 = "MYSQL323"
SQLModeMYSQL40 = "MYSQL40"
SQLModeOracle = "ORACLE"
SQLModePostgreSQL = "POSTGRESQL"
SQLModeTraditional = "TRADITIONAL"
)
// SQL Auth constants allow for MySQL-specific user auth plugins
const (
SQLAuthPluginNative = "mysql_native_password"
SQLAuthPluginCachingSHA2 = "caching_sha2_password"
)
// Redis eviction policies supported by the managed Redis product.
const (
EvictionPolicyNoEviction = "noeviction"
EvictionPolicyAllKeysLRU = "allkeys_lru"
EvictionPolicyAllKeysRandom = "allkeys_random"
EvictionPolicyVolatileLRU = "volatile_lru"
EvictionPolicyVolatileRandom = "volatile_random"
EvictionPolicyVolatileTTL = "volatile_ttl"
)
// The DatabasesService provides access to the DigitalOcean managed database
// suite of products through the public API. 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.
//
// See: https://developers.digitalocean.com/documentation/v2#databases
type DatabasesService interface {
List(context.Context, *ListOptions) ([]Database, *Response, error)
@ -55,6 +114,10 @@ type DatabasesService interface {
DeleteReplica(context.Context, string, string) (*Response, error)
GetEvictionPolicy(context.Context, string) (string, *Response, error)
SetEvictionPolicy(context.Context, string, string) (*Response, error)
GetSQLMode(context.Context, string) (string, *Response, error)
SetSQLMode(context.Context, string, ...string) (*Response, error)
GetFirewallRules(context.Context, string) ([]DatabaseFirewallRule, *Response, error)
UpdateFirewallRules(context.Context, string, *DatabaseUpdateFirewallRulesRequest) (*Response, error)
}
// DatabasesServiceOp handles communication with the Databases related methods
@ -86,6 +149,7 @@ type Database struct {
MaintenanceWindow *DatabaseMaintenanceWindow `json:"maintenance_window,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
PrivateNetworkUUID string `json:"private_network_uuid,omitempty"`
Tags []string `json:"tags,omitempty"`
}
// DatabaseConnection represents a database connection
@ -101,9 +165,15 @@ type DatabaseConnection struct {
// 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"`
Name string `json:"name,omitempty"`
Role string `json:"role,omitempty"`
Password string `json:"password,omitempty"`
MySQLSettings *DatabaseMySQLUserSettings `json:"mysql_settings,omitempty"`
}
// DatabaseMySQLUserSettings contains MySQL-specific user settings
type DatabaseMySQLUserSettings struct {
AuthPlugin string `json:"auth_plugin"`
}
// DatabaseMaintenanceWindow represents the maintenance_window of a database
@ -123,12 +193,14 @@ type DatabaseBackup struct {
// 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"`
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"`
PrivateNetworkUUID string `json:"private_network_uuid"`
Tags []string `json:"tags,omitempty"`
}
// DatabaseResizeRequest can be used to initiate a database resize operation.
@ -139,7 +211,8 @@ type DatabaseResizeRequest struct {
// DatabaseMigrateRequest can be used to initiate a database migrate operation.
type DatabaseMigrateRequest struct {
Region string `json:"region,omitempty"`
Region string `json:"region,omitempty"`
PrivateNetworkUUID string `json:"private_network_uuid"`
}
// DatabaseUpdateMaintenanceRequest can be used to update the database's maintenance window.
@ -165,6 +238,7 @@ type DatabaseReplica struct {
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
PrivateNetworkUUID string `json:"private_network_uuid,omitempty"`
Tags []string `json:"tags,omitempty"`
}
// DatabasePool represents a database connection pool
@ -189,7 +263,8 @@ type DatabaseCreatePoolRequest struct {
// DatabaseCreateUserRequest is used to create a new database user
type DatabaseCreateUserRequest struct {
Name string `json:"name"`
Name string `json:"name"`
MySQLSettings *DatabaseMySQLUserSettings `json:"mysql_settings,omitempty"`
}
// DatabaseCreateDBRequest is used to create a new engine-specific database within the cluster
@ -199,9 +274,25 @@ type DatabaseCreateDBRequest struct {
// 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"`
Name string `json:"name"`
Region string `json:"region"`
Size string `json:"size"`
PrivateNetworkUUID string `json:"private_network_uuid"`
Tags []string `json:"tags,omitempty"`
}
// DatabaseUpdateFirewallRulesRequest is used to set the firewall rules for a database
type DatabaseUpdateFirewallRulesRequest struct {
Rules []*DatabaseFirewallRule `json:"rules"`
}
// DatabaseFirewallRule is a rule describing an inbound source to a database
type DatabaseFirewallRule struct {
UUID string `json:"uuid"`
ClusterUUID string `json:"cluster_uuid"`
Type string `json:"type"`
Value string `json:"value"`
CreatedAt time.Time `json:"created_at"`
}
type databaseUserRoot struct {
@ -252,6 +343,15 @@ type evictionPolicyRoot struct {
EvictionPolicy string `json:"eviction_policy"`
}
type sqlModeRoot struct {
SQLMode string `json:"sql_mode"`
}
type databaseFirewallRuleRoot struct {
Rules []DatabaseFirewallRule `json:"rules"`
}
// URN returns a URN identifier for the database
func (d Database) URN() string {
return ToURN("dbaas", d.ID)
}
@ -635,7 +735,7 @@ func (svc *DatabasesServiceOp) DeleteReplica(ctx context.Context, databaseID, na
// 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)
path := fmt.Sprintf(databaseEvictionPolicyPath, databaseID)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return "", nil, err
@ -649,8 +749,11 @@ func (svc *DatabasesServiceOp) GetEvictionPolicy(ctx context.Context, databaseID
}
// SetEvictionPolicy updates the eviction policy for a given Redis cluster.
//
// The valid eviction policies are documented by the exported string constants
// with the prefix `EvictionPolicy`.
func (svc *DatabasesServiceOp) SetEvictionPolicy(ctx context.Context, databaseID, policy string) (*Response, error) {
path := fmt.Sprintf(evictionPolicyPath, databaseID)
path := fmt.Sprintf(databaseEvictionPolicyPath, databaseID)
root := &evictionPolicyRoot{EvictionPolicy: policy}
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, root)
if err != nil {
@ -662,3 +765,60 @@ func (svc *DatabasesServiceOp) SetEvictionPolicy(ctx context.Context, databaseID
}
return resp, nil
}
// GetSQLMode loads the SQL Mode settings for a given MySQL cluster.
func (svc *DatabasesServiceOp) GetSQLMode(ctx context.Context, databaseID string) (string, *Response, error) {
path := fmt.Sprintf(databaseSQLModePath, databaseID)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return "", nil, err
}
root := &sqlModeRoot{}
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return "", resp, err
}
return root.SQLMode, resp, nil
}
// SetSQLMode updates the SQL Mode settings for a given MySQL cluster.
func (svc *DatabasesServiceOp) SetSQLMode(ctx context.Context, databaseID string, sqlModes ...string) (*Response, error) {
path := fmt.Sprintf(databaseSQLModePath, databaseID)
root := &sqlModeRoot{SQLMode: strings.Join(sqlModes, ",")}
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
}
// GetFirewallRules loads the inbound sources for a given cluster.
func (svc *DatabasesServiceOp) GetFirewallRules(ctx context.Context, databaseID string) ([]DatabaseFirewallRule, *Response, error) {
path := fmt.Sprintf(databaseFirewallRulesPath, databaseID)
root := new(databaseFirewallRuleRoot)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Rules, resp, nil
}
// UpdateFirewallRules sets the inbound sources for a given cluster.
func (svc *DatabasesServiceOp) UpdateFirewallRules(ctx context.Context, databaseID string, firewallRulesReq *DatabaseUpdateFirewallRulesRequest) (*Response, error) {
path := fmt.Sprintf(databaseFirewallRulesPath, databaseID)
req, err := svc.client.NewRequest(ctx, http.MethodPut, path, firewallRulesReq)
if err != nil {
return nil, err
}
return svc.client.Do(ctx, req, nil)
}

View file

@ -1,11 +1,2 @@
// 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 is the DigtalOcean API v2 client for Go.
package godo

View file

@ -47,6 +47,7 @@ type domainRoot struct {
type domainsRoot struct {
Domains []Domain `json:"domains"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// DomainCreateRequest respresents a request to create a domain.
@ -122,6 +123,9 @@ func (s DomainsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Domain,
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Domains, resp, err
}

View file

@ -139,21 +139,25 @@ type dropletRoot struct {
type dropletsRoot struct {
Droplets []Droplet `json:"droplets"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type kernelsRoot struct {
Kernels []Kernel `json:"kernels,omitempty"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type dropletSnapshotsRoot struct {
Snapshots []Image `json:"snapshots,omitempty"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type backupsRoot struct {
Backups []Image `json:"backups,omitempty"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// DropletCreateImage identifies an image for the create request. It prefers slug over ID.
@ -295,6 +299,9 @@ func (s *DropletsServiceOp) list(ctx context.Context, path string) ([]Droplet, *
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Droplets, resp, err
}
@ -449,6 +456,9 @@ func (s *DropletsServiceOp) Kernels(ctx context.Context, dropletID int, opt *Lis
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Kernels, resp, err
}
@ -478,6 +488,9 @@ func (s *DropletsServiceOp) Actions(ctx context.Context, dropletID int, opt *Lis
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Actions, resp, err
}
@ -507,6 +520,9 @@ func (s *DropletsServiceOp) Backups(ctx context.Context, dropletID int, opt *Lis
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Backups, resp, err
}
@ -536,6 +552,9 @@ func (s *DropletsServiceOp) Snapshots(ctx context.Context, dropletID int, opt *L
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Snapshots, resp, err
}

View file

@ -237,6 +237,7 @@ type firewallRoot struct {
type firewallsRoot struct {
Firewalls []Firewall `json:"firewalls"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
func (fw *FirewallsServiceOp) createAndDoReq(ctx context.Context, method, path string, v interface{}) (*Response, error) {
@ -262,6 +263,9 @@ func (fw *FirewallsServiceOp) listHelper(ctx context.Context, path string) ([]Fi
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Firewalls, resp, err
}

View file

@ -44,6 +44,7 @@ func (f FloatingIP) URN() string {
type floatingIPsRoot struct {
FloatingIPs []FloatingIP `json:"floating_ips"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type floatingIPRoot struct {
@ -80,6 +81,9 @@ func (f *FloatingIPsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Fl
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.FloatingIPs, resp, err
}

View file

@ -1,6 +1,6 @@
module github.com/digitalocean/godo
go 1.12
go 1.13
require (
github.com/google/go-querystring v1.0.0

View file

@ -1,6 +1,7 @@
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 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
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=
@ -14,6 +15,8 @@ golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI
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 h1:YUO/7uOKsKeq9UokNS62b8FYywz3ker1l1vDZRCRefw=
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 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

View file

@ -17,7 +17,7 @@ import (
)
const (
libraryVersion = "1.17.0"
libraryVersion = "1.30.0"
defaultBaseURL = "https://api.digitalocean.com/"
userAgent = "godo/" + libraryVersion
mediaType = "application/json"
@ -45,6 +45,7 @@ type Client struct {
// Services used for communicating with the API
Account AccountService
Actions ActionsService
Balance BalanceService
CDNs CDNService
Domains DomainsService
Droplets DropletsService
@ -65,6 +66,7 @@ type Client struct {
Firewalls FirewallsService
Projects ProjectsService
Kubernetes KubernetesService
Registry RegistryService
Databases DatabasesService
VPCs VPCsService
@ -93,6 +95,9 @@ type Response struct {
// request body and not the header.
Links *Links
// Meta describes generic information about the response.
Meta *Meta
// Monitoring URI
Monitor string
@ -161,6 +166,7 @@ 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.Balance = &BalanceServiceOp{client: c}
c.CDNs = &CDNServiceOp{client: c}
c.Certificates = &CertificatesServiceOp{client: c}
c.Domains = &DomainsServiceOp{client: c}
@ -181,6 +187,7 @@ func NewClient(httpClient *http.Client) *Client {
c.StorageActions = &StorageActionsServiceOp{client: c}
c.Tags = &TagsServiceOp{client: c}
c.Kubernetes = &KubernetesServiceOp{client: c}
c.Registry = &RegistryServiceOp{client: c}
c.Databases = &DatabasesServiceOp{client: c}
c.VPCs = &VPCsServiceOp{client: c}
@ -227,13 +234,11 @@ func SetUserAgent(ua string) ClientOpt {
// BaseURL of the Client. Relative URLS should always be specified without a preceding slash. If specified, the
// value pointed to by body is JSON encoded and included in as the request body.
func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error) {
rel, err := url.Parse(urlStr)
u, err := c.BaseURL.Parse(urlStr)
if err != nil {
return nil, err
}
u := c.BaseURL.ResolveReference(rel)
buf := new(bytes.Buffer)
if body != nil {
err = json.NewEncoder(buf).Encode(body)

View file

@ -72,6 +72,7 @@ type imageRoot struct {
type imagesRoot struct {
Images []Image
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type listImageOptions struct {
@ -236,6 +237,9 @@ func (s *ImagesServiceOp) list(ctx context.Context, opt *ListOptions, listOpt *l
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Images, resp, err
}

View file

@ -46,6 +46,7 @@ type KeyUpdateRequest struct {
type keysRoot struct {
SSHKeys []Key `json:"ssh_keys"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type keyRoot struct {
@ -83,6 +84,9 @@ func (s *KeysServiceOp) List(ctx context.Context, opt *ListOptions) ([]Key, *Res
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.SSHKeys, resp, err
}

View file

@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
@ -24,8 +25,10 @@ const (
type KubernetesService interface {
Create(context.Context, *KubernetesClusterCreateRequest) (*KubernetesCluster, *Response, error)
Get(context.Context, string) (*KubernetesCluster, *Response, error)
GetUser(context.Context, string) (*KubernetesClusterUser, *Response, error)
GetUpgrades(context.Context, string) ([]*KubernetesVersion, *Response, error)
GetKubeConfig(context.Context, string) (*KubernetesClusterConfig, *Response, error)
GetCredentials(context.Context, string, *KubernetesClusterCredentialsGetRequest) (*KubernetesClusterCredentials, *Response, error)
List(context.Context, *ListOptions) ([]*KubernetesCluster, *Response, error)
Update(context.Context, string, *KubernetesClusterUpdateRequest) (*KubernetesCluster, *Response, error)
Upgrade(context.Context, string, *KubernetesClusterUpgradeRequest) (*Response, error)
@ -69,8 +72,8 @@ type KubernetesClusterCreateRequest struct {
type KubernetesClusterUpdateRequest struct {
Name string `json:"name,omitempty"`
Tags []string `json:"tags,omitempty"`
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy"`
AutoUpgrade bool `json:"auto_upgrade"`
MaintenancePolicy *KubernetesMaintenancePolicy `json:"maintenance_policy,omitempty"`
AutoUpgrade *bool `json:"auto_upgrade,omitempty"`
}
// KubernetesClusterUpgradeRequest represents a request to upgrade a Kubernetes cluster.
@ -81,18 +84,26 @@ type KubernetesClusterUpgradeRequest struct {
// 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"`
Name string `json:"name,omitempty"`
Size string `json:"size,omitempty"`
Count int `json:"count,omitempty"`
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
AutoScale bool `json:"auto_scale,omitempty"`
MinNodes int `json:"min_nodes,omitempty"`
MaxNodes int `json:"max_nodes,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"`
Name string `json:"name,omitempty"`
Count *int `json:"count,omitempty"`
Tags []string `json:"tags,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
AutoScale *bool `json:"auto_scale,omitempty"`
MinNodes *int `json:"min_nodes,omitempty"`
MaxNodes *int `json:"max_nodes,omitempty"`
}
// KubernetesNodePoolRecycleNodesRequest is DEPRECATED please use DeleteNode
@ -110,6 +121,11 @@ type KubernetesNodeDeleteRequest struct {
SkipDrain bool `json:"skip_drain,omitempty"`
}
// KubernetesClusterCredentialsGetRequest is a request to get cluster credentials.
type KubernetesClusterCredentialsGetRequest struct {
ExpirySeconds *int `json:"expiry_seconds,omitempty"`
}
// KubernetesCluster represents a Kubernetes cluster.
type KubernetesCluster struct {
ID string `json:"id,omitempty"`
@ -133,6 +149,22 @@ type KubernetesCluster struct {
UpdatedAt time.Time `json:"updated_at,omitempty"`
}
// KubernetesClusterUser represents a Kubernetes cluster user.
type KubernetesClusterUser struct {
Username string `json:"username,omitempty"`
Groups []string `json:"groups,omitempty"`
}
// KubernetesClusterCredentials represents Kubernetes cluster credentials.
type KubernetesClusterCredentials struct {
Server string `json:"server"`
CertificateAuthorityData []byte `json:"certificate_authority_data"`
ClientCertificateData []byte `json:"client_certificate_data"`
ClientKeyData []byte `json:"client_key_data"`
Token string `json:"token"`
ExpiresAt time.Time `json:"expires_at"`
}
// KubernetesMaintenancePolicy is a configuration to set the maintenance window
// of a cluster
type KubernetesMaintenancePolicy struct {
@ -267,20 +299,25 @@ type KubernetesClusterStatus struct {
// 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"`
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"`
Labels map[string]string `json:"labels,omitempty"`
AutoScale bool `json:"auto_scale,omitempty"`
MinNodes int `json:"min_nodes,omitempty"`
MaxNodes int `json:"max_nodes,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"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Status *KubernetesNodeStatus `json:"status,omitempty"`
DropletID string `json:"droplet_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
@ -320,12 +357,17 @@ type KubernetesRegion struct {
type kubernetesClustersRoot struct {
Clusters []*KubernetesCluster `json:"kubernetes_clusters,omitempty"`
Links *Links `json:"links,omitempty"`
Meta *Meta `json:"meta"`
}
type kubernetesClusterRoot struct {
Cluster *KubernetesCluster `json:"kubernetes_cluster,omitempty"`
}
type kubernetesClusterUserRoot struct {
User *KubernetesClusterUser `json:"kubernetes_cluster_user,omitempty"`
}
type kubernetesNodePoolRoot struct {
NodePool *KubernetesNodePool `json:"node_pool,omitempty"`
}
@ -354,6 +396,21 @@ func (svc *KubernetesServiceOp) Get(ctx context.Context, clusterID string) (*Kub
return root.Cluster, resp, nil
}
// GetUser retrieves the details of a Kubernetes cluster user.
func (svc *KubernetesServiceOp) GetUser(ctx context.Context, clusterID string) (*KubernetesClusterUser, *Response, error) {
path := fmt.Sprintf("%s/%s/user", kubernetesClustersPath, clusterID)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(kubernetesClusterUserRoot)
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.User, 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) {
@ -416,6 +473,14 @@ func (svc *KubernetesServiceOp) List(ctx context.Context, opts *ListOptions) ([]
if err != nil {
return nil, resp, err
}
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Clusters, resp, nil
}
@ -444,6 +509,25 @@ func (svc *KubernetesServiceOp) GetKubeConfig(ctx context.Context, clusterID str
return res, resp, nil
}
// GetCredentials returns a Kubernetes API server credentials for the specified cluster.
func (svc *KubernetesServiceOp) GetCredentials(ctx context.Context, clusterID string, get *KubernetesClusterCredentialsGetRequest) (*KubernetesClusterCredentials, *Response, error) {
path := fmt.Sprintf("%s/%s/credentials", kubernetesClustersPath, clusterID)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
q := req.URL.Query()
if get.ExpirySeconds != nil {
q.Add("expiry_seconds", strconv.Itoa(*get.ExpirySeconds))
}
credentials := new(KubernetesClusterCredentials)
resp, err := svc.client.Do(ctx, req, credentials)
if err != nil {
return nil, nil, err
}
return credentials, 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)

View file

@ -59,7 +59,7 @@ func (l *Links) IsLastPage() bool {
}
func (p *Pages) isLast() bool {
return p.Last == ""
return p.Next == ""
}
func pageForURL(urlText string) (int, error) {

View file

@ -167,6 +167,7 @@ func (l dropletIDsRequest) String() string {
type loadBalancersRoot struct {
LoadBalancers []LoadBalancer `json:"load_balancers"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type loadBalancerRoot struct {
@ -218,6 +219,9 @@ func (l *LoadBalancersServiceOp) List(ctx context.Context, opt *ListOptions) ([]
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.LoadBalancers, resp, err
}

6
vendor/github.com/digitalocean/godo/meta.go generated vendored Normal file
View file

@ -0,0 +1,6 @@
package godo
// Meta describes generic information about a response.
type Meta struct {
Total int `json:"total"`
}

View file

@ -125,6 +125,7 @@ type ProjectResourceLinks struct {
type projectsRoot struct {
Projects []Project `json:"projects"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type projectRoot struct {
@ -134,6 +135,7 @@ type projectRoot struct {
type projectResourcesRoot struct {
Resources []ProjectResource `json:"resources"`
Links *Links `json:"links,omitempty"`
Meta *Meta `json:"meta"`
}
var _ ProjectsService = &ProjectsServiceOp{}
@ -158,6 +160,9 @@ func (p *ProjectsServiceOp) List(ctx context.Context, opts *ListOptions) ([]Proj
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Projects, resp, err
}
@ -238,6 +243,9 @@ func (p *ProjectsServiceOp) ListResources(ctx context.Context, projectID string,
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Resources, resp, err
}

View file

@ -32,6 +32,7 @@ type Region struct {
type regionsRoot struct {
Regions []Region
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
func (r Region) String() string {
@ -59,6 +60,9 @@ func (s *RegionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Region
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Regions, resp, err
}

121
vendor/github.com/digitalocean/godo/registry.go generated vendored Normal file
View file

@ -0,0 +1,121 @@
package godo
import (
"bytes"
"context"
"fmt"
"net/http"
"time"
)
const (
registryPath = "/v2/registry"
)
// RegistryService is an interface for interfacing with the Registry endpoints
// of the DigitalOcean API.
// See: https://developers.digitalocean.com/documentation/v2#registry
type RegistryService interface {
Create(context.Context, *RegistryCreateRequest) (*Registry, *Response, error)
Get(context.Context) (*Registry, *Response, error)
Delete(context.Context) (*Response, error)
DockerCredentials(context.Context, *RegistryDockerCredentialsRequest) (*DockerCredentials, *Response, error)
}
var _ RegistryService = &RegistryServiceOp{}
// RegistryServiceOp handles communication with Registry methods of the DigitalOcean API.
type RegistryServiceOp struct {
client *Client
}
// RegistryCreateRequest represents a request to create a registry.
type RegistryCreateRequest struct {
Name string `json:"name,omitempty"`
}
// RegistryDockerCredentialsRequest represents a request to retrieve docker
// credentials for a registry.
type RegistryDockerCredentialsRequest struct {
ReadWrite bool `json:"read_write"`
}
// Registry represents a registry.
type Registry struct {
Name string `json:"name,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
type registryRoot struct {
Registry *Registry `json:"registry,omitempty"`
}
// Get retrieves the details of a Registry.
func (svc *RegistryServiceOp) Get(ctx context.Context) (*Registry, *Response, error) {
req, err := svc.client.NewRequest(ctx, http.MethodGet, registryPath, nil)
if err != nil {
return nil, nil, err
}
root := new(registryRoot)
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Registry, resp, nil
}
// Create creates a registry.
func (svc *RegistryServiceOp) Create(ctx context.Context, create *RegistryCreateRequest) (*Registry, *Response, error) {
req, err := svc.client.NewRequest(ctx, http.MethodPost, registryPath, create)
if err != nil {
return nil, nil, err
}
root := new(registryRoot)
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Registry, resp, nil
}
// Delete deletes a registry. There is no way to recover a registry once it has
// been destroyed.
func (svc *RegistryServiceOp) Delete(ctx context.Context) (*Response, error) {
req, err := svc.client.NewRequest(ctx, http.MethodDelete, registryPath, nil)
if err != nil {
return nil, err
}
resp, err := svc.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}
// DockerCredentials is the content of a Docker config file
// that is used by the docker CLI
// See: https://docs.docker.com/engine/reference/commandline/cli/#configjson-properties
type DockerCredentials struct {
DockerConfigJSON []byte
}
// DockerCredentials retrieves a Docker config file containing the registry's credentials.
func (svc *RegistryServiceOp) DockerCredentials(ctx context.Context, request *RegistryDockerCredentialsRequest) (*DockerCredentials, *Response, error) {
path := fmt.Sprintf("%s/%s?read_write=%t", registryPath, "docker-credentials", request.ReadWrite)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
var buf bytes.Buffer
resp, err := svc.client.Do(ctx, req, &buf)
if err != nil {
return nil, resp, err
}
dc := &DockerCredentials{
DockerConfigJSON: buf.Bytes(),
}
return dc, resp, nil
}

View file

@ -40,6 +40,7 @@ func (s Size) String() string {
type sizesRoot struct {
Sizes []Size
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// List all images
@ -63,6 +64,9 @@ func (s *SizesServiceOp) List(ctx context.Context, opt *ListOptions) ([]Size, *R
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Sizes, resp, err
}

View file

@ -47,6 +47,7 @@ type snapshotRoot struct {
type snapshotsRoot struct {
Snapshots []Snapshot `json:"snapshots"`
Links *Links `json:"links,omitempty"`
Meta *Meta `json:"meta,omitempty"`
}
type listSnapshotOptions struct {

View file

@ -15,7 +15,7 @@ const (
// StorageService is an interface for interfacing with the storage
// endpoints of the Digital Ocean API.
// See: https://developers.digitalocean.com/documentation/v2#storage
// See: https://developers.digitalocean.com/documentation/v2/#block-storage
type StorageService interface {
ListVolumes(context.Context, *ListVolumeParams) ([]Volume, *Response, error)
GetVolume(context.Context, string) (*Volume, *Response, error)
@ -67,6 +67,7 @@ func (f Volume) URN() string {
type storageVolumesRoot struct {
Volumes []Volume `json:"volumes"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type storageVolumeRoot struct {
@ -122,6 +123,9 @@ func (svc *StorageServiceOp) ListVolumes(ctx context.Context, params *ListVolume
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Volumes, resp, nil
}
@ -203,6 +207,9 @@ func (svc *StorageServiceOp) ListSnapshots(ctx context.Context, volumeID string,
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Snapshots, resp, nil
}

View file

@ -120,6 +120,9 @@ func (s *StorageActionsServiceOp) list(ctx context.Context, path string) ([]Acti
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Actions, resp, err
}

View file

@ -42,7 +42,9 @@ const (
// 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"
VolumeSnapshotResourceType ResourceType = "volume_snapshot"
// DatabaseResourceType holds the string representing our ResourceType of Database.
DatabaseResourceType ResourceType = "database"
)
// Resource represent a single resource for associating/disassociating with tags
@ -53,11 +55,13 @@ type Resource struct {
// TaggedResources represent the set of resources a tag is attached to
type TaggedResources struct {
Count int `json:"count"`
LastTaggedURI string `json:"last_tagged_uri,omitempty"`
Droplets *TaggedDropletsResources `json:"droplets,omitempty"`
Images *TaggedImagesResources `json:"images"`
Volumes *TaggedVolumesResources `json:"volumes"`
Count int `json:"count"`
LastTaggedURI string `json:"last_tagged_uri,omitempty"`
Droplets *TaggedDropletsResources `json:"droplets,omitempty"`
Images *TaggedImagesResources `json:"images"`
Volumes *TaggedVolumesResources `json:"volumes"`
VolumeSnapshots *TaggedVolumeSnapshotsResources `json:"volume_snapshots"`
Databases *TaggedDatabasesResources `json:"databases"`
}
// TaggedDropletsResources represent the droplet resources a tag is attached to
@ -79,6 +83,12 @@ type TaggedImagesResources TaggedResourcesData
// TaggedVolumesResources represent the volume resources a tag is attached to
type TaggedVolumesResources TaggedResourcesData
// TaggedVolumeSnapshotsResources represent the volume snapshot resources a tag is attached to
type TaggedVolumeSnapshotsResources TaggedResourcesData
// TaggedDatabasesResources represent the database resources a tag is attached to
type TaggedDatabasesResources TaggedResourcesData
// Tag represent DigitalOcean tag
type Tag struct {
Name string `json:"name,omitempty"`
@ -103,6 +113,7 @@ type UntagResourcesRequest struct {
type tagsRoot struct {
Tags []Tag `json:"tags"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
type tagRoot struct {
@ -131,6 +142,9 @@ func (s *TagsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Tag, *Res
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.Tags, resp, err
}

View file

@ -63,6 +63,7 @@ type vpcRoot struct {
type vpcsRoot struct {
VPCs []*VPC `json:"vpcs"`
Links *Links `json:"links"`
Meta *Meta `json:"meta"`
}
// Get returns the details of a Virtual Private Cloud.
@ -118,6 +119,9 @@ func (v *VPCsServiceOp) List(ctx context.Context, opt *ListOptions) ([]*VPC, *Re
if l := root.Links; l != nil {
resp.Links = l
}
if m := root.Meta; m != nil {
resp.Meta = m
}
return root.VPCs, resp, nil
}

2
vendor/modules.txt vendored
View file

@ -73,7 +73,7 @@ github.com/cpuguy83/go-md2man/v2/md2man
github.com/davecgh/go-spew/spew
# github.com/dgrijalva/jwt-go v3.2.1-0.20190620180102-5e25c22bd5d6+incompatible
github.com/dgrijalva/jwt-go
# github.com/digitalocean/godo v1.17.1-0.20190625192827-3ec0b9ce8cde
# github.com/digitalocean/godo v1.30.0
github.com/digitalocean/godo
# github.com/dimchansky/utfbom v1.1.0
github.com/dimchansky/utfbom