Class: LDAPNetgroupPlugin

Inherits:
Architect::Plugin show all
Defined in:
lib/architect/plugin/ldap_netgroup.rb

Overview

Manage host membership in the LDAP ‘Security Netgroup’ subtree

Instance Attribute Summary collapse

Attributes inherited from Architect::Plugin

#name

Instance Method Summary collapse

Methods inherited from Architect::Plugin

#check, #design, #execute, #plan, #register

Constructor Details

#initializeLDAPNetgroupPlugin

Returns a new instance of LDAPNetgroupPlugin.



10
11
12
13
14
# File 'lib/architect/plugin/ldap_netgroup.rb', line 10

def initialize
  @name = 'ldap_netgroup'
  @log = Architect::Log.log
  #log.level = Logger::DEBUG
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



8
9
10
# File 'lib/architect/plugin/ldap_netgroup.rb', line 8

def log
  @log
end

Instance Method Details

#configure(config_hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/architect/plugin/ldap_netgroup.rb', line 16

def configure(config_hash)
  @config = OpenStruct.new({
      host: nil,
      port: nil,
      bind_dn: nil,
      bind_password: nil,
      base_dn: nil,
      nis_domain: nil,
  }.merge(config_hash))

  bind_to_server
end

#instance_create(fqdn) ⇒ Object

Add a [fqdn] to netgroups



53
54
55
56
57
58
59
60
61
# File 'lib/architect/plugin/ldap_netgroup.rb', line 53

def instance_create(fqdn)
  value = '(' + [fqdn.gsub(/\..*/, ''), '', config.nis_domain].join(',') + ')'
  netgroup_membership(fqdn).each do |dn|
    log.debug "adding #{value} to #{dn}"
    ops = [[:add, :nisNetgroupTriple, value]]
    ldap.modify :dn => dn, :operations => ops
    check_operation_result
  end
end

#instance_delete(fqdn) ⇒ Object

Delete a [fqdn] from all netgroups



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/architect/plugin/ldap_netgroup.rb', line 30

def instance_delete(fqdn)
  shortname = fqdn.gsub(/\..*/, '')
  match = '(' + [shortname, '', config.nis_domain].join(',') + ')'
  treebase = config.base_dn
  filter = Net::LDAP::Filter.eq( 'nisnetgrouptriple', match )
  attrs = [ "nisnetgrouptriple" ]

  log.debug "searching for #{match}"
  ldap.search(base: treebase, filter: filter, attributes: attrs, return_result: false) do |entry|
         log.debug "deleting #{shortname} from #{entry.dn}"
         dn = entry.dn
         ops = [[:delete, :nisNetgroupTriple, match]]
         ldap.modify :dn => dn, :operations => ops
  end
end

#instance_rename(old_fqdn, new_fqdn) ⇒ Object

Rename an instance



47
48
49
50
# File 'lib/architect/plugin/ldap_netgroup.rb', line 47

def instance_rename(old_fqdn, new_fqdn)
  instance_delete old_fqdn
  instance_create new_fqdn
end