v9.0.0
This commit is contained in:
41
pkg/cloudapi/user/api_list.go
Normal file
41
pkg/cloudapi/user/api_list.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// APIListRequest struct for getting API list.
|
||||
type APIListRequest struct {
|
||||
// ID of the user.
|
||||
// Required: true
|
||||
UserID string `url:"userId" json:"userId" validate:"required"`
|
||||
}
|
||||
|
||||
// APIList gets a list of all API functions that a given user has
|
||||
// access to according to their apiaccess group membership.
|
||||
func (u User) APIList(ctx context.Context, req APIListRequest) (*APIsEndpoints, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/apiList"
|
||||
|
||||
info := APIsEndpoints{}
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
38
pkg/cloudapi/user/authenticate.go
Normal file
38
pkg/cloudapi/user/authenticate.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// AuthenticateRequest struct to authenticate user.
|
||||
type AuthenticateRequest struct {
|
||||
// Username
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
|
||||
// Password
|
||||
// Required: true
|
||||
Password string `url:"password" json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
// Authenticate evaluates the provided username and password and returns a session key.
|
||||
// The session key can be used for doing api requests. E.g this is the authkey parameter in every actor request.
|
||||
// A session key is only vallid for a limited time.
|
||||
func (u User) Authenticate(ctx context.Context, req AuthenticateRequest) (string, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return "", validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/authenticate"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(res), nil
|
||||
}
|
||||
26
pkg/cloudapi/user/brief.go
Normal file
26
pkg/cloudapi/user/brief.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Brief gets information about user's enabled and disabled resources.
|
||||
func (u User) Brief(ctx context.Context) (*BriefResources, error) {
|
||||
url := "/cloudapi/user/brief"
|
||||
|
||||
info := BriefResources{}
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(res, &info)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &info, nil
|
||||
}
|
||||
46
pkg/cloudapi/user/get.go
Normal file
46
pkg/cloudapi/user/get.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to get user details.
|
||||
type GetRequest struct {
|
||||
// Username
|
||||
// Required: true
|
||||
Username string `url:"username" json:"username" validate:"required"`
|
||||
}
|
||||
|
||||
// Get gets user details as an ItemUser struct.
|
||||
func (u User) Get(ctx context.Context, req GetRequest) (*ItemUser, error) {
|
||||
res, err := u.GetRaw(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := ItemUser{}
|
||||
|
||||
err = json.Unmarshal(res, &item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
// GetRaw gets user details as an array of bytes
|
||||
func (u User) GetRaw(ctx context.Context, req GetRequest) ([]byte, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return nil, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/get"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
return res, err
|
||||
}
|
||||
57
pkg/cloudapi/user/get_audit.go
Normal file
57
pkg/cloudapi/user/get_audit.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetAuditRequest struct for getting user's audits.
|
||||
type GetAuditRequest struct {
|
||||
// Find by api call.
|
||||
// Required: false
|
||||
Call string `url:"call,omitempty" json:"call,omitempty"`
|
||||
|
||||
// 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 HTTP max status code
|
||||
// Required: false
|
||||
MaxStatusCode uint64 `url:"maxStatusCode,omitempty" json:"maxStatusCode,omitempty"`
|
||||
|
||||
// find by HTTP min status code
|
||||
// Required: false
|
||||
MinStatusCode uint64 `url:"minStatusCode,omitempty" json:"minStatusCode,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"`
|
||||
}
|
||||
|
||||
// GetAudit gets user's audits.
|
||||
func (u User) GetAudit(ctx context.Context, req GetAuditRequest) (ListAudits, error) {
|
||||
url := "/cloudapi/user/getAudit"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return ListAudits{}, err
|
||||
}
|
||||
|
||||
list := ListAudits{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return ListAudits{}, err
|
||||
}
|
||||
|
||||
return list, nil
|
||||
}
|
||||
26
pkg/cloudapi/user/get_resource_consumption.go
Normal file
26
pkg/cloudapi/user/get_resource_consumption.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// GetResourceConsumption gets amount of consumed and reserved resources (cpu, ram, disk) by current user
|
||||
func (u User) GetResourceConsumption(ctx context.Context) (*ResourceConsumption, error) {
|
||||
url := "/cloudapi/user/getResourceConsumption"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := ResourceConsumption{}
|
||||
|
||||
err = json.Unmarshal(res, &item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &item, nil
|
||||
}
|
||||
44
pkg/cloudapi/user/is_valid_invite_user_token.go
Normal file
44
pkg/cloudapi/user/is_valid_invite_user_token.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// GetRequest struct to check if the inviteusertoken and emailaddress pair are valid and matching.
|
||||
type IsValidInviteUserTokenRequest struct {
|
||||
// InviteUserToken
|
||||
// The token that was previously sent to the invited user email
|
||||
// Required: true
|
||||
InviteUserToken string `url:"inviteusertoken" json:"inviteusertoken" validate:"required"`
|
||||
|
||||
// EmailAddress
|
||||
// Email address for the user
|
||||
// Required: true
|
||||
EmailAddress string `url:"emailaddress" json:"emailaddress" validate:"required"`
|
||||
}
|
||||
|
||||
// IsValidInviteUserToken checks if the inviteusertoken and emailaddress pair are valid and matching.
|
||||
func (u User) IsValidInviteUserToken(ctx context.Context, req IsValidInviteUserTokenRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/isValidInviteUserToken"
|
||||
|
||||
res, err := u.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
|
||||
}
|
||||
181
pkg/cloudapi/user/models.go
Normal file
181
pkg/cloudapi/user/models.go
Normal file
@@ -0,0 +1,181 @@
|
||||
package user
|
||||
|
||||
import "strconv"
|
||||
|
||||
type ItemUser struct {
|
||||
// Data
|
||||
Data interface{} `json:"data"`
|
||||
|
||||
// EmailAddresses
|
||||
EmailAddresses []string `json:"emailaddresses"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type ItemAudit struct {
|
||||
// Call
|
||||
Call string `json:"Call"`
|
||||
|
||||
// Response time
|
||||
ResponseTime ResponseTime `json:"Response Time"`
|
||||
|
||||
// StatusCode
|
||||
StatusCode StatusCode `json:"Status Code"`
|
||||
|
||||
// Guid
|
||||
GUID string `json:"Guid"`
|
||||
|
||||
// Time
|
||||
Time float64 `json:"Time"`
|
||||
}
|
||||
|
||||
type ListAudits struct {
|
||||
// Data
|
||||
Data []ItemAudit `json:"data"`
|
||||
|
||||
// Entry count
|
||||
EntryCount uint64 `json:"entryCount"`
|
||||
}
|
||||
|
||||
type ResponseTime float64
|
||||
|
||||
func (r *ResponseTime) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*r = ResponseTime(-1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := strconv.ParseFloat(string(b), 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = ResponseTime(res)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type StatusCode int64
|
||||
|
||||
func (s *StatusCode) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
*s = StatusCode(-1)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
res, err := strconv.ParseInt(string(b), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*s = StatusCode(res)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type BriefResources struct {
|
||||
Accounts Accounts `json:"Accounts,omitempty"`
|
||||
CSs CSs `json:"CSs,omitempty"`
|
||||
Computes Computes `json:"Computes,omitempty"`
|
||||
RGs RGs `json:"RGs,omitempty"`
|
||||
VMs VMs `json:"VMs,omitempty"`
|
||||
}
|
||||
|
||||
type Accounts struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type CSs struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type Computes struct {
|
||||
Started uint64 `json:"Started,omitempty"`
|
||||
Stopped uint64 `json:"Stopped,omitempty"`
|
||||
}
|
||||
|
||||
type RGs struct {
|
||||
Disabled uint64 `json:"DISABLED,omitempty"`
|
||||
Enabled uint64 `json:"ENABLED,omitempty"`
|
||||
}
|
||||
|
||||
type VMs struct {
|
||||
Halted uint64 `json:"Halted,omitempty"`
|
||||
Running uint64 `json:"Running,omitempty"`
|
||||
}
|
||||
|
||||
type APIsEndpoints struct {
|
||||
CloudAPI CloudAPIEndpoints `json:"cloudapi,omitempty"`
|
||||
CloudBroker CloudBrokerEndpoints `json:"cloudbroker,omitempty"`
|
||||
LibCloud LibCloudEndpoints `json:"libcloud,omitempty"`
|
||||
System SystemEndpoints `json:"system,omitempty"`
|
||||
}
|
||||
|
||||
type CloudAPIEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type CloudBrokerEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type LibCloudEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type SystemEndpoints struct {
|
||||
All bool `json:"ALL,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceConsumption struct {
|
||||
// Consumed
|
||||
Consumed Resources `json:"Consumed"`
|
||||
|
||||
// Reserved
|
||||
Reserved Resources `json:"Reserved"`
|
||||
|
||||
// Username
|
||||
Username string `json:"username"`
|
||||
}
|
||||
|
||||
type Resources struct {
|
||||
// CPU
|
||||
CPU uint64 `json:"cpu"`
|
||||
|
||||
// Disksize
|
||||
DiskSize uint64 `json:"disksize"`
|
||||
|
||||
// DiskSizeMax
|
||||
DiskSizeMax uint64 `json:"disksizemax"`
|
||||
|
||||
// ExtIPs
|
||||
ExtIPs uint64 `json:"extips"`
|
||||
|
||||
// ExtTraffic
|
||||
ExtTraffic uint64 `json:"exttraffic"`
|
||||
|
||||
// GPU
|
||||
GPU uint64 `json:"gpu"`
|
||||
|
||||
// RAM
|
||||
RAM uint64 `json:"ram"`
|
||||
|
||||
// SEPs
|
||||
SEPs map[string]map[string]DiskUsage `json:"seps"`
|
||||
}
|
||||
|
||||
// Disk usage
|
||||
type DiskUsage struct {
|
||||
// Disk size
|
||||
DiskSize float64 `json:"disksize"`
|
||||
|
||||
// Disk size max
|
||||
DiskSizeMax float64 `json:"disksizemax"`
|
||||
}
|
||||
|
||||
type FoundElements []interface{}
|
||||
33
pkg/cloudapi/user/search.go
Normal file
33
pkg/cloudapi/user/search.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// SearchRequest struct for searching user's elements.
|
||||
type SearchRequest struct {
|
||||
// Text to search
|
||||
// Required: true
|
||||
Text string `url:"text" json:"text" validate:"required"`
|
||||
}
|
||||
|
||||
// Search searches for user's elements.
|
||||
func (u User) Search(ctx context.Context, req SearchRequest) (*FoundElements, error) {
|
||||
url := "/cloudapi/user/search"
|
||||
|
||||
res, err := u.client.DecortApiCall(ctx, http.MethodPost, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
list := FoundElements{}
|
||||
|
||||
err = json.Unmarshal(res, &list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &list, nil
|
||||
}
|
||||
38
pkg/cloudapi/user/set_data.go
Normal file
38
pkg/cloudapi/user/set_data.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/validators"
|
||||
)
|
||||
|
||||
// SetDataRequest struct for setting extra user information.
|
||||
type SetDataRequest struct {
|
||||
// Data to set to user in json format
|
||||
// Required: true
|
||||
Data string `url:"data" json:"data" validation:"required"`
|
||||
}
|
||||
|
||||
// SetData sets extra user information.
|
||||
func (u User) SetData(ctx context.Context, req SetDataRequest) (bool, error) {
|
||||
err := validators.ValidateRequest(req)
|
||||
if err != nil {
|
||||
return false, validators.ValidationErrors(validators.GetErrors(err))
|
||||
}
|
||||
|
||||
url := "/cloudapi/user/setData"
|
||||
|
||||
res, err := u.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
|
||||
}
|
||||
15
pkg/cloudapi/user/user.go
Normal file
15
pkg/cloudapi/user/user.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package user
|
||||
|
||||
import "repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/interfaces"
|
||||
|
||||
// Structure for creating request to User
|
||||
type User struct {
|
||||
client interfaces.Caller
|
||||
}
|
||||
|
||||
// Builder for User endpoints
|
||||
func New(client interfaces.Caller) *User {
|
||||
return &User{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user