From 2fce7e80bbde13277dd0bc6f4948ce3b98f1511c Mon Sep 17 00:00:00 2001 From: mondragonfx <35617339+mondragonfx@users.noreply.github.com> Date: Tue, 4 Mar 2025 17:06:02 -0500 Subject: [PATCH] Update govultr from v3.11.2 to v3.15.0 (#290) * Update govultr from v3.11.2 to v3.15.0 * Add SSL delete functions * Update vendored code --- go.mod | 2 +- go.sum | 2 + .../github.com/vultr/govultr/v3/CHANGELOG.md | 33 +++ vendor/github.com/vultr/govultr/v3/account.go | 45 ++++ vendor/github.com/vultr/govultr/v3/billing.go | 29 ++ .../github.com/vultr/govultr/v3/database.go | 35 +-- vendor/github.com/vultr/govultr/v3/govultr.go | 66 ++--- .../vultr/govultr/v3/load_balancer.go | 45 +++- .../govultr/v3/virtual_file_system_storage.go | 255 ++++++++++++++++++ vendor/modules.txt | 4 +- vultr/fakeclient.go | 10 + 11 files changed, 471 insertions(+), 55 deletions(-) create mode 100644 vendor/github.com/vultr/govultr/v3/virtual_file_system_storage.go diff --git a/go.mod b/go.mod index 765ec1f4c..6d541f6fe 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.24 require ( github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 github.com/spf13/pflag v1.0.5 - github.com/vultr/govultr/v3 v3.11.2 + github.com/vultr/govultr/v3 v3.15.0 github.com/vultr/metadata v1.1.0 golang.org/x/oauth2 v0.23.0 k8s.io/api v0.31.1 diff --git a/go.sum b/go.sum index 9786094d1..7bd7364ff 100644 --- a/go.sum +++ b/go.sum @@ -257,6 +257,8 @@ github.com/vultr/govultr/v3 v3.9.1 h1:uxSIb8Miel7tqTs3ee+z3t+JelZikwqBBsZzCOPBy/ github.com/vultr/govultr/v3 v3.9.1/go.mod h1:Rd8ebpXm7jxH3MDmhnEs+zrlYW212ouhx+HeUMfHm2o= github.com/vultr/govultr/v3 v3.11.2 h1:F3QBuWb9mz3ZOecmVKm31dRAJ5f8fe279+dxZDpS64c= github.com/vultr/govultr/v3 v3.11.2/go.mod h1:q34Wd76upKmf+vxFMgaNMH3A8BbsPBmSYZUGC8oZa5w= +github.com/vultr/govultr/v3 v3.15.0 h1:hvc5MqKr9FSYFdK0pAAq8ta/JvQiuYPv6x3LKuDUPDc= +github.com/vultr/govultr/v3 v3.15.0/go.mod h1:WO5RKj6HvR4KNXsnCW1+28ak2UofTNhFC5ytaS/kf78= github.com/vultr/metadata v1.1.0 h1:RUjCnH5Mdlz7uuyfb1jOZNkU72zl/HwK76jLzVFdiOo= github.com/vultr/metadata v1.1.0/go.mod h1:4yocaI6h2EFJzwN0m1KnnC/vDCx2axIqnyxmtF/LWoQ= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= diff --git a/vendor/github.com/vultr/govultr/v3/CHANGELOG.md b/vendor/github.com/vultr/govultr/v3/CHANGELOG.md index 0c0d6a4d1..336303f96 100644 --- a/vendor/github.com/vultr/govultr/v3/CHANGELOG.md +++ b/vendor/github.com/vultr/govultr/v3/CHANGELOG.md @@ -1,4 +1,37 @@ # Change Log +## [3.15.0](https://github.com/vultr/govultr/compare/v3.14.1...v3.15.0) (2025-03-04) +### Enhancements +* Add functions for account bandwidth [PR 356](https://github.com/vultr/govultr/pull/356) +* Add functions for billing pending charges [PR 357](https://github.com/vultr/govultr/pull/357) + +### Dependencies +* Update Go from v1.23 to v1.24 [PR 360](https://github.com/vultr/govultr/pull/360) + +### Clean Up +* Fix whitespace [PR 359](https://github.com/vultr/govultr/pull/359) + +### New Contributors +* @DazWilkin made their first contribution in [PR 356](https://github.com/vultr/govultr/pull/356) + +## [3.14.1](https://github.com/vultr/govultr/compare/v3.14.0...v3.14.1) (2025-01-17) +### Bug Fixes +* Load Balancers: Add missing SSL fields and AutoSSL struct [PR 352](https://github.com/vultr/govultr/pull/352) + +## [3.14.0](https://github.com/vultr/govultr/compare/v3.13.0...v3.14.0) (2025-01-15) +### Enhancements +* Load Balancers: Add support for AutoSSL and GlobalRegions [PR 350](https://github.com/vultr/govultr/pull/350) + +### Clean Up +* Database: Remove deprecated Redis references [PR 349](https://github.com/vultr/govultr/pull/349) + +## [3.13.0](https://github.com/vultr/govultr/compare/v3.12.0...v3.13.0) (2024-12-17) +### Enhancements +* VFS Storage: Add support for virtual file system storages [PR 347](https://github.com/vultr/govultr/pull/347) + +## [3.12.0]( https://github.com/vultr/govultr/compare/v3.11.2...v3.12.0) (2024-11-22) +### Clean Up +* Database: Deprecate Redis-Named Fields [PR 345](https://github.com/vultr/govultr/pull/345) + ## [3.11.2]( https://github.com/vultr/govultr/compare/v3.11.1...v3.11.2) (2024-10-30) ### Bug fixes * Database: Fix Kafka advanced config field names [PR 343](https://github.com/vultr/govultr/pull/343) diff --git a/vendor/github.com/vultr/govultr/v3/account.go b/vendor/github.com/vultr/govultr/v3/account.go index 1a6af3c86..668df01ac 100644 --- a/vendor/github.com/vultr/govultr/v3/account.go +++ b/vendor/github.com/vultr/govultr/v3/account.go @@ -9,6 +9,7 @@ import ( // Link : https://www.vultr.com/api/#tag/account type AccountService interface { Get(ctx context.Context) (*Account, *http.Response, error) + GetBandwidth(ctx context.Context) (*AccountBandwidth, *http.Response, error) } // AccountServiceHandler handles interaction with the account methods for the Vultr API @@ -31,6 +32,33 @@ type Account struct { ACL []string `json:"acls"` } +type accountBandwidthBase struct { + Bandwidth *AccountBandwidth `json:"bandwidth"` +} + +// Bandwidth represents a Vultr account bandwidth +type AccountBandwidth struct { + PreviousMonth AccountBandwidthPeriod `json:"previous_month"` + CurrentMonthToDate AccountBandwidthPeriod `json:"current_month_to_date"` + CurrentMonthProjected AccountBandwidthPeriod `json:"current_month_projected"` +} + +// AccountBandwidthPeriod represents a Vultr account bandwidth period +type AccountBandwidthPeriod struct { + TimestampStart string `json:"timestamp_start"` + TimestampEnd string `json:"timestamp_end"` + GBIn int `json:"gb_in"` + GBOut int `json:"gb_out"` + TotalInstanceHours int `json:"total_instance_hours"` + TotalInstanceCount int `json:"total_instance_count"` + InstanceBandwidthCredits int `json:"instance_bandwidth_credits"` + FreeBandwidthCredits int `json:"free_bandwidth_credits"` + PurchasedBandwidthCredits int `json:"purchased_bandwidth_credits"` + Overage float32 `json:"overage"` + OverageUnitCost float32 `json:"overage_unit_cost"` + OverageCost float32 `json:"overage_cost"` +} + // Get Vultr account info func (a *AccountServiceHandler) Get(ctx context.Context) (*Account, *http.Response, error) { uri := "/v2/account" @@ -47,3 +75,20 @@ func (a *AccountServiceHandler) Get(ctx context.Context) (*Account, *http.Respon return account.Account, resp, nil } + +// Get Vultr account bandwidth info +func (a *AccountServiceHandler) GetBandwidth(ctx context.Context) (*AccountBandwidth, *http.Response, error) { + uri := "/v2/account/bandwidth" + req, err := a.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, nil, err + } + + accountBandwidth := new(accountBandwidthBase) + resp, err := a.client.DoWithContext(ctx, req, accountBandwidth) + if err != nil { + return nil, resp, err + } + + return accountBandwidth.Bandwidth, resp, nil +} diff --git a/vendor/github.com/vultr/govultr/v3/billing.go b/vendor/github.com/vultr/govultr/v3/billing.go index f1dd15ce5..46d336263 100644 --- a/vendor/github.com/vultr/govultr/v3/billing.go +++ b/vendor/github.com/vultr/govultr/v3/billing.go @@ -15,6 +15,7 @@ type BillingService interface { ListInvoices(ctx context.Context, options *ListOptions) ([]Invoice, *Meta, *http.Response, error) GetInvoice(ctx context.Context, invoiceID string) (*Invoice, *http.Response, error) ListInvoiceItems(ctx context.Context, invoiceID int, options *ListOptions) ([]InvoiceItem, *Meta, *http.Response, error) + ListPendingCharges(ctx context.Context, options *ListOptions) ([]InvoiceItem, *http.Response, error) } // BillingServiceHandler handles interaction with the billing methods for the Vultr API @@ -72,6 +73,10 @@ type invoiceItemsBase struct { Meta *Meta `json:"meta"` } +type pendingChargesBase struct { + PendingCharges []InvoiceItem `json:"pending_charges"` +} + // ListHistory retrieves a list of all billing history on the current account func (b *BillingServiceHandler) ListHistory(ctx context.Context, options *ListOptions) ([]History, *Meta, *http.Response, error) { //nolint:dupl,lll uri := "/v2/billing/history" @@ -161,3 +166,27 @@ func (b *BillingServiceHandler) ListInvoiceItems(ctx context.Context, invoiceID return invoice.InvoiceItems, invoice.Meta, resp, nil } + +// ListPendingCharges retrieves a list of all pending charges on the current account +func (b *BillingServiceHandler) ListPendingCharges(ctx context.Context, options *ListOptions) ([]InvoiceItem, *http.Response, error) { + uri := "/v2/billing/pending-charges" + req, err := b.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, nil, err + } + + newValues, err := query.Values(options) + if err != nil { + return nil, nil, err + } + + req.URL.RawQuery = newValues.Encode() + + invoice := new(pendingChargesBase) + resp, err := b.client.DoWithContext(ctx, req, invoice) + if err != nil { + return nil, resp, err + } + + return invoice.PendingCharges, resp, nil +} diff --git a/vendor/github.com/vultr/govultr/v3/database.go b/vendor/github.com/vultr/govultr/v3/database.go index 1e6b25815..a1a286973 100644 --- a/vendor/github.com/vultr/govultr/v3/database.go +++ b/vendor/github.com/vultr/govultr/v3/database.go @@ -103,9 +103,10 @@ type DatabasePlan struct { // SupportedEngines represents an object containing supported database engine types for Managed Database plans type SupportedEngines struct { - MySQL *bool `json:"mysql"` - PG *bool `json:"pg"` - Redis *bool `json:"redis"` + MySQL *bool `json:"mysql"` + PG *bool `json:"pg"` + Valkey *bool `json:"valkey"` + Kafka *bool `json:"kafka"` } // MaxConnections represents an object containing the maximum number of connections by engine type for Managed Database plans @@ -163,7 +164,7 @@ type Database struct { MySQLSlowQueryLog *bool `json:"mysql_slow_query_log,omitempty"` MySQLLongQueryTime int `json:"mysql_long_query_time,omitempty"` PGAvailableExtensions []PGExtension `json:"pg_available_extensions,omitempty"` - RedisEvictionPolicy string `json:"redis_eviction_policy,omitempty"` + EvictionPolicy string `json:"eviction_policy,omitempty"` ClusterTimeZone string `json:"cluster_time_zone,omitempty"` ReadReplicas []Database `json:"read_replicas,omitempty"` } @@ -211,7 +212,7 @@ type DatabaseCreateReq struct { MySQLRequirePrimaryKey *bool `json:"mysql_require_primary_key,omitempty"` MySQLSlowQueryLog *bool `json:"mysql_slow_query_log,omitempty"` MySQLLongQueryTime int `json:"mysql_long_query_time,omitempty"` - RedisEvictionPolicy string `json:"redis_eviction_policy,omitempty"` + EvictionPolicy string `json:"eviction_policy,omitempty"` } // DatabaseUpdateReq struct used to update a dataase. @@ -229,7 +230,7 @@ type DatabaseUpdateReq struct { MySQLRequirePrimaryKey *bool `json:"mysql_require_primary_key,omitempty"` MySQLSlowQueryLog *bool `json:"mysql_slow_query_log,omitempty"` MySQLLongQueryTime int `json:"mysql_long_query_time,omitempty"` - RedisEvictionPolicy string `json:"redis_eviction_policy,omitempty"` + EvictionPolicy string `json:"eviction_policy,omitempty"` } // DatabaseUsage represents disk, memory, and CPU usage for a Managed Database @@ -274,21 +275,21 @@ type DatabaseUser struct { AccessCert string `json:"access_cert,omitempty"` } -// DatabaseUserACL represents an access control configuration for a user within a Redis Managed Database cluster +// DatabaseUserACL represents an access control configuration for a user within a Valkey Managed Database cluster type DatabaseUserACL struct { - RedisACLCategories []string `json:"redis_acl_categories"` - RedisACLChannels []string `json:"redis_acl_channels"` - RedisACLCommands []string `json:"redis_acl_commands"` - RedisACLKeys []string `json:"redis_acl_keys"` + ACLCategories []string `json:"acl_categories"` + ACLChannels []string `json:"acl_channels"` + ACLCommands []string `json:"acl_commands"` + ACLKeys []string `json:"acl_keys"` } // DatabaseUserACLReq represents input for updating a user's access control within a Managed Database cluster type DatabaseUserACLReq struct { - RedisACLCategories *[]string `json:"redis_acl_categories,omitempty"` - RedisACLChannels *[]string `json:"redis_acl_channels,omitempty"` - RedisACLCommands *[]string `json:"redis_acl_commands,omitempty"` - RedisACLKeys *[]string `json:"redis_acl_keys,omitempty"` - Permission string `json:"permission,omitempty"` + ACLCategories *[]string `json:"acl_categories,omitempty"` + ACLChannels *[]string `json:"acl_channels,omitempty"` + ACLCommands *[]string `json:"acl_commands,omitempty"` + ACLKeys *[]string `json:"acl_keys,omitempty"` + Permission string `json:"permission,omitempty"` } // databaseUserBase holds the API response for retrieving a single database user within a Managed Database @@ -910,7 +911,7 @@ func (d *DatabaseServiceHandler) DeleteUser(ctx context.Context, databaseID, use return err } -// UpdateUserACL will update a user's access control within the Redis Managed Database +// UpdateUserACL will update a user's access control within the Valkey Managed Database func (d *DatabaseServiceHandler) UpdateUserACL(ctx context.Context, databaseID, username string, databaseUserACLReq *DatabaseUserACLReq) (*DatabaseUser, *http.Response, error) { //nolint:lll,dupl uri := fmt.Sprintf("%s/%s/users/%s/access-control", databasePath, databaseID, username) diff --git a/vendor/github.com/vultr/govultr/v3/govultr.go b/vendor/github.com/vultr/govultr/v3/govultr.go index 3727ce1c2..73ee82537 100644 --- a/vendor/github.com/vultr/govultr/v3/govultr.go +++ b/vendor/github.com/vultr/govultr/v3/govultr.go @@ -19,7 +19,7 @@ import ( ) const ( - version = "3.11.2" + version = "3.15.0" defaultBase = "https://api.vultr.com" userAgent = "govultr/" + version rateLimit = 500 * time.Millisecond @@ -41,37 +41,38 @@ type Client struct { UserAgent string // Services used to interact with the API - Account AccountService - Application ApplicationService - Backup BackupService - BareMetalServer BareMetalServerService - Billing BillingService - BlockStorage BlockStorageService - CDN CDNService - ContainerRegistry ContainerRegistryService - Database DatabaseService - Domain DomainService - DomainRecord DomainRecordService - FirewallGroup FirewallGroupService - FirewallRule FireWallRuleService - Instance InstanceService - ISO ISOService - Kubernetes KubernetesService - LoadBalancer LoadBalancerService - Marketplace MarketplaceService - ObjectStorage ObjectStorageService - OS OSService - Plan PlanService - Region RegionService - ReservedIP ReservedIPService - Inference InferenceService - Snapshot SnapshotService - SSHKey SSHKeyService - StartupScript StartupScriptService - SubAccount SubAccountService - User UserService - VPC VPCService - VPC2 VPC2Service + Account AccountService + Application ApplicationService + Backup BackupService + BareMetalServer BareMetalServerService + Billing BillingService + BlockStorage BlockStorageService + CDN CDNService + ContainerRegistry ContainerRegistryService + Database DatabaseService + Domain DomainService + DomainRecord DomainRecordService + FirewallGroup FirewallGroupService + FirewallRule FireWallRuleService + Instance InstanceService + ISO ISOService + Kubernetes KubernetesService + LoadBalancer LoadBalancerService + Marketplace MarketplaceService + ObjectStorage ObjectStorageService + OS OSService + Plan PlanService + Region RegionService + ReservedIP ReservedIPService + Inference InferenceService + Snapshot SnapshotService + SSHKey SSHKeyService + StartupScript StartupScriptService + SubAccount SubAccountService + User UserService + VirtualFileSystemStorage VirtualFileSystemStorageService + VPC VPCService + VPC2 VPC2Service // Optional function called after every successful request made to the Vultr API onRequestCompleted RequestCompletionCallback @@ -144,6 +145,7 @@ func NewClient(httpClient *http.Client) *Client { client.StartupScript = &StartupScriptServiceHandler{client} client.SubAccount = &SubAccountServiceHandler{client} client.User = &UserServiceHandler{client} + client.VirtualFileSystemStorage = &VirtualFileSystemStorageServiceHandler{client} client.VPC = &VPCServiceHandler{client} client.VPC2 = &VPC2ServiceHandler{client} diff --git a/vendor/github.com/vultr/govultr/v3/load_balancer.go b/vendor/github.com/vultr/govultr/v3/load_balancer.go index 37e0ff845..3b8fa03b1 100644 --- a/vendor/github.com/vultr/govultr/v3/load_balancer.go +++ b/vendor/github.com/vultr/govultr/v3/load_balancer.go @@ -17,6 +17,8 @@ type LoadBalancerService interface { Get(ctx context.Context, lbID string) (*LoadBalancer, *http.Response, error) Update(ctx context.Context, lbID string, updateReq *LoadBalancerReq) error Delete(ctx context.Context, lbID string) error + DeleteSSL(ctx context.Context, lbID string) error + DeleteAutoSSL(ctx context.Context, lbID string) error List(ctx context.Context, options *ListOptions) ([]LoadBalancer, *Meta, *http.Response, error) CreateForwardingRule(ctx context.Context, lbID string, rule *ForwardingRule) (*ForwardingRule, *http.Response, error) GetForwardingRule(ctx context.Context, lbID string, ruleID string) (*ForwardingRule, *http.Response, error) @@ -45,10 +47,12 @@ type LoadBalancer struct { HealthCheck *HealthCheck `json:"health_check,omitempty"` GenericInfo *GenericInfo `json:"generic_info,omitempty"` SSLInfo *bool `json:"has_ssl,omitempty"` + AutoSSL *AutoSSL `json:"auto_ssl,omitempty"` HTTP2 *bool `json:"http2,omitempty"` HTTP3 *bool `json:"http3,omitempty"` ForwardingRules []ForwardingRule `json:"forwarding_rules,omitempty"` FirewallRules []LBFirewallRule `json:"firewall_rules,omitempty"` + GlobalRegions []string `json:"global_regions,omitempty"` } // LoadBalancerReq gives options for creating or updating a load balancer @@ -61,6 +65,7 @@ type LoadBalancerReq struct { StickySessions *StickySessions `json:"sticky_session,omitempty"` ForwardingRules []ForwardingRule `json:"forwarding_rules,omitempty"` SSL *SSL `json:"ssl,omitempty"` + AutoSSL *AutoSSL `json:"auto_ssl,omitempty"` SSLRedirect *bool `json:"ssl_redirect,omitempty"` HTTP2 *bool `json:"http2,omitempty"` HTTP3 *bool `json:"http3,omitempty"` @@ -69,6 +74,7 @@ type LoadBalancerReq struct { FirewallRules []LBFirewallRule `json:"firewall_rules,omitempty"` Timeout int `json:"timeout,omitempty"` VPC *string `json:"vpc,omitempty"` + GlobalRegions []string `json:"global_regions,omitempty"` } // InstanceList represents instances that are attached to your load balancer @@ -126,9 +132,18 @@ type LBFirewallRule struct { // SSL represents valid SSL config type SSL struct { - PrivateKey string `json:"private_key,omitempty"` - Certificate string `json:"certificate,omitempty"` - Chain string `json:"chain,omitempty"` + PrivateKey string `json:"private_key,omitempty"` + Certificate string `json:"certificate,omitempty"` + Chain string `json:"chain,omitempty"` + PrivateKeyB64 string `json:"private_key_b64,omitempty"` + CertificateB64 string `json:"certificate_b64,omitempty"` + ChainB64 string `json:"chain_b64,omitempty"` +} + +// AutoSSL represents valid AutoSSL config +type AutoSSL struct { + DomainZone string `json:"domain_zone"` + DomainSub string `json:"domain_sub,omitempty"` } type lbsBase struct { @@ -348,3 +363,27 @@ func (l *LoadBalancerHandler) ListFirewallRules(ctx context.Context, lbID string return fwRules.FirewallRules, fwRules.Meta, resp, nil } + +// DeleteSSL removes the SSL configuration from a load balancer subscription. +func (l *LoadBalancerHandler) DeleteSSL(ctx context.Context, lbID string) error { + uri := fmt.Sprintf("%s/%s/ssl", lbPath, lbID) + req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil) + if err != nil { + return err + } + + _, err = l.client.DoWithContext(ctx, req, nil) + return err +} + +// DeleteAutoSSL removes the AutoSSL configuration from a load balancer subscription. +func (l *LoadBalancerHandler) DeleteAutoSSL(ctx context.Context, lbID string) error { + uri := fmt.Sprintf("%s/%s/auto_ssl", lbPath, lbID) + req, err := l.client.NewRequest(ctx, http.MethodDelete, uri, nil) + if err != nil { + return err + } + + _, err = l.client.DoWithContext(ctx, req, nil) + return err +} diff --git a/vendor/github.com/vultr/govultr/v3/virtual_file_system_storage.go b/vendor/github.com/vultr/govultr/v3/virtual_file_system_storage.go new file mode 100644 index 000000000..b8cc0f112 --- /dev/null +++ b/vendor/github.com/vultr/govultr/v3/virtual_file_system_storage.go @@ -0,0 +1,255 @@ +package govultr + +import ( + "context" + "fmt" + "net/http" + + "github.com/google/go-querystring/query" +) + +const virtualFileSystemStoragePath = "/v2/vfs" + +// VirtualFileSystemStorageService is the interface to interact with virtual +// file system endpoint on the Vultr API +// Link : https://www.vultr.com/api/#tag/vfs +type VirtualFileSystemStorageService interface { + Create(ctx context.Context, vfsReq *VirtualFileSystemStorageReq) (*VirtualFileSystemStorage, *http.Response, error) + Get(ctx context.Context, vfsID string) (*VirtualFileSystemStorage, *http.Response, error) + Update(ctx context.Context, vfsID string, vfsUpdateReq *VirtualFileSystemStorageUpdateReq) (*VirtualFileSystemStorage, *http.Response, error) //nolint:lll + Delete(ctx context.Context, vfsID string) error + List(ctx context.Context, options *ListOptions) ([]VirtualFileSystemStorage, *Meta, *http.Response, error) + + AttachmentList(ctx context.Context, vfsID string) ([]VirtualFileSystemStorageAttachment, *http.Response, error) + AttachmentGet(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error) + Attach(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error) + Detach(ctx context.Context, vfsID, targetID string) error +} + +// VirtualFileSystemStorageServiceHandler handles interaction with the virtual +// file system methods for the Vultr API. +type VirtualFileSystemStorageServiceHandler struct { + client *Client +} + +// VirtualFileSystemStorage represents a virtual file system storage. +type VirtualFileSystemStorage struct { + ID string `json:"id"` + Region string `json:"region"` + DateCreated string `json:"date_created"` + Status string `json:"status"` + Label string `json:"label"` + Tags []string `json:"tags"` + DiskType string `json:"disk_type"` + StorageSize VirtualFileSystemStorageSize `json:"storage_size"` + StorageUsed VirtualFileSystemStorageSize `json:"storage_used"` + Billing VirtualFileSystemStorageBilling `json:"billing"` +} + +// VirtualFileSystemStorageSize represents the on disk size of a virtual file +// system storage. +type VirtualFileSystemStorageSize struct { + SizeBytes int `json:"bytes,omitempty"` + SizeGB int `json:"gb"` +} + +// VirtualFileSystemStorageBilling represents the billing data of a virtual +// file system storage. +type VirtualFileSystemStorageBilling struct { + Charges float32 `json:"charges"` + Monthly float32 `json:"monthly"` +} + +type virtualFileSystemStoragesBase struct { + VFSs []VirtualFileSystemStorage `json:"vfs"` + Meta *Meta `json:"meta"` +} + +// VirtualFileSystemStorageReq struct represents the request used when creating +// a virtual file system storage. +type VirtualFileSystemStorageReq struct { + Region string `json:"region"` + Label string `json:"label"` + StorageSize VirtualFileSystemStorageSize `json:"storage_size"` + DiskType string `json:"disk_type,omitempty"` + Tags []string `json:"tags,omitempty"` +} + +// VirtualFileSystemStorageUpdateReq struct represents the request used when +// updating virtual file system storage. +type VirtualFileSystemStorageUpdateReq struct { + Label string `json:"label,omitempty"` + StorageSize VirtualFileSystemStorageSize `json:"storage_size"` +} + +// VirtualFileSystemStorageAttachment represents an attachment for a virtual +// file system. +type VirtualFileSystemStorageAttachment struct { + ID string `json:"vfs_id"` + State string `json:"state"` + TargetID string `json:"target_id"` + MountTag int `json:"mount_tag"` +} + +type virtualFileSystemStorageAttachmentsBase struct { + Attachments []VirtualFileSystemStorageAttachment `json:"attachments"` +} + +// Create sends a create request for a virtual file system storage. +func (f *VirtualFileSystemStorageServiceHandler) Create(ctx context.Context, vfsReq *VirtualFileSystemStorageReq) (*VirtualFileSystemStorage, *http.Response, error) { //nolint:lll + req, err := f.client.NewRequest(ctx, http.MethodPost, virtualFileSystemStoragePath, vfsReq) + if err != nil { + return nil, nil, err + } + + vfs := new(VirtualFileSystemStorage) + resp, err := f.client.DoWithContext(ctx, req, vfs) + if err != nil { + return nil, resp, err + } + + return vfs, resp, nil +} + +// Get retrieves a single virtual file system storage. +func (f *VirtualFileSystemStorageServiceHandler) Get(ctx context.Context, vfsID string) (*VirtualFileSystemStorage, *http.Response, error) { + uri := fmt.Sprintf("%s/%s", virtualFileSystemStoragePath, vfsID) + + req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, nil, err + } + + vfs := new(VirtualFileSystemStorage) + resp, err := f.client.DoWithContext(ctx, req, vfs) + if err != nil { + return nil, resp, err + } + + return vfs, resp, nil +} + +// Update sends a update request for a virtual file system storage. +func (f *VirtualFileSystemStorageServiceHandler) Update(ctx context.Context, vfsID string, vfsUpdateReq *VirtualFileSystemStorageUpdateReq) (*VirtualFileSystemStorage, *http.Response, error) { //nolint:lll + uri := fmt.Sprintf("%s/%s", virtualFileSystemStoragePath, vfsID) + + req, err := f.client.NewRequest(ctx, http.MethodPut, uri, vfsUpdateReq) + if err != nil { + return nil, nil, err + } + + vfs := new(VirtualFileSystemStorage) + resp, err := f.client.DoWithContext(ctx, req, vfs) + if err != nil { + return nil, resp, err + } + return vfs, resp, err +} + +// Delete sends a delete request for a virtual file system storage. +func (f *VirtualFileSystemStorageServiceHandler) Delete(ctx context.Context, vfsID string) error { + uri := fmt.Sprintf("%s/%s", virtualFileSystemStoragePath, vfsID) + + req, err := f.client.NewRequest(ctx, http.MethodDelete, uri, nil) + if err != nil { + return err + } + _, err = f.client.DoWithContext(ctx, req, nil) + return err +} + +// List retrieves a list of all virtual file system storages. +func (f *VirtualFileSystemStorageServiceHandler) List(ctx context.Context, options *ListOptions) ([]VirtualFileSystemStorage, *Meta, *http.Response, error) { //nolint:dupl,lll + req, err := f.client.NewRequest(ctx, http.MethodGet, virtualFileSystemStoragePath, nil) + if err != nil { + return nil, nil, nil, err + } + + newValues, err := query.Values(options) + if err != nil { + return nil, nil, nil, err + } + + req.URL.RawQuery = newValues.Encode() + + vfsStorages := new(virtualFileSystemStoragesBase) + resp, err := f.client.DoWithContext(ctx, req, vfsStorages) + if err != nil { + return nil, nil, resp, err + } + + return vfsStorages.VFSs, vfsStorages.Meta, resp, nil +} + +// Attach attaches a virtual file system storage to another instance. +func (f *VirtualFileSystemStorageServiceHandler) Attach(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error) { //nolint:lll + uri := fmt.Sprintf("%s/%s/attachments/%s", virtualFileSystemStoragePath, vfsID, targetID) + + req, err := f.client.NewRequest(ctx, http.MethodPut, uri, nil) + if err != nil { + return nil, nil, err + } + + att := new(VirtualFileSystemStorageAttachment) + resp, err := f.client.DoWithContext(ctx, req, att) + if err != nil { + return nil, resp, err + } + + return att, resp, err +} + +// AttachmentList retrieves a list the active attachments on a virtual file +// system storage. +func (f *VirtualFileSystemStorageServiceHandler) AttachmentList(ctx context.Context, vfsID string) ([]VirtualFileSystemStorageAttachment, *http.Response, error) { //nolint:lll + uri := fmt.Sprintf("%s/%s/attachments", virtualFileSystemStoragePath, vfsID) + + req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, nil, err + } + + atts := new(virtualFileSystemStorageAttachmentsBase) + resp, err := f.client.DoWithContext(ctx, req, atts) + if err != nil { + return nil, resp, err + } + + return atts.Attachments, resp, err +} + +// AttachmentGet retrieves the attachment of a virtual file system storage and +// its attached instance. +func (f *VirtualFileSystemStorageServiceHandler) AttachmentGet(ctx context.Context, vfsID, targetID string) (*VirtualFileSystemStorageAttachment, *http.Response, error) { //nolint:lll + uri := fmt.Sprintf("%s/%s/attachments/%s", virtualFileSystemStoragePath, vfsID, targetID) + + req, err := f.client.NewRequest(ctx, http.MethodGet, uri, nil) + if err != nil { + return nil, nil, err + } + + att := new(VirtualFileSystemStorageAttachment) + resp, err := f.client.DoWithContext(ctx, req, att) + if err != nil { + return nil, resp, err + } + + return att, resp, err +} + +// Detach sends a delete request for an attachment of a virtual file system +// storage, detaching it from its instance. +func (f *VirtualFileSystemStorageServiceHandler) Detach(ctx context.Context, vfsID, targetID string) error { + uri := fmt.Sprintf("%s/%s/attachments/%s", virtualFileSystemStoragePath, vfsID, targetID) + + req, err := f.client.NewRequest(ctx, http.MethodDelete, uri, nil) + if err != nil { + return err + } + + if _, err := f.client.DoWithContext(ctx, req, nil); err != nil { + return err + } + + return nil +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 4d9eb8119..514f85673 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -222,8 +222,8 @@ github.com/spf13/pflag # github.com/stoewer/go-strcase v1.3.0 ## explicit; go 1.11 github.com/stoewer/go-strcase -# github.com/vultr/govultr/v3 v3.11.2 -## explicit; go 1.23 +# github.com/vultr/govultr/v3 v3.15.0 +## explicit; go 1.24 github.com/vultr/govultr/v3 # github.com/vultr/metadata v1.1.0 ## explicit; go 1.17 diff --git a/vultr/fakeclient.go b/vultr/fakeclient.go index 02f42080a..8ee74be4b 100644 --- a/vultr/fakeclient.go +++ b/vultr/fakeclient.go @@ -270,6 +270,16 @@ func (f *fakeLB) Delete(_ context.Context, _ string) error { panic("implement me") } +// DeleteAutoSSL deletes AutoSSL (not implemented, yet) +func (f *fakeLB) DeleteAutoSSL(_ context.Context, _ string) error { + panic("implement me") +} + +// DeleteSSL deletes SSL (not implemented, yet) +func (f *fakeLB) DeleteSSL(_ context.Context, _ string) error { + panic("implement me") +} + // List gets loadbalancers func (f *fakeLB) List(_ context.Context, _ *govultr.ListOptions) ([]govultr.LoadBalancer, *govultr.Meta, *http.Response, error) { return []govultr.LoadBalancer{