Class: JSS::PatchPolicy

Inherits:
APIObject show all
Includes:
Creatable, Scopable, SelfServable, Updatable
Defined in:
lib/jss/api_object/patch_policy.rb,
lib/jss.rb

Overview

A Patch Policy in the JSS

When making new Patch Polices :patch_title and :target_version must be provided as well as :name.

:patch_title is the name or id of a currently active patch title

:target_version is the string identfier of an available version of the title. The target version MUST have a package assigned to it.

See PatchTitle and JSS::PatchSource.available_titles for methods to acquire such info.

See Also:

Constant Summary collapse

RSRC_BASE =
'patchpolicies'.freeze
RSRC_LIST_KEY =
:patch_policies
RSRC_OBJECT_KEY =
:patch_policy
RSRC_BY_PATCH_TITLE =
'patchpolicies/softwaretitleconfig/id/'.freeze
RSRC_BY_PATCH_TITLE_LIST_KEY =

TODO: complain to jamf about this - should be the same as RSRC_LIST_KEY

:"patch policies"
SCOPE_TARGET_KEY =
:computers
AUTO_INSTALL_GRACE_PERIOD_MESSAGE =
'$APP_NAMES will quit in $DELAY_MINUTES minutes so that $SOFTWARE_TITLE can be updated. Save anything you are working on and quit the app(s).'.freeze
DFT_ENABLED =
false
DFT_DISTRIBUTION =

the default dist method - not in ssvc

'prompt'.freeze
NO_DEADLINE =

the value of #deadline when there is no deadline

:none
DFT_DEADLINE =
7
DFT_GRACE_PERIOD =

The valud of #grace_period when not defined

15
DFT_GRACE_PERIOD_SUBJECT =
'Important'.freeze
DFT_GRACE_PERIOD_MESSAGE =
'$APP_NAMES will quit in $DELAY_MINUTES minutes so that $SOFTWARE_TITLE can be updated. Save anything you are working on and quit the app(s).'.freeze
USE_XML_WORKAROUND =
{
  patch_policy: {
    general: {
      id: -1,
      name: JSS::BLANK,
      enabled: nil,
      target_version: JSS::BLANK,
      release_date: 0,
      incremental_update: nil,
      reboot: nil,
      minimum_os: JSS::BLANK,
      kill_apps: [
        {
          kill_app_name: JSS::BLANK,
          kill_app_bundle_id: JSS::BLANK
        }
      ],
      distribution_method: JSS::BLANK,
      allow_downgrade: nil,
      patch_unknown: nil
    },
    scope: {
      all_computers: nil,
      computers: [
        {
          id: -1,
          name: JSS::BLANK,
          udid: JSS::BLANK
        }
      ],
      computer_groups: [
        {
          id: -1,
          name: JSS::BLANK
        }
      ],
      users: [
        {
          id: -1,
          username: JSS::BLANK
        }
      ],
      user_groups: [
        {
          id: -1,
          name: JSS::BLANK
        }
      ],
      buildings: [
        {
          id: -1,
          name: JSS::BLANK
        }
      ],
      departments: [
        {
          id: -1,
          name: JSS::BLANK
        }
      ],
      limitations: {
        network_segments: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        ibeacons: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ]
      },
      exclusions: {
        computers: [
          {
            id: -1,
            name: JSS::BLANK,
            udid: JSS::BLANK
          }
        ],
        computer_groups: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        users: [
          {
            id: -1,
            username: JSS::BLANK
          }
        ],
        user_groups: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        buildings: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        departments: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        network_segments: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ],
        ibeacons: [
          {
            id: -1,
            name: JSS::BLANK
          }
        ]
      }
    },
    user_interaction: {
      install_button_text: JSS::BLANK,
      self_service_description: JSS::BLANK,
      self_service_icon: {
        id: -1,
        filename: JSS::BLANK,
        uri: JSS::BLANK
      },
      notifications: {
        notification_enabled: nil,
        notification_type: JSS::BLANK,
        notification_subject: JSS::BLANK,
        notification_message: JSS::BLANK,
        reminders: {
          notification_reminders_enabled: nil,
          notification_reminder_frequency: 1
        }
      },
      deadlines: {
        deadline_enabled: nil,
        deadline_period: 7
      },
      grace_period: {
        grace_period_duration: 15,
        notification_center_subject: 'Important',
        message: AUTO_INSTALL_GRACE_PERIOD_MESSAGE
      }
    },
    software_title_configuration_id: 2
  }
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ PatchPolicy

