smart_proxy_dhcp_kea_api 1.0.0

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.
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proxy
4
+ module DHCP
5
+ module KeaApi
6
+ # This class manages the setup and configuration of the KeaApi plugin's
7
+ # internal components. It follows a pattern used by the Foreman Smart Proxy's
8
+ # dependency injection (DI) framework. Its responsibilities are divided into
9
+ # two main parts: loading the necessary classes into memory and then "wiring"
10
+ # them together by defining how each service gets created and what its
11
+ # dependencies are.
12
+ class PluginConfiguration
13
+ # Loads all the necessary classes for this provider into memory.
14
+ # This is called by the Smart Proxy before the dependency injection
15
+ # wirings are configured.
16
+
17
+ def load_classes
18
+ require 'dhcp_common/free_ips'
19
+ require 'smart_proxy_dhcp_kea_api/kea_api_client'
20
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_subnet_service'
21
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_main'
22
+ end
23
+
24
+ # Configures the dependency injection wirings for the KeaApi provider.
25
+ # The container is responsible for creating and managing instances of our services.
26
+ #
27
+ # @param container [Proxy::DependencyInjection::Container] The DI container to register services with.
28
+ # @param settings [Hash] The settings hash for this provider.
29
+
30
+ def load_dependency_injection_wirings(container, settings)
31
+ # A standard in-memory key-value store provided by the Smart Proxy framework.
32
+ # It's used by the SubnetService to cache DHCP data.
33
+ container.singleton_dependency :memory_store, -> { ::Proxy::MemoryStore.new }
34
+
35
+ # A singleton service that manages the temporary blacklisting of suggested IP addresses
36
+ # to prevent race conditions. Its duration is configured via the settings file.
37
+ container.singleton_dependency :unused_ips, -> { ::Proxy::DHCP::FreeIps.new(settings[:blacklist_duration_minutes]) }
38
+
39
+ # The custom client for communicating with the Kea API. This is registered as a singleton
40
+ # so that a single, persistent HTTP connection pool is used for all API calls.
41
+ container.singleton_dependency :kea_client, (lambda do
42
+ ::Proxy::DHCP::KeaApi::Client.new(
43
+ url: settings[:kea_api_url],
44
+ open_timeout: settings[:open_timeout],
45
+ read_timeout: settings[:read_timeout]
46
+ )
47
+ end)
48
+
49
+ # The custom service for caching all subnet, reservation, and lease data.
50
+ # This is a singleton because we want one central, authoritative cache that all
51
+ # requests can share. It depends on the Kea client to fetch data and the memory
52
+ # stores to cache it.
53
+ container.singleton_dependency :subnet_service, (lambda do
54
+ memory_store = container.get_dependency(:memory_store)
55
+ ::Proxy::DHCP::KeaApi::SubnetService.new(
56
+ container.get_dependency(:kea_client),
57
+ memory_store,
58
+ memory_store,
59
+ memory_store,
60
+ memory_store,
61
+ memory_store
62
+ )
63
+ end)
64
+
65
+ # The main provider class that ties everything together. This is the entry point
66
+ # for handling DHCP requests from Foreman. It depends on the subnet service,
67
+ # the API client, and the IP blacklist service to do its job.
68
+ container.dependency :dhcp_provider, (lambda do
69
+ ::Proxy::DHCP::KeaApi::Provider.new(
70
+ container.get_dependency(:subnet_service),
71
+ container.get_dependency(:kea_client),
72
+ container.get_dependency(:unused_ips)
73
+ )
74
+ end)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proxy
4
+ module DHCP
5
+ # The top-level namespace for this DHCP provider. All classes, modules,
6
+ # and services related to the Kea API integration will be defined within
7
+ # this KeaApi module to prevent naming conflicts with other plugins.
8
+ module KeaApi; end
9
+ end
10
+ end
11
+
12
+ # Require all the plugin's classes so they are available in the test environment
13
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_version'
14
+ require 'smart_proxy_dhcp_kea_api/kea_api_client'
15
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_subnet_service'
16
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_main'
17
+ require 'smart_proxy_dhcp_kea_api/plugin_configuration'
18
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_plugin'
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+
5
+ require 'smart_proxy_dhcp_kea_api/dhcp_kea_api_version'
6
+ require 'date'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'smart_proxy_dhcp_kea_api'
10
+ s.version = Proxy::DHCP::KeaApi::VERSION
11
+ s.authors = ['Sam McCarthy']
12
+ s.homepage = 'https://gitlab.surrey.ac.uk/sm0049/smart-proxy-dhcp-kea-api'
13
+ s.summary = 'Foreman Smart Proxy plugin for ISC Kea DHCP API'
14
+ s.description = 'Provides DHCP management for Foreman via the ISC Kea API, requiring the host_cmds and lease_cmds hooks.'
15
+ s.license = 'GPL-3.0-only'
16
+ s.required_ruby_version = '>= 3.0', '< 4'
17
+
18
+ s.files = Dir.glob('{lib}/**/*', File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
19
+ s.files += %w[LICENSE README.md smart_proxy_dhcp_kea_api.gemspec]
20
+
21
+ s.require_paths = ['lib']
22
+
23
+ s.metadata['rubygems_mfa_required'] = 'true'
24
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_proxy_dhcp_kea_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sam McCarthy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides DHCP management for Foreman via the ISC Kea API, requiring the
14
+ host_cmds and lease_cmds hooks.
15
+ email:
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/smart_proxy_dhcp_kea_api.rb
23
+ - lib/smart_proxy_dhcp_kea_api/dhcp_kea_api_main.rb
24
+ - lib/smart_proxy_dhcp_kea_api/dhcp_kea_api_plugin.rb
25
+ - lib/smart_proxy_dhcp_kea_api/dhcp_kea_api_subnet_service.rb
26
+ - lib/smart_proxy_dhcp_kea_api/dhcp_kea_api_version.rb
27
+ - lib/smart_proxy_dhcp_kea_api/kea_api_client.rb
28
+ - lib/smart_proxy_dhcp_kea_api/plugin_configuration.rb
29
+ - smart_proxy_dhcp_kea_api.gemspec
30
+ homepage: https://gitlab.surrey.ac.uk/sm0049/smart-proxy-dhcp-kea-api
31
+ licenses:
32
+ - GPL-3.0-only
33
+ metadata:
34
+ rubygems_mfa_required: 'true'
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '4'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.4.19
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Foreman Smart Proxy plugin for ISC Kea DHCP API
57
+ test_files: []