Merge pull request #5369 from kobergj/CollectGlobalEnvVars
Collect global Envvars
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
Enhancement: Collect global envvars
|
||||||
|
|
||||||
|
Compose a list of all envvars living in more than 1 service
|
||||||
|
|
||||||
|
https://github.com/owncloud/ocis/pull/5367
|
||||||
@@ -9,11 +9,14 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"sort"
|
||||||
|
|
||||||
{{- range $key, $value := .}}
|
{{- range $key, $value := .}}
|
||||||
pkg{{$key}} "{{$value}}"
|
pkg{{$key}} "{{$value}}"
|
||||||
{{- end}})
|
{{- end}}
|
||||||
|
)
|
||||||
|
|
||||||
|
// ConfigField is the representation of one configuration field
|
||||||
type ConfigField struct {
|
type ConfigField struct {
|
||||||
EnvVars []string
|
EnvVars []string
|
||||||
DefaultValue string
|
DefaultValue string
|
||||||
@@ -23,6 +26,7 @@ type ConfigField struct {
|
|||||||
DeprecationLink string
|
DeprecationLink string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeprecationField holds information about deprecation
|
||||||
type DeprecationField struct {
|
type DeprecationField struct {
|
||||||
DeprecationVersion string
|
DeprecationVersion string
|
||||||
DeprecationInfo string
|
DeprecationInfo string
|
||||||
@@ -30,6 +34,15 @@ type DeprecationField struct {
|
|||||||
RemovalVersion string
|
RemovalVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnvVar holds information about one envvar
|
||||||
|
type EnvVar struct {
|
||||||
|
Name string
|
||||||
|
DefaultValue string
|
||||||
|
Type string
|
||||||
|
Description string
|
||||||
|
Services []string
|
||||||
|
}
|
||||||
|
|
||||||
type templateData struct {
|
type templateData struct {
|
||||||
ExtensionName string
|
ExtensionName string
|
||||||
Fields []ConfigField
|
Fields []ConfigField
|
||||||
@@ -38,44 +51,66 @@ type templateData struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Generating adoc documentation for environment variables:")
|
fmt.Println("Generating adoc documentation for environment variables:")
|
||||||
content, err := os.ReadFile("../../docs/templates/ADOC.tmpl")
|
content, err := os.ReadFile("../../docs/templates/ADOC.tmpl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
replacer := strings.NewReplacer(
|
replacer := strings.NewReplacer(
|
||||||
"github.com/owncloud/ocis/v2/services/", "",
|
"github.com/owncloud/ocis/v2/services/", "",
|
||||||
"/pkg/config/defaults", "",
|
"/pkg/config/defaults", "",
|
||||||
)
|
)
|
||||||
var fields []ConfigField
|
var fields []ConfigField
|
||||||
var deprecations []DeprecationField
|
var deprecations []DeprecationField
|
||||||
var targetFile *os.File
|
var targetFile *os.File
|
||||||
tpl := template.Must(template.New("").Parse(string(content)))
|
tpl := template.Must(template.New("").Parse(string(content)))
|
||||||
|
|
||||||
m := map[string]interface{}{
|
m := map[string]interface{}{
|
||||||
{{- range $key, $value := .}}
|
{{- range $key, $value := .}}
|
||||||
"{{$value}}": *pkg{{$key}}.FullDefaultConfig(),
|
"{{$value}}": *pkg{{$key}}.FullDefaultConfig(),
|
||||||
{{- end }}
|
{{- end }}
|
||||||
}
|
|
||||||
|
|
||||||
targetFolder := "../../docs/services/_includes/adoc/"
|
|
||||||
for pkg, conf := range m {
|
|
||||||
fields, deprecations = GetAnnotatedVariables(conf)
|
|
||||||
var hasDeprecations bool
|
|
||||||
if len(deprecations) > 0 {
|
|
||||||
hasDeprecations = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(fields) > 0 || len(deprecations) > 0 {
|
targetFolder := "../../docs/services/_includes/adoc/"
|
||||||
fmt.Printf("... %s\n", pkg)
|
all := make(map[string]EnvVar)
|
||||||
targetFile, err = os.Create(filepath.Join(targetFolder, replacer.Replace(pkg) + "_configvars.adoc"))
|
for pkg, conf := range m {
|
||||||
|
service := replacer.Replace(pkg)
|
||||||
|
fields, deprecations = GetAnnotatedVariables(conf)
|
||||||
|
var hasDeprecations bool
|
||||||
|
if len(deprecations) > 0 {
|
||||||
|
hasDeprecations = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range fields {
|
||||||
|
for _, e := range f.EnvVars {
|
||||||
|
if env, ok := all[e]; ok {
|
||||||
|
env.Services = append(env.Services, service)
|
||||||
|
sort.Slice(env.Services, func(i, j int) bool {
|
||||||
|
return env.Services[i] < env.Services[j]
|
||||||
|
})
|
||||||
|
all[e] = env
|
||||||
|
} else {
|
||||||
|
all[e] = EnvVar{
|
||||||
|
Name: e,
|
||||||
|
Description: f.Description,
|
||||||
|
Type: f.Type,
|
||||||
|
DefaultValue: f.DefaultValue,
|
||||||
|
Services: []string{service},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(fields) > 0 || len(deprecations) > 0 {
|
||||||
|
fmt.Printf("... %s\n", pkg)
|
||||||
|
targetFile, err = os.Create(filepath.Join(targetFolder, service + "_configvars.adoc"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to create target file: %s", err)
|
log.Fatalf("Failed to create target file: %s", err)
|
||||||
}
|
}
|
||||||
defer targetFile.Close()
|
defer targetFile.Close()
|
||||||
|
|
||||||
td := templateData{
|
td := templateData{
|
||||||
ExtensionName: replacer.Replace(pkg),
|
ExtensionName: service,
|
||||||
Fields: fields,
|
Fields: fields,
|
||||||
Deprecations: deprecations,
|
Deprecations: deprecations,
|
||||||
HasDeprecations: hasDeprecations ,
|
HasDeprecations: hasDeprecations ,
|
||||||
@@ -83,8 +118,43 @@ m := map[string]interface{}{
|
|||||||
if err := tpl.Execute(targetFile, td); err != nil {
|
if err := tpl.Execute(targetFile, td); err != nil {
|
||||||
log.Fatalf("Failed to execute template: %s", err)
|
log.Fatalf("Failed to execute template: %s", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// render global env vars
|
||||||
|
tmplValues := make([]map[string]interface{}, 0)
|
||||||
|
for _, env := range all {
|
||||||
|
if len(env.Services) > 1 {
|
||||||
|
tmplValues = append(tmplValues, map[string]interface{}{
|
||||||
|
"Name": env.Name,
|
||||||
|
"Services": env.Services,
|
||||||
|
"Description": env.Description,
|
||||||
|
"DefaultValue": env.DefaultValue,
|
||||||
|
"Type": env.Type,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort
|
||||||
|
sort.Slice(tmplValues, func(i, j int) bool {
|
||||||
|
return tmplValues[i]["Name"].(string) < tmplValues[j]["Name"].(string)
|
||||||
|
})
|
||||||
|
|
||||||
|
glc, err := os.ReadFile("../../docs/templates/ADOC_global.tmpl")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
gltpl := template.Must(template.New("").Parse(string(glc)))
|
||||||
|
glfile, err := os.Create(filepath.Join(targetFolder, "global_configvars.adoc"))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to create target file: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gltpl.Execute(glfile, tmplValues); err != nil {
|
||||||
|
log.Printf("Failed to execute template: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("done")
|
fmt.Println("done")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// collected through docs/helpers/adoc-generator.go.tmpl
|
||||||
|
|
||||||
|
[.landscape]
|
||||||
|
[caption=]
|
||||||
|
.Environment variables with global scope available in multiple services
|
||||||
|
[width="100%",cols="30%,25%,~,~,~",options="header"]
|
||||||
|
|===
|
||||||
|
| Name
|
||||||
|
| Services
|
||||||
|
| Type
|
||||||
|
| Default Value
|
||||||
|
| Description
|
||||||
|
|
||||||
|
{{ range . }}
|
||||||
|
|
||||||
|
a| `{{ .Name }}`
|
||||||
|
|
||||||
|
a| [subs=attributes+]
|
||||||
|
{{- range .Services}}
|
||||||
|
* xref:{s-path}/{{ . }}.adoc[{{ . }}] +
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
a| [subs=-attributes]
|
||||||
|
++{{ .Type }} ++
|
||||||
|
|
||||||
|
a| [subs=-attributes]
|
||||||
|
++{{ .DefaultValue }} ++
|
||||||
|
|
||||||
|
a| [subs=-attributes]
|
||||||
|
{{ .Description }}
|
||||||
|
|
||||||
|
{{- end }}
|
||||||
|
|===
|
||||||
Reference in New Issue
Block a user