class Jamf::DirectoryBinding

A Directory Binding object in the JSS These are rather complex objects, and contain settings specific to the directory object’s type.

@see Jamf::APIObject @see Jamf::DirectoryBindingType @note “Jamf::DirectoryBinding.fetch name: ‘BindingName’” seems to be returning a 500 error in my test evironment. Use “Jamf::DirectoryBinding.fetch ‘BindingName’ instead.”

Constants

DIRECTORY_BINDING_TYPE

! You CAN update this

DIRECTORY_BINDING_TYPE_CLASSES
RSRC_BASE

The base for REST resources of this class

RSRC_LIST_KEY

the hash key used for the JSON list output of all objects in the JSS

RSRC_OBJECT_KEY

The hash key used for the JSON object output. It’s also used in various error messages

Attributes

computer_ou[R]
domain[R]
id[R]

Attributes

name[R]
password[R]
password_sha256[R]
priority[R]
type[R]
type_settings[R]
username[R]

Public Class Methods

new(**args) click to toggle source

Constructor @see Jamf::APIObject.initialize @note When creating an object with specific properties use the objects name and then the settings. Ex: Creating an Active Directory object: Jamf::DirectoryBinding.make name: “Example Binding”, username: “BindingUser”, password: “SuperMonkey123”, computer_ou: “computers”, active_directory: { multiple_domains: false }, domain: your.domain.server

Calls superclass method Jamf::APIObject::new
    # File lib/jamf/api/classic/api_objects/directory_binding.rb
110 def initialize(**args)
111     super
112 
113     if self.in_jss?
114         @priority = @init_data[:priority]
115         @domain = @init_data[:domain]
116         @username = @init_data[:username]
117         @password_sha256 = @init_data[:password_sha256]
118         @computer_ou = @init_data[:computer_ou]
119         @type = @init_data[:type]
120 
121         class_key = DIRECTORY_BINDING_TYPE.select { |k,v| v == @type }.map { |k,v| k }.first
122         self.set_type_settings (DIRECTORY_BINDING_TYPE_CLASSES[@type.to_s].new @init_data[class_key])
123     else
124         # Build
125         raise Jamf::MissingDataError, "domain must be provided." if @init_data[:domain].nil?
126         raise Jamf::MissingDataError, "username must be provided." if @init_data[:username].nil?
127         raise Jamf::MissingDataError, "computer_ou must be provided." if @init_data[:computer_ou].nil?
128         raise Jamf::MissingDataError, "password must be provided when creating a DirectoryBinding object." if @init_data[:password].nil?
129         raise Jamf::MissingDataError, "Type must be provided, one of \":#{DIRECTORY_BINDING_TYPE.keys.join(",:")}\"." if @init_data[:type].nil?
130         raise Jamf::InvalidDataError, "Type must be one of \":#{DIRECTORY_BINDING_TYPE.keys.join(",:")}\"." unless DIRECTORY_BINDING_TYPE.keys.include? @init_data[:type]
131         raise Jamf::InvalidDataError, "Priority must be between 1 and 10" if !@init_data[:priority].nil? && (@init_data[:priority] <= 1 || @init_data[:priority] >= 10)
132 
133         @domain = @init_data[:domain]
134         @username = @init_data[:username]
135         @computer_ou = @init_data[:computer_ou]
136         @type = DIRECTORY_BINDING_TYPE[@init_data[:type]]
137         @password = @init_data[:password]
138         @priority = @init_data[:priority]
139 
140         @priority = 1 if @priority.nil?
141 
142 
143         class_key = DIRECTORY_BINDING_TYPE.select { |k,v| v == @type }.map { |k,v| k }.first
144         self.set_type_settings (DIRECTORY_BINDING_TYPE_CLASSES[@type.to_s].new @init_data[class_key])
145 
146     end
147 
148 end

Public Instance Methods

computer_ou=(newvalue) click to toggle source

The OU path the computer object is to be placed

@author Tyler Morgan

@param newvalue [String]

@raise [Jamf::InvalidDataError] If newvalue is not a String

@return [void]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
216 def computer_ou=(newvalue)
217     raise Jamf::InvalidDataError, "Computer OU must be a String" unless newvalue.is_a? String
218 
219     @computer_ou = newvalue
220     @need_to_update = true
221 end
domain=(newvalue) click to toggle source

The domain the device will be bound to.

@author Tyler Morgan

@param newvalue [String]

@raise [Jamf::InvalidDataError] If newvalue is not a String

@return [void]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
162 def domain=(newvalue)
163     raise Jamf::InvalidDataError, "Domain must be a String" unless newvalue.is_a? String
164 
165     @domain = newvalue.to_s
166     @need_to_update = true
167 end
password=(newvalue) click to toggle source

Sets the password used in conjunction with the username to attempt to bind the computer to the domain.

@author Tyler Morgan

@param newvalue [String]

@raise [Jamf::InvalidDataError] If newvalue is not a String

@return [void]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
234 def password=(newvalue)
235     raise Jamf::InvalidDataError, "Password must be a string" unless newvalue.is_a? String
236 
237     @password = newvalue
238     @need_to_update = true
239 end
priority=(newvalue) click to toggle source

The priority the domain has over another one.

@author Tyler Morgan

@param newvalue [Integer]

@raise [Jamf::InvalidDataError] If newvalue is not an Integer @raise [Jamf::InvalidDataError] If newvalue is not between 1 and 10

@return [void]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
197 def priority=(newvalue)
198     raise Jamf::InvalidDataError, "Priority must be a Integer" unless newvalue.is_a? Integer
199     raise Jamf::InvalidDataError, "Priority cannot exceed 10" unless newvalue <= 10
200     raise Jamf::InvalidDataError, "Priority must be greater than 0" unless newvalue > 0
201 
202     @priority = newvalue
203     @need_to_update = true
204 end
username=(newvalue) click to toggle source

The username used to attempt to bind the device to the domain.

@author Tyler Morgan

@param newvalue [String]

@raise [Jamf::InvalidDataError] If newvalue is not a String

@return [void]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
179 def username=(newvalue)
180     raise Jamf::InvalidDataError, "Username must be a String" unless newvalue.is_a? String
181 
182     @username = newvalue
183     @need_to_update = true
184 end

Private Instance Methods

rest_xml() click to toggle source

the xml formated data for adding or updating this in the JSS

This method constructs a properly formatted XML document to be handled by the Jamf Pro API

@author Tyler Morgan

@return [String]

    # File lib/jamf/api/classic/api_objects/directory_binding.rb
252 def rest_xml
253     doc = REXML::Document.new Jamf::Connection::XML_HEADER
254     ns = doc.add_element RSRC_OBJECT_KEY.to_s
255     ns.add_element('id').text = @id.to_s
256     ns.add_element('name').text = @name
257     ns.add_element('priority').text = @priority.to_s
258     ns.add_element('domain').text = @domain.to_s
259     ns.add_element('username').text = @username.to_s
260     ns.add_element('computer_ou').text = @computer_ou.to_s
261     ns.add_element('type').text = @type.to_s
262     if !@password.nil?
263         ns.add_element('password').text = @password.to_s
264     end
265 
266     ns << @type_settings.type_setting_xml
267 
268     return doc.to_s
269 end