diff --git a/accounts/cmd/helper/configdoc/main.go b/accounts/cmd/helper/configdoc/main.go new file mode 100644 index 000000000..4866993c2 --- /dev/null +++ b/accounts/cmd/helper/configdoc/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "io/ioutil" + "log" + "os" + + "text/template" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/docs" +) + +func main() { + cfg := config.DefaultConfig() + fields := docs.Display(*cfg) + + content, err := ioutil.ReadFile("docs/templates/CONFIGURATION.tmpl") + if err != nil { + log.Fatal(err) + } + tpl := template.Must(template.New("").Parse(string(content))) + tpl.Execute(os.Stdout, fields) + // for _, f := range fields { + // fmt.Printf("%s %s = %v\t%s\n", f.Name, f.Type, f.DefaultValue, f.Description) + // } +} diff --git a/accounts/pkg/config/config.go b/accounts/pkg/config/config.go index 0152e4991..ba182fc34 100644 --- a/accounts/pkg/config/config.go +++ b/accounts/pkg/config/config.go @@ -25,8 +25,8 @@ type Config struct { Repo Repo Index Index ServiceUser ServiceUser - HashDifficulty int `env:"ACCOUNTS_HASH_DIFFICULTY"` - DemoUsersAndGroups bool `env:"ACCOUNTS_DEMO_USERS_AND_GROUPS"` + HashDifficulty int `env:"ACCOUNTS_HASH_DIFFICULTY" desc:"The hash difficulty makes sure that validating a password takes at least a certain amount of time."` + DemoUsersAndGroups bool `env:"ACCOUNTS_DEMO_USERS_AND_GROUPS" desc:"If this flag is set the service will setup the demo users and groups."` Context context.Context `yaml:"-"` } diff --git a/docs/templates/CONFIGURATION.tmpl b/docs/templates/CONFIGURATION.tmpl new file mode 100644 index 000000000..da7a6ec8e --- /dev/null +++ b/docs/templates/CONFIGURATION.tmpl @@ -0,0 +1,5 @@ +| Name | Type | Default Value | Description | +|------|------|---------------|-------------| +{{- range .}} +| {{.Name}} | {{.Type}} | {{.DefaultValue}} | {{.Description}}| +{{- end }} \ No newline at end of file diff --git a/ocis-pkg/docs/config.go b/ocis-pkg/docs/config.go new file mode 100644 index 000000000..c55ecde7f --- /dev/null +++ b/ocis-pkg/docs/config.go @@ -0,0 +1,38 @@ +package docs + +import ( + "fmt" + "reflect" +) + +type ConfigField struct { + Name string + DefaultValue string + Type string + Description string +} + +func Display(s interface{}) []ConfigField { + t := reflect.TypeOf(s) + v := reflect.ValueOf(s) + + var fields []ConfigField + for i := 0; i < t.NumField(); i++ { + field := t.Field(i) + value := v.Field(i) + + switch value.Kind() { + default: + desc := field.Tag.Get("desc") + env, ok := field.Tag.Lookup("env") + if !ok { + continue + } + v := fmt.Sprintf("%v", value.Interface()) + fields = append(fields, ConfigField{Name: env, DefaultValue: v, Description: desc, Type: value.Type().Name()}) + case reflect.Struct: + fields = append(fields, Display(value.Interface())...) + } + } + return fields +} diff --git a/thumbnails/cmd/helper/configdoc/main.go b/thumbnails/cmd/helper/configdoc/main.go new file mode 100644 index 000000000..5b2de3700 --- /dev/null +++ b/thumbnails/cmd/helper/configdoc/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "github.com/owncloud/ocis/ocis-pkg/docs" + "github.com/owncloud/ocis/thumbnails/pkg/config" +) + +func main() { + cfg := config.DefaultConfig() + docs.Display(*cfg) +} diff --git a/thumbnails/cmd/helper/defaultconfig/main.go b/thumbnails/cmd/helper/defaultconfig/main.go new file mode 100644 index 000000000..1092497cb --- /dev/null +++ b/thumbnails/cmd/helper/defaultconfig/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + + "github.com/owncloud/ocis/accounts/pkg/config" + "github.com/owncloud/ocis/accounts/pkg/config/parser" + "gopkg.in/yaml.v2" +) + +func main() { + + cfg := config.DefaultConfig() + + parser.EnsureDefaults(cfg) + parser.Sanitize(cfg) + + b, err := yaml.Marshal(cfg) + if err != nil { + return + } + fmt.Println(string(b)) +}