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

support yaml payloads for generic webhooks #10031

Merged
merged 1 commit into from
Jul 27, 2016

Conversation

bparees
Copy link
Contributor

@bparees bparees commented Jul 26, 2016

No description provided.

@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

@csrwng ptal. embarassingly our doc suggests a yaml payload :(

@openshift/api-review this isn't a huge api change, but ptal/sign-off.

@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

[test]

@bparees bparees changed the title support for overriding s2i incremental field at the cluster level support yaml payloads for generic webhooks Jul 26, 2016
@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

flake #9959
[test]

@@ -65,8 +66,13 @@ func (p *WebHookPlugin) Extract(buildCfg *api.BuildConfig, secret, path string,
}

var data api.GenericWebHookEvent
body, err = yaml.ToJSON(body)
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't we skip this conversion if the contentType == "application/json" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yaml.ToJSON no-ops if the content is json.

so this way we will "work" even if they screw up the content-type header, and no real additional cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, cool

Copy link
Contributor

Choose a reason for hiding this comment

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

it does, but the error is really confusing ("yaml: unmarshal errors...")... we should only do it when the content-type indicates it is yaml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt ?

func ToJSON(data []byte) ([]byte, error) {
    if hasJSONPrefix(data) {
        return data, nil
    }
    return yaml.YAMLToJSON(data)
}

Basically this code now says "if you tell us it's yaml or json, we will convert it to json and then process it as json. If it was originally json, then we will no-op the conversion"

where does the error come in?

Copy link
Contributor

Choose a reason for hiding this comment

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

this should not return a yaml unmarshal error:

curl -X POST -H "Content-Type: application/json" --data "invalid data"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a log level 4 error that doesn't even go back to the user, but ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(And it means if someone specifies content-type json but supplies yaml, the payload will now be ignored because it'll catch an error)

@csrwng
Copy link
Contributor

csrwng commented Jul 26, 2016

LGTM

@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

[test]

On Tue, Jul 26, 2016 at 10:16 AM, OpenShift Bot [email protected]
wrote:

continuous-integration/openshift-jenkins/test FAILURE (
https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6894/)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#10031 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEvl3ic6Vwg5KTfB0vpZig2ioxupyNIMks5qZhbQgaJpZM4JUvPT
.

Ben Parees | OpenShift

@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

@liggitt updated.

if err = json.Unmarshal(body, &data); err != nil {
glog.V(4).Infof("Error unmarshaling json %v, but continuing", err)
glog.V(4).Infof("Error unmarshalling payload %v, but continuing with build", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

huh... I didn't realize we continued in cases where the body was invalid. I could maybe see doing that if the body was empty, but it seems wrong to just ignore malformed content, especially if the data could change the behavior of the launched build

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i don't remember exactly why we made that choice, but i think we're mostly stuck with it now.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

Copy link
Contributor

Choose a reason for hiding this comment

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

it's also unfortunate that all other content types get ignored and "successfully" do a generic build

@liggitt
Copy link
Contributor

liggitt commented Jul 26, 2016

changes look fine, can we add a test that submits yaml and makes sure the payload actually takes effect?

@bparees
Copy link
Contributor Author

bparees commented Jul 26, 2016

@liggitt test added
[merge]

@openshift-bot
Copy link
Contributor

openshift-bot commented Jul 26, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6955/) (Image: devenv-rhel7_4675)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 10ba6bd

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 10ba6bd

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/6909/)

@openshift-bot openshift-bot merged commit 5c857d4 into openshift:master Jul 27, 2016
@bparees bparees deleted the webhook_yaml branch July 28, 2016 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants