ruby-jss 0.10.0 → 0.10.1a2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby-jss might be problematic. Click here for more details.

Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jss/api_object.rb +102 -0
  3. data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +4 -0
  4. data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +5 -0
  5. data/lib/jss/api_object/advanced_search/advanced_user_search.rb +5 -0
  6. data/lib/jss/api_object/building.rb +5 -0
  7. data/lib/jss/api_object/category.rb +5 -0
  8. data/lib/jss/api_object/computer.rb +7 -2
  9. data/lib/jss/api_object/computer_invitation.rb +5 -0
  10. data/lib/jss/api_object/department.rb +26 -21
  11. data/lib/jss/api_object/distribution_point.rb +5 -0
  12. data/lib/jss/api_object/ebook.rb +5 -0
  13. data/lib/jss/api_object/extendable.rb +123 -148
  14. data/lib/jss/api_object/extension_attribute.rb +242 -301
  15. data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +5 -0
  16. data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +14 -9
  17. data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +40 -35
  18. data/lib/jss/api_object/group/computer_group.rb +11 -6
  19. data/lib/jss/api_object/group/mobile_device_group.rb +11 -6
  20. data/lib/jss/api_object/group/user_group.rb +16 -11
  21. data/lib/jss/api_object/ldap_server.rb +5 -0
  22. data/lib/jss/api_object/mac_application.rb +5 -0
  23. data/lib/jss/api_object/mobile_device.rb +5 -0
  24. data/lib/jss/api_object/mobile_device_application.rb +5 -0
  25. data/lib/jss/api_object/mobile_device_configuration_profile.rb +5 -0
  26. data/lib/jss/api_object/netboot_server.rb +11 -6
  27. data/lib/jss/api_object/network_segment.rb +5 -0
  28. data/lib/jss/api_object/osx_configuration_profile.rb +4 -0
  29. data/lib/jss/api_object/package.rb +5 -0
  30. data/lib/jss/api_object/peripheral.rb +4 -0
  31. data/lib/jss/api_object/peripheral_type.rb +11 -6
  32. data/lib/jss/api_object/policy.rb +5 -0
  33. data/lib/jss/api_object/removable_macaddr.rb +28 -23
  34. data/lib/jss/api_object/restricted_software.rb +5 -0
  35. data/lib/jss/api_object/script.rb +5 -0
  36. data/lib/jss/api_object/site.rb +29 -24
  37. data/lib/jss/api_object/software_update_server.rb +11 -6
  38. data/lib/jss/api_object/user.rb +5 -0
  39. data/lib/jss/api_object/webhook.rb +5 -0
  40. data/lib/jss/version.rb +1 -1
  41. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 769cbc0fa921b444480b1c3b588664c3c3937aa7
4
- data.tar.gz: 4a4d8ab91135e180d49e52e2be783019cb42e978
3
+ metadata.gz: cbc35fe360debd8ec27b382a0bacb3437a2a2bdd
4
+ data.tar.gz: '08e688dae6471d1075b582e544635dc0710f7b2c'
5
5
  SHA512:
6
- metadata.gz: '069697c8db875ece53b7490a7ec095d695d2852dd1c6d20acc4a6d4a0acdcc4a59f7e978b8408f03796b52f9713991c2345f716aef964bf08bcfea364b384887'
7
- data.tar.gz: 7de60430c90c5ce3f7f92afdb75307e1a8798d22ba75868dd6702970d829c81143943da96fc759612cf9d477e0fc6535e77bb793865ffe22b94efdf6f95d9ffc
6
+ metadata.gz: b2875e1733f3c187248d4a0e17e6ca3fe795231d2391b7764f60d627c9f7fafe2a9c44d4b38e941633eab9cf604db8b7d36cb89ef4ce13af2c69976345405be5
7
+ data.tar.gz: 9e7d9a29bfe5c6e88ea1c79674d5dc8fa8588a5f6c5793fb733e9a30c1f3105bc5c98da4b16c3f457715dd7b31cfaf26db1fb662edb6357470a7e9e8c3ab4aba
@@ -524,6 +524,11 @@ module JSS
524
524
  name: { rsrc_key: :name, list: :all_names }
525
525
  }.freeze
526
526
 
527
+ # This table holds the object history for JSS objects.
528
+ # Object history is not available via the API,
529
+ # only MySQL.
530
+ OBJECT_HISTORY_TABLE = 'object_history'.freeze
531
+
527
532
  # Attributes
528
533
  #####################################
529
534
 
@@ -726,10 +731,107 @@ module JSS
726
731
  vars
727
732
  end
728
733
 
734
+ # Make an entry in this object's Object History.
735
+ # For this to work, the APIObject subclass must define
736
+ # OBJECT_HISTORY_OBJECT_TYPE, an integer indicating the
737
+ # object type in the OBJECT_HISTORY_TABLE in the database
738
+ # (e.g. for computers, the object type is 1)
739
+ #
740
+ # NOTE: Object history is not available via the API,
741
+ # so access is only available through direct MySQL
742
+ # connections
743
+ #
744
+ # Also: the 'details' column in the table shows up in the
745
+ # 'notes' column of the Web UI. and the 'object_description'
746
+ # column of the table shows up in the 'details' column of
747
+ # the UI, under the 'details' button.
748
+ #
749
+ # The params below reflect the UI, not the table.
750
+ #
751
+ # @param user[String] the username creating the entry.
752
+ #
753
+ # @param notes[String] A string that appears as a 'note' in the history
754
+ #
755
+ # @param details[String] A string that appears as the 'details' in the history
756
+ #
757
+ # @return [void]
758
+ #
759
+ def add_object_history_entry(user: nil, notes: nil, details: nil)
760
+ validate_object_history_available
761
+
762
+ raise JSS::MissingDataError, 'A user: must be provided to make the entry' unless user
763
+
764
+ raise JSS::MissingDataError, 'Either notes: must be provided to make the entry' unless notes
765
+
766
+ user = "'#{Mysql.quote user.to_s}'"
767
+ notes = "'#{Mysql.quote notes.to_s}'"
768
+ obj_type = self.class::OBJECT_HISTORY_OBJECT_TYPE
769
+
770
+ field_list = 'object_type, object_id, username, details, timestamp_epoch'
771
+ value_list = "#{obj_type}, #{@id}, #{user}, #{notes}, #{Time.now.to_jss_epoch}"
772
+
773
+ if details
774
+ field_list << ', object_description'
775
+ value_list << ", '#{Mysql.quote details.to_s}'"
776
+ end # if details
777
+
778
+ q = "INSERT INTO #{OBJECT_HISTORY_TABLE}
779
+ (#{field_list})
780
+ VALUES
781
+ (#{value_list})"
782
+
783
+ JSS::DB_CNX.db.query q
784
+ end
785
+
786
+ # the object history for this object, an array of hashes
787
+ # one per history entry, in order of creation.
788
+ # Each hash contains:
789
+ # user: String, the username that created the entry
790
+ # notes: String, the notes for the entry
791
+ # date: Time, the timestamp for the entry
792
+ # details: String or nil, any details provided for the entry
793
+ #
794
+ # @return [Array<Hash>] the object history
795
+ #
796
+ def object_history
797
+ validate_object_history_available
798
+
799
+ q = "SELECT username, details, timestamp_epoch, object_description
800
+ FROM #{OBJECT_HISTORY_TABLE}
801
+ WHERE object_type = #{self.class::OBJECT_HISTORY_OBJECT_TYPE}
802
+ AND object_id = #{@id}
803
+ ORDER BY object_history_id ASC"
804
+
805
+ result = JSS::DB_CNX.db.query q
806
+ history = []
807
+ result.each do |entry|
808
+ history << {
809
+ user: entry[0],
810
+ notes: entry[1],
811
+ date: JSS.epoch_to_time(entry[2]),
812
+ details: entry[3]
813
+ }
814
+ end # each do entry
815
+ history
816
+ end
817
+
729
818
  # Private Instance Methods
730
819
  #####################################
731
820
  private
732
821
 
822
+ # Raise an exception if object history is not
823
+ # available for this object
824
+ #
825
+ # @return [void]
826
+ #
827
+ def validate_object_history_available
828
+ raise JSS::NoSuchItemError, 'Object not yet created' unless @id && @in_jss
829
+
830
+ raise JSS::InvalidConnectionError, 'Not connected to MySQL' unless JSS::DB_CNX.connected?
831
+
832
+ raise JSS::UnsupportedError, "Object History access is not supported for #{self.class} objects at this time" unless defined? self.class::OBJECT_HISTORY_OBJECT_TYPE
833
+ end
834
+
733
835
  # If we were passed pre-lookedup API data, validate it,
734
836
  # raising exceptions if not valid.
735
837
  #
@@ -75,6 +75,10 @@ module JSS
75
75
  # for each computer?
76
76
  RESULT_ID_FIELDS = [:id, :name, :udid].freeze
77
77
 
78
+ # the object type for this object in
79
+ # the object history table.
80
+ # See {APIObject#add_object_history_entry}
81
+ OBJECT_HISTORY_OBJECT_TYPE = 70
78
82
 
79
83
  # Attributes
80
84
  #####################################
@@ -69,6 +69,11 @@ module JSS
69
69
  # for each mobiledevices?
70
70
  RESULT_ID_FIELDS = [:id, :name, :udid].freeze
71
71
 
72
+ # the object type for this object in
73
+ # the object history table.
74
+ # See {APIObject#add_object_history_entry}
75
+ OBJECT_HISTORY_OBJECT_TYPE = 71
76
+
72
77
  # Attributes
73
78
  #####################################
74
79
 
@@ -69,6 +69,11 @@ module JSS
69
69
  # for each user?
70
70
  RESULT_ID_FIELDS = [:id, :name].freeze
71
71
 
72
+ # the object type for this object in
73
+ # the object history table.
74
+ # See {APIObject#add_object_history_entry}
75
+ OBJECT_HISTORY_OBJECT_TYPE = 55
76
+
72
77
  # Attributes
73
78
  #####################################
74
79
 
@@ -66,6 +66,11 @@ module JSS
66
66
  # these keys, as well as :id and :name, are present in valid API JSON data for this class
67
67
  VALID_DATA_KEYS = [].freeze
68
68
 
69
+ # the object type for this object in
70
+ # the object history table.
71
+ # See {APIObject#add_object_history_entry}
72
+ OBJECT_HISTORY_OBJECT_TYPE = 41
73
+
69
74
  # Attributes
70
75
  #####################################
71
76
 
@@ -85,6 +85,11 @@ module JSS
85
85
  # The Default Priority
86
86
  DEFAULT_PRIORITY = 5
87
87
 
88
+ # the object type for this object in
89
+ # the object history table.
90
+ # See {APIObject#add_object_history_entry}
91
+ OBJECT_HISTORY_OBJECT_TYPE = 72
92
+
88
93
  # Attributes
89
94
  #####################################
90
95
 
@@ -331,6 +331,12 @@ module JSS
331
331
 
332
332
  POLICY_STATUS_PENDING = 'Pending'.freeze
333
333
 
334
+ # the object type for this object in
335
+ # the object history table.
336
+ # See {APIObject#add_object_history_entry}
337
+ OBJECT_HISTORY_OBJECT_TYPE = 1
338
+
339
+
334
340
  # Class Methods
335
341
  #####################################
336
342
 
@@ -808,8 +814,7 @@ module JSS
808
814
  # @return [Hash, nil] The hardware[:storage] hash of the boot drive
809
815
  #
810
816
  def boot_drive
811
- drives.each { |d| return d if d[:partition][:type] == 'boot' }
812
- nil
817
+ drives.select { |d| d[:partition] && d[:partition][:type] == 'boot' }.first
813
818
  end
814
819
 
815
820
  # @return [Array<Hash>] each printer on this computer
@@ -83,6 +83,11 @@ module JSS
83
83
  invitation: {rsrc_key: :invitation, list: :all_invitations}
84
84
  }.freeze
85
85
 
86
+ # the object type for this object in
87
+ # the object history table.
88
+ # See {APIObject#add_object_history_entry}
89
+ OBJECT_HISTORY_OBJECT_TYPE = 84
90
+
86
91
  # Attributes
87
92
  #####################################
88
93
 
@@ -1,31 +1,31 @@
1
1
  ### Copyright 2017 Pixar
2
2
 
3
- ###
3
+ ###
4
4
  ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
5
  ### with the following modification; you may not use this file except in
6
6
  ### compliance with the Apache License and the following modification to it:
7
7
  ### Section 6. Trademarks. is deleted and replaced with:
8
- ###
8
+ ###
9
9
  ### 6. Trademarks. This License does not grant permission to use the trade
10
10
  ### names, trademarks, service marks, or product names of the Licensor
11
11
  ### and its affiliates, except as required to comply with Section 4(c) of
12
12
  ### the License and to reproduce the content of the NOTICE file.
13
- ###
13
+ ###
14
14
  ### You may obtain a copy of the Apache License at
15
- ###
15
+ ###
16
16
  ### http://www.apache.org/licenses/LICENSE-2.0
17
- ###
17
+ ###
18
18
  ### Unless required by applicable law or agreed to in writing, software
19
19
  ### distributed under the Apache License with the above modification is
20
20
  ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
21
  ### KIND, either express or implied. See the Apache License for the specific
22
22
  ### language governing permissions and limitations under the Apache License.
23
- ###
23
+ ###
24
24
  ###
25
25
 
26
26
  ###
27
27
  module JSS
28
-
28
+
29
29
  #####################################
30
30
  ### Module Variables
31
31
  #####################################
@@ -33,25 +33,25 @@ module JSS
33
33
  #####################################
34
34
  ### Module Methods
35
35
  #####################################
36
-
36
+
37
37
  #####################################
38
38
  ### Classes
39
39
  #####################################
40
40
 
41
- ###
41
+ ###
42
42
  ### A department in the JSS.
43
43
  ### These are simple, in that they only have an ID and a name
44
44
  ###
45
45
  ### @see JSS::APIObject
46
46
  ###
47
47
  class Department < JSS::APIObject
48
-
48
+
49
49
  #####################################
50
50
  ### Mix-Ins
51
51
  #####################################
52
52
  include JSS::Creatable
53
53
  include JSS::Updatable
54
-
54
+
55
55
  #####################################
56
56
  ### Class Methods
57
57
  #####################################
@@ -59,28 +59,33 @@ module JSS
59
59
  #####################################
60
60
  ### Class Constants
61
61
  #####################################
62
-
62
+
63
63
  ### The base for REST resources of this class
64
64
  RSRC_BASE = "departments"
65
-
65
+
66
66
  ### the hash key used for the JSON list output of all objects in the JSS
67
67
  RSRC_LIST_KEY = :departments
68
-
68
+
69
69
  ### The hash key used for the JSON object output.
70
70
  ### It's also used in various error messages
71
71
  RSRC_OBJECT_KEY = :department
72
-
72
+
73
73
  ### these keys, as well as :id and :name, are present in valid API JSON data for this class
74
74
  VALID_DATA_KEYS = []
75
-
75
+
76
+ # the object type for this object in
77
+ # the object history table.
78
+ # See {APIObject#add_object_history_entry}
79
+ OBJECT_HISTORY_OBJECT_TYPE = 42
80
+
76
81
  #####################################
77
82
  ### Attributes
78
83
  #####################################
79
-
84
+
80
85
  #####################################
81
- ### Constructor
86
+ ### Constructor
82
87
  #####################################
83
-
88
+
84
89
  ###
85
90
  ### See JSS::APIObject#initialize
86
91
  ###
@@ -88,7 +93,7 @@ module JSS
88
93
  #####################################
89
94
  ### Public Instance Methods
90
95
  #####################################
91
-
96
+
92
97
  end # class department
93
-
98
+
94
99
  end # module
@@ -85,6 +85,11 @@ module JSS
85
85
 
86
86
  DEFAULT_MOUNTPOINT_PREFIX = "CasperDistribution-id"
87
87
 
88
+ # the object type for this object in
89
+ # the object history table.
90
+ # See {APIObject#add_object_history_entry}
91
+ OBJECT_HISTORY_OBJECT_TYPE = 76
92
+
88
93
  ### Class Methods
89
94
  #####################################
90
95
 
@@ -16,6 +16,11 @@ module JSS
16
16
  ### It's also used in various error messages
17
17
  RSRC_OBJECT_KEY = :ebook
18
18
 
19
+ # the object type for this object in
20
+ # the object history table.
21
+ # See {APIObject#add_object_history_entry}
22
+ OBJECT_HISTORY_OBJECT_TYPE = 24
23
+
19
24
  end
20
25
 
21
26
  end
@@ -1,119 +1,97 @@
1
- ### Copyright 2017 Pixar
2
-
3
- ###
4
- ### Licensed under the Apache License, Version 2.0 (the "Apache License")
5
- ### with the following modification; you may not use this file except in
6
- ### compliance with the Apache License and the following modification to it:
7
- ### Section 6. Trademarks. is deleted and replaced with:
8
- ###
9
- ### 6. Trademarks. This License does not grant permission to use the trade
10
- ### names, trademarks, service marks, or product names of the Licensor
11
- ### and its affiliates, except as required to comply with Section 4(c) of
12
- ### the License and to reproduce the content of the NOTICE file.
13
- ###
14
- ### You may obtain a copy of the Apache License at
15
- ###
16
- ### http://www.apache.org/licenses/LICENSE-2.0
17
- ###
18
- ### Unless required by applicable law or agreed to in writing, software
19
- ### distributed under the Apache License with the above modification is
20
- ### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
- ### KIND, either express or implied. See the Apache License for the specific
22
- ### language governing permissions and limitations under the Apache License.
23
- ###
24
- ###
25
-
26
- ###
1
+ # Copyright 2017 Pixar
2
+
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "Apache License")
5
+ # with the following modification; you may not use this file except in
6
+ # compliance with the Apache License and the following modification to it:
7
+ # Section 6. Trademarks. is deleted and replaced with:
8
+ #
9
+ # 6. Trademarks. This License does not grant permission to use the trade
10
+ # names, trademarks, service marks, or product names of the Licensor
11
+ # and its affiliates, except as required to comply with Section 4(c) of
12
+ # the License and to reproduce the content of the NOTICE file.
13
+ #
14
+ # You may obtain a copy of the Apache License at
15
+ #
16
+ # http://www.apache.org/licenses/LICENSE-2.0
17
+ #
18
+ # Unless required by applicable law or agreed to in writing, software
19
+ # distributed under the Apache License with the above modification is
20
+ # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21
+ # KIND, either express or implied. See the Apache License for the specific
22
+ # language governing permissions and limitations under the Apache License.
23
+ #
24
+ #
25
+
26
+ #
27
27
  module JSS
