cmd/route-cli: implement some token management commands
This commit is contained in:
parent
14fb7f723d
commit
e1ce5dfd53
|
@ -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})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue