Skip to content

Commit 96b24d6

Browse files
authored
Merge pull request #102 from cedricherzog-passbolt/Enable-parallel-resource-decryption-using-thread-safe-SDK
Enable parallel resource decryption using thread-safe SDK
2 parents a1e7888 + a3e7cb6 commit 96b24d6

File tree

8 files changed

+261
-78
lines changed

8 files changed

+261
-78
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.24.9
77
require (
88
al.essio.dev/pkg/shellescape v1.6.0
99
github.com/google/cel-go v0.26.1
10-
github.com/passbolt/go-passbolt v0.7.3-0.20251103091542-cb52308eb1b6
10+
github.com/passbolt/go-passbolt v0.7.3-0.20251222145204-2c0e56ef73c3
1111
github.com/pterm/pterm v0.12.82
1212
github.com/spf13/cobra v1.10.1
1313
github.com/spf13/viper v1.21.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ
8585
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
8686
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
8787
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
88-
github.com/passbolt/go-passbolt v0.7.3-0.20251031091721-286d90c417f1 h1:GGtUfSQhwUnTiVZEqrxG6qC98CIu57p70/nHkg42zGA=
89-
github.com/passbolt/go-passbolt v0.7.3-0.20251031091721-286d90c417f1/go.mod h1:YU35wLUTbqylBQGyEhyI8HjyceLChXDxajTIyyQlVU4=
90-
github.com/passbolt/go-passbolt v0.7.3-0.20251103091542-cb52308eb1b6 h1:qrV98eGK+9bpcAbcCrjhzO8uXqX40wBL71BE1FWtb3M=
91-
github.com/passbolt/go-passbolt v0.7.3-0.20251103091542-cb52308eb1b6/go.mod h1:YU35wLUTbqylBQGyEhyI8HjyceLChXDxajTIyyQlVU4=
88+
github.com/passbolt/go-passbolt v0.7.3-0.20251222145204-2c0e56ef73c3 h1:2orpLWXfGymctdjTPZr83KJE0RuGdT+X/XXs9aExu0w=
89+
github.com/passbolt/go-passbolt v0.7.3-0.20251222145204-2c0e56ef73c3/go.mod h1:YU35wLUTbqylBQGyEhyI8HjyceLChXDxajTIyyQlVU4=
9290
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
9391
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
9492
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

keepass/export.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package keepass
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"net/url"
@@ -54,7 +53,7 @@ func KeepassExport(cmd *cobra.Command, args []string) error {
5453
if err != nil {
5554
return err
5655
}
57-
defer client.Logout(context.TODO())
56+
defer util.SaveSessionKeysAndLogout(ctx, client)
5857
cmd.SilenceUsage = true
5958

6059
if keepassPassword == "" {

resource/filter.go

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ import (
66

77
"github.com/google/cel-go/cel"
88
"github.com/passbolt/go-passbolt-cli/util"
9-
"github.com/passbolt/go-passbolt/api"
10-
"github.com/passbolt/go-passbolt/helper"
119
)
1210

13-
// Environments for CEl
14-
var celEnvOptions = []cel.EnvOption{
11+
// CelEnvOptions defines the CEL environment for resource filtering
12+
var CelEnvOptions = []cel.EnvOption{
1513
cel.Variable("ID", cel.StringType),
1614
cel.Variable("FolderParentID", cel.StringType),
1715
cel.Variable("Name", cel.StringType),
@@ -23,48 +21,42 @@ var celEnvOptions = []cel.EnvOption{
2321
cel.Variable("ModifiedTimestamp", cel.TimestampType),
2422
}
2523

26-
// Filters the slice resources by invoke CEL program for each resource
27-
func filterResources(resources *[]api.Resource, celCmd string, ctx context.Context, client *api.Client) ([]api.Resource, error) {
24+
// filterDecryptedResources filters already-decrypted resources by evaluating a CEL expression.
25+
func filterDecryptedResources(resources []decryptedResource, celCmd string, ctx context.Context) ([]decryptedResource, error) {
2826
if celCmd == "" {
29-
return *resources, nil
27+
return resources, nil
3028
}
3129

32-
program, err := util.InitCELProgram(celCmd, celEnvOptions...)
30+
program, err := util.InitCELProgram(celCmd, CelEnvOptions...)
3331
if err != nil {
3432
return nil, err
3533
}
3634

37-
filteredResources := []api.Resource{}
38-
for _, resource := range *resources {
39-
// TODO We should decrypt the secret only when required for performance reasonse
40-
_, name, username, uri, pass, desc, err := helper.GetResource(ctx, client, resource.ID)
41-
if err != nil {
42-
return nil, fmt.Errorf("Get Resource %w", err)
43-
}
44-
35+
filtered := []decryptedResource{}
36+
for _, d := range resources {
4537
val, _, err := (*program).ContextEval(ctx, map[string]any{
46-
"Id": resource.ID,
47-
"FolderParentID": resource.FolderParentID,
48-
"Name": name,
49-
"Username": username,
50-
"URI": uri,
51-
"Password": pass,
52-
"Description": desc,
53-
"CreatedTimestamp": resource.Created.Time,
54-
"ModifiedTimestamp": resource.Modified.Time,
38+
"ID": d.resource.ID,
39+
"FolderParentID": d.resource.FolderParentID,
40+
"Name": d.name,
41+
"Username": d.username,
42+
"URI": d.uri,
43+
"Password": d.password,
44+
"Description": d.description,
45+
"CreatedTimestamp": d.resource.Created.Time,
46+
"ModifiedTimestamp": d.resource.Modified.Time,
5547
})
5648

5749
if err != nil {
5850
return nil, err
5951
}
6052

6153
if val.Value() == true {
62-
filteredResources = append(filteredResources, resource)
54+
filtered = append(filtered, d)
6355
}
6456
}
6557

66-
if len(filteredResources) == 0 {
58+
if len(filtered) == 0 {
6759
return nil, fmt.Errorf("No such Resources found with filter %v!", celCmd)
6860
}
69-
return filteredResources, nil
61+
return filtered, nil
7062
}

resource/get.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package resource
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"strconv"
@@ -59,7 +58,7 @@ func ResourceGet(cmd *cobra.Command, args []string) error {
5958
if err != nil {
6059
return err
6160
}
62-
defer client.Logout(context.TODO())
61+
defer util.SaveSessionKeysAndLogout(ctx, client)
6362
cmd.SilenceUsage = true
6463

6564
folderParentID, name, username, uri, password, description, err := helper.GetResource(
@@ -118,7 +117,7 @@ func ResourcePermission(cmd *cobra.Command, args []string) error {
118117
if err != nil {
119118
return err
120119
}
121-
defer client.Logout(context.TODO())
120+
defer util.SaveSessionKeysAndLogout(ctx, client)
122121
cmd.SilenceUsage = true
123122

124123
permissions, err := client.GetResourcePermissions(ctx, resource)

0 commit comments

Comments
 (0)