Class: JSS::Policy

Inherits:
APIObject show all
Includes:
Categorizable, Creatable, Scopable, SelfServable, Sitable, Updatable, Uploadable
Defined in:
lib/jss/api_object/policy.rb,
lib/jss.rb

Overview

A class implementing a JSS Policy.

Like many API objects, the data comes from the API in sections, and the items in the :general section are mapped to direct attributes of this Class.

Policy instances are partially read-only:

  • Due to limitations in the API implementation of policies, as well as the complexity of policy objects, only these attributes can be set and updated via the Policy class:

    • name

    • frequency

    • target_drive

    • offline

    • enabled

    • category

    • triggers

    • client maintenance tasks

    • files and processes

    • reboot options

All other values and sections must be edited via the Web App.

Policies may be deleted via this class

Constant Summary collapse

RSRC_BASE =

The base for REST resources of this class

'policies'.freeze
RSRC_LIST_KEY =

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

:policies
RSRC_OBJECT_KEY =

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

:policy
SUBSETS =

subsets available for fetching TODO: FilesProcesses and Maintenance don't seem to work

%i[
  general
  scope
  selfservice
  self_service
  packages
  scripts
  printers
  dockitems
  dock_items
  reboot
  userinteraction
  user_interaction
  disk_encryption
  diskencryption
  accountmaintenance
  account_maintenance
].freeze
UPLOAD_TYPES =

policies can take uploaded icons

{ icon: :policies }.freeze
SELF_SERVICE_TARGET =

policies are available in macOS self Serviec

:macos
SELF_SERVICE_PAYLOAD =

policies via self services are still polcies

:policy
SECTIONS =
%i[
  general
  maintenance
  account_maintenance
  scripts
  self_service
  package_configuration
  scope
  user_interaction
  reboot
  files_processes
  dock_items
  disk_encryption
  printers
].freeze
FREQUENCIES =
{
  ongoing: 'Ongoing',
  once_per_computer: 'Once per computer',
  once_per_user: 'Once per user',
  once_per_user_per_computer: 'Once per user per computer',
  daily: 'Once every day',
  weekly: 'Once every week',
  monthly: 'Once every month'
}.freeze
RETRY_EVENTS =
{
  none: 'none',
  checkin: 'check-in',
  trigger: 'trigger'
}.freeze
RESTART_WHEN =
{
  if_pkg_requires: 'Restart if a package or update requires it',
  now: 'Restart immediately',
  delayed: 'Restart',
  dont: 'Do not restart'
}.freeze
RESTART_DISKS =
{
  current: 'Current Startup Disk',
  selected: 'Currently Selected Startup Disk (No Bless)',
  netboot: 'NetBoot',
  os_installer: 'inPlaceOSUpgradeDirectory'
}.freeze
ACCOUNT_ACTIONS =

Note: any other value in :specify_startup is a path to some other drive to boot from, e.g. /Volumes/Foo

