deck file patch

Uses: deck
Related Documentation
Related Resources

The deck file patch command allows you to add, update, or remove values from a declarative configuration file. A patch is a combination of a selector that selects which objects to patch in the file, and a value that contains the new value to use.

The data type of the property identified by selector defines the merge behavior:

  • For scalar values (strings, integers, booleans) the existing value is overwritten.
  • For arrays, the provided values are appended to the existing array if the selector is an array.

Changes can be specified as command line arguments, or provided in a patch file that is passed to the deck file patch command.

The deck file patch command outputs the patched file to stdout by default. You can provide a path to a file using -o ./config.yaml to write the updated configuration to a file on disk.

Command line arguments

To patch values using the command line, pass the --selector and --value arguments.

You can run the following examples as deck file patch -s ./kong.yaml --selector <S> --value <V>.

# set field "read_timeout" to a numeric value of 10000
--selector="$..services[*]" --value="read_timeout:10000"

# set field "_comment" to a string value
--selector="$..services[*]" --value='_comment:"comment injected by patching"'

# set field "_ignore" to an array of strings
--selector="$..services[*]" --value='_ignore:["ignore1","ignore2"]'

# remove fields "_ignore" and "_comment" from the object
--selector="$..services[*]" --value='_ignore:' --value='_comment:'

# append entries to the methods array of all route objects
--selector="$..routes[*].methods" --value='["OPTIONS"]'

Patch file

If you have more complex patching needs, you can store the patches in a YAML file. The YAML file contains selectors and values, plus an explicit remove key for deleting values.

patches:
  - selectors:
      - $..services[*]
    values:
      read_timeout: 10000
      _comment: comment injected by patching
    remove:
      - _ignore
      - _comment

To apply the above file, run deck file patch -s ./config.yaml patch1.yaml patch2.yaml. Multiple patch files can be provided at once.

Command usage

Usage:
  deck file patch [flags] [...patch-files]

Examples:
# update the read-timeout on all services
cat kong.yml | deck file patch --selector="$..services[*]" --value="read_timeout:10000"

Flags:
      --format string          Output format: yaml or json. (default "yaml")
  -h, --help                   help for patch
  -o, --output-file string     Output file to write. Use - to write to stdout. (default "-")
      --selector stringArray   json-pointer identifying element to patch. Repeat for multiple selectors.)
  -s, --state string           decK file to process. Use - to read from stdin. (default "-")
      --value stringArray      A value to set in the selected entry in <key:value> format. Can be specified multiple times.

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!