From db1b09c873887561b4331516b6bbb96d24b07425 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 12 Mar 2021 14:13:06 +0100 Subject: [PATCH] add glauth to new config scheme --- glauth/pkg/flagset/flagset.go | 59 ++++++++++++++++++----------------- ocis/pkg/command/glauth.go | 3 ++ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/glauth/pkg/flagset/flagset.go b/glauth/pkg/flagset/flagset.go index 5806e7029..c596609cb 100644 --- a/glauth/pkg/flagset/flagset.go +++ b/glauth/pkg/flagset/flagset.go @@ -3,6 +3,7 @@ package flagset import ( "github.com/micro/cli/v2" "github.com/owncloud/ocis/glauth/pkg/config" + "github.com/owncloud/ocis/ocis-pkg/flags" ) // RootWithConfig applies cfg to the root flagset @@ -34,7 +35,7 @@ func HealthWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "debug-addr", - Value: "0.0.0.0:9129", + Value: flags.OverrideDefaultString(cfg.Debug.Addr, "0.0.0.0:9129"), Usage: "Address to debug endpoint", EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, Destination: &cfg.Debug.Addr, @@ -47,7 +48,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { return []cli.Flag{ &cli.StringFlag{ Name: "config-file", - Value: "", + Value: flags.OverrideDefaultString(cfg.File, ""), Usage: "Path to config file", EnvVars: []string{"GLAUTH_CONFIG_FILE"}, Destination: &cfg.File, @@ -60,42 +61,42 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "tracing-type", - Value: "jaeger", + Value: flags.OverrideDefaultString(cfg.Tracing.Type, "jaeger"), Usage: "Tracing backend type", EnvVars: []string{"GLAUTH_TRACING_TYPE"}, Destination: &cfg.Tracing.Type, }, &cli.StringFlag{ Name: "tracing-endpoint", - Value: "", + Value: flags.OverrideDefaultString(cfg.Tracing.Endpoint, ""), Usage: "Endpoint for the agent", EnvVars: []string{"GLAUTH_TRACING_ENDPOINT"}, Destination: &cfg.Tracing.Endpoint, }, &cli.StringFlag{ Name: "tracing-collector", - Value: "", + Value: flags.OverrideDefaultString(cfg.Tracing.Collector, ""), Usage: "Endpoint for the collector", EnvVars: []string{"GLAUTH_TRACING_COLLECTOR"}, Destination: &cfg.Tracing.Collector, }, &cli.StringFlag{ Name: "tracing-service", - Value: "glauth", + Value: flags.OverrideDefaultString(cfg.Tracing.Service, "glauth"), Usage: "Service name for tracing", EnvVars: []string{"GLAUTH_TRACING_SERVICE"}, Destination: &cfg.Tracing.Service, }, &cli.StringFlag{ Name: "debug-addr", - Value: "0.0.0.0:9129", + Value: flags.OverrideDefaultString(cfg.Debug.Addr, "0.0.0.0:9129"), Usage: "Address to bind debug server", EnvVars: []string{"GLAUTH_DEBUG_ADDR"}, Destination: &cfg.Debug.Addr, }, &cli.StringFlag{ Name: "debug-token", - Value: "", + Value: flags.OverrideDefaultString(cfg.Debug.Token, ""), Usage: "Token to grant metrics access", EnvVars: []string{"GLAUTH_DEBUG_TOKEN"}, Destination: &cfg.Debug.Token, @@ -114,7 +115,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.StringFlag{ Name: "role-bundle-id", - Value: "71881883-1768-46bd-a24d-a356a2afdf7f", // BundleUUIDRoleAdmin + Value: flags.OverrideDefaultString(cfg.RoleBundleUUID, "71881883-1768-46bd-a24d-a356a2afdf7f"), // BundleUUIDRoleAdmin Usage: "roleid used to make internal grpc requests", EnvVars: []string{"GLAUTH_ROLE_BUNDLE_ID"}, Destination: &cfg.RoleBundleUUID, @@ -122,14 +123,14 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "ldap-addr", - Value: "0.0.0.0:9125", + Value: flags.OverrideDefaultString(cfg.Ldap.Address, "0.0.0.0:9125"), Usage: "Address to bind ldap server", EnvVars: []string{"GLAUTH_LDAP_ADDR"}, Destination: &cfg.Ldap.Address, }, &cli.BoolFlag{ Name: "ldap-enabled", - Value: true, + Value: flags.OverrideDefaultBool(cfg.Ldap.Enabled, true), Usage: "Enable ldap server", EnvVars: []string{"GLAUTH_LDAP_ENABLED"}, Destination: &cfg.Ldap.Enabled, @@ -137,28 +138,28 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "ldaps-addr", - Value: "0.0.0.0:9126", + Value: flags.OverrideDefaultString(cfg.Ldaps.Address, "0.0.0.0:9126"), Usage: "Address to bind ldap server", EnvVars: []string{"GLAUTH_LDAPS_ADDR"}, Destination: &cfg.Ldaps.Address, }, &cli.BoolFlag{ Name: "ldaps-enabled", - Value: true, + Value: flags.OverrideDefaultBool(cfg.Ldaps.Enabled, true), Usage: "Enable ldap server", EnvVars: []string{"GLAUTH_LDAPS_ENABLED"}, Destination: &cfg.Ldaps.Enabled, }, &cli.StringFlag{ Name: "ldaps-cert", - Value: "./ldap.crt", + Value: flags.OverrideDefaultString(cfg.Ldaps.Cert, "./ldap.crt"), Usage: "path to ldaps certificate in PEM format", EnvVars: []string{"GLAUTH_LDAPS_CERT"}, Destination: &cfg.Ldaps.Cert, }, &cli.StringFlag{ Name: "ldaps-key", - Value: "./ldap.key", + Value: flags.OverrideDefaultString(cfg.Ldaps.Key, "./ldap.key"), Usage: "path to ldaps key in PEM format", EnvVars: []string{"GLAUTH_LDAPS_KEY"}, Destination: &cfg.Ldaps.Key, @@ -168,35 +169,35 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "backend-basedn", - Value: "dc=example,dc=org", + Value: flags.OverrideDefaultString(cfg.Backend.BaseDN, "dc=example,dc=org"), Usage: "base distinguished name to expose", EnvVars: []string{"GLAUTH_BACKEND_BASEDN"}, Destination: &cfg.Backend.BaseDN, }, &cli.StringFlag{ Name: "backend-name-format", - Value: "cn", + Value: flags.OverrideDefaultString(cfg.Backend.NameFormat, "cn"), Usage: "name attribute for entries to expose. typically cn or uid", EnvVars: []string{"GLAUTH_BACKEND_NAME_FORMAT"}, Destination: &cfg.Backend.NameFormat, }, &cli.StringFlag{ Name: "backend-group-format", - Value: "ou", + Value: flags.OverrideDefaultString(cfg.Backend.GroupFormat, "ou"), Usage: "name attribute for entries to expose. typically ou, cn or dc", EnvVars: []string{"GLAUTH_BACKEND_GROUP_FORMAT"}, Destination: &cfg.Backend.GroupFormat, }, &cli.StringFlag{ Name: "backend-ssh-key-attr", - Value: "sshPublicKey", + Value: flags.OverrideDefaultString(cfg.Backend.SSHKeyAttr, "sshPublicKey"), Usage: "ssh key attribute for entries to expose", EnvVars: []string{"GLAUTH_BACKEND_SSH_KEY_ATTR"}, Destination: &cfg.Backend.SSHKeyAttr, }, &cli.StringFlag{ Name: "backend-datastore", - Value: "accounts", + Value: flags.OverrideDefaultString(cfg.Backend.Datastore, "accounts"), // TODO bring back config / flat file support Usage: "datastore to use as the backend. one of accounts, ldap or owncloud", EnvVars: []string{"GLAUTH_BACKEND_DATASTORE"}, @@ -204,7 +205,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.BoolFlag{ Name: "backend-insecure", - Value: false, + Value: flags.OverrideDefaultBool(cfg.Backend.Insecure, false), Usage: "Allow insecure requests to the datastore", EnvVars: []string{"GLAUTH_BACKEND_INSECURE"}, Destination: &cfg.Backend.Insecure, @@ -217,7 +218,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.BoolFlag{ Name: "backend-use-graphapi", - Value: true, + Value: flags.OverrideDefaultBool(cfg.Backend.UseGraphAPI, true), Usage: "use Graph API, only for owncloud datastore", EnvVars: []string{"GLAUTH_BACKEND_USE_GRAPHAPI"}, Destination: &cfg.Backend.UseGraphAPI, @@ -227,35 +228,35 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { &cli.StringFlag{ Name: "fallback-basedn", - Value: "dc=example,dc=org", + Value: flags.OverrideDefaultString(cfg.Fallback.BaseDN, "dc=example,dc=org"), Usage: "base distinguished name to expose", EnvVars: []string{"GLAUTH_FALLBACK_BASEDN"}, Destination: &cfg.Fallback.BaseDN, }, &cli.StringFlag{ Name: "fallback-name-format", - Value: "cn", + Value: flags.OverrideDefaultString(cfg.Fallback.NameFormat, "cn"), Usage: "name attribute for entries to expose. typically cn or uid", EnvVars: []string{"GLAUTH_FALLBACK_NAME_FORMAT"}, Destination: &cfg.Fallback.NameFormat, }, &cli.StringFlag{ Name: "fallback-group-format", - Value: "ou", + Value: flags.OverrideDefaultString(cfg.Fallback.GroupFormat, "ou"), Usage: "name attribute for entries to expose. typically ou, cn or dc", EnvVars: []string{"GLAUTH_FALLBACK_GROUP_FORMAT"}, Destination: &cfg.Fallback.GroupFormat, }, &cli.StringFlag{ Name: "fallback-ssh-key-attr", - Value: "sshPublicKey", + Value: flags.OverrideDefaultString(cfg.Fallback.SSHKeyAttr, "sshPublicKey"), Usage: "ssh key attribute for entries to expose", EnvVars: []string{"GLAUTH_FALLBACK_SSH_KEY_ATTR"}, Destination: &cfg.Fallback.SSHKeyAttr, }, &cli.StringFlag{ Name: "fallback-datastore", - Value: "", + Value: flags.OverrideDefaultString(cfg.Fallback.Datastore, ""), // TODO bring back config / flat file support Usage: "datastore to use as the fallback. one of accounts, ldap or owncloud", EnvVars: []string{"GLAUTH_FALLBACK_DATASTORE"}, @@ -263,7 +264,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.BoolFlag{ Name: "fallback-insecure", - Value: false, + Value: flags.OverrideDefaultBool(cfg.Fallback.Insecure, false), Usage: "Allow insecure requests to the datastore", EnvVars: []string{"GLAUTH_FALLBACK_INSECURE"}, Destination: &cfg.Fallback.Insecure, @@ -276,7 +277,7 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { }, &cli.BoolFlag{ Name: "fallback-use-graphapi", - Value: true, + Value: flags.OverrideDefaultBool(cfg.Fallback.UseGraphAPI, true), Usage: "use Graph API, only for owncloud datastore", EnvVars: []string{"GLAUTH_FALLBACK_USE_GRAPHAPI"}, Destination: &cfg.Fallback.UseGraphAPI, diff --git a/ocis/pkg/command/glauth.go b/ocis/pkg/command/glauth.go index 21f48257e..e220c8910 100644 --- a/ocis/pkg/command/glauth.go +++ b/ocis/pkg/command/glauth.go @@ -17,6 +17,9 @@ func GLAuthCommand(cfg *config.Config) *cli.Command { Usage: "Start glauth server", Category: "Extensions", Flags: flagset.ServerWithConfig(cfg.GLAuth), + Before: func(ctx *cli.Context) error { + return ParseConfig(ctx, cfg) + }, Action: func(c *cli.Context) error { origCmd := command.Server(configureGLAuth(cfg)) return handleOriginalAction(c, origCmd)