Update OpReadField method to be able to read different item fields

This commit is contained in:
Volodymyr Zotov
2025-08-28 13:20:45 -05:00
parent e61ba49018
commit 976909c438

View File

@@ -6,6 +6,13 @@ import (
"github.com/1Password/onepassword-operator/pkg/testhelper/system"
)
type Field string
const (
FieldUsername = "username"
FieldPassword = "password"
)
// UpdateItemPassword updates the password of an item in 1Password
func UpdateItemPassword(item string) error {
_, err := system.Run("op", "item", "edit", item, "--generate-password=letters,digits,symbols,32")
@@ -15,9 +22,9 @@ func UpdateItemPassword(item string) error {
return nil
}
// ReadItemPassword reads the password of an item in 1Password
func ReadItemPassword(item, vault string) (string, error) {
output, err := system.Run("op", "read", fmt.Sprintf("op://%s/%s/password", vault, item))
// ReadItemField reads the password of an item in 1Password
func ReadItemField(item, vault string, field Field) (string, error) {
output, err := system.Run("op", "read", fmt.Sprintf("op://%s/%s/%s", vault, item, field))
if err != nil {
return "", err
}