Class: Puppet::Provider::OpnsenseDevice::OpnsenseDevice

Inherits:
Puppet::Provider::OpnsenseProvider
  • Object
show all
Defined in:
lib/puppet/provider/opnsense_device/opnsense_device.rb

Overview

Implementation for the opnsense_device type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object

Parameters:

  • _context (Puppet::ResourceApi::BaseContext)
  • resources (Hash)


136
137
138
139
140
141
142
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 136

def canonicalize(_context, resources)
  resources.each do |r|
    if r.key?(:api_secret) && r[:api_secret].is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive)
      r[:api_secret] = _gen_pw(_extract_pw(r[:api_secret]))
    end
  end
end

#create(_context, name, should) ⇒ File

Parameters:

  • _context (Puppet::ResourceApi::BaseContext)
  • name (String)
  • should (Hash<Symbol>)

Returns:

  • (File)


74
75
76
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 74

def create(_context, name, should)
  _write_config(name, should)
end

#delete(_context, name) ⇒ Object

Parameters:

  • _context (Puppet::ResourceApi::BaseContext)
  • name (String)


129
130
131
132
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 129

def delete(_context, name)
  path = get_config_path(name)
  FileUtils.rm(path, force: true)
end

#get(_context, filter) ⇒ Array<Hash<Symbol>>

Parameters:

  • _context (Puppet::ResourceApi::BaseContext)
  • filter (Array<Hash<Symbol>>)

Returns:

  • (Array<Hash<Symbol>>)


14
15
16
17
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 14

def get(_context, filter)
  device_names = get_device_names_by_filter(filter)
  _get_devices(device_names)
end

#get_device_names_by_filter(filter) ⇒ Array<Hash<Symbol>>, Array<String>

Parameters:

  • filter (Array<Hash<Symbol>>)

Returns:

  • (Array<Hash<Symbol>>, Array<String>)


21
22
23
24
25
26
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 21

def get_device_names_by_filter(filter)
  if filter.empty?
    return get_configured_devices
  end
  filter
end

#update(_context, name, should) ⇒ Object

Parameters:

  • _context (Puppet::ResourceApi::BaseContext)
  • name (String)
  • should (Hash<Symbol>)


81
82
83
# File 'lib/puppet/provider/opnsense_device/opnsense_device.rb', line 81

def update(_context, name, should)
  _write_config(name, should)
end