Skip to content

Commit 6e30eca

Browse files
committed
litcli+rpcserver: session registration with config
We add command line flags to litcli in order to be able to submit feature configurations when registering a session.
1 parent 1049de5 commit 6e30eca

File tree

6 files changed

+283
-196
lines changed

6 files changed

+283
-196
lines changed

cmd/litcli/autopilot.go

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"context"
55
"encoding/hex"
6+
"encoding/json"
7+
"fmt"
68
"strconv"
79
"strings"
810
"time"
@@ -39,8 +41,10 @@ var addAutopilotSessionCmd = cli.Command{
3941
ShortName: "a",
4042
Usage: "Initialize an Autopilot session.",
4143
Description: `
42-
Initialize an Autopilot session.
43-
`,
44+
Initialize an Autopilot session.
45+
46+
If set for any feature, configuration flags need to be repeated for each
47+
feature that is registered, corresponding to the order of features.`,
4448
Action: initAutopilotSession,
4549
Flags: []cli.Flag{
4650
labelFlag,
@@ -70,6 +74,15 @@ var addAutopilotSessionCmd = cli.Command{
7074
Usage: "The hex encoded group ID of the session " +
7175
"group to link this one to",
7276
},
77+
cli.StringSliceFlag{
78+
Name: "feature-config",
79+
Usage: `JSON-serialized configuration with the ` +
80+
`expected format: {"version":0,` +
81+
`"option1":"parameter1",` +
82+
`"option2":"parameter2",...}. An empty ` +
83+
`configuration is allowed with {} to use the ` +
84+
`default configuration`,
85+
},
7386
},
7487
}
7588

@@ -221,11 +234,36 @@ func initAutopilotSession(ctx *cli.Context) error {
221234
}
222235
}
223236

237+
features := ctx.StringSlice("feature")
238+
configs := ctx.StringSlice("feature-config")
239+
if len(configs) > 0 && len(features) != len(configs) {
240+
return fmt.Errorf("number of features (%v) and configurations "+
241+
"(%v) must match", len(features), len(configs))
242+
}
243+
224244
featureMap := make(map[string]*litrpc.FeatureConfig)
225-
for _, feature := range ctx.StringSlice("feature") {
245+
for i, feature := range ctx.StringSlice("feature") {
246+
var config []byte
247+
248+
// We allow empty configs, to signal the usage of the default
249+
// configuration when the session is registered.
250+
if len(configs) > 0 && configs[i] != "{}" {
251+
// We expect the config to be a JSON dictionary, so we
252+
// unmarshal it into a map to do a first validation.
253+
var configMap map[string]interface{}
254+
err := json.Unmarshal([]byte(configs[i]), &configMap)
255+
if err != nil {
256+
return fmt.Errorf("could not parse "+
257+
"configuration for feature %v: %v",
258+
feature, err)
259+
}
260+
261+
config = []byte(configs[i])
262+
}
263+
226264
featureMap[feature] = &litrpc.FeatureConfig{
227265
Rules: ruleMap,
228-
Config: nil,
266+
Config: config,
229267
}
230268
}
231269

litrpc/lit-autopilot.swagger.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@
592592
"type": "string",
593593
"format": "byte",
594594
"description": "The ID of the group of Session's that this Session is linked to. If this\nsession is not linked to any older Session, then this value will be the\nsame as the ID."
595+
},
596+
"feature_configs": {
597+
"type": "object",
598+
"additionalProperties": {
599+
"type": "string"
600+
},
601+
"description": "Configurations for each individual feature mapping from the feature name to\na JSON-serialized configuration."
595602
}
596603
}
597604
},

0 commit comments

Comments
 (0)