@@ -10,7 +10,8 @@ import (
1010 "github.com/urfave/cli"
1111)
1212
13- // wtclientCommands will return nil for non-wtclientrpc builds.
13+ // wtclientCommands is a list of commands that can be used to interact with the
14+ // watchtower client.
1415func wtclientCommands () []cli.Command {
1516 return []cli.Command {
1617 {
@@ -20,10 +21,12 @@ func wtclientCommands() []cli.Command {
2021 Subcommands : []cli.Command {
2122 addTowerCommand ,
2223 removeTowerCommand ,
24+ deactivateTowerCommand ,
2325 listTowersCommand ,
2426 getTowerCommand ,
2527 statsCommand ,
2628 policyCommand ,
29+ sessionCommands ,
2730 },
2831 },
2932 }
@@ -84,6 +87,44 @@ func addTower(ctx *cli.Context) error {
8487 return nil
8588}
8689
90+ var deactivateTowerCommand = cli.Command {
91+ Name : "deactivate" ,
92+ Usage : "Deactivate a watchtower to temporarily prevent its use for " +
93+ "sessions/backups." ,
94+ ArgsUsage : "pubkey" ,
95+ Action : actionDecorator (deactivateTower ),
96+ }
97+
98+ func deactivateTower (ctx * cli.Context ) error {
99+ ctxc := getContext ()
100+
101+ // Display the command's help message if the number of arguments/flags
102+ // is not what we expect.
103+ if ctx .NArg () != 1 || ctx .NumFlags () > 0 {
104+ return cli .ShowCommandHelp (ctx , "deactivate" )
105+ }
106+
107+ pubKey , err := hex .DecodeString (ctx .Args ().First ())
108+ if err != nil {
109+ return fmt .Errorf ("invalid public key: %w" , err )
110+ }
111+
112+ client , cleanUp := getWtclient (ctx )
113+ defer cleanUp ()
114+
115+ req := & wtclientrpc.DeactivateTowerRequest {
116+ Pubkey : pubKey ,
117+ }
118+ resp , err := client .DeactivateTower (ctxc , req )
119+ if err != nil {
120+ return err
121+ }
122+
123+ printRespJSON (resp )
124+
125+ return nil
126+ }
127+
87128var removeTowerCommand = cli.Command {
88129 Name : "remove" ,
89130 Usage : "Remove a watchtower to prevent its use for future " +
@@ -333,3 +374,47 @@ func policy(ctx *cli.Context) error {
333374 printRespJSON (resp )
334375 return nil
335376}
377+
378+ var sessionCommands = cli.Command {
379+ Name : "session" ,
380+ Subcommands : []cli.Command {
381+ terminateSessionCommand ,
382+ },
383+ }
384+
385+ var terminateSessionCommand = cli.Command {
386+ Name : "terminate" ,
387+ ArgsUsage : "id" ,
388+ Action : actionDecorator (terminateSession ),
389+ }
390+
391+ func terminateSession (ctx * cli.Context ) error {
392+ ctxc := getContext ()
393+
394+ // Display the command's help message if the number of arguments/flags
395+ // is not what we expect.
396+ if ctx .NArg () > 1 || ctx .NumFlags () != 0 {
397+ return cli .ShowCommandHelp (ctx , "terminate" )
398+ }
399+
400+ client , cleanUp := getWtclient (ctx )
401+ defer cleanUp ()
402+
403+ sessionID , err := hex .DecodeString (ctx .Args ().First ())
404+ if err != nil {
405+ return fmt .Errorf ("invalid session ID: %w" , err )
406+ }
407+
408+ resp , err := client .TerminateSession (
409+ ctxc , & wtclientrpc.TerminateSessionRequest {
410+ SessionId : sessionID ,
411+ },
412+ )
413+ if err != nil {
414+ return err
415+ }
416+
417+ printRespJSON (resp )
418+
419+ return nil
420+ }
0 commit comments