Files
dynamix-golang-sdk/pkg/cloudapi/disks/restore.go

78 lines
1.7 KiB
Go
Raw Normal View History

2025-09-23 14:34:24 +03:00
package disks
import (
"context"
2026-08-28 16:47:26 +03:00
"encoding/json"
2025-09-23 14:34:24 +03:00
"net/http"
"strconv"
2026-08-21 18:12:55 +04:00
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
2025-09-23 14:34:24 +03:00
)
// RestoreRequest struct to restore a deleted unattached disk
type RestoreRequest struct {
// ID of the disk to restore
// Required: true
DiskID uint64 `url:"diskId" json:"diskId" validate:"required"`
}
2026-08-28 16:47:26 +03:00
type wrapperRestoreRequest struct {
RestoreRequest
AsyncMode bool `url:"async_mode" json:"async_mode"`
}
2025-09-23 14:34:24 +03:00
// Restore restores a deleted unattached disk from recycle bin
func (d Disks) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/restore"
2026-08-28 16:47:26 +03:00
wrappedReq := wrapperRestoreRequest{
RestoreRequest: req,
AsyncMode: false,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
2025-09-23 14:34:24 +03:00
if err != nil {
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
return false, err
}
return result, nil
}
2026-08-28 16:47:26 +03:00
// RestoreAsync restores a deleted unattached disk from recycle bin in async mode
func (d Disks) RestoreAsync(ctx context.Context, req RestoreRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudapi/disks/restore"
wrappedReq := wrapperRestoreRequest{
RestoreRequest: req,
AsyncMode: true,
}
res, err := d.client.DecortApiCall(ctx, http.MethodPost, url, wrappedReq)
if err != nil {
return "", err
}
var result string
if err := json.Unmarshal(res, &result); err != nil {
return "", err
}
return result, nil
}