ruby-jss 4.2.0 → 4.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19c9e79713c2ae52e27acf1baaecdf03446328ebce206b0d4a6d6c995d98e0cf
4
- data.tar.gz: b05700b3f5e07771b257af10da6b73cf44334916cbdc0442d9d7aca539518af9
3
+ metadata.gz: c4954d82549682beafa2624e07bad383d732fae5f77b8d1a3a07f499504b4be2
4
+ data.tar.gz: 2bd26c0615a368da8988779fb6a2d2726090a8484dbef6005f98a60c8db50326
5
5
  SHA512:
6
- metadata.gz: d400c1033d40a4128d5021e21f3fd367158caf2ed176108bf912198f76f4669bfd3500b26e0677279a9d87c65dc69974fe636588d100256f64a79315d64747b0
7
- data.tar.gz: 631190601b377d45d1cb1ba80ec54decf662f7b6223d311f6b6e3a73dfea5731b86bac7d5046d47a6364395a3abb5b4ef4c1b1add424868da917ed037152fa8c
6
+ metadata.gz: ad08c4b7028c37be9b8b0a941ef59eabf8e77530d4533c69f9ff824fed78d8624808640121fd84a08d14f0fac55c14a19d58c36a2a2a76ce4f6b503ef93c1796
7
+ data.tar.gz: 88d53f94ac7412b278c6dac089ed52b12327476a32b7e57fd92c0509c3a7dffec9f55c03c533ae1545a7d7b771599192baadfb141af0e230b8648fdcfd6d7267
data/CHANGES.md CHANGED
@@ -14,6 +14,25 @@ __Please update all installations of ruby-jss to at least v1.6.0.__
14
14
 
15
15
  Many many thanks to actae0n of Blacksun Hackers Club for reporting this issue and providing examples of how it could be exploited.
16
16
 
17
+ --------
18
+ ## \[4.2.1] 2025-08-11
19
+
20
+ ### Fixed
21
+
22
+ - `Jamf::JPackage#osRequirements=` now properly expands versions starting with '>='
23
+ - `OAPIObject` no longer overwrites custom getters & setters with autogenerated ones.
24
+ - calling `.all instantiate: true` no longer raises an error for JPAPI collection classes in ruby 3.x
25
+
26
+ ### Changed
27
+
28
+ - `Jamf.expand_min_os` now knows that Apple has skipped macOS v16-25, and that starting with
29
+ Tahoe, the os is v26, incremented yearly. It now expands to v40, which should hold us for over
30
+ a decade.
31
+
32
+ ### Added
33
+
34
+ - `OAPIObject` subclasses now have an attr_reader `creating_from_create` indicating that they are being instantiated by the `.create` class method, as opposed to being fetched or given API data
35
+
17
36
  --------
18
37
  ## \[4.2.0] 2025-06-11
19
38
 
@@ -52,7 +71,7 @@ If you have thoughts or comments on this, please reach out:
52
71
 
53
72
  - Collection Resource classes from the Jamf Pro API can now define a constant OBJECT_NAME_ATTR, which indicates the attribute that holds the individual object's name, if that isn't "name".
54
73
 
55
- For example, Computer and MobileDevice prestage objects, the name is in the "displayName" attribute. For JPackages via the Jamf Pro API, the package object's name (not its file name) is in the "packageName" object.
74
+ For example, Computer and MobileDevice prestage objects, the name is in the "displayName" attribute. For JPackages via the Jamf Pro API, the package object's name (not its file name) is in the "packageName" attribute.
56
75
 
57
76
  When the OBJECT_NAME_ATTR is defined, the class can use "name" as a alias of the OBJECT_NAME_ATTR with getters & setters (`name=` is an alias of `displayName=`, etc) and can be used for .fetch and .valid_id: `Jamf::JPackage.fetch name: 'foo'` is the same as `Jamf::JPackage.fetch packageName: 'foo'`
58
77
 
@@ -340,6 +340,12 @@ module Jamf
340
340
  self.suppressEula = DEFAULT_SUPPRESS_EULA if suppressEula.nil?
341
341
  self.suppressRegistration = DEFAULT_SUPPRESS_REGISTRATION if suppressRegistration.nil?
342
342
 
