smart_proxy_dhcp_bluecat 0.1.5 → 0.1.6

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.
@@ -1,4 +1,4 @@
1
- require 'dhcp_common/server'
1
+ require "dhcp_common/server"
2
2
 
3
3
  module Proxy
4
4
  module DHCP
@@ -9,118 +9,123 @@ module Proxy
9
9
  include Proxy::Util
10
10
 
11
11
  attr_reader :connection
12
+
12
13
  def initialize(connection, managed_subnets)
13
14
  @connection = connection
14
15
  @managed_subnets = managed_subnets
15
- super('bluecat', managed_subnets, nil)
16
+ super("bluecat", managed_subnets, nil)
16
17
  end
17
18
 
18
19
  # returns all subnets
19
20
  def subnets
20
- logger.debug('START subnets')
21
+ logger.debug("START subnets")
21
22
  subnets = @connection.subnets
22
- logger.debug('END subnets')
23
- logger.debug('Returned: ' + subnets.class.to_s + ': ' + subnets.to_s)
23
+ logger.debug("END subnets")
24
+ logger.debug("Returned: #{subnets.class}: #{subnets}")
24
25
  subnets
25
26
  end
26
27
 
27
28
  # returns all hosts in a subnet
28
29
  # in bluecat leases and hosts are the same
29
30
  def all_hosts(network_address)
30
- logger.debug('START all_hosts with network_address: ' + network_address.to_s)
31
+ logger.debug("START all_hosts with network_address: #{network_address}")
31
32
  hosts = @connection.hosts(network_address)
32
- logger.debug('END all_hosts with network_address: ' + network_address.to_s)
33
- logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
33
+ logger.debug("END all_hosts with network_address: #{network_address}")
34
+ logger.debug("Returned: #{hosts.class}: #{hosts}")
34
35
  hosts
35
36
  end
36
37
 
37
38
  # returns all leases in a subnet
38
39
  # in bluecat leases and hosts are the same
39
40
  def all_leases(network_address)
40
- logger.debug('START all_leases with network_address: ' + network_address.to_s)
41
+ logger.debug("START all_leases with network_address: #{network_address}")
41
42
  hosts = @connection.hosts(network_address)
42
- logger.debug('END all_leases with network_address: ' + network_address.to_s)
43
- logger.debug('Returned: ' + hosts.class.to_s + ': ' + hosts.to_s)
43
+ logger.debug("END all_leases with network_address: #{network_address}")
44
+ logger.debug("Returned: #{hosts.class}: #{hosts}")
44
45
  hosts
45
46
  end
46
47
 
47
48
  # returns the next free ip in a subnet
48
49
  def unused_ip(subnet, mac_address, from_ip_address, to_ip_address)
