@fortify/bsi-token-parser
Version:
A parsing library for using Build Server Integration tokens from the Fortify on Demand portal.
96 lines (95 loc) • 4.45 kB
JavaScript
/*!
* (c) Copyright 2017 EntIT Software LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "url-parse", "js-base64"], factory);
}
})(function (require, exports) {
"use strict";
exports.__esModule = true;
var urlParse = require("url-parse");
var js_base64_1 = require("js-base64");
var BsiTokenParser = (function () {
function BsiTokenParser() {
}
BsiTokenParser.prototype.parse = function (token) {
var trimmedToken = token.trim();
if (trimmedToken.indexOf('/bsi2.aspx?') >= 0) {
return this.parseLegacyUrl(token);
}
else {
return this.parseBsiToken(token);
}
};
BsiTokenParser.prototype.parseLegacyUrl = function (urlString) {
var url = urlParse(urlString, true);
var baseUri = null;
if (url.protocol && url.host) {
baseUri = url.protocol + "//" + url.host;
}
var token = {
apiUri: baseUri || BsiTokenParser._tokenDefaults.apiUri,
portalUri: BsiTokenParser._tokenDefaults.portalUri,
tenantId: parseInt(url.query['tid']),
tenantCode: url.query['tc'],
assessmentTypeId: parseInt(url.query['astid']),
payloadType: url.query['payloadType'],
releaseId: parseInt(url.query['pv']),
technologyType: url.query['ts'],
technologyVersion: url.query['ll'] || BsiTokenParser._tokenDefaults.technologyVersion,
includeOpenSourceAnalysis: BsiTokenParser._tokenDefaults.includeOpenSourceAnalysis,
auditPreference: BsiTokenParser._tokenDefaults.auditPreference,
auditPreferenceId: BsiTokenParser._tokenDefaults.auditPreferenceId,
includeThirdParty: BsiTokenParser._tokenDefaults.includeThirdParty,
scanPreference: BsiTokenParser._tokenDefaults.scanPreference,
scanPreferenceId: BsiTokenParser._tokenDefaults.scanPreferenceId,
technologyTypeId: BsiTokenParser._tokenDefaults.technologyTypeId,
technologyVersionId: BsiTokenParser._tokenDefaults.technologyVersionId
};
return token;
};
BsiTokenParser.prototype.parseBsiToken = function (encodedToken) {
var decodedToken = JSON.parse(js_base64_1.Base64.decode(encodedToken));
if (decodedToken.scanPreference === '0') {
decodedToken.scanPreference = BsiTokenParser._tokenDefaults.scanPreference;
}
decodedToken.scanPreferenceId = decodedToken.scanPreferenceId || BsiTokenParser._tokenDefaults.scanPreferenceId;
return decodedToken;
};
BsiTokenParser._tokenDefaults = {
tenantId: 0,
tenantCode: '',
releaseId: 0,
assessmentTypeId: 0,
payloadType: 'ANALYSIS_PAYLOAD',
scanPreferenceId: 1,
scanPreference: 'Standard',
auditPreferenceId: 1,
auditPreference: 'Manual',
includeThirdParty: false,
includeOpenSourceAnalysis: false,
portalUri: 'https://ams.fortify.com',
apiUri: 'https://api.ams.fortify.com',
technologyTypeId: 0,
technologyType: null,
technologyVersionId: null,
technologyVersion: null
};
return BsiTokenParser;
}());
exports.BsiTokenParser = BsiTokenParser;
});