{
  create: 'Create',
  change_pw: 'Reset',
  delete: 'Delete',
  disable_fv2: 'DisableFileVault'
}.freeze
MGMT_ACCOUNT_ACTIONS =
{
  no_change: 'doNotChange',
  change_pw: 'specified',
  generate_pw: 'random',
  enable_fv2: 'fileVaultEnable',
  disable_fv2: 'fileVaultDisable',
  reset_random: 'resetRandom',
  reset_pw: 'reset'
}.freeze
PACKAGE_ACTIONS =
{
  install: 'Install',
  remove: 'Uninstall',
  cache: 'Cache',
  install_cache: 'Install Cached'
}.freeze
SCRIPT_PRIORITIES =
{
  pre: 'Before',
  before: 'Before',
  post: 'After',
  after: 'After'
}.freeze
DISK_ENCRYPTION_ACTIONS =
{
  apply: "apply",
  remediate: "remediate",
  none: "none"
}
PRINTER_ACTIONS =
{
  map: 'install',
  unmap: 'uninstall'
}.freeze
DOCK_ITEM_ACTIONS =
{
  add_start: 'Add To Beginning',
  add_end: 'Add To End', remove: 'Remove'
}.freeze
NETWORK_REQUIREMENTS =
{
  any: 'Any',
  ethernet: 'EtherNet'
}.freeze
TRIGGER_TYPES =
{
  event: 'EVENT',
  user: 'USER_INITIATED'
}.freeze
TRIGGER_EVENTS =
{
  startup: :trigger_startup,
  login: :trigger_login,
  logout: :trigger_logout,
  checkin: :trigger_checkin,
  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_FLUSH_RSRC =

Log Flushing

'logflush'.freeze
LOG_FLUSH_INTERVAL_INTEGERS =
{
  0 => 'Zero',
  1 => 'One',
  2 => 'Two',
  3 => 'Three',
  6 => 'Six'
}.freeze
LOG_FLUSH_INTERVAL_PERIODS =
{
  day: 'Days',
  days: 'Days',
  week: 'Weeks',
  weeks: 'Weeks',
  month: 'Months',
  months: 'Months',
  year: 'Years',
  years: 'Years'
}.freeze
OBJECT_HISTORY_OBJECT_TYPE =

the object type for this object in the object history table. See APIObject#add_object_history_entry

3
SITE_SUBSET =

Where is the Site data in the API JSON?

:general
CATEGORY_SUBSET =

Where is the Category in the API JSON?

:general
CATEGORY_DATA_TYPE =

How is the category stored in the API data?

Hash
SCRIPT_PARAMETERS_AVAILABLE =

All valid script parameters

%i[parameter4 parameter5 parameter6 parameter7 parameter8 parameter9 parameter10 parameter11].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Policy

Returns a new instance of Policy.


697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
# File 'lib/jss/api_object/policy.rb', line 697

def initialize(args = {})
  super

  if @in_jss
    gen = @init_data[:general]
    @target_drive = gen[:target_drive]
    @offline = gen[:offline]
    @enabled = gen[:enabled]
    @site = JSS::APIObject.get_name(gen[:site][:name])
    @override_default_settings = gen[:override_default_settings]
    @trigger = gen[:trigger]
    @trigger_events = {
      trigger_startup: gen[:trigger_startup],
      trigger_login: gen[:trigger_login],
      trigger_logout: gen[:trigger_logout],
      trigger_checkin: gen[:trigger_checkin],
      trigger_network_state_changed: gen[:trigger_network_state_changed],
      trigger_enrollment_complete: gen[:trigger_enrollment_complete],
      trigger_other: gen[:trigger_other]
    }
    @frequency = gen[:frequency]
    @retry_event = gen[:retry_event]
    @retry_attempts = gen[:retry_attempts]
    @notify_failed_retries = gen[:notify_on_each_failed_retry]

    dtl = gen[:date_time_limitations]

    @server_side_limitations = {
      activation: JSS.epoch_to_time(dtl[:activation_date_epoch]),
      expiration: JSS.epoch_to_time(dtl[:expiration_date_epoch])
    }

    @client_side_limitations = {
      no_execute_on: dtl[:no_execute_on], # NOTE- there's a bug in the JSON output, it's been reported to JAMF.
      no_execute_start: dtl[:no_execute_start], # String like "1:01 AM"
      no_execute_end: dtl[:no_execute_end], # String like "2:02 PM"
      network_requirements: gen[:network_requirements]
    }

    maint = @init_data[:maintenance]
    @verify_startup_disk = maint[:verify]
    @permissions_repair = maint[:permissions]
    @recon = maint[:recon]
    @fix_byhost = maint[:byhost]
    @reset_name = maint[:reset_name]
    @flush_system_cache = maint[:system_cache]
    @install_cached_pkgs = maint[:install_all_cached_packages]
    @flush_user_cache = maint[:user_cache]

    amaint = @init_data[:account_maintenance]
    @directory_bindings = amaint[:directory_bindings]
    @open_firmware_efi_password = amaint[:open_firmware_efi_password]
    @management_account = amaint[:management_account]
    @accounts = amaint[:accounts]

    @packages = @init_data[:package_configuration][:packages] ? @init_data[:package_configuration][:packages] : []

    @scripts = @init_data[:scripts]

    uint = @init_data[:user_interaction]
    @user_may_defer = uint[:allow_users_to_defer]
    @user_may_defer_until = JSS.parse_datetime uint[:allow_deferral_until_utc]
    @user_message_start =  uint[:message_start]
    @user_message_finish = uint[:message_finish]

    @reboot_options = @init_data[:reboot]

    @files_processes = @init_data[:files_processes]

    @dock_items = @init_data[:dock_items]

    @disk_encryption = @init_data[:disk_encryption]

    @printers = @init_data[:printers]
    @printers.shift

    # Not in jss yet
  end

  # set non-nil defaults
  @enabled ||= false
  @frequency ||= 'Once per computer'
  @target_drive ||= '/'
  @offline ||= false
  @override_default_settings ||= {}
  @scripts ||= []
  @server_side_limitations ||= {}
  @client_side_limitiations ||= {}
  @trigger_events ||= {}
  @directory_bindings ||= []
  @open_firmware_efi_password ||= {}
  @management_account ||= {}
  @accounts  ||= []
  @packages  ||= []
  @scripts ||= []
  @self_service ||= {}
  @dock_items ||= []
  @disk_encryption ||= {}
  @printers ||= []
  @files_processes ||= {}
  unless @reboot_options
    @reboot_options = {}
    @reboot_options[:user_logged_in] = 'Do not restart'
    @reboot_options[:no_user_logged_in] = 'Do not restart'
  end

  @scope ||= JSS::Scopable::Scope.new(:computers, all_computers: false)
end

Instance Attribute Details

#accountsArray<Hash> (readonly)

Local accts acted-upon by this policy

Keys are:

  • :action => “Create”,

  • :hint => “foo bar”,

  • :picture => “/path/to/pic.tif”,

  • :admin => true,

  • :home => “/Users/chrisltest”,

  • :realname => “ChrisTest Lasell”,

  • :filevault_enabled => true,

  • :username => “chrisltest”,

  • :password_md5 => “3858f62230ac3c915f300c664312c63f”,

  • :password => “foobar”,

  • :password_sha256=> “c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2”

TODO: make individial getters/setters as for @files_processes

Returns:


582
583
584
# File 'lib/jss/api_object/policy.rb', line 582

def accounts
  @accounts
end

#client_side_limitationsHash (readonly)

The client-side limitations of this policy.

The keys are:

  • :no_execute_on - An array of short day names as strings, e.g. [“Sun”, “Mon”, “Tue”]

  • :no_execute_start - Time

  • :no_execute_end - Time

  • :network_connection - String

The data for the first three comes from the API in the date_time_limitations hash of the general section. The fourth comes from the network_requirements of the general section of the API, but the UI shows them in the Client Side Limitations area.

This attribute is just for convience and consistency, and just refers to the data in their API locations

Returns:


471
472
473
# File 'lib/jss/api_object/policy.rb', line 471

def client_side_limitations
  @client_side_limitations
end

#directory_bindingsArray<Hash> (readonly)

The directory bindings applied

each hash is like: {:name => “LDAP”, :id => 4} TODO: handle as for packages & scripts

Returns:


545
546
547
# File 'lib/jss/api_object/policy.rb', line 545

def directory_bindings
  @directory_bindings
end

#disk_encryptionHash (readonly)

Disk encryption options for this policy

The hash looks like {:disk_encryption_configuration_id => 3, :action => “apply”}

Returns:


682
683
684
# File 'lib/jss/api_object/policy.rb', line 682

def disk_encryption
  @disk_encryption
end

#dock_itemsArray<Hash> (readonly)

The dock items handled by this policy

each item hash looks like: {:name => “Mail”, :id => 14, :action => “Add To Beginning”}

Returns:


675
676
677
# File 'lib/jss/api_object/policy.rb', line 675

def dock_items
  @dock_items
end

#enabledBoolean Also known as: enabled?

Returns is the policy enabled?.

Returns:

  • (Boolean)

    is the policy enabled?


389
390
391
# File 'lib/jss/api_object/policy.rb', line 389

def enabled
  @enabled
end

#fix_byhostBoolean

Should this policy fix the ByHost prefs?

Returns:

  • (Boolean)

    client maintenance task


521
522
523
# File 'lib/jss/api_object/policy.rb', line 521

def fix_byhost
  @fix_byhost
end

#flush_system_cacheBoolean

Should this policy flush the system cache?

Returns:

  • (Boolean)

    client maintenance task


529
530
531
# File 'lib/jss/api_object/policy.rb', line 529

def flush_system_cache
  @flush_system_cache
end

#flush_user_cacheBoolean

Should this policy flush the user cache?

Returns:

  • (Boolean)

    client maintenance task


537
538
539
# File 'lib/jss/api_object/policy.rb', line 537

def flush_user_cache
  @flush_user_cache
end

#frequencyString

Returns how often to run the policy on each computer.

Returns:

  • (String)

    how often to run the policy on each computer


380
381
382
# File 'lib/jss/api_object/policy.rb', line 380

def frequency
  @frequency
end

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

Returns The icon used in self-service.

Returns:

  • (JSS::Icon, nil)

    The icon used in self-service

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

Returns Is this thing available in Self Service?.

Returns:

  • (Boolean)

    Is this thing available in Self Service?

#install_cached_pkgsBoolean

Should this policy install any cached JSS packages?

Returns:

  • (Boolean)

    client maintenance task


533
534
535
# File 'lib/jss/api_object/policy.rb', line 533

def install_cached_pkgs
  @install_cached_pkgs
end

#management_accountHash (readonly)

The management accout changes applied by the policy

The keys are:

  • :action see MGMT_ACCOUNT_ACTIONS

  • :managed_password

  • :managed_password_md5

  • :managed_password_sha256

  • :managed_password_length # for random generating pws

TODO: make individial getters/setters as for @files_processes

Returns:


562
563
564
# File 'lib/jss/api_object/policy.rb', line 562

def 
  @management_account
end

#need_to_updateBoolean (readonly) Originally defined in module Updatable

Returns do we have unsaved changes?.

Returns:

  • (Boolean)

    do we have unsaved changes?

#offlineBoolean

Returns should be policy be available offline.

Returns:

  • (Boolean)

    should be policy be available offline


386
387
388
# File 'lib/jss/api_object/policy.rb', line 386

def offline
  @offline
end

#open_firmware_efi_passwordHash (readonly)

Returns the open firmware mode and password.

Returns:

  • (Hash)

    the open firmware mode and password


548
549
550
# File 'lib/jss/api_object/policy.rb', line 548

def open_firmware_efi_password
  @open_firmware_efi_password
end

#override_default_settingsHash (readonly)

Overrides for various defaults

NOTE: There's an API bug in both XML and JSON with the

:distribution_point and :target_drive values.
First off, it's not clear what the :target_drive value here
is overriding, since there's a :target_drive value in the
main General hash.
Second off - when you set a non-default dist.point in the
packages section of the UI, that value shows up in both
this :target_drive and the general one, but the :distribution_point
value here stays empty.

The hash looks like: :distribution_point => “”, :force_afp_smb => false, :netboot_server => “current”, :target_drive => “default”, :sus => “default”

Returns:


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

def override_default_settings
  @override_default_settings
end

#packagesArray<Hash> (readonly) Also known as: pkgs

The pkgs handled by this policy

Hash keys are:

  • :action => “Install”

  • :update_autorun => false,

  • :feu => false,

  • :name => “rbgem-json-1.6.5-4.pkg”,

  • :id => 1073

Returns:


595
596
597
# File 'lib/jss/api_object/policy.rb', line 595

def packages
  @packages
end

#permissions_repairBoolean

Should this policy run a permission repair?

Returns:

  • (Boolean)

    client maintenance task


512
513
514
# File 'lib/jss/api_object/policy.rb', line 512

def permissions_repair
  @permissions_repair
end

#printersArray<Hash> (readonly)

The printers handled by this policy

Each Hash looks like: {:make_default => false, :name => “torlan”, :id => 3, :action => “install”}

Returns:


689
690
691
# File 'lib/jss/api_object/policy.rb', line 689

def printers
  @printers
end

#reboot_optionsHash (readonly)

Reboot options for the policy

The hash keys are:

  • :user_logged_in => “Do not restart”,

  • :minutes_until_reboot => 5,

  • :message=> “This computer will restart in 5 minutes. yaddayadda.”,

  • :startup_disk => “Current Startup Disk”,

  • :specify_startup => “”,

  • :no_user_logged_in => “Do not restart”

  • :file_vault_2_reboot => false

Returns:


653
654
655
# File 'lib/jss/api_object/policy.rb', line 653

def reboot_options
  @reboot_options
end

#reconBoolean Also known as: update_inventory

Should this policy run a recon?

Returns:

  • (Boolean)

    client maintenance task


516
517
518
# File 'lib/jss/api_object/policy.rb', line 516

def recon
  @recon
end

#reset_nameBoolean

Should this policy reset the local hostname?

Returns:

  • (Boolean)

    client maintenance task


525
526
527
# File 'lib/jss/api_object/policy.rb', line 525

def reset_name
  @reset_name
end

#scopeObject Originally defined in module Scopable

Attribtues

#scriptsArray<Hash> (readonly)

The scripts run by this policy

Hash keys are:

  • :name => “chromegetter.sh”,

  • :parameter4 => “”,

  • :parameter5 => “”,

  • :parameter6 => “”,

  • :parameter7 => “”,

  • :parameter8 => “”,

  • :parameter9 => “”,

  • :parameter10 => “”,

  • :parameter11 => “”,

  • :id => 1428,

  • :priority => “After”

Returns:


615
616
617
# File 'lib/jss/api_object/policy.rb', line 615

def scripts
  @scripts
end

#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)

Returns:

  • (Array<Hash>)

    The categories in which this item should appear in SSvc

#self_service_descriptionString Originally defined in module SelfServable

Returns The verbage that appears in SelfSvc for this item.

Returns:

  • (String)

    The verbage that appears in SelfSvc for this item

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

Returns The name to display in macOS Self Service.

Returns:

  • (String)

    The name to display in macOS Self Service.

#self_service_feature_on_main_pageBoolean Originally defined in module SelfServable

Only applicable to macOS targets

Returns:

  • (Boolean)

    Should this item feature on the main page of SSvc?

#self_service_force_users_to_view_descriptionBoolean Originally defined in module SelfServable

Returns Should an extra window appear before the user can install the item? (OSX SSvc only).

Returns:

  • (Boolean)

    Should an extra window appear before the user can install the item? (OSX SSvc only)

#self_service_install_button_textString Originally defined in module SelfServable

defaults to 'Install'

Returns:

  • (String)

    The text label on the install button in SSvc (OSX SSvc only)

#self_service_notification_messageString Originally defined in module SelfServable

Returns The message text of the notification.

Returns:

  • (String)

    The message text of the notification

#self_service_notification_subjectString Originally defined in module SelfServable

object name.

Returns:

  • (String)

    The subject text of the notification. Defaults to the

#self_service_notification_typeSymbol Originally defined in module SelfServable

Returns How should notifications be sent either :ssvc_only or :ssvc_and_nctr.

Returns:

  • (Symbol)

    How should notifications be sent either :ssvc_only or :ssvc_and_nctr

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

Returns Should jamf send notifications to self service?.

Returns:

  • (Boolean)

    Should jamf send notifications to self service?

#self_service_reinstall_button_textString Originally defined in module SelfServable

defaults to 'Reinstall'

Returns:

  • (String)

    The text label on the reinstall button in SSvc (OSX SSvc only)

#self_service_reminder_frequencyInteger Originally defined in module SelfServable

Returns How often (in days) should reminders be given.

Returns:

  • (Integer)

    How often (in days) should reminders be given

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

Returns Should self service give reminders by displaying the notification repeatedly?.

Returns:

  • (Boolean)

    Should self service give reminders by displaying the notification repeatedly?

#self_service_removal_passwordString (readonly) Originally defined in module SelfServable

Returns The password needed for removal, in plain text.

Returns:

  • (String)

    The password needed for removal, in plain text.

#self_service_user_removableSymbol Originally defined in module SelfServable

Returns one of the keys in PROFILE_REMOVAL_BY_USER.

Returns:

  • (Symbol)

    one of the keys in PROFILE_REMOVAL_BY_USER

#server_side_limitationsHash (readonly)

The server-side limitations of this policy.

The keys are :activation and :expiration, both are Times.

the data comes from the API in the date_time_limitations hash of the general section, but the UI shows them in the Server Side Limitations area. This attribute is just for convience and consistency, and just refers to the data in their API locations

Returns:


453
454
455
# File 'lib/jss/api_object/policy.rb', line 453

def server_side_limitations
  @server_side_limitations
end

#siteString (readonly)

Returns a string with the site name.

Returns:

  • (String)

    a string with the site name


393
394
395
# File 'lib/jss/api_object/policy.rb', line 393

def site
  @site
end

#target_driveString

Returns which drive should the policy target.

Returns:

  • (String)

    which drive should the policy target


383
384
385
# File 'lib/jss/api_object/policy.rb', line 383

def target_drive
  @target_drive
end

#triggerString (readonly)

Either EVENT or USER_INITIATED

If it's EVENT, then one or more of the members @trigger_events must true.

Returns:


478
479
480
# File 'lib/jss/api_object/policy.rb', line 478

def trigger
  @trigger
end

#trigger_eventsHash (readonly)

The triggers that cause this policy to execute on a client when the @trigger is “EVENT”

This is a hash with the following keys. Each comes from the API as a key in the :general hash, but they make more sense separated out like this.

  • :trigger_startup => Bool

  • :trigger_login => Bool

  • :trigger_logout => Bool

  • :trigger_checkin => Bool

  • :trigger_network_state_changed => Bool

  • :trigger_enrollment_complete => Bool

  • :trigger_other => the String that causes a custom trigger

To edit a value, call

set_trigger_event(type, new_val)

where type is one of the keys in TRIGGER_EVENTS and new val is the new value (usually boolean)

Returns:


499
500
501
# File 'lib/jss/api_object/policy.rb', line 499

def trigger_events
  @trigger_events
end

#user_may_deferBoolean (readonly)

Returns can the user defer the policy?.

Returns:

  • (Boolean)

    can the user defer the policy?


628
629
630
# File 'lib/jss/api_object/policy.rb', line 628

def user_may_defer
  @user_may_defer
end

#user_may_defer_untilTime (readonly)

Returns when is the user no longer allowed to defer?.

Returns:

  • (Time)

    when is the user no longer allowed to defer?


631
632
633
# File 'lib/jss/api_object/policy.rb', line 631

def user_may_defer_until
  @user_may_defer_until
end

#user_message_finishString (readonly) Also known as: user_message_end

Returns the message shown the user at policy end.

Returns:

  • (String)

    the message shown the user at policy end


637
638
639
# File 'lib/jss/api_object/policy.rb', line 637

def user_message_finish
  @user_message_finish
end

#user_message_startString

Returns the message shown the user at policy start.

Returns:

  • (String)

    the message shown the user at policy start


634
635
636
# File 'lib/jss/api_object/policy.rb', line 634

def user_message_start
  @user_message_start
end

#verify_startup_diskBoolean

Should this policy verify the startup disk?

Returns:

  • (Boolean)

    client maintenance task


508
509
510
# File 'lib/jss/api_object/policy.rb', line 508

def verify_startup_disk
  @verify_startup_disk
end

Class Method Details

.flush_logs(policy, older_than: 0, period: :days, computers: [], api: JSS.api) ⇒ void

This method returns an undefined value.

Flush logs for a given policy older than some number of days, weeks, months or years, possibly limited to one or more computers.

With no parameters, flushes all logs for the policy for all computers.

NOTE: Currently the API doesn't have a way to flush only failed policies.

WARNING: Log flushing can take a long time, and the API call doesnt return until its finished. The connection timeout will be temporarily raised to 30 minutes, unless it's already higher.

Parameters:

  • policy (Integer, String)

    The id or name of the policy to flush

  • older_than (Integer) (defaults to: 0)

    0, 1, 2, 3, or 6

  • period (Symbol) (defaults to: :days)

    :days, :weeks, :months, or :years

  • computers (Array<Integer,String>) (defaults to: [])

    Identifiers of the target computers either ids, names, SNs, macaddrs, or UDIDs. If omitted, flushes logs for all computers

  • api (JSS::APIConnection) (defaults to: JSS.api)

    the API connection to use.


321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/jss/api_object/policy.rb', line 321

def self.flush_logs(policy, older_than: 0, period: :days, computers: [], api: JSS.api)
  orig_timeout = api.cnx.options.timeout
  pol_id = valid_id policy
  raise JSS::NoSuchItemError, "No Policy identified by '#{policy}'." unless pol_id

  older_than = LOG_FLUSH_INTERVAL_INTEGERS[older_than]
  raise JSS::InvalidDataError, "older_than must be one of these integers: #{LOG_FLUSH_INTERVAL_INTEGERS.keys.join ', '}" unless older_than

  period = LOG_FLUSH_INTERVAL_PERIODS[period]
  raise JSS::InvalidDataError, "period must be one of these symbols: :#{LOG_FLUSH_INTERVAL_PERIODS.keys.join ', :'}" unless period

  computers = [computers] unless computers.is_a? Array

  # log flushes can be really slow
  api.timeout = 1800 unless orig_timeout && orig_timeout > 1800

  return api.delete_rsrc "#{LOG_FLUSH_RSRC}/policy/id/#{pol_id}/interval/#{older_than}+#{period}" if computers.empty?

  flush_logs_for_specific_computers pol_id, older_than, period, computers, api
ensure
  api.timeout = orig_timeout
end

Instance Method Details

#add_directory_binding(identifier, **opts) ⇒ Array?

Add a Directory Bidning to the list of directory_bindings handled by this policy. If the directory binding already exists in the policy, nil is returned and no changes are made.

Parameters:

  • identifier (String, Integer)

    the name or id of the directory binding to add to this policy

  • position (Symbol, Integer)

    where to add this directory binding among the list of directory_bindings. Zero-based, :start and 0 are the same, as are :end and -1. Defaults to :end

Returns:

  • (Array, nil)

    the new @directory_bindings array, nil if directory_binding was already in the policy


1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
# File 'lib/jss/api_object/policy.rb', line 1562

def add_directory_binding(identifier, **opts)
  id = validate_directory_binding_opts identifier, opts

  return nil if @directory_bindings.map { |s| s[:id] }.include? id

  name = JSS::DirectoryBinding.map_all_ids_to(:name, api: @api)[id]

  directory_binding_data = {
    id: id,
    name: name
  }

  @directory_bindings.insert opts[:position], directory_binding_data

  @need_to_update = true
  @directory_bindings
end

#add_dock_item(identifier, action) ⇒ Object

Add a dock item to the policy


1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
# File 'lib/jss/api_object/policy.rb', line 1660

def add_dock_item(identifier, action)
  id = JSS::DockItem.valid_id identifier, api: @api

  raise JSS::NoSuchItemError, "No Dock Item matches '#{identifier}'" unless id

  raise JSS::InvalidDataError, "Action must be one of: :#{DOCK_ITEM_ACTIONS.keys.join ', :'}" unless DOCK_ITEM_ACTIONS.include? action

  return nil if @dock_items.map { |d| d[:id] }.include? id

  name = JSS::DockItem.map_all_ids_to(:name, api: @api)[id]

  @dock_items << {id: id, name: name, action: DOCK_ITEM_ACTIONS[action]}

  @need_to_update = true
  @dock_items
end

#add_package(identifier, **opts) ⇒ Array?

Add a package to the list of pkgs handled by this policy. If the pkg already exists in the policy, nil is returned and no changes are made.

Parameters:

  • identifier (String, Integer)

    the name or id of the package to add to this policy

  • position (Symbol, Integer)

    where to add this pkg among the list of pkgs. Zero-based, :start and 0 are the same, as are :end and -1. Defaults to :end

  • action (String)

    One of the values of PACKAGE_ACTIONS

  • feu (Boolean)

    Overrides the setting for the pkg itself Defaults to false

  • fut (Boolean)

    Overrides the setting for the pkg itself Defaults to false

  • update_autorun (Boolean)

    Defaults to false

Returns:

  • (Array, nil)

    the new @packages array, nil if pkg was already in the policy


1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
# File 'lib/jss/api_object/policy.rb', line 1367

def add_package(identifier, **opts)
  id = validate_package_opts(identifier, opts)

  return nil if @packages.map { |p| p[:id] }.include? id

  name = JSS::Package.map_all_ids_to(:name, api: @api)[id]

  pkg_data = {
    id: id,
    name: name,
    action: PACKAGE_ACTIONS[opts[:action]],
    feu: opts[:feu],
    fut: opts[:feu],
    update_autorun: opts[:update_autorun]
  }

  @packages.insert opts[:position], pkg_data

  @need_to_update = true
  @packages
end

#add_printer(identifier, **opts) ⇒ String

Add a specific printer object to the policy.

Parameters:

  • newvalue (String, Integer)

    The name or the id of the printer to be added to this policy.

  • position (Symbol, Integer)

    where to add this printer object among the list of printer objects. Zero-based, :start and 0 are the same, as are :end and -1. Defaults to :end

  • action (Symbol)

    One of the PRINTER_ACTIONS symbols. What you want done with the printer object upon policy execution.

  • make_default (TrueClass, FalseClass)

    Should this printer object be set to default. Defaults to false

Returns:

  • (String)

    The new printers array or nil if the printer was already in the policy

Author:

  • Tyler Morgan


1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
# File 'lib/jss/api_object/policy.rb', line 1624

def add_printer(identifier, **opts)
  id = validate_printer_opts identifier, opts

  return nil if @printers.map { |p| p[:id] }.include? id

  name = JSS::Printer.map_all_ids_to(:name, api: @api)[id]

  printer_data = {
    id: id,
    name: name,
    action: PRINTER_ACTIONS[opts[:action]],
    make_default: opts[:make_default]
  }

  @printers.insert opts[:position], printer_data

  @need_to_update = true
  @printers
end

#add_script(identifier, **opts) ⇒ Array?

Add a script to the list of SCRIPT_PRIORITIESipts run by this policy. If the script already exists in the policy, nil is returned and no changes are made.

Parameters:

  • identifier (String, Integer)

    the name or id of the script to add to this policy

  • opts (Hash)

    the options for this script

  • [Symbol, (Hash)

    a customizable set of options

  • [Symbol] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Array, nil)

    the new @scripts array, nil if script was already in the policy


1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
# File 'lib/jss/api_object/policy.rb', line 1452

def add_script(identifier, **opts)
  id = validate_script_opts(identifier, opts)

  return nil if @scripts.map { |s| s[:id] }.include? id

  name = JSS::Script.map_all_ids_to(:name, api: @api)[id]

  script_data = {
    id: id,
    name: name,
    priority: SCRIPT_PRIORITIES[opts[:priority]],
    parameter4: opts[:parameter4],
    parameter5: opts[:parameter5],
    parameter6: opts[:parameter6],
    parameter7: opts[:parameter7],
    parameter8: opts[:parameter8],
    parameter9: opts[:parameter9],
    parameter10: opts[:parameter10],
    parameter11: opts[:parameter11]
  }

  @scripts.insert opts[:position], script_data

  @need_to_update = true
  @scripts
end

#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

Parameters:

  • new_cat (String, Integer)

    the name or id of a category where this object should appear in SelfSvc

  • display_in (Boolean) (defaults to: true)

    should this item appear in the SelfSvc page for the category? Only meaningful in applicable classes

  • feature_in (Boolean) (defaults to: false)

    should this item be featured in the SelfSvc page for the category? Only meaningful in applicable classes. NOTE: this will always be false if display_in is false.

Raises:

#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.

#apply_encryption_configuration(identifier) ⇒ Void

Sets the Disk Encryption application to “Apply” and sets the correct disk encryption configuration ID using either the name or id.

Returns:

  • (Void)

Author:

  • Tyler Morgan


1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
# File 'lib/jss/api_object/policy.rb', line 1738

def apply_encryption_configuration(identifier)

  id = JSS::DiskEncryptionConfiguration.valid_id identifier

  return if id.nil?

  hash = {
    action: DISK_ENCRYPTION_ACTIONS[:apply],
    disk_encryption_configuration_id: id,
    auth_restart: false
  }

  @disk_encryption = hash
  @need_to_update = true
end

#category=(new_cat) ⇒ void Originally defined in module Categorizable

This method returns an undefined value.

Change the category of this object. Any of the NON_CATEGORIES values will unset the category

Parameters:

  • new_cat (Integer, String)

    The new category

Raises:

#category_assigned?Boolean Also known as: categorized? Originally defined in module Categorizable

Does this object have a category assigned?

Returns:

  • (Boolean)

    Does this object have a category assigned?

#category_idInteger Originally defined in module Categorizable

The id of the category for this object.

Returns:

  • (Integer)

    The id of the category for this object.

#category_nameString Also known as: category Originally defined in module Categorizable

The name of the category for this object. For backward compatibility, this is aliased to just 'category'

Returns:

  • (String)

    The name of the category for this object.

#category_objectJSS::Category Originally defined in module Categorizable

The JSS::Category instance for this object's category

Returns:

  • (JSS::Category)

    The JSS::Category instance for this object's category

#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

Parameters:

  • name (String)

    the name for the new object

  • api (JSS::APIConnection) (defaults to: nil)

    the API in which to create the object Defaults to the API used to instantiate this object

Returns:

  • (APIObject)

    An uncreated clone of this APIObject with the given name

Raises:

#createObject Originally defined in module SelfServable

HACK: ity hack hack… remove when jamf fixes these bugs

#delete_file?Boolean Also known as: delete_path?

Returns Should the searched-for path be deleted if found?.

Returns:

  • (Boolean)

    Should the searched-for path be deleted if found?


1271
1272
1273
# File 'lib/jss/api_object/policy.rb', line 1271

def delete_file?
  @files_processes[:delete_file]
end

#directory_binding_idsArray

Returns the id's of the directory_bindings handled by the policy.

Returns:

  • (Array)

    the id's of the directory_bindings handled by the policy


1541
1542
1543
# File 'lib/jss/api_object/policy.rb', line 1541

def directory_binding_ids
  @directory_bindings.map { |p| p[:id] }
end

#directory_binding_namesArray

Returns the names of the directory_bindings handled by the policy.

Returns:

  • (Array)

    the names of the directory_bindings handled by the policy


1546
1547
1548
# File 'lib/jss/api_object/policy.rb', line 1546

def directory_binding_names
  @directory_bindings.map { |p| p[:name] }
end

#disableObject

Shortcut for endabled = false


826
827
828
# File 'lib/jss/api_object/policy.rb', line 826

def disable
  self.enabled = false
end

#do_not_rebootvoid

This method returns an undefined value.

Reboot Options Do Not Reboot Shortcut method to suppress Reboot Options


1158
1159
1160
1161
1162
# File 'lib/jss/api_object/policy.rb', line 1158

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

#dock_item_idsArray

Returns the id's of the dock_items handled by the policy.

Returns:

  • (Array)

    the id's of the dock_items handled by the policy


1596
1597
1598
# File 'lib/jss/api_object/policy.rb', line 1596

def dock_item_ids
  @dock_items.map { |p| p[:id] }
end

#dock_item_namesArray

Returns the names of the dock_items handled by the policy.

Returns:

  • (Array)

    the names of the dock_items handled by the policy


1601
1602
1603
# File 'lib/jss/api_object/policy.rb', line 1601

def dock_item_names
  @dock_items.map { |p| p[:name] }
end

#enableObject

Shortcut for enabled = true


821
822
823
# File 'lib/jss/api_object/policy.rb', line 821

def enable
  self.enabled = true
end

#evaluate_new_category(new_cat) ⇒ Array<String, Integer> Originally defined in module Categorizable

Given a category name or id, return the name and id TODO: use APIObject.exist? and/or APIObject.valid_id

Parameters:

  • new_cat (String, Integer)

    The name or id of a possible category

Returns:

  • (Array<String, Integer>)

    The matching name and id, which may be nil.

#file_vault_2_reboot=(fv_bool) ⇒ void

This method returns an undefined value.

Reboot Options FileVault Authenticated Reboot

Parameters:

  • fv_bool (Boolean)

    true or false

Raises:


1184
1185
1186
1187
1188
# File 'lib/jss/api_object/policy.rb', line 1184

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

#flush_logs(older_than: 0, period: :days, computers: []) ⇒ void

This method returns an undefined value.

Flush logs for this policy older than some number of days, weeks, months or years, possibly limited to one or more computers

With no parameters, flushes all logs for all computers

NOTE: Currently the API doesn't have a way to flush only failed policies.

WARNING: Log flushing can take a long time, and the API call doesnt return until its finished. The connection timeout will be temporarily raised to 30 minutes, unless it's already higher.

Parameters:

  • older_than (Integer) (defaults to: 0)

    0, 1, 2, 3, or 6

  • period (Symbol) (defaults to: :days)

    :days, :weeks, :months, or :years

  • computers (Array<Integer,String>) (defaults to: [])

    Identifiers of the target computers either ids, names, SNs, macaddrs, or UDIDs

Raises:


1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
# File 'lib/jss/api_object/policy.rb', line 1866

def flush_logs(older_than: 0, period: :days, computers: [])
  raise JSS::NoSuchItemError, "Policy doesn't exist in the JSS. Use #create first." unless @in_jss

  JSS::Policy.flush_logs(
    @id,
    older_than: older_than,
    period: period,
    computers: computers,
    api: @api
  )
end

#kill_process?Boolean

Returns Should the searched-for process be killed if found.

Returns:

  • (Boolean)

    Should the searched-for process be killed if found.


1237
1238
1239
# File 'lib/jss/api_object/policy.rb', line 1237

def kill_process?
  @files_processes[:kill_process]
end

#locate_fileString

Returns The term to seach for using the locate command.

Returns:

  • (String)

    The term to seach for using the locate command


1315
1316
1317
# File 'lib/jss/api_object/policy.rb', line 1315

def locate_file
  @files_processes[:locate_file]
end

#locate_file=(term) ⇒ void

This method returns an undefined value.

Set the term to seach for using the locate command

Parameters:

  • term (String)

    the term to seach for using the locate command

Raises:


1325
1326
1327
1328
1329
# File 'lib/jss/api_object/policy.rb', line 1325

def locate_file=(term)
  raise JSS::InvalidDataError, 'Term to locate must be a String' unless term.is_a? String
  @files_processes[:locate_file] = term
  @need_to_update = true
end

#minutes_until_reboot=(minutes) ⇒ void

This method returns an undefined value.

Reboot Options Minutes Until Reboot

Parameters:

  • minutes (String)

    The number of minutes to delay prior to reboot

Raises:


1171
1172
1173
1174
1175
# File 'lib/jss/api_object/policy.rb', line 1171

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

#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.

Parameters:

  • newname (String)

    the new name

Raises:

#no_user_logged_in=(no_user_option) ⇒ void

This method returns an undefined value.

What to do at reboot when No User Logged In

Parameters:

  • no_user_option (String)

    Any one of the Strings from NO_USER_LOGGED_IN

Raises:


1070
1071
1072
1073
1074
# File 'lib/jss/api_object/policy.rb', line 1070

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

#notify_failed_retries=(bool) ⇒ void

This method returns an undefined value.

Parameters:

  • bool (Boolean)

    Should admins be notified of failed retry attempts


918
919
920
921
922
923
924
925
# File 'lib/jss/api_object/policy.rb', line 918

def notify_failed_retries=(bool)
  validate_retry_opt
  bool = JSS::Validate.boolean bool
  return if @notify_failed_retries == bool

  @notify_failed_retries = bool
  @need_to_update = true
end

#notify_failed_retries?Boolean Also known as: notify_failed_retries, notify_on_each_failed_retry

Returns Should admins be notified of failed retry attempts.

Returns:

  • (Boolean)

    Should admins be notified of failed retry attempts


908
909
910
911
912
# File 'lib/jss/api_object/policy.rb', line 908

def notify_failed_retries?
  return false unless FREQUENCIES[:once_per_computer] == @frequency

  @notify_failed_retries
end

#package_idsArray

Returns the id's of the packages handled by the policy.

Returns:

  • (Array)

    the id's of the packages handled by the policy


1338
1339
1340
# File 'lib/jss/api_object/policy.rb', line 1338

def package_ids
  @packages.map { |p| p[:id] }
end

#package_namesArray

Returns the names of the packages handled by the policy.

Returns:

  • (Array)

    the names of the packages handled by the policy


1343
1344
1345
# File 'lib/jss/api_object/policy.rb', line 1343

def package_names
  @packages.map { |p| p[:name] }
end

#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

#printer_idsArray

Returns the id's of the printers handled by the policy.

Returns:

  • (Array)

    the id's of the printers handled by the policy


1686
1687
1688
1689
1690
1691
1692
# File 'lib/jss/api_object/policy.rb', line 1686

def printer_ids
    begin
        @printers.map { |p| p[:id] }
        rescue TypeError
        return []
    end
end

#printer_namesArray

Returns the names of the printers handled by the policy.

Returns:

  • (Array)

    the names of the printers handled by the policy


1695
1696
1697
1698
1699
1700
1701
# File 'lib/jss/api_object/policy.rb', line 1695

def printer_names
    begin
        @printers.map { |p| p[:name] }
        rescue TypeError
        return []
    end
end

#reboot_message=(message) ⇒ void Also known as: message=

This method returns an undefined value.

Set Reboot Message

Parameters:

  • reboot_message (String)

    Text of Reboot Message

Raises:


1094
1095
1096
1097
1098
# File 'lib/jss/api_object/policy.rb', line 1094

def reboot_message=(message)
  raise JSS::InvalidDataError, 'Reboot message must be a String' unless message.is_a? String
  @reboot_options[:message] = message
  @need_to_update = true
end

#reissue_keyVoid

Sets the Disk Encryption application to “Remediate” and sets the remediation key type to individual.

Returns:

  • (Void)

Author:

  • Tyler Morgan


1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
# File 'lib/jss/api_object/policy.rb', line 1713

def reissue_key()
  if @disk_encryption[:action] != DISK_ENCRYPTION_ACTIONS[:remediate]
    # Setting New Action
    hash = {
      action: DISK_ENCRYPTION_ACTIONS[:remediate],
      remediate_key_type: "Individual"
    }

    @disk_encryption = hash
    @need_to_update = true

  else
    # Update
    return
  end

end

#remove_directory_binding(identifier) ⇒ Array?

Remove a directory binding from this policy by name or id

Parameters:

  • identifier (String, Integer)

    the name or id of the directory binding to remove

Returns:

  • (Array, nil)

    the new directory bindings array or nil if no change


1587
1588
1589
1590
1591
# File 'lib/jss/api_object/policy.rb', line 1587

def remove_directory_binding(identifier)
  removed = @directory_bindings.delete_if { |s| s[:id] == identifier || s[:name] == identifier }
  @need_to_update = true if removed
  removed
end

#remove_dock_item(identifier) ⇒ Object

Remove a dock item from the policy


1678
1679
1680
1681
1682
1683
# File 'lib/jss/api_object/policy.rb', line 1678

def remove_dock_item(identifier)
  # TODO: Add validation against JSS::DockItem
  removed = @dock_items.delete_if { |d| d[:id] == identifier || d[:name] == identifier }
  @need_to_update = true if removed
  removed
end

#remove_encryption_configurationVoid

Removes the Disk Encryption settings associated with this specific policy.

Returns:

  • (Void)

Author:

  • Tyler Morgan


1761
1762
1763
1764
1765
1766
1767
1768
# File 'lib/jss/api_object/policy.rb', line 1761

def remove_encryption_configuration()
  hash = {
    action: DISK_ENCRYPTION_ACTIONS[:none]
  }

  @disk_encryption = hash
  @need_to_update = true
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_package(identifier) ⇒ Array?

Remove a package from this policy by name or id

Parameters:

  • identifier (String, Integer)

    the name or id of the package to remove

Returns:

  • (Array, nil)

    the new packages array or nil if no change


1395
1396
1397
1398
1399
# File 'lib/jss/api_object/policy.rb', line 1395

def remove_package(identifier)
  removed = @packages.delete_if { |p| p[:id] == identifier || p[:name] == identifier }
  @need_to_update = true if removed
  removed
end

#remove_printer(identifier) ⇒ Array?

Remove a specific printer object from the policy.

Parameters:

  • identifier (String, Integer)

    The name or id of the printer to be removed.

Returns:

  • (Array, nil)

    The new printers array or nil if no change.

Author:

  • Tyler Morgan


1652
1653
1654
1655
1656
1657
# File 'lib/jss/api_object/policy.rb', line 1652

def remove_printer(identifier)
  removed = @printers.delete_if { |p| p[:id] == identifier || p[:name] == identifier }

  @need_to_update = true
  removed
end

#remove_script(identifier) ⇒ Array?

Remove a script from this policy by name or id

Parameters:

  • identifier (String, Integer)

    the name or id of the script to remove

Returns:

  • (Array, nil)

    the new scripts array or nil if no change


1485
1486
1487
1488
1489
# File 'lib/jss/api_object/policy.rb', line 1485

def remove_script(identifier)
  removed = @scripts.delete_if { |s| s[:id] == identifier || s[:name] == identifier }
  @need_to_update = true if removed
  removed
end

#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

Parameters:

  • cat (String, Integer)

    the name or id of the category to remove

#retry_attemptsInteger

Returns How many times wil the policy be retried if it fails. -1 means no retries, otherwise, an integer from 1 to 10.

Returns:

  • (Integer)

    How many times wil the policy be retried if it fails. -1 means no retries, otherwise, an integer from 1 to 10


879
880
881
882
883
# File 'lib/jss/api_object/policy.rb', line 879

def retry_attempts
  return 0 unless FREQUENCIES[:once_per_computer] == @frequency

  @retry_attempts
end

#retry_attempts=(int) ⇒ void

This method returns an undefined value.

Set the number of times to retry if the policy fails. One of the ways to turn off policy retry is to set this to 0 or -1 The other is to set retry_event to :none

Parameters:

  • From (Integer)

    -1 to 10

Raises:


892
893
894
895
896
897
898
899
900
901
902
903
904
905
# File 'lib/jss/api_object/policy.rb', line 892

def retry_attempts=(int)
  validate_retry_opt
  raise JSS::InvalidDataError, 'Retry attempts must be an integer from 0-10' unless int.is_a?(Integer) && (-1..10).include?(int)

  # if zero or -1, turn off retries
  if int <= 0
    @retry_event = RETRY_EVENTS[:none]
    int = -1
  end
  return if @retry_attempts == int

  @retry_attempts = int
  @need_to_update = true
end

#retry_eventString

Returns The event that causes a policy retry.

Returns:

  • (String)

    The event that causes a policy retry


847
848
849
850
851
# File 'lib/jss/api_object/policy.rb', line 847

def retry_event
  return RETRY_EVENTS[:none] unless FREQUENCIES[:once_per_computer] == @frequency

  @retry_event
end

#retry_event=(evt) ⇒ void

This method returns an undefined value.

Set the event that causes a retry if the policy fails. One of the ways to turn off policy retry is to set this to :none The other is to set the retry_attempts to 0

Parameters:

  • A (Symbol, String)

    key or value from RETRY_EVENTS

Raises:


860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
# File 'lib/jss/api_object/policy.rb', line 860

def retry_event=(evt)
  validate_retry_opt
  raise JSS::InvalidDataError, "Retry event must be one of :#{RETRY_EVENTS.keys.join ', :'}" unless RETRY_EVENTS.key?(evt) || RETRY_EVENTS.value?(evt)

  evt = evt.is_a?(Symbol) ? RETRY_EVENTS[evt] : evt
  return if evt == @retry_event

  # if the event is not 'none' and attempts is <= 0,
  # set events to 1, or the API won't accept it
  unless evt == RETRY_EVENTS[:none]
    @retry_attempts = 1 unless @retry_attempts.positive?
  end

  @retry_event = evt
  @need_to_update = true
end

#run(show_output = false) ⇒ Boolean? Also known as: execute

Try to execute this policy on this machine.

Parameters:

  • show_output (Boolean) (defaults to: false)

    should the stdout and stderr of the 'jamf policy' command be sent to stdout in realtime?

Returns:

  • (Boolean, nil)

    The success of the 'jamf policy' command, or nil if the policy couldn't be executed (out of scope, policy disabled, etc)


1837
1838
1839
1840
1841
1842
# File 'lib/jss/api_object/policy.rb', line 1837

def run(show_output = false)
  return nil unless enabled?
  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

#run_commandString Also known as: command_to_run

Returns The unix shell command to run on ths client.

Returns:

  • (String)

    The unix shell command to run on ths client.


1194
1195
1196
# File 'lib/jss/api_object/policy.rb', line 1194

def run_command
  @files_processes[:run_command]
end

#run_command=(command) ⇒ void Also known as: command_to_run=

This method returns an undefined value.

Set the unix shell command to be run on the client

Parameters:

  • command (String)

    the unix shell command to be run on the client

Raises:


1205
1206
1207
1208
1209
# File 'lib/jss/api_object/policy.rb', line 1205

def run_command=(command)
  raise JSS::InvalidDataError, 'Command to run must be a String' unless command.is_a? String
  @files_processes[:run_command] = command
  @need_to_update = true
end

#script_idsArray

Returns the id's of the scripts handled by the policy.

Returns:

  • (Array)

    the id's of the scripts handled by the policy


1404
1405
1406
# File 'lib/jss/api_object/policy.rb', line 1404

def script_ids
  @scripts.map { |p| p[:id] }
end

#script_namesArray

Returns the names of the scripts handled by the policy.

Returns:

  • (Array)

    the names of the scripts handled by the policy


1409
1410
1411
# File 'lib/jss/api_object/policy.rb', line 1409

def script_names
  @scripts.map { |p| p[:name] }
end

#search_by_pathPathname

Returns The path to search for.

Returns:


1261
1262
1263
1264
1265
1266
1267
# File 'lib/jss/api_object/policy.rb', line 1261

def search_by_path
  if @files_processes[:search_by_path].nil?
    return nil
  else
    Pathname.new @files_processes[:search_by_path]
  end
end

#search_for_processString

Returns The process name to search for on the client.

Returns:

  • (String)

    The process name to search for on the client


1231
1232
1233
# File 'lib/jss/api_object/policy.rb', line 1231

def search_for_process
  @files_processes[:search_for_process]
end

#self_service_execute_urlString Originally defined in module SelfServable

Returns The url to view this thing in Self Service.

Returns:

  • (String)

    The url to view this thing in Self Service

#self_service_payloadSymbol Originally defined in module SelfServable

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

Returns:

  • (Symbol)

    :profile, :app, or :policy

#self_service_targetsArray<Symbol> Originally defined in module SelfServable

What devices types can get this thing in Self Service

Returns:

  • (Array<Symbol>)

    An array of :macos, :ios, or both.

#self_service_view_urlString Originally defined in module SelfServable

Returns The url to view this thing in Self Service.

Returns:

  • (String)

    The url to view this thing in Self Service

#server_side_activation=(activation) ⇒ void

This method returns an undefined value.

Set Server Side Activation

Parameters:

  • activation (Time)

    Activation date and time

Raises:


976
977
978
979
980
# File 'lib/jss/api_object/policy.rb', line 976

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

#server_side_expiration=(expiration) ⇒ void

This method returns an undefined value.

Set Server Side Expiration

Parameters:

  • expiration (Time)

    Expiration date and time

Raises:


988
989
990
991
992
# File 'lib/jss/api_object/policy.rb', line 988

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

#set_management_account(action, **opts) ⇒ Object

Interact with management account settings

Reference: developer.jamf.com/documentation#resources-with-passwords

Parameters:

  • action (Key)

    one of the MGMT_ACCOUNT_ACTIONS keys

Returns:

  • The current specified management settings.

Raises:


1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
# File 'lib/jss/api_object/policy.rb', line 1778

def (action, **opts)
  # TODO: Add proper error handling
  raise JSS::InvalidDataError, "Action must be one of: :#{MGMT_ACCOUNT_ACTIONS.keys.join ', :'}" unless MGMT_ACCOUNT_ACTIONS.include? action

  management_data = {}

  if action == :change_pw || action == :reset_pw
    raise JSS::MissingDataError, ":password must be provided when changing management account password" if opts[:password].nil?

    management_data = {
      action: MGMT_ACCOUNT_ACTIONS[action],
      managed_password: opts[:password]
    }
  elsif action == :reset_random || action == :generate_pw
    raise JSS::MissingDataError, ":password_length must be provided when setting a random password" if opts[:password_length].nil?
    raise JSS::InvalidDataError, ":password_length must be an Integer" unless opts[:password_length].is_a? Integer

    management_data = {
      action: MGMT_ACCOUNT_ACTIONS[action],
      managed_password_length: opts[:password_length]
    }
  else
    management_data = {
      action: MGMT_ACCOUNT_ACTIONS[action]
    }
  end

  @management_account = management_data

  @need_to_update = true

  @management_account

end

#set_script_parameters(identifier, **opts) ⇒ Array

Set a script parameter

Parameters:

  • identifier (Integer, String)

    identifier the id or name of a script in this policy

  • opts (Hash)

    opts the options to alter for this script

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Array)

    the scripts array

Raises:


1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
# File 'lib/jss/api_object/policy.rb', line 1523

def set_script_parameters(identifier, **opts)
  id = JSS::Script.valid_id identifier, api: @api
  raise JSS::NoSuchItemError, "No script matches '#{identifier}'" unless id

  script_data = @scripts.select { |s| s[:id] == id }[0]
  raise JSS::InvalidDataError, "Script #{id} is not configured. Use add_script method." unless script_data

  opts.each do |parameter, value|
    script_data[parameter] = value if SCRIPT_PARAMETERS_AVAILABLE.include? parameter
  end

  @need_to_update = true
  @scripts
end

#set_search_by_path(path, delete = false) ⇒ void

This method returns an undefined value.

Set the path to search for, a String or Pathname, and whether or not to delete it if found.

Setter methods (which end with =) can't easily take multiple arguments, so we instead name them “set_blah_blah” rather than “blah_blah=”

Parameters:

  • path (String, Pathname)

    the path to search for

  • delete (Boolean) (defaults to: false)

    should the path be deleted if found

Raises:


1288
1289
1290
1291
1292
1293
# File 'lib/jss/api_object/policy.rb', line 1288

def set_search_by_path(path, delete = false)
  raise JSS::InvalidDataError, 'Path to search for must be a String or a Pathname' unless path.is_a?(String) || path.is_a?(Pathname)
  @files_processes[:search_by_path] = path.to_s
  @files_processes[:delete_file] = delete ? true : false
  @need_to_update = true
