ruby-jss 0.10.0a3 → 0.10.0

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7727d3ed2d2b1be1f06c518739e40ca271fdc2a2
4
- data.tar.gz: 3f2b112e349629a2832e3de91fc8b5ac7425d02a
3
+ metadata.gz: 769cbc0fa921b444480b1c3b588664c3c3937aa7
4
+ data.tar.gz: 4a4d8ab91135e180d49e52e2be783019cb42e978
5
5
  SHA512:
6
- metadata.gz: 8d4dfa7278b3ec4542c2f4004648e52730d4a9791754b4b91401e68b51c07682c61c53b58e114061cd46cdc9cb008260e37b056d732017ee31089118d9d6f0f5
7
- data.tar.gz: 636c0dc8dfe3c41d75a2d11239cd4be4d92682d09958baf3f89e1c5038fcd401c605efd27c8b1e171f210453901470b0d139d50931b2c4c25cb9d949e6e85cf9
6
+ metadata.gz: '069697c8db875ece53b7490a7ec095d695d2852dd1c6d20acc4a6d4a0acdcc4a59f7e978b8408f03796b52f9713991c2345f716aef964bf08bcfea364b384887'
7
+ data.tar.gz: 7de60430c90c5ce3f7f92afdb75307e1a8798d22ba75868dd6702970d829c81143943da96fc759612cf9d477e0fc6535e77bb793865ffe22b94efdf6f95d9ffc
data/CHANGES.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # Change History
2
2
 
3
- ## v0.10.0a2 2017-08-17 (pre release)
4
-
5
- - Fix: require 'English', rather than require 'english'. Thanks to HIMANSHU-ELIGIBLE @ github for catching & fixing this one.
6
-
7
- ## v0.10.0a1 2017-08-15 (pre release)
3
+ ## v0.10.0 2017-10-09
8
4
 
9
5
  - Improvement: Working with multiple APIConnections is now far more flexible!
10
6
 
@@ -16,6 +12,17 @@
16
12
  The default/active connection continues to work as always, so your existing code will be fine.
