yamlhyperledger-fabric

What is `<<` and `&` in yaml mean?


When I review the cryptogen(a fabric command) config file . I saw there symbol.

Profiles:

    SampleInsecureSolo:
        Orderer:
            <<: *OrdererDefaults  ## what is the `<<`
            Organizations:
                - *ExampleCom     ## what is the `*`
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1ExampleCom
                    - *Org2ExampleCom

Above there a two symbol << and *.

Application: &ApplicationDefaults  # what is the `&` mean

    Organizations:

As you can see there is another symbol &. I don't know what are there mean. I didn't get any information even by reviewing the source code (fabric/common/configtx/tool/configtxgen/main.go)


Solution

  • Well, those are elements of the YAML file format, which is used here to provide a configuration file for configtxgen. The "&" sign mean anchor and "*" reference to the anchor, this is basically used to avoid duplication, for example:

    person: &person
        name: "John Doe"
    
    employee: &employee
        << : *person
        salary : 5000
    

    will reuse fields of person and has similar meaning as:

    employee: &employee
        name   : "John Doe"
        salary : 5000
    

    another example is simply reusing value:

    key1: &key some very common value
    
    key2: *key
    

    equivalent to:

    key1: some very common value
    
    key2: some very common value
    

    Since abric/common/configtx/tool/configtxgen/main.go uses of the shelf YAML parser you won't find any reference to these symbols in configtxgen related code. I would suggest to read a bit more about YAML file format.