343
+ if creating_from_create && osRequirements
344
+ # if we're creating a new object, and osRequirements is set,
345
+ # convert it to a comma-separated string
346
+ @osRequirements = osRequirements_as_comma_sep_string(osRequirements)
347
+ end
348
+
343
349
  @checksum =
344
350
  case hashType
345
351
  when CHECKSUM_HASH_TYPE_MD5
@@ -374,16 +380,36 @@ module Jamf
374
380
  # @return [void]
375
381
  #############################
376
382
  def osRequirements=(new_val)
377
- # make sure we have an array
378
- new_val = [new_val].flatten.compact.uniq.map(&:to_s)
379
- new_val.map! do |vers|
383
+ orig_osRequirements = osRequirements
384
+
385
+ new_val = osRequirements_as_comma_sep_string(new_val)
386
+ @osRequirements = new_val
387
+
388
+ note_unsaved_change :osRequirements, orig_osRequirements
389
+ end
390
+
391
+ # Take a value for osRequirements, and return it as a comma-separated string,
392
+ # possibly expanded if any of them starts with '>='.
393
+ #
394
+ # @see Jamf.expand_min_os
395
+ #
396
+ # @param val [String,Array<String>] comma-separated string, or array of os versions
397
+ #
398
+ # @return [Array<String>] the osRequirements as an array of strings
399
+ #############################
400
+ def osRequirements_as_comma_sep_string(val)
401
+ # make sure we have a flat array of strings
402
+ val = val.split(',').map(&:strip) if val.is_a? String
403
+ val = [val].flatten.compact.uniq.map(&:to_s)
404
+
405
+ # expand any minimum OS versions
406
+ val.map! do |vers|
380
407
  vers.start_with?('>=') ? Jamf.expand_min_os(vers) : vers
381
408
  end
382
409
 
383
- orig_osRequirements = osRequirements
384
- @osRequirements = new_val.join(', ')
385
- note_unsaved_change :osRequirements, orig_osRequirements
410
+ val.flatten.join(', ')
386
411
  end
412
+ private :osRequirements_as_comma_sep_string
387
413
 
388
414
  # Recalculate the checksum of the package file from a given filepath, and update the
389
415
  # object's checksum and hashValue attributes.
@@ -118,6 +118,9 @@ module Jamf
118
118
  # create a getter for an attribute, and any aliases needed
119
119
  ##############################
120
120
  def self.create_getters(attr_name, attr_def)
121
+ # if the getter has already been defined, don't overwrite it
122
+ return if instance_methods.include? attr_name.to_sym
123
+
121
124
  # multi_value - only return a frozen dup, no direct editing of the Array
122
125
  if attr_def[:multi]
123
126
  define_method(attr_name) do
@@ -139,6 +142,11 @@ module Jamf
139
142
  # create setter(s) for an attribute, and any aliases needed
140
143
  ##############################
141
144
  def self.create_setters(attr_name, attr_def)
145
+ setter_method_name = "#{attr_name}="
146
+
147
+ # if the setter has already been defined, don't overwrite it
148
+ return if instance_methods.include? setter_method_name.to_sym
149
+
142
150
  # multi_value
143
151
  if attr_def[:multi]
144
152
  create_array_setters(attr_name, attr_def)
@@ -146,7 +154,7 @@ module Jamf
146
154
  end
147
155
 
148
156
  # single value
149
- define_method("#{attr_name}=") do |new_value|
157
+ define_method(setter_method_name) do |new_value|
150
158
  new_value = validate_attr attr_name, new_value
151
159
  old_value = instance_variable_get("@#{attr_name}")
152
160
  return if new_value == old_value
@@ -345,6 +353,11 @@ module Jamf
345
353
  # @return [Hash]
346
354
  attr_reader :init_data
347
355
 
356
+ # If this is true, we are being created via the .create method
357
+ # and not fetched from the API.
358
+ # @return [Boolean]
359
+ attr_reader :creating_from_create
360
+
348
361
  # Constructor
349
362
  #####################################
350
363
 
@@ -356,9 +369,9 @@ module Jamf
356
369
  @init_data = data
357
370
 
358
371
  # creating a new one via ruby-jss, not fetching one from the API
359
- creating = data.delete :creating_from_create if data.is_a?(Hash)
372
+ @creating_from_create = data.delete :creating_from_create if data.is_a?(Hash)
360
373
 
