Skip to content
Snippets Groups Projects
0-getting-started.md 5.49 KiB
Newer Older
  • Learn to ignore specific revisions
  • # Getting started
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    This section will allow you to launch a proper local environment of the Ecolyo application
    
    
    :::tip Clone the project
    
    First, clone [Ecolyo](https://forge.grandlyon.com/web-et-numerique/factory/llle_project/ecolyo)
    
    Hugo's avatar
    Hugo committed
    ## Installation of the project
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ### Start the app
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    Install required node modules, open a terminal on the root folder of the project and type the following command:
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    yarn install
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    Start ecolyo application just launch the command:
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    yarn start
    ```
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    If the application starts successfully you should obtain the following message:
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    > App successfully compiled!  
    
    > Dev assets: 'http://localhost:8888'
    
    Once the application is started, run the easy-cozy stack with docker.
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ### Start cozy stack
    
    Hugo's avatar
    Hugo committed
    Launch the stack with the following command:
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    docker-compose up
    
    :::note If you have an access denied issue
    `docker login registry.forge.grandlyon.com`
    :::
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    Wait until the success message:
    
    > Everything is setup. Go to http://ecolyo.cozy.tools:8080/
    
    > To exit, press ^C
    
    Once successful you can launch your local cozy with following url: [Cozy local url](http://cozy.tools:8080/). The password of this instance is set to *"cozy"* by default.
    
    Hugo's avatar
    Hugo committed
    
    
    Local database can also be consulted at the following url: [Cozy local DB](http://localhost:5984/_utils/)
    
    
    ## Use local konnectors
    
    In most case you will use mocked konnectors with mock data, but for some testing goals you will need real accounts.
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    In local, it is possible to run EGL en SGE-Enedis konnectors, with real accounts, but it needs some specific manipulation as well as you'll need to use api secrets that are, of course, basically not available in the project. If you need to use konnectors with real accounts in testing goals, please follow the following steps. Otherwise, refer to the next two sections 'Import Mock Data' et 'Simulate konnector connections'.
    
    First step, make sure your stack is running. Then open your [CouchDB](http://localhost:5984/_utils/) and look for the `secrets/io-cozy-account_types` entry.
    
    Then add a new document like this :
    
    EGL Example
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    ```json
    
    {
      "_id": "eglgrandlyon",
      "grant_mode": "secret",
      "slug": "eglgrandlyon",
      "secret": {
        "eglBaseURL": "******",
        "eglAPIAuthKey": "*****"
      }
    }
    ```
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    SGE Enedis example
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    ```json
    
    {
      "_id": "enedis-sge-grandlyon",
      "grant_mode": "secret",
      "slug": "enedis-sge-grandlyon",
      "secret": {
        "loginUtilisateur": "******",
        "wso2BaseUrl": "*****",
        "contractId": "*****",
        "apiToken": "*****"
      }
    }
    ```
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    
    
    You'll need to use konnector slug as is to make it work properly
    
    You can contact an administrator in order to get the proper information to fill in your secret.
    
    Once it is done, you will be able to use these 2 Konnectors with real accounts.
    
    
    :::warning You might see this message before trying to log with SGE Account
    
    Make sure you have the person's consent to use their PDL number, as it is sensitive data.
    
    ## Import mock data
    
    :::info Requirement
    
    Your dev stack should be running to import the mock data
    
    First install ACH using yarn :
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    yarn global add cozy-ach
    ```
    
    
    Mathieu Ponton's avatar
    Mathieu Ponton committed
    Next create the "config.js" file based on the "config.template.js"
    
    :::info You can change the period of data generated by changing the following lines:
    
    ```js title="config.js"
    const startingDate = DateTime.local()
        // highlight-next-line
        .plus({ days: -120 })
        .startOf('day')
    const endingDate = DateTime.local()
        .plus({ days: -1 })
        .startOf('day')
    ```
    
    Just replace -120 by the value needed
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    Next launch the script `createDayDataFiles.js` available into the `scripts` folder
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    Mathieu Ponton's avatar
    Mathieu Ponton committed
    cd scripts
    node createDayDataFiles.js
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    Json files with data will be created into `scripts/data` folder.
    ACH script `importData.bat` will load the content of the file into your CouchDB (database of your dev stack). Launch it using following commands:
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    
    ./importData.bat
    ```
    
    If you cannot execute `ACH` after this command, it may be because you do not have the directory where yarn stores its symbolic links in your `PATH`. Edit it to append the result of `yarn global bin` by executing the following command:
    
    ```sh
     export PATH="$PATH:`yarn global bin`"
    ```
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    You'll be prompted for a **cozysessid**, you can get it in the web console : in the `application` tab, look for the cookies and just copy the cozysessid value.
    
    A new browser windows will open and asking you approval to import data. Just click on **Approve**
    
    
    Finally your data is loaded in the Ecolyo Application !
    
    
    ## Simulate konnectors connection
    
    
    :::info Requirement
    
    Your dev stack should be running to import data needed to simulate konnectors connection
    
    When using local environment, konnectors are not able to connect as in production.
    
    To simulate the connection you can use the script **createConnection.js** available in **scripts** folder.
    
    
    Hugo's avatar
    Hugo committed
    First update the authorization and cookie information from the "config.js" file (if not created just create it from the "config.template.js" file):
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```js
    
    const authorization = 'Bearer xxxxxxxxxxx';
    const cookie = 'cozysessid=xxxxxxxxxxx';
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    To obtain your own Bearer and cozysessid you need to have the application launched and display the web console (F12) in your navigator and select the **Network tab**. Just select one request and retrieve information for Request Header:
    
    Hugo's avatar
    Hugo committed
    ![Bearer&cozysessid](/img/bearer_cozysessid.png)
    
    
    Next launch the script :
    
    
    Bastien DUMONT's avatar
    Bastien DUMONT committed
    ```sh
    node scripts/createConnections.js
    
    Your data is now loaded and you can refresh the application to see your konnector connected.