From 641a1b3a6ccd5f054ecb3afb0ff89d23e0011cb5 Mon Sep 17 00:00:00 2001 From: Renan Porto Date: Mon, 23 Jan 2023 17:54:26 -0300 Subject: [PATCH 1/2] feat: Add param tags to ACL and allow find all resources by some field --- README.md | 4 +++- lib/kong/acl.rb | 2 +- lib/kong/base.rb | 14 ++++++++++++++ spec/kong/acl_spec.rb | 2 +- spec/kong/base_spec.rb | 8 ++++++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f4eaea5..25a3a2d 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ Kong::Consumer.list(filters) Kong::Consumer.all() Kong::Consumer.find(id) Kong::Consumer.find_by_*(value) +Kong::Consumer.find_all_by_*(value) Kong::Consumer.create(attributes) consumer = Kong::Consumer.new({ username: 'test-user' }) @@ -262,7 +263,8 @@ consumer.jwts acl = Kong::Acl.new({ consumer_id: 'a3dX2dh2-1adb-40a5-c042-63b19dbx83hF4', - group: 'group1' + group: 'group1',, + tags: ["tag1", "tag2"] }) acl.create diff --git a/lib/kong/acl.rb b/lib/kong/acl.rb index ccee4bb..93c140a 100644 --- a/lib/kong/acl.rb +++ b/lib/kong/acl.rb @@ -2,7 +2,7 @@ module Kong class Acl include Base include BelongsToConsumer - ATTRIBUTE_NAMES = %w(id group consumer_id).freeze + ATTRIBUTE_NAMES = %w(id group tags consumer_id).freeze API_END_POINT = "/acls/".freeze end end diff --git a/lib/kong/base.rb b/lib/kong/base.rb index 0a5e7bd..3f90fce 100644 --- a/lib/kong/base.rb +++ b/lib/kong/base.rb @@ -37,6 +37,13 @@ def method_missing(method, *arguments, &block) else super end + elsif method.to_s.start_with?('find_all_by_') + attribute = method.to_s.sub('find_all_by_', '') + if self.attribute_names.include?(attribute) + self.list({ attribute => arguments[0] }) + else + super + end else super end @@ -50,6 +57,13 @@ def respond_to?(method, include_private = false) else super end + elsif method.to_s.start_with?('find_all_by_') + attribute = method.to_s.sub('find_all_by_', '') + if self.attribute_names.include?(attribute) + return true + else + super + end else super end diff --git a/spec/kong/acl_spec.rb b/spec/kong/acl_spec.rb index cb21c45..32dd40c 100644 --- a/spec/kong/acl_spec.rb +++ b/spec/kong/acl_spec.rb @@ -2,7 +2,7 @@ describe Kong::Acl do let(:valid_attribute_names) do - %w(id group consumer_id) + %w(id group tags consumer_id) end describe '::ATTRIBUTE_NAMES' do diff --git a/spec/kong/base_spec.rb b/spec/kong/base_spec.rb index 5e72f02..15792c5 100644 --- a/spec/kong/base_spec.rb +++ b/spec/kong/base_spec.rb @@ -51,12 +51,20 @@ it 'will respond to find_by_* methods' do expect(Klass.respond_to?(:find_by_name)).to be_truthy end + + it 'will respond to find_all_by_* methods' do + expect(Klass.respond_to?(:find_all_by_name)).to be_truthy + end end context 'when attribute does not exit' do it 'will not respond to find_by_* methods' do expect(Klass.respond_to?(:find_by_invalid)).to be_falsey end + + it 'will not respond to find_all_by_* methods' do + expect(Klass.respond_to?(:find_all_by_invalid)).to be_falsey + end end end From 0d5640830ef9bc917306454d42b3b5e0b4897816 Mon Sep 17 00:00:00 2001 From: Renan Porto Date: Mon, 30 Jan 2023 14:09:04 -0300 Subject: [PATCH 2/2] Update README.md Co-authored-by: Hilderlan Almeida --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25a3a2d..d612051 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ consumer.jwts acl = Kong::Acl.new({ consumer_id: 'a3dX2dh2-1adb-40a5-c042-63b19dbx83hF4', - group: 'group1',, + group: 'group1', tags: ["tag1", "tag2"] })