diff --git a/go.mod b/go.mod index bd1f12687..7e7aae519 100644 --- a/go.mod +++ b/go.mod @@ -47,7 +47,7 @@ require ( github.com/tdewolff/test v1.0.6 // indirect github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1 github.com/urfave/cli/v2 v2.1.1 - github.com/vultr/govultr v0.1.7 + github.com/vultr/govultr v0.2.0 golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678 // indirect golang.org/x/mod v0.2.0 // indirect golang.org/x/net v0.0.0-20200202094626-16171245cfb2 diff --git a/go.sum b/go.sum index 1d268d01b..f88271555 100644 --- a/go.sum +++ b/go.sum @@ -234,8 +234,8 @@ github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1 h1:FOkGM6K21IiX github.com/tiramiseb/go-gandi v0.0.0-20200128175142-df8b8e9d23a1/go.mod h1:wevS0bE43PMSmEldbtya+tp+Ow180ftEPix8Onwh+E4= github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k= github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= -github.com/vultr/govultr v0.1.7 h1:+AilzQB5HAStp/mOyBRNil+l8FHWRfHgDEKfC0oQMzY= -github.com/vultr/govultr v0.1.7/go.mod h1:glSLa57Jdj5s860EEc6+DEBbb/t3aUOKnB4gVPmDVlQ= +github.com/vultr/govultr v0.2.0 h1:CZSNNCk+PHz9hzmfH2PFGkDgc3qNetwZqtcaqL8shlg= +github.com/vultr/govultr v0.2.0/go.mod h1:glSLa57Jdj5s860EEc6+DEBbb/t3aUOKnB4gVPmDVlQ= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= diff --git a/vendor/github.com/vultr/govultr/CHANGELOG.md b/vendor/github.com/vultr/govultr/CHANGELOG.md index 3e58de4b0..f1570f77d 100644 --- a/vendor/github.com/vultr/govultr/CHANGELOG.md +++ b/vendor/github.com/vultr/govultr/CHANGELOG.md @@ -1,10 +1,13 @@ # Change Log +## [v0.2.0](https://github.com/vultr/govultr/compare/v0.1.7..v0.2.0) (2020-02-06) +### Enhancement +* Added support for Object Storage [#39](https://github.com/vultr/govultr/pull/39) + ## [v0.1.7](https://github.com/vultr/govultr/compare/v0.1.6..v0.1.7) (2019-11-11) ### Enhancement * Version number was missing in v0.1.6 - Attempt was made to fix however it will not work. Cutting new release to remedy this. - ## [v0.1.6](https://github.com/vultr/govultr/compare/v0.1.5..v0.1.6) (2019-11-07) ### Enhancement * Retry rate-limited requests with exponential backoff[#28](https://github.com/vultr/govultr/pull/28) diff --git a/vendor/github.com/vultr/govultr/govultr.go b/vendor/github.com/vultr/govultr/govultr.go index b20615b92..610e8e847 100644 --- a/vendor/github.com/vultr/govultr/govultr.go +++ b/vendor/github.com/vultr/govultr/govultr.go @@ -16,7 +16,7 @@ import ( ) const ( - version = "0.1.7" + version = "0.2.0" defaultBase = "https://api.vultr.com" userAgent = "govultr/" + version rateLimit = 600 * time.Millisecond @@ -24,8 +24,10 @@ const ( ) // whiteListURI is an array of endpoints that should not have the API Key passed to them -var whiteListURI = [12]string{"/v1/regions/availability", +var whiteListURI = [13]string{ + "/v1/regions/availability", "/v1/app/list", + "/v1/objectstorage/list_cluster", "/v1/os/list", "/v1/plans/list", "/v1/plans/list_baremetal", @@ -71,6 +73,7 @@ type Client struct { FirewallRule FireWallRuleService ISO ISOService Network NetworkService + ObjectStorage ObjectStorageService OS OSService Plan PlanService Region RegionService @@ -121,6 +124,7 @@ func NewClient(httpClient *http.Client, key string) *Client { client.FirewallRule = &FireWallRuleServiceHandler{client} client.ISO = &ISOServiceHandler{client} client.Network = &NetworkServiceHandler{client} + client.ObjectStorage = &ObjectStorageServiceHandler{client} client.OS = &OSServiceHandler{client} client.Plan = &PlanServiceHandler{client} client.Region = &RegionServiceHandler{client} diff --git a/vendor/github.com/vultr/govultr/object_storage.go b/vendor/github.com/vultr/govultr/object_storage.go new file mode 100644 index 000000000..886f7b2dc --- /dev/null +++ b/vendor/github.com/vultr/govultr/object_storage.go @@ -0,0 +1,254 @@ +package govultr + +import ( + "context" + "net/http" + "net/url" + "strconv" +) + +// ObjectStorageService is the interface to interact with the object storage endpoints on the Vultr API. +// Link: https://www.vultr.com/api/#objectstorage +type ObjectStorageService interface { + Create(ctx context.Context, objectStoreClusterID int, Label string) (*struct{ ID int `json:"SUBID"` }, error) + Delete(ctx context.Context, id int) error + SetLabel(ctx context.Context, id int, label string) error + List(ctx context.Context, options *ObjectListOptions) ([]ObjectStorage, error) + Get(ctx context.Context, id int) (*ObjectStorage, error) + ListCluster(ctx context.Context) ([]ObjectStorageCluster, error) + RegenerateKeys(ctx context.Context, id int, s3AccessKey string) (*S3Keys, error) +} + +// ObjectStorageServiceHandler handles interaction with the firewall rule methods for the Vultr API. +type ObjectStorageServiceHandler struct { + client *Client +} + +// ObjectStorage represents a Vultr Object Storage subscription. +type ObjectStorage struct { + ID int `json:"SUBID"` + DateCreated string `json:"date_created"` + ObjectStoreClusterID int `json:"OBJSTORECLUSTERID"` + RegionID int `json:"DCID"` + Location string + Label string + Status string + S3Keys +} + +// ObjectStorageCluster represents a Vultr Object Storage cluster. +type ObjectStorageCluster struct { + ObjectStoreClusterID int `json:"OBJSTORECLUSTERID"` + RegionID int `json:"DCID"` + Location string + Hostname string + Deploy string +} + +// S3Keys define your api access to your cluster +type S3Keys struct { + S3Hostname string `json:"s3_hostname"` + S3AccessKey string `json:"s3_access_key"` + S3SecretKey string `json:"s3_secret_key"` +} + +// ObjectListOptions are your optional params you have available to list data. +type ObjectListOptions struct { + IncludeS3 bool + Label string +} + +// Create an object storage subscription +func (o *ObjectStorageServiceHandler) Create(ctx context.Context, objectStoreClusterID int, Label string) (*struct{ ID int `json:"SUBID"` }, error) { + uri := "/v1/objectstorage/create" + + values := url.Values{ + "OBJSTORECLUSTERID": {strconv.Itoa(objectStoreClusterID)}, + "label": {Label}, + } + + req, err := o.client.NewRequest(ctx, http.MethodPost, uri, values) + + if err != nil { + return nil, err + } + + id := struct { + ID int `json:"SUBID"` + }{} + + err = o.client.DoWithContext(ctx, req, &id) + if err != nil { + return nil, err + } + + return &id, nil +} + +// Delete an object storage subscription. +func (o *ObjectStorageServiceHandler) Delete(ctx context.Context, id int) error { + uri := "/v1/objectstorage/destroy" + + values := url.Values{ + "SUBID": {strconv.Itoa(id)}, + } + + req, err := o.client.NewRequest(ctx, http.MethodPost, uri, values) + + if err != nil { + return err + } + + err = o.client.DoWithContext(ctx, req, nil) + + if err != nil { + return err + } + + return nil +} + +// SetLabel of an object storage subscription. +func (o *ObjectStorageServiceHandler) SetLabel(ctx context.Context, id int, label string) error { + uri := "/v1/objectstorage/label_set" + + values := url.Values{ + "SUBID": {strconv.Itoa(id)}, + "label": {label}, + } + + req, err := o.client.NewRequest(ctx, http.MethodPost, uri, values) + + if err != nil { + return err + } + + err = o.client.DoWithContext(ctx, req, nil) + + if err != nil { + return err + } + + return nil +} + +// List returns all object storage subscriptions on the current account. This includes both pending and active subscriptions. +func (o *ObjectStorageServiceHandler) List(ctx context.Context, options *ObjectListOptions) ([]ObjectStorage, error) { + uri := "/v1/objectstorage/list" + + req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) + + if err != nil { + return nil, err + } + + if options != nil { + q := req.URL.Query() + + // default behavior is true + if options.IncludeS3 == false { + q.Add("include_s3", "false") + } + + if options.Label != "" { + q.Add("label", options.Label) + } + + req.URL.RawQuery = q.Encode() + } + + var objectStorageMap map[string]ObjectStorage + + err = o.client.DoWithContext(ctx, req, &objectStorageMap) + + if err != nil { + return nil, err + } + + var objectStorages []ObjectStorage + + for _, o := range objectStorageMap { + objectStorages = append(objectStorages, o) + } + + return objectStorages, nil +} + +// Get returns a specified object storage by the provided ID +func (o *ObjectStorageServiceHandler) Get(ctx context.Context, id int) (*ObjectStorage, error) { + uri := "/v1/objectstorage/list" + + req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) + + if err != nil { + return nil, err + } + + if id != 0 { + q := req.URL.Query() + q.Add("SUBID", strconv.Itoa(id)) + req.URL.RawQuery = q.Encode() + } + + objectStorage := new(ObjectStorage) + + err = o.client.DoWithContext(ctx, req, objectStorage) + + if err != nil { + return nil, err + } + + return objectStorage, nil +} + +// ListCluster returns back your object storage clusters. +// Clusters may be removed over time. The "deploy" field can be used to determine whether or not new deployments are allowed in the cluster. +func (o *ObjectStorageServiceHandler) ListCluster(ctx context.Context) ([]ObjectStorageCluster, error) { + uri := "/v1/objectstorage/list_cluster" + req, err := o.client.NewRequest(ctx, http.MethodGet, uri, nil) + + if err != nil { + return nil, err + } + + var objectClusterMap map[string]ObjectStorageCluster + + err = o.client.DoWithContext(ctx, req, &objectClusterMap) + + if err != nil { + return nil, err + } + + var objectStorageCluster []ObjectStorageCluster + + for _, o := range objectClusterMap { + objectStorageCluster = append(objectStorageCluster, o) + } + + return objectStorageCluster, nil +} + +// RegenerateKeys of the S3 API Keys for an object storage subscription +func (o *ObjectStorageServiceHandler) RegenerateKeys(ctx context.Context, id int, s3AccessKey string) (*S3Keys, error) { + uri := "/v1/objectstorage/s3key_regenerate" + + values := url.Values{ + "SUBID": {strconv.Itoa(id)}, + "s3_access_key": {s3AccessKey}, + } + + req, err := o.client.NewRequest(ctx, http.MethodPost, uri, values) + + if err != nil { + return nil, err + } + + s3Keys := new(S3Keys) + err = o.client.DoWithContext(ctx, req, s3Keys) + + if err != nil { + return nil, err + } + + return s3Keys, nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 69c417fac..399599e67 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -246,7 +246,7 @@ github.com/tiramiseb/go-gandi/internal/client github.com/tiramiseb/go-gandi/livedns # github.com/urfave/cli/v2 v2.1.1 github.com/urfave/cli/v2 -# github.com/vultr/govultr v0.1.7 +# github.com/vultr/govultr v0.2.0 github.com/vultr/govultr # go.opencensus.io v0.22.0 go.opencensus.io