end

#set_search_for_process(process, kill = false) ⇒ void

This method returns an undefined value.

Set the process name to search for, and if it should be killed if found.

Setter methods (which end with =) can't easily take multiple arguments, so we instead name them “set_blah_blah” rather than “blah_blah=”

Parameters:

  • process (String)

    the process name to search for

  • kill (Boolean) (defaults to: false)

    should be process be killed if found


1253
1254
1255
1256
1257
# File 'lib/jss/api_object/policy.rb', line 1253

def set_search_for_process(process, kill = false)
  @files_processes[:search_for_process] = process.to_s
  @files_processes[:kill_process] = kill ? true : false
  @need_to_update = true
end

#set_trigger_event(type, new_val) ⇒ void

This method returns an undefined value.

Change a trigger event

Parameters:

  • type (Symbol)

    the type of trigger, one of the keys of TRIGGER_EVENTS

  • new_val (Boolean)

    whether the type of trigger is active or not.

Raises:


959
960
961
962
963
964
965
966
967
968
# File 'lib/jss/api_object/policy.rb', line 959

def set_trigger_event(type, new_val)
  raise JSS::InvalidDataError, "Trigger type must be one of #{TRIGGER_EVENTS.keys.join(', ')}" unless TRIGGER_EVENTS.key?(type)
  if type == :custom
    raise JSS::InvalidDataError, 'Custom triggers must be Strings' unless new_val.is_a? String
  else
    raise JSS::InvalidDataError, 'Non-custom triggers must be true or false' unless JSS::TRUE_FALSE.include? new_val
  end
  @trigger_events[TRIGGER_EVENTS[type]] = new_val
  @need_to_update = true
end

#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.

#site=(new_site) ⇒ void Originally defined in module Sitable

This method returns an undefined value.

Change the site of this object. Any of the NON_SITES values will unset the site

Parameters:

  • new_site (Integer, String)

    The new site

Raises:

#site_assigned?Boolean Originally defined in module Sitable

Does this object have a site assigned?

Returns:

  • (Boolean)

    Does this object have a site assigned?

#site_idInteger Originally defined in module Sitable

The id of the site for this object.

Returns:

  • (Integer)

    The id of the site for this object.

#site_nameString Also known as: site Originally defined in module Sitable

The name of the site for this object. For backward compatibility, this is aliased to just 'site'

Returns:

  • (String)

    The name of the site for this object.

#site_objectJSS::Site Originally defined in module Sitable

The JSS::Site instance for this object's site

Returns:

  • (JSS::Site)

    The JSS::Site instance for this object's site

#specify_startup=(startup_volume) ⇒ void

This method returns an undefined value.

Specify Startup Volume Only Supports “Specify Local Startup Disk”

Parameters:

  • startup_volume (String)

    a Volume to reboot to

Raises:


1146
1147
1148
1149
1150
# File 'lib/jss/api_object/policy.rb', line 1146

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

#spotlight_searchString

Returns The term to search for using spotlight.

