Kong / deck

decK: Configuration management and drift detection for Kong

Home Page:https://docs.konghq.com/deck/overview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Selector CLI flag on file patch and file add-plugin not working when using a patch/plugin YAML file

andrewgkew opened this issue · comments

I am trying to use 2 of the new commands, file patch and file add-plugin and have tried using the --selector flag but its being ignored

I am using a file with the info for the patch and plugin but then the selector via the CLI

cat kong.yaml | deck file patch --selector="$..services[*]" patch.yaml

If I put that selector into the patch.yaml file then it works, can I not use CLI flag --selector with a patch file?

@andrewgkew The intention of the command is to either provide a patch file, which you did with the patch.yaml argument, or provide --selector && --value arguments. I'm assuming the code is seeing the patch file argument and then ignoring the selector argument. I think the code should produce an error here explaining the usage properly. I will track.

@rspurgeon yes I think that is whats happening, let me explain my use case:

  1. I have plugin template files defined that I want to re-use for all OAS specs that I want to publish on Kong
  2. At pipeline time I want the flexibility to either apply the plugin at the service or route level
  3. If I cant use the combination of selector flag and plugin/patch YAML file then I need to store these files for both services and routes (as the selector needs to be stored within the file)

Any recommendations on how to handle this without duplicating things?

@andrewgkew Here is an option. Store the plugin configuration in a JSON file as an array. For example:

plugins.json

[ 
    { "name":"rate-limiting",
        "config":{"second":5,"hour":10000,"policy":"local"}
    },
    { "name":"key-auth",
        "config":{"key_names":"apikey"}
    }
]

Then on the command line you can cat the JSON file into the --value argument at runtime.

For services:

deck file patch -s kong.yaml --selector '$..services[*].plugins' --value "$(cat plugins.json)"

Or for routes:

deck file patch -s kong.yaml --selector '$..routes[*].plugins' --value "$(cat plugins.json)"

Thanks @rspurgeon I can do the same with yq as well - good shout will give that a go

deck file patch -s kong.yaml --selector '$..routes[*].plugins' --value "$(yq -o=json -I=0 plugin.yaml)"