Skip to content

Commit 60c10bd

Browse files
committed
multi: use group ID for PrivacyMapConversion query
1 parent bd9a99c commit 60c10bd

File tree

5 files changed

+93
-26
lines changed

5 files changed

+93
-26
lines changed

cmd/litcli/privacy_map.go

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ var privacyMapCommands = cli.Command{
1818
Category: "Privacy",
1919
Flags: []cli.Flag{
2020
cli.StringFlag{
21-
Name: "session_id",
22-
Usage: "The id of the session in question",
23-
Required: true,
21+
Name: "session_id",
22+
Usage: "Deprecated, use group_id instead.",
23+
Hidden: true,
2424
},
2525
cli.BoolFlag{
2626
Name: "realtopseudo",
@@ -30,6 +30,11 @@ var privacyMapCommands = cli.Command{
3030
"as the pseudo value that should be " +
3131
"mapped to its real counterpart.",
3232
},
33+
cli.StringFlag{
34+
Name: "group_id",
35+
Usage: "The ID of the session group who's privacy " +
36+
"map DB should be queried.",
37+
},
3338
},
3439
Subcommands: []cli.Command{
3540
privacyMapConvertStrCommand,
@@ -60,16 +65,26 @@ func privacyMapConvertStr(ctx *cli.Context) error {
6065
defer cleanup()
6166
client := litrpc.NewFirewallClient(clientConn)
6267

63-
id, err := hex.DecodeString(ctx.GlobalString("session_id"))
64-
if err != nil {
65-
return err
68+
var groupID []byte
69+
if ctx.GlobalIsSet("group_id") {
70+
groupID, err = hex.DecodeString(ctx.GlobalString("group_id"))
71+
if err != nil {
72+
return err
73+
}
74+
} else if ctx.GlobalIsSet("session_id") {
75+
groupID, err = hex.DecodeString(ctx.GlobalString("session_id"))
76+
if err != nil {
77+
return err
78+
}
79+
} else {
80+
return fmt.Errorf("must set group_id")
6681
}
6782

6883
resp, err := client.PrivacyMapConversion(
6984
ctxb, &litrpc.PrivacyMapConversionRequest{
70-
SessionId: id,
7185
RealToPseudo: ctx.GlobalBool("realtopseudo"),
7286
Input: ctx.String("input"),
87+
GroupId: groupID,
7388
},
7489
)
7590
if err != nil {
@@ -104,18 +119,28 @@ func privacyMapConvertUint64(ctx *cli.Context) error {
104119
defer cleanup()
105120
client := litrpc.NewFirewallClient(clientConn)
106121

107-
id, err := hex.DecodeString(ctx.GlobalString("session_id"))
108-
if err != nil {
109-
return err
122+
var groupID []byte
123+
if ctx.GlobalIsSet("group_id") {
124+
groupID, err = hex.DecodeString(ctx.GlobalString("group_id"))
125+
if err != nil {
126+
return err
127+
}
128+
} else if ctx.GlobalIsSet("session_id") {
129+
groupID, err = hex.DecodeString(ctx.GlobalString("session_id"))
130+
if err != nil {
131+
return err
132+
}
133+
} else {
134+
return fmt.Errorf("must set group_id")
110135
}
111136

112137
input := firewalldb.Uint64ToStr(ctx.Uint64("input"))
113138

114139
resp, err := client.PrivacyMapConversion(
115140
ctxb, &litrpc.PrivacyMapConversionRequest{
116-
SessionId: id,
117141
RealToPseudo: ctx.GlobalBool("realtopseudo"),
118142
Input: input,
143+
GroupId: groupID,
119144
},
120145
)
121146
if err != nil {

litrpc/firewall.pb.go

Lines changed: 24 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litrpc/firewall.proto

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ message PrivacyMapConversionRequest {
3636
bool real_to_pseudo = 1;
3737

3838
/*
39+
Deprecated, use group_id.
3940
The session ID under which to search for the real-pseudo pair.
4041
*/
41-
bytes session_id = 2;
42+
bytes session_id = 2 [deprecated = true];
4243

4344
/*
4445
The input to be converted into the real or pseudo value.
4546
*/
4647
string input = 3;
48+
49+
/*
50+
The group ID under which to search for the real-pseudo pair.
51+
*/
52+
bytes group_id = 4;
4753
}
4854

4955
message PrivacyMapConversionResponse {

litrpc/firewall.swagger.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,16 @@
237237
"session_id": {
238238
"type": "string",
239239
"format": "byte",
240-
"description": "The session ID under which to search for the real-pseudo pair."
240+
"description": "Deprecated, use group_id.\nThe session ID under which to search for the real-pseudo pair."
241241
},
242242
"input": {
243243
"type": "string",
244244
"description": "The input to be converted into the real or pseudo value."
245+
},
246+
"group_id": {
247+
"type": "string",
248+
"format": "byte",
249+
"description": "The group ID under which to search for the real-pseudo pair."
245250
}
246251
}
247252
},

session_rpcserver.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,29 @@ func (s *sessionRpcServer) PrivacyMapConversion(_ context.Context,
592592
req *litrpc.PrivacyMapConversionRequest) (
593593
*litrpc.PrivacyMapConversionResponse, error) {
594594

595-
sessionID, err := session.IDFromBytes(req.SessionId)
596-
if err != nil {
597-
return nil, err
595+
var (
596+
groupID session.ID
597+
err error
598+
)
599+
if len(req.GroupId) != 0 {
600+
groupID, err = session.IDFromBytes(req.GroupId)
601+
if err != nil {
602+
return nil, err
603+
}
604+
} else {
605+
sessionID, err := session.IDFromBytes(req.SessionId)
606+
if err != nil {
607+
return nil, err
608+
}
609+
610+
groupID, err = s.cfg.db.GetGroupID(sessionID)
611+
if err != nil {
612+
return nil, err
613+
}
598614
}
599615

600616
var res string
601-
privMap := s.cfg.privMap(sessionID)
617+
privMap := s.cfg.privMap(groupID)
602618
err = privMap.View(func(tx firewalldb.PrivacyMapTx) error {
603619
var err error
604620
if req.RealToPseudo {

0 commit comments

Comments
 (0)