Initial commit: omnichannel-mcp — MCP-сервер управления платформой Omnichannel
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package configserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// api_release.go — страница «Развёртывание»: файлы схемы, seed/fill, релиз.
|
||||
|
||||
// DeploymentUpdate — частичное обновление файлов развёртывания. nil-поля не
|
||||
// отправляются (сервер не перезаписывает их пустыми значениями).
|
||||
type DeploymentUpdate struct {
|
||||
Schema *string
|
||||
Manifest *string
|
||||
PrebuildVars *string
|
||||
IPOverrides *string
|
||||
}
|
||||
|
||||
// SaveDeploymentFiles сохраняет schema/manifest/prebuild_vars/ip_overrides.
|
||||
func (a *API) SaveDeploymentFiles(ctx context.Context, upd DeploymentUpdate) (*StatusAck, error) {
|
||||
ctx, cancel := a.withTimeout(ctx)
|
||||
defer cancel()
|
||||
|
||||
body := map[string]string{}
|
||||
if upd.Schema != nil {
|
||||
body["schema"] = *upd.Schema
|
||||
}
|
||||
if upd.Manifest != nil {
|
||||
body["manifest"] = *upd.Manifest
|
||||
}
|
||||
if upd.PrebuildVars != nil {
|
||||
body["prebuild_vars"] = *upd.PrebuildVars
|
||||
}
|
||||
if upd.IPOverrides != nil {
|
||||
body["ip_overrides"] = *upd.IPOverrides
|
||||
}
|
||||
|
||||
out := &StatusAck{}
|
||||
if err := a.Sess.postJSON(ctx, "/api/deployment/files", body, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SeedHosts создаёт хосты из schema.json.
|
||||
func (a *API) SeedHosts(ctx context.Context) (*SeedHostsAck, error) {
|
||||
ctx, cancel := a.withTimeout(ctx)
|
||||
defer cancel()
|
||||
out := &SeedHostsAck{}
|
||||
if err := a.Sess.postJSON(ctx, "/api/deployment/seed_hosts", nil, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// FillVars заполняет prebuild_vars из схемы (ответ — произвольный JSON).
|
||||
func (a *API) FillVars(ctx context.Context) (json.RawMessage, error) {
|
||||
ctx, cancel := a.withTimeout(ctx)
|
||||
defer cancel()
|
||||
var out json.RawMessage
|
||||
if err := a.Sess.postJSON(ctx, "/api/deployment/fill_vars", nil, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// DownloadRelease запускает загрузку релиза. При load_images=true сервер
|
||||
// отвечает сразу (фоновая задача), прогресс читается через ReleaseJob.
|
||||
func (a *API) DownloadRelease(ctx context.Context, token string, loadImages bool) (*DownloadReleaseAck, error) {
|
||||
if token == "" {
|
||||
token = a.Srv.GitlabToken
|
||||
}
|
||||
body := map[string]any{"load_images": loadImages}
|
||||
if token != "" {
|
||||
body["gitlab_token"] = token
|
||||
}
|
||||
|
||||
// Синхронная выгрузка (load_images=false) может быть долгой.
|
||||
ctx, cancel := a.withUploadTimeout(ctx)
|
||||
defer cancel()
|
||||
out := &DownloadReleaseAck{}
|
||||
if err := a.Sess.postJSON(ctx, "/api/deployment/download_release", body, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// StartServices создаёт задачи запуска сервисов для хостов из схемы.
|
||||
func (a *API) StartServices(ctx context.Context) (*StartServicesAck, error) {
|
||||
ctx, cancel := a.withTimeout(ctx)
|
||||
defer cancel()
|
||||
out := &StartServicesAck{}
|
||||
if err := a.Sess.postJSON(ctx, "/api/deployment/start_services", nil, out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user