From ea9f06c8874f232632022d6114612e47dad99b52 Mon Sep 17 00:00:00 2001 From: gcarron <gcarron@grandlyon.com> Date: Mon, 26 Sep 2022 14:40:30 +0200 Subject: [PATCH] publish: Merge branch 'fix/onDeleteIssue' of https://forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector into feat/US858-Save-expiration-date generated from commit 56459d1cb71f7574d66f8405015e875609229208 --- index.js | 24 ++++++++++++++++-- onDeleteAccount.js | 63 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 69 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 79e0665..b5b9117 100644 --- a/index.js +++ b/index.js @@ -161,6 +161,7 @@ async function start(fields, cozyParameters) { contractEndDate ) } + console.log('testgf') consent = await updateBoConsent( boBaseUrl, boToken, @@ -228531,7 +228532,18 @@ async function getAccount(accountId) { )[0] } -module.exports = { getAccount, saveAccountData } +async function getAccountForDelete(accountId, accountRev) { + log('info', `getAccountForDelete: ${accountId} ${accountRev}`) + const body = await cozyClient.fetchJSON( + 'GET', + `/data/io.cozy.accounts/${accountId}?rev=${accountRev}` + ) + + log('debug', `getAccountForDelete: ${body}`) + return body +} + +module.exports = { getAccount, saveAccountData, getAccountForDelete } /***/ }), @@ -228546,7 +228558,15 @@ function isLocal() { ) } -module.exports = { isLocal } +/** + * Verify if it's an alpha URL + * @returns {boolean} + */ +function isAlpha() { + return process.env.COZY_URL.includes('alpha') +} + +module.exports = { isLocal, isAlpha } /***/ }) diff --git a/onDeleteAccount.js b/onDeleteAccount.js index 37f98e3..b77b00b 100644 --- a/onDeleteAccount.js +++ b/onDeleteAccount.js @@ -227431,7 +227431,18 @@ async function getAccount(accountId) { )[0] } -module.exports = { getAccount, saveAccountData } +async function getAccountForDelete(accountId, accountRev) { + log('info', `getAccountForDelete: ${accountId} ${accountRev}`) + const body = await cozyClient.fetchJSON( + 'GET', + `/data/io.cozy.accounts/${accountId}?rev=${accountRev}` + ) + + log('debug', `getAccountForDelete: ${body}`) + return body +} + +module.exports = { getAccount, saveAccountData, getAccountForDelete } /***/ }), @@ -227446,7 +227457,15 @@ function isLocal() { ) } -module.exports = { isLocal } +/** + * Verify if it's an alpha URL + * @returns {boolean} + */ +function isAlpha() { + return process.env.COZY_URL.includes('alpha') +} + +module.exports = { isLocal, isAlpha } /***/ }), @@ -227455,28 +227474,33 @@ module.exports = { isLocal } // @ts-check const { log, errors } = __webpack_require__(1) -const { getAccountRev, getAccountSecret } = __webpack_require__(1607) +const { + getAccountRev, + getAccountSecret, + getAccountId, +} = __webpack_require__(1607) const { getBoConsent, deleteBoConsent } = __webpack_require__(1557) const { terminateContract } = __webpack_require__(1598) -const { getAccount } = __webpack_require__(1604) +const { getAccountForDelete } = __webpack_require__(1604) const moment = __webpack_require__(1373) __webpack_require__(1510) moment.locale('fr') // set the language moment.tz.setDefault('Europe/Paris') // set the timezone -const { isLocal } = __webpack_require__(1605) -const ACCOUNT_ID = isLocal() ? 'default_account_id' : 'enedis-sge-grandlyon' +const { isLocal, isAlpha } = __webpack_require__(1605) +// const ACCOUNT_ID = isLocal() ? 'default_account_id' : 'enedis-sge-grandlyon' async function onDeleteAccount() { log('info', 'Deleting account ...') log('info', 'Getting secrets ...') - + const ACCOUNT_ID = getAccountId() const accountRev = getAccountRev() if (accountRev) { log('info', 'Account rev exist') - const accountData = await getAccount(ACCOUNT_ID) + const accountData = await getAccountForDelete(ACCOUNT_ID, accountRev) // Parse local info for deletion test if (isLocal()) { + log('warn', 'Local run') const fields = JSON.parse( process.env.COZY_FIELDS ? process.env.COZY_FIELDS : '{}' ) @@ -227492,6 +227516,8 @@ async function onDeleteAccount() { accountData.data.consentId ) + log('info', `isAlpha: ${isAlpha()}`) + log('info', `userConsent: ${JSON.stringify(userConsent)}`) if (userConsent.ID && userConsent.pointID) { log('log', `Consent ${userConsent.ID} found for user`) if (userConsent.serviceID) { @@ -227500,14 +227526,17 @@ async function onDeleteAccount() { secrets.boToken, userConsent.ID ) - await terminateContract( - secrets.wso2BaseUrl, - secrets.apiToken, - secrets.sgeLogin, - secrets.contractId, - userConsent.pointID, - userConsent.serviceID - ) + // Verify if it's dev env to prevent delete of real data + if (!isAlpha()) { + await terminateContract( + secrets.wso2BaseUrl, + secrets.apiToken, + secrets.sgeLogin, + secrets.contractId, + userConsent.pointID, + userConsent.serviceID + ) + } } else { log('error', `No service id retrieved from BO`) throw errors.VENDOR_DOWN @@ -227558,6 +227587,7 @@ function getAccountId() { function getAccountRev() { log('info', `getAccountRev`) + log('info', `getAccountRev: ${JSON.stringify(process.env.COZY_FIELDS)}`) try { return isLocal() ? 'fakeAccountRev' @@ -227573,6 +227603,7 @@ function getAccountRev() { * @returns {Fields} */ function getAccountSecret() { + log('info', `getAccountSecret`) try { return isLocal() ? JSON.parse(process.env.COZY_FIELDS) -- GitLab