Returns:

  • (String)

    The term to search for using spotlight


1297
1298
1299
# File 'lib/jss/api_object/policy.rb', line 1297

def spotlight_search
  @files_processes[:spotlight_search]
end

#spotlight_search=(term) ⇒ void

This method returns an undefined value.

Set the term to seach for using spotlight

Parameters:

  • term (String)

    the term to seach for using spotlight

Raises:


1307
1308
1309
1310
1311
# File 'lib/jss/api_object/policy.rb', line 1307

def spotlight_search=(term)
  raise JSS::InvalidDataError, 'Spotlight search term must be a String' unless term.is_a? String
  @files_processes[:spotlight_search] = term
  @need_to_update = true
end

#startup_disk=(startup_disk_option) ⇒ void

This method returns an undefined value.

Set Startup Disk Only Supports 'Specify Local Startup Disk' at the moment

Parameters:

  • startup_disk_option (String)

Raises:


1132
1133
1134
1135
1136
1137
# File 'lib/jss/api_object/policy.rb', line 1132

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

#unset_categoryvoid Originally defined in module Categorizable

This method returns an undefined value.

Set the category to nothing

#unset_sitevoid Originally defined in module Sitable

This method returns an undefined value.

Set the site to nothing

#updateObject Originally defined in module SelfServable

