Compare commits

...

2 commits

Author SHA1 Message Date
e2e0694683 Update go-passbolt 2025-08-11 15:57:24 +02:00
a3c466919c
v5 Fix Resource Listing (#82)
* Fix json Listing

* Always Decrypt Resource
2025-08-11 15:30:31 +02:00
4 changed files with 29 additions and 39 deletions

2
go.mod
View file

@ -7,7 +7,7 @@ toolchain go1.23.6
require ( require (
al.essio.dev/pkg/shellescape v1.6.0 al.essio.dev/pkg/shellescape v1.6.0
github.com/google/cel-go v0.26.0 github.com/google/cel-go v0.26.0
github.com/passbolt/go-passbolt v0.7.3-0.20250805134827-8b00fcd4971e github.com/passbolt/go-passbolt v0.7.3-0.20250811135314-1ffa5a23bd29
github.com/pterm/pterm v0.12.81 github.com/pterm/pterm v0.12.81
github.com/spf13/cobra v1.9.1 github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1 github.com/spf13/viper v1.20.1

2
go.sum
View file

@ -79,6 +79,8 @@ github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6T
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/passbolt/go-passbolt v0.7.3-0.20250805134827-8b00fcd4971e h1:hOFvvLNg7JoW0BlBX89Cu1kFRZMggRcAyOC8ZnCoJqo= github.com/passbolt/go-passbolt v0.7.3-0.20250805134827-8b00fcd4971e h1:hOFvvLNg7JoW0BlBX89Cu1kFRZMggRcAyOC8ZnCoJqo=
github.com/passbolt/go-passbolt v0.7.3-0.20250805134827-8b00fcd4971e/go.mod h1:gluZh5f4qwo4QraUD6B68ZM3GHX3i3J2T/HHLcC1O7U= github.com/passbolt/go-passbolt v0.7.3-0.20250805134827-8b00fcd4971e/go.mod h1:gluZh5f4qwo4QraUD6B68ZM3GHX3i3J2T/HHLcC1O7U=
github.com/passbolt/go-passbolt v0.7.3-0.20250811135314-1ffa5a23bd29 h1:4KBVFj492jMi8pu99lZjxrFFfXH49O7Itw8yiCRXkGU=
github.com/passbolt/go-passbolt v0.7.3-0.20250811135314-1ffa5a23bd29/go.mod h1:gluZh5f4qwo4QraUD6B68ZM3GHX3i3J2T/HHLcC1O7U=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

View file

@ -5,8 +5,6 @@ import (
"fmt" "fmt"
"github.com/google/cel-go/cel" "github.com/google/cel-go/cel"
"github.com/google/cel-go/common/types"
"github.com/google/cel-go/common/types/ref"
"github.com/passbolt/go-passbolt-cli/util" "github.com/passbolt/go-passbolt-cli/util"
"github.com/passbolt/go-passbolt/api" "github.com/passbolt/go-passbolt/api"
"github.com/passbolt/go-passbolt/helper" "github.com/passbolt/go-passbolt/helper"
@ -38,28 +36,20 @@ func filterResources(resources *[]api.Resource, celCmd string, ctx context.Conte
filteredResources := []api.Resource{} filteredResources := []api.Resource{}
for _, resource := range *resources { for _, resource := range *resources {
// TODO We should decrypt the secret only when required for performance reasonse
_, name, username, uri, pass, desc, err := helper.GetResource(ctx, client, resource.ID)
if err != nil {
return nil, fmt.Errorf("Get Resource %w", err)
}
val, _, err := (*program).ContextEval(ctx, map[string]any{ val, _, err := (*program).ContextEval(ctx, map[string]any{
"Id": resource.ID, "Id": resource.ID,
"FolderParentID": resource.FolderParentID, "FolderParentID": resource.FolderParentID,
"Name": resource.Name, "Name": name,
"Username": resource.Username, "Username": username,
"URI": resource.URI, "URI": uri,
"Password": func() ref.Val { "Password": pass,
_, _, _, _, pass, _, err := helper.GetResource(ctx, client, resource.ID) "Description": desc,
if err != nil {
fmt.Printf("Get Resource %v", err)
return types.String("")
}
return types.String(pass)
},
"Description": func() ref.Val {
_, _, _, _, _, descr, err := helper.GetResource(ctx, client, resource.ID)
if err != nil {
fmt.Printf("Get Resource %v", err)
return types.String("")
}
return types.String(descr)
},
"CreatedTimestamp": resource.Created.Time, "CreatedTimestamp": resource.Created.Time,
"ModifiedTimestamp": resource.Modified.Time, "ModifiedTimestamp": resource.Modified.Time,
}) })

View file

@ -93,16 +93,16 @@ func ResourceList(cmd *cobra.Command, args []string) error {
if jsonOutput { if jsonOutput {
outputResources := []ResourceJsonOutput{} outputResources := []ResourceJsonOutput{}
for i := range resources { for i := range resources {
_, _, _, _, pass, desc, err := helper.GetResource(ctx, client, resources[i].ID) _, name, username, uri, pass, desc, err := helper.GetResource(ctx, client, resources[i].ID)
if err != nil { if err != nil {
return fmt.Errorf("Get Resource %w", err) return fmt.Errorf("Get Resource %w", err)
} }
outputResources = append(outputResources, ResourceJsonOutput{ outputResources = append(outputResources, ResourceJsonOutput{
ID: &resources[i].ID, ID: &resources[i].ID,
FolderParentID: &resources[i].FolderParentID, FolderParentID: &resources[i].FolderParentID,
Name: &resources[i].Name, Name: &name,
Username: &resources[i].Username, Username: &username,
URI: &resources[i].URI, URI: &uri,
Password: &pass, Password: &pass,
Description: &desc, Description: &desc,
CreatedTimestamp: &resources[i].Created.Time, CreatedTimestamp: &resources[i].Created.Time,
@ -118,6 +118,12 @@ func ResourceList(cmd *cobra.Command, args []string) error {
data := pterm.TableData{columns} data := pterm.TableData{columns}
for _, resource := range resources { for _, resource := range resources {
// TODO We should decrypt the secret only when required for performance reasonse
_, name, username, uri, pass, desc, err := helper.GetResource(ctx, client, resource.ID)
if err != nil {
return fmt.Errorf("Get Resource %w", err)
}
entry := make([]string, len(columns)) entry := make([]string, len(columns))
for i := range columns { for i := range columns {
switch strings.ToLower(columns[i]) { switch strings.ToLower(columns[i]) {
@ -126,22 +132,14 @@ func ResourceList(cmd *cobra.Command, args []string) error {
case "folderparentid": case "folderparentid":
entry[i] = resource.FolderParentID entry[i] = resource.FolderParentID
case "name": case "name":
entry[i] = shellescape.StripUnsafe(resource.Name) entry[i] = shellescape.StripUnsafe(name)
case "username": case "username":
entry[i] = shellescape.StripUnsafe(resource.Username) entry[i] = shellescape.StripUnsafe(username)
case "uri": case "uri":
entry[i] = shellescape.StripUnsafe(resource.URI) entry[i] = shellescape.StripUnsafe(uri)
case "password": case "password":
_, _, _, _, pass, _, err := helper.GetResource(ctx, client, resource.ID)
if err != nil {
return fmt.Errorf("Get Resource %w", err)
}
entry[i] = shellescape.StripUnsafe(pass) entry[i] = shellescape.StripUnsafe(pass)
case "description": case "description":
_, _, _, _, _, desc, err := helper.GetResource(ctx, client, resource.ID)
if err != nil {
return fmt.Errorf("Get Resource %w", err)
}
entry[i] = shellescape.StripUnsafe(desc) entry[i] = shellescape.StripUnsafe(desc)
case "createdtimestamp": case "createdtimestamp":
entry[i] = resource.Created.Format(time.RFC3339) entry[i] = resource.Created.Format(time.RFC3339)