From 27f05c227bec699b924ca7e24a77b731bba0205d Mon Sep 17 00:00:00 2001 From: dhaneesh Date: Tue, 9 Oct 2018 14:21:45 +0530 Subject: [PATCH] supportting old key separator --- bin/common.js | 15 ++++++++++++ bin/here-geocode.js | 38 ++++++++++++++++------------- bin/here-xyz.js | 58 ++++++++++++++++++++++++--------------------- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/bin/common.js b/bin/common.js index 81ca839..db3ab22 100644 --- a/bin/common.js +++ b/bin/common.js @@ -225,6 +225,20 @@ function extractData(fields, data) { } return outArr; } + +function getSplittedKeys(inString){ + if(inString.indexOf(keySeparator)!=-1){ + return inString.split(keySeparator); + }else { + //Backward support for old separator + const tokens = inString.split("-"); + if(tokens.length==2){ + return tokens; + }else{ + return null; + } + } +} module.exports.drawTable = drawTable; module.exports.timeStampToLocaleString = timeStampToLocaleString; module.exports.md5Sum = md5Sum; @@ -235,5 +249,6 @@ module.exports.decryptAndGet=decryptAndGet; module.exports.encryptAndStore=encryptAndStore; module.exports.hereAccountLogin=hereAccountLogin; module.exports.keySeparator=keySeparator; +module.exports.getSplittedKeys=getSplittedKeys; module.exports.xyzRoot = function() {return xyzRoot} diff --git a/bin/here-geocode.js b/bin/here-geocode.js index 238081e..32a0562 100644 --- a/bin/here-geocode.js +++ b/bin/here-geocode.js @@ -46,23 +46,27 @@ function toFeature(result){ function geoCode(locationString){ common.decryptAndGet("appDetails").then((dataStr) =>{ - const appInfo = dataStr.split(common.keySeparator); - var geocodeURL = 'https://geocoder.cit.api.here.com/6.2/geocode.json' + - '?app_id=' + appInfo[0] + - '&app_code=' + appInfo[1] + - '&searchtext=' + locationString; - request.get(geocodeURL, (error, response, body) => { - if (error) - throw error; - if (response.statusCode !== 200) - throw new Error(response.body); - let geocodeJson = JSON.parse(body); - if(geocodeJson.Response.View.length==0){ - console.log("Could not geocode the place '"+locationString+"'"); - }else{ - console.log(JSON.stringify(toGeoJson(geocodeJson),null,2)); - } - }); + const appInfo = common.getSplittedKeys(dataStr); + if(appInfo){ + var geocodeURL = 'https://geocoder.cit.api.here.com/6.2/geocode.json' + + '?app_id=' + appInfo[0] + + '&app_code=' + appInfo[1] + + '&searchtext=' + locationString; + request.get(geocodeURL, (error, response, body) => { + if (error) + throw error; + if (response.statusCode !== 200) + throw new Error(response.body); + let geocodeJson = JSON.parse(body); + if(geocodeJson.Response.View.length==0){ + console.log("Could not geocode the place '"+locationString+"'"); + }else{ + console.log(JSON.stringify(toGeoJson(geocodeJson),null,2)); + } + }); + }else{ + console.log("Account information needs to be updated. Retry after executing the command 'here configure'."); + } }).catch(function (error) { console.log(error.message); }); diff --git a/bin/here-xyz.js b/bin/here-xyz.js index 1b51a62..1641c3a 100755 --- a/bin/here-xyz.js +++ b/bin/here-xyz.js @@ -448,33 +448,37 @@ program .action(function (id) { common.decryptAndGet("accountInfo","No here account configure found. Try running 'here configure account'").then((dataStr) =>{ if(dataStr){ - const appInfo = dataStr.split(common.keySeparator); - sso.executeWithCookie(appInfo[0],appInfo[1]).then(cookie=>{ - const options = { - url: common.xyzRoot()+"/token-api/token", - method: 'GET', - headers: { - "Cookie":cookie, - "Content-Type":"application/json" - } - }; - return new Promise(function(resolve, reject) { - request(options, function(error, response, body) { - var statusCode = response && response.statusCode; - if (statusCode != 200) { - reject(new Error("Error while fetching maxrights :"+body)); - }else{ - var tokenInfo = JSON.parse(body); - common.decryptAndGet("keyInfo","No token found").then((currentToken) =>{ - console.log("===================================================="); - console.log("Current CLI token is : "+currentToken); - console.log("===================================================="); - common.drawTable(tokenInfo.tokens,["id","type","iat","description"]); - }); - } - }); - }); - }); + const appInfo = common.getSplittedKeys(dataStr); + if(appInfo){ + sso.executeWithCookie(appInfo[0],appInfo[1]).then(cookie=>{ + const options = { + url: common.xyzRoot()+"/token-api/token", + method: 'GET', + headers: { + "Cookie":cookie, + "Content-Type":"application/json" + } + }; + return new Promise(function(resolve, reject) { + request(options, function(error, response, body) { + var statusCode = response && response.statusCode; + if (statusCode != 200) { + reject(new Error("Error while fetching maxrights :"+body)); + }else{ + var tokenInfo = JSON.parse(body); + common.decryptAndGet("keyInfo","No token found").then((currentToken) =>{ + console.log("===================================================="); + console.log("Current CLI token is : "+currentToken); + console.log("===================================================="); + common.drawTable(tokenInfo.tokens,["id","type","iat","description"]); + }); + } + }); + }); + }); + }else{ + console.log("Account information needs to be updated. Retry after executing the command 'here configure account'."); + } } }); });