When making new Patch Polices :patch_title is required and is a JSS::PatchTitle or the name or id of one

If target_version: is provided, it must exist in the PatchTitle, and must have a package assigned to it.



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/jss/api_object/patch_policy.rb', line 348

def initialize(data = {})
  super

  # creation...
  unless in_jss
    @init_data[:general] ||= {}
    @init_data[:software_title_configuration_id] = validate_patch_title @init_data[:patch_title]

    # were we given target_version in the make params?
    validate_target_version @init_data[:target_version] if @init_data[:target_version]
    @init_data[:general][:target_version] = @init_data[:target_version]

    # other defaults
    @init_data[:general][:enabled] = false
    @init_data[:general][:allow_downgrade] = false
    @init_data[:general][:patch_unknown] = false
    @init_data[:general][:distribution_method] = DFT_DISTRIBUTION
  end

  @patch_title_id = @init_data[:software_title_configuration_id]

  gen = @init_data[:general]
  @enabled = gen[:enabled]
  @target_version = gen[:target_version]
  @allow_downgrade = gen[:allow_downgrade]
  @patch_unknown = gen[:patch_unknown]

  @init_data[:user_interaction] ||= {}

  deadlines = @init_data[:user_interaction][:deadlines]
  deadlines ||= {}
  deadlines[:deadline_period] = DFT_DEADLINE if deadlines[:deadline_period].to_s.empty?
  @deadline = deadlines[:deadline_enabled] ? deadlines[:deadline_period] : NO_DEADLINE

  grace = @init_data[:user_interaction][:grace_period]
  grace ||= {}

  @grace_period = grace[:grace_period_duration]
  @grace_period = DFT_GRACE_PERIOD if @grace_period.to_s.empty?

  @grace_period_subject = grace[:notification_center_subject]
  @grace_period_subject = DFT_GRACE_PERIOD_SUBJECT if @grace_period_subject.to_s.empty?

  @grace_period_message = grace[:message]
  @grace_period_message = DFT_GRACE_PERIOD_MESSAGE if @grace_period_message.to_s.empty?


  # read-only values, they come from the version.
  @release_date = JSS.epoch_to_time gen[:release_date]
  @incremental_update = gen[:incremental_update]
  @reboot = gen[:reboot]
  @minimum_os = gen[:minimum_os]
  @kill_apps = gen[:kill_apps]
end

Instance Attribute Details

#allow_downgradeBoolean Also known as: allow_downgrade?, downgradable?

Can this title be downgraded to this version?



298
299
300
# File 'lib/jss/api_object/patch_policy.rb', line 298

def allow_downgrade
  @allow_downgrade
end

#deadlineInteger, Symnol

How many days is the install deadline?



313
314
315
# File 'lib/jss/api_object/patch_policy.rb', line 313

def deadline
  @deadline
end

#enabledBoolean (readonly) Also known as: enabled?



262
263
264
# File 'lib/jss/api_object/patch_policy.rb', line 262

def enabled
  @enabled
end

#grace_periodInteger Also known as: grace_period_duration



319
320
321
# File 'lib/jss/api_object/patch_policy.rb', line 319

def grace_period
  @grace_period
end

#grace_period_messageString



333
334
335
# File 'lib/jss/api_object/patch_policy.rb', line 333

def grace_period_message
  @grace_period_message
end

#grace_period_subjectString Also known as: grace_period_notification_center_subject



326
327
328
# File 'lib/jss/api_object/patch_policy.rb', line 326

