configtxlator

The configtxlator command allows users to translate between protobuf and JSON versions of fabric data structures and create config updates. The command may either start a REST server to expose its functions over HTTP or may be utilized directly as a command line tool.

Syntax

The configtxlator tool has five sub-commands, as follows:

  • start

  • proto_encode

  • proto_decode

  • compute_update

  • version

configtxlator start

  1. usage: configtxlator start [<flags>]
  2. Start the configtxlator REST server
  3. Flags:
  4. --help Show context-sensitive help (also try --help-long and
  5. --help-man).
  6. --hostname="0.0.0.0" The hostname or IP on which the REST server will listen
  7. --port=7059 The port on which the REST server will listen
  8. --CORS=CORS ... Allowable CORS domains, e.g. '*' or 'www.example.com'
  9. (may be repeated).

configtxlator proto_encode

  1. usage: configtxlator proto_encode --type=TYPE [<flags>]
  2. Converts a JSON document to protobuf.
  3. Flags:
  4. --help Show context-sensitive help (also try --help-long and
  5. --help-man).
  6. --type=TYPE The type of protobuf structure to encode to. For
  7. example, 'common.Config'.
  8. --input=/dev/stdin A file containing the JSON document.
  9. --output=/dev/stdout A file to write the output to.

configtxlator proto_decode

  1. usage: configtxlator proto_decode --type=TYPE [<flags>]
  2. Converts a proto message to JSON.
  3. Flags:
  4. --help Show context-sensitive help (also try --help-long and
  5. --help-man).
  6. --type=TYPE The type of protobuf structure to decode from. For
  7. example, 'common.Config'.
  8. --input=/dev/stdin A file containing the proto message.
  9. --output=/dev/stdout A file to write the JSON document to.

configtxlator compute_update

  1. usage: configtxlator compute_update --channel_id=CHANNEL_ID [<flags>]
  2. Takes two marshaled common.Config messages and computes the config update which
  3. transitions between the two.
  4. Flags:
  5. --help Show context-sensitive help (also try --help-long and
  6. --help-man).
  7. --original=ORIGINAL The original config message.
  8. --updated=UPDATED The updated config message.
  9. --channel_id=CHANNEL_ID The name of the channel for this update.
  10. --output=/dev/stdout A file to write the JSON document to.

configtxlator version

  1. usage: configtxlator version
  2. Show version information
  3. Flags:
  4. --help Show context-sensitive help (also try --help-long and --help-man).

Examples

Decoding

Decode a block named fabric_block.pb to JSON and print to stdout.

  1. configtxlator proto_decode --input fabric_block.pb --type common.Block

Alternatively, after starting the REST server, the following curl command performs the same operation through the REST API.

  1. curl -X POST --data-binary @fabric_block.pb "${CONFIGTXLATOR_URL}/protolator/decode/common.Block"

Encoding

Convert a JSON document for a policy from stdin to a file named policy.pb.

  1. configtxlator proto_encode --type common.Policy --output policy.pb

Alternatively, after starting the REST server, the following curl command performs the same operation through the REST API.

  1. curl -X POST --data-binary /dev/stdin "${CONFIGTXLATOR_URL}/protolator/encode/common.Policy" > policy.pb

Pipelines

Compute a config update from original_config.pb and modified_config.pb and decode it to JSON to stdout.

  1. configtxlator compute_update --channel_id testchan --original original_config.pb --updated modified_config.pb | configtxlator proto_decode --type common.ConfigUpdate

Alternatively, after starting the REST server, the following curl commands perform the same operations through the REST API.

  1. curl -X POST -F channel=testchan -F "original=@original_config.pb" -F "updated=@modified_config.pb" "${CONFIGTXLATOR_URL}/configtxlator/compute/update-from-configs" | curl -X POST --data-binary /dev/stdin "${CONFIGTXLATOR_URL}/protolator/decode/common.ConfigUpdate"

Additional Notes

The tool name is a portmanteau of configtx and translator and is intended to convey that the tool simply converts between different equivalent data representations. It does not generate configuration. It does not submit or retrieve configuration. It does not modify configuration itself, it simply provides some bijective operations between different views of the configtx format.

There is no configuration file configtxlator nor any authentication or authorization facilities included for the REST server. Because configtxlator does not have any access to data, key material, or other information which might be considered sensitive, there is no risk to the owner of the server in exposing it to other clients. However, because the data sent by a user to the REST server might be confidential, the user should either trust the administrator of the server, run a local instance, or operate via the CLI.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.