-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for backup gateways, agent-level props
- Loading branch information
Showing
8 changed files
with
874 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
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) { | ||
body := &connection.APIResponseBodyData[[]BackupGateway]{} | ||
|
||
response, err := s.connection.Get("/ecloud/v2/backup-gateways", parameters) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, nil) | ||
} | ||
|
||
// 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) { | ||
body := &connection.APIResponseBodyData[BackupGateway]{} | ||
|
||
if gatewayID == "" { | ||
return body, fmt.Errorf("invalid backup gateway id") | ||
} | ||
|
||
response, err := s.connection.Get(fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID), connection.APIRequestParameters{}) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, func(resp *connection.APIResponse) error { | ||
if response.StatusCode == 404 { | ||
return &BackupGatewayNotFoundError{ID: gatewayID} | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
// 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) { | ||
body := &connection.APIResponseBodyData[TaskReference]{} | ||
|
||
response, err := s.connection.Post("/ecloud/v2/backup-gateways", &req) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, nil) | ||
} | ||
|
||
// 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) { | ||
body := &connection.APIResponseBodyData[TaskReference]{} | ||
|
||
if gatewayID == "" { | ||
return body, fmt.Errorf("invalid gateway id") | ||
} | ||
|
||
response, err := s.connection.Patch(fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID), &req) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, func(resp *connection.APIResponse) error { | ||
if response.StatusCode == 404 { | ||
return &BackupGatewayNotFoundError{ID: gatewayID} | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
// 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) { | ||
body := &connection.APIResponseBodyData[TaskReference]{} | ||
|
||
if gatewayID == "" { | ||
return body, fmt.Errorf("invalid gateway id") | ||
} | ||
|
||
response, err := s.connection.Delete(fmt.Sprintf("/ecloud/v2/backup-gateways/%s", gatewayID), nil) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, func(resp *connection.APIResponse) error { | ||
if response.StatusCode == 404 { | ||
return &BackupGatewayNotFoundError{ID: gatewayID} | ||
} | ||
|
||
return nil | ||
}) | ||
} | ||
|
||
// GetBackupGatewayTasks retrieves a list of backup gateway tasks | ||
func (s *Service) GetBackupGatewayTasks(gatewayID string, parameters connection.APIRequestParameters) ([]Task, error) { | ||
return connection.InvokeRequestAll(func(p connection.APIRequestParameters) (*connection.Paginated[Task], error) { | ||
return s.GetBackupGatewayTasksPaginated(gatewayID, p) | ||
}, parameters) | ||
} | ||
|
||
// GetBackupGatewayTasksPaginated retrieves a paginated list of backup gateway tasks | ||
func (s *Service) GetBackupGatewayTasksPaginated(gatewayID string, parameters connection.APIRequestParameters) (*connection.Paginated[Task], error) { | ||
body, err := s.getBackupGatewayTasksPaginatedResponseBody(gatewayID, parameters) | ||
|
||
return connection.NewPaginated(body, parameters, func(p connection.APIRequestParameters) (*connection.Paginated[Task], error) { | ||
return s.GetBackupGatewayTasksPaginated(gatewayID, p) | ||
}), err | ||
} | ||
|
||
func (s *Service) getBackupGatewayTasksPaginatedResponseBody(gatewayID string, parameters connection.APIRequestParameters) (*connection.APIResponseBodyData[[]Task], error) { | ||
body := &connection.APIResponseBodyData[[]Task]{} | ||
|
||
if gatewayID == "" { | ||
return body, fmt.Errorf("invalid backup gateway id") | ||
} | ||
|
||
response, err := s.connection.Get(fmt.Sprintf("/ecloud/v2/backup-gateways/%s/tasks", gatewayID), parameters) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, func(resp *connection.APIResponse) error { | ||
if response.StatusCode == 404 { | ||
return &BackupGatewayNotFoundError{ID: gatewayID} | ||
} | ||
|
||
return nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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) { | ||
body := &connection.APIResponseBodyData[[]BackupGatewaySpecification]{} | ||
|
||
response, err := s.connection.Get("/ecloud/v2/backup-gateway-specs", parameters) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, nil) | ||
} | ||
|
||
// 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) { | ||
body := &connection.APIResponseBodyData[BackupGatewaySpecification]{} | ||
|
||
if specificationID == "" { | ||
return body, fmt.Errorf("invalid backup gateway specification id") | ||
} | ||
|
||
response, err := s.connection.Get(fmt.Sprintf("/ecloud/v2/backup-gateway-specs/%s", specificationID), connection.APIRequestParameters{}) | ||
if err != nil { | ||
return body, err | ||
} | ||
|
||
return body, response.HandleResponse(body, func(resp *connection.APIResponse) error { | ||
if response.StatusCode == 404 { | ||
return &BackupGatewaySpecificationNotFoundError{ID: specificationID} | ||
} | ||
|
||
return nil | ||
}) | ||
} |
Oops, something went wrong.