def grace_period_subject
  @grace_period_subject
end

#iconJSS::Icon? Also known as: self_service_icon Originally defined in module SelfServable

#in_self_serviceBoolean (readonly) Also known as: in_self_service? Originally defined in module SelfServable

#incremental_updateBoolean (readonly) Also known as: incremental_update?



279
280
281
# File 'lib/jss/api_object/patch_policy.rb', line 279

def incremental_update
  @incremental_update
end

#kill_appsArray<Hash> (readonly)



293
294
295
# File 'lib/jss/api_object/patch_policy.rb', line 293

def kill_apps
  @kill_apps
end

#minimum_osString (readonly)



289
290
291
# File 'lib/jss/api_object/patch_policy.rb', line 289

def minimum_os
  @minimum_os
end

#need_to_updateBoolean (readonly) Originally defined in module Updatable

#patch_title_idInteger (readonly) Also known as: software_title_id, software_title_configuration_id



338
339
340
# File 'lib/jss/api_object/patch_policy.rb', line 338

def patch_title_id
  @patch_title_id
end

#patch_unknownBoolean Also known as: patch_unknown?

Can this policy run when we don’t know the prev. version?



305
306
307
# File 'lib/jss/api_object/patch_policy.rb', line 305

def patch_unknown
  @patch_unknown
end

#rebootBoolean (readonly) Also known as: reboot_required, reboot?, reboot_required?



283
284
285
# File 'lib/jss/api_object/patch_policy.rb', line 283

def reboot
  @reboot
end

#release_dateTime (readonly)



276
277
278
# File 'lib/jss/api_object/patch_policy.rb', line 276

def release_date
  @release_date
end

#scopeObject Originally defined in module Scopable

Attribtues

#self_service_categoriesArray<Hash> (readonly) Originally defined in module SelfServable

Each Hash has these keys about the category

  • :id => [Integer] the JSS id of the category

  • :name => [String] the name of the category

Most objects also include one or both of these keys:

  • :display_in => [Boolean] should the item be displayed in this category in SSvc? (not MobDevConfProfiles)

  • :feature_in => [Boolean] should the item be featured in this category in SSVC? (macOS targets only)

#self_service_descriptionString Originally defined in module SelfServable

#self_service_display_nameString Also known as: self_service_dislay_name Originally defined in module SelfServable

#self_service_feature_on_main_pageBoolean Originally defined in module SelfServable

Only applicable to macOS targets

#self_service_force_users_to_view_descriptionBoolean Originally defined in module SelfServable

#self_service_install_button_textString Originally defined in module SelfServable

defaults to ‘Install’

#self_service_notification_messageString Originally defined in module SelfServable

#self_service_notification_subjectString Originally defined in module SelfServable

object name.

#self_service_notification_typeSymbol Originally defined in module SelfServable

#self_service_notifications_enabledBoolean Also known as: self_service_notifications_enabled? Originally defined in module SelfServable

#self_service_reinstall_button_textString Originally defined in module SelfServable

defaults to ‘Reinstall’

#self_service_reminder_frequencyInteger Originally defined in module SelfServable

#self_service_reminders_enabledBoolean Also known as: self_service_reminders_enabled? Originally defined in module SelfServable

#self_service_removal_passwordString (readonly) Originally defined in module SelfServable

#self_service_user_removableSymbol Originally defined in module SelfServable

#target_versionString Also known as: version

When setting, the version must exist in the policy’s PatchTitle, and have a package assigned to it.



272
273
274
# File 'lib/jss/api_object/patch_policy.rb', line 272

def target_version
  @target_version
end

Class Method Details

.all_for_title(title, api: JSS.api) ⇒ Array<Hash>

Fetch name and id of all PatchPolicies tied to a given PatchTitle



252
253
254
255
256
# File 'lib/jss/api_object/patch_policy.rb', line 252

