This commit is contained in:
2023-11-29 15:57:26 +03:00
parent a85ad3acd5
commit cd741b7f11
36 changed files with 995 additions and 145 deletions

10
pkg/cloudbroker/audit.go Normal file
View File

@@ -0,0 +1,10 @@
package cloudbroker
import (
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
)
// Accessing the Stack method group
func (cb *CloudBroker) Audit() *audit.Audit {
return audit.New(cb.client)
}

View File

@@ -0,0 +1,15 @@
package audit
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
// Structure for creating request to audit
type Audit struct {
client interfaces.Caller
}
// Builder for audit endpoint
func New(client interfaces.Caller) *Audit{
return &Audit{
client: client,
}
}

View File

@@ -0,0 +1,46 @@
package audit
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetRequest struct to get information about account
type GetRequest struct {
// Audit GUID
// Required: true
AuditGuid string `url:"auditGuid" json:"auditGuid" validate:"required"`
}
// Get gets information about audit as a RecordAudit struct
func (a Audit) Get(ctx context.Context, req GetRequest) (*RecordAudit, error) {
res, err := a.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordAudit{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets information about audit as an array of bytes
func (a Audit) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/audit/get"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,46 @@
package audit
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// LinkedJobsRequest struct to get information about jobs linked with Audit
type LinkedJobsRequest struct {
// Audit GUID
// Required: true
AuditGuid string `url:"auditGuid" json:"auditGuid" validate:"required"`
}
// LinkedJobs gets information about Linked Jobs as a ListLinkedJobs struct
func (a Audit) LinkedJobs(ctx context.Context, req LinkedJobsRequest) (*ListLinkedJobs, error) {
res, err := a.GetRawLinkedJobs(ctx, req)
if err != nil {
return nil, err
}
info := ListLinkedJobs{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRawLinkedJobs gets information about Linked Jobs as an array of bytes
func (a Audit) GetRawLinkedJobs(ctx context.Context, req LinkedJobsRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/audit/linkedJobs"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,64 @@
package audit
import (
"context"
"encoding/json"
"net/http"
)
// ListRequest struct to give list of account audits
type ListRequest struct {
// Find all audits after point in time (unixtime)
// Required: false
TimestampAt uint64 `url:"timestampAt,omitempty" json:"timestampAt,omitempty"`
// Find all audits before point in time (unixtime)
// Required: false
TimestampTo uint64 `url:"timestampTo,omitempty" json:"timestampTo,omitempty"`
// Find by user (Mongo RegExp supported)
// Required: false
User string `url:"user,omitempty" json:"user,omitempty"`
// Find by api endpoint (Mongo RegExp supported)
// Required: false
Call string `url:"call,omitempty" json:"call,omitempty"`
// Find by HTTP status code
// Required: false
StatusCode uint64 `url:"statusCode,omitempty" json:"statusCode,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// List gets audit records for the specified account object
func (a Audit) List(ctx context.Context, req ListRequest) (*ListAudits, error) {
res, err := a.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListAudits{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of audit records an array of bytes
func (a Audit) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
url := "/cloudbroker/audit/list"
res, err := a.client.DecortApiCall(ctx, http.MethodPost, url, req)
return res, err
}

View File

@@ -0,0 +1,102 @@
package audit
// Main info about audit
type ItemAudit struct {
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// User
User string `json:"user"`
}
// List of audits
type ListAudits struct {
// Data
Data []ItemAudit `json:"data"`
// EntryCount
EntryCount uint64 `json:"entryCount"`
}
// Main info about audit
type RecordAudit struct {
// Apitask
Apitask string `json:"apitask"`
// Arguments
Arguments string `json:"args"`
// Call
Call string `json:"call"`
// GUID
GUID string `json:"guid"`
// Kwargs
Kwargs string `json:"kwargs"`
// RemoteAddr
RemoteAddr string `json:"remote_addr"`
// Response time
ResponseTime float64 `json:"responsetime"`
// Result
Result string `json:"result"`
// Status code
StatusCode uint64 `json:"statuscode"`
// Tags
Tags string `json:"tags"`
// Timestamp
Timestamp float64 `json:"timestamp"`
// TimestampEnd
TimestampEnd float64 `json:"timestampEnd"`
// User
User string `json:"user"`
}
// List of Linked Jobs
type ListLinkedJobs []ItemLinkedJobs
// Main info about Linked Jobs
type ItemLinkedJobs struct {
// CMD
CMD string `json:"cmd"`
// NID
NID uint64 `json:"nid"`
// state
State string `json:"state"`
// TimeCreate
TimeCreate uint64 `json:"timeCreate"`
// TimeStart
TimeStart uint64 `json:"timeStart"`
// TimeStop
TimeStop uint64 `json:"timeStop"`
// Timeout
Timeout uint64 `json:"timeout"`
}

View File

@@ -0,0 +1,38 @@
package compute
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// DeleteCustomFieldsRequest struct to delete compute's custom fields
type DeleteCustomFieldsRequest struct {
// ID of the compute
// Required: true
ComputeID uint64 `url:"computeId" json:"computeId" validate:"required"`
}
// DeleteCustomFields deletes computes custom fields
func (c Compute) DeleteCustomFields(ctx context.Context, req DeleteCustomFieldsRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/compute/deleteCustomFields"
res, err := c.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
}

View File

@@ -20,8 +20,8 @@ func (lid ListInfoDisks) IDs() []uint64 {
// IDs gets array of PFWsIDs from ListPFW struct
func (lp ListPFW) IDs() []uint64 {
res := make([]uint64, 0, len(lp))
for _, p := range lp {
res := make([]uint64, 0, len(lp.Data))
for _, p := range lp.Data {
res = append(res, p.ID)
}
return res
@@ -43,4 +43,4 @@ func (lpd ListPCIDevices) IDs() []uint64 {
res = append(res, pd.ID)
}
return res
}
}

View File

@@ -12,6 +12,14 @@ type RecordACL struct {
RGACL ListACL `json:"rgACL"`
}
type ListUsers struct {
// Data
Data RecordACL `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// ACL information
type ItemACL struct {
// Explicit
@@ -75,6 +83,15 @@ type ItemSnapshot struct {
// List of snapshots
type ListSnapshots []ItemSnapshot
// List of snapshots
type ListSnapShot struct {
// Data
Data []ItemSnapshot `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about snapshot usage
type ItemSnapshotUsage struct {
// Count
@@ -232,7 +249,13 @@ type ItemPFW struct {
}
// List port forwards
type ListPFW []ItemPFW
type ListPFW struct {
// Data
Data []ItemPFW `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// Main information about rule
type ItemRule struct {
@@ -569,6 +592,9 @@ type InfoCompute struct {
// Boot disk size
BootDiskSize uint64 `json:"bootdiskSize"`
// cd Image Id
CdImageId uint64 `json:"cdImageId"`
// Clone reference
CloneReference uint64 `json:"cloneReference"`
@@ -638,6 +664,9 @@ type InfoCompute struct {
// Name
Name string `json:"name"`
// Need reboot
NeedReboot bool `json:"needReboot"`
// List OS users
OSUsers ListOSUsers `json:"osUsers"`
@@ -721,7 +750,7 @@ type RecordCompute struct {
}
// Information about of disk IDs
type ListInfoDisks []InfoDisk
type ListInfoDisks []InfoDisk
// Main information about compute for list
type ItemCompute struct {
@@ -732,7 +761,7 @@ type ItemCompute struct {
InfoCompute
// Total disk size
TotalDiskSize uint64 `json:"totalDiskSize"`
TotalDiskSize uint64 `json:"totalDisksSize"`
// VINS connected
VINSConnected uint64 `json:"vinsConnected"`

View File

@@ -20,7 +20,7 @@ type PFWListRequest struct {
}
// PFWList gets compute port forwards list
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFW, error) {
func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (*ListPFW, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
@@ -40,5 +40,5 @@ func (c Compute) PFWList(ctx context.Context, req PFWListRequest) (ListPFW, erro
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -16,7 +16,7 @@ type SnapshotListRequest struct {
}
// SnapshotList gets list of compute snapshots
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (ListSnapshots, error) {
func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (*ListSnapShot, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
@@ -29,12 +29,12 @@ func (c Compute) SnapshotList(ctx context.Context, req SnapshotListRequest) (Lis
return nil, err
}
list := ListSnapshots{}
list := ListSnapShot{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return list, nil
return &list, nil
}

View File

@@ -16,7 +16,7 @@ type UserListRequest struct {
}
// UserList gets users list for compute
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL, error) {
func (c Compute) UserList(ctx context.Context, req UserListRequest) (*ListUsers, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
@@ -29,7 +29,7 @@ func (c Compute) UserList(ctx context.Context, req UserListRequest) (*RecordACL,
return nil, err
}
list := RecordACL{}
list := ListUsers{}
err = json.Unmarshal(res, &list)
if err != nil {

View File

@@ -2,6 +2,7 @@ package grid
import (
"context"
"fmt"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
@@ -38,7 +39,7 @@ func (g Grid) GetDiagnosisGET(ctx context.Context, req GetDiagnosisRequest) (str
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/grid/getDiagnosis"
url := fmt.Sprintf("/cloudbroker/grid/getDiagnosis/?gid=%d", req.GID)
res, err := g.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {

View File

@@ -67,6 +67,9 @@ type DiskUsage struct {
// Detailed information about grid
type RecordGrid struct {
// AuthBroker
AuthBroker []interface{} `json:"authBroker"`
// Flag
Flag string `json:"flag"`
@@ -91,6 +94,9 @@ type ItemGridList struct {
// Resource information
Resources Resources `json:"Resources"`
// AuthBroker
AuthBroker []interface{} `json:"authBroker"`
// Flag
Flag string `json:"flag"`

View File

@@ -0,0 +1,36 @@
package k8ci
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AccessAddRequest struct for adding permission to access to account for a k8ci
type AccessAddRequest struct {
// ID of the K8 catalog item to add access for
// Required: true
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
// Account ID to add to the sharedWith access list
// Required: true
AccountId uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Add accountId to sharedWith access list for k8ci.
func (k K8CI) AccessAdd (ctx context.Context, req AccessAddRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8ci/accessAdd"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -0,0 +1,36 @@
package k8ci
import (
"context"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AccessRemoveRequest struct for removing permission to access to account for a k8ci
type AccessRemoveRequest struct {
// ID of the K8 catalog item to remove access for
// Required: true
K8CIID uint64 `url:"k8ciId" json:"k8ciId" validate:"required"`
// Account ID to be removed from the sharedWith access list
// Required: true
AccountId uint64 `url:"accountId" json:"accountId" validate:"required"`
}
// Remove accountId from sharedWith access list for k8ci.
func (k K8CI) AccessRemove (ctx context.Context, req AccessRemoveRequest) (string, error) {
err := validators.ValidateRequest(req)
if err != nil {
return "", validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/k8ci/accessRemove"
res, err := k.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return "", err
}
return string(res), nil
}

View File

@@ -17,7 +17,7 @@ type DeleteRequest struct {
// True if cluster is destroyed permanently.
// Otherwise it can be restored from recycle bin
// Required: false
Permanently bool `url:"permanently,omitempty" json:"permanently,omitempty"`
Permanently bool `url:"permanently" json:"permanently"`
}
// Delete deletes kubernetes cluster

View File

@@ -29,10 +29,10 @@ func (l LB) HighlyAvailable(ctx context.Context, req HighlyAvailableRequest) (bo
return false, err
}
result, err := strconv.ParseBool(string(res))
if err != nil {
result, err := strconv.ParseUint(string(res), 10, 64)
if err != nil || result != req.LBID {
return false, err
}
return result, nil
return true, nil
}

View File

@@ -13,6 +13,14 @@ type AffinityGroupsListRequest struct {
// Resource group ID
// Required: true
RGID uint64 `url:"rgId" json:"rgId" validate:"required"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
}
// AffinityGroupsList gets all currently defined affinity groups in this resource group with compute IDs

View File

@@ -53,3 +53,12 @@ func (lpfw ListPFW) IDs() []uint64 {
}
return res
}
// IDs gets array of ComputeIDs from ListAffinityGroupItems struct
func (lag ListAffinityGroupItems) IDs() []uint64 {
res := make([]uint64, 0, len(lag))
for _, ag := range lag {
res = append(res, ag.ID)
}
return res
}

View File

@@ -36,6 +36,10 @@ type ListRequest struct {
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`
// Find by status lock
// Required: false
LockStatus string `url:"lockStatus,omitempty" json:"lockStatus,omitempty"`
// Included deleted resource groups
// Required: false
IncludeDeleted bool `url:"includedeleted,omitempty" json:"includedeleted,omitempty"`

View File

@@ -65,6 +65,10 @@ type ItemResourceConsumption struct {
// Reserved information
Reserved Reservation `json:"Reserved"`
// Resource limits
ResourceLimits ResourceLimits `json:"resourceLimits"`
// Resource group ID
RGID uint64 `json:"rgid"`
}
@@ -687,8 +691,15 @@ type ListLB struct {
type ListAffinityGroup struct {
// Data
Data map[string][]uint64 `json:"data"`
Data []map[string]ListAffinityGroupItems `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
type ListAffinityGroupItems []ItemAffinityGroup
type ItemAffinityGroup struct {
ID uint64 `json:"id"`
NodeID uint64 `json:"node_id"`
}

View File

@@ -1,4 +1,3 @@
// Lists all the stack.
package stack
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"