Skip to content

Instantly share code, notes, and snippets.

@Tatsiana888
Created May 15, 2017 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tatsiana888/899e4889a1d4ba43b10ab5a4e327d282 to your computer and use it in GitHub Desktop.
Save Tatsiana888/899e4889a1d4ba43b10ab5a4e327d282 to your computer and use it in GitHub Desktop.
// in bootstrap.yml is defined spring.cloud.config.server.prefix = /config and client microservice call to
// org.springframework.cloud.config.server.resource.ResourceController. So in UrlMappings we need write our
// mapping for call - get "/config/${serviceName}/${profile}"(controller: 'configuration', action: 'config')
def config(String serviceName, String profile) {
def propertySources = [:]
propertySources.name = "${serviceName}.properties"
propertySources.source = [:]
// read from db all configurations for requested service
["application", "application-${profile}", "${serviceName}-${profile}"].each { configName ->
Configuration configuration = Configuration.findByName(configName)
if (configuration) {
configuration.configLines?.each { line ->
if (line) {
propertySources.source.put(line.label, line.value)
}
}
}
}
def environment = [name : "${serviceName}", profiles: ["${profile}"], "label": null, "version": null, "state": null,
propertySources: [propertySources]]
render(text: environment as JSON, contentType: "application/json")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment