Repository navigation
fix: [backport] support mTLS in 1.0 Binary and Structured emitters - #106
Conversation
This commit modifies both of the 1.0 emitters so that they may accept typed objects as a part of the configuration. When using mTLS in Node, you need to provide an `Agent` to the underlying HTTP handler. In this case, Axios will pass this object along to Node.js when it is provided. Fixes: cloudevents#48 Signed-off-by: Lance Ball <lball@redhat.com>
|
The Codacy failure is due to this problem:
|
grant
left a comment
There was a problem hiding this comment.
Looks fine, however we should use ES6 JS features. I gave some examples.
| return axios.request(this.config).then(response => { | ||
| delete this.config[Constants.DATA_ATTRIBUTE]; | ||
| return response; | ||
| }); |
There was a problem hiding this comment.
This is very confusing.
Why don't we just do this?
const res = await axios.request(this.config);
delete this.config[Constants.DATA_ATTRIBUTE];
return res;The outer function needs to be async of course.
There was a problem hiding this comment.
The change you suggest introduces a race condition.
There was a problem hiding this comment.
No, where's the race? That's not how Node executes.
There was a problem hiding this comment.
I vote for then notation.
There was a problem hiding this comment.
@grant try this in your browser https://gist.github.com/lance/ff1bf6d2da191ad164257349486c4c95
There was a problem hiding this comment.
Although, playing around with this code reveals to me that the race condition exists even using then(). Boo.
| var axios = require("axios"); | ||
|
|
||
| const Constants = require("./constants.js"); | ||
| const defaults = {}; |
There was a problem hiding this comment.
Why are we creating an empty object and then adding properties to it?
const defaults = {
[Constants.HEADERS]: {
[Constants.HEADER_CONTENT_TYPE]: Constants.DEFAULT_CE_CONTENT_TYPE
}
};There was a problem hiding this comment.
You introduced new syntax to me. I wasn't aware that you could bracket a nested property as a field name.
There was a problem hiding this comment.
OK. This is a feature of JavaScript ES2015. Here's a reference:
https://stackoverflow.com/a/19837961
There was a problem hiding this comment.
I did not know either! Looks good
| this.config[Constants.HEADERS][Constants.HEADER_CONTENT_TYPE] = | ||
| Constants.DEFAULT_CE_CONTENT_TYPE; | ||
| } | ||
| this.config = Object.assign({}, defaults, configuration); |
There was a problem hiding this comment.
Why are we using Object.assign when we can just use the native JavaScript object spread operator?
this.config = {...defaults, ...configuration};There was a problem hiding this comment.
The commit happened before we dropped support for early versions of Node.js so this would not have passed CI. It's a reasonable change for master now that we've dropped 6 and 8.
There was a problem hiding this comment.
I'm not sure of the CI system yet but Node versions < 10 were end of life Dec 31, 2019. Completely understandable, but we should only use non-deprecated versions of Node in our CI.
There was a problem hiding this comment.
@grant yes, I am aware. That's why I updated CI last month to only use 10 & 12. aa2cef6#diff-354f30a63fb0907d4ad57269548329e3
There was a problem hiding this comment.
@helio-frota I think submitting a separate PR for that is fine.
| key: 'other value' | ||
| }) | ||
| }) | ||
| return event.emit(cloudevent).then(response => { |
There was a problem hiding this comment.
This can also be converted to ES6.
There was a problem hiding this comment.
Again - this was prior to dropping Node 6 and 8 support.
| config[Constants.DATA_ATTRIBUTE] = data; | ||
| config.headers = headers; | ||
|
|
||
| // Return the Promise |
|
@grant this is a backport of an existing commit, cherry picked onto the v1.x.y branch. I think it should remain as the original commit. The whole entire idea is that this 1.x branch get the exact commits that landed on master. If you want to change syntax to ES6 on master that's great. We can chose to backport that or not. |
OK. So we're basically just freezing a version of master and setting it to this branch? In that case, that's fine, and we should indicate the PR is meant for that. We probably don't need a review if this is just mirroring |
Sort of. Here I used I understand that there aren't a lot of people using this module right now. But, there are some people using it, I'm sure. And those people are all on 1.0.0 right now. If our 2.0.0 release is going to have major breaking changes (say the API is completely changed - not using builder patter for example), we can't expect people to immediately rewrite their code to accommodate our new release. HOWEVER, they still should have the bug fixes and updates that keep their application working correctly through patch/minor version level releases of the 1.x line. That's what this whole branch/backport thing is about. |
The "Landed in: xxxxx" indicates what commit this cherry pick originally landed in on Backporting isn't always easy and doesn't always apply cleanly. It's not as simple as "mirroring master" - it's taking a single commit from the master branch and applying it to the backport branch. As you are aware, the velocity of change in the repo has increased quite a bit. It's easy to get conflicts when backporting and you need to take care with what you are doing. I think it's important to still have approvals for these kinds of PRs. They shouldn't just be allowed to land without review. |
| BinaryHTTPEmitter, | ||
| StructuredHTTPReceiver, | ||
| BinaryHTTPReceiver, | ||
| Cloudevent: event, |
grant
left a comment
There was a problem hiding this comment.
Merging into cloudevents:v1.x.y looks fine.
This commit modifies both of the 1.0 emitters so that they may
accept typed objects as a part of the configuration. When using
mTLS in Node, you need to provide an
Agentto the underlyingHTTP handler. In this case, Axios will pass this object along to
Node.js when it is provided.
Landed in: 3a063d7
Pull Request: #53
Fixes: #48
Signed-off-by: Lance Ball lball@redhat.com