cmd/route-cli: implement some token management commands

This commit is contained in:
Cadey Ratio 2017-10-01 07:37:47 -07:00
parent 14fb7f723d
commit e1ce5dfd53
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
1 changed files with 46 additions and 0 deletions

View File

@ -148,6 +148,8 @@ retry_netrc:
ln.FatalErr(ctx, http.ListenAndServe(*testServerAddr, nil), ln.Action("test server listenAndServe"))
return
case "generate-key":
key, err := routecrypto.GenerateKey()
if err != nil {
@ -155,6 +157,9 @@ retry_netrc:
}
fmt.Println("Your key is:", routecrypto.ShowKey(key))
return
case "token generate-root":
key, err := routecrypto.ParseKey(*tokenGenerateKey)
if err != nil {
@ -252,6 +257,8 @@ retry_netrc:
ln.FatalErr(ctx, err, ln.Action("remove single route"), ln.F{"id": *routesRmID})
}
return
case "backend list":
bkds, err := bc.List(context.Background(), &proto.BackendSelector{
Domain: *backendListDomain,
@ -270,6 +277,8 @@ retry_netrc:
table.Render()
return
case "backend kill":
_, err := bc.Kill(context.Background(), &proto.BackendID{Id: *backendKillID})
if err != nil {
@ -277,5 +286,42 @@ retry_netrc:
}
fmt.Println("killed backend " + *backendKillID)
return
case "token list":
lis, err := tc.GetAll(ctx, &proto.Nil{})
if err != nil {
ln.FatalErr(ctx, err, ln.Action("get all tokens"))
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Active", "Scopes"})
for _, tkn := range lis.Tokens {
table.Append([]string{tkn.Id, fmt.Sprint(tkn.Active), fmt.Sprint(tkn.Scopes)})
}
table.Render()
return
case "token create":
scps := *tokenCreateScopes
tkn := &proto.Token{
Scopes: scps,
}
ftkn, err := tc.Put(ctx, tkn)
if err != nil {
ln.FatalErr(ctx, err, ln.Action("put token to server"))
}
fmt.Printf("Your token is: %s\n", ftkn.Body)
fmt.Printf("It has permission for the following scopes: %v\n", ftkn.Scopes)
return
}
ln.Fatal(ctx, ln.Action("not implemented"), ln.F{"command": cmdline})
}