This commit is contained in:
2026-09-04 17:29:39 +04:00
parent fe3c7bf63a
commit dbd979b6f3
23 changed files with 450 additions and 130 deletions

View File

@@ -90,6 +90,9 @@ type ListRequest struct {
// Exclude audit lines from response
// Required: false
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
}
// List gets audit records for the specified account object

View File

@@ -2,7 +2,6 @@ package audit
// Main info about audit
type RecordAudit struct {
// Arguments
Arguments string `json:"args"`
@@ -41,6 +40,9 @@ type RecordAudit struct {
// User
User string `json:"user"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
}
// Main info about audit
@@ -81,6 +83,9 @@ type ItemAudit struct {
// User
User string `json:"user"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
// TTL
TTL string `json:"_ttl"`
}

View File

@@ -18,10 +18,6 @@ type ListVGPURequest struct {
// Required: false
GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,omitempty"`
// Find by type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`

View File

@@ -73,10 +73,10 @@ type Rule struct {
Protocol string `json:"protocol"`
// Priority Code Point (0-7). L2 marking
PCPTag uint64 `json:"pcp_tag"`
PCPTag *uint64 `json:"pcp_tag"`
// DSCP value (0-63). L3 marking
DSCPValue uint64 `json:"dscp_value"`
DSCPValue *uint64 `json:"dscp_value"`
// Source IP address
SrcIP string `json:"src_ip"`

View File

@@ -16,11 +16,11 @@ type UpdateRequest struct {
// New QoS policy name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
// New QoS policy description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
}
func (qp QoSPolicy) Update(ctx context.Context, req UpdateRequest) (*RecordQoSPolicy, error) {

View File

@@ -329,6 +329,9 @@ type ItemVNFInterface struct {
// QOS
QOS QOS `json:"qos"`
// List of QoS policies
QoSPolicies []uint64 `json:"qos_policies"`
// Target
Target string `json:"target"`

View File

@@ -94,6 +94,9 @@ type ListRequest struct {
// Exclude audit lines from response
// Required: false
ExcludeAuditLines bool `url:"exclude_audit_lines,omitempty" json:"exclude_audit_lines,omitempty"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
}
// List gets audit records for the specified account object

View File

@@ -38,6 +38,9 @@ type ItemAudit struct {
// User
User string `json:"user"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
// TTL
TTL string `json:"_ttl"`
}
@@ -93,6 +96,9 @@ type RecordAudit struct {
// User
User string `json:"user"`
// Public Session ID
PublicSessionID string `json:"public_session_id"`
// TTL
TTL string `json:"_ttl"`

View File

@@ -18,10 +18,6 @@ type ListVGPURequest struct {
// Required: false
GPUID uint64 `url:"gpuId,omitempty" json:"gpuId,omitempty"`
// Find by type
// Required: false
Type string `url:"type,omitempty" json:"type,omitempty"`
// Find by status
// Required: false
Status string `url:"status,omitempty" json:"status,omitempty"`

View File

@@ -114,6 +114,9 @@ type RecordGrid struct {
// Is BRO enabled
BROEnabled bool `json:"bro_enabled"`
// Budget
Budget bool `json:"budget"`
}
// Information about grid
@@ -159,6 +162,9 @@ type ItemGridList struct {
// Is BRO enabled
BROEnabled bool `json:"bro_enabled"`
// Budget
Budget bool `json:"budget"`
}
// List Grids

View File

@@ -73,10 +73,10 @@ type Rule struct {
Protocol string `json:"protocol"`
// Priority Code Point (0-7). L2 marking
PCPTag uint64 `json:"pcp_tag"`
PCPTag *uint64 `json:"pcp_tag"`
// DSCP value (0-63). L3 marking
DSCPValue uint64 `json:"dscp_value"`
DSCPValue *uint64 `json:"dscp_value"`
// Source IP address
SrcIP string `json:"src_ip"`

View File

@@ -16,11 +16,11 @@ type UpdateRequest struct {
// New QoS policy name
// Required: false
Name string `url:"name,omitempty" json:"name,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
// New QoS policy description
// Required: false
Description string `url:"description,omitempty" json:"description,omitempty"`
Description *string `url:"description,omitempty" json:"description,omitempty"`
}
func (qp QoSPolicy) Update(ctx context.Context, req UpdateRequest) (*RecordQoSPolicy, error) {

View File

@@ -0,0 +1,8 @@
package cloudbroker
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/pkg/cloudbroker/session"
// Accessing the session method group
func (cb *CloudBroker) Session() *session.Session {
return session.New(cb.client)
}

View File

@@ -0,0 +1,53 @@
package session
// FilterByID returns ListSession with specified ID.
func (lsession ListSession) FilterByID(id string) ListSession {
predicate := func(rsession ItemSession) bool {
return rsession.PublicSessionID == id
}
return lsession.FilterFunc(predicate)
}
// FilterByName returns ListSession with specified User.
func (lsession ListSession) FilterByUser(user string) ListSession {
predicate := func(rsession ItemSession) bool {
return rsession.User == user
}
return lsession.FilterFunc(predicate)
}
// FilterByObjStatus returns ListSession with specified IP.
func (lsession ListSession) FilterByIP(ip string) ListSession {
predicate := func(rsession ItemSession) bool {
return rsession.IP == ip
}
return lsession.FilterFunc(predicate)
}
// FilterFunc allows filtering ListSession based on user-specified predicate.
func (lsession ListSession) FilterFunc(predicate func(session ItemSession) bool) ListSession {
var result ListSession
for _, item := range lsession.Data {
if predicate(item) {
result.Data = append(result.Data, item)
}
}
result.EntryCount = uint64(len(result.Data))
return result
}
// FindOne returns first found ItemSession
// If none was found, returns an empty struct.
func (lsession ListSession) FindOne() ItemSession {
if len(lsession.Data) == 0 {
return ItemSession{}
}
return lsession.Data[0]
}

View File

@@ -0,0 +1,54 @@
package session
import "testing"
var sessions = ListSession{
Data: []ItemSession{
{
PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd1",
IP: "10.244.0.243",
User: "someuser",
},
{
PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd5",
IP: "10.244.0.242",
User: "someuser2",
},
{
PublicSessionID: "06674bdf-13f1-4f78-a40a-242fd76e4cd7",
IP: "10.244.0.243",
User: "someuser2",
},
},
EntryCount: 3,
}
func TestFilterByID(t *testing.T) {
actual := sessions.FilterByID("06674bdf-13f1-4f78-a40a-242fd76e4cd1").FindOne()
if actual.PublicSessionID != "06674bdf-13f1-4f78-a40a-242fd76e4cd1" {
t.Fatal("expected ID 1, found: ", actual.PublicSessionID)
}
}
func TestFilterByUser(t *testing.T) {
actual := sessions.FilterByUser("someuser").FindOne()
if actual.User != "someuser" {
t.Fatal("expected User 'someuser', found: ", actual.User)
}
}
func TestFilterByIP(t *testing.T) {
actual := sessions.FilterByIP("10.244.0.243")
if len(actual.Data) != 2 {
t.Fatal("expected 2 found, actual: ", len(actual.Data))
}
for _, item := range actual.Data {
if item.IP != "10.244.0.243" {
t.Fatal("expected IP '10.244.0.243', found: ", item.IP)
}
}
}

View File

@@ -0,0 +1,46 @@
package session
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
)
// GetRequest struct to get Session parameters
type GetRequest struct {
// Storage endpoint provider ID
// Required: true
PublicSessionID string `url:"public_session_id" json:"public_session_id" validate:"required"`
}
// Get gets Session parameters as a RecordSession struct
func (s Session) Get(ctx context.Context, req GetRequest) (*RecordSession, error) {
res, err := s.GetRaw(ctx, req)
if err != nil {
return nil, err
}
info := RecordSession{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}
// GetRaw gets Session parameters as an array of bytes
func (s Session) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/session/get"
res, err := s.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,10 @@
package session
// IDs gets array of PublicSessionIDs from ListSession struct
func (ls ListSession) IDs() []string {
res := make([]string, 0, len(ls.Data))
for _, s := range ls.Data {
res = append(res, s.PublicSessionID)
}
return res
}

View File

@@ -0,0 +1,79 @@
package session
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/internal/validators"
)
type ListRequest struct {
// Filter by username
User string `url:"user,omitempty" json:"user,omitempty"`
// Filter by authorization system (bvs, decs3o, password)
AuthorizeSystem string `url:"authorize_system,omitempty" json:"authorize_system,omitempty"`
// Filter by public session ID (UUID)
PublicSessionID string `url:"public_session_id,omitempty" json:"public_session_id,omitempty"`
// Filter by sub from JWT
Sub string `url:"sub,omitempty" json:"sub,omitempty"`
// Filter by sid from JWT
SID uint64 `url:"sid,omitempty" json:"sid,omitempty"`
// Filter sessions with login_time >= timestamp (Unix timestamp)
TimestampAt uint64 `url:"timestamp_at,omitempty" json:"timestamp_at,omitempty"`
// Filter sessions with login_time <= timestamp (Unix timestamp)
TimestampTo uint64 `url:"timestamp_to,omitempty" json:"timestamp_to,omitempty"`
// Filter sessions active at this timestamp (login_time <= T < logout_time/expires_at)
ActiveAt uint64 `url:"active_at,omitempty" json:"active_at,omitempty"`
// Page size
// Required: false
Size uint64 `url:"size,omitempty" json:"size,omitempty"`
// Page number
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Sort by one of supported fields, format +|-(field)
// Required: false
SortBy string `url:"sortBy,omitempty" json:"sortBy,omitempty"`
}
// List gets list of sessions as a ListSession struct
func (s Session) List(ctx context.Context, req ListRequest) (*ListSession, error) {
res, err := s.ListRaw(ctx, req)
if err != nil {
return nil, err
}
list := ListSession{}
err = json.Unmarshal(res, &list)
if err != nil {
return nil, err
}
return &list, nil
}
// ListRaw gets list of sessions as an array of bytes
func (s Session) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
err := validators.ValidateRequest(req)
if err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/session/list"
res, err := s.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,85 @@
package session
// Main information about a session
type RecordSession struct {
// Public session ID
PublicSessionID string `json:"public_session_id"`
// Username
User string `json:"user"`
// Subject from JWT
Sub string `json:"sub"`
// Session ID from JWT
SID string `json:"sid"`
// Authorization system
AuthorizeSystem string `json:"authorize_system"`
// Client IP address
IP string `json:"ip"`
// Client User-Agent
UserAgent string `json:"user_agent"`
// First login time
LoginTime string `json:"login_time"`
// Last activity time
UpdatedAt string `json:"updated_at"`
// Logout time
LogoutTime string `json:"logout_time"`
// Session expiration time
Expires string `json:"expires"`
// OAuth provider type
OAuthType string `json:"oauth_type"`
}
// List of sessions
type ListSession struct {
// Data
Data []ItemSession `json:"data"`
// Entry count
EntryCount uint64 `json:"entryCount"`
}
// A session item
type ItemSession struct {
// Public session ID
PublicSessionID string `json:"public_session_id"`
// Username
User string `json:"user"`
// Subject from JWT
Sub string `json:"sub"`
// Session ID from JWT
SID string `json:"sid"`
// Authorization system
AuthorizeSystem string `json:"authorize_system"`
// Client IP address
IP string `json:"ip"`
// Client User-Agent
UserAgent string `json:"user_agent"`
// First login time
LoginTime string `json:"login_time"`
// Last activity time
UpdatedAt string `json:"updated_at"`
// Logout time
LogoutTime string `json:"logout_time"`
// Session expiration time
Expires string `json:"expires"`
}

View File

@@ -0,0 +1,18 @@
// Operator actions for handling interventions on a session
package session
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v16/interfaces"
)
// Structure for creating request to session
type Session struct {
client interfaces.Caller
}
// Builder for Session endpoints
func New(client interfaces.Caller) *Session {
return &Session{
client: client,
}
}

View File

@@ -173,6 +173,9 @@ type ItemInterface struct {
// QOS
QOS QOS `json:"qos"`
// List of QoS policies
QoSPolicies []uint64 `json:"qos_policies"`
// Target
Target string `json:"target"`