HACK: ity hack hack… remove when jamf fixes these bugs

#update_locate_database=(bool) ⇒ void

This method returns an undefined value.

Set whether or not to update the database used by the locate command.

Parameters:

  • bool (Boolean)

    whether or not to update the database used by the locate command.


1224
1225
1226
1227
# File 'lib/jss/api_object/policy.rb', line 1224

def update_locate_database=(bool)
  @files_processes[:update_locate_database] = JSS::Validate.boolean bool
  @need_to_update = true
end

#update_locate_database?Boolean

Returns Should we update the database used by the locate command?.

Returns:

  • (Boolean)

    Should we update the database used by the locate command?


1214
1215
1216
# File 'lib/jss/api_object/policy.rb', line 1214

def update_locate_database?
  @files_processes[:update_locate_database]
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.

Parameters:

  • type (Symbol)

    the type of upload happening. Must be one of the keys defined in the class's UPLOAD_TYPES Hash.

  • local_file (String, Pathname)

    String or Pathname pointing to the locally-readable file to be uploaded.

Returns:

  • (String)

    The xml response from the server.

Raises:

#user_logged_in=(logged_in_option) ⇒ void

This method returns an undefined value.

What to do at reboot when there is a User Logged In

Parameters:

  • logged_in_option (String)

    Any one of the Strings from USER_LOGGED_IN

