Sandro Rey
Sandro Rey

Reputation: 2999

YAML Configuration replace one property value for the value of another

I would like to know if it is possible to replace the value of one value for the value of another one, like e.g. :

booking:    
    services:
      dans:
        PRIVATE_KEY: MIIEowIBAAKCAQEAr8nAQCQZ8hL0up8LzItKrBwIWhvbFgTtVEHjQIJ0Yw/F3u82         
      mode:
         PRIVATE_KEY: {booking.services.dans.PRIVATE_KEY}

Upvotes: 0

Views: 399

Answers (1)

flyx
flyx

Reputation: 39768

You can use anchors and aliases:

booking:    
    services:
      dans:
        PRIVATE_KEY: &a
          MIIEowIBAAKCAQEAr8nAQCQZ8hL0up8LzItKrBwIWhvbFgTtVEHjQIJ0Yw/F3u82         
      mode:
         PRIVATE_KEY: *a

This is not a replacement, but a reference; both PRIVATE_KEY keys will link to the same value.

YAML does not provide a way to refer to other values via some kind of path. Mind that {} in YAML do have a special meaning; they create flow mappings. What you wrote is equivalent to this:

booking:    
    services:
      dans:
        PRIVATE_KEY: MIIEowIBAAKCAQEAr8nAQCQZ8hL0up8LzItKrBwIWhvbFgTtVEHjQIJ0Yw/F3u82         
      mode:
         PRIVATE_KEY:
             booking.services.dans.PRIVATE_KEY:

Upvotes: 1

Related Questions