77 "time"
88
99 "github.com/lightninglabs/lightning-terminal/litrpc"
10+ "github.com/lightningnetwork/lnd/macaroons"
1011 "github.com/urfave/cli"
1112)
1213
@@ -62,9 +63,18 @@ var addSessionCommand = cli.Command{
6263 Usage : "session type to be created which will " +
6364 "determine the permissions a user has when " +
6465 "connecting with the session. Options " +
65- "include readonly|admin" ,
66+ "include readonly|admin|custom " ,
6667 Value : "readonly" ,
6768 },
69+ cli.StringSliceFlag {
70+ Name : "uri" ,
71+ Usage : "A URI that should be included in the " +
72+ "macaroon of a custom session. Note that " +
73+ "this flat will only be used if the 'type' " +
74+ "flag is set to 'custom'. This flag can be " +
75+ "specified multiple times if multiple URI's " +
76+ "should be included" ,
77+ },
6878 },
6979}
7080
@@ -87,17 +97,26 @@ func addSession(ctx *cli.Context) error {
8797 return err
8898 }
8999
100+ var macPerms []* litrpc.MacaroonPermission
101+ for _ , uri := range ctx .StringSlice ("uri" ) {
102+ macPerms = append (macPerms , & litrpc.MacaroonPermission {
103+ Entity : macaroons .PermissionEntityCustomURI ,
104+ Action : uri ,
105+ })
106+ }
107+
90108 sessionLength := time .Second * time .Duration (ctx .Uint64 ("expiry" ))
91109 sessionExpiry := time .Now ().Add (sessionLength ).Unix ()
92110
93111 ctxb := context .Background ()
94112 resp , err := client .AddSession (
95113 ctxb , & litrpc.AddSessionRequest {
96- Label : label ,
97- SessionType : sessType ,
98- ExpiryTimestampSeconds : uint64 (sessionExpiry ),
99- MailboxServerAddr : ctx .String ("mailboxserveraddr" ),
100- DevServer : ctx .Bool ("devserver" ),
114+ Label : label ,
115+ SessionType : sessType ,
116+ ExpiryTimestampSeconds : uint64 (sessionExpiry ),
117+ MailboxServerAddr : ctx .String ("mailboxserveraddr" ),
118+ DevServer : ctx .Bool ("devserver" ),
119+ MacaroonCustomPermissions : macPerms ,
101120 },
102121 )
103122 if err != nil {
@@ -115,6 +134,8 @@ func parseSessionType(sessionType string) (litrpc.SessionType, error) {
115134 return litrpc .SessionType_TYPE_MACAROON_ADMIN , nil
116135 case "readonly" :
117136 return litrpc .SessionType_TYPE_MACAROON_READONLY , nil
137+ case "custom" :
138+ return litrpc .SessionType_TYPE_MACAROON_CUSTOM , nil
118139 default :
119140 return 0 , fmt .Errorf ("unsupported session type %s" , sessionType )
120141 }
0 commit comments