ruby-jss 1.2.4a2 → 1.2.4a3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jamf.rb +8 -1
  3. data/lib/jamf/api/abstract_classes/advanced_search.rb +86 -0
  4. data/lib/jamf/api/abstract_classes/collection_resource.rb +3 -8
  5. data/lib/jamf/api/abstract_classes/json_object.rb +11 -5
  6. data/lib/jamf/api/abstract_classes/prestage.rb +189 -6
  7. data/lib/jamf/api/abstract_classes/resource.rb +8 -3
  8. data/lib/jamf/api/connection.rb +19 -9
  9. data/lib/jamf/api/json_objects/criterion.rb +152 -0
  10. data/lib/jamf/api/json_objects/device_enrollment_device.rb +156 -0
  11. data/lib/jamf/api/json_objects/device_enrollment_sync_status.rb +71 -0
  12. data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +6 -1
  13. data/lib/jamf/api/json_objects/prestage_assignment.rb +15 -2
  14. data/lib/jamf/api/json_objects/prestage_scope.rb +5 -2
  15. data/lib/jamf/api/mixins/immutable.rb +1 -1
  16. data/lib/jamf/api/mixins/lockable.rb +9 -1
  17. data/lib/jamf/api/resources/collection_resources/advanced_mobile_device_search.rb +52 -0
  18. data/lib/jamf/api/resources/collection_resources/advanced_user_search.rb +52 -0
  19. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +3 -1
  20. data/lib/jamf/api/resources/collection_resources/device_enrollment.rb +292 -0
  21. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +7 -7
  22. data/lib/jamf/api/resources/collection_resources/{md_prestage.rb → mobile_device_prestage.rb} +5 -3
  23. data/lib/jamf/exceptions.rb +5 -0
  24. data/lib/jamf/ruby_extensions/array/utils.rb +26 -12
  25. data/lib/jamf/version.rb +1 -1
  26. data/lib/jss/api_object/criteriable/criterion.rb +0 -1
  27. data/lib/jss/version.rb +1 -1
  28. metadata +10 -3
@@ -29,7 +29,11 @@ module Jamf
29
29
  # Classes
30
30
  #####################################
31
31
  class InventoryPreloadExtensionAttribute < Jamf::JSONObject
