lncli: add policy type flags to wtclient policy

This commit is contained in:
Conner Fromknecht 2020-11-25 15:31:19 -08:00
parent b28bbc3223
commit f3c8311b28
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -250,19 +250,44 @@ var policyCommand = cli.Command{
Name: "policy", Name: "policy",
Usage: "Display the active watchtower client policy configuration.", Usage: "Display the active watchtower client policy configuration.",
Action: actionDecorator(policy), Action: actionDecorator(policy),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "legacy",
Usage: "Retrieve the legacy tower client's current " +
"policy. (default)",
},
cli.BoolFlag{
Name: "anchor",
Usage: "Retrieve the anchor tower client's current policy.",
},
},
} }
func policy(ctx *cli.Context) error { func policy(ctx *cli.Context) error {
// Display the command's help message if the number of arguments/flags // Display the command's help message if the number of arguments/flags
// is not what we expect. // is not what we expect.
if ctx.NArg() > 0 || ctx.NumFlags() > 0 { if ctx.NArg() > 0 || ctx.NumFlags() > 1 {
return cli.ShowCommandHelp(ctx, "policy") return cli.ShowCommandHelp(ctx, "policy")
} }
var policyType wtclientrpc.PolicyType
switch {
case ctx.Bool("anchor"):
policyType = wtclientrpc.PolicyType_ANCHOR
case ctx.Bool("legacy"):
policyType = wtclientrpc.PolicyType_LEGACY
// For backwards compatibility with original rpc behavior.
default:
policyType = wtclientrpc.PolicyType_LEGACY
}
client, cleanUp := getWtclient(ctx) client, cleanUp := getWtclient(ctx)
defer cleanUp() defer cleanUp()
req := &wtclientrpc.PolicyRequest{} req := &wtclientrpc.PolicyRequest{
PolicyType: policyType,
}
resp, err := client.Policy(context.Background(), req) resp, err := client.Policy(context.Background(), req)
if err != nil { if err != nil {
return err return err