This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/connector/config_repo.go
2016-01-19 08:59:34 -08:00

45 lines
967 B
Go

package connector
import (
"encoding/json"
"io"
"github.com/coreos/dex/repo"
)
func ReadConfigs(r io.Reader) ([]ConnectorConfig, error) {
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
}
func NewConnectorConfigRepoFromConfigs(cfgs []ConnectorConfig) ConnectorConfigRepo {
return &memConnectorConfigRepo{configs: cfgs}
}
func (r *memConnectorConfigRepo) All() ([]ConnectorConfig, error) {
return r.configs, nil
}
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
}