Skip to content

Commit

Permalink
feat: Added additional option to getCognos: ignoreInvalidCertificates
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Removed options parameter from uploadExtension
  • Loading branch information
batje committed Jul 11, 2019
1 parent b3af602 commit 4c21b2f
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 102 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ retrieve the Cognos instance.

- `debug`
- `timeout`
- `ignoreInvalidCertificates`

### capabilities

Expand Down Expand Up @@ -233,7 +234,6 @@ This function is only supported by Node.js. In the browser this function returns
- `filename` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to the .zip file
- `name` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** name of the module (as found in the spec.json)
- `type` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** type of upload. Default is 'extensions', for themes use 'themes'. (optional, default `'extensions'`)
- `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object with additional options. sslcheck = true/false checks valid certificates or not. (optional, default `{}`)

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise that resolves to a string.

Expand All @@ -253,7 +253,9 @@ at any time.
- `url` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The URL of your Cognos installation. If empty, this function becomes static and a Promise for the current jCognos object is returned. (optional, default `false`)
- `debug` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If true, starts debugging into the console (optional, default `false`)
- `timeout` (optional, default `60000`)
- `ignoreInvalidCertificates` (optional, default `false`)
- `Timeout` **[Number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** value for http(s) connections. In milliseconds. Default is 60000.
- `ignoreinvalidcertificates` **[Boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Should invalid certificates over ssl be ignored. Default = false

Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)** a promise that will return the jCognos object

Expand Down
57 changes: 35 additions & 22 deletions dist/jcognos.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var Utils = {
var cRequest;

var CognosRequest = (function() {
function CognosRequest(url, debug, timeout) {
function CognosRequest(url, debug, timeout, ignoreinvalidcertificates) {
_classCallCheck(this, CognosRequest);

if (url.substr(-1) !== '/') {
Expand All @@ -96,6 +96,7 @@ var CognosRequest = (function() {
this.namespace = '';
this.namespaces = [];
this.timeout = timeout;
this.ignoreinvalidcertificates = ignoreinvalidcertificates;
}

_createClass(CognosRequest, [
Expand Down Expand Up @@ -133,11 +134,19 @@ var CognosRequest = (function() {
var me = this;
var cookieJar = false;
var firstheaders = {};
this.axios = axios.create({
var axiosparams = {
timeout: me.timeout,
maxRedirects: 10,
maxContentLength: 50 * 1000 * 1000
});
};

if (this.ignoreinvalidcertificates) {
axiosparams.httpsAgent = new https.Agent({
rejectUnauthorized: false
});
}

this.axios = axios.create(axiosparams);

if (Utils.isNode()) {
axiosCookieJarSupport(this.axios);
Expand Down Expand Up @@ -486,10 +495,8 @@ var CognosRequest = (function() {
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: {};
var options = arguments.length > 3 ? arguments[3] : undefined;
var me = this;
var stream;
var checkssl = options.checkssl ? options.checkssl : false;

if (Utils.isStandardBrowserEnv()) {
console.log(
Expand Down Expand Up @@ -536,13 +543,6 @@ var CognosRequest = (function() {
withCredentials: true,
data: stream
};

if (checkssl) {
axiosparams.httpsAgent = new https.Agent({
rejectUnauthorized: false
});
}

var result = me
.axios(axiosparams)
.then(function(response) {
Expand Down Expand Up @@ -722,6 +722,8 @@ function getCognosRequest(url, debug) {
var reset =
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var timeout = arguments.length > 3 ? arguments[3] : undefined;
var ignoreinvalidcertificates =
arguments.length > 4 ? arguments[4] : undefined;

if (reset) {
cRequest = undefined;
Expand All @@ -730,7 +732,12 @@ function getCognosRequest(url, debug) {
var result;

if (typeof cRequest == 'undefined' || reset) {
cRequest = new CognosRequest(url, debug, timeout);
cRequest = new CognosRequest(
url,
debug,
timeout,
ignoreinvalidcertificates
);
result = cRequest.initialise();
} else {
result = Promise.resolve(cRequest);
Expand All @@ -743,7 +750,7 @@ var jCognos;
var cognosUrl;

var Cognos = (function() {
function Cognos(debug, timeout) {
function Cognos(debug, timeout, ignoreInvalidCertificates) {
_classCallCheck(this, Cognos);

this.loggedin = false;
Expand All @@ -753,6 +760,7 @@ var Cognos = (function() {
this.password = '';
this.timeout = timeout;
this.productVersion = '';
this.ignoreInvalidCertificates;
this.capabilities = {};
this.preferences = {};
this.defaultNamespace = '';
Expand Down Expand Up @@ -952,7 +960,8 @@ var Cognos = (function() {
this.url,
this.debug,
true,
this.timeout
this.timeout,
this.ignoreInvalidCertificates
)
.then(function(cRequest) {
me.requester = cRequest;
Expand Down Expand Up @@ -1352,14 +1361,10 @@ var Cognos = (function() {
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: 'extensions';
var options =
arguments.length > 3 && arguments[3] !== undefined
? arguments[3]
: {};
var me = this;
var path = 'bi/v1/plugins/' + type + '/' + name;
var result = this.requester
.put(path, filename, false, options)
.put(path, filename, false)
.then(function(response) {
me.log('New extension id =' + response.id);
})
Expand Down Expand Up @@ -1548,6 +1553,8 @@ function getCognos() {
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var timeout =
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 60000;
var ignoreInvalidCertificates =
arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var reset = false;

if (url && url !== cognosUrl) {
Expand All @@ -1556,9 +1563,15 @@ function getCognos() {
}

if (typeof jCognos == 'undefined' && url) {
var myRequest = getCognosRequest(url, debug, reset, timeout)
var myRequest = getCognosRequest(
url,
debug,
reset,
timeout,
ignoreInvalidCertificates
)
.then(function(cRequest) {
jCognos = new Cognos(debug, timeout);
jCognos = new Cognos(debug, timeout, ignoreInvalidCertificates);
jCognos.requester = cRequest;
jCognos.url = url;
jCognos.defaultNamespace = cRequest.namespace;
Expand Down
57 changes: 35 additions & 22 deletions dist/jcognos.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var Utils = {
var cRequest;

var CognosRequest = (function() {
function CognosRequest(url, debug, timeout) {
function CognosRequest(url, debug, timeout, ignoreinvalidcertificates) {
_classCallCheck(this, CognosRequest);

if (url.substr(-1) !== '/') {
Expand All @@ -88,6 +88,7 @@ var CognosRequest = (function() {
this.namespace = '';
this.namespaces = [];
this.timeout = timeout;
this.ignoreinvalidcertificates = ignoreinvalidcertificates;
}

_createClass(CognosRequest, [
Expand Down Expand Up @@ -125,11 +126,19 @@ var CognosRequest = (function() {
var me = this;
var cookieJar = false;
var firstheaders = {};
this.axios = axios.create({
var axiosparams = {
timeout: me.timeout,
maxRedirects: 10,
maxContentLength: 50 * 1000 * 1000
});
};

if (this.ignoreinvalidcertificates) {
axiosparams.httpsAgent = new https.Agent({
rejectUnauthorized: false
});
}

this.axios = axios.create(axiosparams);

if (Utils.isNode()) {
axiosCookieJarSupport(this.axios);
Expand Down Expand Up @@ -478,10 +487,8 @@ var CognosRequest = (function() {
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: {};
var options = arguments.length > 3 ? arguments[3] : undefined;
var me = this;
var stream;
var checkssl = options.checkssl ? options.checkssl : false;

if (Utils.isStandardBrowserEnv()) {
console.log(
Expand Down Expand Up @@ -528,13 +535,6 @@ var CognosRequest = (function() {
withCredentials: true,
data: stream
};

if (checkssl) {
axiosparams.httpsAgent = new https.Agent({
rejectUnauthorized: false
});
}

var result = me
.axios(axiosparams)
.then(function(response) {
Expand Down Expand Up @@ -714,6 +714,8 @@ function getCognosRequest(url, debug) {
var reset =
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var timeout = arguments.length > 3 ? arguments[3] : undefined;
var ignoreinvalidcertificates =
arguments.length > 4 ? arguments[4] : undefined;

if (reset) {
cRequest = undefined;
Expand All @@ -722,7 +724,12 @@ function getCognosRequest(url, debug) {
var result;

if (typeof cRequest == 'undefined' || reset) {
cRequest = new CognosRequest(url, debug, timeout);
cRequest = new CognosRequest(
url,
debug,
timeout,
ignoreinvalidcertificates
);
result = cRequest.initialise();
} else {
result = Promise.resolve(cRequest);
Expand All @@ -735,7 +742,7 @@ var jCognos;
var cognosUrl;

var Cognos = (function() {
function Cognos(debug, timeout) {
function Cognos(debug, timeout, ignoreInvalidCertificates) {
_classCallCheck(this, Cognos);

this.loggedin = false;
Expand All @@ -745,6 +752,7 @@ var Cognos = (function() {
this.password = '';
this.timeout = timeout;
this.productVersion = '';
this.ignoreInvalidCertificates;
this.capabilities = {};
this.preferences = {};
this.defaultNamespace = '';
Expand Down Expand Up @@ -944,7 +952,8 @@ var Cognos = (function() {
this.url,
this.debug,
true,
this.timeout
this.timeout,
this.ignoreInvalidCertificates
)
.then(function(cRequest) {
me.requester = cRequest;
Expand Down Expand Up @@ -1344,14 +1353,10 @@ var Cognos = (function() {
arguments.length > 2 && arguments[2] !== undefined
? arguments[2]
: 'extensions';
var options =
arguments.length > 3 && arguments[3] !== undefined
? arguments[3]
: {};
var me = this;
var path = 'bi/v1/plugins/' + type + '/' + name;
var result = this.requester
.put(path, filename, false, options)
.put(path, filename, false)
.then(function(response) {
me.log('New extension id =' + response.id);
})
Expand Down Expand Up @@ -1540,6 +1545,8 @@ function getCognos() {
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var timeout =
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 60000;
var ignoreInvalidCertificates =
arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var reset = false;

if (url && url !== cognosUrl) {
Expand All @@ -1548,9 +1555,15 @@ function getCognos() {
}

if (typeof jCognos == 'undefined' && url) {
var myRequest = getCognosRequest(url, debug, reset, timeout)
var myRequest = getCognosRequest(
url,
debug,
reset,
timeout,
ignoreInvalidCertificates
)
.then(function(cRequest) {
jCognos = new Cognos(debug, timeout);
jCognos = new Cognos(debug, timeout, ignoreInvalidCertificates);
jCognos.requester = cRequest;
jCognos.url = url;
jCognos.defaultNamespace = cRequest.namespace;
Expand Down
Loading

0 comments on commit 4c21b2f

Please sign in to comment.