From 794f54e36556562296af971e66979daa470b279d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 21 Sep 2026 14:23:16 +0000 Subject: [PATCH] build(deps): bump github.com/digitalocean/godo from 1.208.0 to 1.210.0 Bumps [github.com/digitalocean/godo](https://github.com/digitalocean/godo) from 1.208.0 to 1.210.0. - [Release notes](https://github.com/digitalocean/godo/releases) - [Changelog](https://github.com/digitalocean/godo/blob/main/CHANGELOG.md) - [Commits](https://github.com/digitalocean/godo/compare/v1.208.0...v1.210.0) --- updated-dependencies: - dependency-name: github.com/digitalocean/godo dependency-version: 1.210.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- .../github.com/digitalocean/godo/CHANGELOG.md | 8 + vendor/github.com/digitalocean/godo/godo.go | 8 +- .../digitalocean/godo/micro_droplets.go | 551 ----------------- .../github.com/digitalocean/godo/microvms.go | 554 ++++++++++++++++++ .../digitalocean/godo/prepayment.go | 96 +++ vendor/modules.txt | 2 +- 8 files changed, 667 insertions(+), 558 deletions(-) delete mode 100644 vendor/github.com/digitalocean/godo/micro_droplets.go create mode 100644 vendor/github.com/digitalocean/godo/microvms.go create mode 100644 vendor/github.com/digitalocean/godo/prepayment.go diff --git a/go.mod b/go.mod index ff9b5259e..982b9459c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.27.0 require ( github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc - github.com/digitalocean/godo v1.208.0 + github.com/digitalocean/godo v1.210.0 github.com/go-logr/logr v1.4.4 github.com/google/go-cmp v0.7.0 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index baafc8f0a..d74a05277 100644 --- a/go.sum +++ b/go.sum @@ -27,8 +27,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/digitalocean/godo v1.208.0 h1:J1+thyQyuU5OXRvifI3NKQZNirNiY6jzEPbvqOQ8yoI= -github.com/digitalocean/godo v1.208.0/go.mod h1:xQsWpVCCbkDrWisHA72hPzPlnC+4W5w/McZY5ij9uvU= +github.com/digitalocean/godo v1.210.0 h1:syE1urCVp/pG/Y8hZ+ECK9LxkVGlGbIWVHEq1YG6Rg0= +github.com/digitalocean/godo v1.210.0/go.mod h1:xQsWpVCCbkDrWisHA72hPzPlnC+4W5w/McZY5ij9uvU= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes= diff --git a/vendor/github.com/digitalocean/godo/CHANGELOG.md b/vendor/github.com/digitalocean/godo/CHANGELOG.md index 66f4b96d1..aad287a40 100644 --- a/vendor/github.com/digitalocean/godo/CHANGELOG.md +++ b/vendor/github.com/digitalocean/godo/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## [1.210.0] - 2026-09-18 + +- #1110 - @kwadhwa-source - Mdrop 391/create options sizes + +## [1.209.0] - 2026-09-17 + +- #1107 - @rodrigoea - billing(prepayment): add public config and status client methods + ## [1.208.0] - 2026-09-15 - #1105 - @AKatruwar - registry: expose registry UUID and add ListByUUID diff --git a/vendor/github.com/digitalocean/godo/godo.go b/vendor/github.com/digitalocean/godo/godo.go index 3e57c8f10..127b8cc71 100644 --- a/vendor/github.com/digitalocean/godo/godo.go +++ b/vendor/github.com/digitalocean/godo/godo.go @@ -21,7 +21,7 @@ import ( ) const ( - libraryVersion = "1.208.0" + libraryVersion = "1.210.0" defaultBaseURL = "https://api.digitalocean.com/" userAgent = "godo/" + libraryVersion mediaType = "application/json" @@ -59,6 +59,7 @@ type Client struct { Apps AppsService Balance BalanceService BillingHistory BillingHistoryService + Prepayment PrepaymentService CDNs CDNService Certificates CertificatesService Databases DatabasesService @@ -77,7 +78,7 @@ type Client struct { Keys KeysService Kubernetes KubernetesService LoadBalancers LoadBalancersService - MicroDroplets MicroDropletsService + MicroVMs MicroVMsService Monitoring MonitoringService Security SecurityService Secrets SecretsService @@ -304,6 +305,7 @@ func NewClient(httpClient *http.Client) *Client { c.Apps = &AppsServiceOp{client: c} c.Balance = &BalanceServiceOp{client: c} c.BillingHistory = &BillingHistoryServiceOp{client: c} + c.Prepayment = &PrepaymentServiceOp{client: c} c.CDNs = &CDNServiceOp{client: c} c.Certificates = &CertificatesServiceOp{client: c} c.Databases = &DatabasesServiceOp{client: c} @@ -321,7 +323,7 @@ func NewClient(httpClient *http.Client) *Client { c.Keys = &KeysServiceOp{client: c} c.Kubernetes = &KubernetesServiceOp{client: c} c.LoadBalancers = &LoadBalancersServiceOp{client: c} - c.MicroDroplets = &MicroDropletsServiceOp{client: c} + c.MicroVMs = &MicroVMsServiceOp{client: c} c.Monitoring = &MonitoringServiceOp{client: c} c.Security = &SecurityServiceOp{client: c} c.Secrets = &SecretsServiceOp{client: c} diff --git a/vendor/github.com/digitalocean/godo/micro_droplets.go b/vendor/github.com/digitalocean/godo/micro_droplets.go deleted file mode 100644 index d3a364ce4..000000000 --- a/vendor/github.com/digitalocean/godo/micro_droplets.go +++ /dev/null @@ -1,551 +0,0 @@ -package godo - -import ( - "context" - "fmt" - "net/http" -) - -const ( - microDropletBasePath = "v2/microdroplets" - microDropletCheckpointsBasePath = "v2/microdroplets/checkpoints" - microDropletOptionsPath = "v2/microdroplets/options" -) - -// MicroDropletState represents the lifecycle state of a MicroDroplet. -type MicroDropletState string - -// Possible lifecycle states for a MicroDroplet. -const ( - MicroDropletStateUnknown = MicroDropletState("unknown") - MicroDropletStateCreating = MicroDropletState("creating") - MicroDropletStateRunning = MicroDropletState("running") - MicroDropletStatePausing = MicroDropletState("pausing") - MicroDropletStatePaused = MicroDropletState("paused") - MicroDropletStateResuming = MicroDropletState("resuming") - MicroDropletStateTerminating = MicroDropletState("terminating") - MicroDropletStateTerminated = MicroDropletState("terminated") - MicroDropletStateFailed = MicroDropletState("failed") -) - -// MicroDropletNetworking represents the networking mode of a MicroDroplet. -type MicroDropletNetworking string - -// Possible networking modes for a MicroDroplet. -const ( - MicroDropletNetworkingUnknown = MicroDropletNetworking("unknown") - MicroDropletNetworkingPublic = MicroDropletNetworking("public") - MicroDropletNetworkingVPC = MicroDropletNetworking("vpc") -) - -// MicroDropletHTTPProtocol represents the HTTP protocol option for a MicroDroplet. -type MicroDropletHTTPProtocol string - -// Possible HTTP protocol values for a MicroDroplet. -const ( - MicroDropletHTTPProtocolHTTP = MicroDropletHTTPProtocol("http") - MicroDropletHTTPProtocolHTTP2 = MicroDropletHTTPProtocol("http2") -) - -// MicroDropletURLStatus represents the lifecycle of a MicroDroplet URL. -type MicroDropletURLStatus string - -// Possible statuses for a MicroDroplet URL. -const ( - MicroDropletURLStatusPending = MicroDropletURLStatus("PENDING") - MicroDropletURLStatusActive = MicroDropletURLStatus("ACTIVE") -) - -// MicroDropletCheckpointStatus represents the status of a MicroDroplet checkpoint. -type MicroDropletCheckpointStatus string - -// Possible states for a MicroDroplet checkpoint. -const ( - MicroDropletCheckpointStatusUnknown = MicroDropletCheckpointStatus("CHECKPOINT_UNKNOWN") - MicroDropletCheckpointStatusCreating = MicroDropletCheckpointStatus("CHECKPOINT_CREATING") - MicroDropletCheckpointStatusAvailable = MicroDropletCheckpointStatus("CHECKPOINT_AVAILABLE") - MicroDropletCheckpointStatusFailed = MicroDropletCheckpointStatus("CHECKPOINT_FAILED") - MicroDropletCheckpointStatusDeleted = MicroDropletCheckpointStatus("CHECKPOINT_DELETED") - MicroDropletCheckpointStatusDeleting = MicroDropletCheckpointStatus("CHECKPOINT_DELETING") -) - -// MicroDropletsService is an interface for interfacing with the MicroDroplet -// endpoints of the DigitalOcean API. -// See: https://docs.digitalocean.com/reference/api/api-reference/#tag/MicroDroplets -type MicroDropletsService interface { - List(ctx context.Context, opt *ListOptions) ([]MicroDroplet, *Response, error) - ListByRegion(ctx context.Context, region string, opt *ListOptions) ([]MicroDroplet, *Response, error) - ListByName(ctx context.Context, name string, opt *ListOptions) ([]MicroDroplet, *Response, error) - Get(ctx context.Context, id string) (*MicroDroplet, *Response, error) - Create(ctx context.Context, createRequest *MicroDropletCreateRequest) (*MicroDroplet, *Response, error) - Pause(ctx context.Context, id string) (*MicroDroplet, *Response, error) - Resume(ctx context.Context, id string) (*MicroDroplet, *Response, error) - Delete(ctx context.Context, id string) (*Response, error) - - ListCheckpoints(ctx context.Context, opt *ListMicroDropletCheckpointsOptions) ([]MicroDropletCheckpoint, *Response, error) - CreateCheckpoint(ctx context.Context, microDropletID string, createRequest *MicroDropletCheckpointCreateRequest) (*MicroDropletCheckpoint, *Response, error) - GetCheckpoint(ctx context.Context, id string) (*MicroDropletCheckpoint, *Response, error) - DeleteCheckpoint(ctx context.Context, id string) (*Response, error) - - GetCreateOptions(ctx context.Context) (*MicroDropletCreateOptions, *Response, error) -} - -// MicroDropletsServiceOp handles communication with the MicroDroplet related -// methods of the DigitalOcean API. -type MicroDropletsServiceOp struct { - client *Client -} - -var _ MicroDropletsService = &MicroDropletsServiceOp{} - -// MicroDropletSize is the compute capacity reported on a MicroDroplet. -type MicroDropletSize struct { - CPU uint32 `json:"cpu,omitempty"` - Memory uint32 `json:"memory,omitempty"` - Disk uint64 `json:"disk,omitempty"` -} - -// MicroDropletSizeRequest is the compute capacity requested at create time. -// Disk is provisioned with the size and is not requested. -type MicroDropletSizeRequest struct { - CPU uint32 `json:"cpu"` - Memory uint32 `json:"memory"` -} - -// MicroDropletSource names what a MicroDroplet runs. Exactly one of OCIRef or -// CheckpointID must be set on create; the API rejects both or neither. -type MicroDropletSource struct { - OCIRef string `json:"oci_ref,omitempty"` - CheckpointID string `json:"checkpoint_id,omitempty"` -} - -// MicroDropletURL is one ingress URL attached to a MicroDroplet. -type MicroDropletURL struct { - Hostname string `json:"hostname,omitempty"` - Port int `json:"port,omitempty"` - Default bool `json:"default,omitempty"` - Status MicroDropletURLStatus `json:"status,omitempty"` -} - -// MicroDroplet represents a DigitalOcean MicroDroplet. -type MicroDroplet struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - Region string `json:"region,omitempty"` - State MicroDropletState `json:"state,omitempty"` - Size *MicroDropletSize `json:"size,omitempty"` - URLs []MicroDropletURL `json:"urls,omitempty"` - Ports []uint32 `json:"ports,omitempty"` - FailureReason string `json:"failure_reason,omitempty"` - Networking MicroDropletNetworking `json:"networking,omitempty"` - Source *MicroDropletSource `json:"source,omitempty"` - AutoPause *AutoPauseConfig `json:"auto_pause,omitempty"` - AutoResume *bool `json:"auto_resume,omitempty"` - Created string `json:"created_at,omitempty"` - Tags []string `json:"tags,omitempty"` -} - -// AutoPauseConfig configures MicroDroplet auto-pause behavior. IdleTimeout is -// a Go duration string (e.g. "5m", "30s") describing how long the MicroDroplet -// must be idle before it is paused. -type AutoPauseConfig struct { - Enabled *bool `json:"enabled,omitempty"` - IdleTimeout string `json:"idle_timeout,omitempty"` -} - -// MicroDropletCheckpoint represents a checkpoint of a MicroDroplet -// (persisted memory + disk state). -type MicroDropletCheckpoint struct { - ID string `json:"id,omitempty"` - MicroDropletID string `json:"micro_droplet_id,omitempty"` - MicroDropletName string `json:"micro_droplet_name,omitempty"` - Name string `json:"name,omitempty"` - Region string `json:"region,omitempty"` - Status MicroDropletCheckpointStatus `json:"status,omitempty"` - MemoryBytes uint64 `json:"memory_bytes,omitempty"` - DiskBytes uint64 `json:"disk_bytes,omitempty"` - Created string `json:"created_at,omitempty"` -} - -// MicroDropletCreateRequest represents a request to create a MicroDroplet. -// Size and Region may be omitted when restoring from a checkpoint so the API -// can inherit them from the checkpoint (api-v2 C6). -type MicroDropletCreateRequest struct { - Name string `json:"name"` - Region string `json:"region,omitempty"` - Size *MicroDropletSizeRequest `json:"size,omitempty"` - Source *MicroDropletSource `json:"source"` - Networking MicroDropletNetworking `json:"networking,omitempty"` - VPCUUID string `json:"vpc_uuid,omitempty"` - AutoPause *AutoPauseConfig `json:"auto_pause,omitempty"` - AutoResume *bool `json:"auto_resume,omitempty"` - HTTPPort uint32 `json:"http_port,omitempty"` - HTTPProtocol MicroDropletHTTPProtocol `json:"http_protocol,omitempty"` - Ports []uint32 `json:"ports,omitempty"` - Environment map[string]string `json:"environment,omitempty"` - Tags []string `json:"tags,omitempty"` -} - -// MicroDropletCheckpointCreateRequest represents a request to create a checkpoint. -type MicroDropletCheckpointCreateRequest struct { - Name string `json:"name,omitempty"` -} - -// ListMicroDropletCheckpointsOptions are the optional parameters for listing -// checkpoints. MicroDropletID filters to checkpoints captured from that -// MicroDroplet; omit it to list all checkpoints for the team. -type ListMicroDropletCheckpointsOptions struct { - ListOptions - MicroDropletID string `url:"micro_droplet_id,omitempty"` -} - -// MicroDropletCreateOptions is the response from GET /v2/microdroplets/options. -type MicroDropletCreateOptions struct { - Regions []MicroDropletRegionOption `json:"regions,omitempty"` - DefaultRegion string `json:"default_region,omitempty"` - Sizes []MicroDropletSizeOption `json:"sizes,omitempty"` - Features []MicroDropletFeatureOption `json:"features,omitempty"` - AccountLimits *MicroDropletAccountLimits `json:"account_limits,omitempty"` -} - -// MicroDropletRegionOption is one region evaluated for the authenticated team. -type MicroDropletRegionOption struct { - Slug string `json:"slug,omitempty"` - Available bool `json:"available"` - UnavailableReason string `json:"unavailable_reason,omitempty"` -} - -// MicroDropletSizeOption is one supported size evaluated for the team. -type MicroDropletSizeOption struct { - Size MicroDropletSize `json:"size"` - Available bool `json:"available"` - Pricing *MicroDropletSizePricing `json:"pricing,omitempty"` -} - -// MicroDropletSizePricing is the USD price of one size. -type MicroDropletSizePricing struct { - PricePerHour float64 `json:"price_per_hour"` - PricePerMonth float64 `json:"price_per_month"` -} - -// MicroDropletFeatureOption is one product feature gate for the team. -type MicroDropletFeatureOption struct { - Name string `json:"name,omitempty"` - Enabled bool `json:"enabled"` -} - -// MicroDropletAccountLimits are the team's effective MicroDroplet limits. -type MicroDropletAccountLimits struct { - MaxConcurrentRunning uint64 `json:"max_concurrent_running,omitempty"` - MaxTotalCount uint64 `json:"max_total_count,omitempty"` - MaxMemoryBytes uint64 `json:"max_memory_bytes,omitempty"` - MaxDiskBytes uint64 `json:"max_disk_bytes,omitempty"` - MaxIdleTimeoutSeconds uint64 `json:"max_idle_timeout_seconds,omitempty"` -} - -// String returns a human-readable description of a MicroDroplet. -func (m MicroDroplet) String() string { - return Stringify(m) -} - -// URN returns the MicroDroplet ID in a valid DO API URN form. -func (m MicroDroplet) URN() string { - return ToURN("MicroDroplet", m.ID) -} - -// String returns a human-readable description of a MicroDropletCheckpoint. -func (c MicroDropletCheckpoint) String() string { - return Stringify(c) -} - -// String returns a human-readable description of a MicroDropletCreateRequest. -func (r MicroDropletCreateRequest) String() string { - return Stringify(r) -} - -type microDropletRoot struct { - MicroDroplet *MicroDroplet `json:"micro_droplet"` -} - -type microDropletsRoot struct { - MicroDroplets []MicroDroplet `json:"micro_droplets"` - Links *Links `json:"links"` - Meta *Meta `json:"meta"` -} - -type microDropletCheckpointRoot struct { - Checkpoint *MicroDropletCheckpoint `json:"checkpoint"` -} - -type microDropletCheckpointsRoot struct { - Checkpoints []MicroDropletCheckpoint `json:"checkpoints"` - Links *Links `json:"links"` - Meta *Meta `json:"meta"` -} - -// listMicroDropletOptions holds MicroDroplet-specific list filters that are -// not part of the shared ListOptions. -type listMicroDropletOptions struct { - Region string `url:"region,omitempty"` - Name string `url:"name,omitempty"` -} - -// List lists all MicroDroplets, with optional pagination. -func (s *MicroDropletsServiceOp) List(ctx context.Context, opt *ListOptions) ([]MicroDroplet, *Response, error) { - return s.list(ctx, opt, nil) -} - -// ListByRegion lists MicroDroplets filtered by region slug, with optional pagination. -func (s *MicroDropletsServiceOp) ListByRegion(ctx context.Context, region string, opt *ListOptions) ([]MicroDroplet, *Response, error) { - if region == "" { - return nil, nil, NewArgError("region", "cannot be empty") - } - return s.list(ctx, opt, &listMicroDropletOptions{Region: region}) -} - -// ListByName lists MicroDroplets filtered by exact name match, with optional pagination. -func (s *MicroDropletsServiceOp) ListByName(ctx context.Context, name string, opt *ListOptions) ([]MicroDroplet, *Response, error) { - if name == "" { - return nil, nil, NewArgError("name", "cannot be empty") - } - return s.list(ctx, opt, &listMicroDropletOptions{Name: name}) -} - -func (s *MicroDropletsServiceOp) list(ctx context.Context, opt *ListOptions, listOpt *listMicroDropletOptions) ([]MicroDroplet, *Response, error) { - path := microDropletBasePath - path, err := addOptions(path, opt) - if err != nil { - return nil, nil, err - } - path, err = addOptions(path, listOpt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(microDropletsRoot) - resp, err := s.client.Do(ctx, req, root) - 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.MicroDroplets, resp, nil -} - -// Get retrieves a MicroDroplet by its ID. -func (s *MicroDropletsServiceOp) Get(ctx context.Context, id string) (*MicroDroplet, *Response, error) { - if id == "" { - return nil, nil, NewArgError("id", "cannot be empty") - } - - path := fmt.Sprintf("%s/%s", microDropletBasePath, id) - - req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(microDropletRoot) - resp, err := s.client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root.MicroDroplet, resp, nil -} - -// Create provisions a new MicroDroplet with the provided configuration. -func (s *MicroDropletsServiceOp) Create(ctx context.Context, createRequest *MicroDropletCreateRequest) (*MicroDroplet, *Response, error) { - if createRequest == nil { - return nil, nil, NewArgError("createRequest", "cannot be nil") - } - - req, err := s.client.NewRequest(ctx, http.MethodPost, microDropletBasePath, createRequest) - if err != nil { - return nil, nil, err - } - - root := new(microDropletRoot) - resp, err := s.client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root.MicroDroplet, resp, nil -} - -// Pause synchronously transitions a RUNNING MicroDroplet to PAUSED. It blocks -// until the platform has durably paused the MicroDroplet and returns the -// updated resource. The call is idempotent: pausing a MicroDroplet that is -// already PAUSED returns the current MicroDroplet with no side effects. -func (s *MicroDropletsServiceOp) Pause(ctx context.Context, id string) (*MicroDroplet, *Response, error) { - return s.doTransition(ctx, id, "pause") -} - -// Resume synchronously transitions a PAUSED MicroDroplet to RUNNING. It blocks -// until the platform has durably resumed the MicroDroplet and returns the -// updated resource. The call is idempotent: resuming a MicroDroplet that is -// already RUNNING returns the current MicroDroplet with no side effects. -func (s *MicroDropletsServiceOp) Resume(ctx context.Context, id string) (*MicroDroplet, *Response, error) { - return s.doTransition(ctx, id, "resume") -} - -// doTransition posts an empty body to a MicroDroplet transition sub-resource -// (e.g. /pause, /resume) and decodes the returned MicroDroplet. -func (s *MicroDropletsServiceOp) doTransition(ctx context.Context, id, action string) (*MicroDroplet, *Response, error) { - if id == "" { - return nil, nil, NewArgError("id", "cannot be empty") - } - - path := fmt.Sprintf("%s/%s/%s", microDropletBasePath, id, action) - - req, err := s.client.NewRequest(ctx, http.MethodPost, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(microDropletRoot) - resp, err := s.client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root.MicroDroplet, resp, nil -} - -// Delete removes a MicroDroplet by its ID. The DigitalOcean API returns a 204 -// on success and does not include a response body. -func (s *MicroDropletsServiceOp) Delete(ctx context.Context, id string) (*Response, error) { - if id == "" { - return nil, NewArgError("id", "cannot be empty") - } - - path := fmt.Sprintf("%s/%s", microDropletBasePath, id) - - req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// ListCheckpoints lists checkpoints for the authenticated team. Pass a -// MicroDropletID on opt to filter to checkpoints captured from that MicroDroplet. -func (s *MicroDropletsServiceOp) ListCheckpoints(ctx context.Context, opt *ListMicroDropletCheckpointsOptions) ([]MicroDropletCheckpoint, *Response, error) { - path := microDropletCheckpointsBasePath - path, err := addOptions(path, opt) - if err != nil { - return nil, nil, err - } - - req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(microDropletCheckpointsRoot) - resp, err := s.client.Do(ctx, req, root) - 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.Checkpoints, resp, nil -} - -// CreateCheckpoint starts an asynchronous checkpoint of a running MicroDroplet. -func (s *MicroDropletsServiceOp) CreateCheckpoint(ctx context.Context, microDropletID string, createRequest *MicroDropletCheckpointCreateRequest) (*MicroDropletCheckpoint, *Response, error) { - if microDropletID == "" { - return nil, nil, NewArgError("microDropletID", "cannot be empty") - } - if createRequest == nil { - createRequest = &MicroDropletCheckpointCreateRequest{} - } - - path := fmt.Sprintf("%s/%s/checkpoints", microDropletBasePath, microDropletID) - - req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest) - if err != nil { - return nil, nil, err - } - - root := new(microDropletCheckpointRoot) - resp, err := s.client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root.Checkpoint, resp, nil -} - -// GetCheckpoint retrieves a checkpoint by its ID. -func (s *MicroDropletsServiceOp) GetCheckpoint(ctx context.Context, id string) (*MicroDropletCheckpoint, *Response, error) { - if id == "" { - return nil, nil, NewArgError("id", "cannot be empty") - } - - path := fmt.Sprintf("%s/%s", microDropletCheckpointsBasePath, id) - - req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - root := new(microDropletCheckpointRoot) - resp, err := s.client.Do(ctx, req, root) - if err != nil { - return nil, resp, err - } - - return root.Checkpoint, resp, nil -} - -// DeleteCheckpoint releases the state stored by a checkpoint. Returns a 204 -// on success with no response body. -func (s *MicroDropletsServiceOp) DeleteCheckpoint(ctx context.Context, id string) (*Response, error) { - if id == "" { - return nil, NewArgError("id", "cannot be empty") - } - - path := fmt.Sprintf("%s/%s", microDropletCheckpointsBasePath, id) - - req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil) - if err != nil { - return nil, err - } - - return s.client.Do(ctx, req, nil) -} - -// GetCreateOptions returns the regions, sizes, features, and account limits -// available to the authenticated team when creating a MicroDroplet. -func (s *MicroDropletsServiceOp) GetCreateOptions(ctx context.Context) (*MicroDropletCreateOptions, *Response, error) { - req, err := s.client.NewRequest(ctx, http.MethodGet, microDropletOptionsPath, nil) - if err != nil { - return nil, nil, err - } - - opts := new(MicroDropletCreateOptions) - resp, err := s.client.Do(ctx, req, opts) - if err != nil { - return nil, resp, err - } - - return opts, resp, nil -} diff --git a/vendor/github.com/digitalocean/godo/microvms.go b/vendor/github.com/digitalocean/godo/microvms.go new file mode 100644 index 000000000..15abc71ce --- /dev/null +++ b/vendor/github.com/digitalocean/godo/microvms.go @@ -0,0 +1,554 @@ +package godo + +import ( + "context" + "fmt" + "net/http" +) + +const ( + microVMBasePath = "v2/microvms" + microVMCheckpointsBasePath = "v2/microvms/checkpoints" + microVMOptionsPath = "v2/microvms/options" +) + +// MicroVMState represents the lifecycle state of a MicroVM. +type MicroVMState string + +// Possible lifecycle states for a MicroVM. +const ( + MicroVMStateUnknown = MicroVMState("unknown") + MicroVMStateCreating = MicroVMState("creating") + MicroVMStateRunning = MicroVMState("running") + MicroVMStatePausing = MicroVMState("pausing") + MicroVMStatePaused = MicroVMState("paused") + MicroVMStateResuming = MicroVMState("resuming") + MicroVMStateTerminating = MicroVMState("terminating") + MicroVMStateTerminated = MicroVMState("terminated") + MicroVMStateFailed = MicroVMState("failed") +) + +// MicroVMNetworking represents the networking mode of a MicroVM. +type MicroVMNetworking string + +// Possible networking modes for a MicroVM. +const ( + MicroVMNetworkingUnknown = MicroVMNetworking("unknown") + MicroVMNetworkingPublic = MicroVMNetworking("public") + MicroVMNetworkingVPC = MicroVMNetworking("vpc") +) + +// MicroVMHTTPProtocol represents the HTTP protocol option for a MicroVM. +type MicroVMHTTPProtocol string + +// Possible HTTP protocol values for a MicroVM. +const ( + MicroVMHTTPProtocolHTTP = MicroVMHTTPProtocol("http") + MicroVMHTTPProtocolHTTP2 = MicroVMHTTPProtocol("http2") +) + +// MicroVMURLStatus represents the lifecycle of a MicroVM URL. +type MicroVMURLStatus string + +// Possible statuses for a MicroVM URL. +const ( + MicroVMURLStatusPending = MicroVMURLStatus("PENDING") + MicroVMURLStatusActive = MicroVMURLStatus("ACTIVE") +) + +// MicroVMCheckpointStatus represents the status of a MicroVM checkpoint. +type MicroVMCheckpointStatus string + +// Possible states for a MicroVM checkpoint. +const ( + MicroVMCheckpointStatusUnknown = MicroVMCheckpointStatus("CHECKPOINT_UNKNOWN") + MicroVMCheckpointStatusCreating = MicroVMCheckpointStatus("CHECKPOINT_CREATING") + MicroVMCheckpointStatusAvailable = MicroVMCheckpointStatus("CHECKPOINT_AVAILABLE") + MicroVMCheckpointStatusFailed = MicroVMCheckpointStatus("CHECKPOINT_FAILED") + MicroVMCheckpointStatusDeleted = MicroVMCheckpointStatus("CHECKPOINT_DELETED") + MicroVMCheckpointStatusDeleting = MicroVMCheckpointStatus("CHECKPOINT_DELETING") +) + +// MicroVMsService is an interface for interfacing with the MicroVM +// endpoints of the DigitalOcean API. +// See: https://docs.digitalocean.com/reference/api/api-reference/#tag/MicroVMs +type MicroVMsService interface { + List(ctx context.Context, opt *ListOptions) ([]MicroVM, *Response, error) + ListByRegion(ctx context.Context, region string, opt *ListOptions) ([]MicroVM, *Response, error) + ListByName(ctx context.Context, name string, opt *ListOptions) ([]MicroVM, *Response, error) + Get(ctx context.Context, id string) (*MicroVM, *Response, error) + Create(ctx context.Context, createRequest *MicroVMCreateRequest) (*MicroVM, *Response, error) + Pause(ctx context.Context, id string) (*MicroVM, *Response, error) + Resume(ctx context.Context, id string) (*MicroVM, *Response, error) + Delete(ctx context.Context, id string) (*Response, error) + + ListCheckpoints(ctx context.Context, opt *ListMicroVMCheckpointsOptions) ([]MicroVMCheckpoint, *Response, error) + CreateCheckpoint(ctx context.Context, microVMID string, createRequest *MicroVMCheckpointCreateRequest) (*MicroVMCheckpoint, *Response, error) + GetCheckpoint(ctx context.Context, id string) (*MicroVMCheckpoint, *Response, error) + DeleteCheckpoint(ctx context.Context, id string) (*Response, error) + + GetCreateOptions(ctx context.Context) (*MicroVMCreateOptions, *Response, error) +} + +// MicroVMsServiceOp handles communication with the MicroVM related +// methods of the DigitalOcean API. +type MicroVMsServiceOp struct { + client *Client +} + +var _ MicroVMsService = &MicroVMsServiceOp{} + +// MicroVMSize is the compute capacity reported on a MicroVM. +type MicroVMSize struct { + CPU uint32 `json:"cpu,omitempty"` + Memory uint32 `json:"memory,omitempty"` + Disk uint64 `json:"disk,omitempty"` +} + +// MicroVMSizeRequest is the compute capacity requested at create time. +// Disk is provisioned with the size and is not requested. +type MicroVMSizeRequest struct { + CPU uint32 `json:"cpu"` + Memory uint32 `json:"memory"` +} + +// MicroVMSource names what a MicroVM runs. Exactly one of OCIRef or +// CheckpointID must be set on create; the API rejects both or neither. +type MicroVMSource struct { + OCIRef string `json:"oci_ref,omitempty"` + CheckpointID string `json:"checkpoint_id,omitempty"` +} + +// MicroVMURL is one ingress URL attached to a MicroVM. +type MicroVMURL struct { + Hostname string `json:"hostname,omitempty"` + Port int `json:"port,omitempty"` + Default bool `json:"default,omitempty"` + Status MicroVMURLStatus `json:"status,omitempty"` +} + +// MicroVM represents a DigitalOcean MicroVM. +type MicroVM struct { + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Region string `json:"region,omitempty"` + State MicroVMState `json:"state,omitempty"` + Size *MicroVMSize `json:"size,omitempty"` + URLs []MicroVMURL `json:"urls,omitempty"` + Ports []uint32 `json:"ports,omitempty"` + FailureReason string `json:"failure_reason,omitempty"` + Networking MicroVMNetworking `json:"networking,omitempty"` + Source *MicroVMSource `json:"source,omitempty"` + AutoPause *AutoPauseConfig `json:"auto_pause,omitempty"` + AutoResume *bool `json:"auto_resume,omitempty"` + Created string `json:"created_at,omitempty"` + Tags []string `json:"tags,omitempty"` +} + +// AutoPauseConfig configures MicroVM auto-pause behavior. IdleTimeout is +// a Go duration string (e.g. "5m", "30s") describing how long the MicroVM +// must be idle before it is paused. +type AutoPauseConfig struct { + Enabled *bool `json:"enabled,omitempty"` + IdleTimeout string `json:"idle_timeout,omitempty"` +} + +// MicroVMCheckpoint represents a checkpoint of a MicroVM +// (persisted memory + disk state). +type MicroVMCheckpoint struct { + ID string `json:"id,omitempty"` + MicroVMID string `json:"microvm_id,omitempty"` + MicroVMName string `json:"microvm_name,omitempty"` + Name string `json:"name,omitempty"` + Region string `json:"region,omitempty"` + Status MicroVMCheckpointStatus `json:"status,omitempty"` + MemoryBytes uint64 `json:"memory_bytes,omitempty"` + DiskBytes uint64 `json:"disk_bytes,omitempty"` + Created string `json:"created_at,omitempty"` +} + +// MicroVMCreateRequest represents a request to create a MicroVM. +// Size and Region may be omitted when restoring from a checkpoint so the API +// can inherit them from the checkpoint (api-v2 C6). +type MicroVMCreateRequest struct { + Name string `json:"name"` + Region string `json:"region,omitempty"` + Size *MicroVMSizeRequest `json:"size,omitempty"` + Source *MicroVMSource `json:"source"` + Networking MicroVMNetworking `json:"networking,omitempty"` + VPCUUID string `json:"vpc_uuid,omitempty"` + AutoPause *AutoPauseConfig `json:"auto_pause,omitempty"` + AutoResume *bool `json:"auto_resume,omitempty"` + HTTPPort uint32 `json:"http_port,omitempty"` + HTTPProtocol MicroVMHTTPProtocol `json:"http_protocol,omitempty"` + Ports []uint32 `json:"ports,omitempty"` + Environment map[string]string `json:"environment,omitempty"` + Tags []string `json:"tags,omitempty"` +} + +// MicroVMCheckpointCreateRequest represents a request to create a checkpoint. +type MicroVMCheckpointCreateRequest struct { + Name string `json:"name,omitempty"` +} + +// ListMicroVMCheckpointsOptions are the optional parameters for listing +// checkpoints. MicroVMID filters to checkpoints captured from that +// MicroVM; omit it to list all checkpoints for the team. +type ListMicroVMCheckpointsOptions struct { + ListOptions + MicroVMID string `url:"microvm_id,omitempty"` +} + +// MicroVMCreateOptions is the response from GET /v2/microvms/options. +type MicroVMCreateOptions struct { + DefaultRegion string `json:"default_region,omitempty"` + Sizes []MicroVMSizeOption `json:"sizes,omitempty"` + Features []MicroVMFeatureOption `json:"features,omitempty"` + AccountLimits *MicroVMAccountLimits `json:"account_limits,omitempty"` +} + +// MicroVMSizeOption is one supported size evaluated for the team. Regions +// holds the slugs where the team can create this size; a region it cannot use +// is absent rather than listed as unavailable. +type MicroVMSizeOption struct { + CPU uint32 `json:"cpu"` + Memory uint32 `json:"memory"` + Disk uint64 `json:"disk"` + Available bool `json:"available"` + Regions []string `json:"regions"` + Pricing *MicroVMSizePricing `json:"pricing,omitempty"` +} + +// MicroVMSizePricing is the USD price of one size. +type MicroVMSizePricing struct { + PricePerHour float64 `json:"price_per_hour"` + PricePerMonth float64 `json:"price_per_month"` +} + +// MicroVMFeatureOption is one product feature gate for the team. +type MicroVMFeatureOption struct { + Name string `json:"name,omitempty"` + Enabled bool `json:"enabled"` +} + +// MicroVMAccountLimits are the team's effective MicroVM limits. +type MicroVMAccountLimits struct { + MaxConcurrentRunning uint64 `json:"max_concurrent_running,omitempty"` + MaxTotalCount uint64 `json:"max_total_count,omitempty"` + MaxMemoryBytes uint64 `json:"max_memory_bytes,omitempty"` + MaxDiskBytes uint64 `json:"max_disk_bytes,omitempty"` + MaxIdleTimeoutSeconds uint64 `json:"max_idle_timeout_seconds,omitempty"` +} + +// String returns a human-readable description of a MicroVM. +func (m MicroVM) String() string { + return Stringify(m) +} + +// URN returns the MicroVM ID in a valid DO API URN form. +// +// The collection is still "microdroplet" on purpose. URNs are persisted by +// tags and emitted in billing events, and the collection name comes from a +// proto enum shared across those consumers, so renaming it is a coordinated +// change rather than part of this one. +func (m MicroVM) URN() string { + return ToURN("MicroDroplet", m.ID) +} + +// String returns a human-readable description of a MicroVMCheckpoint. +func (c MicroVMCheckpoint) String() string { + return Stringify(c) +} + +// String returns a human-readable description of a MicroVMCreateRequest. +func (r MicroVMCreateRequest) String() string { + return Stringify(r) +} + +type microVMRoot struct { + MicroVM *MicroVM `json:"microvm"` +} + +type microVMsRoot struct { + MicroVMs []MicroVM `json:"microvms"` + Links *Links `json:"links"` + Meta *Meta `json:"meta"` +} + +type microVMCheckpointRoot struct { + Checkpoint *MicroVMCheckpoint `json:"checkpoint"` +} + +type microVMCheckpointsRoot struct { + Checkpoints []MicroVMCheckpoint `json:"checkpoints"` + Links *Links `json:"links"` + Meta *Meta `json:"meta"` +} + +// listMicroVMOptions holds MicroVM-specific list filters that are +// not part of the shared ListOptions. +type listMicroVMOptions struct { + Region string `url:"region,omitempty"` + Name string `url:"name,omitempty"` +} + +// List lists all MicroVMs, with optional pagination. +func (s *MicroVMsServiceOp) List(ctx context.Context, opt *ListOptions) ([]MicroVM, *Response, error) { + return s.list(ctx, opt, nil) +} + +// ListByRegion lists MicroVMs filtered by region slug, with optional pagination. +func (s *MicroVMsServiceOp) ListByRegion(ctx context.Context, region string, opt *ListOptions) ([]MicroVM, *Response, error) { + if region == "" { + return nil, nil, NewArgError("region", "cannot be empty") + } + return s.list(ctx, opt, &listMicroVMOptions{Region: region}) +} + +// ListByName lists MicroVMs filtered by exact name match, with optional pagination. +func (s *MicroVMsServiceOp) ListByName(ctx context.Context, name string, opt *ListOptions) ([]MicroVM, *Response, error) { + if name == "" { + return nil, nil, NewArgError("name", "cannot be empty") + } + return s.list(ctx, opt, &listMicroVMOptions{Name: name}) +} + +func (s *MicroVMsServiceOp) list(ctx context.Context, opt *ListOptions, listOpt *listMicroVMOptions) ([]MicroVM, *Response, error) { + path := microVMBasePath + path, err := addOptions(path, opt) + if err != nil { + return nil, nil, err + } + path, err = addOptions(path, listOpt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(microVMsRoot) + resp, err := s.client.Do(ctx, req, root) + 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.MicroVMs, resp, nil +} + +// Get retrieves a MicroVM by its ID. +func (s *MicroVMsServiceOp) Get(ctx context.Context, id string) (*MicroVM, *Response, error) { + if id == "" { + return nil, nil, NewArgError("id", "cannot be empty") + } + + path := fmt.Sprintf("%s/%s", microVMBasePath, id) + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(microVMRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root.MicroVM, resp, nil +} + +// Create provisions a new MicroVM with the provided configuration. +func (s *MicroVMsServiceOp) Create(ctx context.Context, createRequest *MicroVMCreateRequest) (*MicroVM, *Response, error) { + if createRequest == nil { + return nil, nil, NewArgError("createRequest", "cannot be nil") + } + + req, err := s.client.NewRequest(ctx, http.MethodPost, microVMBasePath, createRequest) + if err != nil { + return nil, nil, err + } + + root := new(microVMRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root.MicroVM, resp, nil +} + +// Pause synchronously transitions a RUNNING MicroVM to PAUSED. It blocks +// until the platform has durably paused the MicroVM and returns the +// updated resource. The call is idempotent: pausing a MicroVM that is +// already PAUSED returns the current MicroVM with no side effects. +func (s *MicroVMsServiceOp) Pause(ctx context.Context, id string) (*MicroVM, *Response, error) { + return s.doTransition(ctx, id, "pause") +} + +// Resume synchronously transitions a PAUSED MicroVM to RUNNING. It blocks +// until the platform has durably resumed the MicroVM and returns the +// updated resource. The call is idempotent: resuming a MicroVM that is +// already RUNNING returns the current MicroVM with no side effects. +func (s *MicroVMsServiceOp) Resume(ctx context.Context, id string) (*MicroVM, *Response, error) { + return s.doTransition(ctx, id, "resume") +} + +// doTransition posts an empty body to a MicroVM transition sub-resource +// (e.g. /pause, /resume) and decodes the returned MicroVM. +func (s *MicroVMsServiceOp) doTransition(ctx context.Context, id, action string) (*MicroVM, *Response, error) { + if id == "" { + return nil, nil, NewArgError("id", "cannot be empty") + } + + path := fmt.Sprintf("%s/%s/%s", microVMBasePath, id, action) + + req, err := s.client.NewRequest(ctx, http.MethodPost, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(microVMRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root.MicroVM, resp, nil +} + +// Delete removes a MicroVM by its ID. The DigitalOcean API returns a 204 +// on success and does not include a response body. +func (s *MicroVMsServiceOp) Delete(ctx context.Context, id string) (*Response, error) { + if id == "" { + return nil, NewArgError("id", "cannot be empty") + } + + path := fmt.Sprintf("%s/%s", microVMBasePath, id) + + req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// ListCheckpoints lists checkpoints for the authenticated team. Pass a +// MicroVMID on opt to filter to checkpoints captured from that MicroVM. +func (s *MicroVMsServiceOp) ListCheckpoints(ctx context.Context, opt *ListMicroVMCheckpointsOptions) ([]MicroVMCheckpoint, *Response, error) { + path := microVMCheckpointsBasePath + path, err := addOptions(path, opt) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(microVMCheckpointsRoot) + resp, err := s.client.Do(ctx, req, root) + 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.Checkpoints, resp, nil +} + +// CreateCheckpoint starts an asynchronous checkpoint of a running MicroVM. +func (s *MicroVMsServiceOp) CreateCheckpoint(ctx context.Context, microVMID string, createRequest *MicroVMCheckpointCreateRequest) (*MicroVMCheckpoint, *Response, error) { + if microVMID == "" { + return nil, nil, NewArgError("microVMID", "cannot be empty") + } + if createRequest == nil { + createRequest = &MicroVMCheckpointCreateRequest{} + } + + path := fmt.Sprintf("%s/%s/checkpoints", microVMBasePath, microVMID) + + req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest) + if err != nil { + return nil, nil, err + } + + root := new(microVMCheckpointRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root.Checkpoint, resp, nil +} + +// GetCheckpoint retrieves a checkpoint by its ID. +func (s *MicroVMsServiceOp) GetCheckpoint(ctx context.Context, id string) (*MicroVMCheckpoint, *Response, error) { + if id == "" { + return nil, nil, NewArgError("id", "cannot be empty") + } + + path := fmt.Sprintf("%s/%s", microVMCheckpointsBasePath, id) + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(microVMCheckpointRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root.Checkpoint, resp, nil +} + +// DeleteCheckpoint releases the state stored by a checkpoint. Returns a 204 +// on success with no response body. +func (s *MicroVMsServiceOp) DeleteCheckpoint(ctx context.Context, id string) (*Response, error) { + if id == "" { + return nil, NewArgError("id", "cannot be empty") + } + + path := fmt.Sprintf("%s/%s", microVMCheckpointsBasePath, id) + + req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, err + } + + return s.client.Do(ctx, req, nil) +} + +// GetCreateOptions returns the sizes, the regions each one can be created in, +// the feature gates, and the account limits available to the authenticated +// team when creating a MicroVM. +func (s *MicroVMsServiceOp) GetCreateOptions(ctx context.Context) (*MicroVMCreateOptions, *Response, error) { + req, err := s.client.NewRequest(ctx, http.MethodGet, microVMOptionsPath, nil) + if err != nil { + return nil, nil, err + } + + opts := new(MicroVMCreateOptions) + resp, err := s.client.Do(ctx, req, opts) + if err != nil { + return nil, resp, err + } + + return opts, resp, nil +} diff --git a/vendor/github.com/digitalocean/godo/prepayment.go b/vendor/github.com/digitalocean/godo/prepayment.go new file mode 100644 index 000000000..2b9cf4d18 --- /dev/null +++ b/vendor/github.com/digitalocean/godo/prepayment.go @@ -0,0 +1,96 @@ +package godo + +import ( + "context" + "net/http" + "time" +) + +// PrepaymentService is an interface for interfacing with the Prepayment +// endpoints of the DigitalOcean API. +type PrepaymentService interface { + GetConfig(context.Context) (*PrepaymentConfigResponse, *Response, error) + GetStatus(context.Context) (*PrepaymentStatusResponse, *Response, error) +} + +// PrepaymentServiceOp handles communication with the Prepayment related methods of +// the DigitalOcean API. +type PrepaymentServiceOp struct { + client *Client +} + +var _ PrepaymentService = &PrepaymentServiceOp{} + +// PrepaymentConfig represents prepayment gate configuration for an account. +type PrepaymentConfig struct { + SpendLimit string `json:"spend_limit"` + IsAutoPrepayEnabled bool `json:"is_auto_prepay_enabled"` + PrepayAmount string `json:"prepay_amount"` + PrepayThreshold string `json:"prepay_threshold"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` +} + +// PrepaymentStatus represents prepayment gate status for an account. +type PrepaymentStatus struct { + Balance string `json:"balance"` + IsAutoPrepayEnabled bool `json:"is_auto_prepay_enabled"` + Blocked bool `json:"blocked"` + Eligible bool `json:"eligible"` + MonthToDateBalance string `json:"month_to_date_balance"` +} + +// PrepaymentConfigResponse is the response from the public prepayment config endpoint. +type PrepaymentConfigResponse struct { + Config *PrepaymentConfig `json:"config"` + Status *PrepaymentStatus `json:"status"` +} + +func (r PrepaymentConfigResponse) String() string { + return Stringify(r) +} + +// PrepaymentStatusResponse is the response from the public prepayment status endpoint. +type PrepaymentStatusResponse struct { + Status *PrepaymentStatus `json:"status"` +} + +func (r PrepaymentStatusResponse) String() string { + return Stringify(r) +} + +// GetConfig retrieves the authenticated customer's prepayment configuration and status. +func (s *PrepaymentServiceOp) GetConfig(ctx context.Context) (*PrepaymentConfigResponse, *Response, error) { + path := "v2/customers/my/prepayment_config" + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(PrepaymentConfigResponse) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// GetStatus retrieves the authenticated customer's prepayment status. +func (s *PrepaymentServiceOp) GetStatus(ctx context.Context) (*PrepaymentStatusResponse, *Response, error) { + path := "v2/customers/my/prepayment_status" + + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(PrepaymentStatusResponse) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 5ead63ac8..66ba3998b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -33,7 +33,7 @@ github.com/coreos/go-systemd/v22/journal # github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc ## explicit github.com/davecgh/go-spew/spew -# github.com/digitalocean/godo v1.208.0 +# github.com/digitalocean/godo v1.210.0 ## explicit; go 1.23.0 github.com/digitalocean/godo github.com/digitalocean/godo/metrics