kongfigure 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +54 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +3 -0
- data/exe/kongfigure +6 -0
- data/exe/kongfigure_local +6 -0
- data/kongfigure.gemspec +31 -0
- data/lib/kongfigure/cli.rb +21 -0
- data/lib/kongfigure/configuration.rb +51 -0
- data/lib/kongfigure/errors/bad_request.rb +4 -0
- data/lib/kongfigure/errors/internal_server_error.rb +4 -0
- data/lib/kongfigure/errors/invalid_configuration.rb +4 -0
- data/lib/kongfigure/errors/resource_conflict.rb +4 -0
- data/lib/kongfigure/errors/resource_not_found.rb +4 -0
- data/lib/kongfigure/http_client.rb +94 -0
- data/lib/kongfigure/kong.rb +40 -0
- data/lib/kongfigure/parser.rb +32 -0
- data/lib/kongfigure/resources/base.rb +48 -0
- data/lib/kongfigure/resources/consumer.rb +40 -0
- data/lib/kongfigure/resources/consumers/acl.rb +18 -0
- data/lib/kongfigure/resources/consumers/key_auth.rb +18 -0
- data/lib/kongfigure/resources/plugin.rb +51 -0
- data/lib/kongfigure/resources/route.rb +41 -0
- data/lib/kongfigure/resources/service.rb +56 -0
- data/lib/kongfigure/resources/target.rb +19 -0
- data/lib/kongfigure/resources/upstream.rb +51 -0
- data/lib/kongfigure/services/base.rb +164 -0
- data/lib/kongfigure/services/consumer.rb +60 -0
- data/lib/kongfigure/services/plugin.rb +18 -0
- data/lib/kongfigure/services/route.rb +4 -0
- data/lib/kongfigure/services/service.rb +53 -0
- data/lib/kongfigure/services/upstream.rb +41 -0
- data/lib/kongfigure/version.rb +3 -0
- data/lib/kongfigure.rb +46 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f564d50bbbc1a4cf274b1852df89477270c45f123412a03c06201fe3a084e6fb
|
4
|
+
data.tar.gz: eae01666b3ce461e99ac2f2698a0a3fc33d914358ed81805a2121f550413be20
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02d1ca884c2892bb0020745baccad8491cc51dec67f8165abeb220ec323e5cb760f39ef680e8e17e10642a7cbede32527a3636b674e56d6c8437ab09225266a6
|
7
|
+
data.tar.gz: 9650447e01b1cc052c808df5e85ecc211f500a5168b4b6855516d502ee2e4ff0a738c283c30e8137dd20d5a9ce8aa29fc0b19d6599ad54157afda034ae8d68a7
|
data/.gitignore
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
/.config
|
5
|
+
/coverage/
|
6
|
+
/InstalledFiles
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/spec/examples.txt
|
10
|
+
/test/tmp/
|
11
|
+
/test/version_tmp/
|
12
|
+
/tmp/
|
13
|
+
|
14
|
+
# Used by dotenv library to load environment variables.
|
15
|
+
# .env
|
16
|
+
|
17
|
+
# Ignore Byebug command history file.
|
18
|
+
.byebug_history
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kongfigure (0.0.1)
|
5
|
+
awesome_print
|
6
|
+
colorize
|
7
|
+
dry-inflector
|
8
|
+
rest-client (~> 2.0, >= 2.0.2)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
awesome_print (1.8.0)
|
14
|
+
colorize (0.8.1)
|
15
|
+
domain_name (0.5.20180417)
|
16
|
+
unf (>= 0.0.5, < 1.0.0)
|
17
|
+
dry-inflector (0.1.2)
|
18
|
+
http-cookie (1.0.3)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
mime-types (3.2.2)
|
21
|
+
mime-types-data (~> 3.2015)
|
22
|
+
mime-types-data (3.2018.0812)
|
23
|
+
netrc (0.11.0)
|
24
|
+
rest-client (2.0.2)
|
25
|
+
http-cookie (>= 1.0.2, < 2.0)
|
26
|
+
mime-types (>= 1.16, < 4.0)
|
27
|
+
netrc (~> 0.8)
|
28
|
+
unf (0.1.4)
|
29
|
+
unf_ext
|
30
|
+
unf_ext (0.0.7.5)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
kongfigure!
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ibanity, Isabel Group
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/exe/kongfigure
ADDED
data/kongfigure.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "kongfigure/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "kongfigure"
|
7
|
+
spec.version = Kongfigure::VERSION
|
8
|
+
spec.authors = ["Ibanity"]
|
9
|
+
spec.email = ["it@ibanity.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Kongfigure.}
|
12
|
+
spec.description = %q{A tool to manage Kong resources with a declarative configuration.}
|
13
|
+
spec.homepage = "https://github.com/ibanity/kongfigure"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.required_ruby_version = ">= 2.4.0"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = ["kongfigure"]
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
|
27
|
+
spec.add_dependency "rest-client", "~> 2.0", ">= 2.0.2"
|
28
|
+
spec.add_dependency "awesome_print", "~> 1.8.0"
|
29
|
+
spec.add_dependency "dry-inflector", "~> 0.1.2"
|
30
|
+
spec.add_dependency "colorize", "~> 0.8.1"
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "optparse"
|
2
|
+
|
3
|
+
module Kongfigure
|
4
|
+
class CLI
|
5
|
+
attr_accessor :options
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@options = {}
|
9
|
+
@option_parser = OptionParser.new do |parser|
|
10
|
+
parser.on("-f", "--file FILE", "Path to the Kongfigure configuration file.") do |file|
|
11
|
+
@options[:file] = file
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse!(args)
|
17
|
+
@option_parser.parse!(args)
|
18
|
+
@options
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require "pp"
|
3
|
+
require "awesome_print"
|
4
|
+
|
5
|
+
module Kongfigure
|
6
|
+
class Configuration
|
7
|
+
|
8
|
+
attr_accessor :host, :services, :consumers, :plugins, :upstreams
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@host = nil
|
12
|
+
@services = []
|
13
|
+
@consumers = []
|
14
|
+
@plugins = []
|
15
|
+
@upstreams = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_services(yaml_services)
|
19
|
+
yaml_services.each do |yaml_service|
|
20
|
+
@services.push(Kongfigure::Resources::Service.build(yaml_service))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_consumers(yaml_consumers)
|
25
|
+
yaml_consumers.each do |yaml_consumer|
|
26
|
+
@consumers.push(Kongfigure::Resources::Consumer.build(yaml_consumer))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_plugins(yaml_plugins)
|
31
|
+
yaml_plugins.each do |yaml_plugin|
|
32
|
+
@plugins.push(Kongfigure::Resources::Plugin.build(yaml_plugin))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_upstreams(yaml_upstreams)
|
37
|
+
yaml_upstreams.each do |yaml_upstream|
|
38
|
+
@upstreams.push(Kongfigure::Resources::Upstream.build(yaml_upstream))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
{
|
44
|
+
services: @services.map do |service| service.to_s end,
|
45
|
+
consumers: @consumers.map do |consumer| consumer.to_s end,
|
46
|
+
plugins: @plugins.map do |plugin| plugin.to_s end,
|
47
|
+
upstreams: @upstreams.map do |upstream| upstream.to_s end
|
48
|
+
}.ai
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Kongfigure
|
4
|
+
class HTTPClient
|
5
|
+
|
6
|
+
HTTP_HEADERS = {
|
7
|
+
accept: "application/json; charset=UTF-8",
|
8
|
+
content_type: "application/json; charset=UTF-8",
|
9
|
+
accept_encoding: "gzip"
|
10
|
+
}
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@configuration = {
|
14
|
+
ssl_ca_path: nil,
|
15
|
+
verify_ssl: OpenSSL::SSL::VERIFY_NONE,
|
16
|
+
url: "https://localhost:8445"
|
17
|
+
}
|
18
|
+
@inflector = Dry::Inflector.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def post(path, payload)
|
22
|
+
execute(request_options(:post, path, payload))
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(path, payload)
|
26
|
+
execute(request_options(:put, path, payload))
|
27
|
+
end
|
28
|
+
|
29
|
+
def patch(path, payload)
|
30
|
+
execute(request_options(:patch, path, payload))
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(path)
|
34
|
+
execute(request_options(:get, path))
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(path)
|
38
|
+
execute(request_options(:delete, path))
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def execute(options)
|
44
|
+
RestClient::Request.execute(options) do |response, _request, _result|
|
45
|
+
handle_response(response)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def ssl_options
|
50
|
+
{
|
51
|
+
ssl_ca_file: @configuration[:ssl_ca_path],
|
52
|
+
verify_ssl: @configuration[:verify_ssl]
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def request_options(method, path, payload = nil)
|
57
|
+
opts = {
|
58
|
+
method: method,
|
59
|
+
url: "#{@configuration[:url]}/#{path}",
|
60
|
+
headers: HTTP_HEADERS,
|
61
|
+
}
|
62
|
+
|
63
|
+
opts.merge!(ssl_options) if @configuration[:url].include?("https://")
|
64
|
+
opts.merge!(payload: payload) if payload
|
65
|
+
|
66
|
+
opts
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def handle_response(response)
|
71
|
+
if response.code == 204
|
72
|
+
nil
|
73
|
+
elsif response.code.between?(200, 399)
|
74
|
+
handle_success(response)
|
75
|
+
elsif response.code == 400
|
76
|
+
parsed_response = JSON.parse(response.body)
|
77
|
+
raise Kongfigure::Errors::BadRequest, {
|
78
|
+
name: parsed_response["name"],
|
79
|
+
fields: parsed_response["fields"]
|
80
|
+
}
|
81
|
+
elsif response.code == 404
|
82
|
+
raise Kongfigure::Errors::ResourceNotFound
|
83
|
+
elsif response.code == 409
|
84
|
+
raise Kongfigure::Errors::ResourceConflict
|
85
|
+
elsif response.code == 500
|
86
|
+
raise Kongfigure::Errors::InternalServerError
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def handle_success(response)
|
91
|
+
JSON.parse(response.body)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kongfigure
|
2
|
+
class Kong
|
3
|
+
|
4
|
+
def initialize(parser, http_client)
|
5
|
+
@parser = parser
|
6
|
+
@http_client = http_client
|
7
|
+
display_information
|
8
|
+
end
|
9
|
+
|
10
|
+
def apply!
|
11
|
+
@configuration = @parser.parse!
|
12
|
+
puts @configuration.to_s
|
13
|
+
puts "Applying configuration...".colorize(:color => :white, :background => :red)
|
14
|
+
apply_all(@configuration.plugins, Kongfigure::Services::Plugin)
|
15
|
+
apply_all(@configuration.upstreams, Kongfigure::Services::Upstream)
|
16
|
+
apply_all(@configuration.services, Kongfigure::Services::Service)
|
17
|
+
apply_all(@configuration.consumers, Kongfigure::Services::Consumer)
|
18
|
+
puts "Done.".colorize(:color => :white, :background => :red)
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply_all(resources, service_module)
|
22
|
+
service = service_module.new(@http_client)
|
23
|
+
puts "<- Fetching remote #{service.resource_name}..."
|
24
|
+
remote_resources = service.all
|
25
|
+
|
26
|
+
resources.map do |resource|
|
27
|
+
service.create_or_update(@http_client, resource, remote_resources)
|
28
|
+
end
|
29
|
+
service.cleanup_useless_resources(@http_client, resources, remote_resources)
|
30
|
+
end
|
31
|
+
|
32
|
+
def display_information
|
33
|
+
data = @http_client.get("/")
|
34
|
+
puts "Kong information:".colorize(:color => :white, :background => :red)
|
35
|
+
puts "* hostname: \t#{data['version']}"
|
36
|
+
puts "* version: \t#{data['hostname']}"
|
37
|
+
puts "* lua_version: \t#{data['lua_version']}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Kongfigure
|
4
|
+
class Parser
|
5
|
+
|
6
|
+
def initialize(file)
|
7
|
+
@yaml_configuration = File.read(file)
|
8
|
+
@configuration = Kongfigure::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse!
|
12
|
+
puts "Parsing YAML configuration...".colorize(:color => :white, :background => :red)
|
13
|
+
YAML.load(@yaml_configuration).each do |key, value|
|
14
|
+
case key
|
15
|
+
when "host"
|
16
|
+
@configuration.host = value
|
17
|
+
when "services"
|
18
|
+
@configuration.add_services(value || [])
|
19
|
+
when "consumers"
|
20
|
+
@configuration.add_consumers(value || [])
|
21
|
+
when "plugins"
|
22
|
+
@configuration.add_plugins(value || [])
|
23
|
+
when "upstreams"
|
24
|
+
@configuration.add_upstreams(value || [])
|
25
|
+
else
|
26
|
+
raise "Invalid configuration key: #{key}."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@configuration
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "dry/inflector"
|
2
|
+
|
3
|
+
module Kongfigure::Resources
|
4
|
+
class Base
|
5
|
+
|
6
|
+
attr_accessor :id, :kongfigure_ignore_fields, :plugins
|
7
|
+
|
8
|
+
def initialize(id, kongfigure_ignore_fields = nil)
|
9
|
+
@id = id
|
10
|
+
@kongfigure_ignore_fields = (kongfigure_ignore_fields || []).map { |field| field.split(".") }
|
11
|
+
@plugins = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.build_all(resources_hash)
|
15
|
+
resources_hash.map do |resource_hash|
|
16
|
+
build(resource_hash)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def ==(other_object)
|
21
|
+
differences = deep_diff(other_object.api_attributes, api_attributes, kongfigure_ignore_fields)
|
22
|
+
differences.flatten.size == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def deep_diff(a, b, ignore_nested_keys=[], level=0)
|
28
|
+
ignore_nested_keys = ignore_nested_keys.inject([]) do |ignore_nested_keys, ignore_nested_key|
|
29
|
+
current_key = ignore_nested_key[level]
|
30
|
+
if a.has_key?(current_key) || b.has_key?(current_key)
|
31
|
+
ignore_nested_keys.push(ignore_nested_key[level..ignore_nested_key.size])
|
32
|
+
end
|
33
|
+
ignore_nested_keys
|
34
|
+
end
|
35
|
+
ignore_keys = ignore_nested_keys.select {|ignore_nested_key| ignore_nested_key.size == 1}.flatten
|
36
|
+
(a.keys | b.keys).each_with_object([]) do |k, diff|
|
37
|
+
if a[k] != b[k]
|
38
|
+
if a[k].is_a?(Hash) && b[k].is_a?(Hash)
|
39
|
+
diff.push(deep_diff(a[k], b[k], ignore_nested_keys, level + 1))
|
40
|
+
elsif !ignore_keys.include?(k) && !b[k].nil? && k != "id"
|
41
|
+
diff.push([a[k], b[k], k, level])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
diff
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Kongfigure::Resources
|
2
|
+
class Consumer < Base
|
3
|
+
attr_accessor :username, :acls, :key_auths, :custom_id
|
4
|
+
|
5
|
+
def self.build(hash)
|
6
|
+
consumer = new(hash["id"], hash["kongfigure_ignore_fields"])
|
7
|
+
consumer.username = hash["username"]
|
8
|
+
consumer.custom_id = hash["custom_id"]
|
9
|
+
consumer.acls = Kongfigure::Resources::Consumers::ACL.build_all(hash["acls"] || [])
|
10
|
+
consumer.plugins = Kongfigure::Resources::Plugin.build_all(hash["plugins"] || [])
|
11
|
+
consumer.key_auths = (hash["key_auths"] || []).map do |key_auth_hash|
|
12
|
+
Kongfigure::Resources::Consumers::KeyAuth.build(key_auth_hash)
|
13
|
+
end
|
14
|
+
consumer
|
15
|
+
end
|
16
|
+
|
17
|
+
def identifier
|
18
|
+
username
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_attributes
|
22
|
+
{
|
23
|
+
"username" => username,
|
24
|
+
"custom_id" => custom_id
|
25
|
+
}.compact
|
26
|
+
end
|
27
|
+
|
28
|
+
def has_key_auth?(key_auth)
|
29
|
+
key_auths && key_auths.include?(key_auth)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_acl?(acl)
|
33
|
+
acls && acls.include?(acl)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s
|
37
|
+
"#{username}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kongfigure::Resources::Consumers
|
2
|
+
class ACL < ::Kongfigure::Resources::Base
|
3
|
+
|
4
|
+
attr_accessor :group
|
5
|
+
|
6
|
+
def self.build(hash)
|
7
|
+
acl = new(hash["id"])
|
8
|
+
acl.group = hash["group"]
|
9
|
+
acl
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_attributes
|
13
|
+
{
|
14
|
+
"group" => group
|
15
|
+
}.compact
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kongfigure::Resources::Consumers
|
2
|
+
class KeyAuth < ::Kongfigure::Resources::Base
|
3
|
+
|
4
|
+
attr_accessor :key
|
5
|
+
|
6
|
+
def self.build(hash)
|
7
|
+
key_auth = new(hash["id"])
|
8
|
+
key_auth.key = hash["key"]
|
9
|
+
key_auth
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_attributes
|
13
|
+
{
|
14
|
+
"key" => key
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Kongfigure::Resources
|
2
|
+
class Plugin < Base
|
3
|
+
attr_accessor :name, :config, :enabled, :route, :service, :consumer, :run_on
|
4
|
+
|
5
|
+
def self.build(hash)
|
6
|
+
plugin = new(hash["id"], hash["kongfigure_ignore_fields"])
|
7
|
+
plugin.config = hash["config"]
|
8
|
+
plugin.name = hash["name"]
|
9
|
+
plugin.enabled = hash["enabled"]
|
10
|
+
plugin.route = hash["route"]
|
11
|
+
plugin.service = hash["service"]
|
12
|
+
plugin.consumer = hash["consumer"]
|
13
|
+
plugin.run_on = hash["run_on"]
|
14
|
+
plugin
|
15
|
+
end
|
16
|
+
|
17
|
+
def identifier
|
18
|
+
name
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_attributes
|
22
|
+
{
|
23
|
+
"name" => name,
|
24
|
+
"config" => config,
|
25
|
+
"enabled" => enabled,
|
26
|
+
"route" => route,
|
27
|
+
"service" => service,
|
28
|
+
"consumer" => consumer,
|
29
|
+
"run_on" => run_on
|
30
|
+
}.compact
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_global?
|
34
|
+
service.nil? && route.nil? && consumer.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
str = name
|
39
|
+
if route
|
40
|
+
str += " on route #{route}"
|
41
|
+
elsif service
|
42
|
+
str += " on service #{service}"
|
43
|
+
elsif consumer
|
44
|
+
str += " on consumer #{consumer}"
|
45
|
+
else
|
46
|
+
str += " attached globally"
|
47
|
+
end
|
48
|
+
str + (enabled ? " (enabled)" : " (disabled)")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Kongfigure::Resources
|
2
|
+
class Route < Base
|
3
|
+
attr_accessor :name, :protocols, :methods, :hosts, :paths, :regex_priority, :strip_path, :preserve_host, :snis,
|
4
|
+
:sources, :destinations, :service
|
5
|
+
|
6
|
+
def self.build(hash)
|
7
|
+
route = new(hash["id"], hash["kongfigure_ignore_fields"])
|
8
|
+
route.name = hash["name"]
|
9
|
+
route.protocols = hash["protocols"]
|
10
|
+
route.methods = hash["methods"]
|
11
|
+
route.paths = hash["paths"]
|
12
|
+
route.regex_priority = hash["regex_priority"]
|
13
|
+
route.strip_path = hash["strip_path"]
|
14
|
+
route.preserve_host = hash["snis"]
|
15
|
+
route.sources = hash["destinations"]
|
16
|
+
route.service = hash["service"]
|
17
|
+
route.hosts = hash["hosts"]
|
18
|
+
route.plugins = Kongfigure::Resources::Plugin.build_all(hash["plugins"] || [])
|
19
|
+
route
|
20
|
+
end
|
21
|
+
|
22
|
+
def identifier
|
23
|
+
name
|
24
|
+
end
|
25
|
+
|
26
|
+
def api_attributes
|
27
|
+
{
|
28
|
+
"name" => name,
|
29
|
+
"protocols" => protocols,
|
30
|
+
"methods" => methods,
|
31
|
+
"paths" => paths,
|
32
|
+
"hosts" => hosts,
|
33
|
+
"regex_priority" => regex_priority,
|
34
|
+
"strip_path" => strip_path,
|
35
|
+
"preserve_host" => preserve_host,
|
36
|
+
"sources" => sources,
|
37
|
+
"service" => service
|
38
|
+
}.compact
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|