Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup Gateway support #163

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/service/ecloud/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
return fmt.Sprintf("Image not found with ID [%s]", e.ID)
}

// HostSpecFoundError indicates an host spec was not found

Check notice on line 275 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'HostSpecNotFoundError ...' (with an optional leading article)
type HostSpecNotFoundError struct {
ID string
}
Expand All @@ -281,7 +281,7 @@
return fmt.Sprintf("Host spec not found with ID [%s]", e.ID)
}

// HostGroupFoundError indicates an host group was not found

Check notice on line 284 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'HostGroupNotFoundError ...' (with an optional leading article)
type HostGroupNotFoundError struct {
ID string
}
Expand All @@ -290,7 +290,7 @@
return fmt.Sprintf("Host group not found with ID [%s]", e.ID)
}

// SSHKeyPairFoundError indicates a SSH key pair was not found

Check notice on line 293 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'SSHKeyPairNotFoundError ...' (with an optional leading article)
type SSHKeyPairNotFoundError struct {
ID string
}
Expand All @@ -299,7 +299,7 @@
return fmt.Sprintf("SSH key pair not found with ID [%s]", e.ID)
}

// HostFoundError indicates an host was not found

Check notice on line 302 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'HostNotFoundError ...' (with an optional leading article)
type HostNotFoundError struct {
ID string
}
Expand All @@ -308,7 +308,7 @@
return fmt.Sprintf("Host not found with ID [%s]", e.ID)
}

// TaskFoundError indicates an task was not found

Check notice on line 311 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'TaskNotFoundError ...' (with an optional leading article)
type TaskNotFoundError struct {
ID string
}
Expand All @@ -317,7 +317,7 @@
return fmt.Sprintf("Task not found with ID [%s]", e.ID)
}

// NetworkPolicyFoundError indicates a network policy was not found

Check notice on line 320 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'NetworkPolicyNotFoundError ...' (with an optional leading article)
type NetworkPolicyNotFoundError struct {
ID string
}
Expand Down Expand Up @@ -398,7 +398,7 @@
return fmt.Sprintf("Load balancer not found with ID [%s]", e.ID)
}

// LoadBalancerNetworkNotFoundError indicates a load balancer spec was not found

Check notice on line 401 in pkg/service/ecloud/error.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'LoadBalancerSpecNotFoundError ...' (with an optional leading article)
type LoadBalancerSpecNotFoundError struct {
ID string
}
Expand Down Expand Up @@ -496,3 +496,21 @@
func (e *VPNGatewayUserNotFoundError) Error() string {
return fmt.Sprintf("VPN gateway user not found with ID [%s]", e.ID)
}

// BackupGatewaySpecificationNotFoundError represents a VPN gateway specification not found error
type BackupGatewaySpecificationNotFoundError struct {
ID string
}

func (e *BackupGatewaySpecificationNotFoundError) Error() string {
return fmt.Sprintf("Backup gateway specification not found with ID [%s]", e.ID)
}

// BackupGatewayNotFoundError represents a backup gateway not found error
type BackupGatewayNotFoundError struct {
ID string
}

func (e *BackupGatewayNotFoundError) Error() string {
return fmt.Sprintf("Backup gateway not found with ID [%s]", e.ID)
}
27 changes: 27 additions & 0 deletions pkg/service/ecloud/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@
RAMCapacity int `json:"ram_capacity"`
Locked bool `json:"locked"`
BackupEnabled bool `json:"backup_enabled"`
BackupGatewayID string `json:"backup_gateway_id"`
BackupAgentEnabled bool `json:"secure_backup"` // TODO: Change tag to 'backup_agent_enabled' when ADO#34659 released
IsEncrypted bool `json:"is_encrypted"`
Platform string `json:"platform"`
VolumeCapacity int `json:"volume_capacity"`
Expand Down Expand Up @@ -931,7 +933,7 @@
UpdatedAt connection.DateTime `json:"updated_at"`
}

// IP Address represents an eCloud VPC Network IP Address

Check notice on line 936 in pkg/service/ecloud/model.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'IPAddress ...' (with an optional leading article)
type IPAddress struct {
ID string `json:"id"`
Name string `json:"name"`
Expand Down Expand Up @@ -1063,3 +1065,28 @@
CreatedAt connection.DateTime `json:"created_at"`
UpdatedAt connection.DateTime `json:"updated_at"`
}

// BackupGatewaySpecification represents a Backup Gateway specification
type BackupGatewaySpecification struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
CPU int `json:"cpu"`
RAM int `json:"ram"`
IopsID string `json:"iops_id"`
VolumeCapacity int `json:"volume_capacity"`
ImageID string `json:"image_id"`
}

