ruby-jss 1.2.3 → 1.2.4a1

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.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jamf.rb +169 -0
  3. data/lib/jamf/api/abstract_classes/collection_resource.rb +422 -0
  4. data/lib/jamf/api/abstract_classes/generic_reference.rb +145 -0
  5. data/lib/jamf/api/abstract_classes/json_object.rb +1074 -0
  6. data/lib/jamf/api/abstract_classes/prestage.rb +219 -0
  7. data/lib/jamf/api/abstract_classes/prestage_skip_setup_items.rb +126 -0
  8. data/lib/jamf/api/abstract_classes/resource.rb +250 -0
  9. data/lib/jamf/api/abstract_classes/singleton_resource.rb +87 -0
  10. data/lib/jamf/api/attribute_classes/ip_address.rb +66 -0
  11. data/lib/jamf/api/attribute_classes/timestamp.rb +144 -0
  12. data/lib/jamf/api/connection.rb +734 -0
  13. data/lib/jamf/api/connection/api_error.rb +111 -0
  14. data/lib/jamf/api/connection/api_error_styleguide.rb +96 -0
  15. data/lib/jamf/api/connection/token.rb +220 -0
  16. data/lib/jamf/api/json_objects/account_prefs.rb +79 -0
  17. data/lib/jamf/api/json_objects/android_details.rb +139 -0
  18. data/lib/jamf/api/json_objects/appletv_details.rb +110 -0
  19. data/lib/jamf/api/json_objects/attachment.rb +68 -0
  20. data/lib/jamf/api/json_objects/cellular_network.rb +151 -0
  21. data/lib/jamf/api/json_objects/change_log_entry.rb +77 -0
  22. data/lib/jamf/api/json_objects/computer_prestage_skip_setup_items.rb +67 -0
  23. data/lib/jamf/api/json_objects/country.rb +51 -0
  24. data/lib/jamf/api/json_objects/extension_attribute_value.rb +128 -0
  25. data/lib/jamf/api/json_objects/installed_application.rb +59 -0
  26. data/lib/jamf/api/json_objects/installed_certificate.rb +53 -0
  27. data/lib/jamf/api/json_objects/installed_configuration_profile.rb +67 -0
  28. data/lib/jamf/api/json_objects/installed_ebook.rb +58 -0
  29. data/lib/jamf/api/json_objects/installed_provisioning_profile.rb +59 -0
  30. data/lib/jamf/api/json_objects/inventory_preload_extension_attribute.rb +52 -0
  31. data/lib/jamf/api/json_objects/ios_details.rb +244 -0
  32. data/lib/jamf/api/json_objects/location.rb +95 -0
  33. data/lib/jamf/api/json_objects/md_prestage_name.rb +57 -0
  34. data/lib/jamf/api/json_objects/md_prestage_names.rb +82 -0
  35. data/lib/jamf/api/json_objects/md_prestage_skip_setup_items.rb +165 -0
  36. data/lib/jamf/api/json_objects/mobile_device_details.rb +219 -0
  37. data/lib/jamf/api/json_objects/mobile_device_security.rb +101 -0
  38. data/lib/jamf/api/json_objects/prestage_assignment.rb +61 -0
  39. data/lib/jamf/api/json_objects/prestage_location.rb +104 -0
  40. data/lib/jamf/api/json_objects/prestage_purchasing_data.rb +132 -0
  41. data/lib/jamf/api/json_objects/prestage_scope.rb +54 -0
  42. data/lib/jamf/api/json_objects/prestage_sync_status.rb +63 -0
  43. data/lib/jamf/api/json_objects/purchasing_data.rb +125 -0
  44. data/lib/jamf/api/mixins/abstract.rb +58 -0
  45. data/lib/jamf/api/mixins/bulk_deletable.rb +39 -0
  46. data/lib/jamf/api/mixins/change_log.rb +136 -0
  47. data/lib/jamf/api/mixins/extendable.rb +75 -0
  48. data/lib/jamf/api/mixins/immutable.rb +39 -0
  49. data/lib/jamf/api/mixins/locatable.rb +124 -0
  50. data/lib/jamf/api/mixins/lockable.rb +48 -0
  51. data/lib/jamf/api/mixins/referable.rb +92 -0
  52. data/lib/jamf/api/mixins/searchable.rb +202 -0
  53. data/lib/jamf/api/mixins/uncreatable.rb +40 -0
  54. data/lib/jamf/api/mixins/undeletable.rb +40 -0
  55. data/lib/jamf/api/resources/collection_resources/account.rb +163 -0
  56. data/lib/jamf/api/resources/collection_resources/building.rb +114 -0
  57. data/lib/jamf/api/resources/collection_resources/category.rb +82 -0
  58. data/lib/jamf/api/resources/collection_resources/computer.rb +49 -0
  59. data/lib/jamf/api/resources/collection_resources/computer_prestage.rb +80 -0
  60. data/lib/jamf/api/resources/collection_resources/department.rb +79 -0
  61. data/lib/jamf/api/resources/collection_resources/extension_attribute.rb +45 -0
  62. data/lib/jamf/api/resources/collection_resources/inventory_preload_record.rb +274 -0
  63. data/lib/jamf/api/resources/collection_resources/md_prestage.rb +139 -0
  64. data/lib/jamf/api/resources/collection_resources/mobile_device.rb +315 -0
  65. data/lib/jamf/api/resources/collection_resources/script.rb +190 -0
  66. data/lib/jamf/api/resources/collection_resources/site.rb +77 -0
  67. data/lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb +131 -0
  68. data/lib/jamf/api/resources/singleton_resources/authorization.rb +88 -0
  69. data/lib/jamf/api/resources/singleton_resources/client_checkin_settings.rb +139 -0
  70. data/lib/jamf/api/resources/singleton_resources/reenrollment_settings.rb +95 -0
  71. data/lib/jamf/client.rb +301 -0
  72. data/lib/jamf/client/jamf_binary.rb +132 -0
  73. data/lib/jamf/client/jamf_helper.rb +298 -0
  74. data/lib/jamf/client/management_action.rb +114 -0
  75. data/lib/jamf/compatibility.rb +88 -0
  76. data/lib/jamf/composer.rb +190 -0
  77. data/lib/jamf/configuration.rb +281 -0
  78. data/lib/jamf/exceptions.rb +107 -0
  79. data/lib/jamf/ruby_extensions.rb +36 -0
  80. data/lib/jamf/ruby_extensions/array.rb +35 -0
  81. data/lib/jamf/ruby_extensions/array/predicates.rb +46 -0
  82. data/lib/jamf/ruby_extensions/array/utils.rb +47 -0
  83. data/lib/jamf/ruby_extensions/filetest.rb +32 -0
  84. data/lib/jamf/ruby_extensions/filetest/predicates.rb +46 -0
  85. data/lib/jamf/ruby_extensions/hash.rb +33 -0
  86. data/lib/jamf/ruby_extensions/hash/backports.rb +92 -0
  87. data/lib/jamf/ruby_extensions/ipaddr.rb +37 -0
  88. data/lib/jamf/ruby_extensions/ipaddr/utils.rb +95 -0
  89. data/lib/jamf/ruby_extensions/object.rb +30 -0
  90. data/lib/jamf/ruby_extensions/object/predicates.rb +51 -0
  91. data/lib/jamf/ruby_extensions/pathname.rb +39 -0
  92. data/lib/jamf/ruby_extensions/pathname/predicates.rb +50 -0
  93. data/lib/jamf/ruby_extensions/pathname/utils.rb +75 -0
  94. data/lib/jamf/ruby_extensions/string.rb +35 -0
  95. data/lib/jamf/ruby_extensions/string/backports.rb +66 -0
  96. data/lib/jamf/ruby_extensions/string/conversions.rb +65 -0
  97. data/lib/jamf/ruby_extensions/string/predicates.rb +47 -0
  98. data/lib/jamf/utility.rb +423 -0
  99. data/lib/jamf/validate.rb +224 -0
  100. data/lib/jamf/version.rb +32 -0
  101. data/lib/jpapi.rb +26 -0
  102. data/lib/jss/version.rb +1 -1
  103. metadata +104 -4
