This commit is contained in:
stSolo
2022-12-22 17:56:47 +03:00
parent 8712561853
commit d4b1ab7133
672 changed files with 28509 additions and 4419 deletions

View File

@@ -7,11 +7,14 @@ import (
"net/http"
)
// Request struct for get information about K8CI
type GetRequest struct {
// ID of the K8 catalog item to get
// Required: true
K8CIID uint64 `url:"k8ciId"`
}
func (krq GetRequest) Validate() error {
func (krq GetRequest) validate() error {
if krq.K8CIID == 0 {
return errors.New("field K8CIID can not be empty or equal to 0")
}
@@ -19,21 +22,24 @@ func (krq GetRequest) Validate() error {
return nil
}
func (k K8CI) Get(ctx context.Context, req GetRequest) (*K8CIRecord, error) {
if err := req.Validate(); err != nil {
// Get gets details of the specified K8 catalog item
func (k K8CI) Get(ctx context.Context, req GetRequest) (*RecordK8CI, error) {
if err := req.validate(); err != nil {
return nil, err
}
url := "/cloudapi/k8ci/get"
k8ciRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
k8ci := &K8CIRecord{}
if err := json.Unmarshal(k8ciRaw, k8ci); err != nil {
info := RecordK8CI{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return k8ci, nil
return &info, nil
}

View File

@@ -1,13 +1,16 @@
// API to manage K8CI instances
package k8ci
import (
"github.com/rudecs/decort-sdk/interfaces"
)
// Structure for creating request to K8CI
type K8CI struct {
client interfaces.Caller
}
// Builder for K8CI endpoints
func New(client interfaces.Caller) *K8CI {
return &K8CI{
client,

View File

@@ -6,23 +6,36 @@ import (
"net/http"
)
// Request struct for get list information about images
type ListRequest struct {
IncludeDisabled bool `url:"includeDisabled,omitempty"`
Page uint64 `url:"page,omitempty"`
Size uint64 `url:"size,omitempty"`
// List disabled items as well
// Required: false
IncludeDisabled bool `url:"includeDisabled,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (k K8CI) List(ctx context.Context, req ListRequest) (K8CIList, error) {
// List gets list all k8ci catalog items available to the current user
func (k K8CI) List(ctx context.Context, req ListRequest) (ListK8CI, error) {
url := "/cloudapi/k8ci/list"
k8ciListRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
k8ciList := K8CIList{}
if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil {
list := ListK8CI{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return k8ciList, nil
return list, nil
}

View File

@@ -6,22 +6,32 @@ import (
"net/http"
)
// Request struct for get list information about deleted images
type ListDeletedRequest struct {
// Page number
// Required: false
Page uint64 `url:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty"`
}
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (K8CIList, error) {
// ListDeleted gets list all deleted k8ci catalog items available to the current user
func (k K8CI) ListDeleted(ctx context.Context, req ListDeletedRequest) (ListK8CI, error) {
url := "/cloudapi/k8ci/listDeleted"
k8ciListRaw, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
k8ciList := K8CIList{}
if err := json.Unmarshal(k8ciListRaw, &k8ciList); err != nil {
list := ListK8CI{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return k8ciList, nil
return list, nil
}

View File

@@ -1,15 +1,28 @@
package k8ci
type K8CIItem struct {
// Detailed information about K8CI
type ItemK8CI struct {
// Created time
CreatedTime uint64 `json:"createdTime"`
K8CIRecord
// Main information about K8CI
RecordK8CI
}
type K8CIList []K8CIItem
// List of K8CI
type ListK8CI []ItemK8CI
type K8CIRecord struct {
// Main information about K8CI
type RecordK8CI struct {
// Description
Description string `json:"desc"`
ID uint64 `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
// ID
ID uint64 `json:"id"`
// Name
Name string `json:"name"`
// Version
Version string `json:"version"`
}