// BackupGateway represents a Backup Gateway
type BackupGateway struct {
ID string `json:"id"`
VPCID string `json:"vpc_id"`
Name string `json:"name"`
AvailabilityZoneID string `json:"availability_zone_id"`
GatewaySpecID string `json:"gateway_spec_id"`
Sync ResourceSync `json:"sync"`
Task ResourceTask `json:"task"`
CreatedAt connection.DateTime `json:"created_at"`
UpdatedAt connection.DateTime `json:"updated_at"`
}
13 changes: 13 additions & 0 deletions pkg/service/ecloud/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@
VolumeCapacity int `json:"volume_capacity"`
VolumeIOPS int `json:"volume_iops,omitempty"`
BackupEnabled bool `json:"backup_enabled"`
BackupGatewayID string `json:"backup_gateway_id,omitempty"`
BackupAgentEnabled bool `json:"secure_backup,omitempty"` // XXX: This will change in the future to `backup_agent_enabled`, see ADO#34659
IsEncrypted bool `json:"is_encrypted"`
NetworkID string `json:"network_id,omitempty"`
FloatingIPID string `json:"floating_ip_id,omitempty"`
Expand Down Expand Up @@ -544,7 +546,7 @@
NetworkID string `json:"network_id"`
}

// CreateLoadBalancerRequest represents a request to patch a load balancer

Check notice on line 549 in pkg/service/ecloud/request.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'PatchLoadBalancerRequest ...' (with an optional leading article)
type PatchLoadBalancerRequest struct {
Name string `json:"name,omitempty"`
}
Expand Down Expand Up @@ -615,7 +617,7 @@
Description string `json:"description,omitempty"`
}

// NATOverloadRule represents an eCloud NAT overload rule

Check notice on line 620 in pkg/service/ecloud/request.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'CreateNATOverloadRuleRequest ...' (with an optional leading article)
type CreateNATOverloadRuleRequest struct {
Name string `json:"name,omitempty"`
NetworkID string `json:"network_id"`
Expand All @@ -624,7 +626,7 @@
Action NATOverloadRuleAction `json:"action"`
}

// NATOverloadRule represents an eCloud NAT overload rule

Check notice on line 629 in pkg/service/ecloud/request.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'PatchNATOverloadRuleRequest ...' (with an optional leading article)
type PatchNATOverloadRuleRequest struct {
Name string `json:"name,omitempty"`
Subnet string `json:"subnet,omitempty"`
Expand Down Expand Up @@ -662,3 +664,14 @@
Name string `json:"name,omitempty"`
Password string `json:"password,omitempty"`
}

type CreateBackupGatewayRequest struct {
Name string `json:"name,omitempty"`
VPCID string `json:"vpc_id"`
RouterID string `json:"router_id"`
GatewaySpecID string `json:"gateway_spec_id"`
}

type PatchBackupGatewayRequest struct {
Name string `json:"name"`
}
13 changes: 13 additions & 0 deletions pkg/service/ecloud/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// ECloudService is an interface for managing eCloud
type ECloudService interface {
// Virtual Machine

Check notice on line 10 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVirtualMachines ...' (with an optional leading article)
GetVirtualMachines(parameters connection.APIRequestParameters) ([]VirtualMachine, error)
GetVirtualMachinesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VirtualMachine], error)
GetVirtualMachine(vmID int) (VirtualMachine, error)
Expand All @@ -29,7 +29,7 @@
DeleteVirtualMachineTag(vmID int, tagKey string) error
CreateVirtualMachineConsoleSession(vmID int) (ConsoleSession, error)

// Solution

Check notice on line 32 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetSolutions ...' (with an optional leading article)
GetSolutions(parameters connection.APIRequestParameters) ([]Solution, error)
GetSolutionsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Solution], error)
GetSolution(solutionID int) (Solution, error)
Expand Down Expand Up @@ -58,28 +58,28 @@
PatchSolutionTag(solutionID int, tagKey string, patch PatchTagRequest) error
DeleteSolutionTag(solutionID int, tagKey string) error

// Site

Check notice on line 61 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetSites ...' (with an optional leading article)
GetSites(parameters connection.APIRequestParameters) ([]Site, error)
GetSitesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Site], error)
GetSite(siteID int) (Site, error)

// Host

Check notice on line 66 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetV1Hosts ...' (with an optional leading article)
GetV1Hosts(parameters connection.APIRequestParameters) ([]V1Host, error)
GetV1HostsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[V1Host], error)
GetV1Host(hostID int) (V1Host, error)

// Datastore

Check notice on line 71 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetDatastores ...' (with an optional leading article)
GetDatastores(parameters connection.APIRequestParameters) ([]Datastore, error)
GetDatastoresPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Datastore], error)
GetDatastore(datastoreID int) (Datastore, error)

// Firewall

Check notice on line 76 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetFirewalls ...' (with an optional leading article)
GetFirewalls(parameters connection.APIRequestParameters) ([]Firewall, error)
GetFirewallsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Firewall], error)
GetFirewall(firewallID int) (Firewall, error)
GetFirewallConfig(firewallID int) (FirewallConfig, error)

// Pod

Check notice on line 82 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetPods ...' (with an optional leading article)
GetPods(parameters connection.APIRequestParameters) ([]Pod, error)
GetPodsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Pod], error)
GetPod(podID int) (Pod, error)
Expand All @@ -92,14 +92,14 @@
GetPodAppliancesPaginated(podID int, parameters connection.APIRequestParameters) (*connection.Paginated[Appliance], error)
PodConsoleAvailable(podID int) (bool, error)

// Appliance