Raises:


1082
1083
1084
1085
1086
# File 'lib/jss/api_object/policy.rb', line 1082

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

#user_message_end=(message) ⇒ void Also known as: user_message_finish=

This method returns an undefined value.

Set User Finish Message

Parameters:

  • user_message (String)

    Text of User Message

Raises:


1117
1118
1119
1120
1121
# File 'lib/jss/api_object/policy.rb', line 1117

def user_message_end=(message)
  raise JSS::InvalidDataError, 'User message must be a String' unless message.is_a? String
  @user_message_finish = message
  @need_to_update = true
end

#user_removable?Boolean? Originally defined in module SelfServable

Can this thing be removed by the user?

Returns:

  • (Boolean, nil)

    nil means 'not applicable'

#verify_management_password(password) ⇒ Boolean

Check if management password matches provided password

Parameters:

  • password (String)

    the password that is SHA256'ed to compare to the one from the API.

Returns:

  • (Boolean)

    The result of the comparison of the management password and provided text.

Raises:


1819
1820
1821
1822
1823
1824
1825
# File 'lib/jss/api_object/policy.rb', line 1819

def verify_management_password(password)
  raise JSS::InvalidDataError, "Management password must be a string." unless password.is_a? String

  raise JSS::UnsupportedError, "'#{@management_account[:action].to_s}' does not support management passwords." unless @management_account[:action] == MGMT_ACCOUNT_ACTIONS[:change_pw] || @management_account[:action] == MGMT_ACCOUNT_ACTIONS[:reset_pw]

  return Digest::SHA256.hexdigest(password).to_s == @management_account[:managed_password_sha256].to_s
end