Skip to content

Commit

Permalink
Merge pull request #11 from ibm-bluemix-mobile-services/name-change
Browse files Browse the repository at this point in the history
add support for AppID as the VCAP name
  • Loading branch information
vitalymibm authored May 7, 2017
2 parents 0042657 + c8799b7 commit 6e7c763
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The `options` parameter is optional. If specified, it can contain:

* `cacheSize` The cache size, the default value is 10000;

The MCABackendStrategy is used for a backend application that is deployed on IBM Bluemix. It will validate the `authorization` header from an incoming request against the MCA server url specified in the VCAP_SERVICES variable, where the service name starts with `AdvancedMobileAccess`, for the `appId` extracted from VCAP_APPLICATION.
The MCABackendStrategy is used for a backend application that is deployed on IBM Bluemix. It will validate the `authorization` header from an incoming request against the MCA server url specified in the VCAP_SERVICES variable, where the service name starts with `AppID`, for the `appId` extracted from VCAP_APPLICATION.

### MCAResourceStrategy
```
Expand Down
53 changes: 27 additions & 26 deletions lib/util/filter-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,93 +11,94 @@
* 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.
* limitations under the License.
*/

var imfService;
var applicationId;

var FilterUtil = {};

FilterUtil.getJson = function(jsonData) {
FilterUtil.getJson = function (jsonData) {
var json = jsonData;
if (typeof jsonData == 'string') {
json = JSON.parse(jsonData);
json = JSON.parse (jsonData);
}

return json;
}

FilterUtil.clone = function(object) {
FilterUtil.clone = function (object) {
var cloneObj = {};

if (object) {
for(var prop in object) {
if (object) {
for (var prop in object) {
cloneObj[prop] = object[prop];
}
}
return cloneObj;
}

FilterUtil.getEnvProperty = function(propName,defaultValue) {
FilterUtil.getEnvProperty = function (propName, defaultValue) {
var result = process.env[propName] || defaultValue;
if (result) {
result = result.trim();
result = result.trim ();
}

return result;
}

FilterUtil.getAppIdFromUrl = function(url) {
FilterUtil.getAppIdFromUrl = function (url) {
var result = null;
var reg = /([0-9,a-f]{8}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{4}-[0-9,a-f]{12}){1}/ig;
if (url) {
var matches = url.match(reg);
result = matches && matches.length>0 && matches[0];
var matches = url.match (reg);
result = matches && matches.length > 0 && matches[0];
}

return result;
}

FilterUtil.getApplicationIdFromVcap = function() {
if (! applicationId) {
var imfService = getImfService();
FilterUtil.getApplicationIdFromVcap = function () {
if (!applicationId) {
var imfService = getImfService ();
applicationId = imfService && imfService['credentials'] && imfService['credentials']['tenantId'];
}
return applicationId;
}

FilterUtil.getServerUrlFromVcap = function() {
var imfService = getImfService();
FilterUtil.getServerUrlFromVcap = function () {
var imfService = getImfService ();
var serverUrl = imfService && imfService['credentials'] && imfService['credentials']['serverUrl'];

return serverUrl;
}

FilterUtil.getArrayFromString = function(value,delim) {
FilterUtil.getArrayFromString = function (value, delim) {
var array = [];
if (value) {
var a = value.split(delim);
if (a && a.length>0) {
a.forEach(function(item){
array.push(item.trim());
var a = value.split (delim);
if (a && a.length > 0) {
a.forEach (function (item) {
array.push (item.trim ());
});
}
}
return array;
}

FilterUtil.getMcaServiceCredentials = function (){
var mcaServiceInfo = getImfService();
FilterUtil.getMcaServiceCredentials = function () {
var mcaServiceInfo = getImfService ();
var credentials = mcaServiceInfo && mcaServiceInfo["credentials"];
return credentials;
}

function getImfService() {
function getImfService () {
if (!imfService) {
var vcapServices = FilterUtil.getJson(process.env['VCAP_SERVICES']);
var vcapServices = FilterUtil.getJson (process.env['VCAP_SERVICES']);
for (var prop in vcapServices) {
if (prop.indexOf('AdvancedMobileAccess') == 0 && vcapServices[prop].length > 0) {
if (prop.indexOf ('AdvancedMobileAccess') === 0 && vcapServices[prop].length > 0 ||
prop.indexOf ('AppID') === 0 && vcapServices[prop].length > 0) {
imfService = vcapServices[prop][0];
}
}
Expand Down

0 comments on commit 6e7c763

Please sign in to comment.