49
- logger.debug('START unused_ip with subnet: ' + subnet.to_s + ' mac_address: ' + mac_address.to_s + ' from_ip_address: ' + from_ip_address.to_s + ' to_ip_address: ' + to_ip_address.to_s)
50
+ logger.debug("START unused_ip with subnet: #{subnet} mac_address: #{mac_address} \
51
+ from_ip_address: #{from_ip_address} to_ip_address: #{to_ip_address}")
50
52
  ip = @connection.next_ip(subnet, from_ip_address, to_ip_address)
51
- logger.debug('END unused_ip with subnet: ' + subnet.to_s + ' mac_address: ' + mac_address.to_s + ' from_ip_address: ' + from_ip_address.to_s + ' to_ip_address: ' + to_ip_address.to_s)
52
- logger.debug('Returned: ' + ip.class.to_s + ': ' + ip.to_s)
53
+ logger.debug("END unused_ip with subnet: #{subnet} mac_address: #{mac_address} \
54
+ from_ip_address: #{from_ip_address} to_ip_address: #{to_ip_address}")
55
+ logger.debug("Returned: #{ip.class}: #{ip}")
53
56
  ip
54
57
  end
55
58
 
56
59
  # returns a record
57
60
  # foreman calls this method with a ip or a mac address
58
61
  def find_record(subnet_address, address)
59
- logger.debug('START find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
60
- records = if IPAddress.valid?(address)
61
- find_records_by_ip(subnet_address, address)
62
- else
63
- find_record_by_mac(subnet_address, address)
64
- end
65
- logger.debug('END find_record with subnet_address: ' + subnet_address.to_s + ' address: ' + address.to_s)
66
- logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
62
+ logger.debug("START find_record with subnet_address: #{net} address: #{address}")
63
+ if IPAddress.valid?(address)
64
+ records = find_records_by_ip(subnet_address, address)
65
+ else
66
+ records = find_record_by_mac(subnet_address, address)
67
+ end
68
+ logger.debug("END find_record with subnet_address: #{subnet_address} address: #{address}")
69
+ logger.debug("Returned: #{records.class}: #{records}")
67
70
  return [] if records.nil?
71
+
68
72
  records
69
73
  end
70
74
 
71
75
  # returns a record based on a ip address
72
76
  def find_records_by_ip(subnet_address, ip)
73
- logger.debug('START find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
77
+ logger.debug("START find_records_by_ip with subnet_address: #{subnet_address} ip: #{ip}")
74
78
  records = @connection.hosts_by_ip(ip)
75
- logger.debug('END find_records_by_ip with subnet_address: ' + subnet_address.to_s + ' ip: ' + ip.to_s)
76
- logger.debug('Returned: ' + records.class.to_s + ': ' + records.to_s)
79
+ logger.debug("END find_records_by_ip with subnet_address: #{subnet_address} ip: #{ip}")
80
+ logger.debug("Returned: #{records.class}: #{records}")
77
81
  return [] if records.nil?
82
+
78
83
  records
79
84
  end
80
85
 
81
86
  # returns a record based on a mac address
82
87
  def find_record_by_mac(subnet_address, mac_address)
83
- logger.debug('START find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
84
- record = @connection.host_by_mac(mac_address)
85
- logger.debug('END find_record_by_mac with subnet_address: ' + subnet_address.to_s + ' mac_address: ' + mac_address.to_s)
86
- logger.debug('Returned: ' + record.class.to_s + ': ' + record.to_s)
88
+ logger.debug("START find_record_by_mac with subnet_address: #{subnet_address} mac_address: #{mac_address}")
89
+ record = @connection.host_by_mac_and_subnet(subnet_address, mac_address)
90
+ logger.debug("END find_record_by_mac with subnet_address: #{subnet_address} mac_address: #{mac_address}")
91
+ logger.debug("Returned: #{record.class}: #{record}")
87
92
  record
88
93
  end
89
94
 
90
95
  # returns a subnet based on a subnet address
91
96
  def find_subnet(subnet_address)
92
- logger.debug('START find_subnet with subnet_address: ' + subnet_address.to_s)
97
+ logger.debug("START find_subnet with subnet_address: #{subnet_address}")
93
98
  net = @connection.find_mysubnet(subnet_address)
94
- logger.debug('END find_subnet with subnet_address: ' + subnet_address.to_s)
95
- logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
99
+ logger.debug("END find_subnet with subnet_address: #{subnet_address}")
100
+ logger.debug("Returned: #{net.class}: #{net}")
96
101
  net
97
102
  end
98
103
 
99
104
  # returns a subnet based on a subnet address
100
105
  def get_subnet(subnet_address)
101
- logger.debug('START get_subnet with subnet_address: ' + subnet_address.to_s)
106
+ logger.debug("START get_subnet with subnet_address: #{subnet_address}")
102
107
  net = @connection.find_mysubnet(subnet_address)
103
- logger.debug('END get_subnet with subnet_address: ' + subnet_address.to_s)
104
- logger.debug('Returned: ' + net.class.to_s + ': ' + net.to_s)
108
+ logger.debug("END get_subnet with subnet_address: #{subnet_address}")
109
+ logger.debug("Returned: #{net.class}: #{net}")
105
110
  net
106
111
  end
107
112
 
108
113
  # adds a host record
109
114
  def add_record(options)
110
- logger.debug('START add_record with options: ' + options.to_s)
115
+ logger.debug("START add_record with options: #{options}")
111
116
  @connection.add_host(options)
112
- logger.debug('END add_record with options: ' + options.to_s)
117
+ logger.debug("END add_record with options: #{options}")
113
118
  end
114
119
 
115
120
  # removes a host record
116
121
  def del_record(record)
117
- logger.debug('START del_record with record: ' + record.to_s)
122
+ logger.debug("START del_record with record: #{record}")
118
123
  if record.empty?
119
- logger.debug('record empty, nothing to do')
124
+ logger.debug("record empty, nothing to do")
120
125
  else
121
126
  @connection.remove_host(record.ip)
122
127
  end
123
- logger.debug('END del_record with record: ' + record.to_s)
128
+ logger.debug("END del_record with record: #{record}")
124
129
  end
125
130
  end
126
131
  end
@@ -4,9 +4,10 @@ module Proxy
4
4
  class Plugin < ::Proxy::Provider
5
5
  plugin :dhcp_bluecat, ::Proxy::DHCP::BlueCat::VERSION
6
6
 
7
- validate_presence :scheme, :verify, :host, :parent_block, :view_name, :config_id, :config_name, :server_id, :username, :password
7
+ validate_presence :scheme, :verify, :host, :parent_block, :view_name, :config_id, :config_name, :server_id, :username,
8
+ :password
8
9
 
9
- requires :dhcp, '>= 1.16'
10
+ requires :dhcp, ">= 1.16"
10
11
 
11
12
  load_classes ::Proxy::DHCP::BlueCat::PluginConfiguration
12
13
  load_dependency_injection_wirings ::Proxy::DHCP::BlueCat::PluginConfiguration
@@ -1,7 +1,7 @@
1
- module Proxy
2
- module DHCP
3
- module BlueCat
4
- VERSION = '0.1.5'.freeze
5
- end
6
- end
7
- end
1
+ module Proxy
2
+ module DHCP
3
+ module BlueCat
4
+ VERSION = "0.1.6".freeze
5
+ end
6
+ end
7
+ end
@@ -4,7 +4,7 @@ module Proxy
4
4
  class ModuleLoader < ::Proxy::DefaultModuleLoader
5
5
  def log_provider_settings(settings)
6
6
  super(settings)
7
- logger.warn('http is used for connection to BlueCat address manager') if settings[:scheme] != 'https'
7
+ logger.warn("http is used for connection to BlueCat address manager") if settings[:scheme] != "https"
8
8
  end
9
9
  end
10
10
  end
@@ -3,33 +3,33 @@ module Proxy
3
3
  module BlueCat
4
4
  class PluginConfiguration
5
5
  def load_classes
6
- require 'dhcp_common/dhcp_common'
7
- require 'smart_proxy_dhcp_bluecat/bluecat_api'
8
- require 'smart_proxy_dhcp_bluecat/dhcp_bluecat_main'
6
+ require "dhcp_common/dhcp_common"
7
+ require "smart_proxy_dhcp_bluecat/bluecat_api"
8
+ require "smart_proxy_dhcp_bluecat/dhcp_bluecat_main"
9
9
  end
10
10
 
11
- def load_dependency_injection_wirings(c, settings)
12
- c.dependency :connection, (lambda do
13
- ::Proxy::DHCP::BlueCat::BlueCatAPI.new(
14
- settings[:scheme],
15
- settings[:verify],
16
- settings[:host],
17
- settings[:parent_block],
18
- settings[:view_name],
19
- settings[:config_name],
20
- settings[:config_id],
21
- settings[:server_id],
22
- settings[:username],
23
- settings[:password]
24
- )
25
- end)
11
+ def load_dependency_injection_wirings(conf, settings)
12
+ conf.dependency :connection, (lambda do
13
+ ::Proxy::DHCP::BlueCat::BlueCatAPI.new(
14
+ settings[:scheme],
15
+ settings[:verify],
16
+ settings[:host],
17
+ settings[:parent_block],
18
+ settings[:view_name],
19
+ settings[:config_name],
20
+ settings[:config_id],
21
+ settings[:server_id],
22
+ settings[:username],
23
+ settings[:password]
24
+ )
25
+ end)
26
26
 
27
- c.dependency :dhcp_provider, (lambda do
28
- ::Proxy::DHCP::BlueCat::Provider.new(
29
- c.get_dependency(:connection),
30
- settings[:subnets]
31
- )
32
- end)
27
+ conf.dependency :dhcp_provider, (lambda do
28
+ ::Proxy::DHCP::BlueCat::Provider.new(
29
+ c.get_dependency(:connection),
30
+ settings[:subnets]
31
+ )
32
+ end)
33
33
  end
34
34
  end
35
35
  end
@@ -3,61 +3,80 @@ module Proxy
3
3
  module BlueCat
4
4
  class SchemeValidator < ::Proxy::PluginValidators::Base
5
5
  def validate!(settings)
6
- return true if ['http', 'https'].include?(settings[:scheme])
6
+ return true if %w[http https].include?(settings[:scheme])
7
+
7
8
  raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
8
9
  end
9
10
  end
11
+
10
12
  class VerifyValidator < ::Proxy::PluginValidators::Base
11
13
  def validate!(settings)
12
14
  return true if [true, false].include?(settings[:verify])
15
+
13
16
  raise ::Proxy::Error::ConfigurationError, "Setting 'verify' can be set to either 'true' or 'false' (bool)"
14
17
  end
15
18
  end
19
+
16
20
  class HostValidator < ::Proxy::PluginValidators::Base
17
21
  def validate!(settings)
18
- return true if ['http', 'https'].include?(settings[:scheme])
22
+ return true if %w[http https].include?(settings[:scheme])
23
+
19
24
  raise ::Proxy::Error::ConfigurationError, "Setting 'scheme' can be set to either 'http' or 'https'"
20
25
  end
21
26
  end
27
+
22
28
  class ParentBlockValidator < ::Proxy::PluginValidators::Base
23
29
  def validate!(settings)
24
30
  return true if settings[:parent_block].is_a?(Integer)
31
+
25
32
  raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
26
33
  end
27
34
  end
35
+
28
36
  class ViewNameValidator < ::Proxy::PluginValidators::Base
29
37
  def validate!(settings)
30
38
  return true if settings[:view_name].is_a?(String)
39
+
31
40
  raise ::Proxy::Error::ConfigurationError, "Setting 'view_name' must be (string)"
32
41
  end
33
42
  end
43
+
34
44
  class ConfigIdValidator < ::Proxy::PluginValidators::Base
35
45
  def validate!(settings)
36
46
  return true if settings[:config_id].is_a?(Integer)
47
+
37
48
  raise ::Proxy::Error::ConfigurationError, "Setting 'parent_block' must be (integer)"
38
49
  end
39
50
  end
51
+
40
52
  class ConfigNameValidator < ::Proxy::PluginValidators::Base
41
53
  def validate!(settings)
42
54
  return true if settings[:config_name].is_a?(String)
55
+
43
56
  raise ::Proxy::Error::ConfigurationError, "Setting 'config_name' must be (string)"
44
57
  end
45
58
  end
59
+
46
60
  class ServerIdValidator < ::Proxy::PluginValidators::Base
47
61
  def validate!(settings)
48
62
  return true if settings[:server_id].is_a?(Integer)
63
+
49
64
  raise ::Proxy::Error::ConfigurationError, "Setting 'server_id' must be (integer)"
50
65
  end
51
66
  end
67
+
52
68
  class UsernameValidator < ::Proxy::PluginValidators::Base
53
69
  def validate!(settings)
54
70
  return true if settings[:username].is_a?(String)
71
+
55
72
  raise ::Proxy::Error::ConfigurationError, "Setting 'username' must be (string)"
56
73
  end
57
74
  end
75
+
58
76
  class PasswordValidator < ::Proxy::PluginValidators::Base
59
77
  def validate!(settings)
60
78
  return true if settings[:password].is_a?(String)
79
+
61
80
  raise ::Proxy::Error::ConfigurationError, "Setting 'password' must be (string)"
62
81
  end
63
82
  end
@@ -4,8 +4,8 @@ module Proxy
4
4
  end
5
5
  end
6
6
 
7
- require 'smart_proxy_dhcp_bluecat/plugin_configuration'
8
- require 'smart_proxy_dhcp_bluecat/module_loader'
9
- require 'smart_proxy_dhcp_bluecat/settings_validator'
10
- require 'smart_proxy_dhcp_bluecat/dhcp_bluecat_version'
11
- require 'smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin'
7
+ require "smart_proxy_dhcp_bluecat/plugin_configuration"
8
+ require "smart_proxy_dhcp_bluecat/module_loader"
9
+ require "smart_proxy_dhcp_bluecat/settings_validator"
10
+ require "smart_proxy_dhcp_bluecat/dhcp_bluecat_version"
11
+ require "smart_proxy_dhcp_bluecat/dhcp_bluecat_plugin"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dhcp_bluecat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Hähnel
8
8
  - The Foreman Team
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-23 00:00:00.000000000 Z
12
+ date: 2021-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -39,20 +39,6 @@ dependencies:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: rubocop
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: 0.50.0
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: 0.50.0
56
42
  description: BlueCat DHCP provider plugin for Foreman's smart proxy
57
43
  email:
58
44
  - matthias.haehnel@sixt.com
@@ -77,7 +63,7 @@ homepage: https://github.com/theforeman/smart_proxy_dhcp_bluecat
77
63
  licenses:
78
64
  - GPL-3.0
79
65
  metadata: {}
80
- post_install_message:
66
+ post_install_message:
81
67
  rdoc_options: []
82
68
  require_paths:
83
69
  - lib
@@ -85,7 +71,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
71
  requirements:
86
72
  - - ">="
87
73
  - !ruby/object:Gem::Version
88
- version: '0'
74
+ version: '2.5'
89
75
  required_rubygems_version: !ruby/object:Gem::Requirement
90
76
  requirements:
91
77
  - - ">="
@@ -93,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
79
  version: '0'
94
80
  requirements: []
95
81
  rubygems_version: 3.1.2
96
- signing_key:
82
+ signing_key:
97
83
  specification_version: 4
98
84
  summary: BlueCat DHCP provider plugin for Foreman's smart proxy
99
85
  test_files: []