28
28
 
29
- #####################################
30
- ### Module Variables
31
- #####################################
32
-
33
- #####################################
34
- ### Module Methods
35
- #####################################
36
-
37
- #####################################
38
- ### Sub-Modules
39
- #####################################
40
-
41
- ### A mix-in module for handling extension attribute data for objects in the JSS.
42
- ###
43
- ### This module provides standardized ways to deal with Extension Attribute data
44
- ### in objects that gather that data ({JSS::Computer}s, {JSS::MobileDevice}s,
45
- ### and {JSS::User}s). For working with the Extension Attributes themselves, see
46
- ### {JSS::ExtensionAttribute} and its subclasses.
47
- ###
48
- ### API objects that have Extension Attribute data return it in an Array of Hashes,
49
- ### one for each defined ExtensionAttribute for the class;
50
- ### i.e. a {JSS::Computer}'s Array has one Hash for each {JSS::ComputerExtensionAttribute}
51
- ### defined in the JSS.
52
- ###
53
- ### The Hash keys are:
54
- ### * :id => the ExtAttr id
55
- ### * :name => the ExtAttr name
56
- ### * :type => the data type of the ExtAttr value
57
- ### * :value => the value for the ExtAttr for this object as of the last report.
58
- ###
59
- ### Classes including this module must define the constant EXT_ATTRIB_CLASS
60
- ### specifying which {JSS::ExtensionAttribute} subclass defines the relevant extension attributes.
61
- ### For Example, {JSS::Computer} sets this:
62
- ### EXT_ATTRIB_CLASS = JSS::ComputerExtensionAttribute
63
- ###
64
- ###
65
- ### Parsing also populates @ext_attrs which is a Hash of name => value for each EA.
66
- ###
67
- ### When updating or creating, those classes must add the REXML output of {#ext_attr_xml} to their
68
- ### rest_xml output.
69
- ###
29
+ # Sub-Modules
30
+ ###################################
31
+
32
+ # A mix-in module for handling extension attribute data for objects in the JSS.
33
+ #
34
+ # This module provides standardized ways to deal with Extension Attribute data
35
+ # in objects that gather that data ({JSS::Computer}s, {JSS::MobileDevice}s,
36
+ # and {JSS::User}s). For working with the Extension Attributes themselves, see
37
+ # {JSS::ExtensionAttribute} and its subclasses.
38
+ #
39
+ # API objects that have Extension Attribute data return it in an Array of Hashes,
40
+ # one for each defined ExtensionAttribute for the class;
41
+ # i.e. a {JSS::Computer}'s Array has one Hash for each {JSS::ComputerExtensionAttribute}
42
+ # defined in the JSS.
43
+ #
44
+ # The Hash keys are:
45
+ # * :id => the ExtAttr id
46
+ # * :name => the ExtAttr name
47
+ # * :type => the data type of the ExtAttr value
48
+ # * :value => the value for the ExtAttr for this object as of the last report.
49
+ #
50
+ # Classes including this module must define the constant EXT_ATTRIB_CLASS
51
+ # specifying which {JSS::ExtensionAttribute} subclass defines the relevant extension attributes.
52
+ # For Example, {JSS::Computer} sets this:
53
+ # EXT_ATTRIB_CLASS = JSS::ComputerExtensionAttribute
54
+ #
55
+ #
56
+ # Parsing also populates @ext_attrs which is a Hash of name => value for each EA.
57
+ #
58
+ # When updating or creating, those classes must add the REXML output of {#ext_attr_xml} to their
59
+ # rest_xml output.
60
+ #
70
61
  module Extendable
