-
Notifications
You must be signed in to change notification settings - Fork 52
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 auto_pause_notifications_parameters JSON serialization #94
Fix auto_pause_notifications_parameters JSON serialization #94
Conversation
@@ -51,8 +51,8 @@ type AlertGroupingParameters struct { | |||
|
|||
// AutoPauseNotificationsParameters defines how alerts on this service are automatically suspended for a period of time before triggering, when identified as likely being transient. | |||
type AutoPauseNotificationsParameters struct { | |||
Enabled bool `json:enabled,omitempty` | |||
Timeout int `json:timeout,omitempty` | |||
Enabled bool `json:"enabled"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing omitempty
is required to avoid the following error when enabled
is false
:
---[ REQUEST ]---------------------------------------
PUT /services/P49BQU7 HTTP/1.1
Host: api.pagerduty.com
User-Agent: heimweh/go-pagerduty(terraform)
Content-Length: 369
Accept: application/vnd.pagerduty+json;version=2
Authorization: Token token=******
Content-Type: application/json
Accept-Encoding: gzip
{
"service": {
"acknowledgement_timeout": 1800,
"alert_creation": "create_alerts_and_incidents",
"alert_grouping": null,
"auto_pause_notifications_parameters": {
"timeout": 120
},
"auto_resolve_timeout": 1800,
"description": "foo",
"escalation_policy": {
"id": "PW95IJV",
"type": "escalation_policy_reference"
},
"incident_urgency_rule": {
"type": "constant",
"urgency": "high"
},
"name": "tf-7vwjy"
}
}
-----------------------------------------------------
2022/06/10 14:22:53 [DEBUG] PagerDuty API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 400 Bad Request
Content-Length: 116
Access-Control-Allow-Headers: Authorization, Content-Type, AuthorizationOauth, X-EARLY-ACCESS
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers:
Access-Control-Max-Age: 1728000
Cache-Control: no-cache
Content-Type: application/json
Date: Fri, 10 Jun 2022 12:22:53 GMT
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
X-Request-Id: c1841333efa37b0fd7acd858b7648312
{
"error": {
"message": "Invalid Input Provided",
"code": 2001,
"errors": [
"Enabled must be a TrueClass or a FalseClass."
]
}
}
-----------------------------------------------------
pagerduty/service.go
Outdated
Enabled bool `json:enabled,omitempty` | ||
Timeout int `json:timeout,omitempty` | ||
Enabled bool `json:"enabled"` | ||
Timeout int `json:"timeout"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out the API returns null
for timeout
if enabled
is set to false:
---[ REQUEST ]---------------------------------------
PUT /services/PDKFHYX HTTP/1.1
Host: api.pagerduty.com
User-Agent: heimweh/go-pagerduty(terraform)
Content-Length: 385
Accept: application/vnd.pagerduty+json;version=2
Authorization: Token token=******
Content-Type: application/json
Accept-Encoding: gzip
{
"service": {
"acknowledgement_timeout": 1800,
"alert_creation": "create_alerts_and_incidents",
"alert_grouping": null,
"auto_pause_notifications_parameters": {
"enabled": false,
"timeout": 300
},
"auto_resolve_timeout": 1800,
"description": "foo",
"escalation_policy": {
"id": "PPF7AEC",
"type": "escalation_policy_reference"
},
"incident_urgency_rule": {
"type": "constant",
"urgency": "high"
},
"name": "tf-43e4n"
}
}
-----------------------------------------------------
2022/06/10 15:06:33 [DEBUG] PagerDuty API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 200 OK
Access-Control-Allow-Headers: Authorization, Content-Type, AuthorizationOauth, X-EARLY-ACCESS
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers:
Access-Control-Max-Age: 1728000
Cache-Control: max-age=0, private, must-revalidate
Content-Type: application/json
Date: Fri, 10 Jun 2022 13:06:33 GMT
Etag: W/"45b125457a612501fdfc61e82a2213e0"
Feature-Policy: accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'
Referrer-Policy: strict-origin-when-cross-origin
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Strict-Transport-Security: max-age=31536000; includeSubDomains
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Request-Id: 218f2e5d06395dc71236b61febd23c66
X-Xss-Protection: 1; mode=block
{
"service": {
"id": "PDKFHYX",
"name": "tf-43e4n",
"description": "foo",
"created_at": "2022-06-10T15:06:29+02:00",
"updated_at": "2022-06-10T15:06:33+02:00",
"status": "active",
"teams": [],
"alert_creation": "create_alerts_and_incidents",
"addons": [],
"scheduled_actions": [],
"support_hours": null,
"last_incident_timestamp": null,
"escalation_policy": {
"id": "PPF7AEC",
"type": "escalation_policy_reference",
"summary": "tf-xgyxe",
"self": "https://api.pagerduty.com/escalation_policies/PPF7AEC",
"html_url": "https://dev-claranet.pagerduty.com/escalation_policies/PPF7AEC"
},
"incident_urgency_rule": {
"type": "constant",
"urgency": "high"
},
"acknowledgement_timeout": 1800,
"auto_resolve_timeout": 1800,
"auto_pause_notifications_parameters": {
"enabled": false,
"timeout": null
},
"alert_grouping": null,
"alert_grouping_timeout": null,
"alert_grouping_parameters": {
"type": null,
"config": null
},
"integrations": [],
"response_play": null,
"type": "service",
"summary": "tf-43e4n",
"self": "https://api.pagerduty.com/services/PDKFHYX",
"html_url": "https://dev-claranet.pagerduty.com/service-directory/PDKFHYX"
}
}
-----------------------------------------------------
timeout
probably needs to be an int pointer instead of an int.
Note that running
I've submitted #96 to run |
b60e050
to
ceae303
Compare
Hey @pdecat! It looks great! Thank you for fixing JSON serialization for this... 👏🏽🎉 |
@stmcallister this PR fixes my previous #92 PR which had broken JSON serialization:
Note that
Enabled
andTimeout
have a capital letter.