diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fef13ef2d2249f6cb2e84092c31acb1d14f8da6a..fc9104e3d9bc5184a863e9538cbc52d3484d7bb4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,59 @@ # Note that environment variables can be set in several places # See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence stages: -- test + - test + - build + - publish + sast: stage: test include: -- template: Security/SAST.gitlab-ci.yml + - template: Security/SAST.gitlab-ci.yml + +build-dev: + image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 + stage: build + before_script: + - apk add git + - apk add bash + script: + - yarn + - yarn build-dev + - git config --global user.name build-pipeline + - git config --global user.email "$GIT_USER" + - git config --global user.password "$GIT_PWD" + - git config user.email "$GIT_USER" + - git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/llle_project/enedis-sge-konnector.git + - git config --global credential.helper store + - yarn deploy-dev + only: + - dev + +build: + image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/node:16.14.2-alpine3.14 + stage: build + before_script: + - apk add git + - apk add bash + script: + - yarn + - yarn build + - git config --global user.name build-pipeline + - git config --global user.email "$GIT_USER" + - git config --global user.password "$GIT_PWD" + - git config user.email "$GIT_USER" + - git remote set-url origin https://"$GIT_USER":"$GIT_PWD"@forge.grandlyon.com/web-et-numerique/llle_project/enedis-sge-konnector.git + - git config --global credential.helper store + - yarn deploy + only: + - master + +publish: + stage: publish + before_script: + - apk add git + script: + - yarn cozyPublish + only: + - tags + when: manual diff --git a/manifest.konnector b/manifest.konnector index 4196b41f2d5a992ab20dd690dd8be1d5af580213..29b0c77bead9cd9dd2974da94c17a0ea97df0a0a 100644 --- a/manifest.konnector +++ b/manifest.konnector @@ -11,6 +11,15 @@ "categories": ["energy"], "frequency": "daily", "fields": { + "wso2BaseUrl": { + "type": "hidden" + }, + "loginUtilisateur": { + "type": "hidden" + }, + "apiToken": { + "type": "hidden" + }, "pdl": { "type": "text" }, @@ -26,7 +35,8 @@ "screenshots": [], "permissions": { "accounts": { - "type": "io.cozy.accounts" + "type": "io.cozy.accounts", + "verbs": ["GET"] }, "enedis data": { "type": "com.grandlyon.enedis.*" diff --git a/src/index.js b/src/index.js index 262dae5f3b81c3820e235900d9795826a766289b..da6036cadbeccc46ea3f7519d2e0d174a30ff363 100644 --- a/src/index.js +++ b/src/index.js @@ -134,16 +134,7 @@ async function getData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - // If start date exceed the maximum amount of data we can get with one query - // get only 24 month - if (moment(endDate).diff(startDailyDate, 'months', true) > 24) { - log( - 'info', - 'Start date exceed 24 month, setting start date to current date minus 24 month' - ) - startDailyDate = moment(endDate).subtract(24, 'month') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - } + setStartDate() const { response } = await soapRequest({ url: url, @@ -185,16 +176,7 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { apikey: apiAuthKey, } - // If start date exceed the maximum amount of data we can get with one query - // get only 24 month - if (moment(endDate).diff(startDailyDate, 'months', true) > 24) { - log( - 'info', - 'Start date exceed 24 month, setting start date to current date minus 24 month' - ) - startDailyDate = moment(endDate).subtract(24, 'month') - startDailyDateString = startDailyDate.format('YYYY-MM-DD') - } + setStartDate() const { response } = await soapRequest({ url: url, @@ -217,6 +199,21 @@ async function getMaxPowerData(url, apiAuthKey, userLogin, pointId) { ) } +/** + * If start date exceed the maximum amount of data we can get with one query + * get only 36 month + */ +function setStartDate() { + if (moment(endDate).diff(startDailyDate, 'months', true) > 36) { + log( + 'info', + 'Start date exceed 36 month, setting start date to current date minus 36 month' + ) + startDailyDate = moment(endDate).subtract(36, 'month') + startDailyDateString = startDailyDate.format('YYYY-MM-DD') + } +} + /** * Get half-hour data * @param {string} url