Skip to content
Snippets Groups Projects
Commit fbda1243 authored by Yoan VALLET's avatar Yoan VALLET
Browse files

feat: script for accounts & triggers creation

parent aac5e0f3
No related branches found
No related tags found
1 merge request!113Features/us221 report view creation
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/camelcase */
const axios = require('axios')
const headers = {
Accept: 'application/json',
Authorization:
'Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcHAiLCJpYXQiOjE2MDIyNTExMTEsImlzcyI6ImNvenkudG9vbHM6ODA4MCIsInN1YiI6ImVjb2x5byIsInNlc3Npb25faWQiOiIzZWQ4MzJjZWM2N2U2ZTBiMmM2MzgyZWRkMzAwYTM0MSJ9.vp7r-LxVrwtvSCxTv5NwGV_AJLozUKqFMhCrG3cLCSnU237dp7pCYOq-CXJRLiG2MvTFztPBEZ2-2Zda_aAT5A',
Cookie:
'cozysessid=AAAAAF-ALvszZWQ4MzJjZWM2N2U2ZTBiMmM2MzgyZWRkMzAwYTM0MYO4rN61eyNbWbrWXaZShPaUM8YPXSjKPqWA7MV1DQfs',
'content-type': 'application/json',
}
const dataEnedisAccount = JSON.stringify({
account_type: 'enedisgrandlyon',
name: '',
oauth: {
access_token: '',
expires_at: '2020-10-09T08:00:00.285910671+02:00',
refresh_token: '',
token_type: 'Bearer',
},
oauth_callback_results: {
issued_at: '1592232569642',
refresh_token_issued_at: '1592232569642',
scope:
'/v4/metering_data/production_load_curve.GET /v3/customers/usage_points/addresses.GET /v4/metering_data/consumption_load_curve.GET /v3/customers/usage_points/contracts.GET /v4/metering_data/daily_production.GET /v4/metering_data/daily_consumption.GET /v4/metering_data/daily_consumption_max_power.GET /v3/customers/identity.GET',
usage_points_id: '',
},
})
const dataGrdfAccount = JSON.stringify({
account_type: 'grdfgrandlyon',
auth: {
credentials_encrypted:
'bmFjbMKrNCS+4Liakxdu+xNu9I3sSyvda8iAp0o3U3OAymbIeoLhLtxPdsa+3mu/8yTnDudBcJo=',
login: 'test',
},
id: '89e68b8450cee09fe2f077610901094d',
identifier: 'login',
state: null,
})
const dataEglAccount = JSON.stringify({
account_type: 'eglgrandlyon',
auth: {
credentials_encrypted:
'bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=',
login: 'test',
},
id: '90e68b8450cee09fe2f077610901094d',
identifier: 'login',
state: null,
})
const dataEnedisTrigger = JSON.stringify({
data: {
attributes: {
_id: '3ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: '88e68b8450cee09fe2f077610901094d',
konnector: 'enedisgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
},
})
const dataGrdfTrigger = JSON.stringify({
data: {
attributes: {
_id: '4ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: '89e68b8450cee09fe2f077610901094d',
konnector: 'grdfgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
},
})
const dataEglTrigger = JSON.stringify({
data: {
attributes: {
_id: '5ed832cec67e6e0b2c6382edd30df11c',
domain: 'cozy.tools:8080',
prefix: 'cozy35ba44d2d1749e6f21646edce51e7190',
type: '@cron',
worker: 'konnector',
arguments: '0 47 8 * * *',
debounce: '',
options: null,
message: {
account: '90e68b8450cee09fe2f077610901094d',
konnector: 'eglgrandlyon',
},
cozyMetadata: {
doctypeVersion: '1',
metadataVersion: 1,
createdAt: '2020-10-09T08:00:00.6092798Z',
createdByApp: 'ecolyo',
updatedAt: '2020-10-09T08:00:00.6092798Z',
},
},
},
})
async function launch() {
// Enedis
await axios({
method: 'put',
url:
'http://cozy.tools:8080/data/io.cozy.accounts/88e68b8450cee09fe2f077610901094d',
headers: headers,
data: dataEnedisAccount,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataEnedisTrigger,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
// GRDF
await axios({
method: 'put',
url:
'http://cozy.tools:8080/data/io.cozy.accounts/89e68b8450cee09fe2f077610901094d',
headers: headers,
data: dataGrdfAccount,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataGrdfTrigger,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
// EGL
await axios({
method: 'put',
url:
'http://cozy.tools:8080/data/io.cozy.accounts/90e68b8450cee09fe2f077610901094d',
headers: headers,
data: dataEglAccount,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
await axios({
method: 'post',
url: 'http://cozy.tools:8080/jobs/triggers',
headers: headers,
data: dataEglTrigger,
})
.then(function(response) {
console.log(JSON.stringify(response.data))
})
.catch(function(error) {
console.log(error)
})
}
launch()
{"io.cozy.accounts":
[
{
"_id": "88e68b8450cee09fe2f077610901094d",
"account_type": "enedisgrandlyon",
"name": "",
"oauth": {
"access_token": "",
"expires_at": "2020-06-16T04:17:03.285910671+02:00",
"refresh_token": "",
"token_type": "Bearer"
},
"oauth_callback_results": {
"issued_at": "1592232569642",
"refresh_token_issued_at": "1592232569642",
"scope": "/v4/metering_data/production_load_curve.GET /v3/customers/usage_points/addresses.GET /v4/metering_data/consumption_load_curve.GET /v3/customers/usage_points/contracts.GET /v4/metering_data/daily_production.GET /v4/metering_data/daily_consumption.GET /v4/metering_data/daily_consumption_max_power.GET /v3/customers/identity.GET",
"usage_points_id": ""
}
},
{
"_id": "89e68b8450cee09fe2f077610901094d",
"account_type": "grdfgrandlyon",
"auth": {
"credentials_encrypted": "bmFjbI7TqHf7FTj8b6T8JyV7ORUSYjziwua6bnbh0P3CE/3dJ9G0w6GdtmhbuqxAgqiQS/uqrZw=",
"login": "test"
},
"identifier": "login",
"state": null
},
{
"_id": "90e68b8450cee09fe2f077610901094d",
"account_type": "eglgrandlyon",
"auth": {
"credentials_encrypted": "bmFjbHI5OoL+VNCT6JDFYea1dNiBGGNJM1zY0M4uWcjhALJcQT9uk9p9WPD7+1OryCAoYf9eaSE=",
"login": "test"
},
"identifier": "login",
"state": null
}
]
}
\ No newline at end of file
{"io.cozy.jobs":
[
{
"_id": "0813eafc594ef00e8e6b72167c0067a2",
"domain": "cozy.tools:8080",
"worker": "konnector",
"trigger_id": "0813eafc594ef00e8e6b72167c006480",
"message": {
"account": "88e68b8450cee09fe2f077610901094d",
"konnector": "enedisgrandlyon"
},
"event": null,
"manual_execution": true,
"state": "done",
"queued_at": "2020-10-09T08:00:00.0000000Z",
"started_at": "2020-10-09T08:00:00.0000000Z",
"finished_at": "2020-10-09T08:00:00.0000000Z"
},
{
"_id": "0823eafc594ef00e8e6b72167c0067a2",
"domain": "cozy.tools:8080",
"worker": "konnector",
"trigger_id": "0823eafc594ef00e8e6b72167c006480",
"message": {
"account": "89e68b8450cee09fe2f077610901094d",
"konnector": "grdfgrandlyon"
},
"event": null,
"manual_execution": true,
"state": "done",
"queued_at": "2020-10-09T08:00:00.0000000Z",
"started_at": "2020-10-09T08:00:00.0000000Z",
"finished_at": "2020-10-09T08:00:00.0000000Z"
},{
"_id": "0833eafc594ef00e8e6b72167c0067a2",
"domain": "cozy.tools:8080",
"worker": "konnector",
"trigger_id": "0833eafc594ef00e8e6b72167c006480",
"message": {
"account": "90e68b8450cee09fe2f077610901094d",
"konnector": "eglgrandlyon"
},
"event": null,
"manual_execution": true,
"state": "done",
"queued_at": "2020-10-09T08:00:00.0000000Z",
"started_at": "2020-10-09T08:00:00.0000000Z",
"finished_at": "2020-10-09T08:00:00.0000000Z"
},
]
}
\ No newline at end of file
{"io.cozy.triggers":
[
{
"_id": "0813eafc594ef00e8e6b72167c006480",
"_rev": "9-d4d186ce53a9bfcc6ce2a0aced39f591",
"arguments": "0 5 9 * * *",
"debounce": "",
"domain": "cozy.tools:8080",
"prefix": "cozy35ba44d2d1749e6f21646edce51e7190",
"message": {
"account": "88e68b8450cee09fe2f077610901094d",
"konnector": "enedisgrandlyon"
},
"options": null,
"type": "@cron",
"worker": "konnector",
"cozyMetadata": {
"doctypeVersion": "1",
"metadataVersion": 1,
"createdAt": "2020-10-09T08:00:00.0000000Z",
"createdByApp": "ecolyo",
"updatedAt": "2020-10-09T08:00:00.0000000Z",
"updatedByApps": [
{
"slug": "ecolyo",
"date": "2020-10-09T08:00:00.0000000Z"
}
]
}
},
{
"_id": "0823eafc594ef00e8e6b72167c006480",
"arguments": "0 5 9 * * *",
"debounce": "",
"domain": "cozy.tools:8080",
"prefix": "cozy35ba44d2d1749e6f21646edce51e7190",
"message": {
"account": "89e68b8450cee09fe2f077610901094d",
"konnector": "grdfgrandlyon"
},
"options": null,
"type": "@cron",
"worker": "konnector",
"cozyMetadata": {
"doctypeVersion": "1",
"metadataVersion": 1,
"createdAt": "2020-10-09T08:00:00.0000000Z",
"createdByApp": "ecolyo",
"updatedAt": "2020-10-09T08:00:00.0000000Z",
"updatedByApps": [
{
"slug": "ecolyo",
"date": "2020-10-09T08:00:00.0000000Z"
}
]
}
},
{
"_id": "0833eafc594ef00e8e6b72167c006480",
"arguments": "0 5 9 * * *",
"debounce": "",
"domain": "cozy.tools:8080",
"prefix": "cozy35ba44d2d1749e6f21646edce51e7190",
"message": {
"account": "90e68b8450cee09fe2f077610901094d",
"konnector": "eglgrandlyon"
},
"options": null,
"type": "@cron",
"worker": "konnector",
"cozyMetadata": {
"doctypeVersion": "1",
"metadataVersion": 1,
"createdAt": "2020-10-09T08:00:00.0000000Z",
"createdByApp": "ecolyo",
"updatedAt": "2020-10-09T08:00:00.0000000Z",
"updatedByApps": [
{
"slug": "ecolyo",
"date": "2020-10-09T08:00:00.0000000Z"
}
]
}
}
]
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment