kongfigure 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf57cebf09bbe6f5d2a0be2ef0b963d26b8482fdf3be87d38308db576593effe
4
- data.tar.gz: f072f428db96554d2fd79b1121af4fe414cf8a61153d71ff853d3720f71b59fc
3
+ metadata.gz: 65d5602bfed712c59cc8c2dba6c00e13f782d42155dabed11a3483f57d52ee8e
4
+ data.tar.gz: 0ebe8e6a7404fa178b7b57c0fe9c299d3993488a055fd8f005911d5b181618c9
5
5
  SHA512:
6
- metadata.gz: 90325a8f142dbf70982d3d3d5e05d8f1d7eb9c85d5283c202334cc32c9fb97b500768a24b81b909e27522b4b0e94f8c09c0ed54b89a441f6c17b0545b2f726a4
7
- data.tar.gz: 114692c7a0dae4e049cfd0b5441d2817ceeb7bf126fb8a922ff0c82aa7811846b1efe1cd962400927b421bb5aa8488ee0f9f838547069c021118b77b6c324ebe
6
+ metadata.gz: 0773bea047fca72dc0316252a8e4d67ccd5de7088b82833fef789882c8526928a54a6229a9da4854dbecb802e9e1dedc5edf1ce6e54d9a7389f8c3b8bd0d71a7
7
+ data.tar.gz: e7ec43aa67c41d17d5f8735d83f1601a55eb3b728a411b82cabe5fa117a69221c6b7e1f432dd9ca220105669932cd117c349aa18139000b236d19d1a604b63df
@@ -5,7 +5,9 @@ module Kongfigure
5
5
  attr_accessor :options
6
6
 
7
7
  def initialize
8
- @options = {}
8
+ @options = {
9
+ debug: false
10
+ }
9
11
  @option_parser = OptionParser.new do |parser|
10
12
  parser.on("-f", "--file FILE", "Path to the Kongfigure configuration file.") do |file|
11
13
  @options[:file] = file
@@ -13,6 +15,9 @@ module Kongfigure
13
15
  parser.on("-u", "--url URL", "Url to the kong admin API.") do |url|
14
16
  @options[:url] = url
15
17
  end
18
+ parser.on("-d", "--debug", "Debug mode.") do
19
+ @options[:debug] = true
20
+ end
16
21
  end
17
22
  end
18
23
 
@@ -1,7 +1,3 @@
1
- require "optparse"
2
- require "pp"
3
- require "awesome_print"
4
-
5
1
  module Kongfigure
6
2
  class Configuration
7
3
 
@@ -1,17 +1,18 @@
1
- require "yaml"
2
-
3
1
  module Kongfigure
4
2
  class Parser
5
3
 
6
- def initialize(file)
7
- @yaml_configuration = File.read(file)
4
+ def initialize(file, debug=false)
5
+ @yaml_erb_configuration = File.read(file)
6
+ @debug = debug
8
7
  end
9
8
 
10
9
  def parse!
11
10
  return @configuration unless @configuration.nil?
12
11
  @configuration = Kongfigure::Configuration.new
13
12
  puts "Parsing YAML configuration...".colorize(:color => :white, :background => :red)
14
- YAML.load(@yaml_configuration).each do |key, value|
13
+ parsed_configuration = YAML.load(ERB.new(@yaml_erb_configuration).result)
14
+ ap parsed_configuration if @debug
15
+ parsed_configuration.each do |key, value|
15
16
  case key
16
17
  when "url"
17
18
  @configuration.url = value
@@ -155,7 +155,7 @@ module Kongfigure::Services
155
155
 
156
156
  def cleanup_plugins(http_client, local_resource, remote_resource)
157
157
  remote_resource.plugins.each do |plugin|
158
- unless find_related_resource(plugin, local_resource.plugins)
158
+ if local_resource.nil? || find_related_resource(plugin, local_resource.plugins).nil?
159
159
  http_client.delete("#{resource_name}/#{remote_resource.identifier}/plugins/#{plugin.id}")
160
160
  end
161
161
  end
@@ -44,7 +44,7 @@ module Kongfigure::Services
44
44
  end
45
45
  # cleanup useless routes
46
46
  remote_resource.routes.each do |remote_resource_route|
47
- unless local_resource.has_route?(remote_resource_route)
47
+ if local_resource.nil? || !local_resource.has_route?(remote_resource_route)
48
48
  http_client.delete("routes/#{remote_resource_route.id}")
49
49
  end
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module Kongfigure
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/kongfigure.rb CHANGED
@@ -27,6 +27,11 @@ require_relative "kongfigure/errors/invalid_configuration.rb"
27
27
 
28
28
  require "rest-client"
29
29
  require "logger"
30
+ require "yaml"
31
+ require "erb"
32
+ require "optparse"
33
+ require "pp"
34
+ require "awesome_print"
30
35
 
31
36
  module Kongfigure
32
37
  def self.logger
@@ -38,7 +43,7 @@ module Kongfigure
38
43
  cli = Kongfigure::CLI.new
39
44
  options = cli.parse!(args)
40
45
  # Parser
41
- parser = Kongfigure::Parser.new(options[:file])
46
+ parser = Kongfigure::Parser.new(options[:file], options[:debug])
42
47
  http_client = Kongfigure::HTTPClient.new(parser, options[:url])
43
48
  kong = Kongfigure::Kong.new(parser, http_client)
44
49
  kong.apply!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kongfigure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ibanity
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-12 00:00:00.000000000 Z
11
+ date: 2019-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler