lib/jss/api_object/policy.rb in ruby-jss-0.8.2 vs lib/jss/api_object/policy.rb in ruby-jss-0.9.0.b1

- old
+ new

@@ -76,11 +76,10 @@ include JSS::Scopable include JSS::Uploadable include JSS::SelfServable include JSS::Categorizable - ##################################### ### Class Methods ##################################### ##################################### @@ -205,12 +204,48 @@ network_state: :trigger_network_state_changed, enrollment: :trigger_enrollment_complete, custom: :trigger_other }.freeze + NO_USER_LOGGED_IN = [ + 'Do not restart', + 'Restart immediately', + 'Restart if a package or update requires it' + ].freeze + + USER_LOGGED_IN = [ + 'Do not restart', + 'Restart', + 'Restart if a package or update requires it', + 'Restart immediately' + ].freeze + SCOPE_TARGET_KEY = :computers + # Log Flushing + + LOG_FLUSH_RSRC = 'logflush'.freeze + + LOG_FLUSH_INTERVAL_INTEGERS = { + 0 => 'Zero', + 1 => 'One', + 2 => 'Two', + 3 => 'Three', + 6 => 'Six' + }.freeze + + LOG_FLUSH_INTERVAL_PERIODS = { + day: 'Day', + days: 'Day', + week: 'Week', + weeks: 'Week', + month: 'Month', + months: 'Month', + year: 'Year', + years: 'Year' + }.freeze + ###################### ### Attributes ###################### ##### General @@ -597,11 +632,10 @@ @disk_encryption = @init_data[:disk_encryption] @printers = @init_data[:printers] - ### Not in jss yet end # set non-nil defaults @enabled ||= false @@ -711,10 +745,140 @@ end @trigger_events[TRIGGER_EVENTS[type]] = new_val @need_to_update = true end + ### Set Server Side Activation + ### + ### @param activation[Time] Activation date and time + ### + ### @return [void] + ### + def server_side_activation=(activation) + raise JSS::InvalidDataError, 'Activation must be a Time' unless activation.is_a? Time + @server_side_limitations[:activation] = activation + @need_to_update = true + end + + ### Set Server Side Expiration + ### + ### @param expiration[Time] Expiration date and time + ### + ### @return [void] + ### + def server_side_expiration=(expiration) + raise JSS::InvalidDataError, 'Expiration must be a Time' unless expiration.is_a? Time + @server_side_limitations[:expiration] = expiration + @need_to_update = true + end + + ### Reboot Options + ### Set Reboot Message + ### + ### @param reboot_message[String] Text of Reboot Message + ### + ### @return [void] description of returned object + ### + def message=(reboot_message) + raise JSS::InvalidDataError, 'Reboot message must be a String' unless reboot_message.is_a? String + @reboot_options[:message] = reboot_message + @need_to_update = true + end + + ### Reboot Options + ### Set Startup Disk + ### Only Supports 'Specify Local Startup Disk' at the moment + ### + ### @param startup_disk_option[String] + ### + ### @return [void] + ### + def startup_disk=(startup_disk_option) + raise JSS::InvalidDataError, "#{startup_disk_option} is not a valid Startup Disk" unless startup_disk_option.is_a? String + @reboot_options[:startup_disk] = 'Specify Local Startup Disk' + self.specify_startup = startup_disk_option + @need_to_update = true + end + + ### Reboot Options + ### Specify Startup Volume + ### Only Supports "Specify Local Startup Disk" + ### + ### @param startup_volume[String] a Volume to reboot to + ### + ### @return [void] + ### + def specify_startup=(startup_volume) + raise JSS::InvalidDataError, "#{startup_volume} is not a valid Startup Disk" unless startup_volume.is_a? String + @reboot_options[:specify_startup] = startup_volume + @need_to_update = true + end + + ### Reboot Options + ### No User Logged In + ### + ### @param no_user_option[String] Any one of the Strings from NO_USER_LOGGED_IN + ### + ### @return [void] + ### + def no_user_logged_in=(no_user_option) + raise JSS::InvalidDataError, "no_user_logged_in options: #{NO_USER_LOGGED_IN.join(', ')}" unless NO_USER_LOGGED_IN.include? no_user_option + @reboot_options[:no_user_logged_in] = no_user_option + @need_to_update = true + end + + ### Reboot Options + ### User Logged In + ### + ### @param logged_in_option[String] Any one of the Strings from USER_LOGGED_IN + ### + ### @return [void] + ### + def user_logged_in=(logged_in_option) + raise JSS::InvalidDataError, "user_logged_in options: #{USER_LOGGED_IN.join(', ')}" unless USER_LOGGED_IN.include? logged_in_option + @reboot_options[:user_logged_in] = logged_in_option + @need_to_update = true + end + + ### Reboot Options + ### Do Not Reboot + ### Shortcut method to suppress Reboot Options + ### + ### @return [void] + ### + def do_not_reboot + @reboot_options[:user_logged_in] = 'Do not restart' + @reboot_options[:no_user_logged_in] = 'Do not restart' + @need_to_update = true + end + + ### Reboot Options + ### Minutes Until Reboot + ### + ### @param minutes[String] The number of minutes to delay prior to reboot + ### + ### @return [void] + ### + def minutes_until_reboot=(minutes) + raise JSS::InvalidDataError, 'Minutes until reboot must be an Integer' unless minutes.is_a? Integer + @reboot_options[:minutes_until_reboot] = minutes + @need_to_update = true + end + + ### Reboot Options + ### FileVault Authenticated Reboot + ### + ### @param fv_bool[Boolean] true or false + ### + ### @return [void] + ### + def file_vault_2_reboot=(fv_bool) + raise JSS::InvalidDataError, 'FileVault 2 Reboot must be a Boolean' unless fv_bool.jss_boolean? + @reboot_options[:file_vault_2_reboot] = fv_bool + @need_to_update = true + end + ###### Files & Processes ### @return [String] The unix shell command to run on ths client. ### def run_command @@ -1101,10 +1265,37 @@ output = JSS::Client.run_jamf('policy', "-id #{id}", show_output) return nil if output.include? 'No policies were found for the ID' $CHILD_STATUS.exitstatus.zero? ? true : false end + # Flush all policy logs for this policy older than + # some number of days, weeks, months or years. + # + # With no parameters, flushes all logs + # + # NOTE: Currently the API doesn't have a way to + # flush only failed policies. + # + # @param older_than[Integer] 0, 1, 2, 3, or 6 + # + # @param period[Symbol] :days, :weeks, :months, or :years + # + # @return [void] + # + def flush_logs(older_than: 0, period: :days) + raise JSS::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." \ + unless @in_jss + raise JSS::InvalidDataError, "older_than must be one of: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" \ + unless LOG_FLUSH_INTERVAL_INTEGERS.keys.include? older_than + raise JSS::InvalidDataError, "period must be one of: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" \ + unless LOG_FLUSH_INTERVAL_PERIODS.keys.include? period + + interval = "#{LOG_FLUSH_INTERVAL_INTEGERS[older_than]}+#{LOG_FLUSH_INTERVAL_PERIODS[period]}" + + JSS.api_connection.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{@id}/interval/#{interval}" + end + ###### Aliases alias enabled? enabled alias pkgs packages alias command_to_run run_command @@ -1128,10 +1319,23 @@ add_category_to_xml(doc) JSS.hash_to_rexml_array(@trigger_events).each { |t| general << t } + date_time_limitations = general.add_element 'date_time_limitations' + date_time_limitations.add_element('expiration_date_epoch').text = @server_side_limitations[:expiration].to_jss_epoch if @server_side_limitations[:expiration] + date_time_limitations.add_element('activation_date_epoch').text = @server_side_limitations[:activation].to_jss_epoch if @server_side_limitations[:activation] + obj << @scope.scope_xml + + reboot = obj.add_element 'reboot' + reboot.add_element('message').text = @reboot_options[:message] if @reboot_options[:message] + reboot.add_element('startup_disk').text = @reboot_options[:startup_disk] if @reboot_options[:startup_disk] + reboot.add_element('specify_startup').text = @reboot_options[:specify_startup] if @reboot_options[:specify_startup] + reboot.add_element('no_user_logged_in').text = @reboot_options[:no_user_logged_in] if @reboot_options[:no_user_logged_in] + reboot.add_element('user_logged_in').text = @reboot_options[:user_logged_in] if @reboot_options[:user_logged_in] + reboot.add_element('minutes_until_reboot').text = @reboot_options[:minutes_until_reboot] if @reboot_options[:minutes_until_reboot] + reboot.add_element('file_vault_2_reboot').text = @reboot_options[:file_vault_2_reboot] if @reboot_options[:file_vault_2_reboot] files_processes = obj.add_element 'files_processes' JSS.hash_to_rexml_array(@files_processes).each { |f| files_processes << f } pkg_conf = obj.add_element 'package_configuration'