Index: testservices/main.go |
=== added file 'testservices/main.go' |
--- testservices/main.go 1970-01-01 00:00:00 +0000 |
+++ testservices/main.go 2012-11-11 11:13:52 +0000 |
@@ -0,0 +1,69 @@ |
+package main |
+ |
+import ( |
+ "fmt" |
+ "launchpad.net/gnuflag" |
+ "launchpad.net/goose/testservices/identityservice" |
+ "log" |
+ "net/http" |
+ "strings" |
+) |
+ |
+type userInfo struct { |
+ user, secret string |
+} |
rog
2012/11/26 12:51:38
func (uv userInfo) String() {
return fmt.Sprin
|
+type userValues struct { |
+ users []userInfo |
+} |
+ |
+func (uv *userValues) Set(s string) error { |
+ vals := strings.Split(s, ":") |
rog
2012/11/26 12:51:38
the secret can't contain a colon?
|
+ if len(vals) != 2 { |
+ return fmt.Errorf("Invalid --user option, should be: user:secret") |
+ } |
+ uv.users = append(uv.users, userInfo{ |
+ user: vals[0], |
+ secret: vals[1], |
+ }) |
+ return nil |
+} |
+func (uv *userValues) String() string { |
+ return fmt.Sprintf("%v", uv.users) |
+} |
+ |
+var provider = gnuflag.String("provider", "userpass", "provide the name of the identity service to run") |
+ |
+var serveAddr = gnuflag.String("addr", "localhost:8080", "serve the provider on the given address.") |
+ |
+var users userValues |
+ |
+func init() { |
+ |
+ gnuflag.Var(&users, "user", "supply to add a user to the identity provider. Can be supplied multiple times. Should be of the form \"user:secret:token\".") |
+} |
+ |
+var providerMap = map[string]identityservice.IdentityService{ |
+ "legacy": identityservice.NewLegacy(), |
+ "userpass": identityservice.NewUserPass(), |
+} |
+ |
+func providers() []string { |
+ out := make([]string, 0, len(providerMap)) |
+ for provider := range providerMap { |
+ out = append(out, provider) |
+ } |
+ return out |
+} |
+ |
+func main() { |
+ gnuflag.Parse(true) |
+ p, ok := providerMap[*provider] |
+ if !ok { |
+ log.Fatalf("No such provider: %s, pick one of: %v", provider, providers()) |
+ } |
+ http.Handle("/", p) |
+ for _, u := range users.users { |
+ p.AddUser(u.user, u.secret) |
+ } |
+ log.Fatal(http.ListenAndServe(*serveAddr, nil)) |
+} |