Skip to content

Enhance client side resolution of plain-text files #789

Open

Description

@csterwa

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.

Activity

  1. spencergibb commented on Sep 11, 2017

    @spencergibb
    Member

    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?

  2. dsyer commented on Sep 12, 2017

    @dsyer
    Contributor

    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.

  3. ryanjbaxter commented on Sep 12, 2017

    @ryanjbaxter
    Contributor

    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.

  4. dsyer commented on Sep 12, 2017

    @dsyer
    Contributor

    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).

  5. jyinpci commented on Nov 20, 2017

    @jyinpci

    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.

  6. cforce commented on Mar 5, 2018

    @cforce

    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.

  7. csterwa commented on Mar 13, 2018

    @csterwa
    Author

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

  8. cforce commented on Mar 18, 2018

    @cforce

    Would you please link the documentation for this pull?

  9. spencergibb commented on Mar 18, 2018

    @spencergibb
    Member

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

  10. cforce commented on Mar 19, 2018

    @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

  11. spencergibb commented on Mar 19, 2018

    @spencergibb
    Member

    @cforce it's not here.

  12. leogtzr commented on May 29, 2018

    @leogtzr

    Hello! has this been implemented?

  13. 5 remaining items

  14. dsyer commented on Oct 30, 2018

    @dsyer
    Contributor

    "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).

  15. vgvineet4 commented on Oct 30, 2018

    @vgvineet4

    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

  16. MilosHavranek commented on Sep 3, 2019

    @MilosHavranek

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

    pivotal-cf/spring-cloud-services-connector#129

    #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.

  17. spencergibb commented on Sep 3, 2019

    @spencergibb
    Member

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

  18. MilosHavranek commented on Oct 4, 2019

    @MilosHavranek

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

  19. spencergibb commented on Oct 4, 2019

    @spencergibb
    Member

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

  20. mrodal commented on Jun 24, 2024

    @mrodal

    Any plans on adding this feature?

  21. ryanjbaxter commented on Jun 24, 2024

    @ryanjbaxter
    Contributor

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

  22. vibAtCryptomathic commented on Jun 12, 2025

    @vibAtCryptomathic

    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.

  23. sharanggupta commented on Oct 21, 2026

    @sharanggupta
    Contributor

    @ryanjbaxter, I'd like to pick this up. I have a working branch to show the shape before opening a pull request: main...sharanggupta:spring-cloud-config:gh-789-config-server-resources

    A plain URL can already point at the config server, so the value is in reusing the client's configuration: its URIs with the same failover rules as the config data loader, the credentials, headers, token, TLS settings and timeouts, and its application name, profiles and label. The branch adds:

    • ConfigServerResource, a Resource for a file on the config server, with Accept: application/octet-stream for binary files.
    • ConfigServerResourceFactory, a bean with getResource(path) and getBinaryResource(path). With spring.config.import, it reuses the RestTemplate that loaded the configuration, registered like configDataConfigClientProperties. With the legacy bootstrap, it is auto-configured.
    • A ProtocolResolver, so that @Value("configserver-file:nginx.conf") Resource and ResourceLoader work.
    • Docs in the client section, and tests, including integration tests against a running config server.

    A few questions before I open the pull request:

    1. configserver: is already the prefix of spring.config.import, so I used configserver-file:. Would you prefer another prefix?
    2. Binary files use a ?binary suffix, for example configserver-file:certs/truststore.p12?binary. Would a separate prefix be better?
    3. Without a label, the client uses the useDefaultLabel endpoint, whose {path:.*} only matches one path segment, so a file in a subdirectory needs a label. Should the server endpoint match nested paths, in a separate change?
  24. sharanggupta commented on Oct 22, 2026

    @sharanggupta
    Contributor

    Thanks, @ryanjbaxter, that is a better starting point. PR #3355 ports ConfigResourceClient, DefaultConfigResourceClient and ConfigResourceClientAutoConfiguration from the starters into the client module, with the resolver registering configClientRestClient (and the RestTemplate behind it) at bootstrap close as the commercial OAuth2ConfigDataLocationResolver does. The only adjustments are for the open source client having no default label: the request falls back to ?useDefaultLabel, and a slash in a label is escaped as (_) like the config data loader does. The earlier resource-based branch is dropped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions