v1.12.2
This commit is contained in:
10
pkg/sdn/access_groups.go
Normal file
10
pkg/sdn/access_groups.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package sdn
|
||||
|
||||
import (
|
||||
ag "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/sdn/acsgroups"
|
||||
)
|
||||
|
||||
// Accessing the SDN method group
|
||||
func (sdn *SDN) AccessGroups() *ag.AccessGroups {
|
||||
return ag.New(sdn.client)
|
||||
}
|
||||
18
pkg/sdn/acsgroups/access_groups.go
Normal file
18
pkg/sdn/acsgroups/access_groups.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// API Actor API for managing SDN access groups
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
)
|
||||
|
||||
// Structure for creating request to access groups
|
||||
type AccessGroups struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for access groups endpoints
|
||||
func New(client interfaces.Caller) *AccessGroups {
|
||||
return &AccessGroups{
|
||||
client,
|
||||
}
|
||||
}
|
||||
45
pkg/sdn/acsgroups/create.go
Normal file
45
pkg/sdn/acsgroups/create.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// CreateRequest struct to create access group
|
||||
type CreateRequest struct {
|
||||
// Comment of the access group
|
||||
// Required: true
|
||||
Comment string `url:"comment" json:"comment" validate:"required"`
|
||||
|
||||
// Name of acces group
|
||||
// Required: true
|
||||
DisplayName string `url:"display_name" json:"display_name" validate:"required"`
|
||||
}
|
||||
|
||||
// Create creates a access groups
|
||||
func (i AccessGroups) Create(ctx context.Context, req CreateRequest) (*AccessGroupItem, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/create"
|
||||
|
||||
res, err := i.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := AccessGroupItem{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
39
pkg/sdn/acsgroups/delete.go
Normal file
39
pkg/sdn/acsgroups/delete.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// DeleteRequest struct to delete access group
|
||||
type DeleteRequest struct {
|
||||
// Comment of the access group
|
||||
// Required: true
|
||||
GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
}
|
||||
|
||||
// Delete a access groups
|
||||
func (i AccessGroups) Delete(ctx context.Context, req DeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/delete"
|
||||
|
||||
res, err := i.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
result, err := strconv.ParseBool(string(res))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
42
pkg/sdn/acsgroups/filter.go
Normal file
42
pkg/sdn/acsgroups/filter.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package acsgroups
|
||||
|
||||
// FilterByID returns AccessGroupList with specified ID.
|
||||
func (agl AccessGroupList) FilterByID(id string) AccessGroupList {
|
||||
predicate := func(ia AccessGroup) bool {
|
||||
return ia.ID == id
|
||||
}
|
||||
|
||||
return agl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterByName returns AccessGroupList with specified Name.
|
||||
func (agl AccessGroupList) FilterByName(name string) AccessGroupList {
|
||||
predicate := func(ia AccessGroup) bool {
|
||||
return ia.DisplayName == name
|
||||
}
|
||||
|
||||
return agl.FilterFunc(predicate)
|
||||
}
|
||||
|
||||
// FilterFunc allows filtering AccessGroupList based on a user-specified predicate.
|
||||
func (agl AccessGroupList) FilterFunc(predicate func(AccessGroup) bool) AccessGroupList {
|
||||
var result AccessGroupList
|
||||
|
||||
for _, acc := range agl.AccessGroups {
|
||||
if predicate(acc) {
|
||||
result.AccessGroups = append(result.AccessGroups, acc)
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// FindOne returns first element.
|
||||
// If none was found, returns an empty struct.
|
||||
func (agl AccessGroupList) FindOne() AccessGroup {
|
||||
if len(agl.AccessGroups) == 0 {
|
||||
return AccessGroup{}
|
||||
}
|
||||
|
||||
return agl.AccessGroups[0]
|
||||
}
|
||||
89
pkg/sdn/acsgroups/filter_test.go
Normal file
89
pkg/sdn/acsgroups/filter_test.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testAccessGroups = AccessGroupList{
|
||||
AccessGroups: []AccessGroup{
|
||||
{
|
||||
ID: "group1",
|
||||
DisplayName: "Developers",
|
||||
Comment: "First group",
|
||||
CreatedAt: "2023-01-01",
|
||||
CreatedBy: "admin",
|
||||
},
|
||||
{
|
||||
ID: "group2",
|
||||
DisplayName: "Admins",
|
||||
Comment: "Second group",
|
||||
CreatedAt: "2023-01-02",
|
||||
CreatedBy: "admin",
|
||||
},
|
||||
{
|
||||
ID: "group3",
|
||||
DisplayName: "Users",
|
||||
Comment: "Third group",
|
||||
CreatedAt: "2023-01-03",
|
||||
CreatedBy: "admin",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestFilterByID(t *testing.T) {
|
||||
actual := testAccessGroups.FilterByID("group2").FindOne()
|
||||
|
||||
if actual.ID != "group2" {
|
||||
t.Fatal("actual:", actual.ID, "> expected: group2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByName(t *testing.T) {
|
||||
actual := testAccessGroups.FilterByName("Users").FindOne()
|
||||
|
||||
if actual.DisplayName != "Users" {
|
||||
t.Fatal("actual:", actual.DisplayName, ">> expected: Users")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterFunc(t *testing.T) {
|
||||
actual := testAccessGroups.FilterFunc(func(ag AccessGroup) bool {
|
||||
return ag.Comment == "Second group"
|
||||
})
|
||||
|
||||
if len(actual.AccessGroups) != 1 || actual.AccessGroups[0].ID != "group2" {
|
||||
t.Fatal("Expected 1 group with comment 'Second group', found:", len(actual.AccessGroups))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneWithResults(t *testing.T) {
|
||||
result := testAccessGroups.FilterByID("group1").FindOne()
|
||||
if result.ID != "group1" {
|
||||
t.Fatal("Expected group1, got:", result.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindOneEmpty(t *testing.T) {
|
||||
emptyList := AccessGroupList{}
|
||||
result := emptyList.FindOne()
|
||||
|
||||
if result.ID != "" || result.DisplayName != "" {
|
||||
t.Fatal("Expected empty AccessGroup, got:", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByIDNotFound(t *testing.T) {
|
||||
actual := testAccessGroups.FilterByID("nonexistent")
|
||||
|
||||
if len(actual.AccessGroups) != 0 {
|
||||
t.Fatal("Expected 0 groups, found:", len(actual.AccessGroups))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterByNameNotFound(t *testing.T) {
|
||||
actual := testAccessGroups.FilterByName("Nonexistent Group")
|
||||
|
||||
if len(actual.AccessGroups) != 0 {
|
||||
t.Fatal("Expected 0 groups, found:", len(actual.AccessGroups))
|
||||
}
|
||||
}
|
||||
19
pkg/sdn/acsgroups/ids.go
Normal file
19
pkg/sdn/acsgroups/ids.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package acsgroups
|
||||
|
||||
// IDs gets array of IDs from AccessGroupList struct
|
||||
func (agl AccessGroupList) IDs() []string {
|
||||
res := make([]string, 0, len(agl.AccessGroups))
|
||||
for _, c := range agl.AccessGroups {
|
||||
res = append(res, c.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// IDs gets array of IDs from UsersList struct
|
||||
func (ul UsersList) IDs() []string {
|
||||
res := make([]string, 0, len(ul.Users))
|
||||
for _, c := range ul.Users {
|
||||
res = append(res, c.ID)
|
||||
}
|
||||
return res
|
||||
}
|
||||
80
pkg/sdn/acsgroups/list.go
Normal file
80
pkg/sdn/acsgroups/list.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// ListGroupsRequest struct to get a list of access groups
|
||||
type ListGroupsRequest struct {
|
||||
// Find by enabled status, true or false
|
||||
// Required: false
|
||||
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Find by deleted status, true or false
|
||||
// Required: false
|
||||
Deleted interface{} `url:"deleted,omitempty" json:"deleted,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Display name filter
|
||||
// Required: false
|
||||
DisplayName string `url:"display_name,omitempty" json:"display_name,omitempty"`
|
||||
|
||||
// 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, created_at, updated_at, deleted_at, owner_login)
|
||||
// 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"`
|
||||
|
||||
// Creation date lower bound (inclusive)
|
||||
// Required: false
|
||||
CreatedFrom string `url:"created_from,omitempty" json:"created_from,omitempty"`
|
||||
|
||||
// Creation date upper bound (inclusive)
|
||||
// Required: false
|
||||
CreatedTo string `url:"created_to,omitempty" json:"created_to,omitempty"`
|
||||
}
|
||||
|
||||
// List of access groups
|
||||
func (i AccessGroups) List(ctx context.Context, req ListGroupsRequest) (*AccessGroupList, error) {
|
||||
res, err := i.ListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
groups := []AccessGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &groups)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := AccessGroupList{AccessGroups: groups}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all users as an array of bytes
|
||||
func (a AccessGroups) ListRaw(ctx context.Context, req ListGroupsRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/list"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
49
pkg/sdn/acsgroups/models.go
Normal file
49
pkg/sdn/acsgroups/models.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package acsgroups
|
||||
|
||||
type AccessGroupItem struct {
|
||||
Name string `json:"display_name"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type AccessGroupList struct {
|
||||
AccessGroups []AccessGroup
|
||||
}
|
||||
|
||||
type AccessGroup struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Comment string `json:"comment"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
CreatedBy string `json:"created_by"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
UpdatedBy string `json:"updated_by"`
|
||||
NetObjectAccessGroup NetObjectAccessGroup `json:"net_object_access_group"`
|
||||
DefaultSecurityPolicy DefaultSecurityPolicy `json:"default_security_policy"`
|
||||
}
|
||||
|
||||
type NetObjectAccessGroup struct {
|
||||
ID string `json:"id"`
|
||||
VersionID int64 `json:"version_id"`
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
}
|
||||
|
||||
type DefaultSecurityPolicy struct {
|
||||
ID string `json:"id"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Description string `json:"description"`
|
||||
VersionID int64 `json:"version_id"`
|
||||
AccessGroupID string `json:"access_group_id"`
|
||||
DefaultAclDrop string `json:"default_acl_drop"`
|
||||
DefaultOpenSessionDrop bool `json:"default_open_session_drop"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string `json:"display_name"`
|
||||
ID string `json:"id"`
|
||||
RoleID string `json:"role_id"`
|
||||
Login string `json:"login"`
|
||||
}
|
||||
|
||||
type UsersList struct {
|
||||
Users []User
|
||||
}
|
||||
49
pkg/sdn/acsgroups/path.go
Normal file
49
pkg/sdn/acsgroups/path.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// PatchRequest struct to update access group
|
||||
type PatchRequest struct {
|
||||
// Access group ID
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Comment of the acces group
|
||||
// Required: false
|
||||
Comment string `url:"comment,omitempty" json:"comment,omitempty"`
|
||||
|
||||
// Name of acces group
|
||||
// Required: false
|
||||
DisplayName string `url:"display_name,omitempty" json:"display_name,omitempty"`
|
||||
}
|
||||
|
||||
// Update updates a access groups
|
||||
func (i AccessGroups) Patch(ctx context.Context, req PatchRequest) (*AccessGroup, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/patch"
|
||||
|
||||
res, err := i.client.DecortApiCallCtype(ctx, http.MethodPatch, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := AccessGroup{}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
41
pkg/sdn/acsgroups/user_add.go
Normal file
41
pkg/sdn/acsgroups/user_add.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// UserAddRequest struct to userAdd access group
|
||||
type UserAddRequest struct {
|
||||
// Comment of the access group
|
||||
// Required: true
|
||||
GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group role ID
|
||||
// Required: true
|
||||
AccessGroupRoleID string `url:"access_group_role_id" json:"access_group_role_id" validate:"required"`
|
||||
|
||||
// User ID
|
||||
// Required: true
|
||||
UserID string `url:"user_id" json:"user_id" validate:"required"`
|
||||
}
|
||||
|
||||
// UserAdd a access groups
|
||||
func (i AccessGroups) UserAdd(ctx context.Context, req UserAddRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/user_add"
|
||||
|
||||
_, err = i.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
37
pkg/sdn/acsgroups/user_delete.go
Normal file
37
pkg/sdn/acsgroups/user_delete.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// UserDeleteRequest struct to userDelete access group
|
||||
type UserDeleteRequest struct {
|
||||
// Comment of the access group
|
||||
// Required: true
|
||||
GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// User ID
|
||||
// Required: true
|
||||
UserID string `url:"user_id" json:"user_id" validate:"required"`
|
||||
}
|
||||
|
||||
// UserDelete a access groups
|
||||
func (i AccessGroups) UserDelete(ctx context.Context, req UserDeleteRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/user_delete"
|
||||
|
||||
_, err = i.client.DecortApiCallCtype(ctx, http.MethodDelete, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
113
pkg/sdn/acsgroups/user_list.go
Normal file
113
pkg/sdn/acsgroups/user_list.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// UsersListRequest struct to get a list of users
|
||||
type UsersListRequest struct {
|
||||
// Access group identifier
|
||||
// Required: true
|
||||
AccessGroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Filter by global role
|
||||
// Required: false
|
||||
GlobalRole string `url:"global_role,omitempty" json:"global_role,omitempty"`
|
||||
|
||||
// Filter by access group role
|
||||
// Required: false
|
||||
AccessGroupRole string `url:"access_group_role,omitempty" json:"access_group_role,omitempty"`
|
||||
|
||||
// Filter by enabled status (true/false)
|
||||
// Required: false
|
||||
Enabled interface{} `url:"enabled,omitempty" json:"enabled,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Filter by deleted status (true/false)
|
||||
// Required: false
|
||||
Deleted interface{} `url:"deleted,omitempty" json:"deleted,omitempty" validate:"omitempty,isBool"`
|
||||
|
||||
// Filter by display name
|
||||
// Required: false
|
||||
DisplayName string `url:"display_name,omitempty" json:"display_name,omitempty"`
|
||||
|
||||
// Filter by user login
|
||||
// Required: false
|
||||
Login string `url:"login,omitempty" json:"login,omitempty"`
|
||||
|
||||
// Filter by creator login
|
||||
// Required: false
|
||||
CreatedBy string `url:"created_by,omitempty" json:"created_by,omitempty"`
|
||||
|
||||
// Filter by last updater login
|
||||
// Required: false
|
||||
UpdatedBy string `url:"updated_by,omitempty" json:"updated_by,omitempty"`
|
||||
|
||||
// Filter by deleter login
|
||||
// Required: false
|
||||
DeletedBy string `url:"deleted_by,omitempty" json:"deleted_by,omitempty"`
|
||||
|
||||
// Filter by disabler login
|
||||
// Required: false
|
||||
DisabledBy string `url:"disabled_by,omitempty" json:"disabled_by,omitempty"`
|
||||
|
||||
// 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, email, phone, created_at, updated_at, deleted_at)
|
||||
// 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"`
|
||||
|
||||
// Creation date lower bound (inclusive)
|
||||
// Required: false
|
||||
CreatedFrom string `url:"created_from,omitempty" json:"created_from,omitempty"`
|
||||
|
||||
// Creation date upper bound (exclusive)
|
||||
// Required: false
|
||||
CreatedTo string `url:"created_to,omitempty" json:"created_to,omitempty"`
|
||||
}
|
||||
|
||||
// List of access groups
|
||||
func (i AccessGroups) UsersList(ctx context.Context, req UsersListRequest) (*UsersList, error) {
|
||||
|
||||
res, err := i.UserListRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
users := []User{}
|
||||
|
||||
err = json.Unmarshal(res, &users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := UsersList{Users: users}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// ListRaw gets a list of all users as an array of bytes
|
||||
func (a AccessGroups) UserListRaw(ctx context.Context, req UsersListRequest) ([]byte, error) {
|
||||
|
||||
if err := validators.ValidateRequest(req); err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/user_list"
|
||||
|
||||
res, err := a.client.DecortApiCall(ctx, http.MethodGet, url, req)
|
||||
return res, err
|
||||
}
|
||||
41
pkg/sdn/acsgroups/user_update_role.go
Normal file
41
pkg/sdn/acsgroups/user_update_role.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package acsgroups
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
|
||||
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
|
||||
)
|
||||
|
||||
// UserUpdateRoleRequest struct to userUpdateRole access group
|
||||
type UserUpdateRoleRequest struct {
|
||||
// Comment of the access group
|
||||
// Required: true
|
||||
GroupID string `url:"access_group_id" json:"access_group_id" validate:"required"`
|
||||
|
||||
// Access group role ID
|
||||
// Required: true
|
||||
AccessGroupRoleID string `url:"access_group_role_id" json:"access_group_role_id" validate:"required"`
|
||||
|
||||
// User ID
|
||||
// Required: true
|
||||
UserID string `url:"user_id" json:"user_id" validate:"required"`
|
||||
}
|
||||
|
||||
// UserUpdateRole a access groups
|
||||
func (i AccessGroups) UserUpdateRole(ctx context.Context, req UserUpdateRoleRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/sdn/access_group/update_role"
|
||||
|
||||
_, err = i.client.DecortApiCallCtype(ctx, http.MethodPut, url, constants.MIMEJSON, req)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
16
pkg/sdn/sdn.go
Normal file
16
pkg/sdn/sdn.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// List of method groups for the SDN
|
||||
package sdn
|
||||
|
||||
import "repository.basistech.ru/BASIS/decort-golang-sdk/interfaces"
|
||||
|
||||
// Structure for creating request to SDN groups
|
||||
type SDN struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder to get access to SDN
|
||||
func New(client interfaces.Caller) *SDN {
|
||||
return &SDN{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user