71
62
 
72
- #####################################
73
- ### Constants
74
- #####################################
63
+ # Constants
64
+ ###################################
75
65
 
76
- ###
77
66
  EXTENDABLE = true
78
67
 
68
+ # ExtensionAttributes refer to the numeric data type as "Integer"
69
+ # but the ext. attr values that come with extendable objects refer to
70
+ # that data type as "Number". Here's an array with both, so we can
71
+ # work with ether more easily.
72
+ NUMERIC_TYPES = %w[Number Integer].freeze
79
73
 
80
- ### ExtensionAttributes refer to the numeric data type as "Integer"
81
- ### but the ext. attr values that come with extendable objects refer to
82
- ### that data type as "Number". Here's an array with both, so we can
83
- ### work with ether more easily.
84
- NUMERIC_TYPES = ["Number", "Integer"]
74
+ # Attribtues
75
+ ###################################
85
76
 
86
- #####################################
87
- ### Variables
88
- #####################################
89
-
90
- #####################################
91
- ### Attribtues
92
- #####################################
93
-
94
- ### @return [Array<Hash>] The extension attribute values for the object
77
+ # @return [Array<Hash>] The extension attribute values for the object
95
78
  attr_reader :extension_attributes
96
79
 
97
- ### @return [Hash] A mapping of Ext Attrib names to their values
80
+ # @return [Hash] A mapping of Ext Attrib names to their values
98
81
  attr_reader :ext_attrs
