From cb5a9dfe612f83539d50270eefa67da118af0697 Mon Sep 17 00:00:00 2001
From: i-vall <ivallanzasca@gmail.com>
Date: Thu, 18 Jul 2019 13:15:28 +0200
Subject: [PATCH] publish: fix: correct use of COZY_PARAMETERS env. variable

generated from commit 78b110d700ffbb572b65615d785e4eac19f4b362
---
 index.js | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/index.js b/index.js
index c867ba2..9ed44e3 100644
--- a/index.js
+++ b/index.js
@@ -134,23 +134,28 @@ const moment = __webpack_require__(1045)
 //const moment = require('moment')
 //require('request-debug')(rp)
 
-const baseUrl = process.env.COZY_PARAMETERS.eglBaseURL
-const apiAuthKey = process.env.COZY_PARAMETERS.eglAPIAuthKey
-
 module.exports = new BaseKonnector(start)
 
 // The start function is run by the BaseKonnector instance only when it got all the account
 // information (fields). When you run this connector yourself in "standalone" mode or "dev" mode,
 // the account information come from ./konnector-dev-config.json file
-async function start(fields) {
+async function start(fields, cozyParameters) {
   try {
     // resetting data for demo only
     // await resetData()
+    const baseUrl = cozyParameters.secret.eglBaseURL
+    const apiAuthKey = cozyParameters.secret.eglAPIAuthKey
+
     log('info', 'Authenticating ...')
-    const response = await authenticate(fields.login, fields.password)
+    const response = await authenticate(
+      fields.login,
+      fields.password,
+      baseUrl,
+      apiAuthKey
+    )
     log('info', 'Successfully logged in')
     log('info', 'Getting data')
-    const loadProfile = await getData(response)
+    const loadProfile = await getData(response, baseUrl, apiAuthKey)
     log('info', 'Saving data to Cozy')
     storeLoadProfile(loadProfile)
   } catch (error) {
@@ -158,7 +163,7 @@ async function start(fields) {
   }
 }
 
-async function authenticate(login, password) {
+async function authenticate(login, password, baseUrl, apiAuthKey) {
   const authRequest = {
     method: 'POST',
     uri: baseUrl + '/connect.aspx',
@@ -184,7 +189,7 @@ async function authenticate(login, password) {
   }
 }
 
-async function getData(response) {
+async function getData(response, baseUrl, apiAuthKey) {
   const dataRequest = {
     method: 'POST',
     uri: baseUrl + '/getAllAgregatsByAbonnement.aspx',
-- 
GitLab