Enhance API with OIDC support, including login and callback endpoints. Update environment variables for OIDC configuration in .env.example. Add new features to the catalog service for listing software families, Minecraft versions, and deployment regions. Implement server management actions such as kill, delete, and update in the servers module. Integrate feature flags for maintenance mode in server operations. Update pnpm-lock.yaml with new dependencies and versions.
This commit is contained in:
@@ -4,10 +4,13 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/hexahost/gamecloud/node-agent/internal/archive"
|
||||
"github.com/hexahost/gamecloud/node-agent/internal/docker"
|
||||
@@ -357,6 +360,88 @@ func (m *Manager) HandleFilesWrite(ctx context.Context, correlationID string, pa
|
||||
})
|
||||
}
|
||||
|
||||
// HandleFilesDelete removes a file or directory from the server data directory.
|
||||
func (m *Manager) HandleFilesDelete(ctx context.Context, correlationID string, payload protocol.ServerFilesDeletePayload) {
|
||||
meta := payload.OperationMeta
|
||||
rec, ok := m.getServer(meta.ServerID)
|
||||
if !ok {
|
||||
m.failOperation(ctx, correlationID, meta, "files.delete", "SERVER_NOT_FOUND", "server is not provisioned on this node")
|
||||
return
|
||||
}
|
||||
|
||||
if err := files.RemovePath(rec.DataPath, payload.Path); err != nil {
|
||||
m.failOperation(ctx, correlationID, meta, "files.delete", filesErrorCode(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
m.completeOperation(ctx, correlationID, meta, "files.delete", map[string]string{
|
||||
"path": payload.Path,
|
||||
})
|
||||
}
|
||||
|
||||
// HandleFilesArchive creates a tar.gz archive from selected paths.
|
||||
func (m *Manager) HandleFilesArchive(ctx context.Context, correlationID string, payload protocol.ServerFilesArchivePayload) {
|
||||
meta := payload.OperationMeta
|
||||
rec, ok := m.getServer(meta.ServerID)
|
||||
if !ok {
|
||||
m.failOperation(ctx, correlationID, meta, "files.archive", "SERVER_NOT_FOUND", "server is not provisioned on this node")
|
||||
return
|
||||
}
|
||||
|
||||
archiveName := payload.ArchiveName
|
||||
if archiveName == "" {
|
||||
archiveName = fmt.Sprintf("archive-%d.tar.gz", time.Now().Unix())
|
||||
}
|
||||
if !strings.HasSuffix(archiveName, ".tar.gz") {
|
||||
archiveName += ".tar.gz"
|
||||
}
|
||||
|
||||
outputPath := filepath.Join(rec.DataPath, ".hexahost-archives", archiveName)
|
||||
checksum, size, err := archive.CreateTarGzFromPaths(rec.DataPath, payload.Paths, outputPath)
|
||||
if err != nil {
|
||||
m.failOperation(ctx, correlationID, meta, "files.archive", "ARCHIVE_FAILED", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
rel, _ := filepath.Rel(rec.DataPath, outputPath)
|
||||
m.completeOperation(ctx, correlationID, meta, "files.archive", map[string]any{
|
||||
"archivePath": filepath.ToSlash(rel),
|
||||
"sha256": checksum,
|
||||
"size": size,
|
||||
})
|
||||
}
|
||||
|
||||
// HandleFilesUnarchive extracts a tar.gz archive into a destination path.
|
||||
func (m *Manager) HandleFilesUnarchive(ctx context.Context, correlationID string, payload protocol.ServerFilesUnarchivePayload) {
|
||||
meta := payload.OperationMeta
|
||||
rec, ok := m.getServer(meta.ServerID)
|
||||
if !ok {
|
||||
m.failOperation(ctx, correlationID, meta, "files.unarchive", "SERVER_NOT_FOUND", "server is not provisioned on this node")
|
||||
return
|
||||
}
|
||||
|
||||
archiveAbs, err := files.ResolvePath(rec.DataPath, payload.ArchivePath)
|
||||
if err != nil {
|
||||
m.failOperation(ctx, correlationID, meta, "files.unarchive", filesErrorCode(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
destAbs, err := files.ResolvePath(rec.DataPath, payload.DestinationPath)
|
||||
if err != nil {
|
||||
m.failOperation(ctx, correlationID, meta, "files.unarchive", filesErrorCode(err), err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if err := archive.ExtractTarGz(archiveAbs, destAbs); err != nil {
|
||||
m.failOperation(ctx, correlationID, meta, "files.unarchive", "UNARCHIVE_FAILED", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
m.completeOperation(ctx, correlationID, meta, "files.unarchive", map[string]string{
|
||||
"destinationPath": payload.DestinationPath,
|
||||
})
|
||||
}
|
||||
|
||||
// HandleBackupPrepare runs save-off and save-all flush via RCON.
|
||||
func (m *Manager) HandleBackupPrepare(ctx context.Context, correlationID string, meta protocol.OperationMeta) {
|
||||
rec, ok := m.getServer(meta.ServerID)
|
||||
|
||||
Reference in New Issue
Block a user