99
82
 
100
- #####################################
101
- ### Mixed-in Instance Methods
102
- #####################################
103
-
104
-
105
-
106
- ###
107
- ### Populate @extension_attributes (the Array of Hashes that comes from the API)
108
- ### and @ext_attr_names, which is a Hash mapping the EA names to their
109
- ### index in the @extension_attributes Array.
110
- ###
111
- ### Classes including this module should call this in #initialize
112
- ###
113
- ### @return [void]
114
- ###
83
+ # Mixed-in Instance Methods
84
+ ###################################
85
+
86
+ # Populate @extension_attributes (the Array of Hashes that comes from the API)
87
+ # and @ext_attr_names, which is a Hash mapping the EA names to their
88
+ # index in the @extension_attributes Array.
89
+ #
90
+ # Classes including this module should call this in #initialize
91
+ #
92
+ # @return [void]
93
+ #
115
94
  def parse_ext_attrs
116
-
117
95
  unless @init_data[:extension_attributes]
118
96
  @extension_attributes = []
119
97
  @ext_attrs = {}
@@ -126,83 +104,79 @@ module JSS
126
104
  @extension_attributes.each do |ea|
127
105
  case ea[:type]
128
106
 
129
- when "Date"
130
- begin # if there's random non-date data, the parse will fail
131
- ea[:value] = JSS.parse_datetime ea[:value]
132
- rescue
133
- end
107
+ when 'Date'
108
+ begin # if there's random non-date data, the parse will fail
109
+ ea[:value] = JSS.parse_datetime ea[:value]
110
+ rescue
111
+ end
134
112
 