Check notice on line 95 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetAppliances ...' (with an optional leading article)
GetAppliances(parameters connection.APIRequestParameters) ([]Appliance, error)
GetAppliancesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Appliance], error)
GetAppliance(applianceID string) (Appliance, error)
GetApplianceParameters(applianceID string, reqParameters connection.APIRequestParameters) ([]ApplianceParameter, error)
GetApplianceParametersPaginated(applianceID string, parameters connection.APIRequestParameters) (*connection.Paginated[ApplianceParameter], error)

// Credit

Check notice on line 102 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetCredits ...' (with an optional leading article)
GetCredits(parameters connection.APIRequestParameters) ([]account.Credit, error)

GetActiveDirectoryDomains(parameters connection.APIRequestParameters) ([]ActiveDirectoryDomain, error)
Expand All @@ -108,7 +108,7 @@

// V2

// VPC

Check notice on line 111 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPCs ...' (with an optional leading article)
GetVPCs(parameters connection.APIRequestParameters) ([]VPC, error)
GetVPCsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPC], error)
GetVPC(vpcID string) (VPC, error)
Expand All @@ -123,14 +123,14 @@
GetVPCTasks(vpcID string, parameters connection.APIRequestParameters) ([]Task, error)
GetVPCTasksPaginated(vpcID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Availability zone

Check notice on line 126 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetAvailabilityZones ...' (with an optional leading article)
GetAvailabilityZones(parameters connection.APIRequestParameters) ([]AvailabilityZone, error)
GetAvailabilityZonesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[AvailabilityZone], error)
GetAvailabilityZone(azID string) (AvailabilityZone, error)
GetAvailabilityZoneIOPSTiers(azID string, parameters connection.APIRequestParameters) ([]IOPSTier, error)
GetAvailabilityZoneIOPSTiersPaginated(azID string, parameters connection.APIRequestParameters) (*connection.Paginated[IOPSTier], error)

// Network

Check notice on line 133 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNetworks ...' (with an optional leading article)
GetNetworks(parameters connection.APIRequestParameters) ([]Network, error)
GetNetworksPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Network], error)
GetNetwork(networkID string) (Network, error)
Expand All @@ -142,14 +142,14 @@
GetNetworkTasks(networkID string, parameters connection.APIRequestParameters) ([]Task, error)
GetNetworkTasksPaginated(networkID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// DHCP

Check notice on line 145 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetDHCPs ...' (with an optional leading article)
GetDHCPs(parameters connection.APIRequestParameters) ([]DHCP, error)
GetDHCPsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[DHCP], error)
GetDHCP(dhcpID string) (DHCP, error)
GetDHCPTasks(dhcpID string, parameters connection.APIRequestParameters) ([]Task, error)
GetDHCPTasksPaginated(dhcpID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Instance

Check notice on line 152 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetInstances ...' (with an optional leading article)
GetInstances(parameters connection.APIRequestParameters) ([]Instance, error)
GetInstancesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Instance], error)
GetInstance(instanceID string) (Instance, error)
Expand Down Expand Up @@ -182,7 +182,7 @@
DecryptInstance(instanceID string) (string, error)
ExecuteInstanceScript(instanceID string, req ExecuteInstanceScriptRequest) (string, error)

// Floating IP

Check notice on line 185 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetFloatingIPs ...' (with an optional leading article)
GetFloatingIPs(parameters connection.APIRequestParameters) ([]FloatingIP, error)
GetFloatingIPsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[FloatingIP], error)
GetFloatingIP(fipID string) (FloatingIP, error)
Expand All @@ -194,7 +194,7 @@
GetFloatingIPTasks(fipID string, parameters connection.APIRequestParameters) ([]Task, error)
GetFloatingIPTasksPaginated(fipID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Firewall Policy

Check notice on line 197 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetFirewallPolicies ...' (with an optional leading article)
GetFirewallPolicies(parameters connection.APIRequestParameters) ([]FirewallPolicy, error)
GetFirewallPoliciesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[FirewallPolicy], error)
GetFirewallPolicy(policyID string) (FirewallPolicy, error)
Expand All @@ -206,7 +206,7 @@
GetFirewallPolicyTasks(policyID string, parameters connection.APIRequestParameters) ([]Task, error)
GetFirewallPolicyTasksPaginated(policyID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Firewall Rule

Check notice on line 209 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetFirewallRules ...' (with an optional leading article)
GetFirewallRules(parameters connection.APIRequestParameters) ([]FirewallRule, error)
GetFirewallRulesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[FirewallRule], error)
GetFirewallRule(ruleID string) (FirewallRule, error)
Expand All @@ -216,7 +216,7 @@
GetFirewallRuleFirewallRulePorts(firewallRuleID string, parameters connection.APIRequestParameters) ([]FirewallRulePort, error)
GetFirewallRuleFirewallRulePortsPaginated(firewallRuleID string, parameters connection.APIRequestParameters) (*connection.Paginated[FirewallRulePort], error)

// Firewall Rule Ports

Check notice on line 219 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetFirewallRulePorts ...' (with an optional leading article)
GetFirewallRulePorts(parameters connection.APIRequestParameters) ([]FirewallRulePort, error)
GetFirewallRulePortsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[FirewallRulePort], error)
GetFirewallRulePort(ruleID string) (FirewallRulePort, error)
Expand All @@ -224,7 +224,7 @@
PatchFirewallRulePort(ruleID string, req PatchFirewallRulePortRequest) (TaskReference, error)
DeleteFirewallRulePort(ruleID string) (string, error)

