Skip to content

Commit

Permalink
Devtooling 287 Removed validation logic for phones (#931)
Browse files Browse the repository at this point in the history
* removed validation logic

* removed validation logic
  • Loading branch information
kavinbalagen authored Mar 22, 2024
1 parent 6f8c235 commit 71c928e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ func createPhone(ctx context.Context, d *schema.ResourceData, meta interface{})
if err != nil {
return diag.Errorf("failed to create phone %v: %v", *phoneConfig.Name, err)
}
_, err = validatePhoneHardwareIdRequirements(phoneConfig)
if err != nil {
return diag.Errorf("failed to create phone %v: %v", *phoneConfig.Name, err)
}
log.Printf("Creating phone %s", *phoneConfig.Name)
diagErr := util.RetryWhen(util.IsStatus404, func() (*platformclientv2.APIResponse, diag.Diagnostics) {
phone, resp, err := pp.createPhone(ctx, phoneConfig)
Expand Down Expand Up @@ -132,10 +128,6 @@ func updatePhone(ctx context.Context, d *schema.ResourceData, meta interface{})
if err != nil {
return diag.Errorf("failed to updated phone %v: %v", *phoneConfig.Name, err)
}
_, err = validatePhoneHardwareIdRequirements(phoneConfig)
if err != nil {
return diag.Errorf("failed to updated phone %v: %v", *phoneConfig.Name, err)
}
log.Printf("Updating phone %s", *phoneConfig.Name)
phone, err := pp.updatePhone(ctx, d.Id(), phoneConfig)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,35 +382,3 @@ func generatePhoneProperties(hardware_id string) string {
)))),
)
}

func validatePhoneHardwareIdRequirements(phone *platformclientv2.Phone) (bool, error) {
var (
hardwareIdType string
hardwareIdValue string
)
hardwareIdRequiredTypes := map[string]bool{
"mac": true,
"fqdn": true,
}

if phone.Capabilities != nil && phone.Capabilities.HardwareIdType != nil {
hardwareIdType = *phone.Capabilities.HardwareIdType
}

if phone.Properties != nil && (*phone.Properties)["phone_hardwareId"] != nil {
hardwareIdval, exists := (*phone.Properties)["phone_hardwareId"].(map[string]interface{})["value"].(map[string]interface{})["instance"]
if exists {
hardwareIdValue = hardwareIdval.(string)
}
}

_, exists := hardwareIdRequiredTypes[hardwareIdType]
if exists && len(hardwareIdValue) <= 0 {
return false, fmt.Errorf("hardwareId is required based on the phone capabilities hardwareIdType: %s", hardwareIdType)
}
if (!exists) && len(hardwareIdValue) > 0 {
return false, fmt.Errorf("hardwareId is not required based on the phone capabilities hardwareIdType:%s", hardwareIdType)
}
return true, nil

}

0 comments on commit 71c928e

Please sign in to comment.