135
- when *NUMERIC_TYPES
136
- ea[:value] = ea[:value].to_i unless ea[:value].to_s.empty?
113
+ when *NUMERIC_TYPES
114
+ ea[:value] = ea[:value].to_i unless ea[:value].to_s.empty?
137
115
  end # case
138
116
 
139
117
  @ext_attrs[ea[:name]] = ea[:value]
140
-
141
118
  end # each do ea
142
119
 
143
120
  # remember changes as they happen so
144
121
  # we only send changes back to the server.
145
122
  @changed_eas = []
146
-
147
123
  end
148
124
 
149
- ###
150
- ### Set the value of an extension attribute
151
- ###
152
- ### If the extension attribute is defined as a popup menu, the value must be one of the
153
- ### defined popup choices.
154
- ###
155
- ### If the ext. attrib. is defined with a data type of Integer, the value must be an Integer.
156
- ###
157
- ### If the ext. attrib. is defined with a data type of Date, the value will be converted to a Time
158
- ###
159
- ### @param name[String] the name of the extension attribute to set
160
- ###
161
- ### @param value[String,Time,Time,Integer] the new value for the extension attribute for this user
162
- ###
163
- ### @return [void]
164
- ###
125
+ # Set the value of an extension attribute
126
+ #
127
+ # If the extension attribute is defined as a popup menu, the value must be one of the
128
+ # defined popup choices, or an empty string
129
+ #
130
+ # If the ext. attrib. is defined with a data type of Integer, the value must be an Integer.
131
+ #
132
+ # If the ext. attrib. is defined with a data type of Date, the value will be converted to a Time
133
+ #
134
+ # Note that while the Jamf Pro Web interface does not allow editing the values of
135
+ # Extension Attributes populated by Scripts or LDAP, the API does allow it.
136
+ # Bear in mind however that those values will be reset again at the next recon.
137
+ #
138
+ # @param name[String] the name of the extension attribute to set
139
+ #
140
+ # @param value[String,Time,Time,Integer] the new value for the extension attribute for this user
141
+ #
142
+ # @return [void]
143
+ #
165
144
  def set_ext_attr(name, value)
