ruby-jss 0.6.3
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.
Potentially problematic release.
This version of ruby-jss might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.yardopts +7 -0
- data/CHANGES.md +112 -0
- data/LICENSE.txt +174 -0
- data/README.md +426 -0
- data/THANKS.md +6 -0
- data/bin/cgrouper +485 -0
- data/bin/subnet-update +400 -0
- data/lib/jss-api.rb +2 -0
- data/lib/jss.rb +190 -0
- data/lib/jss/api_connection.rb +410 -0
- data/lib/jss/api_object.rb +616 -0
- data/lib/jss/api_object/advanced_search.rb +389 -0
- data/lib/jss/api_object/advanced_search/advanced_computer_search.rb +95 -0
- data/lib/jss/api_object/advanced_search/advanced_mobile_device_search.rb +96 -0
- data/lib/jss/api_object/advanced_search/advanced_user_search.rb +95 -0
- data/lib/jss/api_object/building.rb +92 -0
- data/lib/jss/api_object/category.rb +147 -0
- data/lib/jss/api_object/computer.rb +852 -0
- data/lib/jss/api_object/creatable.rb +98 -0
- data/lib/jss/api_object/criteriable.rb +189 -0
- data/lib/jss/api_object/criteriable/criteria.rb +231 -0
- data/lib/jss/api_object/criteriable/criterion.rb +228 -0
- data/lib/jss/api_object/department.rb +93 -0
- data/lib/jss/api_object/distribution_point.rb +560 -0
- data/lib/jss/api_object/extendable.rb +221 -0
- data/lib/jss/api_object/extension_attribute.rb +466 -0
- data/lib/jss/api_object/extension_attribute/computer_extension_attribute.rb +362 -0
- data/lib/jss/api_object/extension_attribute/mobile_device_extension_attribute.rb +189 -0
- data/lib/jss/api_object/extension_attribute/user_extension_attribute.rb +117 -0
- data/lib/jss/api_object/group.rb +380 -0
- data/lib/jss/api_object/group/computer_group.rb +124 -0
- data/lib/jss/api_object/group/mobile_device_group.rb +139 -0
- data/lib/jss/api_object/group/user_group.rb +139 -0
- data/lib/jss/api_object/ldap_server.rb +535 -0
- data/lib/jss/api_object/locatable.rb +286 -0
- data/lib/jss/api_object/matchable.rb +97 -0
- data/lib/jss/api_object/mobile_device.rb +556 -0
- data/lib/jss/api_object/netboot_server.rb +148 -0
- data/lib/jss/api_object/network_segment.rb +414 -0
- data/lib/jss/api_object/osx_configuration_profile.rb +262 -0
- data/lib/jss/api_object/package.rb +839 -0
- data/lib/jss/api_object/peripheral.rb +335 -0
- data/lib/jss/api_object/peripheral_type.rb +295 -0
- data/lib/jss/api_object/policy.rb +898 -0
- data/lib/jss/api_object/purchasable.rb +316 -0
- data/lib/jss/api_object/removable_macaddr.rb +98 -0
- data/lib/jss/api_object/scopable.rb +136 -0
- data/lib/jss/api_object/scopable/scope.rb +621 -0
- data/lib/jss/api_object/script.rb +631 -0
- data/lib/jss/api_object/self_servable.rb +356 -0
- data/lib/jss/api_object/site.rb +93 -0
- data/lib/jss/api_object/software_update_server.rb +109 -0
- data/lib/jss/api_object/updatable.rb +117 -0
- data/lib/jss/api_object/uploadable.rb +138 -0
- data/lib/jss/api_object/user.rb +272 -0
- data/lib/jss/client.rb +504 -0
- data/lib/jss/compatibility.rb +66 -0
- data/lib/jss/composer.rb +185 -0
- data/lib/jss/configuration.rb +306 -0
- data/lib/jss/db_connection.rb +298 -0
- data/lib/jss/exceptions.rb +95 -0
- data/lib/jss/ruby_extensions.rb +35 -0
- data/lib/jss/ruby_extensions/filetest.rb +43 -0
- data/lib/jss/ruby_extensions/hash.rb +79 -0
- data/lib/jss/ruby_extensions/ipaddr.rb +91 -0
- data/lib/jss/ruby_extensions/pathname.rb +77 -0
- data/lib/jss/ruby_extensions/string.rb +59 -0
- data/lib/jss/ruby_extensions/time.rb +63 -0
- data/lib/jss/server.rb +108 -0
- data/lib/jss/utility.rb +478 -0
- data/lib/jss/version.rb +31 -0
- metadata +187 -0
data/bin/subnet-update
ADDED
@@ -0,0 +1,400 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
### Copyright 2016 Pixar
|
4
|
+
###
|
5
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
6
|
+
### with the following modification; you may not use this file except in
|
7
|
+
### compliance with the Apache License and the following modification to it:
|
8
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
9
|
+
###
|
10
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
11
|
+
### names, trademarks, service marks, or product names of the Licensor
|
12
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
13
|
+
### the License and to reproduce the content of the NOTICE file.
|
14
|
+
###
|
15
|
+
### You may obtain a copy of the Apache License at
|
16
|
+
###
|
17
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
18
|
+
###
|
19
|
+
### Unless required by applicable law or agreed to in writing, software
|
20
|
+
### distributed under the Apache License with the above modification is
|
21
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
22
|
+
### KIND, either express or implied. See the Apache License for the specific
|
23
|
+
### language governing permissions and limitations under the Apache License.
|
24
|
+
|
25
|
+
##############################
|
26
|
+
# == Synopsis
|
27
|
+
# Add, remove, or change the Network Segments in the JSS based on data from an input file
|
28
|
+
# in CSV, tab, or other delimited format.
|
29
|
+
#
|
30
|
+
# == Usage
|
31
|
+
# subnet-update [-t | -d delimiter] [-h] file
|
32
|
+
#
|
33
|
+
#
|
34
|
+
# == Author
|
35
|
+
# Chris Lasell <chrisl@pixar.com>
|
36
|
+
#
|
37
|
+
# == Copyright
|
38
|
+
# Copyright (c) 2014 Pixar Animation Studios
|
39
|
+
|
40
|
+
##############################
|
41
|
+
# Libraries
|
42
|
+
require 'jss-api'
|
43
|
+
require 'getoptlong'
|
44
|
+
|
45
|
+
##############################
|
46
|
+
# The app object
|
47
|
+
class App
|
48
|
+
|
49
|
+
##############################
|
50
|
+
# Constants
|
51
|
+
|
52
|
+
USAGE = "Usage: #{File.basename($0)} [-d delim] [--header] [-c col1,col2,col3 ] [-m manual-prefix] [--help] /path/to/file"
|
53
|
+
|
54
|
+
POTENTIAL_COLUMNS = [:name, :starting, :ending, :cidr]
|
55
|
+
|
56
|
+
# Whenever we process a file, we store it here. The next time we
|
57
|
+
# run, if the input file is identical to this, we exit witout doing anything.
|
58
|
+
DEFAULT_CACHE_FILE = Pathname.new("~/.last_subnet_update").expand_path
|
59
|
+
|
60
|
+
DEFAULT_DELIMITER = "\t"
|
61
|
+
DEFAULT_COLUMNS = [:name, :starting, :ending]
|
62
|
+
DEFAULT_MANUAL_PREFIX = "Manual-"
|
63
|
+
|
64
|
+
|
65
|
+
attr_reader :debug
|
66
|
+
|
67
|
+
###############
|
68
|
+
# set up
|
69
|
+
def initialize(args)
|
70
|
+
|
71
|
+
# set defaults
|
72
|
+
@debug = false
|
73
|
+
|
74
|
+
@delim = DEFAULT_DELIMITER
|
75
|
+
@header = false
|
76
|
+
@columns = DEFAULT_COLUMNS
|
77
|
+
@cache_file = DEFAULT_CACHE_FILE
|
78
|
+
@manual_prefix = DEFAULT_MANUAL_PREFIX
|
79
|
+
|
80
|
+
|
81
|
+
#define the cli opts
|
82
|
+
cli_opts = GetoptLong.new(
|
83
|
+
[ '--help', '-H', GetoptLong::NO_ARGUMENT ],
|
84
|
+
[ '--delimiter', '--delim', '-d', GetoptLong::REQUIRED_ARGUMENT],
|
85
|
+
[ '--header', '-h', GetoptLong::NO_ARGUMENT],
|
86
|
+
[ '--columns', '-c', GetoptLong::OPTIONAL_ARGUMENT],
|
87
|
+
[ '--manual-prefix', '-m', GetoptLong::OPTIONAL_ARGUMENT],
|
88
|
+
[ '--cache', GetoptLong::REQUIRED_ARGUMENT ],
|
89
|
+
[ '--debug', GetoptLong::NO_ARGUMENT],
|
90
|
+
[ '--server', '-S', GetoptLong::OPTIONAL_ARGUMENT],
|
91
|
+
[ '--port', '-P', GetoptLong::OPTIONAL_ARGUMENT],
|
92
|
+
[ '--user', '-U', GetoptLong::OPTIONAL_ARGUMENT],
|
93
|
+
[ '--no-verify-cert', '-V', GetoptLong::NO_ARGUMENT],
|
94
|
+
[ '--timeout', '-T', GetoptLong::OPTIONAL_ARGUMENT]
|
95
|
+
)
|
96
|
+
|
97
|
+
# parse the cli opts
|
98
|
+
cli_opts.each do |opt, arg|
|
99
|
+
case opt
|
100
|
+
when '--help' then show_help
|
101
|
+
when '--delimiter' then @delim = arg
|
102
|
+
when '--header' then @header = true
|
103
|
+
when '--columns' then @columns = arg.split(',').map{|c| c.to_sym}
|
104
|
+
when '--manual-prefix' then @manual_prefix = arg
|
105
|
+
when '--cache' then @cache_file = Pathname.new arg
|
106
|
+
when '--debug' then @debug = true
|
107
|
+
when '--server'
|
108
|
+
@server = arg
|
109
|
+
|
110
|
+
when '--port'
|
111
|
+
@port = arg
|
112
|
+
|
113
|
+
when '--user'
|
114
|
+
@user = arg
|
115
|
+
|
116
|
+
when '--no-verify-cert'
|
117
|
+
@verify_cert = false
|
118
|
+
|
119
|
+
when '--timeout'
|
120
|
+
@timeout = arg
|
121
|
+
|
122
|
+
end # case
|
123
|
+
end # each opt arg
|
124
|
+
|
125
|
+
|
126
|
+
@columns = nil if @columns and @columns.empty?
|
127
|
+
|
128
|
+
@file = args.shift
|
129
|
+
|
130
|
+
|
131
|
+
end # init
|
132
|
+
|
133
|
+
###############
|
134
|
+
# Go!
|
135
|
+
def run
|
136
|
+
|
137
|
+
unless @file
|
138
|
+
puts "No input file specified."
|
139
|
+
puts USAGE
|
140
|
+
return
|
141
|
+
end
|
142
|
+
|
143
|
+
@file = Pathname.new @file
|
144
|
+
|
145
|
+
unless parse_file
|
146
|
+
puts "File hasn't changed since last time, no changes to make!"
|
147
|
+
return
|
148
|
+
end
|
149
|
+
|
150
|
+
# use any config settings defined....
|
151
|
+
@user ||= JSS::CONFIG.api_username
|
152
|
+
@server ||= JSS::CONFIG.api_server_name
|
153
|
+
@getpass = $stdin.tty? ? :prompt : :stdin
|
154
|
+
|
155
|
+
raise JSS::MissingDataError, "No JSS Username provided or found in the JSS gem config." unless @user
|
156
|
+
raise JSS::MissingDataError, "No JSS Server provided or found in the JSS gem config." unless @server
|
157
|
+
|
158
|
+
JSS::API.connect( :server => @server,
|
159
|
+
:port => @port,
|
160
|
+
:verify_cert => @verify_cert,
|
161
|
+
:user => @user,
|
162
|
+
:pw => @getpass,
|
163
|
+
:stdin_line => 1,
|
164
|
+
:timeout => @timeout
|
165
|
+
)
|
166
|
+
|
167
|
+
update_network_segments
|
168
|
+
|
169
|
+
end # run
|
170
|
+
|
171
|
+
#####################################
|
172
|
+
###
|
173
|
+
### Show Help
|
174
|
+
###
|
175
|
+
def show_help
|
176
|
+
puts <<-FULLHELP
|
177
|
+
Update the JSS Network Segments from a delimited file of subnet information.
|
178
|
+
|
179
|
+
#{USAGE}
|
180
|
+
|
181
|
+
Options:
|
182
|
+
-d, --delimiter - The field delimiter in the file, defaults to tab.
|
183
|
+
-c, --columns [col1,col2,col3]
|
184
|
+
- The column order in file, must include 'name', 'starting',
|
185
|
+
and either 'ending' or 'cidr'
|
186
|
+
-h, --header - The first line of the file is a header line,
|
187
|
+
possibly defining the columns
|
188
|
+
-m, --manual-prefix - Network Segment names in the JSS with this prefix are ignored.
|
189
|
+
Defaults to 'Manual-'
|
190
|
+
--cache /path/.. - Where read/save the input data for comparison between runs.
|
191
|
+
Defaults to ~/.last_subnet_update
|
192
|
+
-S, --server srvr - specify the JSS API server name
|
193
|
+
-P, --port portnum - specify the JSS API port
|
194
|
+
-U, --user username - specify the JSS API user
|
195
|
+
-V, --no-verify-cert - Allow self-signed, unverified SSL certificate
|
196
|
+
-T, --timeout secs - specify the JSS API timeout
|
197
|
+
-H, --help - show this help
|
198
|
+
--debug - show the ruby backtrace when errors occur
|
199
|
+
|
200
|
+
This program parses the input file line by line (possibly accounting for a header line).
|
201
|
+
Each line defines the name and IP-range of a subnet/network segment.
|
202
|
+
|
203
|
+
- If a segment doesn't exist in the JSS, it is created.
|
204
|
+
- If a segment's range has changed, it is updated in the JSS.
|
205
|
+
- If a JSS segment doesn't exist in the file, it is deleted from the JSS
|
206
|
+
unless its name starts with the --manual-prefix
|
207
|
+
|
208
|
+
Input File:
|
209
|
+
- The file must contain three columns, separated by the --delimiter,
|
210
|
+
with these names, in any order:
|
211
|
+
- 'name' (the network segment name)
|
212
|
+
- 'starting' (the starting IP address of the network segment)
|
213
|
+
- EITHER of:
|
214
|
+
- 'ending' (the ending IP address of the network segment)
|
215
|
+
- 'cidr' (the network range of the segment as a CIDR bitmask, e.g. '24')
|
216
|
+
Notes:
|
217
|
+
- The --columns option is a comma-separted list of the three
|
218
|
+
column names aboveindicating the column-order in the file.
|
219
|
+
|
220
|
+
- If --columns are not provided, and --header is specified, the first line
|
221
|
+
is assumed to contain the column names, separated by the delimiter
|
222
|
+
|
223
|
+
- If --header is provided with --columns, the first line of the file is ignored.
|
224
|
+
|
225
|
+
- The raw data from the file is cached and compared to the input file at
|
226
|
+
the next run. If the data is identical, no JSS connection is made.
|
227
|
+
|
228
|
+
- If no API settings are provided, they will be read from /etc/jss_gem.conf
|
229
|
+
and ~/.jss_gem.conf. See the JSS Gem docs for details.
|
230
|
+
|
231
|
+
- The password for the connection will be read from STDIN or prompted if needed
|
232
|
+
|
233
|
+
FULLHELP
|
234
|
+
exit 0
|
235
|
+
end
|
236
|
+
|
237
|
+
########################
|
238
|
+
# parse the incoming data file.
|
239
|
+
# If the file hasn't changed from the last time we processed it
|
240
|
+
# then return false
|
241
|
+
# otherwise parse it into @parsed_data and return true
|
242
|
+
# @parsed_data is an array of hashes, each with :name, :starting, and :ending
|
243
|
+
#
|
244
|
+
def parse_file
|
245
|
+
|
246
|
+
raise "'#{@file}' is not readable, or not a regular file" unless @file.readable? and @file.file?
|
247
|
+
|
248
|
+
# read in the file
|
249
|
+
@raw_data = @file.read
|
250
|
+
|
251
|
+
# compare it to the one we used last time
|
252
|
+
if @cache_file.readable?
|
253
|
+
return false if @raw_data == @cache_file.read
|
254
|
+
end
|
255
|
+
|
256
|
+
# split the data into an array by newlines
|
257
|
+
lines = @raw_data.split "\n"
|
258
|
+
|
259
|
+
# remove the first line if its a header, and parse it into the columns
|
260
|
+
# if needed
|
261
|
+
if @header
|
262
|
+
header = lines.shift
|
263
|
+
@columns ||= header.split(/\s*#{@delim}\s*/).map{|c| c.to_sym}
|
264
|
+
end
|
265
|
+
|
266
|
+
# check some state
|
267
|
+
raise "Columns must include 'name' and 'starting'" unless @columns.include?(:name) and @columns.include?(:starting)
|
268
|
+
raise "Columns must include either 'ending' or 'cidr'" unless @columns.include?(:ending) or @columns.include?(:cidr)
|
269
|
+
|
270
|
+
@use_cidr = @columns.include? :cidr
|
271
|
+
|
272
|
+
|
273
|
+
# which columns are which in the file?
|
274
|
+
name = @columns.index :name
|
275
|
+
starting = @columns.index :starting
|
276
|
+
ending = @use_cidr ? @columns.index(:cidr) : @columns.index(:ending)
|
277
|
+
|
278
|
+
# split each line and convert it into a hash
|
279
|
+
@parsed_data = lines.map do |line|
|
280
|
+
|
281
|
+
parts = line.split(@delim).map{|f| f.strip }
|
282
|
+
|
283
|
+
unless parts[name] and parts[starting] and parts[ending]
|
284
|
+
puts "Skipping invalid line: #{line}"
|
285
|
+
next
|
286
|
+
end
|
287
|
+
|
288
|
+
|
289
|
+
{:name => parts[name], :starting => parts[starting], :ending => parts[ending]}
|
290
|
+
end
|
291
|
+
|
292
|
+
# parsed data is now an array of hashes
|
293
|
+
return true
|
294
|
+
end
|
295
|
+
|
296
|
+
#############################################
|
297
|
+
#############################################
|
298
|
+
# Update the JSS Network Segments from GIT_NETBLOCKS_URL, q.v.
|
299
|
+
def update_network_segments
|
300
|
+
|
301
|
+
# CREATE any that are in the parsed data but not yet in the JSS,
|
302
|
+
# and UPDATE any that exist but have modified ranges.
|
303
|
+
# While looping through, make a hash of JSS::NetworkSegment objects, keyed by their name.
|
304
|
+
segs_from_data = {}
|
305
|
+
|
306
|
+
@parsed_data.each do |pd|
|
307
|
+
|
308
|
+
# skip anthing with the manual prefix
|
309
|
+
next if pd[:name].start_with? @manual_prefix
|
310
|
+
|
311
|
+
ender = @use_cidr ? :cidr : :ending_address
|
312
|
+
|
313
|
+
begin
|
314
|
+
this_seg = JSS::NetworkSegment.new(:id => :new, :name => pd[:name], :starting_address => pd[:starting], ender => pd[:ending])
|
315
|
+
|
316
|
+
# If the new netsegment should have other settings (dist. point, netboot server, etc...)
|
317
|
+
# here's where you should apply those settings.
|
318
|
+
|
319
|
+
this_seg.create
|
320
|
+
puts "Added Network Segment '#{this_seg.name}' to the JSS"
|
321
|
+
|
322
|
+
# it already exists, so see if it needs any changes
|
323
|
+
rescue JSS::AlreadyExistsError
|
324
|
+
|
325
|
+
# there's already one with this name, so just grab it.
|
326
|
+
this_seg = JSS::NetworkSegment.new( :name => pd[:name])
|
327
|
+
|
328
|
+
# does the startng addres need to be changed?
|
329
|
+
needs_update = this_seg.starting_address.to_s != pd[:starting].to_s
|
330
|
+
|
331
|
+
# even if we don't need to update the starting, we might need to update
|
332
|
+
# the ending...
|
333
|
+
unless needs_update
|
334
|
+
if @use_cidr
|
335
|
+
needs_update = this_seg.cidr.to_i != pd[:ending].to_i
|
336
|
+
else
|
337
|
+
needs_update = this_seg.ending_address.to_s != pd[:ending].to_s
|
338
|
+
end # if @use_cidr
|
339
|
+
end #unless needs update
|
340
|
+
|
341
|
+
# did we decide we need an update?
|
342
|
+
if needs_update
|
343
|
+
this_seg.starting_address = pd[:starting]
|
344
|
+
if @use_cidr
|
345
|
+
this_seg.cidr = pd[:ending].to_i
|
346
|
+
else
|
347
|
+
this_seg.ending_address = pd[:ending]
|
348
|
+
end # if @use_cidr
|
349
|
+
this_seg.update
|
350
|
+
puts "Updated IP range for Network Segment '#{this_seg.name}'"
|
351
|
+
|
352
|
+
else # doesn't need update
|
353
|
+
puts "Network Segment '#{this_seg.name}' doesn't have any changes."
|
354
|
+
end # if needs update
|
355
|
+
|
356
|
+
# rescue other errors
|
357
|
+
rescue
|
358
|
+
raise "There was an error with NetworkSegment #{pd[:name]}: #{$!}"
|
359
|
+
end # begin
|
360
|
+
|
361
|
+
segs_from_data[this_seg.name] = this_seg
|
362
|
+
end
|
363
|
+
|
364
|
+
|
365
|
+
# DELETE those in jss, but not in parsed data,
|
366
|
+
# unless the name starts with @manual_prefix
|
367
|
+
JSS::NetworkSegment.map_all_ids_to(:name).each do |id,name|
|
368
|
+
|
369
|
+
next if name.start_with? @manual_prefix
|
370
|
+
|
371
|
+
unless segs_from_data.keys.include? name
|
372
|
+
JSS::NetworkSegment.new(:id => id).delete
|
373
|
+
puts "Deleted Network Segment '#{name}' from the JSS"
|
374
|
+
end # unless
|
375
|
+
|
376
|
+
end # jss_uids.each seg
|
377
|
+
|
378
|
+
# save the data into a file for comparison next time
|
379
|
+
@cache_file.jss_save @raw_data
|
380
|
+
|
381
|
+
# all done
|
382
|
+
return true
|
383
|
+
end # update_network_segments
|
384
|
+
|
385
|
+
end # app
|
386
|
+
|
387
|
+
##############################
|
388
|
+
# create the app and go
|
389
|
+
begin
|
390
|
+
app = App.new(ARGV)
|
391
|
+
app.run
|
392
|
+
rescue
|
393
|
+
# handle exceptions not handled elsewhere
|
394
|
+
puts "An error occurred: #{$!}"
|
395
|
+
puts "Backtrace:" if app.debug
|
396
|
+
puts $@ if app.debug
|
397
|
+
|
398
|
+
ensure
|
399
|
+
|
400
|
+
end
|
data/lib/jss-api.rb
ADDED
data/lib/jss.rb
ADDED
@@ -0,0 +1,190 @@
|
|
1
|
+
### Copyright 2016 Pixar
|
2
|
+
###
|
3
|
+
### Licensed under the Apache License, Version 2.0 (the "Apache License")
|
4
|
+
### with the following modification; you may not use this file except in
|
5
|
+
### compliance with the Apache License and the following modification to it:
|
6
|
+
### Section 6. Trademarks. is deleted and replaced with:
|
7
|
+
###
|
8
|
+
### 6. Trademarks. This License does not grant permission to use the trade
|
9
|
+
### names, trademarks, service marks, or product names of the Licensor
|
10
|
+
### and its affiliates, except as required to comply with Section 4(c) of
|
11
|
+
### the License and to reproduce the content of the NOTICE file.
|
12
|
+
###
|
13
|
+
### You may obtain a copy of the Apache License at
|
14
|
+
###
|
15
|
+
### http://www.apache.org/licenses/LICENSE-2.0
|
16
|
+
###
|
17
|
+
### Unless required by applicable law or agreed to in writing, software
|
18
|
+
### distributed under the Apache License with the above modification is
|
19
|
+
### distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
20
|
+
### KIND, either express or implied. See the Apache License for the specific
|
21
|
+
### language governing permissions and limitations under the Apache License.
|
22
|
+
###
|
23
|
+
###
|
24
|
+
|
25
|
+
###
|
26
|
+
### JSS, A Ruby module for interacting with the JAMF Software Server via it's REST API.
|
27
|
+
###
|
28
|
+
module JSS
|
29
|
+
|
30
|
+
#####################################
|
31
|
+
### Required Libraries, etc
|
32
|
+
#####################################
|
33
|
+
|
34
|
+
###################
|
35
|
+
### Standard Libraries
|
36
|
+
require 'date'
|
37
|
+
require 'singleton'
|
38
|
+
require 'pathname'
|
39
|
+
require 'fileutils'
|
40
|
+
require 'uri'
|
41
|
+
require "ipaddr"
|
42
|
+
require "rexml/document"
|
43
|
+
require "base64"
|
44
|
+
require "shellwords"
|
45
|
+
require "digest"
|
46
|
+
require 'yaml'
|
47
|
+
|
48
|
+
###################
|
49
|
+
### Gems
|
50
|
+
require 'rest-client'
|
51
|
+
require 'json'
|
52
|
+
require 'plist'
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
#####################################
|
57
|
+
### Constants
|
58
|
+
#####################################
|
59
|
+
|
60
|
+
### The minimum JSS version that works with this gem, as returned by the API
|
61
|
+
### in the deprecated 'jssuser' resource
|
62
|
+
MINIMUM_SERVER_VERSION = "9.4"
|
63
|
+
|
64
|
+
### The current local UTC offset as a fraction of a day (Time.now.utc_offset is the offset in seconds,
|
65
|
+
### 60*60*24 is the seconds in a day)
|
66
|
+
TIME_ZONE_OFFSET = Rational(Time.now.utc_offset, 60*60*24)
|
67
|
+
|
68
|
+
### These are handy for testing values without making new arrays, strings, etc every time.
|
69
|
+
TRUE_FALSE = [true, false]
|
70
|
+
|
71
|
+
### When parsing a date/time data into a Time object, these will return nil
|
72
|
+
NIL_DATES = [0, nil, '', '0']
|
73
|
+
|
74
|
+
|
75
|
+
#####################################
|
76
|
+
### Module Variables
|
77
|
+
#####################################
|
78
|
+
|
79
|
+
### The contents of anything piped to stdin, split into lines. See {JSS.stdin}
|
80
|
+
@@stdin_lines = nil
|
81
|
+
|
82
|
+
#####################################
|
83
|
+
### Module Methods
|
84
|
+
#####################################
|
85
|
+
|
86
|
+
|
87
|
+
###
|
88
|
+
### Define classes and submodules here so that they don't
|
89
|
+
### generate errors when referenced during the loading of
|
90
|
+
### the library.
|
91
|
+
###
|
92
|
+
|
93
|
+
#####################################
|
94
|
+
### Sub Modules
|
95
|
+
#####################################
|
96
|
+
|
97
|
+
module Composer ; end
|
98
|
+
|
99
|
+
### Mix-in Sub Modules
|
100
|
+
|
101
|
+
module Creatable ; end
|
102
|
+
module FileUpload ; end
|
103
|
+
module Locatable ; end
|
104
|
+
module Matchable ; end
|
105
|
+
module Purchasable ; end
|
106
|
+
module Updatable ; end
|
107
|
+
module Extendable ; end
|
108
|
+
|
109
|
+
### Mix-in Sub Modules with Classes
|
110
|
+
|
111
|
+
module Criteriable ; end
|
112
|
+
class Criteriable::Criteria ; end
|
113
|
+
class Criteriable::Criterion ; end
|
114
|
+
|
115
|
+
module Scopable ; end
|
116
|
+
class Scopable::Scope ; end
|
117
|
+
|
118
|
+
#####################################
|
119
|
+
### Classes
|
120
|
+
#####################################
|
121
|
+
|
122
|
+
class APIObject ; end
|
123
|
+
class APIConnection ; end
|
124
|
+
class Client ; end
|
125
|
+
class DBConnection ; end
|
126
|
+
class Server ; end
|
127
|
+
class Preferences ; end
|
128
|
+
|
129
|
+
#####################################
|
130
|
+
### SubClasses
|
131
|
+
#####################################
|
132
|
+
|
133
|
+
### APIObject Classes with SubClasses
|
134
|
+
|
135
|
+
class AdvancedSearch < JSS::APIObject ; end
|
136
|
+
class AdvancedComputerSearch < JSS::AdvancedSearch ; end
|
137
|
+
class AdvancedMobileDeviceSearch < JSS::AdvancedSearch ; end
|
138
|
+
class AdvancedUserSearch < JSS::AdvancedSearch ; end
|
139
|
+
|
140
|
+
|
141
|
+
class ExtensionAttribute < JSS::APIObject ; end
|
142
|
+
class ComputerExtensionAttribute < JSS::ExtensionAttribute ; end
|
143
|
+
class MobileDeviceExtensionAttribute < JSS::ExtensionAttribute ; end
|
144
|
+
class UserExtensionAttribute < JSS::ExtensionAttribute ; end
|
145
|
+
|
146
|
+
class Group < JSS::APIObject ; end
|
147
|
+
class ComputerGroup < JSS::Group ; end
|
148
|
+
class MobileDeviceGroup < JSS::Group ; end
|
149
|
+
class UserGroup < JSS::Group ; end
|
150
|
+
|
151
|
+
### APIObject Classes without SubClasses
|
152
|
+
|
153
|
+
class Building < JSS::APIObject ; end
|
154
|
+
class Category < JSS::APIObject ; end
|
155
|
+
class Computer < JSS::APIObject ; end
|
156
|
+
class Department < JSS::APIObject ; end
|
157
|
+
class DistributionPoint < JSS::APIObject ; end
|
158
|
+
class LDAPServer < JSS::APIObject ; end
|
159
|
+
class MobileDevice < JSS::APIObject ; end
|
160
|
+
class NetBootServer < JSS::APIObject ; end
|
161
|
+
class NetworkSegment < JSS::APIObject ; end
|
162
|
+
class Package < JSS::APIObject ; end
|
163
|
+
class PeripheralType < JSS::APIObject ; end
|
164
|
+
class Peripheral < JSS::APIObject ; end
|
165
|
+
class Policy < JSS::APIObject ; end
|
166
|
+
class RemovableMacAddress < JSS::APIObject ; end
|
167
|
+
class Script < JSS::APIObject ; end
|
168
|
+
class Site < JSS::APIObject ; end
|
169
|
+
class SoftwareUpdateServer < JSS::APIObject ; end
|
170
|
+
class User < JSS::APIObject ; end
|
171
|
+
|
172
|
+
|
173
|
+
end # module JSS
|
174
|
+
|
175
|
+
|
176
|
+
##################
|
177
|
+
### Load the rest of the module
|
178
|
+
|
179
|
+
require "jss/utility"
|
180
|
+
require "jss/composer"
|
181
|
+
require "jss/compatibility"
|
182
|
+
require "jss/ruby_extensions"
|
183
|
+
require "jss/exceptions"
|
184
|
+
require "jss/api_connection"
|
185
|
+
require "jss/api_object"
|
186
|
+
require "jss/server"
|
187
|
+
require "jss/client"
|
188
|
+
require "jss/configuration"
|
189
|
+
require "jss/db_connection"
|
190
|
+
require "jss/version"
|