ruby-jss 2.0.0b1 → 2.0.0rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +1 -0
- data/README-2.0.0.md +101 -64
- data/README.md +223 -173
- data/lib/jamf/api/classic/api_objects/distribution_point.rb +12 -50
- data/lib/jamf/api/classic/api_objects/mobile_device_application.rb +35 -6
- data/lib/jamf/api/classic/api_objects/patch_title.rb +14 -9
- data/lib/jamf/api/classic/base_classes/api_object.rb +69 -10
- data/lib/jamf/api/classic/base_classes/patch_source.rb +10 -5
- data/lib/jamf/api/connection/token.rb +1 -0
- data/lib/jamf/api/connection.rb +1 -5
- data/lib/jamf/api/jamf_pro/api_objects/inventory_preload_record.rb +0 -1
- data/lib/jamf/api/jamf_pro/mixins/collection_resource.rb +8 -12
- data/lib/jamf/api/jamf_pro/mixins/macos_managed_updates.rb +17 -7
- data/lib/jamf/deprecations/deprecated_api_connection_class.rb +29 -0
- data/lib/jamf/version.rb +1 -1
- data/lib/jamf/zeitwerk_config.rb +217 -0
- data/lib/jamf.rb +7 -39
- data/test/tests/policy.rb +1 -0
- metadata +20 -31
- data/lib/zeitwerk_config.rb +0 -163
@@ -107,27 +107,18 @@ module Jamf
|
|
107
107
|
def self.master_distribution_point(refresh = false, default: nil, api: nil, cnx: Jamf.cnx)
|
108
108
|
cnx = api if api
|
109
109
|
|
110
|
-
@master_distribution_point = nil if refresh
|
111
|
-
return @master_distribution_point if @master_distribution_point
|
112
|
-
|
113
110
|
all_ids(refresh, cnx: cnx).each do |dp_id|
|
114
111
|
dp = fetch id: dp_id, cnx: cnx
|
115
|
-
if dp.master?
|
116
|
-
@master_distribution_point = dp
|
117
|
-
break
|
118
|
-
end
|
112
|
+
return dp if dp.master?
|
119
113
|
end
|
120
114
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@master_distribution_point
|
127
|
-
elsif default == :random
|
128
|
-
@master_distribution_point = fetch(id: all_ids.sample, cnx: cnx)
|
115
|
+
case default
|
116
|
+
when :random
|
117
|
+
fetch id: all_ids.sample, cnx: cnx
|
118
|
+
when nil
|
119
|
+
raise Jamf::NoSuchItemError, 'No Master FileShare Distribtion Point. Use the default: parameter if needed.'
|
129
120
|
else
|
130
|
-
|
121
|
+
fetch default, cnx: cnx
|
131
122
|
end
|
132
123
|
end
|
133
124
|
|
@@ -267,38 +258,9 @@ module Jamf
|
|
267
258
|
# @return [String] the ssh password as a SHA256 digest
|
268
259
|
attr_reader :ssh_password_sha256
|
269
260
|
|
270
|
-
# As well as the standard :id, :name, and :data, you can
|
271
|
-
# instantiate this class with :id => :master, in which case you'll
|
272
|
-
# get the Master Distribution Point as defined in the JSS.
|
273
|
-
# An error will be raised if one hasn't been defined.
|
274
|
-
#
|
275
|
-
# You can also do this more easily by calling JSS.master_distribution_point
|
276
|
-
#
|
277
261
|
def initialize(**args)
|
278
|
-
|
279
|
-
|
280
|
-
args[:cnx] ||= Jamf.cnx
|
281
|
-
|
282
|
-
@cnx = args[:cnx]
|
283
|
-
|
284
|
-
@init_data = nil
|
285
|
-
|
286
|
-
# looking for master?
|
287
|
-
if args[:id] == :master
|
288
|
-
|
289
|
-
self.class.all_ids(cnx: @cnx).each do |id|
|
290
|
-
@init_data = @cnx.c_get("#{RSRC_BASE}/id/#{id}")[RSRC_OBJECT_KEY]
|
291
|
-
if @init_data[:is_master]
|
292
|
-
@id = @init_data[:id]
|
293
|
-
@name = @init_data[:name]
|
294
|
-
break
|
295
|
-
end # if data is master
|
296
|
-
@init_data = nil
|
297
|
-
end # each id
|
298
|
-
end # if args is master
|
299
|
-
|
300
|
-
super(args) if @init_data.nil?
|
301
|
-
|
262
|
+
super
|
263
|
+
|
302
264
|
@ip_address = @init_data[:ip_address]
|
303
265
|
@local_path = @init_data[:local_path]
|
304
266
|
@enable_load_balancing = @init_data[:enable_load_balancing]
|
@@ -365,7 +327,7 @@ module Jamf
|
|
365
327
|
when :ro then @read_only_password_sha256
|
366
328
|
when :http then @http_password_sha256
|
367
329
|
when :ssh then @ssh_password_sha256
|
368
|
-
|
330
|
+
end # case
|
369
331
|
|
370
332
|
return nil if sha256 == EMPTY_PW_256
|
371
333
|
|
@@ -449,7 +411,7 @@ module Jamf
|
|
449
411
|
JSS.stdin line
|
450
412
|
else
|
451
413
|
pw
|
452
|
-
|
414
|
+
end
|
453
415
|
|
454
416
|
pwok = check_pw(access, password)
|
455
417
|
unless pwok
|
@@ -466,7 +428,7 @@ module Jamf
|
|
466
428
|
when 'smb' then '/sbin/mount_smbfs'
|
467
429
|
when 'afp' then '/sbin/mount_afp'
|
468
430
|
else raise "Can't mount distribution point #{@name}: no known connection type."
|
469
|
-
|
431
|
+
end
|
470
432
|
|
471
433
|
@mountpoint.mkpath
|
472
434
|
|
@@ -50,7 +50,6 @@ module Jamf
|
|
50
50
|
include Jamf::VPPable
|
51
51
|
include Jamf::Sitable
|
52
52
|
|
53
|
-
|
54
53
|
# Class Methods
|
55
54
|
#####################################
|
56
55
|
|
@@ -162,6 +161,10 @@ module Jamf
|
|
162
161
|
# does its backups (to icloud or itunes)?
|
163
162
|
attr_reader :prevent_backup_of_app_data
|
164
163
|
|
164
|
+
# @return [Boolean] Should this app auto-update on devices?
|
165
|
+
attr_reader :keep_app_updated_on_devices
|
166
|
+
alias auto_update? keep_app_updated_on_devices
|
167
|
+
|
165
168
|
# @return [Boolean] should the JSS update the icon and description from the app
|
166
169
|
# source?
|
167
170
|
attr_reader :keep_description_and_icon_up_to_date
|
@@ -185,7 +188,6 @@ module Jamf
|
|
185
188
|
# which contains a plist <dict> element with config data.
|
186
189
|
attr_reader :configuration_prefs
|
187
190
|
|
188
|
-
|
189
191
|
# Constructor
|
190
192
|
#####################################
|
191
193
|
|
@@ -208,6 +210,7 @@ module Jamf
|
|
208
210
|
@itunes_country_region = general[:itunes_country_region]
|
209
211
|
@itunes_sync_time = general[:itunes_sync_time]
|
210
212
|
@deploy_as_managed_app = general[:deploy_as_managed_app]
|
213
|
+
@keep_app_updated_on_devices = general[:keep_app_updated_on_devices]
|
211
214
|
@remove_app_when_mdm_profile_is_removed = general[:remove_app_when_mdm_profile_is_removed]
|
212
215
|
@prevent_backup_of_app_data = general[:prevent_backup_of_app_data]
|
213
216
|
@keep_description_and_icon_up_to_date = general[:keep_description_and_icon_up_to_date]
|
@@ -232,6 +235,7 @@ module Jamf
|
|
232
235
|
#
|
233
236
|
def display_name=(new_val)
|
234
237
|
return nil if new_val.to_s == @display_name
|
238
|
+
|
235
239
|
@display_name = new_val.to_s
|
236
240
|
@need_to_update = true
|
237
241
|
end
|
@@ -274,6 +278,7 @@ module Jamf
|
|
274
278
|
#
|
275
279
|
def url=(new_val)
|
276
280
|
return nil if new_val == @url
|
281
|
+
|
277
282
|
@url = new_val
|
278
283
|
@need_to_update = true
|
279
284
|
end
|
@@ -288,6 +293,7 @@ module Jamf
|
|
288
293
|
def make_available_after_install=(new_val)
|
289
294
|
return nil if new_val == @make_available_after_install
|
290
295
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
296
|
+
|
291
297
|
@make_available_after_install = new_val
|
292
298
|
@need_to_update = true
|
293
299
|
end
|
@@ -302,10 +308,25 @@ module Jamf
|
|
302
308
|
def deploy_as_managed_app=(new_val)
|
303
309
|
return nil if new_val == @deploy_as_managed_app
|
304
310
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
311
|
+
|
305
312
|
@deploy_as_managed_app = new_val
|
306
313
|
@need_to_update = true
|
307
314
|
end
|
308
315
|
|
316
|
+
# Set whether or not this app should be auto-updated on devices
|
317
|
+
#
|
318
|
+
# @param new_val[Boolean] The new value
|
319
|
+
#
|
320
|
+
# @return [void]
|
321
|
+
#
|
322
|
+
def keep_app_updated_on_devices=(new_val)
|
323
|
+
return nil if new_val == @keep_app_updated_on_devices
|
324
|
+
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
325
|
+
|
326
|
+
@keep_app_updated_on_devices = new_val
|
327
|
+
@need_to_update = true
|
328
|
+
end
|
329
|
+
alias auto_update= keep_app_updated_on_devices=
|
309
330
|
|
310
331
|
# Set whether or not this app should be removed when
|
311
332
|
# the device is unmanaged
|
@@ -317,6 +338,7 @@ module Jamf
|
|
317
338
|
def remove_app_when_mdm_profile_is_removed=(new_val)
|
318
339
|
return nil if new_val == @remove_app_when_mdm_profile_is_removed
|
319
340
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
341
|
+
|
320
342
|
@remove_app_when_mdm_profile_is_removed = new_val
|
321
343
|
@need_to_update = true
|
322
344
|
end
|
@@ -330,11 +352,11 @@ module Jamf
|
|
330
352
|
def prevent_backup_of_app_data=(new_val)
|
331
353
|
return nil if new_val == @prevent_backup_of_app_data
|
332
354
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
355
|
+
|
333
356
|
@prevent_backup_of_app_data = new_val
|
334
357
|
@need_to_update = true
|
335
358
|
end
|
336
359
|
|
337
|
-
|
338
360
|
# Set whether or not the jss should update info about this app from the app store
|
339
361
|
#
|
340
362
|
# @param new_val[Boolean] The new value
|
@@ -344,6 +366,7 @@ module Jamf
|
|
344
366
|
def keep_description_and_icon_up_to_date=(new_val)
|
345
367
|
return nil if new_val == @keep_description_and_icon_up_to_date
|
346
368
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
369
|
+
|
347
370
|
@keep_description_and_icon_up_to_date = new_val
|
348
371
|
@need_to_update = true
|
349
372
|
end
|
@@ -357,6 +380,7 @@ module Jamf
|
|
357
380
|
def free=(new_val)
|
358
381
|
return nil if new_val == @free
|
359
382
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
383
|
+
|
360
384
|
@free = new_val
|
361
385
|
@need_to_update = true
|
362
386
|
end
|
@@ -371,6 +395,7 @@ module Jamf
|
|
371
395
|
def take_over_management=(new_val)
|
372
396
|
return nil if new_val == @take_over_management
|
373
397
|
raise Jamf::InvalidDataError, 'New value must be true or false' unless new_val.jss_boolean?
|
398
|
+
|
374
399
|
@take_over_management = new_val
|
375
400
|
@need_to_update = true
|
376
401
|
end
|
@@ -432,6 +457,7 @@ module Jamf
|
|
432
457
|
#
|
433
458
|
def external_url=(new_val)
|
434
459
|
return nil if new_val == @external_url
|
460
|
+
|
435
461
|
@external_url = new_val
|
436
462
|
@need_to_update = true
|
437
463
|
end
|
@@ -445,11 +471,11 @@ module Jamf
|
|
445
471
|
#
|
446
472
|
def configuration_prefs=(new_val)
|
447
473
|
return nil if new_val == @configuration_prefs
|
474
|
+
|
448
475
|
@configuration_prefs = new_val
|
449
476
|
@need_to_update = true
|
450
477
|
end
|
451
478
|
|
452
|
-
|
453
479
|
# Save the application to a file.
|
454
480
|
#
|
455
481
|
# @param path[Pathname, String] The path to which the file should be saved.
|
@@ -462,10 +488,12 @@ module Jamf
|
|
462
488
|
#
|
463
489
|
def save_ipa(path, overwrite = false)
|
464
490
|
return nil unless @ipa[:data]
|
491
|
+
|
465
492
|
path = Pathname.new path
|
466
|
-
path
|
493
|
+
path += @ipa[:name] if path.directory? && @ipa[:name]
|
467
494
|
|
468
495
|
raise Jamf::AlreadyExistsError, "The file #{path} already exists" if path.exist? && !overwrite
|
496
|
+
|
469
497
|
path.delete if path.exist?
|
470
498
|
path.jss_save Base64.decode64(@ipa[:data])
|
471
499
|
end
|
@@ -507,6 +535,7 @@ module Jamf
|
|
507
535
|
#
|
508
536
|
def refresh_ipa
|
509
537
|
return nil unless @in_jss
|
538
|
+
|
510
539
|
fresh_data = @cnx.c_get(@rest_rsrc)[self.class::RSRC_OBJECT_KEY]
|
511
540
|
@ipa = fresh_data[:general][:ipa]
|
512
541
|
end
|
@@ -523,6 +552,7 @@ module Jamf
|
|
523
552
|
gen.add_element('deploy_as_managed_app').text = @deploy_as_managed_app
|
524
553
|
gen.add_element('remove_app_when_mdm_profile_is_removed').text = @remove_app_when_mdm_profile_is_removed
|
525
554
|
gen.add_element('prevent_backup_of_app_data').text = @prevent_backup_of_app_data
|
555
|
+
gen.add_element('keep_app_updated_on_devices').text = @keep_app_updated_on_devices
|
526
556
|
gen.add_element('keep_description_and_icon_up_to_date').text = @keep_description_and_icon_up_to_date
|
527
557
|
gen.add_element('free').text = @free
|
528
558
|
gen.add_element('take_over_management').text = @take_over_management
|
@@ -540,7 +570,6 @@ module Jamf
|
|
540
570
|
doc.to_s
|
541
571
|
end
|
542
572
|
|
543
|
-
|
544
573
|
end # class removable_macaddr
|
545
574
|
|
546
575
|
end # module
|
@@ -180,6 +180,7 @@ module Jamf
|
|
180
180
|
info[:source_id] = info[:source_id].to_i
|
181
181
|
end
|
182
182
|
return data unless source_id
|
183
|
+
|
183
184
|
data.select { |p| p[:source_id] == source_id }
|
184
185
|
end
|
185
186
|
|
@@ -311,9 +312,11 @@ module Jamf
|
|
311
312
|
# so all other lookup values have to be converted to ID before
|
312
313
|
# the call to super
|
313
314
|
#
|
314
|
-
def self.fetch(identifier = nil, **params)
|
315
|
-
# default
|
316
|
-
|
315
|
+
def self.fetch(identifier = nil, **params)
|
316
|
+
# default connection if unspecified
|
317
|
+
cnx = params.delete :cnx
|
318
|
+
cnx ||= params.delete :api # backward compatibility, deprecated
|
319
|
+
cnx ||= Jamf.cnx
|
317
320
|
|
318
321
|
# source: and source_id: are considered the same, source_id: wins
|
319
322
|
params[:source_id] ||= params[:source]
|
@@ -349,8 +352,8 @@ module Jamf
|
|
349
352
|
cnx = api if api
|
350
353
|
|
351
354
|
id = all_ids(refresh, cnx: cnx).include?(ident) ? ident : nil
|
352
|
-
id ||=
|
353
|
-
id ||=
|
355
|
+
id ||= map_all(:id, to: :source_name_id).invert[ident]
|
356
|
+
id ||= map_all(:id, to: :name).invert[ident]
|
354
357
|
id
|
355
358
|
end
|
356
359
|
|
@@ -376,7 +379,6 @@ module Jamf
|
|
376
379
|
attr_reader :email_notification
|
377
380
|
alias email_notification? email_notification
|
378
381
|
|
379
|
-
#
|
380
382
|
def initialize(**args)
|
381
383
|
super
|
382
384
|
|
@@ -421,11 +423,11 @@ module Jamf
|
|
421
423
|
def versions
|
422
424
|
return @versions unless in_jss
|
423
425
|
return @versions unless @versions.empty?
|
426
|
+
|
424
427
|
# if we are in jss, and versions is empty, re-fetch them
|
425
428
|
@versions = self.class.fetch(id: id).versions
|
426
429
|
end
|
427
430
|
|
428
|
-
|
429
431
|
# @return [Hash] Subset of @versions, containing those which have packages
|
430
432
|
# assigned
|
431
433
|
#
|
@@ -442,6 +444,7 @@ module Jamf
|
|
442
444
|
def email_notification=(new_setting)
|
443
445
|
return if email_notification == new_setting
|
444
446
|
raise Jamf::InvalidDataError, 'New Setting must be boolean true or false' unless Jamf::TRUE_FALSE.include? @email_notification = new_setting
|
447
|
+
|
445
448
|
@need_to_update = true
|
446
449
|
end
|
447
450
|
|
@@ -454,6 +457,7 @@ module Jamf
|
|
454
457
|
def web_notification=(new_setting)
|
455
458
|
return if web_notification == new_setting
|
456
459
|
raise Jamf::InvalidDataError, 'New Setting must be boolean true or false' unless Jamf::TRUE_FALSE.include? @web_notification = new_setting
|
460
|
+
|
457
461
|
@need_to_update = true
|
458
462
|
end
|
459
463
|
|
@@ -467,8 +471,8 @@ module Jamf
|
|
467
471
|
|
468
472
|
# wrapper to fetch versions after creating
|
469
473
|
def create
|
470
|
-
|
471
|
-
|
474
|
+
super
|
475
|
+
|
472
476
|
end
|
473
477
|
|
474
478
|
# wrapper to clear @changed_pkgs after updating
|
@@ -535,6 +539,7 @@ module Jamf
|
|
535
539
|
pkg = velem.add_element 'package'
|
536
540
|
# leave am empty package element to remove the pkg assignement
|
537
541
|
next if versions[vers].package_id == :none
|
542
|
+
|
538
543
|
pkg.add_element('id').text = versions[vers].package_id.to_s
|
539
544
|
end # do vers
|
540
545
|
end
|
@@ -295,7 +295,7 @@ module Jamf
|
|
295
295
|
# This is called automatically when subclasses are loaded by zeitwerk
|
296
296
|
#
|
297
297
|
def self.define_identifier_list_methods
|
298
|
-
Jamf.load_msg "
|
298
|
+
Jamf.load_msg "Defining list-methods for APIObject subclass #{self}"
|
299
299
|
|
300
300
|
lookup_keys.each do |als, key|
|
301
301
|
meth_name = key.to_s.end_with?('s') ? "all_#{key}es" : "all_#{key}s"
|
@@ -557,8 +557,9 @@ module Jamf
|
|
557
557
|
#
|
558
558
|
######################################
|
559
559
|
def self.map_all(ident, to:, cnx: Jamf.cnx, refresh: false, cached_list: nil)
|
560
|
+
orig_ident = ident
|
560
561
|
ident = lookup_keys[ident]
|
561
|
-
raise Jamf::InvalidDataError, "No identifier :#{
|
562
|
+
raise Jamf::InvalidDataError, "No identifier :#{orig_ident} for class #{self}" unless ident
|
562
563
|
|
563
564
|
list = cached_list || all(refresh, cnx: cnx)
|
564
565
|
mapped = list.map do |i|
|
@@ -673,28 +674,85 @@ module Jamf
|
|
673
674
|
# is undefined. In short - dont' use names here unless you know they are
|
674
675
|
# unique.
|
675
676
|
#
|
677
|
+
# NOTE: Integers passed in as strings, e.g. '12345' will be converted to
|
678
|
+
# integers and return the matching integer id if it exists.
|
679
|
+
#
|
680
|
+
# This means that if you have names that might match '12345' and you use
|
681
|
+
# valid_id '12345'
|
682
|
+
# you will get back the id 12345, if such an id exists, even if it is not
|
683
|
+
# the object with the name '12345'
|
684
|
+
#
|
685
|
+
# To explicitly look for '12345' as a name, use:
|
686
|
+
# valid_id name: '12345'
|
687
|
+
# See the ident_and_val param below.
|
688
|
+
#
|
676
689
|
# @param identfier [String,Integer] An identifier for an object, a value for
|
677
|
-
#
|
690
|
+
# one of the available lookup_keys. Omit this and use 'identifier: value'
|
691
|
+
# if you want to limit the search to a specific indentifier key, e.g.
|
692
|
+
# name: 'somename'
|
693
|
+
# or
|
694
|
+
# id: 76538
|
678
695
|
#
|
679
696
|
# @param refresh [Boolean] Should the data be re-read from the server
|
680
697
|
#
|
698
|
+
# @param ident_and_val [Hash] Do not pass in Hash.
|
699
|
+
# This Hash internally holds the arbitrary identifier key
|
700
|
+
# and desired value when you call ".valid_id ident: 'value'", e.g.
|
701
|
+
# ".valid_id name: 'somename'" or ".valid_id udid: some_udid"
|
702
|
+
# Using explicit identifier keys like this will speed things up, since
|
703
|
+
# the method doesn't have to search through all available identifiers
|
704
|
+
# for the desired value.
|
705
|
+
#
|
681
706
|
# @param cnx [Jamf::Connection] an API connection to use for the query.
|
682
707
|
# Defaults to the corrently active API. See {Jamf::Connection}
|
683
708
|
#
|
684
709
|
# @return [Integer, nil] the id of the matching object, or nil if it doesn't exist
|
685
710
|
#
|
686
|
-
def self.valid_id(identifier, refresh = false, api: nil, cnx: Jamf.cnx)
|
711
|
+
def self.valid_id(identifier = nil, refresh = false, api: nil, cnx: Jamf.cnx, **ident_and_val)
|
687
712
|
cnx = api if api
|
688
713
|
|
689
|
-
# refresh if needed
|
714
|
+
# refresh the cache if needed
|
690
715
|
all(refresh, cnx: cnx) if refresh
|
691
716
|
|
692
|
-
#
|
717
|
+
# Were we given an explict identifier key, like name: or id:?
|
718
|
+
# If so, just look for that.
|
719
|
+
unless ident_and_val.empty?
|
720
|
+
# only the first k/v pair of the ident_and_val hash is used
|
721
|
+
key = ident_and_val.keys.first
|
722
|
+
val = ident_and_val[key]
|
723
|
+
|
724
|
+
# if we are explicitly looking for an id, ensure we use an integer
|
725
|
+
# even if we were given an integer in a string.
|
726
|
+
if key == :id
|
727
|
+
val = val.to_i if val.is_a?(String) && val.j_integer?
|
728
|
+
return all_ids(cnx: cnx).include?(val) ? val : nil
|
729
|
+
end
|
730
|
+
|
731
|
+
# map the identifiers to ids, and return the id if there's
|
732
|
+
# a case-insensitive matching identifire
|
733
|
+
map_all(key, to: :id).each do |ident_val, id|
|
734
|
+
return id if ident_val.to_s.casecmp? val.to_s
|
735
|
+
end
|
736
|
+
nil
|
737
|
+
end
|
738
|
+
|
739
|
+
# If we are here, we need to seach all available identifier keys
|
740
|
+
# Start by looking for it as an id.
|
741
|
+
|
742
|
+
# it its a valid integer id, return it
|
693
743
|
return identifier if all_ids(cnx: cnx).include? identifier
|
694
744
|
|
745
|
+
# if its a valid integer-in-a-string id, return it
|
746
|
+
if identifier.is_a?(String) && identifier.j_integer?
|
747
|
+
int_id = identifier.to_i
|
748
|
+
return int_id if all_ids(cnx: cnx).include? int_id
|
749
|
+
end
|
750
|
+
|
751
|
+
# Now go through all the other identifier keys
|
695
752
|
keys_to_check = lookup_keys(no_aliases: true)
|
696
753
|
keys_to_check.delete :id # we've already checked :id
|
697
754
|
|
755
|
+
# loop thru looking for a match
|
698
756
|
keys_to_check.each do |key|
|
699
757
|
mapped_ids = map_all_ids_to key, cnx: cnx
|
700
758
|
matches = mapped_ids.select { |_id, ident| ident.casecmp? identifier }
|
@@ -905,7 +963,7 @@ module Jamf
|
|
905
963
|
|
906
964
|
# which connection?
|
907
965
|
cnx = args.delete :cnx
|
908
|
-
cnx ||= args.delete :api
|
966
|
+
cnx ||= args.delete :api # backward compatibility, deprecated
|
909
967
|
cnx ||= Jamf.cnx
|
910
968
|
|
911
969
|
# refresh the .all list if needed
|
@@ -1073,7 +1131,7 @@ module Jamf
|
|
1073
1131
|
# @param cnx [Jamf::Connection] the connection thru which to make this
|
1074
1132
|
# object. Defaults to the deault API connection in Jamf.cnx
|
1075
1133
|
#
|
1076
|
-
# @param args[Hash] The data for creating an object, such as name:
|
1134
|
+
# @param args [Hash] The data for creating an object, such as name:
|
1077
1135
|
# See {APIObject#initialize}
|
1078
1136
|
#
|
1079
1137
|
# @return [APIObject] The un-created ruby-instance of a JSS object
|
@@ -1084,8 +1142,9 @@ module Jamf
|
|
1084
1142
|
raise Jamf::UnsupportedError, "Creating #{self.class::RSRC_LIST_KEY} isn't yet supported. Please use other Casper workflows."
|
1085
1143
|
end
|
1086
1144
|
raise ArgumentError, "Use '#{self.class}.fetch id: xx' to retrieve existing JSS objects" if args[:id]
|
1087
|
-
|
1088
|
-
args[:
|
1145
|
+
|
1146
|
+
args[:cnx] ||= args[:api] # deprecated
|
1147
|
+
args[:cnx] ||= Jamf.cnx
|
1089
1148
|
args[:id] = :new
|
1090
1149
|
new(**args)
|
1091
1150
|
end
|
@@ -128,8 +128,9 @@ module Jamf
|
|
128
128
|
|
129
129
|
# Fetch either an internal or external patch source
|
130
130
|
#
|
131
|
-
# BUG: there's an API bug
|
132
|
-
# which is why we rescue internal server errors
|
131
|
+
# BUG: there's an API bug when fetching a non-existent patch source
|
132
|
+
# which is why we rescue 500 internal server errors and report them
|
133
|
+
# as 'no matching patch source'
|
133
134
|
#
|
134
135
|
# @see APIObject.fetch
|
135
136
|
#
|
@@ -162,7 +163,7 @@ module Jamf
|
|
162
163
|
# @see APIObject.make
|
163
164
|
#
|
164
165
|
def self.create(**args)
|
165
|
-
case
|
166
|
+
case name
|
166
167
|
when 'Jamf::PatchSource'
|
167
168
|
Jamf::PatchExternalSource.make args
|
168
169
|
when 'Jamf::PatchExternalSource'
|
@@ -184,7 +185,7 @@ module Jamf
|
|
184
185
|
def self.delete(victims, api: nil, cnx: Jamf.cnx)
|
185
186
|
cnx = api if api
|
186
187
|
|
187
|
-
case
|
188
|
+
case name
|
188
189
|
when 'Jamf::PatchSource'
|
189
190
|
Jamf::PatchExternalSource victims, cnx: cnx
|
190
191
|
when 'Jamf::PatchExternalSource'
|
@@ -292,6 +293,7 @@ module Jamf
|
|
292
293
|
|
293
294
|
return :internel if Jamf::PatchInternalSource.valid_id ident, refresh, cnx: cnx
|
294
295
|
return :external if Jamf::PatchExternalSource.valid_id ident, refresh, cnx: cnx
|
296
|
+
|
295
297
|
nil
|
296
298
|
end
|
297
299
|
|
@@ -324,7 +326,10 @@ module Jamf
|
|
324
326
|
|
325
327
|
# Init
|
326
328
|
def initialize(**args)
|
327
|
-
|
329
|
+
if instance_of?(Jamf::PatchSource)
|
330
|
+
raise Jamf::UnsupportedError,
|
331
|
+
'PatchSource is an abstract metaclass. Please use PatchInternalSource or PatchExternalSource'
|
332
|
+
end
|
328
333
|
|
329
334
|
super
|
330
335
|
|
data/lib/jamf/api/connection.rb
CHANGED
@@ -106,7 +106,7 @@ module Jamf
|
|
106
106
|
# If you provide connection details when calling 'new', they will be passed
|
107
107
|
# to the {#connect} method immediately. Otherwise you can call {#connect} later.
|
108
108
|
#
|
109
|
-
#
|
109
|
+
# production_server = Jamf::Connection.new(
|
110
110
|
# 'https://produser@prodserver.address.org:8443/'
|
111
111
|
# name: 'prod',
|
112
112
|
# pw: :prompt
|
@@ -231,8 +231,4 @@ module Jamf
|
|
231
231
|
|
232
232
|
end # class Connection
|
233
233
|
|
234
|
-
# Some backward compatibility
|
235
|
-
# @deprecated
|
236
|
-
APIConnection = Connection
|
237
|
-
|
238
234
|
end # module
|