lib/jamf/api/classic/api_objects/distribution_point.rb in ruby-jss-2.0.0b3 vs lib/jamf/api/classic/api_objects/distribution_point.rb in ruby-jss-2.0.0b5

- old
+ new

@@ -105,31 +105,22 @@ # @return [Jamf::DistributionPoint] # def self.master_distribution_point(refresh = false, default: nil, api: nil, cnx: Jamf.cnx) cnx = api if api - @master_distribution_point = nil if refresh - return @master_distribution_point if @master_distribution_point - all_ids(refresh, cnx: cnx).each do |dp_id| dp = fetch id: dp_id, cnx: cnx - if dp.master? - @master_distribution_point = dp - break - end + return dp if dp.master? end - # If we're here, the Cloud DP might be master, but there's no - # access to it in the API :/ - raise Jamf::NoSuchItemError, 'No Master FileShare Distribtion Point. Use the default: parameter if needed.' unless @master_distribution_point || default - - if @master_distribution_point - @master_distribution_point - elsif default == :random - @master_distribution_point = fetch(id: all_ids.sample, cnx: cnx) + case default + when :random + fetch id: all_ids.sample, cnx: cnx + when nil + raise Jamf::NoSuchItemError, 'No Master FileShare Distribtion Point. Use the default: parameter if needed.' else - @master_distribution_point = fetch(default, cnx: cnx) + fetch default, cnx: cnx end end # Get the DistributionPoint instance for the machine running # this code, based on its IP address. If none is defined for this IP address, @@ -265,42 +256,13 @@ attr_reader :ssh_username # @return [String] the ssh password as a SHA256 digest attr_reader :ssh_password_sha256 - # As well as the standard :id, :name, and :data, you can - # instantiate this class with :id => :master, in which case you'll - # get the Master Distribution Point as defined in the JSS. - # An error will be raised if one hasn't been defined. - # - # You can also do this more easily by calling JSS.master_distribution_point - # def initialize(**args) - # TODO: this looks redundant with super.... - args[:cnx] ||= args[:api] - args[:cnx] ||= Jamf.cnx - - @cnx = args[:cnx] - - @init_data = nil - - # looking for master? - if args[:id] == :master - - self.class.all_ids(cnx: @cnx).each do |id| - @init_data = @cnx.c_get("#{RSRC_BASE}/id/#{id}")[RSRC_OBJECT_KEY] - if @init_data[:is_master] - @id = @init_data[:id] - @name = @init_data[:name] - break - end # if data is master - @init_data = nil - end # each id - end # if args is master - - super(args) if @init_data.nil? - + super + @ip_address = @init_data[:ip_address] @local_path = @init_data[:local_path] @enable_load_balancing = @init_data[:enable_load_balancing] @failover_point = @init_data[:failover_point] @is_master = @init_data[:is_master] @@ -363,11 +325,11 @@ sha256 = case user when :rw then @read_write_password_sha256 when :ro then @read_only_password_sha256 when :http then @http_password_sha256 when :ssh then @ssh_password_sha256 - end # case + end # case return nil if sha256 == EMPTY_PW_256 sha256 == Digest::SHA2.new(256).update(pw).to_s end @@ -447,11 +409,11 @@ line = Regexp.last_match(1) line ||= 2 JSS.stdin line else pw - end + end pwok = check_pw(access, password) unless pwok msg = pwok.nil? ? "No #{access} password set in the JSS" : "Incorrect password for #{access} account" raise Jamf::InvalidDataError, msg @@ -464,10 +426,10 @@ @mount_url = "#{@connection_type.downcase}://#{username}:#{safe_pw}@#{@ip_address}/#{@share_name}" @mnt_cmd = case @connection_type.downcase when 'smb' then '/sbin/mount_smbfs' when 'afp' then '/sbin/mount_afp' else raise "Can't mount distribution point #{@name}: no known connection type." - end + end @mountpoint.mkpath mount_out = `#{@mnt_cmd} -o '#{MOUNT_OPTIONS}' '#{@mount_url}' '#{@mountpoint}' 2>&1` if ($CHILD_STATUS.exitstatus == 0) && @mountpoint.mountpoint?