def self.all_for_title(title, api: JSS.api)
  title_id = JSS::PatchTitle.valid_id title
  raise JSS::NoSuchItemError, "No PatchTitle matching '#{title}'" unless title_id
  api.get_rsrc("#{RSRC_BY_PATCH_TITLE}#{title_id}")[RSRC_BY_PATCH_TITLE_LIST_KEY]
end

Instance Method Details

#add_self_service_category(new_cat, display_in: true, feature_in: false) ⇒ void Also known as: set_self_service_category, change_self_service_category Originally defined in module SelfServable

This method returns an undefined value.

Add or change one of the categories for this item in self service

#add_to_self_servicevoid Originally defined in module SelfServable

This method returns an undefined value.

Add this object to self service if not already there.

#clone(new_name, api: nil) ⇒ APIObject Originally defined in module Creatable

make a clone of this API object, with a new name. The class must be creatable

#createInteger

Create a new PatchPolicy in the JSS



508
509
510
511
512
513
514
515
516
517
518
# File 'lib/jss/api_object/patch_policy.rb', line 508

def create
  validate_for_saving
  # TODO: prepare for more cases where the POST rsrc is
  # different from the PUT/GET/DELETE.
  orig_rsrc = @rest_rsrc
  @rest_rsrc = "#{RSRC_BY_PATCH_TITLE}#{CGI.escape patch_title_id.to_s}"
  super
  @rest_rsrc = orig_rsrc
  refetch_version_info
  id
end

#disablevoid

This method returns an undefined value.

disable this policy



444
445
446
447
448
# File 'lib/jss/api_object/patch_policy.rb', line 444

def disable
  return unless enabled
  @enabled = false
  @need_to_update = true
end

#enablevoid

This method returns an undefined value.

enable this policy



434
435
436
437
438
# File 'lib/jss/api_object/patch_policy.rb', line 434

def enable
  return if enabled
  @enabled = true
  @need_to_update = true
end

#name=(newname) ⇒ void Originally defined in module Updatable

This method returns an undefined value.

Change the name of this item Remember to #update to push changes to the server.

#parse_scopevoid Originally defined in module Scopable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Call this during initialization of objects that have a scope and the scope instance will be created from @init_data

#patch_title(refresh = false) ⇒ JSS::PatchTitle?

The JSS::PatchTitle to for this PatchPolicy



409
410
411
412
# File 'lib/jss/api_object/patch_policy.rb', line 409

def patch_title(refresh = false)
  @patch_title = nil if refresh
  @patch_title ||= JSS::PatchTitle.fetch id: patch_title_id
end

#patch_title_nameString



416
417
418
419
# File 'lib/jss/api_object/patch_policy.rb', line 416

def patch_title_name
  return @patch_title.name if @patch_title
  JSS::PatchTitle.map_all_ids_to(:name)[software_title_configuration_id]
end

#remove_from_self_servicevoid Originally defined in module SelfServable

This method returns an undefined value.

Remove this object from self service if it’s there.

#remove_self_service_category(cat) ⇒ void Originally defined in module SelfServable

This method returns an undefined value.

Remove a category from those for this item in SSvc

#self_service_execute_urlString Originally defined in module SelfServable

#self_service_payloadSymbol Originally defined in module SelfServable

What does this object deploy to the device via self service?

#self_service_targetsArray<Symbol> Originally defined in module SelfServable

What devices types can get this thing in Self Service

#self_service_view_urlString Originally defined in module SelfServable

#should_updatevoid Originally defined in module Scopable

This method returns an undefined value.

When the scope changes, it calls this to tell us that an update is needed.

#updateInteger

Update an existing PatchPolicy with changes from ruby



524
525
526
527
528
529
530
# File 'lib/jss/api_object/patch_policy.rb', line 524

def update
  validate_for_saving
  super
  refetch_version_info if @refetch_for_new_version
  @refetch_for_new_version = false
  id
end

#upload(type, local_file) ⇒ String Originally defined in module Uploadable

Upload a file to the JSS via the REST Resource of the object to which this module is mixed in.

#user_removable?Boolean? Originally defined in module SelfServable

Can this thing be removed by the user?