166
-
167
145
  # if we don't currently have any need to update(cuz we have recently), reset the list of changes to push
168
146
  @changed_eas = [] unless @need_to_update
169
147
 
170
148
  # this will raise an exception if the name doesn't exist
171
- ea_def = self.class::EXT_ATTRIB_CLASS.new :name => name
149
+ ea_def = self.class::EXT_ATTRIB_CLASS.new name: name
172
150
 
173
- unless JSS::ExtensionAttribute::EDITABLE_INPUT_TYPES.include? ea_def.input_type
174
- raise JSS::UnsupportedError, "The value for #{name} cannot be modified. It is gathered during inventory updates."
175
- end
176
-
177
- if ea_def.input_type == "Pop-up Menu" and (not ea_def.popup_choices.include? value.to_s)
151
+ if ea_def.input_type == 'Pop-up Menu' && (!ea_def.popup_choices.include? value.to_s)
178
152
  raise JSS::UnsupportedError, "The value for #{name} must be one of: '#{ea_def.popup_choices.join("' '")}'"
179
153
  end
180
154
 
181
- case ea_def.data_type
182
- when "Date"
183
-
155
+ unless value == JSS::BLANK
156
+ case ea_def.data_type
157
+ when 'Date'
184
158
  value = JSS.parse_datetime value
