From aaf02b9366dfc1679752fbf15d7cd44203a7f268 Mon Sep 17 00:00:00 2001 From: Harry Date: Wed, 8 May 2019 11:25:25 -0700 Subject: [PATCH] fix(solver) set foreign ID only for plugins PUT requests Kong 1.1 introduces a change where specifying the name and id of the service on a POST request results in an incorrect error from Kong. While, this is a bug in Kong, Kong doesn't promise any compat for cases when Admin API reqeusts contains entire nested foreign objects. From #16 --- solver/kong/plugin.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/solver/kong/plugin.go b/solver/kong/plugin.go index cc057ee72..ce90b3c1c 100644 --- a/solver/kong/plugin.go +++ b/solver/kong/plugin.go @@ -40,6 +40,16 @@ func pluginFromStuct(arg diff.Event) *state.Plugin { func (s *PluginCRUD) Create(arg ...crud.Arg) (crud.Arg, error) { event := eventFromArg(arg[0]) plugin := pluginFromStuct(event) + + if plugin.Service != nil { + plugin.Service = &kong.Service{ID: plugin.Service.ID} + } + if plugin.Route != nil { + plugin.Route = &kong.Route{ID: plugin.Route.ID} + } + if plugin.Consumer != nil { + plugin.Consumer = &kong.Consumer{ID: plugin.Consumer.ID} + } createdPlugin, err := s.client.Plugins.Create(nil, &plugin.Plugin) if err != nil { return nil, err