*: load static clients from config file

This commit is contained in:
Eric Chiang
2016-08-05 09:50:22 -07:00
parent 725a94214a
commit 53d1be4a87
7 changed files with 101 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/coreos/poke/connector/mock"
"github.com/coreos/poke/storage"
"github.com/coreos/poke/storage/kubernetes"
"github.com/coreos/poke/storage/memory"
)
// Config is the config format for the main application.
@@ -17,6 +18,8 @@ type Config struct {
Storage Storage `yaml:"storage"`
Connectors []Connector `yaml:"connectors"`
Web Web `yaml:"web"`
StaticClients []storage.Client `yaml:"staticClients"`
}
// Web is the config format for the HTTP server.
@@ -46,9 +49,12 @@ func (s *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error {
var c struct {
Config StorageConfig `yaml:"config"`
}
// TODO(ericchiang): replace this with a registration process.
switch storageMeta.Type {
case "kubernetes":
c.Config = &kubernetes.Config{}
case "memory":
c.Config = &memory.Config{}
default:
return fmt.Errorf("unknown storage type %q", storageMeta.Type)
}

39
cmd/poke/config_test.go Normal file
View File

@@ -0,0 +1,39 @@
package main
import (
"testing"
"github.com/coreos/poke/storage"
"github.com/kylelemons/godebug/pretty"
yaml "gopkg.in/yaml.v2"
)
func TestUnmarshalClients(t *testing.T) {
data := `staticClients:
- id: example-app
redirectURIs:
- 'http://127.0.0.1:5555/callback'
name: 'Example App'
secret: ZXhhbXBsZS1hcHAtc2VjcmV0
`
var c Config
if err := yaml.Unmarshal([]byte(data), &c); err != nil {
t.Fatal(err)
}
wantClients := []storage.Client{
{
ID: "example-app",
Name: "Example App",
Secret: "ZXhhbXBsZS1hcHAtc2VjcmV0",
RedirectURIs: []string{
"http://127.0.0.1:5555/callback",
},
},
}
if diff := pretty.Compare(wantClients, c.StaticClients); diff != "" {
t.Errorf("did not get expected clients: %s", diff)
}
}

View File

@@ -7,10 +7,11 @@ import (
"log"
"net/http"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
"github.com/coreos/poke/server"
"github.com/spf13/cobra"
"github.com/coreos/poke/storage"
)
func commandServe() *cobra.Command {
@@ -83,6 +84,9 @@ func serve(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("initializing storage: %v", err)
}
if len(c.StaticClients) > 0 {
s = storage.WithStaticClients(s, c.StaticClients)
}
serverConfig := server.Config{
Issuer: c.Issuer,