@@ -0,0 +1,139 @@
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 building defined in the JSS
33
+ class MobileDevicePrestage < Jamf::Prestage
34
+
35
+ include Jamf::ChangeLog
36
+
37
+ # Constants
38
+ #####################################
39
+
40
+ RSRC_VERSION = 'v1'.freeze
41
+
42
+ RSRC_PATH = 'mobile-device-prestages'.freeze
43
+
44
+ # Object Model / Attributes
45
+ # See APIObject class documentation for details
46
+ # of how the OBJECT_MODEL hash works.
47
+ #####################################
48
+ OBJECT_MODEL = superclass::OBJECT_MODEL.merge(
49
+
50
+ # @!attribute skipSetupItems
51
+ # @return [Jamf::ComputerPrestageSkipSetupItems]
52
+ skipSetupItems: {
53
+ class: Jamf::MobileDevicePrestageSkipSetupItems
54
+ },
55
+
56
+ # @!attribute isAllowPairing
57
+ # @return [Boolean]
58
+ isAllowPairing: {
59
+ class: :boolean
60
+ },
61
+
62
+ # @!attribute isMultiUser
63
+ # @return [Boolean]
64
+ isMultiUser: {
65
+ class: :boolean
66
+ },
67
+
68
+ # @!attribute isSupervised
69
+ # @return [Boolean]
70
+ isSupervised: {
71
+ class: :boolean
72
+ },
73
+
74
+ # @!attribute maximumSharedAccounts
75
+ # @return [Integer]
76
+ maximumSharedAccounts: {
77
+ class: :integer
78
+ },
79
+
80
+ # @!attribute isAutoAdvanceSetup
81
+ # @return [Boolean]
82
+ isAutoAdvanceSetup: {
83
+ class: :boolean
84
+ },
85
+
86
+ # @!attribute isConfigureDeviceBeforeSetupAssistant
87
+ # @return [Boolean]
88
+ isConfigureDeviceBeforeSetupAssistant: {
89
+ class: :boolean
90
+ },
91
+
92
+ # @!attribute language
93
+ # @return [String]
94
+ language: {
95
+ class: :string
96
+ },
97
+
98
+ # @!attribute region
99
+ # @return [String]
100
+ region: {
101
+ class: :string
102
+ },
103
+
104
+ # @!attribute names
105
+ # @return [Jamf::MobileDevicePrestageNames]
106
+ names: {
107
+ class: Jamf::MobileDevicePrestageNames
108
+ }
109
+
110
+ ).freeze
111
+
112
+ parse_object_model
113
+
114
+
115
+ def self.sync_status(prestage = nil, latest = false, cnx: Jamf.cnx)
116
+ @sync_rsrc ||= "#{self::RSRC_VERSION}/#{self::RSRC_PATH}/#{SYNC_RSRC}"
117
+
118
+ if prestage
119
+ id = self.valid_id prestage
120
+ raise Jamf::NoSuchItemError, "No #{self.class} matching '#{prestage}'" unless id
121
+
122
+ rsrc = "#{@sync_rsrc}/#{id}"
123
+ rsrc << '/latest' if latest
124
+ results = cnx.get rsrc
125
+ latest ? Jamf::PrestageSyncStatus.new(results) : results.map { |ss| Jamf::PrestageSyncStatus.new ss }
126
+ else
127
+ cnx.get(@sync_rsrc).map { |ss| Jamf::PrestageSyncStatus.new ss }
128
+ end
129
+
130
+ end # self.sync_status(prestage = nil, latest = false, cnx: Jamf.cnx)
131
+
132
+
133
+ def sync_status(latest = false)
134
+ self.class.sync_status @id, latest, cnx: @cnx
135
+ end
136
+
137
+ end # class
138
+
139
+ end # module
@@ -0,0 +1,315 @@
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
+ # A mobile device in the JSS
30
+ class MobileDevice < Jamf::CollectionResource
31
+
32
+ # Mix-Ins
33
+ #####################################
34
+
35
+ include Jamf::Referable
36
+ include Jamf::Locatable
37
+ include Jamf::Extendable
38
+
39
+ # currently not creatable via API
40
+ # TODO: remove this when it's time
41
+ extend Jamf::UnCreatable
42
+
43
+ # currently not creatable via API
44
+ # TODO: remove this when it's time
45
+ extend Jamf::UnDeletable
46
+
47
+ # Class Constants
48
+ #####################################
49
+
50
+ IOS = 'ios'.freeze
51
+ APPLETV = 'appleTv'.freeze
52
+ ANDROID = 'android'.freeze
53
+ UNKNOWN = 'unknown'.freeze
54
+
55
+ IPHONE = 'iPhone'.freeze
56
+ IPOD = 'iPod'.freeze
57
+ IPAD = 'iPad'.freeze
58
+
59
+ # The enum for the 'type' attribute
60
+ TYPES = [
61
+ IOS,
62
+ APPLETV,
63
+ ANDROID,
64
+ UNKNOWN
65
+ ].freeze
66
+
67
+ APPLE_TYPES = [IOS, APPLETV].freeze
68
+
69
+ RSRC_PATH = '/inventory/obj/mobileDevice'.freeze
70
+
71
+ # This has a non-std update resource
72
+ # we POST to /inventory/obj/mobileDevice/{id}/update
73
+ # instad of the normal PUT to /inventory/obj/mobileDevice/{id}
74
+ UPDATE_RESOURCE = { method: :post, path_suffix: 'update' }.freeze
75
+
76
+ OBJECT_MODEL = {
77
+
78
+ # @!attribute [r] id
79
+ # @return [Integer]
80
+ id: {
81
+ class: :integer,
82
+ identifier: :primary,
83
+ readonly: true
84
+ },
85
+
86
+ # @!attribute name
87
+ # @param [String]
88
+ # @return [String]
89
+ name: {
90
+ class: :string
91
+ },
92
+
93
+ # @!attribute [r] serialNumber
94
+ # @return [String]
95
+ serialNumber: {
96
+ class: :string,
97
+ identifier: true,
98
+ readonly: true
99
+ },
100
+
101
+ # @!attribute [r] wifiMacAddress
102
+ # @return [String]
103
+ wifiMacAddress: {
104
+ class: :string,
105
+ identifier: true,
106
+ readonly: true
107
+ },
108
+
109
+ # @!attribute [r] udid
110
+ # @return [String]
111
+ udid: {
112
+ class: :string,
113
+ identifier: true,
114
+ readonly: true
115
+ },
116
+
117
+ # @!attribute [r] phoneNumber
118
+ # @return [String]
119
+ phoneNumber: {
120
+ class: :string,
121
+ identifier: true,
122
+ readonly: true
123
+ },
124
+
125
+ # @!attribute [r] model
126
+ # @return [String]
127
+ model: {
128
+ class: :string,
129
+ readonly: true
130
+ },
131
+
132
+ # @!attribute [r] modelIdentifier
133
+ # @return [String]
134
+ modelIdentifier: {
135
+ class: :string,
136
+ readonly: true
137
+ },
138
+
139
+ # @!attribute username
140
+ # Has custom setter, is part of Location in Details
141
+ # @param [String]
142
+ # @return [String]
143
+ username: {
144
+ class: :string,
145
+ readonly: true
146
+ },
147
+
148
+ # TODO: Will jamf give us isManaged or isSupervised?
149
+ # in the non-detail data?
150
+ # @!attribute [r] isManaged
151
+ # @return [Boolean]
152
+ # isManaged: {
153
+ # class: :boolean,
154
+ # readonly: true
155
+ # },
156
+
157
+ # @!attribute [r] type
158
+ # @return [Symbol]
159
+ type: {
160
+ class: :string,
161
+ readonly: true,
162
+ enum: Jamf::MobileDevice::TYPES
163
+ }
164
+
165
+ }.freeze
166
+ parse_object_model
167
+
168
+ # Class Methods
169
+ #####################################
170
+
171
+ # TODO: when jamf gives us isManaged in base object
172
+ # @return [Array<Hash>] the list of all managed mobile devices
173
+ # def self.all_unmanaged(refresh = false, api: JAMF.api)
174
+ # all(refresh, api: api).reject { |d| d[:managed] }
175
+ # end
176
+
177
+ # TODO: when jamf gives us isManaged in base object
178
+ # @return [Array<Hash>] the list of all unmanaged mobile devices
179
+ # def self.all_unmanaged(refresh = false, api: JAMF.api)
180
+ # all(refresh, api: api).reject { |d| d[:managed] }
181
+ # end
182
+
183
+ # TODO: when jamf gives us isSupervised in base object
184
+ # @return [Array<Hash>] the list of all supervised mobile devices
185
+ # def self.all_supervised(refresh = false, api: JAMF.api)
186
+ # all(refresh, api: api).select { |d| d[:supervised] }
187
+ # end
188
+
189
+ # TODO: when jamf gives us isSupervised in base object
190
+ # @return [Array<Hash>] the list of all unsupervised mobile devices
191
+ # def self.all_unsupervised(refresh = false, api: JAMF.api)
192
+ # all(refresh, api: api).reject { |d| d[:supervised] }
193
+ # end
194
+
195
+ # @return [Array<Hash>] the list of all iPhones
196
+ def self.all_iphones(refresh: false, cnx: Jamf.cnx)
197
+ all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPHONE }
198
+ end
199
+
200
+ # @return [Array<Hash>] the list of all iPods
201
+ def self.all_ipods(refresh: false, cnx: Jamf.cnx)
202
+ all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPOD }
203
+ end
204
+
205
+ # @return [Array<Hash>] the list of all iPads
206
+ def self.all_ipads(refresh: false, cnx: Jamf.cnx)
207
+ all(refresh, cnx: cnx).select { |d| d[:model].start_with? IPAD }
208
+ end
209
+
210
+ # @return [Array<Hash>] the list of all AppleTVs
211
+ def self.all_appleTvs(refresh: false, cnx: Jamf.cnx)
212
+ all(refresh, cnx: cnx).select { |d| d[:type] == APPLETV }
213
+ end
214
+
215
+ # @return [Array<Hash>] the list of all Androids
216
+ def self.all_androids(refresh: false, cnx: Jamf.cnx)
217
+ all(refresh, cnx: cnx).select { |d| d[:type] == ANDROID }
218
+ end
219
+
220
+ # Instance Methods
221
+ # Lots of overriding of standard methods in our metaclasses
222
+ # becuase we have a separate @details object, as well as
223
+ # a non-standard UPDATE_RESOURCE object model
224
+ # If this pattern becomes more common, and is uniform,
225
+ # (i.e. for computers) we'll make these methods into a module
226
+ #
227
+ #######################################
228
+
229
+ # This custom method outputs a 'UpdateMobileDevice' object model
230
+ # as defined in the API docs
231
+ #
232
+ def to_jamf
233
+ changes = unsaved_changes
234
+ data_to_send = {}
235
+
236
+ data_to_send[:name] = changes[:name][:new] if changes[:name]
237
+
238
+ data_to_send[:assetTag] = changes[:assetTag][:new] if changes[:assetTag]
239
+ data_to_send[:siteId] = changes[:site][:new].id if changes[:site]
240
+ data_to_send[:location] = details.location.to_jamf if changes[:location]
241
+ data_to_send[:updatedExtensionAttributes] = ext_attrs_to_jamf if ext_attrs_unsaved_changes?
242
+
243
+ return data_to_send unless APPLE_TYPES.include? @type
244
+
245
+ data_to_send[@type] = { purchasing: details.type_details.purchasing.to_jamf } if changes[:type_changes][:purchasing]
246
+
247
+ data_to_send[APPLETV][:airplayPassword] = changes[:type_changes][:airplayPassword][:new] if @type == APPLETV && changes[:type_changes][:airplayPassword]
248
+
249
+ data_to_send
250
+ end # to_jamf
251
+
252
+ # TODO - needed? Clean up?
253
+ # merge top-level and details changes and type-specific changes
254
+ def unsaved_changes
255
+ @unsaved_changes ||= {}
256
+ # name is the only thing at the top-level that isn't readonly
257
+ if @details
258
+ changes = details.unsaved_changes
259
+ changes[:name] = @unsaved_changes[:name] if @unsaved_changes[:name]
260
+ changes[:ext_attrs] = ext_attrs_unsaved_changes if ext_attrs_unsaved_changes?
261
+ type_changes = type_details.unsaved_changes
262
+ changes[:type_changes] = type_changes unless type_changes.empty?
263
+ else
264
+ changes = @unsaved_changes
265
+ end
266
+ changes
267
+ end
268
+
269
+ # clear changes for details as well as top
270
+ def clear_unsaved_changes
271
+ @details.clear_unsaved_changes if @details
272
+ ext_attrs_clear_unsaved_changes
273
+ @unsaved_changes = {}
274
+ end
275
+
276
+ # Fetch the details as needed
277
+ def details
278
+ @details ||= MobileDeviceDetails.fetch @id, @cnx
279
+ end # details
280
+
281
+ # Return the correct part of the details for the
282
+ # device type
283
+ def type_details
284
+ case @type
285
+ when :ios then details.ios
286
+ when :appleTv then details.appleTv
287
+ when :android then details.android
288
+ end
289
+ end
290
+
291
+ # catches the attributes in the details
292
+ def method_missing(meth, *args, &block)
293
+ if details.respond_to? meth
294
+ details.send meth, *args, &block
295
+ elsif type_details.respond_to? meth
296
+ type_details.send meth, *args, &block
297
+ else
298
+ super
299
+ end
300
+ end
301
+
302
+ # provides respond_to? for the attributes in the details
303
+ def respond_to_missing?(meth, *)
304
+ if details.respond_to? meth
305
+ true
306
+ elsif type_details.respond_to? meth
307
+ true
308
+ else
309
+ super
310
+ end
311
+ end
312
+
313
+ end # class Mobile Device
314
+
315
+ end # module