Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Placeholder '@' in application.yaml #167

Closed
thlaegler opened this issue Jul 14, 2017 · 6 comments
Closed

Placeholder '@' in application.yaml #167

thlaegler opened this issue Jul 14, 2017 · 6 comments
Labels

Comments

@thlaegler
Copy link

thlaegler commented Jul 14, 2017

I'm using maven resource plugin to replace some values in my application.yaml. While the @-character is not allowed as beginning of a yaml token there is this workaround to wrap the value in " or ' ( here and here ).
But is there a similar workaround for integer values like server.port?

myproject:
  version: '@project.version@'
  description: '@project.description@'
  java:
    version: '@java.version@'
server:
  port: @xmd.spring.config.port@
@martinlippert
Copy link
Contributor

@kdvolder do you have an idea?

@kdvolder
Copy link
Contributor

But is there a similar workaround for integer values like server.port?

Have you tried it? I bet the same workaround should work. If your substitution of the "@my-port@" happens before spring-boot reads it, I think spring-boot will convert a value like "1234" into 1234. So I think the workaround should work there too.

If you tried it... and it doesn't work... provide some details on the exact errors / problem you see and we can think about it some more.

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Kris De Volder:)

I've tried the workaround of adding quotes around the @...@. While this works to avoid the parse error... the reconciler then gives a error that it is expecting a integer value and considers something like "@BLAH@" to be a string.

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Kris De Volder:)

Example:

server: 
  port: "@application-port@"

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Kris De Volder:)

Just pushed a change that makes the workaround also work for integer properties (i.e. values containing '@...@' placeholders are skipped during type check).

Making the 'naked' placeholder also work a in the following example:

server: 
  port: @application-port@

... is more challenging because the naked '@' values actually break the yaml parser, so we can't get an AST.

A possible approach to getting this to work would be to scan the entire document for stuff that looks like a '@...@' placeholder and replace it with something more harmless prior to parsing. E.g we could replace the leading and trailing '@' with '_'. Then walking the parse-tree to check it we also have to somehow ensure to retrieve the actula text value of scalar nodes from the original document rather than the actual parse-tree node.

@spring-projects-issues
Copy link

(comment in Pivotal Tracker added by Kris De Volder:)

I started to try implement the handling of 'naked' @..@ placeholders. But this quickly turns into a big mess. It isn't straightforward to obtain a node's value if we have to account for the fact that the input we have parsed wasn't actually the document's real contents. I think this is very likely to introduce regressions around improper handling of escape sequences in yaml strings.

So I think I'm just going to deliver this ticket as it stands. I.e. if you want to use @..@ placeholder you just have to surround them with single or double quotes to avoid confusiing the yaml parser.

This workaround should now also work fine for properties like server.port. The presenence of a '@...@' in a value will be detected and reconciler will skip checking that value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

4 participants