// Router

Check notice on line 227 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetRouters ...' (with an optional leading article)
GetRouters(parameters connection.APIRequestParameters) ([]Router, error)
GetRoutersPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Router], error)
GetRouter(routerID string) (Router, error)
Expand All @@ -241,12 +241,12 @@
GetRouterTasks(routerID string, parameters connection.APIRequestParameters) ([]Task, error)
GetRouterTasksPaginated(routerID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Region

Check notice on line 244 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetRegions ...' (with an optional leading article)
GetRegions(parameters connection.APIRequestParameters) ([]Region, error)
GetRegionsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Region], error)
GetRegion(regionID string) (Region, error)

// Volumes

Check notice on line 249 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVolumes ...' (with an optional leading article)
GetVolumes(parameters connection.APIRequestParameters) ([]Volume, error)
GetVolumesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Volume], error)
GetVolume(volumeID string) (Volume, error)
Expand All @@ -258,7 +258,7 @@
GetVolumeTasks(volumeID string, parameters connection.APIRequestParameters) ([]Task, error)
GetVolumeTasksPaginated(volumeID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// NICs

Check notice on line 261 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNICs ...' (with an optional leading article)
GetNICs(parameters connection.APIRequestParameters) ([]NIC, error)
GetNICsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[NIC], error)
GetNIC(nicID string) (NIC, error)
Expand All @@ -269,17 +269,17 @@
AssignNICIPAddress(nicID string, req AssignIPAddressRequest) (string, error)
UnassignNICIPAddress(nicID string, ipID string) (string, error)

// Billing metrics

Check notice on line 272 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetBillingMetrics ...' (with an optional leading article)
GetBillingMetrics(parameters connection.APIRequestParameters) ([]BillingMetric, error)
GetBillingMetricsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[BillingMetric], error)
GetBillingMetric(metricID string) (BillingMetric, error)

// Router throughputs

Check notice on line 277 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetRouterThroughputs ...' (with an optional leading article)
GetRouterThroughputs(parameters connection.APIRequestParameters) ([]RouterThroughput, error)
GetRouterThroughputsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[RouterThroughput], error)
GetRouterThroughput(metricID string) (RouterThroughput, error)

// Image

Check notice on line 282 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetImages ...' (with an optional leading article)
GetImages(parameters connection.APIRequestParameters) ([]Image, error)
GetImagesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Image], error)
GetImage(imageID string) (Image, error)
Expand All @@ -290,12 +290,12 @@
GetImageMetadata(imageID string, parameters connection.APIRequestParameters) ([]ImageMetadata, error)
GetImageMetadataPaginated(imageID string, parameters connection.APIRequestParameters) (*connection.Paginated[ImageMetadata], error)

// HostSpecs

Check notice on line 293 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetHostSpecs ...' (with an optional leading article)
GetHostSpecs(parameters connection.APIRequestParameters) ([]HostSpec, error)
GetHostSpecsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[HostSpec], error)
GetHostSpec(specID string) (HostSpec, error)

// HostGroups

Check notice on line 298 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetHostGroups ...' (with an optional leading article)
GetHostGroups(parameters connection.APIRequestParameters) ([]HostGroup, error)
GetHostGroupsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[HostGroup], error)
GetHostGroup(hostGroupID string) (HostGroup, error)
Expand All @@ -305,7 +305,7 @@
GetHostGroupTasks(hostGroupID string, parameters connection.APIRequestParameters) ([]Task, error)
GetHostGroupTasksPaginated(hostGroupID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Hosts

Check notice on line 308 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetHosts ...' (with an optional leading article)
GetHosts(parameters connection.APIRequestParameters) ([]Host, error)
GetHostsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Host], error)
GetHost(hostID string) (Host, error)
Expand All @@ -315,7 +315,7 @@
GetHostTasks(hostID string, parameters connection.APIRequestParameters) ([]Task, error)
GetHostTasksPaginated(hostID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// SSHKeyPairs

Check notice on line 318 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetSSHKeyPairs ...' (with an optional leading article)
GetSSHKeyPairs(parameters connection.APIRequestParameters) ([]SSHKeyPair, error)
GetSSHKeyPairsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[SSHKeyPair], error)
GetSSHKeyPair(keypairID string) (SSHKeyPair, error)
Expand All @@ -323,12 +323,12 @@
PatchSSHKeyPair(keypairID string, patch PatchSSHKeyPairRequest) error
DeleteSSHKeyPair(keypairID string) error

// Tasks

Check notice on line 326 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetTasks ...' (with an optional leading article)
GetTasks(parameters connection.APIRequestParameters) ([]Task, error)
GetTasksPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)
GetTask(taskID string) (Task, error)

// Network Policy

