7
7
"time"
8
8
9
9
"github.com/lightninglabs/lightning-terminal/litrpc"
10
+ "github.com/lightningnetwork/lnd/macaroons"
10
11
"github.com/urfave/cli"
11
12
)
12
13
@@ -62,9 +63,18 @@ var addSessionCommand = cli.Command{
62
63
Usage : "session type to be created which will " +
63
64
"determine the permissions a user has when " +
64
65
"connecting with the session. Options " +
65
- "include readonly|admin" ,
66
+ "include readonly|admin|custom " ,
66
67
Value : "readonly" ,
67
68
},
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 flag will only be used if the 'type' " +
74
+ "flag is set to 'custom'. This flag can be " +
75
+ "specified multiple times if multiple URIs " +
76
+ "should be included" ,
77
+ },
68
78
},
69
79
}
70
80
@@ -87,17 +97,26 @@ func addSession(ctx *cli.Context) error {
87
97
return err
88
98
}
89
99
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
+
90
108
sessionLength := time .Second * time .Duration (ctx .Uint64 ("expiry" ))
91
109
sessionExpiry := time .Now ().Add (sessionLength ).Unix ()
92
110
93
111
ctxb := context .Background ()
94
112
resp , err := client .AddSession (
95
113
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 ,
101
120
},
102
121
)
103
122
if err != nil {
@@ -115,6 +134,8 @@ func parseSessionType(sessionType string) (litrpc.SessionType, error) {
115
134
return litrpc .SessionType_TYPE_MACAROON_ADMIN , nil
116
135
case "readonly" :
117
136
return litrpc .SessionType_TYPE_MACAROON_READONLY , nil
137
+ case "custom" :
138
+ return litrpc .SessionType_TYPE_MACAROON_CUSTOM , nil
118
139
default :
119
140
return 0 , fmt .Errorf ("unsupported session type %s" , sessionType )
120
141
}
0 commit comments