Skip to content

Commit 143876d

Browse files
committed
litcli: prepare for a client connection without a macaroon
In preparation for an upcoming commit where litcli commands for the Status server are added, the `getClientConn` method is updated with a `noMac` parameter. If true, them the connection will be made without a macaroon.
1 parent 6310eed commit 143876d

File tree

7 files changed

+33
-29
lines changed

7 files changed

+33
-29
lines changed

cmd/litcli/accounts.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var createAccountCommand = cli.Command{
7878

7979
func createAccount(ctx *cli.Context) error {
8080
ctxb := context.Background()
81-
clientConn, cleanup, err := connectClient(ctx)
81+
clientConn, cleanup, err := connectClient(ctx, false)
8282
if err != nil {
8383
return err
8484
}
@@ -185,7 +185,7 @@ var updateAccountCommand = cli.Command{
185185

186186
func updateAccount(ctx *cli.Context) error {
187187
ctxb := context.Background()
188-
clientConn, cleanup, err := connectClient(ctx)
188+
clientConn, cleanup, err := connectClient(ctx, false)
189189
if err != nil {
190190
return err
191191
}
@@ -253,7 +253,7 @@ var listAccountsCommand = cli.Command{
253253

254254
func listAccounts(ctx *cli.Context) error {
255255
ctxb := context.Background()
256-
clientConn, cleanup, err := connectClient(ctx)
256+
clientConn, cleanup, err := connectClient(ctx, false)
257257
if err != nil {
258258
return err
259259
}
@@ -293,7 +293,7 @@ var accountInfoCommand = cli.Command{
293293

294294
func accountInfo(ctx *cli.Context) error {
295295
ctxb := context.Background()
296-
clientConn, cleanup, err := connectClient(ctx)
296+
clientConn, cleanup, err := connectClient(ctx, false)
297297
if err != nil {
298298
return err
299299
}
@@ -341,7 +341,7 @@ var removeAccountCommand = cli.Command{
341341

342342
func removeAccount(ctx *cli.Context) error {
343343
ctxb := context.Background()
344-
clientConn, cleanup, err := connectClient(ctx)
344+
clientConn, cleanup, err := connectClient(ctx, false)
345345
if err != nil {
346346
return err
347347
}

cmd/litcli/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ var listActionsCommand = cli.Command{
9999

100100
func listActions(ctx *cli.Context) error {
101101
ctxb := context.Background()
102-
clientConn, cleanup, err := connectClient(ctx)
102+
clientConn, cleanup, err := connectClient(ctx, false)
103103
if err != nil {
104104
return err
105105
}

cmd/litcli/autopilot.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ var listAutopilotSessionsCmd = cli.Command{
116116

117117
func revokeAutopilotSession(ctx *cli.Context) error {
118118
ctxb := context.Background()
119-
clientConn, cleanup, err := connectClient(ctx)
119+
clientConn, cleanup, err := connectClient(ctx, false)
120120
if err != nil {
121121
return err
122122
}
@@ -144,7 +144,7 @@ func revokeAutopilotSession(ctx *cli.Context) error {
144144

145145
func listAutopilotSessions(ctx *cli.Context) error {
146146
ctxb := context.Background()
147-
clientConn, cleanup, err := connectClient(ctx)
147+
clientConn, cleanup, err := connectClient(ctx, false)
148148
if err != nil {
149149
return err
150150
}
@@ -165,7 +165,7 @@ func listAutopilotSessions(ctx *cli.Context) error {
165165

166166
func listFeatures(ctx *cli.Context) error {
167167
ctxb := context.Background()
168-
clientConn, cleanup, err := connectClient(ctx)
168+
clientConn, cleanup, err := connectClient(ctx, false)
169169
if err != nil {
170170
return err
171171
}
@@ -189,7 +189,7 @@ func initAutopilotSession(ctx *cli.Context) error {
189189
sessionExpiry := time.Now().Add(sessionLength).Unix()
190190

191191
ctxb := context.Background()
192-
clientConn, cleanup, err := connectClient(ctx)
192+
clientConn, cleanup, err := connectClient(ctx, false)
193193
if err != nil {
194194
return err
195195
}

cmd/litcli/main.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ func fatal(err error) {
8989
os.Exit(1)
9090
}
9191

92-
func connectClient(ctx *cli.Context) (grpc.ClientConnInterface, func(), error) {
92+
func connectClient(ctx *cli.Context, noMac bool) (grpc.ClientConnInterface,
93+
func(), error) {
94+
9395
rpcServer := ctx.GlobalString("rpcserver")
9496
tlsCertPath, macPath, err := extractPathArgs(ctx)
9597
if err != nil {
9698
return nil, nil, err
9799
}
98-
conn, err := getClientConn(rpcServer, tlsCertPath, macPath)
100+
conn, err := getClientConn(rpcServer, tlsCertPath, macPath, noMac)
99101
if err != nil {
100102
return nil, nil, err
101103
}
@@ -104,18 +106,20 @@ func connectClient(ctx *cli.Context) (grpc.ClientConnInterface, func(), error) {
104106
return conn, cleanup, nil
105107
}
106108

107-
func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn,
108-
error) {
109-
110-
// We always need to send a macaroon.
111-
macOption, err := readMacaroon(macaroonPath)
112-
if err != nil {
113-
return nil, err
114-
}
109+
func getClientConn(address, tlsCertPath, macaroonPath string, noMac bool) (
110+
*grpc.ClientConn, error) {
115111

116112
opts := []grpc.DialOption{
117113
grpc.WithDefaultCallOptions(maxMsgRecvSize),
118-
macOption,
114+
}
115+
116+
if !noMac {
117+
macOption, err := readMacaroon(macaroonPath)
118+
if err != nil {
119+
return nil, err
120+
}
121+
122+
opts = append(opts, macOption)
119123
}
120124

121125
// TLS cannot be disabled, we'll always have a cert file to read.

cmd/litcli/privacy_map.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var privacyMapConvertStrCommand = cli.Command{
5858

5959
func privacyMapConvertStr(ctx *cli.Context) error {
6060
ctxb := context.Background()
61-
clientConn, cleanup, err := connectClient(ctx)
61+
clientConn, cleanup, err := connectClient(ctx, false)
6262
if err != nil {
6363
return err
6464
}
@@ -112,7 +112,7 @@ var privacyMapConvertUint64Command = cli.Command{
112112

113113
func privacyMapConvertUint64(ctx *cli.Context) error {
114114
ctxb := context.Background()
115-
clientConn, cleanup, err := connectClient(ctx)
115+
clientConn, cleanup, err := connectClient(ctx, false)
116116
if err != nil {
117117
return err
118118
}

cmd/litcli/proxy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var litCommands = []cli.Command{
5353
}
5454

5555
func getInfo(ctx *cli.Context) error {
56-
clientConn, cleanup, err := connectClient(ctx)
56+
clientConn, cleanup, err := connectClient(ctx, false)
5757
if err != nil {
5858
return err
5959
}
@@ -72,7 +72,7 @@ func getInfo(ctx *cli.Context) error {
7272
}
7373

7474
func shutdownLit(ctx *cli.Context) error {
75-
clientConn, cleanup, err := connectClient(ctx)
75+
clientConn, cleanup, err := connectClient(ctx, false)
7676
if err != nil {
7777
return err
7878
}
@@ -109,7 +109,7 @@ func bakeSuperMacaroon(ctx *cli.Context) error {
109109
}
110110
suffix := binary.BigEndian.Uint32(suffixBytes[:])
111111

112-
clientConn, cleanup, err := connectClient(ctx)
112+
clientConn, cleanup, err := connectClient(ctx, false)
113113
if err != nil {
114114
return err
115115
}

cmd/litcli/sessions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ var addSessionCommand = cli.Command{
9696
}
9797

9898
func addSession(ctx *cli.Context) error {
99-
clientConn, cleanup, err := connectClient(ctx)
99+
clientConn, cleanup, err := connectClient(ctx, false)
100100
if err != nil {
101101
return err
102102
}
@@ -229,7 +229,7 @@ var sessionStateMap = map[litrpc.SessionState]sessionFilter{
229229

230230
func listSessions(filter sessionFilter) func(ctx *cli.Context) error {
231231
return func(ctx *cli.Context) error {
232-
clientConn, cleanup, err := connectClient(ctx)
232+
clientConn, cleanup, err := connectClient(ctx, false)
233233
if err != nil {
234234
return err
235235
}
@@ -279,7 +279,7 @@ var revokeSessionCommand = cli.Command{
279279
}
280280

281281
func revokeSession(ctx *cli.Context) error {
282-
clientConn, cleanup, err := connectClient(ctx)
282+
clientConn, cleanup, err := connectClient(ctx, false)
283283
if err != nil {
284284
return err
285285
}

0 commit comments

Comments
 (0)