Skip to content

Commit fe5aa5f

Browse files
committed
add support for Puppet Agent API endpoint
1 parent d6e6cdd commit fe5aa5f

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ A Ruby client library and CLI tool for the OPNsense REST API.
2727
- [Node Exporter](#node-exporter)
2828
- [OpenVPN](#openvpn)
2929
- [Plugins](#plugins)
30+
- [Puppet Agent](#puppet-agent)
3031
- [Routes](#routes)
3132
- [Service reconfigure](#service-reconfigure-1)
3233
- [Snapshots](#snapshots)
@@ -121,6 +122,7 @@ Backups and plugins are managed separately via dedicated commands (`backup`, `pl
121122
| `openvpn_cso` | OpenVPN client-specific overrides |
122123
| `openvpn_instance` | OpenVPN instances |
123124
| `openvpn_statickey` | OpenVPN static keys |
125+
| `puppet_agent` | Puppet Agent settings (singleton) |
124126
| `route` | Static routes |
125127
| `snapshot` | ZFS snapshots |
126128
| `syslog` | Syslog remote destinations |
@@ -607,6 +609,22 @@ $ opn-api -d opnsense01 uninstall os-haproxy
607609

608610
Note: Install/uninstall are asynchronous — the API returns immediately while the operation continues in the background.
609611

612+
### Puppet Agent
613+
614+
Puppet Agent is a singleton resource (one per device).
615+
616+
```
617+
# Show Puppet Agent settings (singleton)
618+
$ opn-api -d opnsense01 show puppet_agent
619+
620+
# Update Puppet Agent settings (wrapper key: "puppetagent")
621+
$ opn-api -d opnsense01 update puppet_agent \
622+
-j '{"puppetagent":{"general":{"Enabled":"1","FQDN":"puppet.example.com","Environment":"production"}}}'
623+
624+
# Apply changes
625+
$ opn-api -d opnsense01 reconfigure puppet_agent
626+
```
627+
610628
### Routes
611629

612630
```
@@ -962,7 +980,7 @@ Resource names follow the [puppet-opn](https://github.com/markt-de/puppet-opn) n
962980

963981
`OpnApi::ServiceReconfigure` orchestrates service reloads after configuration changes. Features include:
964982

965-
- Registry pattern with 18 pre-registered OPNsense service groups
983+
- Registry pattern with many pre-registered OPNsense service groups
966984
- Mark/run pattern: track devices with changes, then batch-reconfigure
967985
- Configtest support (e.g. HAProxy validates config before reconfigure)
968986
- Error tracking: skip reconfigure for devices with failed resource changes

lib/opn_api/resource_registry.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,13 @@ module ResourceRegistry
259259
crud_action: '%{action}', wrapper: 'general',
260260
singleton: true, search_method: :get
261261
},
262+
# --- Puppet Agent ---
263+
'puppet_agent' => {
264+
base_path: 'puppetagent/settings', search_action: 'get',
265+
crud_action: '%{action}', wrapper: 'puppetagent',
266+
singleton: true, search_method: :get,
267+
response_dig: ['general']
268+
},
262269
# --- OpenVPN ---
263270
'openvpn_cso' => {
264271
base_path: 'openvpn/client_overwrites', search_action: 'search',

lib/opn_api/service_reconfigure.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ def self.register_defaults
258258
endpoint: 'nodeexporter/service/reconfigure',
259259
log_prefix: 'opn_node_exporter')
260260

261+
# Puppet Agent
262+
register(:puppet_agent,
263+
endpoint: 'puppetagent/service/reconfigure',
264+
log_prefix: 'opn_puppet_agent')
265+
261266
# OpenVPN
262267
register(:openvpn,
263268
endpoint: 'openvpn/service/reconfigure',

spec/opn_api/resource_registry_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
it 'provides response_dig for singletons with sub-resources' do
5151
# Single sub-key extraction (acmeclient settings nested under 'settings')
5252
expect(described_class.lookup('acmeclient_settings')[:response_dig]).to eq(['settings'])
53+
# Single sub-key extraction (puppet_agent settings nested under 'general')
54+
expect(described_class.lookup('puppet_agent')[:response_dig]).to eq(['general'])
5355
# Multi-key slice (haproxy, ipsec, kea)
5456
expect(described_class.lookup('ipsec_settings')[:response_dig]).to eq(%w[general charon])
5557
expect(described_class.lookup('kea_dhcpv4')[:response_dig]).to eq(%w[general lexpire ha])
@@ -69,6 +71,15 @@
6971
expect(described_class.lookup('zabbix_proxy')[:response_dig]).to be_nil
7072
end
7173

74+
it 'handles puppet_agent singleton with settings controller' do
75+
entry = described_class.lookup('puppet_agent')
76+
expect(entry[:base_path]).to eq('puppetagent/settings')
77+
expect(entry[:singleton]).to be true
78+
expect(entry[:search_method]).to eq(:get)
79+
expect(entry[:wrapper]).to eq('puppetagent')
80+
expect(entry[:response_dig]).to eq(['general'])
81+
end
82+
7283
it 'handles Kea camelCase endpoints' do
7384
entry = described_class.lookup('kea_dhcpv4_subnet')
7485
expect(entry[:base_path]).to eq('kea/dhcpv4')
@@ -118,6 +129,7 @@
118129
'kea_dhcpv6', 'kea_dhcpv6_pd_pool',
119130
'node_exporter',
120131
'openvpn_instance', 'openvpn_cso', 'openvpn_statickey',
132+
'puppet_agent',
121133
'route', 'snapshot', 'syslog',
122134
'trust_ca', 'trust_cert', 'trust_crl',
123135
'tunable', 'user',

spec/opn_api/service_reconfigure_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
described_class.load_defaults!
3939
names = described_class.registered_names
4040
expect(names).to include(:haproxy, :ipsec, :openvpn, :kea, :firewall_alias,
41-
:firewall_rule, :cron, :dhcrelay, :gateway, :route)
41+
:firewall_rule, :cron, :dhcrelay, :gateway,
42+
:puppet_agent, :route)
4243
end
4344
end
4445

0 commit comments

Comments
 (0)