I am making a program that needs to check that certain fields are defined with the correct alias string. For example:
networks:
base:
name: build
address: &dummyname
url: 192.168.1.1
port: 8080
first:
name: masterA
address: *dummyname
second:
name: masterB
address: *dummyname
I need to check whether field address is defined with the alias "*dummyname" in first and second, no matter what the content of the alias is.
When executing load with PyYaml, aliases are always rendered, so I am not able to check that:
data = yaml.safe_load(file_data)
data rendered as python dict:
networks:
base:
name: build
address:
url: 192.168.1.1
port: 8080
first:
name: masterA
address:
url: 192.168.1.1
port: 8080
second:
name: masterB
address:
url: 192.168.1.1
port: 8080
I have seen similar posts for the other way around, dumping python object to YAML without creating aliases/anchors, but I haven't found a solution for this.
How can I access the alias used in the YAML document?