This commit is contained in:
asteam
2025-11-14 17:59:31 +03:00
parent 18a4311b97
commit e3a65c0f33
151 changed files with 10721 additions and 28 deletions

View File

@@ -0,0 +1,50 @@
package rule
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
)
// GetRequest struct to get a security rules
type GetRequest struct {
// Security policy ID
// Required: true
SecurityPolicyID string `url:"security_policy_id" json:"security_policy_id" validate:"required"`
// Security rule ID
// Required: true
SecurityRuleID string `url:"security_rule_id" json:"security_rule_id" validate:"required"`
}
// Get a security policies
func (i Rule) Get(ctx context.Context, req GetRequest) (*SecurityRule, error) {
res, err := i.GetRaw(ctx, req)
if err != nil {
return nil, err
}
result := SecurityRule{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return &result, nil
}
// GetRaw gets a security rule as an array of bytes
func (a Rule) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/sdn/security_policy/rule/get"
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,10 @@
package rule
// IDs gets array of IDs from SecurityRulesList struct
func (srl SecurityRulesList) IDs() []string {
res := make([]string, 0, len(srl))
for _, c := range srl {
res = append(res, c.ID)
}
return res
}

View File

@@ -0,0 +1,70 @@
package rule
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/validators"
)
// ListRequest struct to get a list of security rules
type ListRequest struct {
// Security policy ID
// Required: true
SecurityPolicyID string `url:"security_policy_id" json:"security_policy_id" validate:"required"`
// Display name
// Required: false
DisplayName string `url:"display_name,omitempty" json:"display_name,omitempty"`
// Enabled status
// Required: false
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
// Page number for pagination
// Required: false
Page uint64 `url:"page,omitempty" json:"page,omitempty"`
// Number of results per page
// Required: false
PerPage uint64 `url:"per_page,omitempty" json:"per_page,omitempty"`
// Field to sort by (display_name, enabled, created_at, updated_at, deleted_at, start_priority)
// Required: false
SortBy string `url:"sort_by,omitempty" json:"sort_by,omitempty"`
// Sort order (asc/desc)
// Required: false
SortOrder string `url:"sort_order,omitempty" json:"sort_order,omitempty"`
}
// List of security policies
func (i Rule) List(ctx context.Context, req ListRequest) (SecurityRulesList, error) {
res, err := i.ListRaw(ctx, req)
if err != nil {
return nil, err
}
result := []SecurityRule{}
err = json.Unmarshal(res, &result)
if err != nil {
return nil, err
}
return result, nil
}
// ListRaw gets a list of all security rules as an array of bytes
func (a Rule) ListRaw(ctx context.Context, req ListRequest) ([]byte, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/sdn/security_policy/rule/list"
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
return res, err
}

View File

@@ -0,0 +1,54 @@
package rule
type SecurityRulesList []SecurityRule
// SecurityRule
type SecurityRule struct {
// Access group ID
AccessGroupID string `json:"access_group_id"`
// Action to take (Allow, Deny, etc.)
Action string `json:"action"`
// Description
Description string `json:"description"`
// Traffic direction (Ingress, Egress)
Direction string `json:"direction"`
// Display name
DisplayName string `json:"display_name"`
// Enabled flag
Enabled bool `json:"enabled"`
// Filter criteria
Filter Filter `json:"filter"`
// ID
ID string `json:"id"`
// Log enabled flag
LogEnabled bool `json:"log_enabled"`
// Log severity level
LogSeverity string `json:"log_severity"`
// Priority
Priority int `json:"priority"`
// Security policy ID
SecurityPolicyID string `json:"security_policy_id"`
// Statistics enabled flag
StatisticsEnabled bool `json:"statistics_enabled"`
// Version ID
VersionID uint64 `json:"version_id"`
}
// Filter represents the filter criteria for the security rule
type Filter struct {
// Filters map
Filters map[string]interface{} `json:"filters"`
}

View File

@@ -0,0 +1,18 @@
// API Actor API for managing SDN security policies rule
package rule
import (
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/interfaces"
)
// Structure for creating request to security policies rule
type Rule struct {
client interfaces.Caller
}
// Builder for security policies rule endpoints
func New(client interfaces.Caller) *Rule {
return &Rule{
client,
}
}

View File

@@ -0,0 +1,27 @@
package rule
import (
"encoding/json"
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v12/internal/serialization"
)
// Serialize returns JSON-serialized []byte. Used as a wrapper over json.Marshal and json.MarshalIndent functions.
//
// In order to serialize with indent make sure to follow these guidelines:
// - First argument -> prefix
// - Second argument -> indent
func (la SecurityRulesList) Serialize(params ...string) (serialization.Serialized, error) {
if len(la) == 0 {
return []byte{}, nil
}
if len(params) > 1 {
prefix := params[0]
indent := params[1]
return json.MarshalIndent(la, prefix, indent)
}
return json.Marshal(la)
}