Make Auth dynamically retrieve list of registered OpenLMIS services

This page was created because of 

OLMIS-2111 - Getting issue details... STATUS

and to provide a plan to remove hard-coded services names in Auth.

Current situation

Currently we have hard-coded list of services in Client entity class, which is populated with initial bootstrap. This list is needed for oauth to authorize services that are using service-level tokens.


Proposed solution

The easiest way of retrieving list of registered services is to use Consul API. Consul has API to find all registered services. All of our services are registering with special tag, i.e. Referencedata, so we will need to filter those listed services using "openlmis-service" tag and use "Name" property. Looking into our configuration of Consul we need to send request on "server_address:8500/v1/catalog/services". Example of response: 

Consul response
{
	"auth":["openlmis-service"],
	"consul":[],
	"fulfillment":["openlmis-service"],
	"notification":["openlmis-service"],
	"reference-ui":["openlmis-service"],
	"referencedata":["openlmis-service"],
	"requisition":["openlmis-service"],
	"stockmanagement":["openlmis-service"]
}


All this work should be done in PostContruct task that will periodically execute it in following order:


  1. Retrieve list of all registered services from Consul API.
  2. Filter this list to get only those which have "openlmis-service" tag (make note that some of services can be duplicated).
  3. Concatenate all filtered name using ',' .
  4. Save concatenate value to all records of Client class. 


OpenLMIS: the global initiative for powerful LMIS software