Class: Proxy::AdRealm::Provider

Inherits:
Object
  • Object
show all
Includes:
Kerberos, Log, Util
Defined in:
lib/smart_proxy_realm_ad/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Provider

Returns a new instance of Provider.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/smart_proxy_realm_ad/provider.rb', line 13

def initialize(options = {})
  @realm = options[:realm]
  @keytab_path = options[:keytab_path]
  @principal = options[:principal]
  @domain_controller = options[:domain_controller]
  @domain = options[:realm].downcase
  @ou = options[:ou]
  @computername_prefix = options[:computername_prefix]
  @computername_hash = options.fetch(:computername_hash, false)
  @computername_use_fqdn = options.fetch(:computername_use_fqdn, false)
  logger.info 'Proxy::AdRealm: initialize...'
end

Instance Attribute Details

#computername_hashObject (readonly)

Returns the value of attribute computername_hash.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def computername_hash
  @computername_hash
end

#computername_prefixObject (readonly)

Returns the value of attribute computername_prefix.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def computername_prefix
  @computername_prefix
end

#computername_use_fqdnObject (readonly)

Returns the value of attribute computername_use_fqdn.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def computername_use_fqdn
  @computername_use_fqdn
end

#domainObject (readonly)

Returns the value of attribute domain.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def domain
  @domain
end

#domain_controllerObject (readonly)

Returns the value of attribute domain_controller.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def domain_controller
  @domain_controller
end

#keytab_pathObject (readonly)

Returns the value of attribute keytab_path.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def keytab_path
  @keytab_path
end

#ouObject (readonly)

Returns the value of attribute ou.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def ou
  @ou
end

#principalObject (readonly)

Returns the value of attribute principal.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def principal
  @principal
end

#realmObject (readonly)

Returns the value of attribute realm.



11
12
13
# File 'lib/smart_proxy_realm_ad/provider.rb', line 11

def realm
  @realm
end

Instance Method Details

#check_realm(realm) ⇒ Object

Raises:

  • (Exception)


26
27
28
# File 'lib/smart_proxy_realm_ad/provider.rb', line 26

def check_realm(realm)
  raise Exception, "Unknown realm #{realm}" unless realm.casecmp(@realm).zero?
end

#create(realm, hostfqdn, params) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/smart_proxy_realm_ad/provider.rb', line 34

def create(realm, hostfqdn, params)
  logger.info "Proxy::AdRealm: create... #{realm}, #{hostfqdn}, #{params}"
  check_realm(realm)
  kinit_radcli_connect

  password = generate_password
  result = { randompassword: password }

  computername = hostfqdn_to_computername(hostfqdn)

  if params[:rebuild] == 'true'
    radcli_password(computername, password)
  else
    radcli_join(hostfqdn, computername, password)
  end

  JSON.pretty_generate(result)
end

#delete(realm, hostfqdn) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/smart_proxy_realm_ad/provider.rb', line 53

def delete(realm, hostfqdn)
  logger.info "Proxy::AdRealm: delete... #{realm}, #{hostfqdn}"
  kinit_radcli_connect
  check_realm(realm)
  computername = hostfqdn_to_computername(hostfqdn)
  radcli_delete(computername)
end

#find(_hostfqdn) ⇒ Object



30
31
32
# File 'lib/smart_proxy_realm_ad/provider.rb', line 30

def find(_hostfqdn)
  true
end