v1.16.4
v1.16.4
This commit is contained in:
46
pkg/cloudapi/vmfolder/get.go
Normal file
46
pkg/cloudapi/vmfolder/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package vmfolder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get detailed information about a vm folder
|
||||
type GetRequest struct {
|
||||
// ID of a folder
|
||||
// Required: true
|
||||
FolderID uint64 `url:"folder_id" json:"folder_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets current configuration of the vm folder as a RecordVMFolder struct
|
||||
func (v VMFolder) Get(ctx context.Context, req GetRequest) (*RecordVMFolder, error) {
|
||||
res, err := v.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := RecordVMFolder{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
// GetRaw gets current configuration of the vm folder as an array of bytes
|
||||
func (v VMFolder) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/vmfolder/get"
|
||||
|
||||
res, err := v.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
Reference in New Issue
Block a user