cmd/route: interface with the backends api

This commit is contained in:
Cadey Ratio 2017-09-30 10:06:29 -07:00
parent db341f4c0d
commit ea931db0b2
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
1 changed files with 38 additions and 1 deletions

View File

@ -53,6 +53,15 @@ var (
generateKey = app.Command("generate-key", "generate SSL cert crypto key")
backends = app.Command("backend", "backend management")
backendList = backends.Command("list", "list connected backends")
backendListDomain = backendList.Flag("domain", "if set, match backends against this domain name").String()
backendListUser = backendList.Flag("user", "if set, match backends against this username").String()
backendKill = backends.Command("kill", "forcibly disconnect a given backend")
backendKillID = backendKill.Flag("id", "the ID of the backend to remove").Required().String()
routes = app.Command("route", "route management")
routesCreate = routes.Command("create", "create a new route")
@ -81,7 +90,7 @@ var (
tokenGenerateDatabasePath = tokenGenerate.Flag("db", "database file to add the root token to").Required().String()
tokenInspect = token.Command("inspect", "inspect a token")
tokenInspectID = tokenInspect.Arg("token-id", "token id").Required().String()
tokenInspectID = tokenInspect.Flag("token-id", "token id").Required().String()
tokenList = token.Command("list", "list all tokens belonging to you")
tokenListDeactivated = tokenList.Flag("deactivated", "list deactivated tokens?").Default("false").Bool()
@ -178,9 +187,11 @@ func main() {
rc := proto.NewRoutesClient(conn)
tc := proto.NewTokensClient(conn)
bc := proto.NewBackendsClient(conn)
_ = rc
_ = tc
_ = bc
switch cmdline {
case "route create":
@ -226,5 +237,31 @@ func main() {
if err != nil {
ln.Fatal(ln.F{"err": err, "action": "rc.Delete"})
}
case "backend list":
bkds, err := bc.List(context.Background(), &proto.BackendSelector{
Domain: *backendListDomain,
User: *backendListUser,
})
if err != nil {
ln.Fatal(ln.F{"err": err, "action": "list backends"})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Proto", "User", "Domain", "Failure Chance", "Host"})
for _, bknd := range bkds.Backends {
table.Append([]string{bknd.Id, bknd.Proto, bknd.User, bknd.Domain, fmt.Sprint(bknd.Phi), bknd.Host})
}
table.Render()
case "backend kill":
_, err := bc.Kill(context.Background(), &proto.BackendID{Id: *backendKillID})
if err != nil {
ln.Fatal(ln.F{"err": err, "action": "attempt to kill backend", "backend_id": *backendKillID})
}
fmt.Println("killed backend " + *backendKillID)
}
}