spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Enhance client side resolution of plain-text files

Open csterwa opened this issue 8 years ago • 28 comments

Config server supports serving plain-text configuration files (for configuration tailored to specific libraries or environments), including placeholder resolution from config server properties. (See http://cloud.spring.io/spring-cloud-static/Dalston.SR1/#_serving_plain_text)

It seems that the only way to consume these resources (in OSS) is via RestTemplate or some similar REST client means. This can be complicated when there are additional hoops to jump through in order to resolve access to these files such as secured authentication/authorization around config server. This may require a client to muck about with authentication/authorization beans to get at the access token needed to consume those resources.

To make this easier such client situations, it would be useful to provide some means by which the clients can consume those resources, but without having to deal with the authentication/authorization specifics.

One possible (off-the-cuff) idea might be to provide some sort of ConfigServerResource or other type that would handle the OAuth concerns under the covers. Here is potential pseudo just to further elaborate the point but not yet fleshed out:

FileInputStream fis = configServer.getConfig("myapp","myprofile");

Along with auto resolution such as:

@Value("nginx.conf") // not sure this is possible with `.` in name
FileInputStream nginxConfFileStream

Regardless of the solution, ideally, the client-side piece would be part of Spring Cloud OSS generically, with hooks provided for SCS to provide OAuth details to be included in the request.

csterwa avatar Sep 11 '17 22:09 csterwa

It wouldn't be a FileInputStream ever as it would come from a URL. I think the question we need to solve before any client api, is how would SCS provide the OAuth details?

spencergibb avatar Sep 11 '17 22:09 spencergibb

Seems like a generic client app concern, rather than anything to do with config server. Maybe we should think about it as a commons feature, or spring cloud security, or even Spring Boot.

dsyer avatar Sep 12 '17 05:09 dsyer

When I talked to @csterwa about this initially it was a config client feature not a server feature. My interpretation was that he just wanted a client side API that would return an InputStream rather than the developer having to figure out how to do this themselves. It seemed like more of an enhancement rather than a new feature.

ryanjbaxter avatar Sep 12 '17 11:09 ryanjbaxter

Sure, but my point was that it isn't even really a config client feature. Just a resource type / resolver (which is a core Spring Framework feature, but the security angle makes it higher level concern).

dsyer avatar Sep 12 '17 13:09 dsyer

Regardless how it will be implemented, I think the ability to have a Spring Boot application to pull in, EASILY, plain text resources from a Spring Cloud configuration server would make Spring Boot more powerful. I have a Spring Boot app that uses different configuration files, camel routes, groovy scripts and velocity templates when being deployed for different customers. Currently, I deploy these custom files along with (but not part of) the Spring Boot fat jar. If it can easily pull in such files from the configuration server, then its deployment and maintenance would be significantly simplified.

jyinpci avatar Nov 20 '17 15:11 jyinpci

Additionaly as cfg server suppoorts "labels" (which represent git rev )if would make sense that i can check "before" download loading the compelte file if the remote revison is newer then the one i arleady have retrieved.

cforce avatar Mar 05 '18 10:03 cforce

This has been implemented and pulled through Spring Cloud Services Connectors.

csterwa avatar Mar 13 '18 16:03 csterwa

Would you please link the documentation for this pull?

cforce avatar Mar 18 '18 22:03 cforce

@cforce. This was not implemented in the open source project.

spencergibb avatar Mar 18 '18 22:03 spencergibb

https://github.com/pivotal-cf/spring-cloud-services-connector/blob/master/spring-cloud-services-spring-connector/src/main/java/io/pivotal/spring/cloud/service/config/PlainTextConfigClient.java

cforce avatar Mar 19 '18 05:03 cforce

https://github.com/pivotal-cf/spring-cloud-services-connector/blob/master/spring-cloud-services-spring-connector/src/main/java/io/pivotal/spring/cloud/service/config/PlainTextOAuth2ConfigClient.java

cforce avatar Mar 19 '18 05:03 cforce

Still can not find the code for feature that allows me to retrieve git revision for checking if my local file is outdated before updating from cfg server

cforce avatar Mar 19 '18 05:03 cforce

@cforce it's not here.

spencergibb avatar Mar 19 '18 09:03 spencergibb

Hello! has this been implemented?

leogtzr avatar May 29 '18 01:05 leogtzr

This was not implemented in the open source project.

See links above

spencergibb avatar May 29 '18 01:05 spencergibb

Got it ... thanks!

leogtzr avatar May 29 '18 01:05 leogtzr

What's the final resolution with this enhancement. This use case is pretty generic in my view

vgvineet4 avatar Oct 29 '18 16:10 vgvineet4

It’s already generically provided by the Spring Resource abstraction.

dsyer avatar Oct 29 '18 17:10 dsyer

Ok....So mean to say whenever there is any configuration change in the backend of spring configuration server then config client need to pull the resources changed So in this context a plain text configuration or any xml configuration.

vgvineet4 avatar Oct 30 '18 07:10 vgvineet4

"Pulling a resource" is normally something that happens in the bean lifecycle. That might happen after a refresh event, for instance. Whether that makes sense in the context of your application is up to you to decide and implement. If you want help with an actual sample app, it might be better to go to Stack Overflow (and link back here if you like).

dsyer avatar Oct 30 '18 08:10 dsyer

In our use case we want to bind the resource from spring cloud config server hosted configurations to bean or instance variable of bean say ,

@Bean public class MyBean {

??how in spring bind plain text or xml config to this instance. private String name; }

In our use case there can be anything like security files, xml

vgvineet4 avatar Oct 30 '18 14:10 vgvineet4

I created these 2 issues for text / binary resources resolution.

https://github.com/pivotal-cf/spring-cloud-services-connector/issues/129

https://github.com/spring-cloud/spring-cloud-config/issues/1459

I proposed to either implement the feature or give it away to spring project. Surely everyone can copy the code, create a library from it, implement it by it's own.

But the cleanest way is to add it to the spring project directly. It is a small compact feature so it should not be a problem.

MilosHavranek avatar Sep 03 '19 21:09 MilosHavranek

@csterwa maybe we could port the non-oauth version here. See comments in #1459

spencergibb avatar Sep 03 '19 21:09 spencergibb

It has been a month. Can someone eligible please respond?

MilosHavranek avatar Oct 04 '19 19:10 MilosHavranek

@SpiReCZ this enhancement has not been scheduled for addition at this time. When it has, it will be added to a Project and Milestone.

spencergibb avatar Oct 04 '19 20:10 spencergibb

Any plans on adding this feature?

mrodal avatar Jun 24 '24 15:06 mrodal

Not at the moment, but if you are interested in submitting a PR for it that would be welcome!

ryanjbaxter avatar Jun 24 '24 20:06 ryanjbaxter

It’s already generically provided by the Spring Resource abstraction.

Is this approach also intended to work for binary files? I.e. is there a way to add the Accept: application/octet-stream-header (cf. https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#_serving_binary_files ), when using a resource in my client app? For instance, my.property=http://my-config-server/path/to/binary-file.

vibAtCryptomathic avatar Jun 12 '25 13:06 vibAtCryptomathic