2016-07-26 01:30:28 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/coreos/poke/connector"
|
|
|
|
"github.com/coreos/poke/connector/github"
|
|
|
|
"github.com/coreos/poke/connector/ldap"
|
|
|
|
"github.com/coreos/poke/connector/mock"
|
2016-08-09 00:15:17 +05:30
|
|
|
"github.com/coreos/poke/connector/oidc"
|
2016-07-26 01:30:28 +05:30
|
|
|
"github.com/coreos/poke/storage"
|
|
|
|
"github.com/coreos/poke/storage/kubernetes"
|
2016-08-05 22:20:22 +05:30
|
|
|
"github.com/coreos/poke/storage/memory"
|
2016-07-26 01:30:28 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
// Config is the config format for the main application.
|
|
|
|
type Config struct {
|
|
|
|
Issuer string `yaml:"issuer"`
|
|
|
|
Storage Storage `yaml:"storage"`
|
|
|
|
Connectors []Connector `yaml:"connectors"`
|
|
|
|
Web Web `yaml:"web"`
|
2016-08-05 22:20:22 +05:30
|
|
|
|
|
|
|
StaticClients []storage.Client `yaml:"staticClients"`
|
2016-07-26 01:30:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Web is the config format for the HTTP server.
|
|
|
|
type Web struct {
|
|
|
|
HTTP string `yaml:"http"`
|
|
|
|
HTTPS string `yaml:"https"`
|
|
|
|
TLSCert string `yaml:"tlsCert"`
|
|
|
|
TLSKey string `yaml:"tlsKey"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Storage holds app's storage configuration.
|
|
|
|
type Storage struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Config StorageConfig `yaml:"config"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML allows Storage to unmarshal its config field dynamically
|
|
|
|
// depending on the type of storage.
|
|
|
|
func (s *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var storageMeta struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
}
|
|
|
|
if err := unmarshal(&storageMeta); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
s.Type = storageMeta.Type
|
2016-08-05 22:20:22 +05:30
|
|
|
// TODO(ericchiang): replace this with a registration process.
|
2016-08-11 06:20:55 +05:30
|
|
|
var err error
|
2016-07-26 01:30:28 +05:30
|
|
|
switch storageMeta.Type {
|
|
|
|
case "kubernetes":
|
2016-08-11 06:20:55 +05:30
|
|
|
var config struct {
|
|
|
|
Config kubernetes.Config `yaml:"config"`
|
|
|
|
}
|
|
|
|
err = unmarshal(&config)
|
|
|
|
s.Config = &config.Config
|
2016-08-05 22:20:22 +05:30
|
|
|
case "memory":
|
2016-08-11 06:20:55 +05:30
|
|
|
var config struct {
|
|
|
|
Config memory.Config `yaml:"config"`
|
|
|
|
}
|
|
|
|
err = unmarshal(&config)
|
|
|
|
s.Config = &config.Config
|
2016-07-26 01:30:28 +05:30
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown storage type %q", storageMeta.Type)
|
|
|
|
}
|
2016-08-11 06:20:55 +05:30
|
|
|
return err
|
2016-07-26 01:30:28 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// StorageConfig is a configuration that can create a storage.
|
|
|
|
type StorageConfig interface {
|
|
|
|
Open() (storage.Storage, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connector is a magical type that can unmarshal YAML dynamically. The
|
|
|
|
// Type field determines the connector type, which is then customized for Config.
|
|
|
|
type Connector struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
ID string `yaml:"id"`
|
|
|
|
|
|
|
|
Config ConnectorConfig `yaml:"config"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConnectorConfig is a configuration that can open a connector.
|
|
|
|
type ConnectorConfig interface {
|
|
|
|
Open() (connector.Connector, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalYAML allows Connector to unmarshal its config field dynamically
|
|
|
|
// depending on the type of connector.
|
|
|
|
func (c *Connector) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
|
|
var connectorMetadata struct {
|
|
|
|
Type string `yaml:"type"`
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
ID string `yaml:"id"`
|
|
|
|
}
|
|
|
|
if err := unmarshal(&connectorMetadata); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.Type = connectorMetadata.Type
|
|
|
|
c.Name = connectorMetadata.Name
|
|
|
|
c.ID = connectorMetadata.ID
|
|
|
|
|
2016-08-09 00:15:17 +05:30
|
|
|
var err error
|
2016-07-26 01:30:28 +05:30
|
|
|
switch c.Type {
|
|
|
|
case "mock":
|
|
|
|
var config struct {
|
|
|
|
Config mock.Config `yaml:"config"`
|
|
|
|
}
|
2016-08-09 00:15:17 +05:30
|
|
|
err = unmarshal(&config)
|
2016-07-26 01:30:28 +05:30
|
|
|
c.Config = &config.Config
|
|
|
|
case "ldap":
|
|
|
|
var config struct {
|
|
|
|
Config ldap.Config `yaml:"config"`
|
|
|
|
}
|
2016-08-09 00:15:17 +05:30
|
|
|
err = unmarshal(&config)
|
2016-07-26 01:30:28 +05:30
|
|
|
c.Config = &config.Config
|
|
|
|
case "github":
|
|
|
|
var config struct {
|
|
|
|
Config github.Config `yaml:"config"`
|
|
|
|
}
|
2016-08-09 00:15:17 +05:30
|
|
|
err = unmarshal(&config)
|
|
|
|
c.Config = &config.Config
|
|
|
|
case "oidc":
|
|
|
|
var config struct {
|
|
|
|
Config oidc.Config `yaml:"config"`
|
2016-07-26 01:30:28 +05:30
|
|
|
}
|
2016-08-09 00:15:17 +05:30
|
|
|
err = unmarshal(&config)
|
2016-07-26 01:30:28 +05:30
|
|
|
c.Config = &config.Config
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown connector type %q", c.Type)
|
|
|
|
}
|
2016-08-09 00:15:17 +05:30
|
|
|
return err
|
2016-07-26 01:30:28 +05:30
|
|
|
}
|