Skip to content

Commit 3b5d990

Browse files
committed
cmd/litcli: add session type flag to litcli
Add flag to litcli so that we can create sessions of the admin or readonly macaroon type through the cli. This commit also results in it no longer being possible to create a UIPassword session through the CLI.
1 parent 725f726 commit 3b5d990

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

cmd/litcli/sessions.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ var addSessionCommand = cli.Command{
5050
Usage: "set to true to skip verification of the " +
5151
"server's tls cert.",
5252
},
53+
cli.StringFlag{
54+
Name: "type",
55+
Usage: "session type to be created which will " +
56+
"determine the permissions a user has when " +
57+
"connecting with the session. Options " +
58+
"include readonly|admin",
59+
Value: "readonly",
60+
},
5361
},
5462
}
5563

@@ -65,13 +73,19 @@ func addSession(ctx *cli.Context) error {
6573
return fmt.Errorf("must set a label for the session")
6674
}
6775

76+
sessTypeStr := ctx.String("type")
77+
sessType, err := parseSessionType(sessTypeStr)
78+
if err != nil {
79+
return err
80+
}
81+
6882
sessionLength := time.Second * time.Duration(ctx.Uint64("expiry"))
6983
sessionExpiry := time.Now().Add(sessionLength).Unix()
7084

7185
resp, err := client.AddSession(
7286
getAuthContext(ctx), &litrpc.AddSessionRequest{
7387
Label: label,
74-
SessionType: litrpc.SessionType_TYPE_UI_PASSWORD,
88+
SessionType: sessType,
7589
ExpiryTimestampSeconds: uint64(sessionExpiry),
7690
MailboxServerAddr: ctx.String("mailboxserveraddr"),
7791
DevServer: ctx.Bool("devserver"),
@@ -86,6 +100,17 @@ func addSession(ctx *cli.Context) error {
86100
return nil
87101
}
88102

103+
func parseSessionType(sessionType string) (litrpc.SessionType, error) {
104+
switch sessionType {
105+
case "admin":
106+
return litrpc.SessionType_TYPE_MACAROON_ADMIN, nil
107+
case "readonly":
108+
return litrpc.SessionType_TYPE_MACAROON_READONLY, nil
109+
default:
110+
return 0, fmt.Errorf("unsupported session type %s", sessionType)
111+
}
112+
}
113+
89114
var listSessionCommand = cli.Command{
90115
Name: "list",
91116
ShortName: "l",

0 commit comments

Comments
 (0)