jss-api 0.5.7 → 0.5.8

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.
data/CHANGES.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Change History
2
2
 
3
+ v0.5.8 2015-09-22
4
+
5
+ bugfixes & cleanup
6
+ - location.rb: location value setters are now properly converted to strings
7
+ - api_connection.rb: #connect now takes :use_ssl option (defaults to true)
8
+ - api_connection.rb: #connect will accept arbitrary ports when :use_ssl is true
9
+
10
+ additions & features
11
+ - client.rb: looks for the new ElCap+ location for the jamf binary, falls back to old location if not found.
12
+ - Locatable#clear_location public instance method added
13
+ - TimeoutError and AuthenticationError have been added to exceptions
14
+ - Policy objects now have a #run method - attempts to execute the policy locally.
15
+
3
16
  v0.5.7 2015-05-26
17
+
4
18
  bugfixes & cleanup
5
19
  - JSS.to_s_and_a now properly converts nils to "" and []
6
20
  - DBConnection.connect gracefully handle reconnecting if the old connection went away
@@ -13,6 +27,7 @@ bugfixes & cleanup
13
27
  - Package#upload_master_file: move autoupdate to appropriate location
14
28
 
15
29
  v0.5.6 2014-11-04
30
+
16
31
  - now requires Ruby >= 1.9.3 and rest-client >= 1.7.0. Needed for Casper >= 9.61's lack of support for SSLv3.
17
32
  - APIConnection now accepts :ssl_version option in the argument hash. Defaults to 'TLSv1'
18
33
  - Configuration now supports the api_ssl_version key, used for the :ssl_version option of the APIConnection.
@@ -21,4 +36,5 @@ v0.5.6 2014-11-04
21
36
  - minor bugfixes
22
37
 
23
38
  v0.5.0 2014-10-23
39
+
24
40
  - first opensource release
data/README.md CHANGED
@@ -371,7 +371,7 @@ If you're using Ruby 1.8.7 (Casper 9.4 - 9.6 only), install the following gems m
371
371
 
372
372
  ## LICENSE
373
373
 
374
- Copyright 2014 Pixar
374
+ Copyright 2015 Pixar
375
375
 
376
376
  Licensed under the Apache License, Version 2.0 (the "Apache License")
377
377
  with the following modification; you may not use this file except in
@@ -121,7 +121,6 @@ module JSS
121
121
  ### Class Variables
122
122
  #####################################
123
123
 
124
- ###
125
124
  ### This Hash holds the most recent API query for a list of all items in any subclass,
126
125
  ### keyed by the subclass's RSRC_LIST_KEY. See the self.all class method.
127
126
  ###
@@ -236,7 +235,27 @@ module JSS
236
235
  self.all(refresh).each{|i| h[i[:id]] = i[other_key]}
237
236
  h
238
237
  end
239
-
238
+
239
+
240
+ ### Return an Array of JSS::APIObject subclass instances
241
+ ### e.g when called on JSS::Package, return all JSS::Package
242
+ ### objects in the JSS.
243
+ ###
244
+ ### NOTE: This may be slow as it has to look up each object individually!
245
+ ### use it wisely.
246
+ ###
247
+ ### @param refresh[Boolean] should the data re-queried from the API?
248
+ ###
249
+ ### @return [Hash{Integer => Object}] the objects requested
250
+ def self.all_objects(refresh = false)
251
+ objects_key = "#{self::RSRC_LIST_KEY}_objects".to_sym
252
+ @@all_items[objects_key] = nil if refresh
253
+ return @@all_items[objects_key] if @@all_items[objects_key]
254
+ @@all_items[objects_key] = self.all(refresh = false).map{|o| self.new :id => o[:id]}
255
+ end
256
+
257
+
258
+
240
259
  ###
241
260
  ### Convert an Array of Hashes of API object data to a
242
261
  ### REXML element.
@@ -159,8 +159,8 @@ module JSS
159
159
  ###
160
160
  def building= (new_val)
161
161
  return nil if @building == new_val
162
- new_val.strip!
163
- raise JSS::NoSuchItemError, "No building named #{new_val} exists in the JSS" unless JSS::Building.all_names.include? new_val
162
+ new_val = new_val.to_s.strip
163
+ raise JSS::NoSuchItemError, "No building named #{new_val} exists in the JSS" unless new_val.empty? or JSS::Building.all_names.include? new_val
164
164
  @building = new_val
165
165
  @need_to_update = true
166
166
  end
@@ -168,8 +168,8 @@ module JSS
168
168
  ###
169
169
  def department= (new_val)
170
170
  return nil if @department == new_val
171
- new_val.strip!
172
- raise JSS::NoSuchItemError, "No department named #{new_val} exists in the JSS" unless JSS::Department.all_names.include? new_val
171
+ new_val = new_val.to_s.strip
172
+ raise JSS::NoSuchItemError, "No department named #{new_val} exists in the JSS" unless new_val.empty? or JSS::Department.all_names.include? new_val
173
173
  @department = new_val
174
174
  @need_to_update = true
175
175
  end
@@ -177,8 +177,8 @@ module JSS
177
177
  ###
178
178
  def email_address= (new_val)
179
179
  return nil if @email_address == new_val
180
- new_val.strip!
181
- raise JSS::InvalidDataError, "Invalid Email Address" unless new_val =~ /^[^\s@]+@[^\s@]+$/
180
+ new_val = new_val.to_s.strip
181
+ raise JSS::InvalidDataError, "Invalid Email Address" unless new_val.empty? or new_val =~ /^[^\s@]+@[^\s@]+$/
182
182
  @email_address = new_val
183
183
  @need_to_update = true
184
184
  end
@@ -186,7 +186,7 @@ module JSS
186
186
  ###
187
187
  def position= (new_val)
188
188
  return nil if @position == new_val
189
- new_val.strip!
189
+ new_val = new_val.to_s.strip
190
190
  @position = new_val
191
191
  @need_to_update = true
192
192
  end
@@ -194,7 +194,7 @@ module JSS
194
194
  ###
195
195
  def phone= (new_val)
196
196
  return nil if @phone == new_val
197
- new_val.strip!
197
+ new_val = new_val.to_s.strip
198
198
  @phone = new_val
199
199
  @need_to_update = true
200
200
  end
@@ -202,7 +202,7 @@ module JSS
202
202
  ###
203
203
  def real_name= (new_val)
204
204
  return nil if @real_name == new_val
205
- new_val.strip!
205
+ new_val = new_val.to_s.strip
206
206
  @real_name = new_val
207
207
  @need_to_update = true
208
208
  end
@@ -210,7 +210,7 @@ module JSS
210
210
  ###
211
211
  def room= (new_val)
212
212
  return nil if @room == new_val
213
- new_val.strip!
213
+ new_val = new_val.to_s.strip
214
214
  @room = new_val
215
215
  @need_to_update = true
216
216
  end
@@ -218,7 +218,7 @@ module JSS
218
218
  ###
219
219
  def username= (new_val)
220
220
  return nil if @username == new_val
221
- new_val.strip!
221
+ new_val = new_val.to_s.strip
222
222
  @username = new_val
223
223
  @need_to_update = true
224
224
  end
@@ -237,6 +237,24 @@ module JSS
237
237
  @room
238
238
  end
239
239
 
240
+ ###
241
+ ### Clear all location data
242
+ ###
243
+ ### @return [void]
244
+ ###
245
+ def clear_location
246
+ @username = ''
247
+ @real_name = ''
248
+ @email_address = ''
249
+ @position = ''
250
+ @phone = ''
251
+ @department = ''
252
+ @building = ''
253
+ @room = ''
254
+ @need_to_update = true
255
+ end
256
+
257
+
240
258
  ### aliases
241
259
  alias user username
242
260
 
@@ -843,12 +843,28 @@ module JSS
843
843
  ### @return [Boolean] is this policy available in SelfService?
844
844
  def self_service?; @self_service[:use_for_self_service] ; end
845
845
 
846
+ ### Try to execute this policy on this machine.
847
+ ###
848
+ ### @param show_output[Boolean] should the stdout and stderr of the
849
+ ### 'jamf policy' command be sent to stdout in realtime?
850
+ ###
851
+ ### @return [Boolean, nil] The success of the 'jamf policy' command, or nil
852
+ ### if the policy couldn't be executed (out of scope, policy disabled, etc)
853
+ ###
854
+ def run (show_output = false)
855
+ return nil unless enabled?
856
+ output = JSS::Client.run_jamf("policy", "-id #{id}", show_output)
857
+ return nil if output.include? 'No policies were found for the ID'
858
+ return $?.exitstatus == 0 ? true : false
859
+ end
860
+
846
861
  ### Aliases
847
862
  alias enabled? enabled
848
863
  alias pkgs packages
849
864
  alias command_to_run run_command
850
865
  alias delete_path? delete_file?
851
-
866
+ alias execute run
867
+
852
868
  #####################################
853
869
  ### Private Instance Methods
854
870
  #####################################
@@ -54,7 +54,10 @@ module JSS
54
54
  #####################################
55
55
 
56
56
  ### The Pathname to the jamf binary executable
57
- JAMF_BINARY = Pathname.new "/usr/sbin/jamf"
57
+ ### As of El Capitan (OS X 10.11) the location has moved.
58
+ ORIG_JAMF_BINARY = Pathname.new "/usr/sbin/jamf"
59
+ ELCAP_JAMF_BINARY = Pathname.new "/usr/local/sbin/jamf"
60
+ JAMF_BINARY = ELCAP_JAMF_BINARY.executable? ? ELCAP_JAMF_BINARY : ORIG_JAMF_BINARY
58
61
 
59
62
  ### The Pathname to the jamfHelper executable
60
63
  JAMF_HELPER = Pathname.new "/Library/Application Support/JAMF/bin/jamfHelper.app/Contents/MacOS/jamfHelper"
@@ -80,4 +80,16 @@ module JSS
80
80
  ###
81
81
  class UnsupportedError < RuntimeError; end
82
82
 
83
+ ###
84
+ ### TimeoutError - raise this when we
85
+ ### try to do and it times out
86
+ ###
87
+ class TimeoutError < RuntimeError; end
88
+
89
+ ###
90
+ ### AuthenticationError - raise this when
91
+ ### a name/pw are wrong
92
+ ###
93
+ class AuthenticationError < RuntimeError; end
94
+
83
95
  end # module JSS
@@ -93,7 +93,7 @@ module JSS
93
93
  @version = parsed[:version]
94
94
 
95
95
  rescue RestClient::Request::Unauthorized
96
- raise JSS::InvalidConnectionError, "Incorrect JSS username or password for '#{JSS::API.jss_user}'."
96
+ raise JSS::AuthenticationError, "Incorrect JSS username or password for '#{JSS::API.jss_user}@#{JSS::API.server_host}'."
97
97
  end
98
98
 
99
99
  end
@@ -26,6 +26,6 @@
26
26
  module JSS
27
27
 
28
28
  ### The version of the JSS ruby gem
29
- VERSION = "0.5.7"
29
+ VERSION = "0.5.8"
30
30
 
31
31
  end # module
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jss-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-26 00:00:00.000000000 Z
12
+ date: 2015-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: plist