refactor: extract all generators into independent TOOLS/ modules
Each generator is now a standalone Go module with its own go.mod: TOOLS/ ├── yaml-generator/ ← service_spec_gen (API → YAML) ├── resource-generator/ ← gen_v2 (YAML → Go resources) ├── docs-generator/ ← docs_template_gen_v2 (YAML → Markdown) ├── ops-generator/ ← ops_docs_gen (ops documentation) └── bin/ ← pre-built binaries All scripts updated to use TOOLS/bin/* binaries. Removed old universal_rebuild/tools/ and universal_rebuild/bin/.
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// service_spec_gen — генератор YAML-спеков сервисов из API Nubes.
|
||||
//
|
||||
// Читает список сервисов, дёргает API, собирает операции/параметры/MAN,
|
||||
// пишет один YAML на сервис в resources_yaml/.
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"yaml-generator/client"
|
||||
"yaml-generator/config"
|
||||
"yaml-generator/normalize"
|
||||
"yaml-generator/spec"
|
||||
"yaml-generator/types"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
cli := client.New(cfg.APIEndpoint, cfg.APIToken)
|
||||
|
||||
services := cfg.Services
|
||||
if cfg.SingleServiceID > 0 {
|
||||
services = []config.ServiceRef{{ID: cfg.SingleServiceID, Name: cfg.SingleServiceName}}
|
||||
}
|
||||
|
||||
outputDir := cfg.OutputDir
|
||||
if outputDir == "" {
|
||||
repoRoot, err := config.FindRepoRoot()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
outputDir = filepath.Join(repoRoot, "resources_yaml")
|
||||
}
|
||||
if err := spec.ValidateOutputDir(outputDir); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := os.MkdirAll(outputDir, 0o755); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, svc := range services {
|
||||
if svc.ID <= 0 {
|
||||
continue
|
||||
}
|
||||
info, err := cli.GetService(svc.ID)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "WARNING: service %d (%s) skipped: %v\n", svc.ID, svc.Name, err)
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSpace(svc.Name)
|
||||
if name == "" {
|
||||
name = strings.TrimSpace(info.ShortName)
|
||||
}
|
||||
if name == "" {
|
||||
name = strings.TrimSpace(info.DisplayName)
|
||||
}
|
||||
name = normalize.ServiceName(name)
|
||||
if name == "" {
|
||||
name = fmt.Sprintf("service_%d", svc.ID)
|
||||
}
|
||||
|
||||
ops, hasSuspend, _, _, err := cli.CollectOperations(info.Operations)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
specYAML := types.ServiceSpec{
|
||||
Name: name,
|
||||
ServiceID: svc.ID,
|
||||
ServiceDisplayName: strings.TrimSpace(info.DisplayName),
|
||||
ServiceShortName: strings.TrimSpace(info.ShortName),
|
||||
ServiceMan: strings.TrimSpace(info.Man),
|
||||
Lifecycle: types.Lifecycle{
|
||||
SuspendOnDestroyDefault: hasSuspend,
|
||||
AdoptExistingOnCreateDefault: false,
|
||||
},
|
||||
Outputs: types.OutputSection{Params: spec.DefaultOutputParams()},
|
||||
Operations: ops,
|
||||
}
|
||||
|
||||
outPath := filepath.Join(outputDir, fmt.Sprintf("%d_%s.yaml", svc.ID, name))
|
||||
buf, err := yaml.Marshal(specYAML)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := os.WriteFile(outPath, buf, 0o644); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("written %s\n", outPath)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user