@@ -4,9 +4,11 @@ import (
44 "context"
55 "encoding/hex"
66 "fmt"
7+ "strings"
78 "time"
89
910 "github.com/lightninglabs/lightning-terminal/litrpc"
11+ "github.com/lightningnetwork/lnd/macaroons"
1012 "github.com/urfave/cli"
1113)
1214
@@ -62,9 +64,18 @@ var addSessionCommand = cli.Command{
6264 Usage : "session type to be created which will " +
6365 "determine the permissions a user has when " +
6466 "connecting with the session. Options " +
65- "include readonly|admin" ,
67+ "include readonly|admin|custom " ,
6668 Value : "readonly" ,
6769 },
70+ cli.StringFlag {
71+ Name : "uri_list" ,
72+ Usage : "A list of URIs that should be included in " +
73+ "the macaroon of a custom session. Note that " +
74+ "this list will only be used if the 'type' " +
75+ "flag is set to 'custom'. If multiple URIs " +
76+ "are specified, they should be separated by " +
77+ "commas (eg. 'uri1,uri2,uri3')" ,
78+ },
6879 },
6980}
7081
@@ -87,17 +98,29 @@ func addSession(ctx *cli.Context) error {
8798 return err
8899 }
89100
101+ var macPerms []* litrpc.MacaroonPermission
102+ if ctx .IsSet ("uri_list" ) {
103+ uriList := strings .Split (ctx .String ("uri_list" ), "," )
104+ for _ , uri := range uriList {
105+ macPerms = append (macPerms , & litrpc.MacaroonPermission {
106+ Entity : macaroons .PermissionEntityCustomURI ,
107+ Action : uri ,
108+ })
109+ }
110+ }
111+
90112 sessionLength := time .Second * time .Duration (ctx .Uint64 ("expiry" ))
91113 sessionExpiry := time .Now ().Add (sessionLength ).Unix ()
92114
93115 ctxb := context .Background ()
94116 resp , err := client .AddSession (
95117 ctxb , & litrpc.AddSessionRequest {
96- Label : label ,
97- SessionType : sessType ,
98- ExpiryTimestampSeconds : uint64 (sessionExpiry ),
99- MailboxServerAddr : ctx .String ("mailboxserveraddr" ),
100- DevServer : ctx .Bool ("devserver" ),
118+ Label : label ,
119+ SessionType : sessType ,
120+ ExpiryTimestampSeconds : uint64 (sessionExpiry ),
121+ MailboxServerAddr : ctx .String ("mailboxserveraddr" ),
122+ DevServer : ctx .Bool ("devserver" ),
123+ MacaroonCustomPermissions : macPerms ,
101124 },
102125 )
103126 if err != nil {
@@ -115,6 +138,8 @@ func parseSessionType(sessionType string) (litrpc.SessionType, error) {
115138 return litrpc .SessionType_TYPE_MACAROON_ADMIN , nil
116139 case "readonly" :
117140 return litrpc .SessionType_TYPE_MACAROON_READONLY , nil
141+ case "custom" :
142+ return litrpc .SessionType_TYPE_MACAROON_CUSTOM , nil
118143 default :
119144 return 0 , fmt .Errorf ("unsupported session type %s" , sessionType )
120145 }
0 commit comments