Servers Page & API

This commit is contained in:
allanice001
2025-09-01 23:53:48 +01:00
parent 5425ed5dcc
commit 7f29580d3b
20 changed files with 2350 additions and 49 deletions

View File

@@ -0,0 +1,47 @@
package servers
import (
"errors"
"strings"
"time"
"github.com/glueops/autoglue/internal/db"
"github.com/glueops/autoglue/internal/db/models"
"github.com/google/uuid"
"gorm.io/gorm"
)
func toResponse(s models.Server) serverResponse {
return serverResponse{
ID: s.ID,
OrganizationID: s.OrganizationID,
Hostname: s.Hostname,
IPAddress: s.IPAddress,
SSHUser: s.SSHUser,
SshKeyID: s.SshKeyID,
Role: s.Role,
Status: s.Status,
CreatedAt: s.CreatedAt.UTC().Format(time.RFC3339),
UpdatedAt: s.UpdatedAt.UTC().Format(time.RFC3339),
}
}
func validStatus(s string) bool {
switch strings.ToLower(s) {
case "pending", "provisioning", "ready", "failed", "":
return true
default:
return false
}
}
func ensureKeyBelongsToOrg(orgID uuid.UUID, keyID uuid.UUID) error {
var k models.SshKey
if err := db.DB.Where("id = ? AND organization_id = ?", keyID, orgID).First(&k).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.New("ssh key not found for this organization")
}
return err
}
return nil
}