api-gateway: migrate YAML gen + provider core from deck-api (?endpoint=) to lk-api-gateway (REST paths)
- service_spec_gen: callAPI() auto-detects proxy vs REST mode by index.cfm presence
- core/client.go: buildURL() replaces all 4 ?endpoint= harcoded sites
- build-provider.sh: -ldflags -X main.version=${VERSION} for correct binary version
- 01_generate_yamls.sh (devops + root): Python auto-detect proxy vs REST
- 02_generate_resources_and_docs_v2.sh: pass -api-endpoint to doc generators
- 04_build_and_publish_docs.sh: normalize_api_endpoint without forced /index.cfm
- docs_template_gen + v2: -api-endpoint flag, hardcoded deck-api replaced
- provider.go (both): TODO(api-gateway) comments
- profiles/test/profile.env: NUBES_API_ENDPOINT -> lk-api-gateway-test
- HISTORY: 2026-07-02_api_gateway_migration.md
This commit is contained in:
@@ -88,6 +88,7 @@ func main() {
|
||||
servicesListFlag := flag.String("services", "", "Path to devops/config/services_list.txt")
|
||||
excludeFlag := flag.String("exclude", "", "Comma-separated resource names to skip (e.g. clickhouse)")
|
||||
versionFlag := flag.String("version", "", "Provider version for example block")
|
||||
apiEndpointFlag := flag.String("api-endpoint", "https://deck-api.ngcloud.ru/api/v1/index.cfm", "API endpoint for example block")
|
||||
flag.Parse()
|
||||
|
||||
root := detectRoot()
|
||||
@@ -100,6 +101,7 @@ func main() {
|
||||
if version == "" {
|
||||
version = detectVersion(filepath.Join(root, "universal_rebuild", "main.go"))
|
||||
}
|
||||
apiEndpoint := *apiEndpointFlag
|
||||
|
||||
servicesOrder := loadServicesList(servicesList)
|
||||
specs := loadSpecs(resourcesDir, servicesOrder)
|
||||
@@ -118,7 +120,7 @@ func main() {
|
||||
if excludeSet[spec.Name] {
|
||||
continue
|
||||
}
|
||||
writeResourceDocs(docsDir, spec, version)
|
||||
writeResourceDocs(docsDir, spec, version, apiEndpoint)
|
||||
processedSpecs = append(processedSpecs, spec)
|
||||
}
|
||||
generateIndexMD(docsDir, processedSpecs)
|
||||
@@ -296,12 +298,12 @@ func collectSubresources(spec ServiceSpec) []string {
|
||||
return out
|
||||
}
|
||||
|
||||
func writeResourceDocs(docsDir string, spec ServiceSpec, version string) {
|
||||
func writeResourceDocs(docsDir string, spec ServiceSpec, version string, apiEndpoint string) {
|
||||
base := spec.Name
|
||||
nav := fmt.Sprintf("[Manual](%s.md) | [Create params](%s_params_create.md) | [Modify params](%s_params_modify.md) | [Output params](%s_outputs.md) | [Operations](%s_ops.md) | [Example](%s_example.md)", base, base, base, base, base, base)
|
||||
|
||||
writeFile(filepath.Join(docsDir, base+".md"), buildManualPage(spec, nav))
|
||||
writeFile(filepath.Join(docsDir, base+"_example.md"), buildExamplePage(spec, nav, version))
|
||||
writeFile(filepath.Join(docsDir, base+"_example.md"), buildExamplePage(spec, nav, version, apiEndpoint))
|
||||
writeFile(filepath.Join(docsDir, base+"_params_create.md"), buildCreateParamsPage(spec, nav))
|
||||
writeFile(filepath.Join(docsDir, base+"_params_modify.md"), buildModifyParamsPage(spec, nav))
|
||||
writeFile(filepath.Join(docsDir, base+"_outputs.md"), buildOutputsPage(spec, nav))
|
||||
@@ -314,7 +316,7 @@ func writeResourceDocs(docsDir string, spec ServiceSpec, version string) {
|
||||
srNav := fmt.Sprintf("[%s (основной)](%s.md) | [Operations](%s_ops.md) | [%s](%s.md) | [Example](%s_example.md)",
|
||||
spec.ServiceDisplayName, base, base, capitalize(srName), srBase, srBase)
|
||||
writeFile(filepath.Join(docsDir, srBase+".md"), buildSubresourcePage(spec, srName, srNav))
|
||||
writeFile(filepath.Join(docsDir, srBase+"_example.md"), buildSubresourceExamplePage(spec, srName, srNav, version))
|
||||
writeFile(filepath.Join(docsDir, srBase+"_example.md"), buildSubresourceExamplePage(spec, srName, srNav, version, apiEndpoint))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,12 +349,12 @@ func buildManualPage(spec ServiceSpec, nav string) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func buildExamplePage(spec ServiceSpec, nav, version string) string {
|
||||
func buildExamplePage(spec ServiceSpec, nav, version string, apiEndpoint string) string {
|
||||
var b strings.Builder
|
||||
b.WriteString(buildHeader(spec, nav))
|
||||
b.WriteString(fmt.Sprintf("## Copy-ready manifest (`%s_main.tf`)\n\n", spec.Name))
|
||||
b.WriteString("```hcl\n")
|
||||
b.WriteString(exampleBlock(spec, version))
|
||||
b.WriteString(exampleBlock(spec, version, apiEndpoint))
|
||||
b.WriteString("```\n\n")
|
||||
b.WriteString("## Outputs usage\n\n")
|
||||
b.WriteString("```hcl\n")
|
||||
@@ -369,7 +371,7 @@ func buildExamplePage(spec ServiceSpec, nav, version string) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func exampleBlock(spec ServiceSpec, version string) string {
|
||||
func exampleBlock(spec ServiceSpec, version string, apiEndpoint string) string {
|
||||
createParams := findParams(spec.Operations, "create")
|
||||
requiredParams, defaultParams := splitParams(createParams)
|
||||
|
||||
@@ -385,7 +387,7 @@ func exampleBlock(spec ServiceSpec, version string) string {
|
||||
b.WriteString("# \u0422\u043e\u043a\u0435\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0430 api_token \u043a Nubes API \u2014 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u0435 \u043d\u0430 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439.\n")
|
||||
b.WriteString("provider \"nubes\" {\n")
|
||||
b.WriteString(" api_token = \"token_***\"\n")
|
||||
b.WriteString(" api_endpoint = \"https://deck-api.ngcloud.ru/api/v1/index.cfm\"\n")
|
||||
b.WriteString(fmt.Sprintf(" api_endpoint = \"%s\"\n", apiEndpoint))
|
||||
b.WriteString("}\n")
|
||||
b.WriteString(fmt.Sprintf("resource \"nubes_%s\" \"baza\" {\n", spec.Name))
|
||||
|
||||
@@ -1047,7 +1049,7 @@ func buildSubresourcePage(spec ServiceSpec, srName string, nav string) string {
|
||||
}
|
||||
|
||||
// buildSubresourceExamplePage генерирует страницу с HCL-примером для subresource.
|
||||
func buildSubresourceExamplePage(spec ServiceSpec, srName string, nav string, version string) string {
|
||||
func buildSubresourceExamplePage(spec ServiceSpec, srName string, nav string, version string, apiEndpoint string) string {
|
||||
var b strings.Builder
|
||||
srResourceName := fmt.Sprintf("nubes_%s_%s", spec.Name, slug(srName))
|
||||
b.WriteString(fmt.Sprintf("# Resource %s — Example\n\n", srResourceName))
|
||||
@@ -1068,7 +1070,7 @@ func buildSubresourceExamplePage(spec ServiceSpec, srName string, nav string, ve
|
||||
|
||||
b.WriteString("provider \"nubes\" {\n")
|
||||
b.WriteString(" api_token = \"token_***\"\n")
|
||||
b.WriteString(" api_endpoint = \"https://deck-api.ngcloud.ru/api/v1/index.cfm\"\n")
|
||||
b.WriteString(fmt.Sprintf(" api_endpoint = \"%s\"\n", apiEndpoint))
|
||||
b.WriteString("}\n\n")
|
||||
|
||||
// Основной ресурс (родитель) — ссылка
|
||||
|
||||
Reference in New Issue
Block a user