Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with the uptime widget #93

Merged
merged 5 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion datadog/resource_datadog_screenboard.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package datadog

import (
"encoding/json"
"fmt"
"log"
"strconv"
Expand Down Expand Up @@ -481,7 +482,7 @@ func resourceDatadogScreenboard() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"threshold": &schema.Schema{
Type: schema.TypeInt,
Type: schema.TypeFloat,
Optional: true,
},
"timeframe": &schema.Schema{
Expand Down Expand Up @@ -594,6 +595,14 @@ func setBoolFromDict(dict map[string]interface{}, key string, field **bool) {
}
}

// For setJSONNumberFromDict, dict[key] is expected to be a float64
func setJSONNumberFromDict(dict map[string]interface{}, key string, field **json.Number) {
if v, ok := dict[key]; ok {
f := json.Number(strconv.FormatFloat(v.(float64), 'e', -1, 64))
*field = &f
}
}

func setStringListFromDict(dict map[string]interface{}, key string, field *[]*string) {
if v, ok := dict[key].([]interface{}); ok {
*field = []*string{}
Expand All @@ -611,6 +620,8 @@ func setFromDict(dict map[string]interface{}, key string, field interface{}) {
setIntFromDict(dict, key, field.(**int))
case **bool:
setBoolFromDict(dict, key, field.(**bool))
case **json.Number:
setJSONNumberFromDict(dict, key, field.(**json.Number))
case *[]*string:
setStringListFromDict(dict, key, field.(*[]*string))
default:
Expand Down Expand Up @@ -989,6 +1000,16 @@ func setIntToDict(dict map[string]interface{}, key string, field *int) {
}
}

func setJSONNumberToDict(dict map[string]interface{}, key string, field *json.Number) {
if field != nil {
v, err := (*field).Float64()
if err != nil {
panic(fmt.Sprintf("setJSONNumberToDict(): %v is not convertible to float", *field))
}
dict[key] = v
}
}

func setStringListToDict(dict map[string]interface{}, key string, field []*string) {
if len(field) != 0 {
s := make([]interface{}, len(field))
Expand All @@ -1007,6 +1028,8 @@ func setToDict(dict map[string]interface{}, key string, field interface{}) {
setBoolToDict(dict, key, field.(*bool))
case *int:
setIntToDict(dict, key, field.(*int))
case *json.Number:
setJSONNumberToDict(dict, key, field.(*json.Number))
case []*string:
setStringListToDict(dict, key, field.([]*string))
default:
Expand Down
Loading