This commit is contained in:
dayterr
2025-09-11 15:56:44 +03:00
parent 825b1a0a00
commit abd35f858c
87 changed files with 930 additions and 571 deletions

View File

@@ -0,0 +1,54 @@
package node
import (
"context"
"net/http"
"strconv"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// AddSSHIdentityRequest struct to add node ssh information
type AddSSHIdentityRequest struct {
// Node ID
// Required: true
NID uint64 `url:"node_id" json:"node_id" validate:"required"`
// Host name of the client
// Required: true
ClientHostName string `url:"client_host_name" json:"client_host_name" validate:"required"`
// SSH host key of the client
// Required: true
ClientHostKey string `url:"client_host_key" json:"client_host_key" validate:"required" `
// SSH public key of the client
// Required: true
ClientPublicKey string `url:"client_public_key" json:"client_public_key" validate:"required"`
// IPv4 address
// Required: true
ClientIPAddress string `url:"client_ip_address" json:"client_ip_address" validate:"required" `
}
// AddSSHIdentity adds node ssh information
func (n Node) AddSSHIdentity(ctx context.Context, req AddSSHIdentityRequest) (bool, error) {
err := validators.ValidateRequest(req)
if err != nil {
return false, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/add_ssh_identity"
res, err := n.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
}

View File

@@ -0,0 +1,39 @@
package node
import (
"context"
"encoding/json"
"net/http"
"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)
// GetSSHIdentityRequest struct to get node ssh information
type GetSSHIdentityRequest struct {
// Node ID
// Required: true
NID uint64 `url:"node_id" json:"node_id" validate:"required"`
}
// GetSSHIdentity gets node ssh information
func (n Node) GetSSHIdentity(ctx context.Context, req GetSSHIdentityRequest) (*SSHIdentity, error) {
if err := validators.ValidateRequest(req); err != nil {
return nil, validators.ValidationErrors(validators.GetErrors(err))
}
url := "/cloudbroker/node/get_ssh_identity"
res, err := n.client.DecortApiCall(ctx, http.MethodGet, url, req)
if err != nil {
return nil, err
}
info := SSHIdentity{}
err = json.Unmarshal(res, &info)
if err != nil {
return nil, err
}
return &info, nil
}

View File

@@ -392,3 +392,15 @@ type Role struct {
Reason string `json:"reason"`
Time uint64 `json:"time"`
}
// Information about SSH Identity
type SSHIdentity struct {
//Host name of the client
HostName string `json:"host_name"`
//SSH host key of the client
HostKey string `json:"host_key"`
//Array of SSH public keys of the client
PublicKeys []string `json:"public_keys"`
}