Check notice on line 331 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNetworkPolicies ...' (with an optional leading article)
GetNetworkPolicies(parameters connection.APIRequestParameters) ([]NetworkPolicy, error)
GetNetworkPoliciesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[NetworkPolicy], error)
GetNetworkPolicy(policyID string) (NetworkPolicy, error)
Expand All @@ -340,7 +340,7 @@
GetNetworkPolicyTasks(policyID string, parameters connection.APIRequestParameters) ([]Task, error)
GetNetworkPolicyTasksPaginated(policyID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// Network Rule

Check notice on line 343 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNetworkRules ...' (with an optional leading article)
GetNetworkRules(parameters connection.APIRequestParameters) ([]NetworkRule, error)
GetNetworkRulesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[NetworkRule], error)
GetNetworkRule(ruleID string) (NetworkRule, error)
Expand All @@ -350,7 +350,7 @@
GetNetworkRuleNetworkRulePorts(networkRuleID string, parameters connection.APIRequestParameters) ([]NetworkRulePort, error)
GetNetworkRuleNetworkRulePortsPaginated(networkRuleID string, parameters connection.APIRequestParameters) (*connection.Paginated[NetworkRulePort], error)

// Network Rule Ports

Check notice on line 353 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNetworkRulePorts ...' (with an optional leading article)
GetNetworkRulePorts(parameters connection.APIRequestParameters) ([]NetworkRulePort, error)
GetNetworkRulePortsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[NetworkRulePort], error)
GetNetworkRulePort(ruleID string) (NetworkRulePort, error)
Expand All @@ -358,7 +358,7 @@
PatchNetworkRulePort(ruleID string, req PatchNetworkRulePortRequest) (TaskReference, error)
DeleteNetworkRulePort(ruleID string) (string, error)

// Volume Groups

Check notice on line 361 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVolumeGroups ...' (with an optional leading article)
GetVolumeGroups(parameters connection.APIRequestParameters) ([]VolumeGroup, error)
GetVolumeGroupsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VolumeGroup], error)
GetVolumeGroup(groupID string) (VolumeGroup, error)
Expand All @@ -368,7 +368,7 @@
GetVolumeGroupVolumes(groupID string, parameters connection.APIRequestParameters) ([]Volume, error)
GetVolumeGroupVolumesPaginated(groupID string, parameters connection.APIRequestParameters) (*connection.Paginated[Volume], error)

// VPN Endpoint

Check notice on line 371 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNEndpoints ...' (with an optional leading article)
GetVPNEndpoints(parameters connection.APIRequestParameters) ([]VPNEndpoint, error)
GetVPNEndpointsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNEndpoint], error)
GetVPNEndpoint(endpointID string) (VPNEndpoint, error)
Expand All @@ -376,7 +376,7 @@
PatchVPNEndpoint(endpointID string, req PatchVPNEndpointRequest) (TaskReference, error)
DeleteVPNEndpoint(endpointID string) (string, error)

// VPN Service

Check notice on line 379 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNServices ...' (with an optional leading article)
GetVPNServices(parameters connection.APIRequestParameters) ([]VPNService, error)
GetVPNServicesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNService], error)
GetVPNService(serviceID string) (VPNService, error)
Expand All @@ -384,7 +384,7 @@
PatchVPNService(serviceID string, req PatchVPNServiceRequest) (TaskReference, error)
DeleteVPNService(serviceID string) (string, error)

// VPN Session

Check notice on line 387 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNSessions ...' (with an optional leading article)
GetVPNSessions(parameters connection.APIRequestParameters) ([]VPNSession, error)
GetVPNSessionsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNSession], error)
GetVPNSession(sessionID string) (VPNSession, error)
Expand All @@ -394,12 +394,12 @@
GetVPNSessionPreSharedKey(sessionID string) (VPNSessionPreSharedKey, error)
UpdateVPNSessionPreSharedKey(sessionID string, req UpdateVPNSessionPreSharedKeyRequest) (TaskReference, error)

// VPN Profile Group

Check notice on line 397 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNProfileGroups ...' (with an optional leading article)
GetVPNProfileGroups(parameters connection.APIRequestParameters) ([]VPNProfileGroup, error)
GetVPNProfileGroupsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNProfileGroup], error)
GetVPNProfileGroup(groupID string) (VPNProfileGroup, error)

// VPN Gateways

Check notice on line 402 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNGateways ...' (with an optional leading article)
GetVPNGateways(parameters connection.APIRequestParameters) ([]VPNGateway, error)
GetVPNGatewaysPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNGateway], error)
GetVPNGateway(gatewayID string) (VPNGateway, error)
Expand All @@ -409,7 +409,7 @@
GetVPNGatewayTasks(gatewayID string, parameters connection.APIRequestParameters) ([]Task, error)
GetVPNGatewayTasksPaginated(gatewayID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error)

// VPN Gateway Users

Check notice on line 412 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNGatewayUsers ...' (with an optional leading article)
GetVPNGatewayUsers(parameters connection.APIRequestParameters) ([]VPNGatewayUser, error)
GetVPNGatewayUsersPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNGatewayUser], error)
GetVPNGatewayUser(userID string) (VPNGatewayUser, error)
Expand All @@ -417,14 +417,14 @@
PatchVPNGatewayUser(userID string, req PatchVPNGatewayUserRequest) (TaskReference, error)
DeleteVPNGatewayUser(userID string) (string, error)

// VPN Gateway Specifications

