diff --git a/go.mod b/go.mod index 81c90db..59b79d7 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.23.6 require ( al.essio.dev/pkg/shellescape v1.6.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/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 diff --git a/go.sum b/go.sum index 3296642..30d300c 100644 --- a/go.sum +++ b/go.sum @@ -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/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.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/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/resource/filter.go b/resource/filter.go index 2cc1f31..f84f7d8 100644 --- a/resource/filter.go +++ b/resource/filter.go @@ -5,8 +5,6 @@ import ( "fmt" "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/api" "github.com/passbolt/go-passbolt/helper" @@ -38,28 +36,20 @@ func filterResources(resources *[]api.Resource, celCmd string, ctx context.Conte filteredResources := []api.Resource{} 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{ - "Id": resource.ID, - "FolderParentID": resource.FolderParentID, - "Name": resource.Name, - "Username": resource.Username, - "URI": resource.URI, - "Password": func() ref.Val { - _, _, _, _, pass, _, err := helper.GetResource(ctx, client, resource.ID) - 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) - }, + "Id": resource.ID, + "FolderParentID": resource.FolderParentID, + "Name": name, + "Username": username, + "URI": uri, + "Password": pass, + "Description": desc, "CreatedTimestamp": resource.Created.Time, "ModifiedTimestamp": resource.Modified.Time, }) diff --git a/resource/list.go b/resource/list.go index 0e0280e..010930b 100644 --- a/resource/list.go +++ b/resource/list.go @@ -93,16 +93,16 @@ func ResourceList(cmd *cobra.Command, args []string) error { if jsonOutput { outputResources := []ResourceJsonOutput{} 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 { return fmt.Errorf("Get Resource %w", err) } outputResources = append(outputResources, ResourceJsonOutput{ ID: &resources[i].ID, FolderParentID: &resources[i].FolderParentID, - Name: &resources[i].Name, - Username: &resources[i].Username, - URI: &resources[i].URI, + Name: &name, + Username: &username, + URI: &uri, Password: &pass, Description: &desc, CreatedTimestamp: &resources[i].Created.Time, @@ -118,6 +118,12 @@ func ResourceList(cmd *cobra.Command, args []string) error { data := pterm.TableData{columns} 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)) for i := range columns { switch strings.ToLower(columns[i]) { @@ -126,22 +132,14 @@ func ResourceList(cmd *cobra.Command, args []string) error { case "folderparentid": entry[i] = resource.FolderParentID case "name": - entry[i] = shellescape.StripUnsafe(resource.Name) + entry[i] = shellescape.StripUnsafe(name) case "username": - entry[i] = shellescape.StripUnsafe(resource.Username) + entry[i] = shellescape.StripUnsafe(username) case "uri": - entry[i] = shellescape.StripUnsafe(resource.URI) + entry[i] = shellescape.StripUnsafe(uri) 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) 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) case "createdtimestamp": entry[i] = resource.Created.Format(time.RFC3339)