17
13
  See the [documentation for the JSS::APIConnection class](http://www.rubydoc.info/gems/ruby-jss/JSS/APIConnection) for details.
18
14
  - Fix: Specifying port 443, as well as 8443, when connecting an APIConnection will default to using SSL. To force such a connection to NOT use SSL, provide the parameter `use_ssl: false`
15
+ - Fix: require 'English', rather than require 'english'. Thanks to HIMANSHU-ELIGIBLE @ github for catching & fixing this one.
16
+ - Fix: Popup extension attributes can always take a blank value.
17
+ - Fix: UserGroup members have a 'username' value, not 'name'
18
+ - Add: Two case-insentive string methods added to Array:
19
+ - Array#jss_ci_include_string? Takes a string, returns true if the Array contains the string without regard to case.
20
+ E.g. `['ThrAsHer'].jss_ci_include_string? 'thrasher' # => true`
21
+ - Array#jss_ci_fetch_string Takes a string and fetches it from the array, regardless of case. Nil if not found.
22
+ E.g. `['thrasher'].jss_ci_fetch_string 'ThrAsHer' # => 'thrasher'`
23
+ - Fix: APIConnection.map_all_ids wasn't honoring :refresh
24
+ - Improvement: Extendable module: only push changed EAs when `update` is called.
25
+ - Add: Computer objects now have a `last_enrolled` attribute
19
26
 
20
27
  ## v0.9.3 2017-08-08
21
28
 
data/lib/jss.rb CHANGED
@@ -77,6 +77,9 @@ module JSS
77
77
  ### When parsing a date/time data into a Time object, these will return nil
78
78
  NIL_DATES = [0, nil, '', '0'].freeze
79
79
 
80
+ ### Empty strings are used in various places
81
+ BLANK = ''.freeze
82
+
80
83
  ### Module Variables
81
84
  #####################################
82
85
 
@@ -658,7 +658,7 @@ module JSS
658
658
  def map_all_ids(class_name, refresh = false, to: nil)
659
659
  raise "'to:' value must be provided for mapping ids." unless to
660
660
  the_class = JSS.api_object_class(class_name)
661
- the_class.map_all_ids_to to, api: self
661
+ the_class.map_all_ids_to to, refresh, api: self
662
662
  end
663
663
 
664
664
  # Call the 'valid_id' method on a JSS::APIObject subclass
@@ -444,7 +444,7 @@ module JSS
444
444
  # pass to .new
445
445
  if arg.is_a? Hash
446
446
  raise ArgumentError, 'Use .make to create new JSS objects' if arg[:id] == :new
447
- api = arg[:api] if arg[:api]
447
+ arg[:api] ||= api
448
448
  return new arg
449
449
  end
450
450
 
@@ -452,7 +452,7 @@ module JSS
452
452
  # and if it's result includes the desired value,
453
453
  # the pass they key and arg to .new
454
454
  lookup_key_list_methods.each do |key, method_name|
455
- return new ({ key => arg, :api => api }) if method_name && send(method_name).include?(arg)
455
+ return new(key => arg, :api => api) if method_name && send(method_name).include?(arg)
456
456
  end # each key
457
457
 
458
458
  # if we're here, we couldn't find a matching object
@@ -610,10 +610,10 @@ module JSS
610
610
  #
611
611
  def save
612
612
  if @in_jss
613
- raise JSS::UnsupportedError, 'Updating this object in the JSS is currently not supported' unless updatable?
613
+ raise JSS::UnsupportedError, 'Updating this object in the JSS is currently not supported by ruby-jss' unless updatable?
614
614
  update
615
615
  else
616
- raise JSS::UnsupportedError, 'Creating this object in the JSS is currently not supported' unless creatable?
616
+ raise JSS::UnsupportedError, 'Creating this object in the JSS is currently not supported by ruby-jss' unless creatable?
617
617
  create
618
618
  end
619
619
  end
@@ -53,8 +53,7 @@ module JSS
53
53
  RSRC_BASE = 'advancedmobiledevicesearches'.freeze
54
54
 
55
55
  # the hash key used for the JSON list output of all objects in the JSS
56
- # NOTE - THIS IS A BUG, it should be advanced_mobile_device_searches
57
- RSRC_LIST_KEY = :advanced_computer_searches
56
+ RSRC_LIST_KEY = :advanced_mobile_device_searches
58
57
 
59
58
  # The hash key used for the JSON object output.
60
59
  # It's also used in various error messages
@@ -540,6 +540,9 @@ module JSS
540
540
  # @return [Time] the last contact time
541
541
  attr_reader :last_contact_time
542
542
 
543
+ # @return [Time] the last time this machine was enrolled
544
+ attr_reader :last_enrolled
545
+
543
546
  # @return [String] the primary macaddress
544
547
  attr_reader :mac_address
545
548
 
@@ -743,6 +746,7 @@ module JSS
743
746
  @barcode_2 = @init_data[:general][:barcode_2]
744
747
  @distribution_point = @init_data[:general][:distribution_point]
745
748
  @initial_entry_date = JSS.epoch_to_time @init_data[:general][:initial_entry_date_epoch]
749
+ @last_enrolled = JSS.epoch_to_time @init_data[:general][:last_enrolled_date_epoch]
746
750
  @ip_address = @init_data[:general][:ip_address]
747
751
  @jamf_version = @init_data[:general][:jamf_version]
748
752
  @last_contact_time = JSS.epoch_to_time @init_data[:general][:last_contact_time_epoch]
@@ -94,7 +94,7 @@ module JSS
94
94
  ### @return [void]
95
95
  ###
96
96
  def criteria= (new_criteria)
97
- unless new_criteria.is_a?(Array) && new_criteria.reject{ |c| c.is_a? JSS::Criteriable::Criterion }.empty?
97
+ unless new_criteria.is_a?(Array) && new_criteria.reject{ |c| c.is_a?(JSS::Criteriable::Criterion) }.empty?
98
98
  raise JSS::InvalidDataError, "Argument must be an Array of JSS::Criteriable::Criterion instances."
99
99
  end
100
100
  new_criteria.each{ |nc| criterion_ok? nc }
@@ -139,6 +139,11 @@ module JSS
139
139
  @ext_attrs[ea[:name]] = ea[:value]
140
140
 
141
141
  end # each do ea
142
+
143
+ # remember changes as they happen so
144
+ # we only send changes back to the server.
145
+ @changed_eas = []
146
+
142
147
  end
143
148
 
144
149
  ###
@@ -159,6 +164,9 @@ module JSS
159
164
  ###
160
165
  def set_ext_attr(name, value)
161
166
 
167
+ # if we don't currently have any need to update(cuz we have recently), reset the list of changes to push
168
+ @changed_eas = [] unless @need_to_update
169
+
162
170
  # this will raise an exception if the name doesn't exist
163
171
  ea_def = self.class::EXT_ATTRIB_CLASS.new :name => name
164
172
 
@@ -184,8 +192,9 @@ module JSS
184
192
  ea[:value] = value if ea[:name] == name
185
193
  end
186
194
  @ext_attrs[name] = value
187
-
195
+ @changed_eas << name
188
196
  @need_to_update = true
197
+
189
198
  end
190
199
 
191
200
  ###
@@ -195,10 +204,10 @@ module JSS
195
204
  ### included in the rest_xml of objects that mix-in this module.
196
205
  ###
197
206
  def ext_attr_xml
198
-
207
+ @changed_eas ||= []
199
208
  eaxml = REXML::Element.new('extension_attributes')
200
-
201
209
  @extension_attributes.each do |ea|
210
+ next unless @changed_eas.include? ea[:name]
202
211
  ea_el = eaxml.add_element('extension_attribute')
203
212
  ea_el.add_element('name').text = ea[:name]
204
213
 
@@ -99,6 +99,9 @@ module JSS
99
99
  ### These input types can be modified, the others cannot.
100
100
  EDITABLE_INPUT_TYPES = ["Text Field", "Pop-up Menu"]
101
101
 
102
+ ### Popup choices can, for now, take empty strings
103
+ BLANK = ''.freeze
104
+
102
105
  ### Where can it be displayed in the WebApp?
103
106
  ### subclasses can add to this list
104
107
  WEB_DISPLAY_CHOICES = [
@@ -162,6 +165,8 @@ module JSS
162
165
  if @init_data[:input_type]
163
166
  @input_type = @init_data[:input_type][:type] || DEFAULT_INPUT_TYPE
164
167
  @popup_choices = @init_data[:input_type][:popup_choices]
168
+ # popups can always contain blank
169
+ @popup_choices << JSS::BLANK if @popup_choices
165
170
  else
166
171
  @input_type = DEFAULT_INPUT_TYPE
167
172
  end
@@ -391,7 +396,7 @@ module JSS
391
396
 
392
397
  begin
393
398
  search_class = self.class::TARGET_CLASS::SEARCH_CLASS
394
- acs = search_class.new id: :new, name: tmp_advsrch, api: @api
399
+ acs = search_class.make name: tmp_advsrch, api: @api
395
400
  acs.display_fields = self.class::TARGET_CLASS == JSS::User ? [@name, USERNAME_FIELD] : [@name, USERNAME_FIELD, LAST_RECON_FIELD]
396
401
 
397
402
  # search for 'Username like "" ' because all searchable object classes have a "Username" value
@@ -416,7 +421,7 @@ module JSS
416
421
 
417
422
  ensure
418
423
  if defined? acs
419
- acs.delete
424
+ acs.delete if acs
420
425
  else
421
426
  search_class.fetch(:name => tmp_advsrch, api: @api).delete if search_class.all_names(:refresh, api: @api).include? tmp_advsrch
422
427
  end
@@ -279,7 +279,7 @@ module JSS
279
279
  def remove_member(m)
280
280
  raise InvalidDataError, "Smart group members can't be changed." if @is_smart
281
281
 
282
- if @members.reject!{ |mm| [mm[:id], mm[:name]].include? m }
282
+ if @members.reject!{ |mm| [mm[:id], mm[:name], mm[:username]].include? m }
283
283
  @need_to_update = true
284
284
  else
285
285
  raise JSS::NoSuchItemError, "No member matches '#{m}'"
@@ -27,7 +27,6 @@
27
27
  ### if they are type coercions, "to_jss_"
28
28
  ###
29
29
 
30
- ###
31
30
  require "jss/ruby_extensions/filetest.rb"
32
31
  require "jss/ruby_extensions/hash.rb"
33
32
  require "jss/ruby_extensions/ipaddr.rb"
@@ -35,3 +34,4 @@ require "jss/ruby_extensions/object.rb"
35
34
  require "jss/ruby_extensions/pathname.rb"
36
35
  require "jss/ruby_extensions/time.rb"
37
36
  require "jss/ruby_extensions/string.rb"
37
+ require "jss/ruby_extensions/array.rb"
@@ -0,0 +1,52 @@
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
+ class Array
28
+
29
+ # A case-insensitive version of #include? for Arrays of Strings.
30
+ #
31
+ # @param somestring [String] the String to search for
32
+ #
33
+ # @return [Boolean] Does the Array contain the String, ignoring case?
34
+ #
35
+ def jss_ci_include_string?(somestring)
36
+ any? { |s| s.to_s.casecmp(somestring).zero? }
37
+ end
38
+
39
+ # Fetch a string from an Array of Strings case-insensitively,
40
+ # e.g. my_array.jss_ci_fetch_string('ThRashEer') will return 'thrasher'
41
+ # or nil if no match
42
+ #
43
+ # @param somestring [String] the String to search for
44
+ #
45
+ # @return [String, nil] The matching string as it exists in the Array, nil if it doesn't exist
46
+ #
47
+ def jss_ci_fetch_string(somestring)
48
+ idx = index { |s| s.to_s.casecmp(somestring).zero? }
49
+ idx ? self[idx] : nil
50
+ end
51
+
52
+ end # class
@@ -27,6 +27,6 @@
27
27
  module JSS
28
28
 
29
29
  ### The version of the JSS ruby gem
30
- VERSION = '0.10.0a3'.freeze
30
+ VERSION = '0.10.0'.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: 0.10.0a3
4
+ version: 0.10.0
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: 2017-08-22 00:00:00.000000000 Z
12
+ date: 2017-10-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist
@@ -172,6 +172,7 @@ files:
172
172
  - lib/jss/db_connection.rb
173
173
  - lib/jss/exceptions.rb
174
174
  - lib/jss/ruby_extensions.rb
175
+ - lib/jss/ruby_extensions/array.rb
175
176
  - lib/jss/ruby_extensions/filetest.rb
176
177
  - lib/jss/ruby_extensions/hash.rb
177
178
  - lib/jss/ruby_extensions/ipaddr.rb
@@ -204,9 +205,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
205
  version: 1.9.3
205
206
  required_rubygems_version: !ruby/object:Gem::Requirement
206
207
  requirements:
207
- - - ">"
208
+ - - ">="
208
209
  - !ruby/object:Gem::Version
209
- version: 1.3.1
210
+ version: '0'
210
211
  requirements: []
211
212
  rubyforge_project:
212
213
  rubygems_version: 2.6.8