2015-08-18 05:57:27 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-05-20 05:40:42 +05:30
|
|
|
"github.com/coreos/dex/client"
|
2016-05-12 22:23:01 +05:30
|
|
|
"github.com/coreos/dex/client/manager"
|
2015-08-18 05:57:27 +05:30
|
|
|
"github.com/coreos/dex/connector"
|
|
|
|
"github.com/coreos/dex/db"
|
|
|
|
"github.com/coreos/go-oidc/oidc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newDBDriver(dsn string) (driver, error) {
|
|
|
|
dbc, err := db.NewConnection(db.Config{DSN: dsn})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
drv := &dbDriver{
|
2016-05-12 22:23:01 +05:30
|
|
|
cfgRepo: db.NewConnectorConfigRepo(dbc),
|
|
|
|
ciManager: manager.NewClientManager(db.NewClientRepo(dbc), db.TransactionFactory(dbc), manager.ManagerOptions{}),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return drv, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type dbDriver struct {
|
2016-05-12 22:23:01 +05:30
|
|
|
ciManager *manager.ClientManager
|
|
|
|
cfgRepo *db.ConnectorConfigRepo
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
|
|
|
|
if err := meta.Valid(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-20 05:40:42 +05:30
|
|
|
cli := client.Client{
|
|
|
|
Metadata: meta,
|
|
|
|
}
|
|
|
|
return d.ciManager.New(cli)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) ConnectorConfigs() ([]connector.ConnectorConfig, error) {
|
|
|
|
return d.cfgRepo.All()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) SetConnectorConfigs(cfgs []connector.ConnectorConfig) error {
|
|
|
|
return d.cfgRepo.Set(cfgs)
|
|
|
|
}
|