185
159
 
186
160
  when *NUMERIC_TYPES
187
- raise JSS::InvalidDataError, "The value for #{name} must be an integer" unless value.kind_of? Integer
161
+ raise JSS::InvalidDataError, "The value for #{name} must be an integer" unless value.is_a? Integer
188
162
 
189
- end #case
163
+ end # case
164
+ end # unless blank
190
165
 
191
166
  @extension_attributes.each do |ea|
192
167
  ea[:value] = value if ea[:name] == name
193
168
  end
169
+
194
170
  @ext_attrs[name] = value
195
171
  @changed_eas << name
196
172
  @need_to_update = true
197
-
198
173
  end
199
174
 
200
- ###
201
- ### @api private
202
- ###
203
- ### @return [REXML::Element] An <extension_attribute> element to be
204
- ### included in the rest_xml of objects that mix-in this module.
205
- ###
175
+ # @api private
176
+ #
177
+ # @return [REXML::Element] An <extension_attribute> element to be
178
+ # included in the rest_xml of objects that mix-in this module.
179
+ #
206
180
  def ext_attr_xml
207
181
  @changed_eas ||= []
208
182
  eaxml = REXML::Element.new('extension_attributes')
@@ -211,7 +185,7 @@ module JSS
211
185
  ea_el = eaxml.add_element('extension_attribute')
212
186
  ea_el.add_element('name').text = ea[:name]
213
187
 
214
- if ea[:type] == "Date"
188
+ if ea[:type] == 'Date'
215
189
  begin
216
190
  ea_el.add_element('value').text = ea[:value].to_jss_date
217
191
  rescue
@@ -222,8 +196,9 @@ module JSS
222
196
  end # if
223
197
  end # each do ea
224
198
 
225
- return eaxml
199
+ eaxml
226
200
  end
227
201
 
228
202
  end # module Purchasable
203
+
229
204
  end # module JSS