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(alerts): custom unmarshal of channel configuration Headers and Payload fields #102

Merged
merged 2 commits into from
Jan 22, 2020

Conversation

sanderblue
Copy link
Contributor

@sanderblue sanderblue commented Jan 21, 2020

Resolves: #101

Synopsis

The New Relic v2 API endpoint for alert channels returns two different data types for configuration.payload and configuration.headers. If either of those fields is "empty" or left black when creating an alert channel in the UI, the API will return an empty string. But if headers and/or payload are included in an alert channel, the API will return an object, hence the need for a custom umarshal method for those fields.

Example responses:

Population headers and payload

{
  "type": "webhook",
  "configuration": {
    "headers": {                            
      "x-header-test": "header-value"  <-- notice we have an object here
    },                                                 
    "payload": {                                 
      "account_id": "$ACCOUNT_ID"   <-- notice we have an object here
    },
    "payload_type": "application/json",
    "base_url": "http://example.com"
  },
  // ...
}

Empty headers and payload

{
  "type": "webhook",
  "configuration": {
    "headers":  "",  <-- notice this is a string and NOT an object, so we have to guard for this
    "payload": "",   <-- notice this is a string and NOT an object, so we have to guard for this
    "payload_type": "application/json",
    "base_url": "http://example.com"
  },
  // ...
}

@sanderblue sanderblue added the bug Something isn't working label Jan 21, 2020
@sanderblue sanderblue force-pushed the fix/json-unmarshall-channel-payload-headers branch 2 times, most recently from 9f4af69 to c10b4cf Compare January 21, 2020 23:30
@sanderblue sanderblue marked this pull request as ready for review January 21, 2020 23:40
@sanderblue sanderblue force-pushed the fix/json-unmarshall-channel-payload-headers branch from c10b4cf to dcc2483 Compare January 21, 2020 23:51
@sanderblue sanderblue force-pushed the fix/json-unmarshall-channel-payload-headers branch from dcc2483 to 24009bd Compare January 21, 2020 23:56
@sanderblue sanderblue changed the title fix(alerts): custom marshal/unmarshal of ChannelConfiguration fix(alerts): custom unmarshal of channel configuration Headers and Payload fields Jan 22, 2020
@sanderblue sanderblue requested a review from ctrombley January 22, 2020 00:14
Copy link
Contributor

@jthurman42 jthurman42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@sanderblue sanderblue merged commit a352fbc into master Jan 22, 2020
@sanderblue sanderblue deleted the fix/json-unmarshall-channel-payload-headers branch January 22, 2020 00:27
Copy link
Contributor

@ctrombley ctrombley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tiny change and otherwise LGTM.

pkg/alerts/alerts_types.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom unmarshal method for Payload and Header fields in ChannelConfiguration struct
3 participants