forked from cloudevents/sdk-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support mTLS in 1.0 Binary and Structured emitters
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>
- Loading branch information
Showing
4 changed files
with
72 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,23 @@ | ||
var axios = require("axios"); | ||
|
||
const Constants = require("./constants.js"); | ||
const defaults = {}; | ||
defaults[Constants.HEADERS] = {}; | ||
defaults[Constants.HEADERS][Constants.HEADER_CONTENT_TYPE] = Constants.DEFAULT_CE_CONTENT_TYPE; | ||
|
||
function StructuredHTTPEmitter(configuration){ | ||
this.config = JSON.parse(JSON.stringify(configuration)); | ||
|
||
this.config[Constants.HEADERS] = | ||
(!this.config[Constants.HEADERS] | ||
? {} | ||
: this.config[Constants.HEADERS]); | ||
|
||
if(!this.config[Constants.HEADERS][Constants.HEADER_CONTENT_TYPE]){ | ||
this.config[Constants.HEADERS][Constants.HEADER_CONTENT_TYPE] = | ||
Constants.DEFAULT_CE_CONTENT_TYPE; | ||
} | ||
this.config = Object.assign({}, defaults, configuration); | ||
} | ||
|
||
StructuredHTTPEmitter.prototype.emit = function(cloudevent) { | ||
// Create new request object | ||
var _config = JSON.parse(JSON.stringify(this.config)); | ||
|
||
StructuredHTTPEmitter.prototype.emit = function (cloudevent) { | ||
// Set the cloudevent payload | ||
_config[Constants.DATA_ATTRIBUTE] = cloudevent.format(); | ||
this.config[Constants.DATA_ATTRIBUTE] = cloudevent.format(); | ||
|
||
// Return the Promise | ||
return axios.request(_config); | ||
return axios.request(this.config).then(response => { | ||
delete this.config[Constants.DATA_ATTRIBUTE]; | ||
return response; | ||
}); | ||
}; | ||
|
||
module.exports = StructuredHTTPEmitter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters