Merge pull request #3287 from owncloud/config-example-yaml-v2

Generate config file documentation
This commit is contained in:
Willy Kloucek
2022-03-14 13:09:14 +01:00
committed by GitHub
132 changed files with 1566 additions and 1090 deletions

View File

@@ -1 +1,2 @@
*_configvars.md
*-example.yaml

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/accounts-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/accounts_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/glauth-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/glauth_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/graph-explorer-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/graph-explorer_configvars.md" >}}

View File

@@ -7,6 +7,8 @@ geekdocEditPath: edit/master/docs/extensions/graph
geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/graph-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/graph_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/idm-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/idm_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/idp-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/idp_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/nats-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/nats_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/notifications-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/notifications_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/ocs-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/ocs_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/proxy-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/proxy_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/settings-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/settings_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/store-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/store_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/thumbnails-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/thumbnails_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/web-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/web_configvars.md" >}}

View File

@@ -8,5 +8,8 @@ geekdocFilePath: configuration.md
geekdocCollapseSection: true
---
## Example YAML Config
{{< include file="extensions/_includes/webdav-config-example.yaml" language="yaml" >}}
{{< include file="extensions/_includes/webdav_configvars.md" >}}

View File

@@ -6,14 +6,20 @@ import (
"log"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"text/template"
)
var targets = map[string]string{
"example-config-generator.go.tmpl": "output/exampleconfig/example-config-generator.go",
"extractor.go.tmpl": "output/env/runner.go",
}
func main() {
fmt.Println("Getting relevant packages")
paths, err := filepath.Glob("../../*/pkg/config/defaultconfig.go")
paths, err := filepath.Glob("../../*/pkg/config/defaults/defaultconfig.go")
if err != nil {
log.Fatal(err)
}
@@ -24,27 +30,36 @@ func main() {
for i := range paths {
paths[i] = replacer.Replace(paths[i])
}
content, err := ioutil.ReadFile("extractor.go.tmpl")
for template, output := range targets {
GenerateIntermediateCode(template, output, paths)
RunIntermediateCode(output)
}
fmt.Println("Cleaning up")
os.RemoveAll("output")
}
func GenerateIntermediateCode(templatePath string, intermediateCodePath string, paths []string) {
content, err := ioutil.ReadFile(templatePath)
if err != nil {
log.Fatal(err)
}
fmt.Println("Generating intermediate go code")
fmt.Println("Generating intermediate go code for " + intermediateCodePath + " using template " + templatePath)
tpl := template.Must(template.New("").Parse(string(content)))
os.Mkdir("output", 0700)
runner, err := os.Create("output/runner.go")
os.MkdirAll(path.Dir(intermediateCodePath), 0700)
runner, err := os.Create(intermediateCodePath)
if err != nil {
log.Fatal(err)
}
tpl.Execute(runner, paths)
fmt.Println("Running intermediate go code")
os.Chdir("output")
}
func RunIntermediateCode(intermediateCodePath string) {
fmt.Println("Running intermediate go code for " + intermediateCodePath)
os.Setenv("OCIS_BASE_DATA_PATH", "~/.ocis")
out, err := exec.Command("go", "run", "runner.go").Output()
out, err := exec.Command("go", "run", intermediateCodePath).Output()
if err != nil {
log.Fatal(err)
}
fmt.Println(string(out))
fmt.Println("Cleaning up")
os.Chdir("../")
os.RemoveAll("output")
}

View File

@@ -0,0 +1,53 @@
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v2"
{{- range $key, $value := .}}
pkg{{$key}} "{{$value}}"
{{- end}}
)
func main() {
replacer := strings.NewReplacer(
"github.com/owncloud/ocis/", "",
"/pkg/config/defaults", "",
)
cfg := map[string]string{
{{- range $key, $value := .}}
replacer.Replace("{{$value}}"): func() string {
fmt.Println("Generating example YAML config for {{ $value -}}")
c := pkg{{$key}}.DefaultConfig()
pkg{{$key}}.EnsureDefaults(c)
pkg{{$key}}.Sanitize(c)
yml, err := yaml.Marshal(c)
if err != nil {
log.Fatalf("Marshalling yaml for pkg0 failed: %s\n", err)
}
return "# Autogenerated\n" + string(yml)
}(),
{{- end}}
}
for pkg, yml := range cfg {
targetFolders := []string{
// TODO: comment in when it is clear how to commit this to the structure of the master|main branch
// filepath.Join("../../", pkg, "/config"),
"../../docs/extensions/_includes/",
}
for _, targetFolder := range targetFolders {
os.MkdirAll(targetFolder, 0700)
targetYamlFile, err := os.Create(filepath.Join(targetFolder, replacer.Replace(pkg) + "-config-example.yaml"))
if err != nil {
log.Fatalf("Failed to create target file for : %s", err)
}
defer targetYamlFile.Close()
targetYamlFile.WriteString(yml)
}
}
}

View File

@@ -23,13 +23,13 @@ type ConfigField struct {
func main() {
fmt.Println("Generating documentation for environment variables:")
content, err := ioutil.ReadFile("../../../docs/templates/CONFIGURATION.tmpl")
content, err := ioutil.ReadFile("../../docs/templates/CONFIGURATION.tmpl")
if err != nil {
log.Fatal(err)
}
replacer := strings.NewReplacer(
"github.com/owncloud/ocis/", "",
"/pkg/config", "",
"/pkg/config/defaults", "",
)
var fields []ConfigField
var targetFile *os.File
@@ -41,7 +41,7 @@ m := map[string]interface{}{
{{- end }}
}
targetFolder := "../../../docs/extensions/_includes/"
targetFolder := "../../docs/extensions/_includes/"
for pkg, conf := range m {
fields = GetAnnotatedVariables(conf)
if len(fields) > 0 {