Check notice on line 420 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVPNGatewaySpecifications ...' (with an optional leading article)
GetVPNGatewaySpecifications(parameters connection.APIRequestParameters) ([]VPNGatewaySpecification, error)
GetVPNGatewaySpecificationsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VPNGatewaySpecification], error)
GetVPNGatewaySpecification(specificationID string) (VPNGatewaySpecification, error)
GetVPNGatewaySpecificationAvailabilityZones(specificationID string, parameters connection.APIRequestParameters) ([]AvailabilityZone, error)
GetVPNGatewaySpecificationAvailabilityZonesPaginated(specificationID string, parameters connection.APIRequestParameters) (*connection.Paginated[AvailabilityZone], error)

// Load Balancer

Check notice on line 427 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetLoadBalancers ...' (with an optional leading article)
GetLoadBalancers(parameters connection.APIRequestParameters) ([]LoadBalancer, error)
GetLoadBalancersPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[LoadBalancer], error)
GetLoadBalancer(loadbalancerID string) (LoadBalancer, error)
Expand All @@ -432,12 +432,12 @@
PatchLoadBalancer(loadbalancerID string, req PatchLoadBalancerRequest) (TaskReference, error)
DeleteLoadBalancer(loadbalancerID string) (string, error)

// Load Balancer Spec

Check notice on line 435 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetLoadBalancerSpecs ...' (with an optional leading article)
GetLoadBalancerSpecs(parameters connection.APIRequestParameters) ([]LoadBalancerSpec, error)
GetLoadBalancerSpecsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[LoadBalancerSpec], error)
GetLoadBalancerSpec(lbSpecID string) (LoadBalancerSpec, error)

// VIP

Check notice on line 440 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetVIPs ...' (with an optional leading article)
GetVIPs(parameters connection.APIRequestParameters) ([]VIP, error)
GetVIPsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[VIP], error)
GetVIP(vipID string) (VIP, error)
Expand All @@ -445,7 +445,7 @@
PatchVIP(vipID string, patch PatchVIPRequest) (TaskReference, error)
DeleteVIP(vipID string) (string, error)

// IP Addresses

Check notice on line 448 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetIPAddresses ...' (with an optional leading article)
GetIPAddresses(parameters connection.APIRequestParameters) ([]IPAddress, error)
GetIPAddressesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[IPAddress], error)
GetIPAddress(ipID string) (IPAddress, error)
Expand All @@ -453,7 +453,7 @@
PatchIPAddress(ipID string, patch PatchIPAddressRequest) (TaskReference, error)
DeleteIPAddress(ipID string) (string, error)

// Affinity Rules

Check notice on line 456 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetAffinityRules ...' (with an optional leading article)
GetAffinityRules(parameters connection.APIRequestParameters) ([]AffinityRule, error)
GetAffinityRulesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[AffinityRule], error)
GetAffinityRule(ruleID string) (AffinityRule, error)
Expand All @@ -461,19 +461,19 @@
PatchAffinityRule(ruleID string, patch PatchAffinityRuleRequest) (TaskReference, error)
DeleteAffinityRule(ruleID string) (string, error)

// Affinity Rule Members

Check notice on line 464 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetAffinityRuleMembers ...' (with an optional leading article)
GetAffinityRuleMembers(ruleID string, parameters connection.APIRequestParameters) ([]AffinityRuleMember, error)
GetAffinityRuleMembersPaginated(ruleID string, parameters connection.APIRequestParameters) (*connection.Paginated[AffinityRuleMember], error)
GetAffinityRuleMember(memberID string) (AffinityRuleMember, error)
CreateAffinityRuleMember(req CreateAffinityRuleMemberRequest) (TaskReference, error)
DeleteAffinityRuleMember(memberID string) (string, error)

// Resource Tiers

Check notice on line 471 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetResourceTiers ...' (with an optional leading article)
GetResourceTiers(parameters connection.APIRequestParameters) ([]ResourceTier, error)
GetResourceTiersPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[ResourceTier], error)
GetResourceTier(tierID string) (ResourceTier, error)

// NAT Overload Rules

Check notice on line 476 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetNATOverloadRules ...' (with an optional leading article)
GetNATOverloadRules(parameters connection.APIRequestParameters) ([]NATOverloadRule, error)
GetNATOverloadRulesPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[NATOverloadRule], error)
GetNATOverloadRule(ruleID string) (NATOverloadRule, error)
Expand All @@ -481,10 +481,23 @@
PatchNATOverloadRule(ruleID string, req PatchNATOverloadRuleRequest) (TaskReference, error)
DeleteNATOverloadRule(ruleID string) (string, error)

// IOPS Tiers

Check notice on line 484 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetIOPSTiers ...' (with an optional leading article)
GetIOPSTiers(parameters connection.APIRequestParameters) ([]IOPSTier, error)
GetIOPSTiersPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[IOPSTier], error)
GetIOPSTier(iopsID string) (IOPSTier, error)

// Backup Gateway Specifications

Check notice on line 489 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetBackupGatewaySpecifications ...' (with an optional leading article)
GetBackupGatewaySpecifications(parameters connection.APIRequestParameters) ([]BackupGatewaySpecification, error)
GetBackupGatewaySpecificationsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[BackupGatewaySpecification], error)
GetBackupGatewaySpecification(specificationID string) (BackupGatewaySpecification, error)

// Backup Gateways

Check notice on line 494 in pkg/service/ecloud/service.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Comment of exported element starts with the incorrect name

