From 42be2b614519875a57a65c92afb26d4cbd29b154 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 24 Sep 2024 12:06:21 -0400 Subject: [PATCH 1/2] sc-112651: Updating function to allow optional section searching --- onepassword/main.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/onepassword/main.go b/onepassword/main.go index 55f78c3..f700962 100644 --- a/onepassword/main.go +++ b/onepassword/main.go @@ -30,6 +30,9 @@ func (m *Onepassword) FindSecret( // Name of the item to find itemName string, + // Name of the section to search (optional) + sectionName string, + // Name of the field to find fieldName string, ) (*dagger.Secret, error) { @@ -55,9 +58,24 @@ func (m *Onepassword) FindSecret( item, err := client.Items.Get(ctx, vault.ID, itemOverview.ID) - for _, field := range item.Fields { - if field.Title == fieldName { - return dagger.Connect().SetSecret(fieldName, field.Value), nil + // If sectionName is empty, search top-level fields only + if sectionName == "" { + for _, field := range item.Fields { + if field.Title == fieldName { + return dagger.Connect().SetSecret(fieldName, field.Value), nil + } + } + return nil, ErrFieldNotFound + } + + // Search in the specified section + for _, section := range item.Sections { + if section.Title == sectionName { + for _, field := range item.Fields { + if field.Title == fieldName { + return dagger.Connect().SetSecret(fieldName, field.Value), nil + } + } } } From 19ad72dd6f6f1352da94f05bcb07d2a00c4e79e2 Mon Sep 17 00:00:00 2001 From: Randy Date: Tue, 24 Sep 2024 18:26:22 -0400 Subject: [PATCH 2/2] sc-112651: Updating function to allow optional section searching --- onepassword/main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/onepassword/main.go b/onepassword/main.go index f700962..66ae295 100644 --- a/onepassword/main.go +++ b/onepassword/main.go @@ -68,14 +68,19 @@ func (m *Onepassword) FindSecret( return nil, ErrFieldNotFound } + var sectionID string = "" + // Search in the specified section for _, section := range item.Sections { if section.Title == sectionName { - for _, field := range item.Fields { - if field.Title == fieldName { - return dagger.Connect().SetSecret(fieldName, field.Value), nil - } - } + sectionID = section.ID + + } + } + + for _, field := range item.Fields { + if field.Title == fieldName && field.SectionID != nil && *field.SectionID == sectionID { + return dagger.Connect().SetSecret(fieldName, field.Value), nil } } @@ -95,6 +100,9 @@ func (m *Onepassword) PutSecret( // Name of the item to find itemName string, + // Name of the section to search (optional) + sectionName string, + // Name of the field to find fieldName string,