Waziup / api-server

3 stars 6 forks source link

simplify domains #12

Closed cdupont closed 6 years ago

cdupont commented 7 years ago

As part of the documentation, the "domain" part of the URL embodies several concepts. It's structure is <service>-<subservice>, such as "waziup-farm1".

This has several problems:

cdupont commented 7 years ago

Proposed design is to simplify the domain. The domain will just correspond to a group of resources, for example "farm1". A group of resources can contain sensors, users, fields...

Changes in the api-server:

Configuration file change (config.js):

{
   // backend components are common for all realms
   backend: {
      keycloakUrl:      process.env.KEYCLOAK_URL || 'http://localhost:8080/auth',
      orionUrl:         process.env.ORION_URL || 'http://localhost:1026',
      elasticsearchUrl: process.env.ELASTICSEARCH_URL || 'http://localhost:9200',
      mongoDBUrl:       process.env.MONGODB_URL || 'mongodb://localhost:27017/waziup_history',
      socialsUrl:       process.env.SOCIALS_URL || 'http://localhost:9123',
   }
   //each client gets a different realm and FIWARE-Service
   clients: [
     {
        name: 'waziup'
        port: process.env.SERVER_PORT || 3000,
        serverUrl: process.env.SERVER_URL || `http://localhost:${process.env.SERVER_PORT || 3000}`,  
        realm: 'waziup',
        clientId: 'api-server',
        FIWAREService: 'waziup',
        MongoPrefix: 'waziup'
     }
   ]
};

In this configuration file, there can be several clients: for example 'waziup' and 'myBigCompany'.

For examples: Get all sensors in the default domain: GET www.waziup.io/api/v1/domains/default/sensors This will fetch sensors in the "waziup" FIWARE-Service and use "waziup" realm to verify the permissions.

We can configure another client in the api-server, to serve a completely different application, without sharing any users of resources. In this case, the api-server will serve the URL on another port. This port can be binded to another subdomain. For example: GET myBigCompany.waziup.io/api/v1/domains/default/sensors Will fetch the sensors in the myBigCompany Service in Orion and use user permissions from myBigCompany realm.

cdupont commented 7 years ago

Pro and cons of encoding the domain in the servicePath, vs encoding the domain in an attribute:

Domain in the servicePath:

Pro:

Cons:

Domain in an attribute:

Pros:

cdupont commented 6 years ago

Done: domain is stored as an attribute