361
- if creating
374
+ if @creating_from_create
362
375
  self.class::OAPI_PROPERTIES.each_key do |attr_name|
363
376
  # we'll enforce required values when we save
364
377
  next unless data.key? attr_name
@@ -226,7 +226,13 @@ module Jamf
226
226
 
227
227
  data = @cnx.jp_get "#{@query_path}&page=#{page_number}"
228
228
  data = data[:results]
229
- data.map! { |r| @instantiate.new r } if @instantiate
229
+
230
+ if @instantiate
231
+ data.map! do |r|
232
+ r[:cnx] = @cnx
233
+ @instantiate.new(**r)
234
+ end
235
+ end
230
236
 
231
237
  if increment_next
232
238
  @last_fetched_page = page_number
data/lib/jamf/utility.rb CHANGED
@@ -65,27 +65,33 @@ module Jamf
65
65
  #
66
66
  # 12 is the default for the current OS and higher
67
67
  # (and hoping apple doesn't release, e.g., 11.13)
68
+ #
69
+ # There is no 16-25 because in 2025 Apple changed the numbering
70
+ # scheme to match the year after release. So the OS released in
71
+ # 2025 is versino 26, not 16.
72
+ #
73
+ # This array should take us thru to 2039.
68
74
  MAC_OS_MAXS = {
69
75
  11 => 12,
70
76
  12 => 12,
71
77
  13 => 12,
72
78
  14 => 12,
73
79
  15 => 12,
74
- 16 => 12,
75
- 17 => 12,
76
- 18 => 12,
77
- 19 => 12,
78
- 20 => 12,
79
- 21 => 12,
80
- 22 => 12,
81
- 23 => 12,
82
- 24 => 12,
83
- 25 => 12,
84
80
  26 => 12,
85
81
  27 => 12,
86
82
  28 => 12,
87
83
  29 => 12,
88
- 30 => 12
84
+ 30 => 12,
85
+ 31 => 12,
86
+ 32 => 12,
87
+ 33 => 12,
88
+ 34 => 12,
89
+ 35 => 12,
90
+ 36 => 12,
91
+ 37 => 12,
92
+ 38 => 12,
93
+ 39 => 12,
94
+ 40 => 12
89
95
  }
90
96
 
91
97
  # Converts an OS Version into an Array of equal or higher OS versions, up to
@@ -188,7 +194,7 @@ module Jamf
188
194
  # e.g. 11.x, or 11.x.x
189
195
  # expand to 11.x, 12.x, 13.x, ... 30.x
190
196
  if minor == 'x'
191
- ((major.to_i)..MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" }
197
+ ((major.to_i)..MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" unless (16..25).include?(v) } # skip 16-25
192
198
 
193
199
  # e.g. 11.2.x
194
200
  # expand to 11.2.x, 11.3.x, ... 11.12.x,
@@ -202,7 +208,7 @@ module Jamf
202
208
  end # each m
203
209
 
204
210
  # then add the majors out to 20
205
- ((major.to_i + 1)...MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" }
211
+ ((major.to_i + 1)...MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" unless (16..25).include?(v) }
206
212
 
207
213
  # e.g. 11.2.3
208
214
  # expand to 11.2.3, 11.2.4, ... 11.2.10,
@@ -219,7 +225,7 @@ module Jamf
219
225
  ((minor.to_i + 1)..max_minor_for_major).each { |min| ok_oses << "#{major}.#{min}.x" }
220
226
 
221
227
  # then add the majors out to 20
222
- ((major.to_i + 1)..MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" }
228
+ ((major.to_i + 1)..MAC_OS_MAXS.keys.max).each { |v| ok_oses << "#{v}.x" unless (16..25).include?(v) }
223
229
  end
224
230
 
225
231
  ok_oses
data/lib/jamf/version.rb CHANGED
@@ -27,6 +27,6 @@
27
27
  module Jamf
28
28
 
29
29
  ### The version of ruby-jss
30
- VERSION = '4.2.0'.freeze
30
+ VERSION = '4.2.1'.freeze
31
31
 
32
32
  end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-jss
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Lasell
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-06-12 00:00:00.000000000 Z
12
+ date: 2025-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: CFPropertyList