@@ -116,25 +116,52 @@ func resourceAddressCreate(ctx context.Context, d *schema.ResourceData, m interf
116116 fieldType = ft
117117 }
118118
119- // For now, support text fields as most common custom field type
120- if fieldType == "text" {
121- field := & core.Text {
122- KeeperRecordField : core.KeeperRecordField {
123- Type : "text" ,
124- },
119+ // Support text, multiline, secret, url, and email field types
120+ switch fieldType {
121+ case "text" , "multiline" , "secret" , "url" , "email" :
122+ var field interface {}
123+ switch fieldType {
124+ case "text" :
125+ field = & core.Text {KeeperRecordField : core.KeeperRecordField {Type : "text" }}
126+ case "multiline" :
127+ field = & core.Multiline {KeeperRecordField : core.KeeperRecordField {Type : "multiline" }}
128+ case "secret" :
129+ field = & core.Secret {KeeperRecordField : core.KeeperRecordField {Type : "secret" }}
130+ case "url" :
131+ field = & core.Url {KeeperRecordField : core.KeeperRecordField {Type : "url" }}
132+ case "email" :
133+ field = & core.Email {KeeperRecordField : core.KeeperRecordField {Type : "email" }}
125134 }
126- if label , ok := customMap ["label" ].(string ); ok {
127- field .Label = label
128- }
129- if required , ok := customMap ["required" ].(bool ); ok {
130- field .Required = required
131- }
132- if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok {
133- field .PrivacyScreen = privacyScreen
134- }
135- if value , ok := customMap ["value" ].(string ); ok && value != "" {
136- field .Value = []string {value }
135+
136+ // Set common properties using type assertion
137+ switch f := field .(type ) {
138+ case * core.Text :
139+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
140+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
141+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
142+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
143+ case * core.Multiline :
144+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
145+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
146+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
147+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
148+ case * core.Secret :
149+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
150+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
151+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
152+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
153+ case * core.Url :
154+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
155+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
156+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
157+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
158+ case * core.Email :
159+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
160+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
161+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
162+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
137163 }
164+
138165 nrc .Custom = append (nrc .Custom , field )
139166 }
140167 }
@@ -284,9 +311,73 @@ func resourceAddressUpdate(ctx context.Context, d *schema.ResourceData, m interf
284311 }
285312
286313 if d .HasChange ("custom" ) {
287- if _ , err := ApplyFieldChange ("custom" , "custom" , d , secret ); err != nil {
288- return diag .FromErr (err )
314+ // Clear existing custom fields
315+ customFields := []interface {}{}
316+ // Add updated custom fields
317+ if customData := d .Get ("custom" ); customData != nil && len (customData .([]interface {})) > 0 {
318+ for _ , customItem := range customData .([]interface {}) {
319+ if customMap , ok := customItem .(map [string ]interface {}); ok {
320+ fieldType := "text"
321+ if ft , ok := customMap ["type" ].(string ); ok && ft != "" {
322+ fieldType = ft
323+ }
324+ switch fieldType {
325+ case "text" , "multiline" , "secret" , "url" , "email" :
326+ var field interface {}
327+ switch fieldType {
328+ case "text" :
329+ field = & core.Text {KeeperRecordField : core.KeeperRecordField {Type : "text" }}
330+ case "multiline" :
331+ field = & core.Multiline {KeeperRecordField : core.KeeperRecordField {Type : "multiline" }}
332+ case "secret" :
333+ field = & core.Secret {KeeperRecordField : core.KeeperRecordField {Type : "secret" }}
334+ case "url" :
335+ field = & core.Url {KeeperRecordField : core.KeeperRecordField {Type : "url" }}
336+ case "email" :
337+ field = & core.Email {KeeperRecordField : core.KeeperRecordField {Type : "email" }}
338+ }
339+
340+ // Set common properties using type assertion
341+ var fieldMap map [string ]interface {}
342+ switch f := field .(type ) {
343+ case * core.Text :
344+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
345+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
346+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
347+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
348+ fieldMap = convertFieldToMap (f .Type , f .Label , f .Required , f .PrivacyScreen , f .Value )
349+ case * core.Multiline :
350+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
351+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
352+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
353+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
354+ fieldMap = convertFieldToMap (f .Type , f .Label , f .Required , f .PrivacyScreen , f .Value )
355+ case * core.Secret :
356+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
357+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
358+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
359+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
360+ fieldMap = convertFieldToMap (f .Type , f .Label , f .Required , f .PrivacyScreen , f .Value )
361+ case * core.Url :
362+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
363+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
364+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
365+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
366+ fieldMap = convertFieldToMap (f .Type , f .Label , f .Required , f .PrivacyScreen , f .Value )
367+ case * core.Email :
368+ if label , ok := customMap ["label" ].(string ); ok { f .Label = label }
369+ if required , ok := customMap ["required" ].(bool ); ok { f .Required = required }
370+ if privacyScreen , ok := customMap ["privacy_screen" ].(bool ); ok { f .PrivacyScreen = privacyScreen }
371+ if value , ok := customMap ["value" ].(string ); ok && value != "" { f .Value = []string {value } }
372+ fieldMap = convertFieldToMap (f .Type , f .Label , f .Required , f .PrivacyScreen , f .Value )
373+ }
374+
375+ customFields = append (customFields , fieldMap )
376+ }
377+ }
378+ }
289379 }
380+ secret .RecordDict ["custom" ] = customFields
290381 }
291382
292383 secret .RawJson = core .DictToJson (secret .RecordDict )
0 commit comments