You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
928 B
50 lines
928 B
package rg
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// Request struct for restore resource group
|
|
type RestoreRequest struct {
|
|
// Resource group ID
|
|
// Required: true
|
|
RGID uint64 `url:"rgId" json:"rgId"`
|
|
|
|
// Reason for action
|
|
// Required: false
|
|
Reason string `url:"reason,omitempty" json:"reason,omitempty"`
|
|
}
|
|
|
|
func (rgrq RestoreRequest) validate() error {
|
|
if rgrq.RGID == 0 {
|
|
return errors.New("validation-error: field RGID must be set")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Restore restores resource group from recycle bin
|
|
func (r RG) Restore(ctx context.Context, req RestoreRequest) (bool, error) {
|
|
err := req.validate()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
url := "/cloudbroker/rg/restore"
|
|
|
|
res, err := r.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
result, err := strconv.ParseBool(string(res))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return result, nil
|
|
}
|