class Chef::Resource::WindowsAdJoin

Public Instance Methods

clarify_reboot(reboot_action) click to toggle source

This resource historically took `:immediate` and `:delayed` as arguments to the reboot property but then tried to shove that straight to the `reboot` resource which objected strenuously

# File lib/chef/resource/windows_ad_join.rb, line 221
def clarify_reboot(reboot_action)
  case reboot_action
  when :immediate
    :reboot_now
  when :delayed
    :request_reboot
  else
    reboot_action
  end
end
joined_to_domain?() click to toggle source

@return [true, false] Whether or not the node is joined to ANY domain

# File lib/chef/resource/windows_ad_join.rb, line 190
def joined_to_domain?
  node_workgroup.empty? && !node_domain.empty?
end
node_domain() click to toggle source

@return [String] The domain name the node is joined to. When the node

is not joined to a domain this will return the name of the
workgroup the node is a member of.
# File lib/chef/resource/windows_ad_join.rb, line 168
def node_domain
  node_domain = powershell_exec!("(Get-WmiObject Win32_ComputerSystem).Domain")
  raise "Failed to check if the system is joined to the domain #{new_resource.domain_name}: #{node_domain.errors}}" if node_domain.error?

  node_domain.result.downcase.strip
end
node_workgroup() click to toggle source

@return [String] The workgroup the node is a member of. This will

return an empty string if the system is not a member of a
workgroup.
# File lib/chef/resource/windows_ad_join.rb, line 180
def node_workgroup
  node_workgroup = powershell_exec!("(Get-WmiObject Win32_ComputerSystem).Workgroup")
  raise "Failed to check if the system is currently a member of a workgroup" if node_workgroup.error?

  node_workgroup.result
end
on_desired_domain?() click to toggle source

@return [true, false] Whether or not the node is joined to the domain

defined by the resource :domain_name property.
# File lib/chef/resource/windows_ad_join.rb, line 198
def on_desired_domain?
  node_domain == new_resource.domain_name.downcase
end
sanitize_usename() click to toggle source

@return [String] the correct user and domain to use.

if the domain_user property contains an @ symbol followed by any number of non white space characters
then we assume it is a user from another domain than the one specified in the resource domain_name property.
if this is the case we do not append the domain_name property to the domain_user property
the domain_user and domain_name form the UPN (userPrincipalName)
The specification for the UPN format is RFC 822
links: https://docs.microsoft.com/en-us/windows/win32/ad/naming-properties#userprincipalname https://tools.ietf.org/html/rfc822
regex: https://rubular.com/r/isAWojpTMKzlnp
# File lib/chef/resource/windows_ad_join.rb, line 211
def sanitize_usename
  if /@/.match?(new_resource.domain_user)
    new_resource.domain_user
  else
    "#{new_resource.domain_user}@#{new_resource.domain_name}"
  end
end
sensitive?() click to toggle source
# File lib/chef/resource/windows_ad_join.rb, line 232
def sensitive?
  !!new_resource.sensitive
end