Files
decort-golang-sdk/pkg/cloudbroker/sep/consumption.go

41 lines
883 B
Go
Raw Normal View History

2022-12-22 17:56:47 +03:00
package sep
import (
"context"
"encoding/json"
"net/http"
2023-03-24 17:09:30 +03:00
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
2022-12-22 17:56:47 +03:00
)
2023-10-25 17:37:18 +03:00
// ConsumptionRequest struct to get consumption info
2022-12-22 17:56:47 +03:00
type ConsumptionRequest struct {
// Storage endpoint provider ID
// Required: true
2023-03-24 17:09:30 +03:00
SEPID uint64 `url:"sep_id" json:"sep_id" validate:"required"`
2022-12-22 17:56:47 +03:00
}
2023-10-25 17:37:18 +03:00
// Consumption gets SEP consumption info
2022-12-22 17:56:47 +03:00
func (s SEP) Consumption(ctx context.Context, req ConsumptionRequest) (*RecordConsumption, error) {
2023-03-24 17:09:30 +03:00
err := validators.ValidateRequest(req)
2022-12-22 17:56:47 +03:00
if err != nil {
2023-10-25 17:37:18 +03:00
return nil, validators.ValidationErrors(validators.GetErrors(err))
2022-12-22 17:56:47 +03:00
}
url := "/cloudbroker/sep/consumption"
res, err := s.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := RecordConsumption{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}