switch all other services to struct tag based env config

This commit is contained in:
Willy Kloucek
2022-01-07 15:47:47 +00:00
committed by Jörn Friedrich Dreyer
parent 288d6c469e
commit 6990e7d660
116 changed files with 1024 additions and 1991 deletions
+2 -1
View File
@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/owncloud/ocis/ocs/pkg/logging"
"github.com/urfave/cli/v2"
)
@@ -17,7 +18,7 @@ func Health(cfg *config.Config) *cli.Command {
return ParseConfig(c, cfg)
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
logger := logging.Configure(cfg.Service.Name, cfg.Log)
resp, err := http.Get(
fmt.Sprintf(
+2 -14
View File
@@ -6,7 +6,6 @@ import (
"github.com/imdario/mergo"
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/log"
"github.com/owncloud/ocis/ocis-pkg/version"
"github.com/owncloud/ocis/ocs/pkg/config"
"github.com/thejerf/suture/v4"
@@ -31,7 +30,7 @@ func Execute(cfg *config.Config) error {
Before: func(c *cli.Context) error {
cfg.Service.Version = version.String
return nil
return ParseConfig(c, cfg)
},
Commands: []*cli.Command{
@@ -54,17 +53,6 @@ func Execute(cfg *config.Config) error {
return app.Run(os.Args)
}
// NewLogger initializes a service-specific logger instance.
func NewLogger(cfg *config.Config) log.Logger {
return log.NewLogger(
log.Name("ocs"),
log.Level(cfg.Log.Level),
log.Pretty(cfg.Log.Pretty),
log.Color(cfg.Log.Color),
log.File(cfg.Log.File),
)
}
// ParseConfig loads idp configuration from known paths.
func ParseConfig(c *cli.Context, cfg *config.Config) error {
_, err := ociscfg.BindSourcesToStructs(cfg.Service.Name, cfg)
@@ -105,7 +93,7 @@ type SutureService struct {
// NewSutureService creates a new ocs.SutureService
func NewSutureService(cfg *ociscfg.Config) suture.Service {
cfg.OCS.Commons = cfg.Commons
//cfg.OCS.Commons = cfg.Commons
return SutureService{
cfg: cfg.OCS,
}
+15 -15
View File
@@ -74,27 +74,27 @@ type IdentityManagement struct {
type Config struct {
*shared.Commons
Log Log `ocisConfig:"log"`
Debug Debug `ocisConfig:"debug"`
HTTP HTTP `ocisConfig:"http"`
Tracing Tracing `ocisConfig:"tracing"`
TokenManager TokenManager `ocisConfig:"token_manager"`
Service Service `ocisConfig:"service"`
Reva Reva `ocisConfig:"reva"`
Service Service `ocisConfig:"service"`
Tracing Tracing `ocisConfig:"tracing"`
Log Log `ocisConfig:"log"`
Debug Debug `ocisConfig:"debug"`
HTTP HTTP `ocisConfig:"http"`
TokenManager TokenManager `ocisConfig:"token_manager"`
Reva Reva `ocisConfig:"reva"`
IdentityManagement IdentityManagement `ocisConfig:"identity_management"`
AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"`
StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"`
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"`
AccountBackend string `ocisConfig:"account_backend" env:"OCS_ACCOUNT_BACKEND_TYPE"`
StorageUsersDriver string `ocisConfig:"storage_users_driver" env:"STORAGE_USERS_DRIVER;OCS_STORAGE_USERS_DRIVER"`
MachineAuthAPIKey string `ocisConfig:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY;OCS_MACHINE_AUTH_API_KEY"`
Context context.Context
Supervised bool
}
// New initializes a new configuration with or without defaults.
func New() *Config {
return &Config{}
}
// DefaultConfig provides default values for a config struct.
func DefaultConfig() *Config {
return &Config{