Skip to content

Commit

Permalink
Improve item section and field ID generation
Browse files Browse the repository at this point in the history
williamhpark committed Oct 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent db29adc commit e0d47f1
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions onepassword/resource_onepassword_item.go
Original file line number Diff line number Diff line change
@@ -546,19 +546,17 @@ func dataToItem(data *schema.ResourceData) (*onepassword.Item, error) {
if !ok {
return nil, fmt.Errorf("Unable to parse section: %v", sections[i])
}
sid, err := uuid.GenerateUUID()
if err != nil {
return nil, fmt.Errorf("Unable to generate a section id: %w", err)
}

if section["id"].(string) != "" {
sid = section["id"].(string)
} else {
if section["id"].(string) == "" {
sid, err := uuid.GenerateUUID()
if err != nil {
return nil, fmt.Errorf("Unable to generate a section id: %w", err)
}
section["id"] = sid
}

s := &onepassword.ItemSection{
ID: sid,
ID: section["id"].(string),
Label: section["label"].(string),
}
item.Sections = append(item.Sections, s)
@@ -570,6 +568,14 @@ func dataToItem(data *schema.ResourceData) (*onepassword.Item, error) {
return nil, fmt.Errorf("Unable to parse section field: %v", sectionFields[j])
}

if field["id"].(string) == "" {
fid, err := uuid.GenerateUUID()
if err != nil {
return nil, fmt.Errorf("Unable to generate a field id: %w", err)
}
field["id"] = fid
}

f := &onepassword.ItemField{
Section: s,
ID: field["id"].(string),

0 comments on commit e0d47f1

Please sign in to comment.