2015-08-18 05:57:27 +05:30
|
|
|
package connector
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2015-12-08 06:49:55 +05:30
|
|
|
|
|
|
|
"github.com/coreos/dex/repo"
|
2015-08-18 05:57:27 +05:30
|
|
|
)
|
|
|
|
|
2016-01-19 22:29:34 +05:30
|
|
|
func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
|
2015-08-18 05:57:27 +05:30
|
|
|
var ms []map[string]interface{}
|
|
|
|
if err := json.NewDecoder(r).Decode(&ms); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfgs := make([]ConnectorConfig, len(ms))
|
|
|
|
for i, m := range ms {
|
|
|
|
cfg, err := newConnectorConfigFromMap(m)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
cfgs[i] = cfg
|
|
|
|
}
|
|
|
|
return cfgs, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type memConnectorConfigRepo struct {
|
|
|
|
configs []ConnectorConfig
|
|
|
|
}
|
|
|
|
|
2015-12-08 06:49:55 +05:30
|
|
|
func NewConnectorConfigRepoFromConfigs(cfgs []ConnectorConfig) ConnectorConfigRepo {
|
|
|
|
return &memConnectorConfigRepo{configs: cfgs}
|
|
|
|
}
|
|
|
|
|
2015-08-18 05:57:27 +05:30
|
|
|
func (r *memConnectorConfigRepo) All() ([]ConnectorConfig, error) {
|
|
|
|
return r.configs, nil
|
|
|
|
}
|
2015-12-08 06:49:55 +05:30
|
|
|
|
|
|
|
func (r *memConnectorConfigRepo) GetConnectorByID(_ repo.Transaction, id string) (ConnectorConfig, error) {
|
|
|
|
for _, cfg := range r.configs {
|
|
|
|
if cfg.ConnectorID() == id {
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, ErrorNotFound
|
|
|
|
}
|