mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 04:40:05 +01:00
feat: complete node pool api, sdk and ui
Signed-off-by: allanice001 <allanice001@gmail.com>
This commit is contained in:
46
internal/handlers/dto/node_pools.go
Normal file
46
internal/handlers/dto/node_pools.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package dto
|
||||
|
||||
import "github.com/glueops/autoglue/internal/common"
|
||||
|
||||
type NodeRole string
|
||||
|
||||
const (
|
||||
NodeRoleMaster NodeRole = "master"
|
||||
NodeRoleWorker NodeRole = "worker"
|
||||
)
|
||||
|
||||
type CreateNodePoolRequest struct {
|
||||
Name string `json:"name"`
|
||||
Role NodeRole `json:"role" enums:"master,worker" swaggertype:"string"`
|
||||
}
|
||||
|
||||
type UpdateNodePoolRequest struct {
|
||||
Name *string `json:"name"`
|
||||
Role *NodeRole `json:"role" enums:"master,worker" swaggertype:"string"`
|
||||
}
|
||||
|
||||
type NodePoolResponse struct {
|
||||
common.AuditFields
|
||||
Name string `json:"name"`
|
||||
Role NodeRole `json:"role" enums:"master,worker" swaggertype:"string"`
|
||||
Servers []ServerResponse `json:"servers"`
|
||||
Annotations []AnnotationResponse `json:"annotations"`
|
||||
Labels []LabelResponse `json:"labels"`
|
||||
Taints []TaintResponse `json:"taints"`
|
||||
}
|
||||
|
||||
type AttachServersRequest struct {
|
||||
ServerIDs []string `json:"server_ids"`
|
||||
}
|
||||
|
||||
type AttachTaintsRequest struct {
|
||||
TaintIDs []string `json:"taint_ids"`
|
||||
}
|
||||
|
||||
type AttachLabelsRequest struct {
|
||||
LabelIDs []string `json:"label_ids"`
|
||||
}
|
||||
|
||||
type AttachAnnotationsRequest struct {
|
||||
AnnotationIDs []string `json:"annotation_ids"`
|
||||
}
|
||||
@@ -8,8 +8,8 @@ type CreateServerRequest struct {
|
||||
PrivateIPAddress string `json:"private_ip_address"`
|
||||
SSHUser string `json:"ssh_user"`
|
||||
SshKeyID string `json:"ssh_key_id"`
|
||||
Role string `json:"role" example:"master|worker|bastion"`
|
||||
Status string `json:"status,omitempty" example:"pending|provisioning|ready|failed"`
|
||||
Role string `json:"role" example:"master|worker|bastion" enums:"master,worker,bastion"`
|
||||
Status string `json:"status,omitempty" example:"pending|provisioning|ready|failed" enums:"pending,provisioning,ready,failed"`
|
||||
}
|
||||
|
||||
type UpdateServerRequest struct {
|
||||
@@ -18,8 +18,8 @@ type UpdateServerRequest struct {
|
||||
PrivateIPAddress *string `json:"private_ip_address,omitempty"`
|
||||
SSHUser *string `json:"ssh_user,omitempty"`
|
||||
SshKeyID *string `json:"ssh_key_id,omitempty"`
|
||||
Role *string `json:"role,omitempty" example:"master|worker|bastion"`
|
||||
Status *string `json:"status,omitempty" example:"pending|provisioning|ready|failed"`
|
||||
Role *string `json:"role" example:"master|worker|bastion" enums:"master,worker,bastion"`
|
||||
Status *string `json:"status,omitempty" example:"pending|provisioning|ready|failed" enums:"pending,provisioning,ready,failed"`
|
||||
}
|
||||
|
||||
type ServerResponse struct {
|
||||
@@ -30,8 +30,8 @@ type ServerResponse struct {
|
||||
PrivateIPAddress string `json:"private_ip_address"`
|
||||
SSHUser string `json:"ssh_user"`
|
||||
SshKeyID uuid.UUID `json:"ssh_key_id"`
|
||||
Role string `json:"role"`
|
||||
Status string `json:"status"`
|
||||
Role string `json:"role" example:"master|worker|bastion" enums:"master,worker,bastion"`
|
||||
Status string `json:"status,omitempty" example:"pending|provisioning|ready|failed" enums:"pending,provisioning,ready,failed"`
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
}
|
||||
|
||||
1270
internal/handlers/node_pools.go
Normal file
1270
internal/handlers/node_pools.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -382,7 +382,6 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
if mode == "json" {
|
||||
prefix := keyFilenamePrefix(key.PublicKey)
|
||||
resp := dto.SshMaterialJSON{
|
||||
ID: key.ID.String(),
|
||||
Name: key.Name,
|
||||
@@ -392,7 +391,7 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
case "public":
|
||||
pub := key.PublicKey
|
||||
resp.PublicKey = &pub
|
||||
resp.Filenames = []string{fmt.Sprintf("%s_%s.pub", prefix, key.ID.String())}
|
||||
resp.Filenames = []string{fmt.Sprintf("%s.pub", key.ID.String())}
|
||||
utils.WriteJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
|
||||
@@ -403,7 +402,7 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
resp.PrivatePEM = &plain
|
||||
resp.Filenames = []string{fmt.Sprintf("%s_%s.pem", prefix, key.ID.String())}
|
||||
resp.Filenames = []string{fmt.Sprintf("%s.pem", key.ID.String())}
|
||||
utils.WriteJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
|
||||
@@ -416,16 +415,16 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
_ = toZipFile(fmt.Sprintf("%s_%s.pem", prefix, key.ID.String()), []byte(plain), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s_%s.pub", prefix, key.ID.String()), []byte(key.PublicKey), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s.pem", key.ID.String()), []byte(plain), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s.pub", key.ID.String()), []byte(key.PublicKey), zw)
|
||||
_ = zw.Close()
|
||||
|
||||
b64 := utils.EncodeB64(buf.Bytes())
|
||||
resp.ZipBase64 = &b64
|
||||
resp.Filenames = []string{
|
||||
fmt.Sprintf("%s_%s.zip", prefix, key.ID.String()),
|
||||
fmt.Sprintf("%s_%s.pem", prefix, key.ID.String()),
|
||||
fmt.Sprintf("%s_%s.pub", prefix, key.ID.String()),
|
||||
fmt.Sprintf("%s.zip", key.ID.String()),
|
||||
fmt.Sprintf("%s.pem", key.ID.String()),
|
||||
fmt.Sprintf("%s.pub", key.ID.String()),
|
||||
}
|
||||
utils.WriteJSON(w, http.StatusOK, resp)
|
||||
return
|
||||
@@ -436,11 +435,9 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
prefix := keyFilenamePrefix(key.PublicKey)
|
||||
|
||||
switch part {
|
||||
case "public":
|
||||
filename := fmt.Sprintf("%s_%s.pub", prefix, key.ID.String())
|
||||
filename := fmt.Sprintf("%s.pub", key.ID.String())
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
||||
_, _ = w.Write([]byte(key.PublicKey))
|
||||
@@ -452,7 +449,7 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
utils.WriteError(w, http.StatusInternalServerError, "db_error", "failed to decrypt ssh key")
|
||||
return
|
||||
}
|
||||
filename := fmt.Sprintf("%s_%s.pem", prefix, key.ID.String())
|
||||
filename := fmt.Sprintf("%s.pem", key.ID.String())
|
||||
w.Header().Set("Content-Type", "application/x-pem-file")
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
||||
_, _ = w.Write([]byte(plain))
|
||||
@@ -467,8 +464,8 @@ func DownloadSSHKey(db *gorm.DB) http.HandlerFunc {
|
||||
|
||||
var buf bytes.Buffer
|
||||
zw := zip.NewWriter(&buf)
|
||||
_ = toZipFile(fmt.Sprintf("%s_%s.pem", prefix, key.ID.String()), []byte(plain), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s_%s.pub", prefix, key.ID.String()), []byte(key.PublicKey), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s.pem", key.ID.String()), []byte(plain), zw)
|
||||
_ = toZipFile(fmt.Sprintf("%s.pub", key.ID.String()), []byte(key.PublicKey), zw)
|
||||
_ = zw.Close()
|
||||
|
||||
filename := fmt.Sprintf("ssh_key_%s.zip", key.ID.String())
|
||||
|
||||
Reference in New Issue
Block a user