spring-cloud / spring-cloud-config

External configuration (server and client) for Spring Cloud
Apache License 2.0
1.95k stars 1.29k forks source link

Allowing to use query parameters as further filter to select the right Environment from EnvironmentRepository #1124

Open bsorrentino opened 6 years ago

bsorrentino commented 6 years ago

Problem

I have to access to config server besides springboot applications also from SPA (AngularJS).

I've used the REST api provided out-of-box from config server but the triad application/profile/label seem to me is not enough to express the complexity coming out from my requirements.

Requirements

Acquire configuration from the same app installed in different devices where configuration is different depending from deviceId and location

The natural solution that I've imaged was to call api like application/profile/label?device=x&location=y but I haven't found a simple way to achieve that.

Solution

The solution that I've figured out are:

  1. try to use profile and/or label like Json object (eg. application/profile/{label:'',device:'',location:''})
  2. publish a custom endpoint from my config server
  3. Add a filter and use stuff like ThreadLocal

Proposal

During this analysis I've figured out that if the Request object will be passed to findOne(String application, String profile, String label); method of EnvironmentRepository this allowing to use query parameters as further filter to select the right Environment

The proposal is to extends the EnvironmentRepository interface as show below

public interface EnvironmentRepository {

    Environment findOne(String application, String profile, String label);

    default Environment findOne(Request request, String application, String profile, String label) {
                 return findOne(application, profile, label);
         }

}

and update ResourceController accordly with new interface

ryanjbaxter commented 6 years ago

We certainly cant make this type of change in a minor release. I am also a little wondering if you have looked at other ways of achieving this. Maybe the config can return the configuration data for all devices and all locations and clients can just take what they need? Or you could add your own endpoint to the config server that uses the EnvironmentRepository interface but then further refines that configuration information returned based on the location and device before returning it to the client.

bsorrentino commented 6 years ago

Hi @ryanjbaxter

Thanks for response ... as you say there are other solutions.

The issue was to understand if i can achieve this reusing the spring-cloud-config-server architecture as-is because, in my opinion, I consider the proposal an enhancement for who would want use spring-cloud-config-server out of spring space or also customising the rest call from spring-cloud-config-client

ryanjbaxter commented 6 years ago

Yeah I cant think of any way that might work out of the box, besides filtering the configuration data on the client.

spencergibb commented 6 years ago

Config server is built as a normal boot application so your number 2 and 3 above work. I'm not keen on pushing anything http specific down to the API. Let's see if anyone else is interested in this.

bsorrentino commented 5 years ago

Hi @spencergibb firstly thanks for taking request in consideration. I perfectly understand and agree with you

I'm not keen on pushing anything http specific down to the API

However the request object could be easily substituted by a kind of context or simply a map