Comment should have the following format 'GetBackupGateways ...' (with an optional leading article)
GetBackupGateways(parameters connection.APIRequestParameters) ([]BackupGateway, error)
GetBackupGatewaysPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[BackupGateway], error)
GetBackupGateway(gatewayID string) (BackupGateway, error)
CreateBackupGateway(req CreateBackupGatewayRequest) (TaskReference, error)
PatchBackupGateway(gatewayID string, req PatchBackupGatewayRequest) (TaskReference, error)
DeleteBackupGateway(gatewayID string) (string, error)
}

// Service implements ECloudService for managing
Expand Down
88 changes: 88 additions & 0 deletions pkg/service/ecloud/service_backupgateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package ecloud

import (
"fmt"

"github.com/ans-group/sdk-go/pkg/connection"
)

// GetBackupGateways retrieves a list of backup gateways
func (s *Service) GetBackupGateways(parameters connection.APIRequestParameters) ([]BackupGateway, error) {
return connection.InvokeRequestAll(s.GetBackupGatewaysPaginated, parameters)
}

// GetBackupGatewaysPaginated retrieves a paginated list of backup gateways
func (s *Service) GetBackupGatewaysPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[BackupGateway], error) {
body, err := s.getBackupGatewaysPaginatedResponseBody(parameters)
return connection.NewPaginated(body, parameters, s.GetBackupGatewaysPaginated), err
}

func (s *Service) getBackupGatewaysPaginatedResponseBody(parameters connection.APIRequestParameters) (*connection.APIResponseBodyData[[]BackupGateway], error) {
return connection.Get[[]BackupGateway](s.connection, "/ecloud/v2/backup-gateways", parameters)
}

// GetBackupGateway retrieves a single backup gateway by ID
func (s *Service) GetBackupGateway(gatewayID string) (BackupGateway, error) {
body, err := s.getBackupGatewayResponseBody(gatewayID)

return body.Data, err
}

func (s *Service) getBackupGatewayResponseBody(gatewayID string) (*connection.APIResponseBodyData[BackupGateway], error) {
if gatewayID == "" {
return &connection.APIResponseBodyData[BackupGateway]{}, fmt.Errorf("invalid backup gateway id")
}

return connection.Get[BackupGateway](s.connection, fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID), connection.APIRequestParameters{}, connection.NotFoundResponseHandler(&BackupGatewayNotFoundError{ID: gatewayID}))
}

// CreateBackupGateway creates a new backup gateway
func (s *Service) CreateBackupGateway(req CreateBackupGatewayRequest) (TaskReference, error) {
body, err := s.createBackupGatewayResponseBody(req)

return body.Data, err
}

func (s *Service) createBackupGatewayResponseBody(req CreateBackupGatewayRequest) (*connection.APIResponseBodyData[TaskReference], error) {
return connection.Post[TaskReference](s.connection, "/ecloud/v2/backup-gateways", &req)
}

// PatchBackupGateway patches a backup gateway
func (s *Service) PatchBackupGateway(gatewayID string, req PatchBackupGatewayRequest) (TaskReference, error) {
body, err := s.patchBackupGatewayResponseBody(gatewayID, req)

return body.Data, err
}

func (s *Service) patchBackupGatewayResponseBody(gatewayID string, req PatchBackupGatewayRequest) (*connection.APIResponseBodyData[TaskReference], error) {
if gatewayID == "" {
return &connection.APIResponseBodyData[TaskReference]{}, fmt.Errorf("invalid gateway id")
}

return connection.Patch[TaskReference](
s.connection,
fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID),
&req,
connection.NotFoundResponseHandler(&BackupGatewayNotFoundError{ID: gatewayID}),
)
}

// DeleteBackupGateway deletes a backup gateway
func (s *Service) DeleteBackupGateway(gatewayID string) (string, error) {
body, err := s.deleteBackupGatewayResponseBody(gatewayID)

return body.Data.TaskID, err
}

func (s *Service) deleteBackupGatewayResponseBody(gatewayID string) (*connection.APIResponseBodyData[TaskReference], error) {
if gatewayID == "" {
return &connection.APIResponseBodyData[TaskReference]{}, fmt.Errorf("invalid gateway id")
}

return connection.Delete[TaskReference](
s.connection,
fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID),
nil,
connection.NotFoundResponseHandler(&BackupGatewayNotFoundError{ID: gatewayID}),
)
}
42 changes: 42 additions & 0 deletions pkg/service/ecloud/service_backupgateway_specs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ecloud

import (
"fmt"

"github.com/ans-group/sdk-go/pkg/connection"
)

// GetBackupGatewaySpecifications retrieves a list of Backup gateway specifications
func (s *Service) GetBackupGatewaySpecifications(parameters connection.APIRequestParameters) ([]BackupGatewaySpecification, error) {
return connection.InvokeRequestAll(s.GetBackupGatewaySpecificationsPaginated, parameters)
}

// GetBackupGatewaySpecificationsPaginated retrieves a paginated list of Backup gateway specifications
func (s *Service) GetBackupGatewaySpecificationsPaginated(parameters connection.APIRequestParameters) (*connection.Paginated[BackupGatewaySpecification], error) {
body, err := s.getBackupGatewaySpecificationsPaginatedResponseBody(parameters)
return connection.NewPaginated(body, parameters, s.GetBackupGatewaySpecificationsPaginated), err
}

