Commit 8551e97a authored by ale's avatar ale
Browse files

Simplify Service constructors

Re-use the same base *web.Service object for all services, reduces the
need to pass around irrelevant parameters.
parent ebf4bb3b
Pipeline #410 passed with stages
in 1 minute and 17 seconds
......@@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"html/template"
"net/http"
"regexp"
"strings"
......@@ -13,7 +12,6 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/ory/hydra/firewall"
hydra "github.com/ory/hydra/sdk"
......@@ -32,9 +30,9 @@ type Service struct {
}
// NewService returns a new Service.
func NewService(db idp.Database, tpl *template.Template, store sessions.Store, hc *hydra.Client, mailer idp.Mailer, actionMgr *idp.ActionManager, publicURL string, insecureCookies bool) *Service {
func NewService(base *web.Service, hc *hydra.Client, actionMgr *idp.ActionManager, publicURL string) *Service {
return &Service{
Service: web.NewService(db, tpl, store, mailer, insecureCookies),
Service: base,
publicURL: publicURL,
actions: actionMgr,
hc: hc,
......
......@@ -11,6 +11,7 @@ import (
hydra "github.com/ory/hydra/sdk"
"git.autistici.org/ale/idp"
"git.autistici.org/ale/idp/web"
"git.autistici.org/ale/idp/web/admin"
"git.autistici.org/ale/idp/web/consent"
"git.autistici.org/ale/idp/web/login"
......@@ -51,10 +52,12 @@ func NewApp(hc *hydra.Client, config *Config) (*App, error) {
actionMgr := idp.NewActionManager(config.ActionAuthKey, config.ActionEncKey)
publicURL := strings.TrimRight(config.PublicURL, "/")
loginSrv := login.NewService(config.Database, config.Template, store, mailer, publicURL, config.InsecureCookies)
acct := mgmt.NewService(config.Database, config.Template, store, mailer, actionMgr, config.InsecureCookies)
admin := admin.NewService(config.Database, config.Template, store, hc, mailer, actionMgr, publicURL, config.InsecureCookies)
idpSrv, err := consent.NewService(config.Database, config.Template, store, hc, mailer, config.InsecureCookies)
svcBase := web.NewService(config.Database, config.Template, store, mailer, config.InsecureCookies)
loginSrv := login.NewService(svcBase, publicURL, config.InsecureCookies)
acct := mgmt.NewService(svcBase, actionMgr)
admin := admin.NewService(svcBase, hc, actionMgr, publicURL)
idpSrv, err := consent.NewService(svcBase, store, hc, config.InsecureCookies)
if err != nil {
return nil, err
}
......
package consent
import (
"html/template"
"net/http"
"time"
......@@ -28,9 +27,9 @@ type Service struct {
}
// NewService returns a new Service.
func NewService(db idp.Database, tpl *template.Template, store sessions.Store, hc *hydra.Client, mailer idp.Mailer, insecureCookies bool) (*Service, error) {
func NewService(base *web.Service, store sessions.Store, hc *hydra.Client, insecureCookies bool) (*Service, error) {
s := &Service{
Service: web.NewService(db, tpl, store, mailer, insecureCookies),
Service: base,
provider: NewProvider(hc, &ProviderConfig{
KeyCacheExpiration: keyCacheExpirationTime,
ClientCacheExpiration: clientCacheExpirationTime,
......
......@@ -4,7 +4,6 @@ import (
"encoding/gob"
"encoding/json"
"errors"
"html/template"
"net/http"
"time"
......@@ -50,9 +49,9 @@ type Service struct {
}
// NewService returns a new Service.
func NewService(db idp.Database, tpl *template.Template, store sessions.Store, mailer idp.Mailer, publicURL string, insecureCookies bool) *Service {
func NewService(base *web.Service, publicURL string, insecureCookies bool) *Service {
return &Service{
Service: web.NewService(db, tpl, store, mailer, insecureCookies),
Service: base,
loginSessionOptions: &sessions.Options{
Path: "/auth/",
MaxAge: loginSessionTTL,
......
package mgmt
import (
"html/template"
"net/http"
log "github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"git.autistici.org/ale/idp"
"git.autistici.org/ale/idp/web"
......@@ -19,9 +17,9 @@ type Service struct {
}
// NewService creates a new account management web service.
func NewService(db idp.Database, tpl *template.Template, store sessions.Store, mailer idp.Mailer, actionMgr *idp.ActionManager, insecureCookies bool) *Service {
func NewService(base *web.Service, actionMgr *idp.ActionManager) *Service {
return &Service{
Service: web.NewService(db, tpl, store, mailer, insecureCookies),
Service: base,
actions: actionMgr,
}
}
......
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