68 lines
2.3 KiB
Go
68 lines
2.3 KiB
Go
package configserver
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strconv"
|
|
)
|
|
|
|
// api_configure.go — изменение конфигурации сервиса (compose/env) и её версий.
|
|
|
|
// SetCompose устанавливает текущий docker-compose и отправляет его агенту.
|
|
func (a *API) SetCompose(ctx context.Context, appID int, content string) (*ConfigAck, error) {
|
|
ctx, cancel := a.withTimeout(ctx)
|
|
defer cancel()
|
|
out := &ConfigAck{}
|
|
body := map[string]string{"content": content}
|
|
if err := a.Sess.postJSON(ctx, "/api/compose/"+strconv.Itoa(appID), body, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// SetEnv устанавливает текущий env-файл и отправляет его агенту.
|
|
func (a *API) SetEnv(ctx context.Context, appID int, filename, content string) (*ConfigAck, error) {
|
|
ctx, cancel := a.withTimeout(ctx)
|
|
defer cancel()
|
|
out := &ConfigAck{}
|
|
body := map[string]string{"content": content}
|
|
path := "/api/env/" + strconv.Itoa(appID) + "/" + url.PathEscape(filename)
|
|
if err := a.Sess.postJSON(ctx, path, body, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// RestoreCompose восстанавливает версию compose (создаёт новую текущую версию).
|
|
func (a *API) RestoreCompose(ctx context.Context, versionID int) (*StatusAck, error) {
|
|
ctx, cancel := a.withTimeout(ctx)
|
|
defer cancel()
|
|
out := &StatusAck{}
|
|
if err := a.Sess.postJSON(ctx, "/api/restore_compose/"+strconv.Itoa(versionID), nil, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// RestoreEnvVersion восстанавливает версию env-файла.
|
|
func (a *API) RestoreEnvVersion(ctx context.Context, versionID int) (*StatusAck, error) {
|
|
ctx, cancel := a.withTimeout(ctx)
|
|
defer cancel()
|
|
out := &StatusAck{}
|
|
if err := a.Sess.postJSON(ctx, "/api/restore_env_version/"+strconv.Itoa(versionID), nil, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// UpdateConfig повторно отправляет агенту текущую конфигурацию из БД.
|
|
func (a *API) UpdateConfig(ctx context.Context, appID int) (*TaskAck, error) {
|
|
ctx, cancel := a.withTimeout(ctx)
|
|
defer cancel()
|
|
out := &TaskAck{}
|
|
if err := a.Sess.postJSON(ctx, "/api/update_config/"+strconv.Itoa(appID), nil, out); err != nil {
|
|
return nil, err
|
|
}
|
|
return out, nil
|
|
}
|