This commit is contained in:
2023-06-23 15:13:22 +03:00
parent c06a3198f6
commit 264538f492
50 changed files with 2143 additions and 76 deletions

View File

@@ -0,0 +1,42 @@
package group
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Reuqest struct for getting details of the specified group.
type GetRequest struct {
// Group ID
// Required: true
GroupID string `url:"groupId" json:"groupId" validate:"required"`
}
// Get gets details of the specified group.
func (g Group) Get(ctx context.Context, req GetRequest) (*ItemGroup, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudbroker/group/get"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ItemGroup{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

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

View File

@@ -0,0 +1,57 @@
package group
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// Request struct for getting list of group instances.
type ListRequest struct {
// Find by id.
// Requires: false
ByID uint64 `url:"by_id,omitempty" json:"by_id,omitempty"`
// Find by list users.
// Required: false
User string `url:"user,omitempty" json:"user,omitempty"`
// Page number.
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Page size, maximum - 100.
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Find by active True or False.
// Required: true
Active bool `url:"active" json:"active" validate:"required"`
}
func (g Group) List(ctx context.Context, req ListRequest) (*ListGroups, error) {
err := validators.ValidateRequest(req)
if err != nil {
for _, validationError := range validators.GetErrors(err) {
return nil, validators.ValidationError(validationError)
}
}
url := "/cloudbroker/group/list"
res, err := g.client.DecortApiCall(ctx, http.MethodPost, url, req)
if err != nil {
return nil, err
}
info := ListGroups{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -0,0 +1,42 @@
package group
type ItemGroup struct {
// CKey
CKey string `json:"_ckey"`
// Meta
Meta []interface{} `json:"meta"`
// Is active
Actice bool `json:"active"`
// Description
Description string `json:"description"`
// Domain
Domain string `json:"domain"`
// GID
GID uint64 `json:"gid"`
// GUID
GUID string `json:"guid"`
// ID
ID string
// Last check
LastCheck uint64 `json:"lastcheck"`
// Roles
Roles []interface{} `json:"roles"`
// Users
Users []string `json:"users"`
}
type ListGroups struct {
Data []ItemGroup `json:"data"`
EntryCount uint64 `json:"entryCount"`
}