// New returns a new Service. func New(cfg *config.Config) (services.Service, error) { dirs := cfg.GetDirectives() authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod) dataController, err := data.GetDataController(cfg) if err != nil { return nil, err } authenticationController, err := authentication.GetAuthenticationController(cfg) if err != nil { return nil, err } metaDataController, err := metadata.GetMetaDataController(cfg) if err != nil { return nil, err } if err := os.MkdirAll(dirs.OCWebDAV.ChunksNamespace, 0755); err != nil { return nil, err } if err := os.MkdirAll(dirs.OCWebDAV.ChunksTemporaryNamespace, 0755); err != nil { return nil, err } return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil }
func handleCPU(cfg *config.Config) { cpu := cfg.GetDirectives().Server.CPU // Set CPU capacity err := setCPU(cpu) if err != nil { log.Fatal("Cannot tweak CPU: ", err) } }
func handleShowConfig(cfg *config.Config) { dirs := cfg.GetDirectives() data, err := json.MarshalIndent(dirs, "", " ") if err != nil { log.Fatal(err) } fmt.Println(string(data)) os.Exit(0) }
// GetMetaDataController returns an already configured meta data controller. func GetMetaDataController(conf *config.Config) (metadatacontroller.MetaDataController, error) { dirs := conf.GetDirectives() switch dirs.MetaData.Type { case "simple": return simple.New(conf) case "ocsql": return ocsql.New(conf) default: return nil, errors.New("metadata type " + dirs.MetaData.Type + "does not exist") } }
// GetAuthenticationController returns an already configured authentication controller. func GetAuthenticationController(conf *config.Config) (authenticationcontroller.AuthenticationController, error) { dirs := conf.GetDirectives() switch dirs.Authentication.Type { case "memory": return memory.New(conf) case "sql": return sql.New(conf) default: return nil, errors.New("authentication type " + dirs.Authentication.Type + " does not exist") } }
// New returns an AuthenticationControler that // stores users in memory. This controller is for testing purposes. func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) { dirs := conf.GetDirectives() authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod) users, err := decodeUsers(dirs.Authentication.Memory.Users) if err != nil { return nil, err } return &controller{ users: users, authenticator: authenticator, }, nil }
// New returns a new HTTPServer func New(conf *config.Config) (*Server, error) { directives := conf.GetDirectives() srv := &graceful.Server{ NoSignalHandling: true, Timeout: time.Duration(directives.Server.ShutdownTimeout) * time.Second, Server: &http.Server{ Addr: fmt.Sprintf(":%d", directives.Server.Port), }, } s := &Server{log: helpers.GetAppLogger(conf).WithField("module", "server"), srv: srv, conf: conf} if err := s.configureRouter(); err != nil { return nil, err } return s, nil }
// New returns an implementation of MetaDataController. func New(conf *config.Config) (metadatacontroller.MetaDataController, error) { dirs := conf.GetDirectives() c := &controller{ namespace: dirs.MetaData.Simple.Namespace, temporaryNamespace: dirs.MetaData.Simple.TemporaryNamespace, } if err := os.MkdirAll(dirs.MetaData.Simple.Namespace, 0755); err != nil { return nil, err } if err := os.MkdirAll(dirs.MetaData.Simple.TemporaryNamespace, 0755); err != nil { return nil, err } return c, nil }
func getServices(conf *config.Config) ([]services.Service, error) { enabledServices := conf.GetDirectives().Server.EnabledServices services := []services.Service{} if isServiceEnabled("authentication", enabledServices) { authenticationService, err := authentication.New(conf) if err != nil { return services, err } services = append(services, authenticationService) } if isServiceEnabled("metadata", enabledServices) { metaDataService, err := metadata.New(conf) if err != nil { return services, err } services = append(services, metaDataService) } if isServiceEnabled("data", enabledServices) { dataService, err := data.New(conf) if err != nil { return services, err } services = append(services, dataService) } if isServiceEnabled("webdav", enabledServices) { webDAVService, err := webdav.New(conf) if err != nil { return services, err } services = append(services, webDAVService) } if isServiceEnabled("ocwebdav", enabledServices) { OCWebDAVService, err := ocwebdav.New(conf) if err != nil { return services, err } services = append(services, OCWebDAVService) } return services, nil }
// New returns an AuthenticationControler that uses a SQL database for handling // users and JWT for tokens. func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) { dirs := conf.GetDirectives() authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod) db, err := gorm.Open(dirs.Authentication.SQL.Driver, dirs.Authentication.SQL.DSN) if err != nil { return nil, err } err = db.AutoMigrate(&userRecord{}).Error if err != nil { return nil, err } return &controller{ conf: conf, db: db, authenticator: authenticator, }, nil }
// New returns an implementation of MetaDataController. func New(conf *config.Config) (metadatacontroller.MetaDataController, error) { dirs := conf.GetDirectives() c := &Controller{ namespace: dirs.MetaData.OCSQL.Namespace, temporaryNamespace: dirs.MetaData.OCSQL.TemporaryNamespace, log: helpers.GetAppLogger(conf).WithField("module", "metadata:controller:ocsql"), conf: conf, } if err := os.MkdirAll(dirs.MetaData.OCSQL.Namespace, 0755); err != nil { return nil, err } if err := os.MkdirAll(dirs.MetaData.OCSQL.TemporaryNamespace, 0755); err != nil { return nil, err } db, err := gorm.Open("mysql", dirs.MetaData.OCSQL.DSN) if err != nil { c.log.Error(err) return nil, err } if dirs.MetaData.OCSQL.SQLLogEnabled { sqlLog := helpers.NewLogger("info", dirs.MetaData.OCSQL.SQLLog, dirs.MetaData.OCSQL.SQLLogMaxSize, dirs.MetaData.OCSQL.SQLLogMaxAge, dirs.MetaData.OCSQL.SQLLogMaxBackups) db.SetLogger(sqlLog) db.LogMode(true) } db.DB().SetMaxIdleConns(conf.GetDirectives().MetaData.OCSQL.MaxSQLIdleConnections) db.DB().SetMaxOpenConns(conf.GetDirectives().MetaData.OCSQL.MaxSQLConcurrentConnections) err = db.AutoMigrate(&Record{}).Error if err != nil { return nil, err } c.db = db return c, nil }
// New returns a new Service. func New(cfg *config.Config) (services.Service, error) { dirs := cfg.GetDirectives() authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod) dataController, err := data.GetDataController(cfg) if err != nil { return nil, err } authenticationController, err := authentication.GetAuthenticationController(cfg) if err != nil { return nil, err } metaDataController, err := metadata.GetMetaDataController(cfg) if err != nil { return nil, err } return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil }
// GetHTTPAccessLogger returns an already configured log for logging out HTTP requests. func GetHTTPAccessLogger(conf *config.Config) *logrus.Entry { dirs := conf.GetDirectives() return NewLogger(dirs.Server.HTTPAccessLogLevel, dirs.Server.HTTPAccessLog, dirs.Server.HTTPAccessLogMaxSize, dirs.Server.HTTPAccessLogMaxAge, dirs.Server.HTTPAccessLogMaxBackups) }