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

Placeholder '@' in application.yaml #167

Closed

Description

@thlaegler

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@

Activity

  1. martinlippert commented on Jul 14, 2017

    @martinlippert
    Contributor

    @kdvolder do you have an idea?

  2. kdvolder commented on Jul 14, 2017

    @kdvolder
    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.

  3. spring-projects-issues commented on Aug 22, 2017

    @spring-projects-issues

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

  4. spring-projects-issues commented on Aug 22, 2017

    @spring-projects-issues

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

    Example:

    server: 
      port: "@application-port@"
    
  5. spring-projects-issues commented on Aug 22, 2017

    @spring-projects-issues

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

  6. spring-projects-issues commented on Aug 22, 2017

    @spring-projects-issues

    (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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions