jss-api 0.5.8 → 0.6.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.
- data/CHANGES.md +55 -7
- data/README.md +2 -1
- data/bin/cgrouper +1 -1
- data/bin/subnet-update +1 -1
- data/lib/jss-api.rb +2 -363
- data/lib/jss-api/api_connection.rb +78 -15
- data/lib/jss-api/api_object.rb +1 -1
- data/lib/jss-api/api_object/advanced_search.rb +1 -1
- data/lib/jss-api/api_object/advanced_search/advanced_computer_search.rb +1 -1
- data/lib/jss-api/api_object/advanced_search/advanced_mobile_device_search.rb +1 -1
- data/lib/jss-api/api_object/advanced_search/advanced_user_search.rb +1 -1
- data/lib/jss-api/api_object/building.rb +1 -1
- data/lib/jss-api/api_object/category.rb +1 -1
- data/lib/jss-api/api_object/computer.rb +1 -1
- data/lib/jss-api/api_object/creatable.rb +1 -1
- data/lib/jss-api/api_object/criteriable.rb +1 -1
- data/lib/jss-api/api_object/criteriable/criteria.rb +1 -1
- data/lib/jss-api/api_object/criteriable/criterion.rb +1 -1
- data/lib/jss-api/api_object/department.rb +1 -1
- data/lib/jss-api/api_object/distribution_point.rb +92 -22
- data/lib/jss-api/api_object/extendable.rb +1 -1
- data/lib/jss-api/api_object/extension_attribute.rb +1 -1
- data/lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb +1 -1
- data/lib/jss-api/api_object/extension_attribute/mobile_device_extension_attribute.rb +1 -1
- data/lib/jss-api/api_object/extension_attribute/user_extension_attribute.rb +1 -1
- data/lib/jss-api/api_object/group.rb +1 -1
- data/lib/jss-api/api_object/group/computer_group.rb +1 -1
- data/lib/jss-api/api_object/group/mobile_device_group.rb +1 -1
- data/lib/jss-api/api_object/group/user_group.rb +1 -1
- data/lib/jss-api/api_object/ldap_server.rb +1 -1
- data/lib/jss-api/api_object/locatable.rb +1 -1
- data/lib/jss-api/api_object/matchable.rb +1 -1
- data/lib/jss-api/api_object/mobile_device.rb +1 -1
- data/lib/jss-api/api_object/netboot_server.rb +1 -1
- data/lib/jss-api/api_object/network_segment.rb +1 -1
- data/lib/jss-api/api_object/osx_configuration_profile.rb +1 -1
- data/lib/jss-api/api_object/package.rb +117 -64
- data/lib/jss-api/api_object/peripheral.rb +1 -1
- data/lib/jss-api/api_object/peripheral_type.rb +1 -1
- data/lib/jss-api/api_object/policy.rb +1 -1
- data/lib/jss-api/api_object/purchasable.rb +1 -1
- data/lib/jss-api/api_object/removable_macaddr.rb +1 -1
- data/lib/jss-api/api_object/scopable.rb +1 -1
- data/lib/jss-api/api_object/scopable/scope.rb +1 -1
- data/lib/jss-api/api_object/script.rb +1 -1
- data/lib/jss-api/api_object/self_servable.rb +1 -1
- data/lib/jss-api/api_object/site.rb +1 -1
- data/lib/jss-api/api_object/software_update_server.rb +1 -1
- data/lib/jss-api/api_object/updatable.rb +1 -1
- data/lib/jss-api/api_object/uploadable.rb +1 -1
- data/lib/jss-api/api_object/user.rb +1 -1
- data/lib/jss-api/client.rb +22 -21
- data/lib/jss-api/compatibility.rb +1 -1
- data/lib/jss-api/composer.rb +2 -2
- data/lib/jss-api/configuration.rb +1 -1
- data/lib/jss-api/db_connection.rb +63 -12
- data/lib/jss-api/exceptions.rb +1 -1
- data/lib/jss-api/ruby_extensions.rb +1 -1
- data/lib/jss-api/ruby_extensions/filetest.rb +1 -1
- data/lib/jss-api/ruby_extensions/hash.rb +1 -1
- data/lib/jss-api/ruby_extensions/ipaddr.rb +1 -1
- data/lib/jss-api/ruby_extensions/pathname.rb +1 -1
- data/lib/jss-api/ruby_extensions/string.rb +17 -1
- data/lib/jss-api/ruby_extensions/time.rb +1 -1
- data/lib/jss-api/server.rb +1 -1
- data/lib/jss-api/utility.rb +416 -0
- data/lib/jss-api/version.rb +8 -8
- metadata +3 -2
data/CHANGES.md
CHANGED
@@ -1,21 +1,69 @@
|
|
1
1
|
# Change History
|
2
2
|
|
3
|
-
v0.
|
3
|
+
## v0.6.1 2016-03-01
|
4
|
+
|
5
|
+
#### additions & features
|
6
|
+
|
7
|
+
- JSS::Package#install now takes :alt_download_url argument.Can be used to specify a custom URL from which to download a pkg/dmg for installation with 'jamf install'. This allows the use of cloud distribution points.
|
8
|
+
- JSS::DistributionPoint: Added reachability methods, improved assessment of mount-success. #reachable_for_download? and #reachable_for_upload? will now return a boolean indicating if the DistPoint is reachable.
|
9
|
+
|
10
|
+
## v0.6.0 2016-01-06
|
11
|
+
|
12
|
+
This version of the jss-api gem incorporates changes needed for the upcoming release of d3 (a.k.a. depot3),
|
13
|
+
a package/patch management system for Casper, which was the reason for the jss-api gem to begin with.
|
14
|
+
|
15
|
+
As such, while the JSS module will continue to be a separate git repo, specific commits of it will be
|
16
|
+
submodules of the depot3 git repo, starting with this one, or one shortly hereafter.
|
17
|
+
|
18
|
+
|
19
|
+
#### bugfixes & cleanup
|
20
|
+
|
21
|
+
- new path to the jamf binary was corrected
|
22
|
+
- fixed the logic in using the :use_ssl arg to JSS::APIConnection::connect
|
23
|
+
- Composer module no longer adds redundant .pkg extensions
|
24
|
+
- JSS::DistributionPoint, bug fix when initializing with :id=>:master
|
25
|
+
- JSS::DistributionPoint: #mount now defaults to read-only unless :rw is passed
|
26
|
+
- String: added #jss_to_time to convertion strings to Time objects using JSS::parse_time
|
27
|
+
- JSS::Package: better handling of API values like "None" and "No category assigned"
|
28
|
+
- JSS::Package: added #type to return :pkg or :dmg
|
29
|
+
- JSS::Package: Changes to #install, including return value! See NOTES below.
|
30
|
+
- lots of code cleanup
|
31
|
+
|
32
|
+
#### additions & features
|
33
|
+
|
34
|
+
- JSS::APIConnection and JSS::DBConnection determines server hostname via several means if not yet connected
|
35
|
+
- JSS::APIConnection and JSS::DBConnection can test validitiy of a server
|
36
|
+
- JSS::DBConnection now has a DEFAULT_PORT constant
|
37
|
+
|
38
|
+
|
39
|
+
NOTES:
|
40
|
+
|
41
|
+
Important: Package#install now returns a boolean indicating success of installation.
|
42
|
+
The previous return value (the Process::Status of the 'jamf install' proceess) usually returned 0 exitstatus even if the pkg install failed.
|
43
|
+
Now the actual install command is examined, and if its exitstatus is zero, Package#install returns true, else false.
|
44
|
+
|
45
|
+
Also: As of casper 9.72, the argument requirements havechanged for 'jamf install' with http downloads. This is now handled correctly
|
46
|
+
|
47
|
+
|
48
|
+
## v0.5.8 2015-09-22
|
49
|
+
|
50
|
+
#### bugfixes & cleanup
|
4
51
|
|
5
|
-
bugfixes & cleanup
|
6
52
|
- location.rb: location value setters are now properly converted to strings
|
7
53
|
- api_connection.rb: #connect now takes :use_ssl option (defaults to true)
|
8
54
|
- api_connection.rb: #connect will accept arbitrary ports when :use_ssl is true
|
9
55
|
|
10
|
-
additions & features
|
56
|
+
#### additions & features
|
57
|
+
|
11
58
|
- client.rb: looks for the new ElCap+ location for the jamf binary, falls back to old location if not found.
|
12
59
|
- Locatable#clear_location public instance method added
|
13
60
|
- TimeoutError and AuthenticationError have been added to exceptions
|
14
61
|
- Policy objects now have a #run method - attempts to execute the policy locally.
|
15
62
|
|
16
|
-
v0.5.7 2015-05-26
|
63
|
+
## v0.5.7 2015-05-26
|
64
|
+
|
65
|
+
#### bugfixes & cleanup
|
17
66
|
|
18
|
-
bugfixes & cleanup
|
19
67
|
- JSS.to_s_and_a now properly converts nils to "" and []
|
20
68
|
- DBConnection.connect gracefully handle reconnecting if the old connection went away
|
21
69
|
- DBConnection.connect, and APIConnection.connect: include server name when prompting for password
|
@@ -26,7 +74,7 @@ bugfixes & cleanup
|
|
26
74
|
- Package#required_processor: remove buggy line of ancient, deprecated code
|
27
75
|
- Package#upload_master_file: move autoupdate to appropriate location
|
28
76
|
|
29
|
-
v0.5.6 2014-11-04
|
77
|
+
## v0.5.6 2014-11-04
|
30
78
|
|
31
79
|
- now requires Ruby >= 1.9.3 and rest-client >= 1.7.0. Needed for Casper >= 9.61's lack of support for SSLv3.
|
32
80
|
- APIConnection now accepts :ssl_version option in the argument hash. Defaults to 'TLSv1'
|
@@ -35,6 +83,6 @@ v0.5.6 2014-11-04
|
|
35
83
|
- many documentation updates as we adjust to being live
|
36
84
|
- minor bugfixes
|
37
85
|
|
38
|
-
v0.5.0 2014-10-23
|
86
|
+
## v0.5.0 2014-10-23
|
39
87
|
|
40
88
|
- first opensource release
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# The JSS API Ruby Gem - access to the Casper Suite from Ruby
|
2
|
+
[](http://badge.fury.io/rb/jss-api)
|
2
3
|
|
3
4
|
## DESCRIPTION
|
4
5
|
|
@@ -371,7 +372,7 @@ If you're using Ruby 1.8.7 (Casper 9.4 - 9.6 only), install the following gems m
|
|
371
372
|
|
372
373
|
## LICENSE
|
373
374
|
|
374
|
-
Copyright
|
375
|
+
Copyright 2016 Pixar
|
375
376
|
|
376
377
|
Licensed under the Apache License, Version 2.0 (the "Apache License")
|
377
378
|
with the following modification; you may not use this file except in
|
data/bin/cgrouper
CHANGED
data/bin/subnet-update
CHANGED
data/lib/jss-api.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### Copyright
|
1
|
+
### Copyright 2016 Pixar
|
2
2
|
###
|
3
3
|
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
4
4
|
### with the following modification; you may not use this file except in
|
@@ -84,368 +84,6 @@ module JSS
|
|
84
84
|
#####################################
|
85
85
|
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
###
|
90
|
-
### Given a list of data as a comma-separated string, or an Array of strings,
|
91
|
-
### return a Hash with both versions.
|
92
|
-
###
|
93
|
-
### Some parts of the JSS require lists as comma-separated strings, while
|
94
|
-
### often those data are easier work with as arrays. This method is a handy way
|
95
|
-
### to get either form when given either form.
|
96
|
-
###
|
97
|
-
### @param somedata [String, Array] the data to parse, of either class,
|
98
|
-
###
|
99
|
-
### @return [Hash{:stringform => String, :arrayform => Array}] the data as both comma-separated String and Array
|
100
|
-
###
|
101
|
-
### @example
|
102
|
-
### JSS.to_s_and_a "foo, bar, baz" # Hash => {:stringform => "foo, bar, baz", :arrayform => ["foo", "bar", "baz"]}
|
103
|
-
###
|
104
|
-
### JSS.to_s_and_a ["foo", "bar", "baz"] # Hash => {:stringform => "foo, bar, baz", :arrayform => ["foo", "bar", "baz"]}
|
105
|
-
###
|
106
|
-
def self.to_s_and_a (somedata)
|
107
|
-
case somedata
|
108
|
-
when nil
|
109
|
-
valstr = ""
|
110
|
-
valarr = []
|
111
|
-
when String
|
112
|
-
valstr = somedata
|
113
|
-
valarr = somedata.split(/,\s*/)
|
114
|
-
when Array
|
115
|
-
valstr = somedata.join ", "
|
116
|
-
valarr = somedata
|
117
|
-
else
|
118
|
-
raise JSS::InvalidDataError, "Input must be a comma-separated String or an Array of Strings"
|
119
|
-
end # case
|
120
|
-
return {:stringform => valstr, :arrayform => valarr}
|
121
|
-
end # to_s_and_a
|
122
|
-
|
123
|
-
###
|
124
|
-
### Converts an OS Version into an Array of higher OS versions.
|
125
|
-
###
|
126
|
-
### It's unlikely that this library will still be in use as-is by the release of OS X 10.19.15.
|
127
|
-
### Hopefully well before then JAMF will implement a "minimum OS" in the JSS itself.
|
128
|
-
###
|
129
|
-
### @param min_os [String] the mimimum OS version to expand, e.g. ">=10.6.7" or "10.6.7"
|
130
|
-
###
|
131
|
-
### @return [Array] Nearly all potential OS versions from the minimum to 10.19.x.
|
132
|
-
###
|
133
|
-
### @example
|
134
|
-
### JSS.expand_min_os ">=10.6.7" # => returns this array
|
135
|
-
### # ["10.6.7",
|
136
|
-
### # "10.6.8",
|
137
|
-
### # "10.6.9",
|
138
|
-
### # "10.6.10",
|
139
|
-
### # "10.6.11",
|
140
|
-
### # "10.6.12",
|
141
|
-
### # "10.6.13",
|
142
|
-
### # "10.6.14",
|
143
|
-
### # "10.6.15",
|
144
|
-
### # "10.7.x",
|
145
|
-
### # "10.8.x",
|
146
|
-
### # "10.9.x",
|
147
|
-
### # "10.10.x",
|
148
|
-
### # "10.11.x",
|
149
|
-
### # "10.12.x",
|
150
|
-
### # "10.13.x",
|
151
|
-
### # "10.14.x",
|
152
|
-
### # "10.15.x",
|
153
|
-
### # "10.16.x",
|
154
|
-
### # "10.17.x",
|
155
|
-
### # "10.18.x",
|
156
|
-
### # "10.19.x"]
|
157
|
-
###
|
158
|
-
###
|
159
|
-
def self.expand_min_os (min_os)
|
160
|
-
|
161
|
-
min_os.delete! ">="
|
162
|
-
|
163
|
-
### split the version into major, minor and maintenance release numbers
|
164
|
-
(maj,min,maint) = min_os.split(".")
|
165
|
-
maint = "x" if maint.nil? or maint == "0"
|
166
|
-
|
167
|
-
### if the maint release number is an "x" just start the list of OK OS's with it
|
168
|
-
if maint == "x"
|
169
|
-
ok_oses = [maj + "." + min.to_s + ".x"]
|
170
|
-
|
171
|
-
### otherwise, start with it and explicitly add all maint releases up to 15
|
172
|
-
### (and hope apple doesn't do more than 15 maint releases for an OS)
|
173
|
-
else
|
174
|
-
ok_oses = []
|
175
|
-
(maint.to_i..15).each do |m|
|
176
|
-
ok_oses << maj + "." + min +"." + m.to_s
|
177
|
-
end # each m
|
178
|
-
end
|
179
|
-
|
180
|
-
### now account for all OS X versions starting with 10.
|
181
|
-
### up to at least 10.19.x
|
182
|
-
((min.to_i + 1)..19).each do |v|
|
183
|
-
ok_oses << maj + "." + v.to_s + ".x"
|
184
|
-
end # each v
|
185
|
-
return ok_oses
|
186
|
-
end
|
187
|
-
|
188
|
-
###
|
189
|
-
### Converts anything that responds to #to_s to a Time, or nil
|
190
|
-
###
|
191
|
-
### Return nil if the item is nil, 0 or an empty String.
|
192
|
-
###
|
193
|
-
### Otherwise the item converted to a string, and parsed with DateTime.parse.
|
194
|
-
### It is then examined to see if it has a UTC offset. If not, the local offset
|
195
|
-
### is applied, then the DateTime is converted to a Time.
|
196
|
-
###
|
197
|
-
### @param a_datetime [#to_s] The thing to convert to a time.
|
198
|
-
###
|
199
|
-
### @return [Time, nil] nil is returned if a_datetime is nil, 0 or an empty String.
|
200
|
-
###
|
201
|
-
def self.parse_datetime(a_datetime)
|
202
|
-
return nil if NIL_DATES.include? a_datetime
|
203
|
-
|
204
|
-
the_dt = DateTime.parse(a_datetime.to_s)
|
205
|
-
|
206
|
-
### The microseconds in DateTimes are stored as a fraction of a day.
|
207
|
-
### Convert them to an integer of microseconds
|
208
|
-
usec = (the_dt.sec_fraction * 60 * 60 * 24 * (10**6)).to_i
|
209
|
-
|
210
|
-
### if the UTC offset of the datetime is zero, make a new one with the correct local offset
|
211
|
-
### (which might also be zero if we happen to be in GMT)
|
212
|
-
if the_dt.offset == 0
|
213
|
-
the_dt = DateTime.new(the_dt.year, the_dt.month, the_dt.day, the_dt.hour, the_dt.min, the_dt.sec, JSS::TIME_ZONE_OFFSET)
|
214
|
-
end
|
215
|
-
# now convert it to a Time and return it
|
216
|
-
Time.at the_dt.strftime('%s').to_i, usec
|
217
|
-
|
218
|
-
end #parse_datetime
|
219
|
-
|
220
|
-
###
|
221
|
-
### Converts JSS epoch (unix epoch + milliseconds) to a Ruby Time object
|
222
|
-
###
|
223
|
-
### @param epoch[String, Integer, nil]
|
224
|
-
###
|
225
|
-
### @return [Time, nil] nil is returned if epoch is nil, 0 or an empty String.
|
226
|
-
###
|
227
|
-
def self.epoch_to_time(epoch)
|
228
|
-
return nil if NIL_DATES.include? epoch
|
229
|
-
Time.at(epoch.to_i / 1000.0)
|
230
|
-
end #parse_date
|
231
|
-
|
232
|
-
|
233
|
-
###
|
234
|
-
### Given a string of xml element text, escape any characters that would make XML unhappy.
|
235
|
-
### * & => &
|
236
|
-
### * " => "
|
237
|
-
### * < => <
|
238
|
-
### * > => >
|
239
|
-
### * ' => '
|
240
|
-
###
|
241
|
-
### @param string [String] the string to make xml-compliant.
|
242
|
-
###
|
243
|
-
### @return [String] the xml-compliant string
|
244
|
-
###
|
245
|
-
def self.escape_xml(string)
|
246
|
-
string.gsub(/&/, '&').gsub(/\"/, '"').gsub(/>/, '>').gsub(/</, '<').gsub(/'/, ''')
|
247
|
-
end
|
248
|
-
|
249
|
-
###
|
250
|
-
### Given an element name and an array of content, generate an Array of
|
251
|
-
### REXML::Element objects with that name, and matching content.
|
252
|
-
### The array of REXML elements would render thus:
|
253
|
-
### <foo>bar</foo>
|
254
|
-
### <foo>morefoo</foo>
|
255
|
-
###
|
256
|
-
### @param element [#to_s] an element_name like :foo
|
257
|
-
###
|
258
|
-
### @param list [Array<#to_s>] an Array of element content such as ["bar", :morefoo]
|
259
|
-
###
|
260
|
-
### @return [Array<REXML::Element>]
|
261
|
-
###
|
262
|
-
def self.array_to_rexml_array(element,list)
|
263
|
-
raise JSS::InvalidDataError, "Arg. must be an Array." unless list.kind_of? Array
|
264
|
-
element = element.to_s
|
265
|
-
list.map do |v|
|
266
|
-
e = REXML::Element.new(element)
|
267
|
-
e.text = v
|
268
|
-
e
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
###
|
273
|
-
### Given a simple Hash, convert it to an array of REXML Elements such that each
|
274
|
-
### key becomes an element, and its value becomes the text content of
|
275
|
-
### that element
|
276
|
-
###
|
277
|
-
### @example
|
278
|
-
### my_hash = {:foo => "bar", :baz => :morefoo}
|
279
|
-
### xml = JSS.hash_to_rexml_array(my_hash)
|
280
|
-
### xml.each{|x| puts x }
|
281
|
-
###
|
282
|
-
### <foo>bar</foo>
|
283
|
-
### <baz>morefoo</baz>
|
284
|
-
###
|
285
|
-
### @param hash [Hash{#to_s => #to_s}] the Hash to convert
|
286
|
-
###
|
287
|
-
### @return [Array<REXML::Element>] the Array of REXML elements.
|
288
|
-
###
|
289
|
-
def self.hash_to_rexml_array(hash)
|
290
|
-
raise InvalidDataError, "Arg. must be a Hash." unless hash.kind_of? Hash
|
291
|
-
ary = []
|
292
|
-
hash.each_pair do |k,v|
|
293
|
-
el = REXML::Element.new k.to_s
|
294
|
-
el.text = v
|
295
|
-
ary << el
|
296
|
-
end
|
297
|
-
ary
|
298
|
-
end
|
299
|
-
|
300
|
-
|
301
|
-
###
|
302
|
-
### Given an Array of Hashes with :id and/or :name keys, return
|
303
|
-
### a single REXML element with a sub-element for each item,
|
304
|
-
### each of which contains a :name or :id element.
|
305
|
-
###
|
306
|
-
### @param list_element [#to_s] the name of the XML element that contains the list.
|
307
|
-
### e.g. :computers
|
308
|
-
###
|
309
|
-
### @param item_element [#to_s] the name of each XML element in the list,
|
310
|
-
### e.g. :computer
|
311
|
-
###
|
312
|
-
### @param item_list [Array<Hash>] an Array of Hashes each with a :name or :id key.
|
313
|
-
###
|
314
|
-
### @param content [Symbol] which hash key should be used as the content of if list item? Defaults to :name
|
315
|
-
###
|
316
|
-
### @return [REXML::Element] the item list as REXML
|
317
|
-
###
|
318
|
-
### @example
|
319
|
-
### comps = [{:id=>2,:name=>'kimchi'},{:id=>5,:name=>'mantis'}]
|
320
|
-
### xml = JSS.item_list_to_rexml_list(:computers, :computer , comps, :name)
|
321
|
-
### puts xml
|
322
|
-
### # output manually formatted for clarity. No newlines in the real xml string
|
323
|
-
### <computers>
|
324
|
-
### <computer>
|
325
|
-
### <name>kimchi</name>
|
326
|
-
### </computer>
|
327
|
-
### <computer>
|
328
|
-
### <name>mantis</name>
|
329
|
-
### </computer>
|
330
|
-
### </computers>
|
331
|
-
###
|
332
|
-
### # if content is :id, then, eg. <name>kimchi</name> would be <id>2</id>
|
333
|
-
###
|
334
|
-
def self.item_list_to_rexml_list(list_element, item_element , item_list, content = :name)
|
335
|
-
xml_list = REXML::Element.new list_element.to_s
|
336
|
-
item_list.each do |i|
|
337
|
-
xml_list.add_element(item_element.to_s).add_element(content.to_s).text = i[content]
|
338
|
-
end
|
339
|
-
xml_list
|
340
|
-
end
|
341
|
-
|
342
|
-
|
343
|
-
###
|
344
|
-
### Parse a JSS Version number into something comparable
|
345
|
-
###
|
346
|
-
### Unfortunately, the JSS version numbering is inconsistant and improper at the moment.
|
347
|
-
### Version 9.32 should be version 9.3.2, so that it
|
348
|
-
### will be recognizable as being less than 9.4
|
349
|
-
###
|
350
|
-
### To work around this until JAMF standardizes version numbering,
|
351
|
-
### we will assume any digits before the first dot is the major version
|
352
|
-
### and the first digit after the first dot is the minor version
|
353
|
-
### and anything else, including other dots, is the revision
|
354
|
-
###
|
355
|
-
### If that revision starts with a dot, it is removed.
|
356
|
-
### so 9.32 becomes major-9, minor-3, rev-2
|
357
|
-
### and 9.32.3764 becomes major-9, minor-3, rev-2.3764
|
358
|
-
### and 9.3.2.3764 becomes major-9, minor-3, rev-2.3764
|
359
|
-
###
|
360
|
-
### This method of parsing will break if the minor revision
|
361
|
-
### ever gets above 9.
|
362
|
-
###
|
363
|
-
### Returns a hash with these keys:
|
364
|
-
### * :major => the major version, Integer
|
365
|
-
### * :minor => the minor version, Integor
|
366
|
-
### * :revision => the revision, String
|
367
|
-
### * :version => a Gem::Version object built from the above keys, which is easily compared to others.
|
368
|
-
###
|
369
|
-
### @param version[String] a JSS version number from the API
|
370
|
-
###
|
371
|
-
### @return [Hash{Symbol => String, Gem::Version}] the parsed version data.
|
372
|
-
###
|
373
|
-
def self.parse_jss_version(version)
|
374
|
-
spl = version.split('.')
|
375
|
-
|
376
|
-
case spl.count
|
377
|
-
when 1
|
378
|
-
major = spl[0].to_i
|
379
|
-
minor = 0
|
380
|
-
revision = '0'
|
381
|
-
when 2
|
382
|
-
major = spl[0].to_i
|
383
|
-
minor = spl[1][0,1].to_i
|
384
|
-
revision = spl[1][1..-1]
|
385
|
-
revision = '0' if revision.empty?
|
386
|
-
else
|
387
|
-
major = spl[0].to_i
|
388
|
-
minor = spl[1][0,1].to_i
|
389
|
-
revision = spl[1..-1].join('.')[1..-1]
|
390
|
-
revision = revision[1..-1] if revision.start_with? '.'
|
391
|
-
end
|
392
|
-
|
393
|
-
###revision = revision[1..-1] if revision.start_with? '.'
|
394
|
-
{ :major => major,
|
395
|
-
:minor => minor,
|
396
|
-
:revision => revision,
|
397
|
-
:version => Gem::Version.new("#{major}.#{minor}.#{revision}")
|
398
|
-
}
|
399
|
-
end
|
400
|
-
|
401
|
-
###
|
402
|
-
### @return [Boolean] is this code running as root?
|
403
|
-
###
|
404
|
-
def self.superuser?
|
405
|
-
Process.euid == 0
|
406
|
-
end
|
407
|
-
|
408
|
-
###
|
409
|
-
### Retrive one or all lines from whatever was piped to standard input.
|
410
|
-
###
|
411
|
-
### Standard input is read completely when the module loads
|
412
|
-
### and the lines are stored as an Array in the constant {STDIN_LINES}
|
413
|
-
###
|
414
|
-
### @param line[Integer] which line of stdin is being retrieved.
|
415
|
-
### The default is zero (0) which returns all of stdin as a single string.
|
416
|
-
###
|
417
|
-
### @return [String, nil] the requested ling of stdin, or nil if it doesn't exist.
|
418
|
-
###
|
419
|
-
def self.stdin(line = 0)
|
420
|
-
|
421
|
-
return STDIN_LINES.join("\n") if line <= 0
|
422
|
-
|
423
|
-
idx = line - 1
|
424
|
-
return STDIN_LINES[idx]
|
425
|
-
end
|
426
|
-
|
427
|
-
###
|
428
|
-
### Prompt for a password in a terminal.
|
429
|
-
###
|
430
|
-
### @param message [String] the prompt message to display
|
431
|
-
###
|
432
|
-
### @return [String] the text typed by the user
|
433
|
-
###
|
434
|
-
def self.prompt_for_password(message)
|
435
|
-
|
436
|
-
begin
|
437
|
-
$stdin.reopen '/dev/tty' unless $stdin.tty?
|
438
|
-
$stderr.print "#{message} "
|
439
|
-
system "/bin/stty -echo"
|
440
|
-
pw = $stdin.gets.chomp("\n")
|
441
|
-
puts
|
442
|
-
ensure
|
443
|
-
system "/bin/stty echo"
|
444
|
-
end # begin
|
445
|
-
return pw
|
446
|
-
end
|
447
|
-
|
448
|
-
|
449
87
|
###
|
450
88
|
### Define classes and submodules here so that they don't
|
451
89
|
### generate errors when referenced during the loading of
|
@@ -539,6 +177,7 @@ end # module JSS
|
|
539
177
|
### Load the rest of the module
|
540
178
|
# $:.unshift File.dirname(__FILE__)
|
541
179
|
|
180
|
+
require "jss-api/utility"
|
542
181
|
require "jss-api/composer"
|
543
182
|
require "jss-api/compatibility"
|
544
183
|
require "jss-api/ruby_extensions"
|