mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-09 21:59:42 -06:00
fixed code smells: string literal repetition + cyclomatic complexity
This commit is contained in:
@@ -72,7 +72,7 @@ type Runtime struct {
|
||||
type Config struct {
|
||||
*shared.Commons `mapstructure:"shared"`
|
||||
|
||||
Mode Mode // DEPRECATED
|
||||
Mode Mode
|
||||
File string
|
||||
OcisURL string `mapstructure:"ocis_url"`
|
||||
|
||||
|
||||
@@ -124,10 +124,6 @@ func NewService(options ...Option) (*Service, error) {
|
||||
// Start an rpc service. By default the package scope Start will run all default extensions to provide with a working
|
||||
// oCIS instance.
|
||||
func Start(o ...Option) error {
|
||||
// Start the runtime. Most likely this was called ONLY by the `ocis server` subcommand, but since we cannot protect
|
||||
// from the caller, the previous statement holds truth.
|
||||
|
||||
// prepare a new rpc Service struct.
|
||||
s, err := NewService(o...)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -171,10 +167,7 @@ func Start(o ...Option) error {
|
||||
s.cfg.Storage.Log = &shared.Log{}
|
||||
}
|
||||
|
||||
s.cfg.Storage.Log.Color = s.cfg.Commons.Color
|
||||
s.cfg.Storage.Log.Level = s.cfg.Commons.Level
|
||||
s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty
|
||||
s.cfg.Storage.Log.File = s.cfg.Commons.File
|
||||
propagateLoggingCommonsToStorages(s)
|
||||
|
||||
if err = rpc.Register(s); err != nil {
|
||||
if s != nil {
|
||||
@@ -188,16 +181,7 @@ func Start(o ...Option) error {
|
||||
s.Log.Fatal().Err(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
reason := strings.Builder{}
|
||||
if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
|
||||
reason.WriteString("runtime address already in use")
|
||||
}
|
||||
|
||||
fmt.Println(reason.String())
|
||||
}
|
||||
}()
|
||||
defer gracefulRecovery(s)
|
||||
|
||||
// prepare the set of services to run
|
||||
s.generateRunSet(s.cfg)
|
||||
@@ -222,6 +206,26 @@ func Start(o ...Option) error {
|
||||
return http.Serve(l, nil)
|
||||
}
|
||||
|
||||
func propagateLoggingCommonsToStorages(s *Service) {
|
||||
s.cfg.Storage.Log.Color = s.cfg.Commons.Color
|
||||
s.cfg.Storage.Log.Level = s.cfg.Commons.Level
|
||||
s.cfg.Storage.Log.Pretty = s.cfg.Commons.Pretty
|
||||
s.cfg.Storage.Log.File = s.cfg.Commons.File
|
||||
}
|
||||
|
||||
func gracefulRecovery(s *Service) {
|
||||
func() {
|
||||
if r := recover(); r != nil {
|
||||
reason := strings.Builder{}
|
||||
if _, err := net.Dial("tcp", net.JoinHostPort(s.cfg.Runtime.Host, s.cfg.Runtime.Port)); err != nil {
|
||||
reason.WriteString("runtime address already in use")
|
||||
}
|
||||
|
||||
fmt.Println(reason.String())
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// scheduleServiceTokens adds service tokens to the service supervisor.
|
||||
func scheduleServiceTokens(s *Service, funcSet serviceFuncMap) {
|
||||
for _, name := range runset {
|
||||
|
||||
@@ -256,6 +256,10 @@ func DefaultConfig() *Config {
|
||||
}
|
||||
|
||||
func defaultPolicies() []Policy {
|
||||
const idpBackend = "http://localhost:9130"
|
||||
const revaBackend = "http://localhost:9140"
|
||||
const ingressBackendURL = "https://demo.owncloud.com"
|
||||
|
||||
return []Policy{
|
||||
{
|
||||
Name: "ocis",
|
||||
@@ -266,19 +270,19 @@ func defaultPolicies() []Policy {
|
||||
},
|
||||
{
|
||||
Endpoint: "/.well-known/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: idpBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/konnect/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: idpBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/signin/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: idpBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/archiver",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Type: RegexRoute,
|
||||
@@ -287,7 +291,7 @@ func defaultPolicies() []Policy {
|
||||
},
|
||||
{
|
||||
Endpoint: "/ocs/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Type: QueryRoute,
|
||||
@@ -296,31 +300,31 @@ func defaultPolicies() []Policy {
|
||||
},
|
||||
{
|
||||
Endpoint: "/remote.php/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/dav/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/webdav/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/status.php",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/index.php/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/data",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/app/",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/graph/",
|
||||
@@ -335,7 +339,6 @@ func defaultPolicies() []Policy {
|
||||
Endpoint: "/api/v0/accounts",
|
||||
Backend: "http://localhost:9181",
|
||||
},
|
||||
// TODO the lookup needs a better mechanism
|
||||
{
|
||||
Endpoint: "/accounts.js",
|
||||
Backend: "http://localhost:9181",
|
||||
@@ -359,53 +362,53 @@ func defaultPolicies() []Policy {
|
||||
},
|
||||
{
|
||||
Endpoint: "/.well-known/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: idpBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/konnect/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: idpBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/signin/",
|
||||
Backend: "http://localhost:9130",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/archiver",
|
||||
Backend: "http://localhost:9140",
|
||||
Backend: revaBackend,
|
||||
},
|
||||
{
|
||||
Endpoint: "/ocs/",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/remote.php/",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/dav/",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/webdav/",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/status.php",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/index.php/",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
{
|
||||
Endpoint: "/data",
|
||||
Backend: "https://demo.owncloud.com",
|
||||
Backend: ingressBackendURL,
|
||||
ApacheVHost: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -27,10 +27,12 @@ func Server(opts ...Option) (*http.Server, error) {
|
||||
), nil
|
||||
}
|
||||
|
||||
const contentTypeHeader = "Content-Type"
|
||||
|
||||
// health implements the health check.
|
||||
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set(contentTypeHeader, "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
// TODO(tboerger): check if services are up and running
|
||||
@@ -44,7 +46,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||
// ready implements the ready check.
|
||||
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Header().Set(contentTypeHeader, "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
// TODO(tboerger): check if services are up and running
|
||||
|
||||
@@ -518,9 +518,17 @@ func New() *Config {
|
||||
return &Config{}
|
||||
}
|
||||
|
||||
const (
|
||||
defaultLocalIngressURL = "https://localhost:9200"
|
||||
defaultSharesFolder = "/Shares"
|
||||
defaultEOSMasterURL = "root://eos-mgm1.eoscluster.cern.ch:1094"
|
||||
defaultGatewaySVCAddr = "127.0.0.1:9142"
|
||||
defaultUserLayout = "{{.Id.OpaqueId}}"
|
||||
)
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
|
||||
return &Config{
|
||||
// log is inherited
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9109",
|
||||
},
|
||||
@@ -530,7 +538,7 @@ func DefaultConfig() *Config {
|
||||
TransferSecret: "replace-me-with-a-transfer-secret",
|
||||
TransferExpires: 24 * 60 * 60,
|
||||
OIDC: OIDC{
|
||||
Issuer: "https://localhost:9200",
|
||||
Issuer: defaultLocalIngressURL,
|
||||
Insecure: false,
|
||||
IDClaim: "preferred_username",
|
||||
},
|
||||
@@ -551,7 +559,7 @@ func DefaultConfig() *Config {
|
||||
GroupMemberFilter: "(&(objectclass=posixAccount)(ownclouduuid={{.OpaqueId}}*))",
|
||||
BindDN: "cn=reva,ou=sysusers,dc=ocis,dc=test",
|
||||
BindPassword: "reva",
|
||||
IDP: "https://localhost:9200",
|
||||
IDP: defaultLocalIngressURL,
|
||||
UserSchema: LDAPUserSchema{
|
||||
UID: "ownclouduuid",
|
||||
Mail: "mail",
|
||||
@@ -577,7 +585,7 @@ func DefaultConfig() *Config {
|
||||
DBHost: "mysql",
|
||||
DBPort: 3306,
|
||||
DBName: "owncloud",
|
||||
Idp: "https://localhost:9200",
|
||||
Idp: defaultLocalIngressURL,
|
||||
Nobody: 90,
|
||||
JoinUsername: false,
|
||||
JoinOwnCloudUUID: false,
|
||||
@@ -596,29 +604,29 @@ func DefaultConfig() *Config {
|
||||
EOS: DriverEOS{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: "/eos/dockertest/reva",
|
||||
ShareFolder: "/Shares",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: "{{substr 0 1 .Username}}/{{.Username}}",
|
||||
},
|
||||
ShadowNamespace: "", // Defaults to path.Join(c.Namespace, ".shadow")
|
||||
UploadsNamespace: "", // Defaults to path.Join(c.Namespace, ".uploads")
|
||||
EosBinary: "/usr/bin/eos",
|
||||
XrdcopyBinary: "/usr/bin/xrdcopy",
|
||||
MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094",
|
||||
SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094",
|
||||
MasterURL: defaultEOSMasterURL,
|
||||
SlaveURL: defaultEOSMasterURL,
|
||||
CacheDirectory: os.TempDir(),
|
||||
GatewaySVC: "127.0.0.1:9142",
|
||||
GatewaySVC: defaultGatewaySVCAddr,
|
||||
},
|
||||
Local: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "local", "users"),
|
||||
ShareFolder: "/Shares",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: "{{.Username}}",
|
||||
EnableHome: false,
|
||||
},
|
||||
OwnCloud: DriverOwnCloud{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"),
|
||||
ShareFolder: "/Shares",
|
||||
UserLayout: "{{.Id.OpaqueId}}",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: defaultUserLayout,
|
||||
EnableHome: false,
|
||||
},
|
||||
UploadInfoDir: path.Join(defaults.BaseDataPath(), "storage", "uploadinfo"),
|
||||
@@ -628,7 +636,7 @@ func DefaultConfig() *Config {
|
||||
OwnCloudSQL: DriverOwnCloudSQL{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "owncloud"),
|
||||
ShareFolder: "/Shares",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: "{{.Username}}",
|
||||
EnableHome: false,
|
||||
},
|
||||
@@ -650,8 +658,8 @@ func DefaultConfig() *Config {
|
||||
S3NG: DriverS3NG{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
|
||||
ShareFolder: "/Shares",
|
||||
UserLayout: "{{.Id.OpaqueId}}",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: defaultUserLayout,
|
||||
EnableHome: false,
|
||||
},
|
||||
Region: "default",
|
||||
@@ -663,8 +671,8 @@ func DefaultConfig() *Config {
|
||||
OCIS: DriverOCIS{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "users"),
|
||||
ShareFolder: "/Shares",
|
||||
UserLayout: "{{.Id.OpaqueId}}",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: defaultUserLayout,
|
||||
},
|
||||
ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad",
|
||||
},
|
||||
@@ -673,7 +681,7 @@ func DefaultConfig() *Config {
|
||||
EOS: DriverEOS{
|
||||
DriverCommon: DriverCommon{
|
||||
Root: "/eos/dockertest/reva",
|
||||
ShareFolder: "/Shares",
|
||||
ShareFolder: defaultSharesFolder,
|
||||
UserLayout: "{{substr 0 1 .Username}}/{{.Username}}",
|
||||
EnableHome: false,
|
||||
},
|
||||
@@ -681,9 +689,9 @@ func DefaultConfig() *Config {
|
||||
UploadsNamespace: "",
|
||||
EosBinary: "/usr/bin/eos",
|
||||
XrdcopyBinary: "/usr/bin/xrdcopy",
|
||||
MasterURL: "root://eos-mgm1.eoscluster.cern.ch:1094",
|
||||
MasterURL: defaultEOSMasterURL,
|
||||
GrpcURI: "",
|
||||
SlaveURL: "root://eos-mgm1.eoscluster.cern.ch:1094",
|
||||
SlaveURL: defaultEOSMasterURL,
|
||||
CacheDirectory: os.TempDir(),
|
||||
EnableLogging: false,
|
||||
ShowHiddenSysFiles: false,
|
||||
@@ -692,7 +700,7 @@ func DefaultConfig() *Config {
|
||||
SecProtocol: "",
|
||||
Keytab: "",
|
||||
SingleUsername: "",
|
||||
GatewaySVC: "127.0.0.1:9142",
|
||||
GatewaySVC: defaultGatewaySVCAddr,
|
||||
},
|
||||
Local: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "local", "metadata"),
|
||||
@@ -707,7 +715,7 @@ func DefaultConfig() *Config {
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"),
|
||||
ShareFolder: "",
|
||||
UserLayout: "{{.Id.OpaqueId}}",
|
||||
UserLayout: defaultUserLayout,
|
||||
EnableHome: false,
|
||||
},
|
||||
Region: "default",
|
||||
@@ -716,7 +724,7 @@ func DefaultConfig() *Config {
|
||||
DriverCommon: DriverCommon{
|
||||
Root: path.Join(defaults.BaseDataPath(), "storage", "metadata"),
|
||||
ShareFolder: "",
|
||||
UserLayout: "{{.Id.OpaqueId}}",
|
||||
UserLayout: defaultUserLayout,
|
||||
EnableHome: false,
|
||||
},
|
||||
ServiceUserUUID: "95cb8724-03b2-11eb-a0a6-c33ef8ef53ad",
|
||||
@@ -747,9 +755,9 @@ func DefaultConfig() *Config {
|
||||
OCDavInsecure: false,
|
||||
OCDavPrefix: "",
|
||||
OCSPrefix: "ocs",
|
||||
OCSSharePrefix: "/Shares",
|
||||
OCSSharePrefix: defaultSharesFolder,
|
||||
OCSHomeNamespace: "/home",
|
||||
PublicURL: "https://localhost:9200",
|
||||
PublicURL: defaultLocalIngressURL,
|
||||
OCSCacheWarmupDriver: "",
|
||||
OCSAdditionalInfoAttribute: "{{.Mail}}",
|
||||
OCSResourceInfoCacheTTL: 0,
|
||||
@@ -761,10 +769,10 @@ func DefaultConfig() *Config {
|
||||
},
|
||||
Gateway: Gateway{
|
||||
Port: Port{
|
||||
Endpoint: "127.0.0.1:9142",
|
||||
Endpoint: defaultGatewaySVCAddr,
|
||||
DebugAddr: "127.0.0.1:9143",
|
||||
GRPCNetwork: "tcp",
|
||||
GRPCAddr: "127.0.0.1:9142",
|
||||
GRPCAddr: defaultGatewaySVCAddr,
|
||||
},
|
||||
CommitShareToStorageGrant: true,
|
||||
CommitShareToStorageRef: true,
|
||||
|
||||
@@ -3,10 +3,6 @@ package command
|
||||
import (
|
||||
"context"
|
||||
|
||||
gofig "github.com/gookit/config/v2"
|
||||
ociscfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
|
||||
"github.com/owncloud/ocis/store/pkg/tracing"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/sync"
|
||||
@@ -25,26 +21,7 @@ func Server(cfg *config.Config) *cli.Command {
|
||||
Name: "server",
|
||||
Usage: "Start integrated server",
|
||||
Before: func(ctx *cli.Context) error {
|
||||
// remember shared logging info to prevent empty overwrites
|
||||
inLog := cfg.Log
|
||||
if err := ParseConfig(ctx, cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if (cfg.Log == shared.Log{}) && (inLog != shared.Log{}) {
|
||||
// set the default to the parent config
|
||||
cfg.Log = inLog
|
||||
|
||||
// and parse the environment
|
||||
conf := &gofig.Config{}
|
||||
conf.LoadOSEnv(config.GetEnv(), false)
|
||||
bindings := config.StructMappings(cfg)
|
||||
if err := ociscfg.BindEnv(conf, bindings); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return ParseConfig(ctx, cfg)
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
logger := NewLogger(cfg)
|
||||
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
const defaultIngressURL = "https://localhost:9200"
|
||||
|
||||
// Debug defines the available debug configuration.
|
||||
type Debug struct {
|
||||
Addr string `mapstructure:"addr"`
|
||||
@@ -106,6 +108,7 @@ func New() *Config {
|
||||
}
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
|
||||
return &Config{
|
||||
Debug: Debug{
|
||||
Addr: "127.0.0.1:9104",
|
||||
@@ -131,15 +134,15 @@ func DefaultConfig() *Config {
|
||||
},
|
||||
Web: Web{
|
||||
Path: "",
|
||||
ThemeServer: "https://localhost:9200",
|
||||
ThemeServer: defaultIngressURL,
|
||||
ThemePath: "/themes/owncloud/theme.json",
|
||||
Config: WebConfig{
|
||||
Server: "https://localhost:9200",
|
||||
Server: defaultIngressURL,
|
||||
Theme: "",
|
||||
Version: "0.1.0",
|
||||
OpenIDConnect: OIDC{
|
||||
MetadataURL: "",
|
||||
Authority: "https://localhost:9200",
|
||||
Authority: defaultIngressURL,
|
||||
ClientID: "web",
|
||||
ResponseType: "code",
|
||||
Scope: "openid profile email",
|
||||
|
||||
Reference in New Issue
Block a user