File: main.go

package info (click to toggle)
golang-gopkg-goose.v1 0.0~git20170406.3228e4f-6
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,116 kB
  • sloc: python: 160; makefile: 3
file content (71 lines) | stat: -rw-r--r-- 1,629 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main

import (
	"fmt"
	"log"
	"net/http"
	"strings"

	"github.com/juju/gnuflag"

	"gopkg.in/goose.v1/testservices/identityservice"
)

type userInfo struct {
	user, secret string
}
type userValues struct {
	users []userInfo
}

func (uv *userValues) Set(s string) error {
	vals := strings.Split(s, ":")
	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())
	}
	mux := http.NewServeMux()
	p.SetupHTTP(mux)
	for _, u := range users.users {
		p.AddUser(u.user, u.secret, "tenant", "default")
	}
	log.Fatal(http.ListenAndServe(*serveAddr, mux))
}