32
- OBJECT_MODEL= {
32
+
33
+ OBJECT_MODEL = {
34
+
35
+ # TODO: validation for ea's existance and value data type, once EAs are
36
+ # implemented in JPAPI
33
37
 
34
38
  # @!attribute name
35
39
  # @return [String]
@@ -47,6 +51,7 @@ module Jamf
47
51
  }.freeze
48
52
 
49
53
  parse_object_model
54
+
50
55
  end # class
51
56
 
52
57
  end # module
@@ -29,6 +29,8 @@ module Jamf
29
29
  # A 'location' for a managed object in Jamf Pro
30
30
  class PrestageAssignment < Jamf::JSONObject
31
31
 
32
+ extend Jamf::Immutable
33
+
32
34
  OBJECT_MODEL = {
33
35
 
34
36
  # @!attribute serialNumber
@@ -52,8 +54,19 @@ module Jamf
52
54
 
53
55
  parse_object_model
54
56
 
55
- def assignmentTimestamp
56
- @assignmentTimestamp ||= Jamf::Timestamp.new @assignmentEpoch
57
+ # The assignment epoch as a Jamf::Timestamp object.
58
+ #
59
+ # NOTE: I expct this will go away once Jamf conforms to its own standard
60
+ # of exchanging ALL timestamp data as ISO6801 strings. At that time
61
+ # the assignment epoch won't be a thing anymore.
62
+ #
63
+ # @return [Jamf::Timestamp]
64
+ #
65
+ attr_reader :assignmentTimestamp
66
+
67
+ def initialize(*args)
68
+ super
69
+ @assignmentTimestamp = Jamf::Timestamp.new @assignmentEpoch
57
70
  end
58
71
 
59
72
  end # class Country
@@ -26,9 +26,12 @@
26
26
  # The module
27
27
  module Jamf
28
28
 
29
- # A 'location' for a managed object in Jamf Pro
29
+ # A container for an array of Jamf::PrestageAssignment
30
+ # objects, each of which represents a serial number assigned to the
31
+ # prestage that contains this scope.
30
32
  class PrestageScope < Jamf::JSONObject
31
33
 
34
+ extend Jamf::Immutable
32
35
  include Jamf::Lockable
33
36
 
34
37
  OBJECT_MODEL = {
@@ -49,6 +52,6 @@ module Jamf
49
52
 
50
53
  parse_object_model
51
54
 
52
- end # class Country
55
+ end # class PrestageScope
53
56
 
54
57
  end # module
@@ -24,7 +24,7 @@
24
24
 
25
25
  module Jamf
26
26
 
27
- # This mixin overrides JSONObject.mutable? to return false,
27
+ # When extended with this mixin, JSONObject.mutable? returns false,
28
28
  # meaning that no setters are ever defined, and if the
29
29
  # object is a Jamf::Resource, #save will raise an error
30
30
  #
@@ -33,16 +33,24 @@ module Jamf
33
33
  # from elsewhere since we fetched it, and a 409 Conflict error is raised with
34
34
  # the reason OPTIMISTIC_LOCK_FAILED.
35
35
  #
36
- # If that happens, the save doesnt happen, the object is re-fetched,
36
+ # If that happens, the save doesnt happen, the object must be re-fetched,
37
37
  # and the user can try again.
38
38
  #
39
39
  module Lockable
40
40
 
41
+ attr_reader :versionLock
42
+
41
43
  def initialize(data, cnx: Jamf.cnx)
42
44
  @versionLock = data[:versionLock]
43
45
  super
44
46
  end
45
47
 
48
+ def to_jamf
49
+ data = super
50
+ data[:versionLock] = @versionLock
51
+ data
52
+ end
53
+
46
54
  end # Lockable
47
55
 
48
56
  end # Jamf
@@ -0,0 +1,52 @@
1
+ # Copyright 2019 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
+ # The Module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # A Computer Prestage
33
+ class AdvancedMobileDeviceSearch < Jamf::AdvancedSearch
34
+
35
+ # Constants
36
+ #####################################
37
+
38
+ RSRC_VERSION = 'v1'.freeze
39
+
40
+ RSRC_PATH = 'advanced-mobile-device-searches'.freeze
41
+
42
+ # Object Model / Attributes
43
+ # See APIObject class documentation for details
44
+ # of how the OBJECT_MODEL hash works.
45
+ #####################################
46
+ OBJECT_MODEL = superclass::OBJECT_MODEL
47
+
48
+ parse_object_model
49
+
50
+ end # class
51
+
52
+ end # module
@@ -0,0 +1,52 @@
1
+ # Copyright 2019 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
+ # The Module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # A Computer Prestage
33
+ class AdvancedUserSearch < Jamf::AdvancedSearch
34
+
35
+ # Constants
36
+ #####################################
37
+
38
+ RSRC_VERSION = 'v1'.freeze
39
+
40
+ RSRC_PATH = 'advanced-user-content-searches'.freeze
41
+
42
+ # Object Model / Attributes
43
+ # See APIObject class documentation for details
44
+ # of how the OBJECT_MODEL hash works.
45
+ #####################################
46
+ OBJECT_MODEL = superclass::OBJECT_MODEL
47
+
48
+ parse_object_model
49
+
50
+ end # class
51
+
52
+ end # module
@@ -70,11 +70,13 @@ module Jamf
70
70
  class: :integer,
71
71
  multi: true
72
72
  }
73
-
74
73
  ).freeze
75
74
 
76
75
  parse_object_model
77
76
 
77
+ # Class Methods
78
+ ###############################################
79
+
78
80
  end # class
79
81
 
80
82
  end # module
@@ -0,0 +1,292 @@
1
+ # Copyright 2019 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
+ # The Module
27
+ module Jamf
28
+
29
+ # Classes
30
+ #####################################
31
+
32
+ # A decvice enrollment defined in the Jamf Pro.
33
+ #
34
+ # This is a connection to Apple's Device Enrollment Program.
35
+ # A single Jamf server may have many of them, and they can belong to
36
+ # different sites.
37
+ #
38
+ # These objects can be used to find the details of all the devices
39
+ # connected to them, including the device serial numbers.
40
+ # To see how or if those devices are assigned to prestages, see
41
+ # Jamf::Prestage and its subclasses ComputerPrestage and MobileDevicePrestage
42
+ #
43
+ class DeviceEnrollment < Jamf::CollectionResource
44
+
45
+ # Mix-Ins
46
+ #####################################
47
+
48
+ include Jamf::ChangeLog
49
+
50
+ # Constants
51
+ #####################################
52
+
53
+ RSRC_VERSION = 'v1'.freeze
54
+
55
+ RSRC_PATH = 'device-enrollment'.freeze
56
+
57
+ # Object Model / Attributes
58
+ # See APIObject class documentation for details
59
+ # of how the OBJECT_MODEL hash works.
60
+ #####################################
61
+ OBJECT_MODEL = {
62
+
63
+ # @!attribute id
64
+ # @return [Integer]
65
+ id: {
66
+ class: :integer,
67
+ identifier: :primary,
68
+ readonly: true
69
+ },
70
+
71
+ # @!attribute name
72
+ # @return [String]
73
+ name: {
74
+ class: :string,
75
+ identifier: true
76
+ },
77
+
78
+ # @!attribute supervisionIdentityId
79
+ # @return [Integer]
80
+ supervisionIdentityId: {
81
+ class: :integer
82
+ },
83
+
84
+ # @!attribute siteId
85
+ # @return [Integer]
86
+ siteId: {
87
+ class: :integer
88
+ },
89
+
90
+ # @!attribute serverName
91
+ # @return [String]
92
+ serverName: {
93
+ class: :string
94
+ },
95
+
96
+ # @!attribute serverUuid
97
+ # @return [String]
98
+ serverUuid: {
99
+ class: :string
100
+ },
101
+
102
+ # @!attribute adminId
103
+ # @return [String]
104
+ adminId: {
105
+ class: :string
106
+ },
107
+
108
+ # @!attribute orgName
109
+ # @return [String]
110
+ orgName: {
111
+ class: :string
112
+ },
113
+
114
+ # @!attribute orgEmail
115
+ # @return [String]
116
+ orgEmail: {
117
+ class: :string
118
+ },
119
+
120
+ # @!attribute orgPhone
121
+ # @return [String]
122
+ orgPhone: {
123
+ class: :string
124
+ },
125
+
126
+ # @!attribute orgAddress
127
+ # @return [String]
128
+ orgAddress: {
129
+ class: :string
130
+ },
131
+
132
+ # @!attribute tokenExpirationDate
133
+ # @return [Jamf::Timestamp]
134
+ tokenExpirationDate: {
135
+ class: Jamf::Timestamp
136
+ }
137
+ }.freeze
138
+
139
+ parse_object_model
140
+
141
+ DEVICES_RSRC = 'devices'.freeze
142
+
143
+ SYNC_RSRC = 'sync'.freeze
144
+
145
+ LATEST_RSRC = 'latest'.freeze
146
+
147
+ TYPES = %i[computers mobiledevices].freeze
148
+
149
+ COMPUTERS_RE = /mac/i.freeze
150
+
151
+ # Class Methods
152
+ #########################################
153
+
154
+ # All devices associated by Apple with a given DeviceEnrollment instance
155
+ # or all defined DeviceEnrollment instances
156
+ #
157
+ # @param instance_ident[Integer, String] the id or name of the
158
+ # DeviceEnrollment instance for which to list the devices. If omitted,
159
+ # the devices for all instances will be returned.
160
+ #
161
+ # @param type[Symbol] Either :computers or :mobiledevices, returns both if
162
+ # not specified.
163
+ #
164
+ # @param cnx[Jamf::Connection] The API connection to use
165
+ #
166
+ # @return [Array<Jamf::DeviceEnrollmentDevice>] The devices associated with
167
+ # the given, or all, instances
168
+ #
169
+ def self.devices(instance_ident = nil, type: nil, cnx: Jamf.cnx)
170
+ if type
171
+ raise ArgumentError, "Type must be one of: :#{TYPES.join ', :'}" unless TYPES.include? type
172
+ end
173
+
174
+ devs = fetch_devices(instance_ident, cnx)
175
+ return devs unless type
176
+
177
+ if type == :computers
178
+ devs.select { |d| d.model =~ COMPUTERS_RE }
179
+ else
180
+ devs.reject { |d| d.model =~ COMPUTERS_RE }
181
+ end
182
+ end
183
+
184
+ # See .devices
185
+ # @return [Array<String>] just the serial numbers for the devices
186
+ #
187
+ def self.device_sns(instance_ident = nil, type: nil, cnx: Jamf.cnx)
188
+ devices(instance_ident, type: type, cnx: cnx).map(&:serialNumber)
189
+ end
190
+
191
+ # See .devices
192
+ #
193
+ # @return [Boolean] is the given SN in a given DeviceEnrollment instance
194
+ # or in DEP at all?
195
+ #
196
+ def self.include?(sn, instance_ident = nil, type: nil, cnx: Jamf.cnx)
197
+ device_sns(instance_ident, type: type, cnx: cnx).j_ci_include? sn
198
+ end
199
+
200
+ # See .devices
201
+ # Returns just those devices with the desired profileStatus, which must be
202
+ # an item in DeviceEnrollmentDevice::PROFILE_STATUSES
203
+ #
204
+ # @param status[String] A member of DeviceEnrollmentDevice::PROFILE_STATUSES
205
+ #
206
+ # @return [Array<Jamf::DeviceEnrollmentDevice>] The devices with the desired
207
+ # status, associated with the given, or all, instances
208
+ #
209
+ def self.devices_with_status(status, instance_ident = nil, type: nil, cnx: Jamf.cnx)
210
+ unless Jamf::DeviceEnrollmentDevice::PROFILE_STATUSES.include? status
211
+ raise ArgumentError, "profileStatus must be one of: '#{Jamf::DeviceEnrollmentDevice::PROFILE_STATUSES.join "', '"}'"
212
+ end
213
+
214
+ devices(instance_ident, type: type, cnx: cnx).select { |d| d.profileStatus == status }
215
+ end
216
+
217
+ #
218
+ def self.sync_history(instance_ident = nil, latest = false, cnx: Jamf.cnx)
219
+ if instance_ident
220
+ instance_id = valid_id instance_ident, cnx: cnx
221
+ raise Jamf::NoSuchItemError "No DeviceEnrollment instance matches '#{instance_ident}'" unless instance_id
222
+
223
+ rsrc = "#{RSRC_VERSION}/#{RSRC_PATH}/#{SYNC_RSRC}/#{instance_id}"
224
+ rsrc += "/#{LATEST_RSRC}" if latest
225
+ else
226
+ rsrc = "#{RSRC_VERSION}/#{RSRC_PATH}/#{SYNC_RSRC}"
227
+ end
228
+ data = cnx.get rsrc
229
+
230
+ return Jamf::DeviceEnrollmentSyncStatus.new data if data.is_a? Hash
231
+
232
+ data.map! { |s| Jamf::DeviceEnrollmentSyncStatus.new s }
233
+ end
234
+
235
+ # Private Class Methods
236
+ ###############################################
237
+
238
+ # Private, used by the .devices class method
239
+ def self.fetch_devices(instance_ident, cnx)
240
+ if instance_ident
241
+ instance_id = valid_id instance_ident, cnx: cnx
242
+ raise Jamf::NoSuchItemError "No DeviceEnrollment instance matches '#{instance_ident}'" unless instance_id
243
+
244
+ devs = devices_for_instance_id instance_id, cnx
245
+ else
246
+ devs = []
247
+ all_ids.each do |id|
248
+ devs += devices_for_instance_id id, cnx
249
+ end
250
+ end
251
+ devs
252
+ end
253
+ private_class_method :fetch_devices
254
+
255
+ # Private, used by the .devices class method
256
+ def self.devices_for_instance_id(instance_id, cnx)
257
+ data = cnx.get("#{RSRC_VERSION}/#{RSRC_PATH}/#{instance_id}/#{DEVICES_RSRC}")[:results]
258
+
259
+ data.map { |dev| Jamf::DeviceEnrollmentDevice.new dev }
260
+ end
261
+ private_class_method :devices_for_instance_id
262
+
263
+ # Instance Methods
264
+ #########################################
265
+
266
+ def devices(type: nil)
267
+ self.class.devices @id, type: type, cnx: @cnx
268
+ end
269
+
270
+ def device_sns(type: nil)
271
+ devices(type: type).map(&:serialNumber)
272
+ end
273
+
274
+ def include?(sn, type: nil)
275
+ device_sns(type: type).j_ci_include? sn
276
+ end
277
+
278
+ def devices_with_status(status, type: nil)
279
+ self.class.devices_with_status(status, @id, type: type, cnx: @cnx)
280
+ end
281
+
282
+ def sync_history(latest = false)
283
+ self.class.sync_history(@id, latest, cnx: @cnx)
284
+ end
285
+
286
+ def latest_sync
287
+ sync_history :latest
288
+ end
289
+
290
+ end # class
291
+
292
+ end # module