Spring cloud's config server plain text api with SVN and a default label - spring

I have spring boot 2 app that acts as a config server with the following properties. Notice in particularly the "default-label" properties which is the empty string because we check out directly the folder that contains the files, and not some parent branch/folder.
spring:
application:
name: config-server
profiles:
include: subversion
cloud:
config:
server:
svn:
uri: https://...somesvnrepo.../project/trunk/config
username: fake
password: notreal
default-label:
basedir: C:\Users\John\Documents\Application\configserver_tmp
The contents of /trunk/config is straigthforward. There ae no subdirectories and just these files:
application.yml
application-dev.yml
myservice.yml
myservice-dev.yml
logback.xml
Serving the yml files works fine, but getting the logback.xml file using the "plain text api" not work at all.
Doing localhost:8888/appname/default/master/logback.xml gives the error "no label master found" which is true, I don't have that label. Any other combination of paths by omitting profiles or labels results in a 404 all the way up to just calling localhost:8888/logback.xml. Adding the ?useDefaultLabel request parameter makes no difference. Actually I don't understand the purpose of the appname, profile and label part of the url when the context is to get a plain text file that is not bound to any specific application, profile or label.
I found similar questions on the internet but they mention updating their spring boot version and then it worked for them. I'm already at the latest spring boot version (2.1.3-release).
Is this because I use SVN? Or because of of the default-label being empty?

Related

Understanding the spring profile

I have basic idea how spring profile works. But here in this file this - i am not able to get it. And current Application.yml file mentioning the three profile which one will get active and when that i need to know as well. Below is the Application.yml file content.
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
Note: i have three config files present in my resources. Also if i want to look another config file
then spring use the naming convention like Application-<Name>.extension . so - is already get added for the new config file then why we explicitly need
to put another one in our application.yml file under spring.profile.active.
Below are the names of the three config files present under the resources folder.
application.yml
application-local.yml
bootstrap-default.yml
But here in this file this - i am not able to get it. spring use the
naming convention like Application-.extension . so - is already
get added for the new config file then why we explicitly need to put
another one in our application.yml file under spring.profile.active
spring:
application:
name:
profiles:
active:
-default
-local
-swaggerinfo
The declaration of profiles are incorrect. You must either put space or should not use (-) at all.
spring:
profiles:
active:
- default
- local
- swaggerinfo
The Spring also supports the following way of declarations.
spring:
profiles:
active: default,local,swaggerinfo
or
spring:
profiles:
active:
default
local
swaggerinfo
Here default refers to application.properties file not bootstrap-default.properties. Also, You don't need to specify the default profile. Spring automatically use application.properties as default one. So, in your case it's appropriate to go with local and swaggerinfo.
current Aplication.yml file mentioning the three profile which one
will get active and when that i need to know as well.
Let's talk about the following declaration.
spring:
profiles:
active:
- local
- swaggerinfo
Both local and swaggerinfo profiles will be active for props loading. So,which means that all the three files (application.yml by default) will be consumed by spring.
Let's talk about the order.
The order in the above case would be
application -> application-local -> application-swaggerinfo
Note:
Assume that you've mentioned the same prop in all the three files then in that case the precedence will be given as per the order highlighted above i.e prop mentioned in the application-swaggerinfo will override the ones available in the other twos.

Spring Cloud Config Server serving nested plain text files

I have a Config Server up and running, with the relevant application.yml setting of
spring:
application:
name: config
...
searchPaths:
- '{application}'
- '{application}/{profile}'
I would like to access a file that is not application.properties, something like myfile.txt. If I have the git layout
/myapp/nested/folder/myfile.txt
I want to be able to access that file. According to the Spring Config Server docs, I should be able to do this via /{name}/{profile}/{label}/{path}, but I can't get any paths to work.
TL;DR: How do I retrieve nested config files from a git repo via Config Server?
TL;DR: The documentation is wrong. The endpoint /{name}/{profile}/{label}/{path} should be written as /{application}/{profile}/{label}/{path}. You just need to make sure that one of your searchPaths/{path} can resolve your file.
First off, {label} is, as always, the git branch name (probably "master").
Second, {path} can can be an absolute path to the file. It uses /, i.e., myapp/nested/folder/myfile.txt, not (_) as is required in {application} or {label}.
Third, the search paths in the question are set to '{application}' and '{application}/{profile}', along with the default search path of /, the git repo's root directory. These define the places Config Server will search for a plain text file as:
/{expanded application}/{path}
/{expanded application}/{profile}/{path}
/{path}
Note that only {application} can be expanded into multiple folders with (_) and that only {path} can include multiple folders with /. For instance, with these searchPaths and a file located at /myapp/nested/folder/myfile.txt, the following requests are valid:
/asdf/asdf/master/myapp/nested/folder/myfile.txt
/myapp/asdf/master/nested/folder/myfile.txt
/myapp/nested/master/folder/myfile.txt
/myapp(_)nested(_)folder/asdf/master/myfile.txt
/myapp(_)nested/folder/master/myfile.txt
where asdf can be any arbitrary string.

Set logfile location based on OS in spring boot application.properties/.yml

I'm wondering if there's a nice clean way to set logging location based on OS just using the application.properties file in Spring Boot?
For instance is it possible to use a regex matcher on ${os.name} or would I just need to go ahead and create a groovy script or something?
My ideal solution is something like
logging:
file: ${os.name}.test(/*window*/gi) ? C:/ProgramData/Logs/ : /var/log/
You can take advantage of spring profiles and pick configurations according to the -Dspring.profile.active=some_profile system property or SPRING_PROFILES_ACTIVE=some_profile env variable.
Yaml file could be
# a safe default relative to app root
logging:
file: logs
----
spring:
profiles: nix
logging:
file: /var/log/myapp
----
spring:
profiles: win
logging:
file: C:/ProgramData/Logs/
App is executed as
java -Dspring.profile.active=nix <more opts> MyAppMain
or also:
SPRING_PROFILES_ACTIVE=nix java <more opts> MyAppMAin

Spring Boot yaml configuration doesn't load second key

I'm trying to create a config file in yaml for my Spring Boot project.
For a test I just setup some values:
user:
test: hello
Now I'm trying to get the information of user.test, but I get the error message Could not resolve placeholder 'user.test' in value "${user.test}"
The strange thing is, that if my config files just has user.test: hello, then everything works fine.
Is there something that I have to setup before to work with yml files as properties?

Call /env on Spring cloud config client side, password property shows " portal.db.password=*** "

My config file on remote git repo:
myapp-uat.properties:
portal.db.userName=allen
portal.db.password=allen1235
I could load this file on client side, and I want save these properties by call /env, but get portal.db.password=***.
I wonder if I could get real value (portal.db.password=allen1235) by adding some properties in client config file or some other methods. Hope for your help.
The below is the default sanitized keywords for /env endpoint.
endpoints:
env:
keys-to-sanitize: password,secret,key,token,.*credentials.*,vcap_services
You can override the below property without password by defining below in your application.yml/properties.
endpoints:
env:
keys-to-sanitize: secret,key,token,.*credentials.*,vcap_services

Resources