Commit bcc483e2 authored by ale's avatar ale
Browse files

Reduce complexity of the run() function

parent c06fa1a7
......@@ -145,28 +145,29 @@ func (c *serverCommand) checkArgs() error {
return nil
}
func (c *serverCommand) run(ctx context.Context) error {
var database idp.Database
func (c *serverCommand) openDB() (idp.Database, error) {
switch c.backendType {
case "etcd":
var err error
opts := &etcd.Options{
return etcd.NewDB(&etcd.Options{
Endpoints: strings.Split(c.etcdURLs, ","),
CertFile: c.etcdSSLCert,
KeyFile: c.etcdSSLKey,
CAFile: c.etcdSSLCA,
SRV: c.etcdSRV,
}
database, err = etcd.NewDB(opts)
if err != nil {
return err
}
})
case "memory":
database = inmemory.NewDB(defaultTestData)
return inmemory.NewDB(defaultTestData), nil
default:
return fmt.Errorf("Unknown database backend '%s'", c.backendType)
return nil, fmt.Errorf("Unknown database backend '%s'", c.backendType)
}
}
func (c *serverCommand) run(ctx context.Context) error {
database, err := c.openDB()
if err != nil {
return err
}
hc, err := hydra.Connect(
......@@ -183,8 +184,7 @@ func (c *serverCommand) run(ctx context.Context) error {
var rlConfig []byte
if c.ratelimitConfigFile != "" {
data, err := ioutil.ReadFile(c.ratelimitConfigFile)
if err != nil {
if data, err := ioutil.ReadFile(c.ratelimitConfigFile); err != nil {
log.Warn("could not read ratelimit config: %v", err)
} else {
rlConfig = data
......@@ -209,6 +209,10 @@ func (c *serverCommand) run(ctx context.Context) error {
return err
}
return c.runServer(app)
}
func (c *serverCommand) runServer(app *idpapp.App) error {
csrfWrapper := csrf.Protect(securecookie.GenerateRandomKey(32), csrf.Secure(false))
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment