jss-api 0.5.4

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.
Files changed (65) hide show
  1. data/CHANGES.md +4 -0
  2. data/LICENSE.txt +174 -0
  3. data/README.md +368 -0
  4. data/THANKS.md +6 -0
  5. data/lib/jss-api.rb +549 -0
  6. data/lib/jss-api/api_connection.rb +326 -0
  7. data/lib/jss-api/api_object.rb +590 -0
  8. data/lib/jss-api/api_object/advanced_search.rb +389 -0
  9. data/lib/jss-api/api_object/advanced_search/advanced_computer_search.rb +95 -0
  10. data/lib/jss-api/api_object/advanced_search/advanced_mobile_device_search.rb +96 -0
  11. data/lib/jss-api/api_object/advanced_search/advanced_user_search.rb +95 -0
  12. data/lib/jss-api/api_object/building.rb +92 -0
  13. data/lib/jss-api/api_object/category.rb +147 -0
  14. data/lib/jss-api/api_object/computer.rb +852 -0
  15. data/lib/jss-api/api_object/creatable.rb +98 -0
  16. data/lib/jss-api/api_object/criteriable.rb +189 -0
  17. data/lib/jss-api/api_object/criteriable/criteria.rb +231 -0
  18. data/lib/jss-api/api_object/criteriable/criterion.rb +228 -0
  19. data/lib/jss-api/api_object/department.rb +93 -0
  20. data/lib/jss-api/api_object/distribution_point.rb +490 -0
  21. data/lib/jss-api/api_object/extendable.rb +221 -0
  22. data/lib/jss-api/api_object/extension_attribute.rb +457 -0
  23. data/lib/jss-api/api_object/extension_attribute/computer_extension_attribute.rb +362 -0
  24. data/lib/jss-api/api_object/extension_attribute/mobile_device_extension_attribute.rb +189 -0
  25. data/lib/jss-api/api_object/extension_attribute/user_extension_attribute.rb +117 -0
  26. data/lib/jss-api/api_object/group.rb +380 -0
  27. data/lib/jss-api/api_object/group/computer_group.rb +124 -0
  28. data/lib/jss-api/api_object/group/mobile_device_group.rb +139 -0
  29. data/lib/jss-api/api_object/group/user_group.rb +139 -0
  30. data/lib/jss-api/api_object/ldap_server.rb +535 -0
  31. data/lib/jss-api/api_object/locatable.rb +268 -0
  32. data/lib/jss-api/api_object/matchable.rb +97 -0
  33. data/lib/jss-api/api_object/mobile_device.rb +556 -0
  34. data/lib/jss-api/api_object/netboot_server.rb +148 -0
  35. data/lib/jss-api/api_object/network_segment.rb +414 -0
  36. data/lib/jss-api/api_object/package.rb +760 -0
  37. data/lib/jss-api/api_object/peripheral.rb +335 -0
  38. data/lib/jss-api/api_object/peripheral_type.rb +295 -0
  39. data/lib/jss-api/api_object/policy.rb +882 -0
  40. data/lib/jss-api/api_object/purchasable.rb +316 -0
  41. data/lib/jss-api/api_object/removable_macaddr.rb +98 -0
  42. data/lib/jss-api/api_object/scopable.rb +136 -0
  43. data/lib/jss-api/api_object/scopable/scope.rb +621 -0
  44. data/lib/jss-api/api_object/script.rb +631 -0
  45. data/lib/jss-api/api_object/site.rb +93 -0
  46. data/lib/jss-api/api_object/software_update_server.rb +109 -0
  47. data/lib/jss-api/api_object/updatable.rb +117 -0
  48. data/lib/jss-api/api_object/uploadable.rb +138 -0
  49. data/lib/jss-api/api_object/user.rb +272 -0
  50. data/lib/jss-api/client.rb +500 -0
  51. data/lib/jss-api/compatibility.rb +66 -0
  52. data/lib/jss-api/composer.rb +171 -0
  53. data/lib/jss-api/configuration.rb +301 -0
  54. data/lib/jss-api/db_connection.rb +243 -0
  55. data/lib/jss-api/exceptions.rb +83 -0
  56. data/lib/jss-api/ruby_extensions.rb +35 -0
  57. data/lib/jss-api/ruby_extensions/filetest.rb +43 -0
  58. data/lib/jss-api/ruby_extensions/hash.rb +79 -0
  59. data/lib/jss-api/ruby_extensions/ipaddr.rb +91 -0
  60. data/lib/jss-api/ruby_extensions/pathname.rb +77 -0
  61. data/lib/jss-api/ruby_extensions/string.rb +43 -0
  62. data/lib/jss-api/ruby_extensions/time.rb +63 -0
  63. data/lib/jss-api/server.rb +108 -0
  64. data/lib/jss-api/version.rb +31 -0
  65. metadata +219 -0
@@ -0,0 +1,66 @@
1
+ ### Copyright 2014 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
+ ###
27
+ ### Augmentation to make this code compatible with ruby 1.8.7
28
+ ###
29
+
30
+ #############################################
31
+ ### Hash.key
32
+ ###
33
+ ### #key exists in ruby 1.9+, in 1.8 its called #index
34
+ ### it returns the hash key for a given value, if the value exists
35
+ ### in the hash
36
+ ###
37
+ unless {}.respond_to? :key
38
+ class Hash
39
+ alias_method :key, :index
40
+ end
41
+ end
42
+
43
+ #############################################
44
+ ### Array.sample
45
+ ###
46
+ ### #sample exists in ruby 1.9+, in 1.8 its called #choice
47
+ ### it returns a randomly chosen element of the given array
48
+ ### eg: [1, 2, 3].sample returns either 1, 2, or 3
49
+ ###
50
+ unless [].respond_to? :sample
51
+ class Array
52
+ alias_method :sample, :choice
53
+ end
54
+ end
55
+
56
+
57
+ #############################################
58
+ ### String.force_encoding
59
+ ###
60
+ ### Ruby 1.8 doesn't do encodings...
61
+ ###
62
+ unless "".respond_to? :force_encoding
63
+ class String
64
+ def force_encoding(args = nil); self; end
65
+ end
66
+ end
@@ -0,0 +1,171 @@
1
+ ### Copyright 2014 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
+ module JSS
27
+
28
+ ###
29
+ ### This module provides two methods for building very simple Casper-happy .pkg and .dmg packages for deployment.
30
+ ###
31
+ ### Unlike Composer.app from JAMF, this module currently doesn't offer a way to do a before/after disk scan
32
+ ### and use the differences to build the root folder from which the package is built. Nor does the module support
33
+ ### editing the pre/post install scripts in .pkgs.
34
+ ###
35
+ ### The 'root folder', a folder representing the root filesystem of the target machine where the package will be installed,
36
+ ### must already exist and be fully populated and with correct permissions.
37
+ ###
38
+ module Composer
39
+
40
+
41
+
42
+ #####################################
43
+ ### Constants
44
+ #####################################
45
+
46
+ ### the apple pkgutil tool
47
+ PKG_UTIL = Pathname.new "/usr/sbin/pkgutil"
48
+
49
+ ### The location of the cli tool for making .pkgs
50
+ PKGBUILD = Pathname.new "/usr/bin/pkgbuild"
51
+
52
+ ### the default bundle identifier prefix for pkgs
53
+ PKG_BUNDLE_ID_PFX = 'jss_gem_composer'
54
+
55
+ ### Apple's hdiutil for making dmgs
56
+ HDI_UTIL= '/usr/bin/hdiutil'
57
+
58
+ ### Where to save the output ?
59
+ DEFAULT_OUT_DIR = Pathname.new "/Users/Shared"
60
+
61
+ ###
62
+ ### Make a casper-happy .pkg out of a root folder, permissions are assumed to be correct.
63
+ ###
64
+ ### @param name[String] the name of the .pkg. The .pkg suffix will be added if not present
65
+ ###
66
+ ### @param version[String] the version of the .pkg, needed for building the .pkg
67
+ ###
68
+ ### @param root[String, Pathname] the path to the "root folder" representing the root file system of the target install drive
69
+ ###
70
+ ### @param opts[Hash] the options for building the .pkg
71
+ ###
72
+ ### @option opts :bundle_id_prefix[String] the pkg bundle identifier prefix.
73
+ ### e.g. 'org.some.organization' or 'com.pixar.d3'.
74
+ ### Defaults to '{PKG_BUNDLE_ID_PFX}'. See 'man pkgbuild' for more info
75
+ ###
76
+ ### @option opts :out_dir[String,Pathname] he folder in which the .pkg will be created. Defaults to {DEFAULT_OUT_DIR}
77
+ ###
78
+ ### @option opts :preserve_ownership[Boolean] If true, the owner/group of the rootpath are preserved.
79
+ ### Default is false: they become the pkgbuild/installer "recommended" (root/wheel or root/admin)
80
+ ###
81
+ ### @return [Pathname] the local path to the new .pkg
82
+ ###
83
+ def self.mk_pkg(name, version, root, opts = {})
84
+ raise NoSuchItemError, "Missing pkgbuild tool. Please make sure you're running 10.8 or later." unless PKGBUILD.executable?
85
+
86
+ opts[:out_dir] ||= DEFAULT_OUT_DIR
87
+ opts[:bundle_id_prefix] ||= PKG_BUNDLE_ID_PFX
88
+
89
+ pkg_filename = "#{name}.pkg"
90
+ pkg_id = opts[:bundle_id_prefix] + "." + name
91
+ pkg_out = "#{opts[:out_dir]}/#{pkg_filename}"
92
+ pkg_ownership = opts[:preserve_ownership] ? "preserve" : "recommended"
93
+
94
+
95
+ ### first, run 'analyze' to get a 'component plist' in which we can change some settings
96
+ ### for any bundles in the root (bundles like .apps, frameworks, plugins, etc..)
97
+ ###
98
+ ### we edit the settings thus:
99
+ ### BundleOverwriteAction = upgrade, totally replace any version current on disk
100
+ ### BundleIsVersionChecked = false, allow us to install regardless of what version is currently installed
101
+ ### BundleIsRelocatable = false, if there's a version of this in some other location, Do Not move this one there after installation
102
+ ### BundleHasStrictIdentifier = false, don't care if there's something at the install path with a different bundle id.
103
+ ###
104
+ ### In other words, just install the thing!
105
+ ### (see 'man pkgbuild' for more info)
106
+ ###
107
+ ###
108
+ comp_plist_out = Pathname.new "/tmp/#{PKG_BUNDLE_ID_PFX}-#{pkg_filename}.plist"
109
+ system "#{PKGBUILD} --analyze --root '#{root}' '#{comp_plist_out}'"
110
+ comp_plist = Plist.parse_xml comp_plist_out.read
111
+
112
+ ### if the plist is empty, there are no bundles in the pkg
113
+ if comp_plist[0].nil?
114
+ comp_plist_arg = ''
115
+ else
116
+ ### otherwise, edit the bundle dictionaries
117
+ comp_plist.each do |bndl|
118
+ bndl.delete "ChildBundles" if bndl["ChildBundles"]
119
+ bndl["BundleOverwriteAction"] = "upgrade"
120
+ bndl["BundleIsVersionChecked"] = false
121
+ bndl["BundleIsRelocatable"] = false
122
+ bndl["BundleHasStrictIdentifier"] = false
123
+ end
124
+ ### write out the edits
125
+ comp_plist_out.open('w'){|f| f.write comp_plist.to_plist}
126
+ comp_plist_arg = "--component-plist '#{comp_plist_out}'"
127
+ end
128
+
129
+ ### now build the pkg
130
+ begin
131
+ system "#{PKGBUILD} --identifier '#{pkg_id}' --version '#{version}' --ownership #{pkg_ownership} --install-location / --root '#{root}' #{comp_plist_arg} '#{pkg_out}' "
132
+
133
+ raise RuntimeError, "There was an error building the .pkg" unless $?.exitstatus == 0
134
+ ensure
135
+ comp_plist_out.delete if comp_plist_out.exist?
136
+ end
137
+
138
+ return Pathname.new pkg_out
139
+ end # mk_dot_pkg
140
+
141
+
142
+ ###
143
+ ### Make a casper-happy .dmg out of a root folder, permissions are assumed to be correct.
144
+ ###
145
+ ### @param name[String] The name of the .dmg, the suffix will be added if needed
146
+ ###
147
+ ### @param root[String, Pathname] the path to the "root folder" representing the root file system of the target install drive
148
+ ###
149
+ ### @param out_dir[String, Pathname] the folder in which the .pkg will be created. Defaults to {DEFAULT_OUT_DIR}
150
+ ###
151
+ ### @return [Pathname] the local path to the new .dmg
152
+ ###
153
+ ###
154
+ def self.mk_dmg(name, root, out_dir = DEFAULT_OUT_DIR)
155
+
156
+ dmg_filename = "#{name}.dmg"
157
+ dmg_vol = name
158
+ dmg_out = "#{out_dir}/#{dmg_filename}"
159
+
160
+ system "#{HDI_UTIL} create -volname '#{dmg_vol}' -srcfolder '#{root}' '#{dmg_out}'"
161
+
162
+ raise RuntimeError, "There was an error building the .dmg" unless $?.exitstatus == 0
163
+ return Pathname.new dmg_out
164
+
165
+ end # mk_dmg
166
+
167
+
168
+ end # module Composer
169
+ end # module JSS
170
+
171
+
@@ -0,0 +1,301 @@
1
+ ### Copyright 2014 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
+ module JSS
27
+
28
+
29
+ #####################################
30
+ ### Module Variables
31
+ #####################################
32
+
33
+ #####################################
34
+ ### Module Methods
35
+ #####################################
36
+
37
+ #####################################
38
+ ### Classes
39
+ #####################################
40
+
41
+ ###
42
+ ### A class for working with pre-defined settings & preferences for the JSS Gem
43
+ ###
44
+ ### This is a singleton class, only one instance can exist at a time.
45
+ ###
46
+ ### When the JSS module loads, that instance is created and stored in the constant {JSS::CONFIG},
47
+ ### which can then be used in applications to avoid always having to pass in server names, API user names
48
+ ### and so on.
49
+ ###
50
+ ### When the JSS::Configuration instance is created, the {GLOBAL_CONF} file (/etc/jss_gem.conf) is examined if it exists, and
51
+ ### the items in it are loaded into the attributes.
52
+ ###
53
+ ### Then the user-specific {USER_CONF} file (~/.jss_gem.conf) is examined if it exists, and any attributes defined there will
54
+ ### override those values from the {GLOBAL_CONF}.
55
+ ###
56
+ ### The file format is one attribute per line, thus:
57
+ ### attr_name: value
58
+ ###
59
+ ### Lines that don't start with a known attribute name followed by a colon are ignored. If an attribute is defined
60
+ ### more than once, the last one wins.
61
+ ###
62
+ ### The known attributes are:
63
+ ### - api_server_name [String] the hostname of the JSS API server
64
+ ### - api_server_port [Integer] the port number for the API connection
65
+ ### - api_verify_cert [Boolean] if SSL is used, should the SSL certificate be verified (usually false for a self-signed cert)
66
+ ### - api_username [String] the JSS username for connecting to the API
67
+ ### - api_timeout_open [Integer] the number of seconds for the open-connection timeout
68
+ ### - api_timeout [Integer] the number of seconds for the response timeout
69
+ ###
70
+ ### The {APIConnection#connect} method will first use any values given as method arguments. For any not given, it will
71
+ ### look at the Preferences instance for any values there, and if still none, will use default values or raise an exception.
72
+ ###
73
+ ### At any point, the attributes can read or changed using standard Ruby getter/setter methods matching the name of the attribute,
74
+ ### e.g.
75
+ ### JSS::CONFIG.api_server_name # => 'myjss.mycompany.com'
76
+ ### JSS::CONFIG.api_server_name = 'otherjss.mycompany.com' # sets the api_server_name to a new value
77
+ ###
78
+ ###
79
+ ### The current settings may be saved to the GLOBAL_CONF file, the USER_CONF file, or an arbitrary file using {#save}.
80
+ ### The argument to {#save} should be either :user, :global, or a String or Pathname file path.
81
+ ### NOTE: This overwrites any existing file.
82
+ ###
83
+ ### To re-load the settings use {#reload}. This clears the current settings, and re-reads both the global and user files.
84
+ ### If a pathname is provided, e.g.
85
+ ### JSS::CONFIG.reload '/path/to/other/file'
86
+ ### the current settings are cleared and reloaded from that other file.
87
+ ###
88
+ ### To view the current settings, use {#print}.
89
+ ###
90
+ ### @note Passwords are not saved in prefs files. Your application will have to acquire them using the :prompt or :stdin options to
91
+ ### {APIConnection#connect}, or by custom means.
92
+ ###
93
+ class Configuration
94
+ include Singleton
95
+
96
+ #####################################
97
+ ### Class Constants
98
+ #####################################
99
+
100
+ ### The filename for storing the prefs, globally or user-level
101
+ CONF_FILE = "jss_gem.conf"
102
+
103
+ ### The Pathname to the machine-wide preferences plist
104
+ GLOBAL_CONF = Pathname.new "/etc/#{CONF_FILE}"
105
+
106
+ ### The Pathname to the user-specific preferences plist
107
+ USER_CONF = Pathname.new("~/.#{CONF_FILE}").expand_path
108
+
109
+ ### The attribute keys we maintain, and the type they should be stored as
110
+ CONF_KEYS = {
111
+ :api_server_name => :to_s,
112
+ :api_server_port => :to_i,
113
+ :api_verify_cert => :jss_to_bool,
114
+ :api_username => :to_s,
115
+ :api_timeout_open => :to_i,
116
+ :api_timeout => :to_i,
117
+ :db_server_name => :to_s,
118
+ :db_server_port => :to_i,
119
+ :db_server_socket => :to_s,
120
+ :db_username => :to_s,
121
+ :db_name => :to_s,
122
+ :db_connect_timeout => :to_i,
123
+ :db_read_timeout => :to_i,
124
+ :db_write_timeout => :to_i
125
+ }
126
+
127
+ #####################################
128
+ ### Class Variables
129
+ #####################################
130
+
131
+ #####################################
132
+ ### Class Methods
133
+ #####################################
134
+
135
+ #####################################
136
+ ### Attributes
137
+ #####################################
138
+
139
+ # automatically create accessors for all the CONF_KEYS
140
+ CONF_KEYS.keys.each {|k| attr_accessor k}
141
+
142
+
143
+ #####################################
144
+ ### Constructor
145
+ #####################################
146
+
147
+ ###
148
+ ### Initialize!
149
+ ###
150
+ def initialize
151
+
152
+ read_global
153
+ read_user
154
+
155
+ end
156
+
157
+ #####################################
158
+ ### Public Instance Methods
159
+ #####################################
160
+
161
+ ###
162
+ ### Clear all values
163
+ ###
164
+ ### @return [void]
165
+ ###
166
+ def clear_all
167
+ CONF_KEYS.keys.each {|k| self.send "#{k}=".to_sym, nil}
168
+ end
169
+
170
+ ###
171
+ ### (Re)read the global prefs, if it exists.
172
+ ###
173
+ ### @return [void]
174
+ ###
175
+ def read_global
176
+ read GLOBAL_CONF if GLOBAL_CONF.file? and GLOBAL_CONF.readable?
177
+ end
178
+
179
+ ###
180
+ ### (Re)read the user prefs, if it exists.
181
+ ###
182
+ ### @return [void]
183
+ ###
184
+ def read_user
185
+ read USER_CONF if USER_CONF.file? and USER_CONF.readable?
186
+ end
187
+
188
+
189
+ ###
190
+ ### Clear the settings and reload the prefs files, or another file if provided
191
+ ###
192
+ ### @param file[String,Pathname] a non-standard prefs file to load
193
+ ###
194
+ ### @return [void]
195
+ ###
196
+ def reload(file = nil)
197
+ clear_all
198
+ if file
199
+ read file
200
+ return true
201
+ end
202
+ read_global
203
+ read_user
204
+ return true
205
+ end
206
+
207
+
208
+ ###
209
+ ### Save the prefs into a file
210
+ ###
211
+ ### @param file[Symbol,String,Pathname] either :user, :global, or an arbitrary file to save.
212
+ ###
213
+ ### @return [void]
214
+ ###
215
+ def save(file)
216
+ path = case file
217
+ when :global then GLOBAL_CONF
218
+ when :user then USER_CONF
219
+ else Pathname.new(file)
220
+ end
221
+
222
+ # file already exists? read it in and update the values.
223
+ if path.readable?
224
+ data = path.read
225
+
226
+ # go thru the known attributes/keys
227
+ CONF_KEYS.keys.sort.each do |k|
228
+
229
+ # if the key exists, update it.
230
+ if data =~ /^#{k}:/
231
+ data.sub!(/^#{k}:.*$/, "#{k}: #{self.send k}")
232
+
233
+ # if not, add it to the end unless it's nil
234
+ else
235
+ data += "\n#{k}: #{self.send k}" unless self.send(k).nil?
236
+ end # if data =~ /^#{k}:/
237
+ end #each do |k|
238
+
239
+ else # not readable, make a new file
240
+ data = ""
241
+ CONF_KEYS.keys.sort.each do |k|
242
+ data << "#{k}: #{self.send k}\n" unless self.send(k).nil?
243
+ end
244
+ end # if path readable
245
+
246
+ # make sure we end with a newline, the save it.
247
+ data << "\n" unless data.end_with?("\n")
248
+ path.jss_save data
249
+ end # read file
250
+
251
+
252
+ ###
253
+ ### Print out the current settings to stdout
254
+ ###
255
+ ### @return [void]
256
+ ###
257
+ def print
258
+ CONF_KEYS.keys.sort.each{|k| puts "#{k}: #{self.send k}"}
259
+ end
260
+
261
+ #####################################
262
+ ### Private Instance Methods
263
+ #####################################
264
+ private
265
+
266
+ ###
267
+ ### Read in any prefs file
268
+ ###
269
+ ### @param file[String,Pathname] the file to read
270
+ ###
271
+ ### @return [void]
272
+ ###
273
+ def read(file)
274
+
275
+ Pathname.new(file).read.each_line do |line|
276
+ # skip blank lines and those starting with #
277
+ next if line =~ /^\s*(#|$)/
278
+
279
+ line.strip =~ /^(\w+?):\s*(\S.*)$/
280
+ next unless $1
281
+ attr = $1.to_sym
282
+ setter = "#{attr}=".to_sym
283
+ value = $2.strip
284
+
285
+ if CONF_KEYS.keys.include? attr
286
+ if value
287
+ # convert the value to the correct class
288
+ value = value.send(CONF_KEYS[attr])
289
+ end
290
+ self.send(setter, value)
291
+ end # if
292
+ end # do line
293
+
294
+ end # read file
295
+
296
+ end # class Preferences
297
+
298
+ # The single instance of Configuration
299
+ CONFIG = JSS::Configuration.instance
300
+
301
+ end # module