func (s *Service) getBackupGatewaySpecificationsPaginatedResponseBody(parameters connection.APIRequestParameters) (*connection.APIResponseBodyData[[]BackupGatewaySpecification], error) {
return connection.Get[[]BackupGatewaySpecification](s.connection, "/ecloud/v2/backup-gateway-specs", parameters)
}

// GetBackupGatewaySpecification retrieves a single Backup gateway specification by ID
func (s *Service) GetBackupGatewaySpecification(specificationID string) (BackupGatewaySpecification, error) {
body, err := s.getBackupGatewaySpecificationResponseBody(specificationID)

return body.Data, err
}

func (s *Service) getBackupGatewaySpecificationResponseBody(specificationID string) (*connection.APIResponseBodyData[BackupGatewaySpecification], error) {
if specificationID == "" {
return &connection.APIResponseBodyData[BackupGatewaySpecification]{}, fmt.Errorf("invalid backup gateway specification id")
}

return connection.Get[BackupGatewaySpecification](
s.connection,
fmt.Sprintf("/ecloud/v2/backup-gateway-specs/%s", specificationID),
connection.APIRequestParameters{},
connection.NotFoundResponseHandler(&BackupGatewaySpecificationNotFoundError{ID: specificationID}),
)
}
140 changes: 140 additions & 0 deletions pkg/service/ecloud/service_backupgateway_specs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package ecloud

import (
"bytes"
"errors"
"io/ioutil"
"net/http"
"testing"

"github.com/ans-group/sdk-go/pkg/connection"
"github.com/ans-group/sdk-go/test/mocks"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
)

func TestGetBackupGatewaySpecifications(t *testing.T) {
t.Run("Single", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

c.EXPECT().Get("/ecloud/v2/backup-gateway-specs", gomock.Any()).Return(&connection.APIResponse{
Response: &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte("{\"data\":[{\"id\":\"bkupgs-abcdef12\"}],\"meta\":{\"pagination\":{\"total_pages\":1}}}"))),

Check warning on line 29 in pkg/service/ecloud/service_backupgateway_specs_test.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Deprecated element

`NopCloser` is deprecated
StatusCode: 200,
},
}, nil).Times(1)

specs, err := s.GetBackupGatewaySpecifications(connection.APIRequestParameters{})

assert.Nil(t, err)
assert.Len(t, specs, 1)
assert.Equal(t, "bkupgs-abcdef12", specs[0].ID)
})

t.Run("ConnectionError_ReturnsError", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

c.EXPECT().Get("/ecloud/v2/backup-gateway-specs", gomock.Any()).Return(&connection.APIResponse{}, errors.New("test error 1"))

_, err := s.GetBackupGatewaySpecifications(connection.APIRequestParameters{})

assert.NotNil(t, err)
assert.Equal(t, "test error 1", err.Error())
})
}

func TestGetBackupGatewaySpecification(t *testing.T) {
t.Run("Valid", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

c.EXPECT().Get("/ecloud/v2/backup-gateway-specs/bkupgs-abcdef12", gomock.Any()).Return(&connection.APIResponse{
Response: &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte("{\"data\":{\"id\":\"bkupgs-abcdef12\"}}"))),

Check warning on line 73 in pkg/service/ecloud/service_backupgateway_specs_test.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Deprecated element

`NopCloser` is deprecated
StatusCode: 200,
},
}, nil).Times(1)

spec, err := s.GetBackupGatewaySpecification("bkupgs-abcdef12")

assert.Nil(t, err)
assert.Equal(t, "bkupgs-abcdef12", spec.ID)
})

t.Run("ConnectionError_ReturnsError", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

c.EXPECT().Get("/ecloud/v2/backup-gateway-specs/bkupgs-abcdef12", gomock.Any()).Return(&connection.APIResponse{}, errors.New("test error 1")).Times(1)

_, err := s.GetBackupGatewaySpecification("bkupgs-abcdef12")

assert.NotNil(t, err)
assert.Equal(t, "test error 1", err.Error())
})

t.Run("InvalidBackupGatewaySpecificationID_ReturnsError", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

_, err := s.GetBackupGatewaySpecification("")

assert.NotNil(t, err)
assert.Equal(t, "invalid backup gateway specification id", err.Error())
})

t.Run("404_ReturnsBackupGatewaySpecificationNotFoundError", func(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

c := mocks.NewMockConnection(mockCtrl)

s := Service{
connection: c,
}

c.EXPECT().Get("/ecloud/v2/backup-gateway-specs/bkupgs-abcdef12", gomock.Any()).Return(&connection.APIResponse{
Response: &http.Response{
Body: ioutil.NopCloser(bytes.NewReader([]byte(""))),

Check warning on line 130 in pkg/service/ecloud/service_backupgateway_specs_test.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Deprecated element

`NopCloser` is deprecated
StatusCode: 404,
},
}, nil).Times(1)

_, err := s.GetBackupGatewaySpecification("bkupgs-abcdef12")

assert.NotNil(t, err)
assert.IsType(t, &BackupGatewaySpecificationNotFoundError{}, err)
})
}
Loading
Loading