Module: D3::Admin::Validate
Overview
This module contains methods for validating options given to d3admin either on the commandline or via a walkthru
Each method takes an argument, and either raises an exception if the argument isn’t valid for its destination, or converts it to the proper type for its destination.
For options that set attributes of packages, the appropriate D3::Package::Validate method is called.
For example, the #validate_groups takes either a comma-seprated String or an Array of computer group names, converts the String to an Array if needed, and then confirms that each group exists in the JSS If they all do, the Array is returned.
Class Method Summary collapse
-
.validate(value, validate_method) ⇒ Array<Boolean, Object>
Check a value with a given ‘validate_’ method catching the excpetions and returning error messages.
- .validate_auto_groups(groups) ⇒ Object
-
.validate_basename(basename) ⇒ String
Check that a basename exists, and return it or raise an exception.
-
.validate_category(cat) ⇒ String
Check the validity of a category Raise an exception if not valid.
-
.validate_computer(ident) ⇒ Integer
check that a computer name or id exists in jamf.
-
.validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid.
-
.validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens.
- .validate_excluded_groups(groups) ⇒ Object
-
.validate_existing_package(pkg_to_check) ⇒ D3::Package
Check that a given basename or edition exists in d3, and if so, return the package id If a basename is given, the currently live one is returned If there is no matching edition or live basename, an exception is raised.
-
.validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration.
-
.validate_expiration_path(path) ⇒ Pathname?
Confirm the validity of an expiration path.
-
.validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths.
-
.validate_filename(name) ⇒ String
check that the given filename doesn’t already exist.
-
.validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
-
.validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid.
-
.validate_package_build_type(type) ⇒ Symbol
check the validity of the pkg build type.
-
.validate_package_for_import(pkg_to_check) ⇒ D3::Package
check that a given pkg id or display name exists in the JSS but not in d3, and if so, return the valid name or id.
-
.validate_package_identifier(pkgid) ⇒ String
Check the pkg identifier.
-
.validate_package_identifier_prefix(pfx) ⇒ String
Check the pkg identifier prefix.
-
.validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist.
-
.validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script.
-
.validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
.validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script.
-
.validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
.validate_prohibiting_processes(process_names) ⇒ Array<String>
Check multiple prohibiting_processes for validity.
-
.validate_report_type(type) ⇒ String
Check that a report type is valid.
-
.validate_revision(rev) ⇒ Integer
Confirm the validity of a revision.
- .validate_scoped_groups(groups) ⇒ Object
-
.validate_show_type(type) ⇒ String
Check that a show type is valid.
-
.validate_signing_idenitity(id) ⇒ Object
Validate Signing Identity ?.
-
.validate_signing_options(options) ⇒ Object
Validate Signing Options.
-
.validate_source_path(src) ⇒ Pathname
Check the validity of the local source path Raises an exception if not valid.
-
.validate_version(vers) ⇒ String
Confirm the validity of a version.
-
.validate_workspace(wkspc) ⇒ Pathname
Check the path given as a workspace for building pkgs.
-
.validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no true/false reply.
Instance Method Summary collapse
-
#validate(value, validate_method) ⇒ Array<Boolean, Object>
Check a value with a given ‘validate_’ method catching the excpetions and returning error messages.
- #validate_auto_groups(groups) ⇒ Object
-
#validate_basename(basename) ⇒ String
Check that a basename exists, and return it or raise an exception.
-
#validate_category(cat) ⇒ String
Check the validity of a category Raise an exception if not valid.
-
#validate_computer(ident) ⇒ Integer
check that a computer name or id exists in jamf.
-
#validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid.
-
#validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens.
- #validate_excluded_groups(groups) ⇒ Object
-
#validate_existing_package(pkg_to_check) ⇒ D3::Package
Check that a given basename or edition exists in d3, and if so, return the package id If a basename is given, the currently live one is returned If there is no matching edition or live basename, an exception is raised.
-
#validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration.
-
#validate_expiration_path(path) ⇒ Pathname?
Confirm the validity of an expiration path.
-
#validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths.
-
#validate_filename(name) ⇒ String
check that the given filename doesn’t already exist.
-
#validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
-
#validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid.
-
#validate_package_build_type(type) ⇒ Symbol
check the validity of the pkg build type.
-
#validate_package_for_import(pkg_to_check) ⇒ D3::Package
check that a given pkg id or display name exists in the JSS but not in d3, and if so, return the valid name or id.
-
#validate_package_identifier(pkgid) ⇒ String
Check the pkg identifier.
-
#validate_package_identifier_prefix(pfx) ⇒ String
Check the pkg identifier prefix.
-
#validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist.
-
#validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script.
-
#validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
#validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script.
-
#validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script.
-
#validate_prohibiting_processes(process_names) ⇒ Array<String>
Check multiple prohibiting_processes for validity.
-
#validate_report_type(type) ⇒ String
Check that a report type is valid.
-
#validate_revision(rev) ⇒ Integer
Confirm the validity of a revision.
- #validate_scoped_groups(groups) ⇒ Object
-
#validate_show_type(type) ⇒ String
Check that a show type is valid.
-
#validate_signing_idenitity(id) ⇒ Object
Validate Signing Identity ?.
-
#validate_signing_options(options) ⇒ Object
Validate Signing Options.
-
#validate_source_path(src) ⇒ Pathname
Check the validity of the local source path Raises an exception if not valid.
-
#validate_version(vers) ⇒ String
Confirm the validity of a version.
-
#validate_workspace(wkspc) ⇒ Pathname
Check the path given as a workspace for building pkgs.
-
#validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no true/false reply.
Class Method Details
.validate(value, validate_method) ⇒ Array<Boolean, Object>
Check a value with a given ‘validate_’ method catching the excpetions and returning error messages
59 60 61 62 63 64 65 66 67 |
# File 'lib/d3/admin/validate.rb', line 59 def validate(value, validate_method) return [true, value] unless validate_method begin valid_value = self.send(validate_method, value) return [true, valid_value] rescue JSS::InvalidDataError, JSS::NoSuchItemError, JSS::AlreadyExistsError return [false, $ERROR_INFO] end # begin end |
.validate_auto_groups(groups) ⇒ Object
320 321 322 |
# File 'lib/d3/admin/validate.rb', line 320 def validate_auto_groups(groups) D3::Package::Validate.validate_auto_groups groups end |
.validate_basename(basename) ⇒ String
Check that a basename exists, and return it or raise an exception
132 133 134 135 |
# File 'lib/d3/admin/validate.rb', line 132 def validate_basename(basename) raise JSS::NoSuchItemError, "There's no package in d3 with the basename '#{basename}'" unless D3::Package::Validate.basename_exist? basename.to_s basename.to_s end |
.validate_category(cat) ⇒ String
Check the validity of a category Raise an exception if not valid
371 372 373 |
# File 'lib/d3/admin/validate.rb', line 371 def validate_category(cat) D3::Package::Validate.validate_category cat end |
.validate_computer(ident) ⇒ Integer
check that a computer name or id exists in jamf
277 278 279 280 281 282 283 284 285 |
# File 'lib/d3/admin/validate.rb', line 277 def validate_computer(ident) id = JSS::Computer.map_all_ids_to(:name).invert[ident] id ||= JSS::Computer.map_all_ids_to(:serial_number).invert[ident] id ||= JSS::Computer.map_all_ids_to(:mac_address).invert[ident] id ||= JSS::Computer.map_all_ids_to(:udid).invert[ident] return id if id return ident.to_i if JSS::Computer.all_ids.include? ident.to_i raise JSS::NoSuchItemError, "No computer in the JSS matches '#{ident}'" end |
.validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid
360 361 362 |
# File 'lib/d3/admin/validate.rb', line 360 def validate_cpu_type(type) D3::Package::Validate.validate_cpu_type type end |
.validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens
144 145 146 |
# File 'lib/d3/admin/validate.rb', line 144 def validate_edition(edition) D3::Package::Validate.validate_edition edition end |
.validate_excluded_groups(groups) ⇒ Object
325 326 327 |
# File 'lib/d3/admin/validate.rb', line 325 def validate_excluded_groups(groups) D3::Package::Validate.validate_groups groups end |
.validate_existing_package(pkg_to_check) ⇒ D3::Package
Check that a given basename or edition exists in d3, and if so, return the package id If a basename is given, the currently live one is returned If there is no matching edition or live basename, an exception is raised
99 100 101 102 103 104 105 106 |
# File 'lib/d3/admin/validate.rb', line 99 def validate_existing_package(pkg_to_check) # were we given an edition? pkgid = D3::Package.ids_to_editions.invert[pkg_to_check] # if not, were we given a basename? pkgid ||= D3::Package.basenames_to_live_ids[pkg_to_check] raise JSS::NoSuchItemError, "No edition or live-basename in d3 match '#{pkg_to_check}'" if pkgid.nil? pkgid end |
.validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration. Raise an exception if invalid.
404 405 406 |
# File 'lib/d3/admin/validate.rb', line 404 def validate_expiration(exp) D3::Package::Validate.validate_expiration exp end |
.validate_expiration_path(path) ⇒ Pathname?
Confirm the validity of an expiration path. any string that starts with a / is valid.
427 428 429 |
# File 'lib/d3/admin/validate.rb', line 427 def validate_expiration_path(path) D3::Package::Validate.validate_expiration_path path end |
.validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths. Any string that starts with a / is valid. The strings “n” or “none” returns an empty array.
416 417 418 |
# File 'lib/d3/admin/validate.rb', line 416 def validate_expiration_paths(paths) D3::Package::Validate.validate_expiration_paths paths end |
.validate_filename(name) ⇒ String
check that the given filename doesn’t already exist
def self.validate_filename(name)
123 124 125 |
# File 'lib/d3/admin/validate.rb', line 123 def validate_filename(name) D3::Package::Validate.validate_filename name end |
.validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
338 339 340 |
# File 'lib/d3/admin/validate.rb', line 338 def validate_non_overlapping_groups(auto, excl) D3::Package::Validate.validate_non_overlapping_groups auto, excl end |
.validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid
349 350 351 |
# File 'lib/d3/admin/validate.rb', line 349 def validate_oses(os_list) D3::Package::Validate.validate_oses os_list end |
.validate_package_build_type(type) ⇒ Symbol
check the validity of the pkg build type
193 194 195 196 197 198 199 |
# File 'lib/d3/admin/validate.rb', line 193 def validate_package_build_type(type) case type.to_s.delete('.') when /^p/i then :pkg when /^d/i then :dmg else raise JSS::InvalidDataError, "Package type must be 'pkg', 'dmg', 'p', or 'd'" end # case end |
.validate_package_for_import(pkg_to_check) ⇒ D3::Package
check that a given pkg id or display name exists in the JSS but not in d3, and if so, return the valid name or id
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/d3/admin/validate.rb', line 76 def validate_package_for_import(pkg_to_check) # an id, or a name? if pkg_to_check.to_s =~ /^\d+$/ raise JSS::NoSuchItemError, "No package in the JSS with id #{pkg_to_check}" unless JSS::Package.all_ids.include? pkg_to_check.to_i raise JSS::AlreadyExistsError, "JSS Package id #{pkg_to_check} is already in d3" if D3::Package.all_ids.include? pkg_to_check.to_i pkg_to_check.to_i else raise JSS::NoSuchItemError, "No package in the JSS with display-name #{pkg_to_check}" unless JSS::Package.all_names.include? pkg_to_check raise JSS::AlreadyExistsError, "JSS Package named #{pkg_to_check} is already in d3" if D3::Package.all_names.include? pkg_to_check pkg_to_check end end |
.validate_package_identifier(pkgid) ⇒ String
Check the pkg identifier
207 208 209 210 211 |
# File 'lib/d3/admin/validate.rb', line 207 def validate_package_identifier(pkgid) raise JSS::InvalidDataError, 'Package Identifier must be a String' unless pkgid.is_a? String raise JSS::InvalidDataError, 'Package Identifier cannot be empty' if pkgid.empty? pkgid end |
.validate_package_identifier_prefix(pfx) ⇒ String
Check the pkg identifier prefix
219 220 221 222 223 |
# File 'lib/d3/admin/validate.rb', line 219 def validate_package_identifier_prefix(pfx) return nil if pfx.to_s.empty? raise JSS::InvalidDataError, 'Package Identifier Prefix must be a String' unless pfx.is_a? String pfx end |
.validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist
112 113 114 |
# File 'lib/d3/admin/validate.rb', line 112 def validate_package_name(name) D3::Package::Validate.validate_package_name name end |
.validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script
299 300 301 |
# File 'lib/d3/admin/validate.rb', line 299 def validate_post_install_script(script) D3::Package::Validate.validate_script script end |
.validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
315 316 317 |
# File 'lib/d3/admin/validate.rb', line 315 def validate_post_remove_script(script) D3::Package::Validate.validate_script script end |
.validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script
291 292 293 |
# File 'lib/d3/admin/validate.rb', line 291 def validate_pre_install_script(script) D3::Package::Validate.validate_script script end |
.validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
307 308 309 |
# File 'lib/d3/admin/validate.rb', line 307 def validate_pre_remove_script(script) D3::Package::Validate.validate_script script end |
.validate_prohibiting_processes(process_names) ⇒ Array<String>
Check multiple prohibiting_processes for validity
381 382 383 384 385 |
# File 'lib/d3/admin/validate.rb', line 381 def validate_prohibiting_processes(process_names) process_names = [] if process_names.to_s =~ /^n(one)?$/i names_as_array = JSS.to_s_and_a(process_names)[:arrayform] names_as_array.map { |procname| D3::Package::Validate.validate_prohibiting_process(procname) }.compact end |
.validate_report_type(type) ⇒ String
Check that a report type is valid
251 252 253 254 |
# File 'lib/d3/admin/validate.rb', line 251 def validate_report_type(type) raise ArgumentError, "Report type must be one of: #{D3::Admin::Report::REPORT_TYPES.join(', ')}" unless D3::Admin::Report::REPORT_TYPES.include? type type end |
.validate_revision(rev) ⇒ Integer
Confirm the validity of a revision. Raise an exception if invalid.
165 166 167 |
# File 'lib/d3/admin/validate.rb', line 165 def validate_revision(rev) D3::Package::Validate.validate_revision rev end |
.validate_scoped_groups(groups) ⇒ Object
266 267 268 |
# File 'lib/d3/admin/validate.rb', line 266 def validate_scoped_groups(groups) D3::Package::Validate.validate_groups groups end |
.validate_show_type(type) ⇒ String
Check that a show type is valid
260 261 262 263 |
# File 'lib/d3/admin/validate.rb', line 260 def validate_show_type(type) raise ArgumentError, "Package list must be one of: #{D3::Admin::Report::SHOW_TYPES.join(', ')}" unless D3::Admin::Report::SHOW_TYPES.include? type type end |
.validate_signing_idenitity(id) ⇒ Object
Validate Signing Identity ?
226 227 228 |
# File 'lib/d3/admin/validate.rb', line 226 def validate_signing_idenitity(id) id.is_a?(String) && id end |
.validate_signing_options(options) ⇒ Object
Validate Signing Options
231 232 233 |
# File 'lib/d3/admin/validate.rb', line 231 def () .is_a?(String) && end |
.validate_source_path(src) ⇒ Pathname
Check the validity of the local source path Raises an exception if not valid
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/d3/admin/validate.rb', line 176 def validate_source_path(src) raise JSS::InvalidDataError, 'Source path cannot be empty' if src.to_s.empty? src = Pathname.new(src.to_s). raise JSS::NoSuchItemError, "'#{src}' doesn't exist" unless src.exist? return src if src.to_s.end_with?('.dmg') || src.to_s =~ /\.m?pkg$/ # isn't a dmg or pkg, check that its a directory to use as a pkg root raise JSS::InvalidDataError, "#{src} isn't a .dmg or .pkg, but isn't a folder,\ncan't use it for building packages." unless src.directory? src end |
.validate_version(vers) ⇒ String
Confirm the validity of a version. Raise an exception if invalid.
154 155 156 |
# File 'lib/d3/admin/validate.rb', line 154 def validate_version(vers) D3::Package::Validate.validate_version vers end |
.validate_workspace(wkspc) ⇒ Pathname
Check the path given as a workspace for building pkgs
239 240 241 242 243 244 245 |
# File 'lib/d3/admin/validate.rb', line 239 def validate_workspace(wkspc) wkspc = Pathname.new(wkspc). raise JSS::NoSuchItemError, "Workspace folder '#{wkspc}' doesn't exist" unless wkspc.exist? raise JSS::InvalidDataError, "Workspace folder '#{wkspc}' isn't a folder" unless wkspc.directory? D3::Admin::Prefs.set_pref :workspace, wkspc wkspc end |
.validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no true/false reply
393 394 395 |
# File 'lib/d3/admin/validate.rb', line 393 def validate_yes_no(yn) D3::Package::Validate.validate_yes_no yn end |
Instance Method Details
#validate(value, validate_method) ⇒ Array<Boolean, Object>
Check a value with a given ‘validate_’ method catching the excpetions and returning error messages
59 60 61 62 63 64 65 66 67 |
# File 'lib/d3/admin/validate.rb', line 59 def validate(value, validate_method) return [true, value] unless validate_method begin valid_value = self.send(validate_method, value) return [true, valid_value] rescue JSS::InvalidDataError, JSS::NoSuchItemError, JSS::AlreadyExistsError return [false, $ERROR_INFO] end # begin end |
#validate_auto_groups(groups) ⇒ Object
320 321 322 |
# File 'lib/d3/admin/validate.rb', line 320 def validate_auto_groups(groups) D3::Package::Validate.validate_auto_groups groups end |
#validate_basename(basename) ⇒ String
Check that a basename exists, and return it or raise an exception
132 133 134 135 |
# File 'lib/d3/admin/validate.rb', line 132 def validate_basename(basename) raise JSS::NoSuchItemError, "There's no package in d3 with the basename '#{basename}'" unless D3::Package::Validate.basename_exist? basename.to_s basename.to_s end |
#validate_category(cat) ⇒ String
Check the validity of a category Raise an exception if not valid
371 372 373 |
# File 'lib/d3/admin/validate.rb', line 371 def validate_category(cat) D3::Package::Validate.validate_category cat end |
#validate_computer(ident) ⇒ Integer
check that a computer name or id exists in jamf
277 278 279 280 281 282 283 284 285 |
# File 'lib/d3/admin/validate.rb', line 277 def validate_computer(ident) id = JSS::Computer.map_all_ids_to(:name).invert[ident] id ||= JSS::Computer.map_all_ids_to(:serial_number).invert[ident] id ||= JSS::Computer.map_all_ids_to(:mac_address).invert[ident] id ||= JSS::Computer.map_all_ids_to(:udid).invert[ident] return id if id return ident.to_i if JSS::Computer.all_ids.include? ident.to_i raise JSS::NoSuchItemError, "No computer in the JSS matches '#{ident}'" end |
#validate_cpu_type(type) ⇒ Symbol
Check the validity of a CPU type Raise an exception if not valid
360 361 362 |
# File 'lib/d3/admin/validate.rb', line 360 def validate_cpu_type(type) D3::Package::Validate.validate_cpu_type type end |
#validate_edition(edition) ⇒ String
Check if an edition exists and raise an exception if so Also check that it contains at least two hyphens
144 145 146 |
# File 'lib/d3/admin/validate.rb', line 144 def validate_edition(edition) D3::Package::Validate.validate_edition edition end |
#validate_excluded_groups(groups) ⇒ Object
325 326 327 |
# File 'lib/d3/admin/validate.rb', line 325 def validate_excluded_groups(groups) D3::Package::Validate.validate_groups groups end |
#validate_existing_package(pkg_to_check) ⇒ D3::Package
Check that a given basename or edition exists in d3, and if so, return the package id If a basename is given, the currently live one is returned If there is no matching edition or live basename, an exception is raised
99 100 101 102 103 104 105 106 |
# File 'lib/d3/admin/validate.rb', line 99 def validate_existing_package(pkg_to_check) # were we given an edition? pkgid = D3::Package.ids_to_editions.invert[pkg_to_check] # if not, were we given a basename? pkgid ||= D3::Package.basenames_to_live_ids[pkg_to_check] raise JSS::NoSuchItemError, "No edition or live-basename in d3 match '#{pkg_to_check}'" if pkgid.nil? pkgid end |
#validate_expiration(exp) ⇒ Integer
Confirm the validity of an expiration. Raise an exception if invalid.
404 405 406 |
# File 'lib/d3/admin/validate.rb', line 404 def validate_expiration(exp) D3::Package::Validate.validate_expiration exp end |
#validate_expiration_path(path) ⇒ Pathname?
Confirm the validity of an expiration path. any string that starts with a / is valid.
427 428 429 |
# File 'lib/d3/admin/validate.rb', line 427 def validate_expiration_path(path) D3::Package::Validate.validate_expiration_path path end |
#validate_expiration_paths(paths) ⇒ Array<Pathname>
Confirm the validity of one or more expiration paths. Any string that starts with a / is valid. The strings “n” or “none” returns an empty array.
416 417 418 |
# File 'lib/d3/admin/validate.rb', line 416 def validate_expiration_paths(paths) D3::Package::Validate.validate_expiration_paths paths end |
#validate_filename(name) ⇒ String
check that the given filename doesn’t already exist
def self.validate_filename(name)
123 124 125 |
# File 'lib/d3/admin/validate.rb', line 123 def validate_filename(name) D3::Package::Validate.validate_filename name end |
#validate_non_overlapping_groups(auto, excl) ⇒ True
Make sure auto and excluded groups don’t have any members in common, raise an exception if they do.
338 339 340 |
# File 'lib/d3/admin/validate.rb', line 338 def validate_non_overlapping_groups(auto, excl) D3::Package::Validate.validate_non_overlapping_groups auto, excl end |
#validate_oses(os_list) ⇒ Array
Check the validity of a list of OSes Raise an exception if not valid
349 350 351 |
# File 'lib/d3/admin/validate.rb', line 349 def validate_oses(os_list) D3::Package::Validate.validate_oses os_list end |
#validate_package_build_type(type) ⇒ Symbol
check the validity of the pkg build type
193 194 195 196 197 198 199 |
# File 'lib/d3/admin/validate.rb', line 193 def validate_package_build_type(type) case type.to_s.delete('.') when /^p/i then :pkg when /^d/i then :dmg else raise JSS::InvalidDataError, "Package type must be 'pkg', 'dmg', 'p', or 'd'" end # case end |
#validate_package_for_import(pkg_to_check) ⇒ D3::Package
check that a given pkg id or display name exists in the JSS but not in d3, and if so, return the valid name or id
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/d3/admin/validate.rb', line 76 def validate_package_for_import(pkg_to_check) # an id, or a name? if pkg_to_check.to_s =~ /^\d+$/ raise JSS::NoSuchItemError, "No package in the JSS with id #{pkg_to_check}" unless JSS::Package.all_ids.include? pkg_to_check.to_i raise JSS::AlreadyExistsError, "JSS Package id #{pkg_to_check} is already in d3" if D3::Package.all_ids.include? pkg_to_check.to_i pkg_to_check.to_i else raise JSS::NoSuchItemError, "No package in the JSS with display-name #{pkg_to_check}" unless JSS::Package.all_names.include? pkg_to_check raise JSS::AlreadyExistsError, "JSS Package named #{pkg_to_check} is already in d3" if D3::Package.all_names.include? pkg_to_check pkg_to_check end end |
#validate_package_identifier(pkgid) ⇒ String
Check the pkg identifier
207 208 209 210 211 |
# File 'lib/d3/admin/validate.rb', line 207 def validate_package_identifier(pkgid) raise JSS::InvalidDataError, 'Package Identifier must be a String' unless pkgid.is_a? String raise JSS::InvalidDataError, 'Package Identifier cannot be empty' if pkgid.empty? pkgid end |
#validate_package_identifier_prefix(pfx) ⇒ String
Check the pkg identifier prefix
219 220 221 222 223 |
# File 'lib/d3/admin/validate.rb', line 219 def validate_package_identifier_prefix(pfx) return nil if pfx.to_s.empty? raise JSS::InvalidDataError, 'Package Identifier Prefix must be a String' unless pfx.is_a? String pfx end |
#validate_package_name(name) ⇒ Object
check that the given package name doesn’t already exist
112 113 114 |
# File 'lib/d3/admin/validate.rb', line 112 def validate_package_name(name) D3::Package::Validate.validate_package_name name end |
#validate_post_install_script(script) ⇒ Object
Check the validity of a post_install script
299 300 301 |
# File 'lib/d3/admin/validate.rb', line 299 def validate_post_install_script(script) D3::Package::Validate.validate_script script end |
#validate_post_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
315 316 317 |
# File 'lib/d3/admin/validate.rb', line 315 def validate_post_remove_script(script) D3::Package::Validate.validate_script script end |
#validate_pre_install_script(script) ⇒ Object
Check the validity of a pre_install script
291 292 293 |
# File 'lib/d3/admin/validate.rb', line 291 def validate_pre_install_script(script) D3::Package::Validate.validate_script script end |
#validate_pre_remove_script(script) ⇒ Object
Check the validity of a pre_remove script
307 308 309 |
# File 'lib/d3/admin/validate.rb', line 307 def validate_pre_remove_script(script) D3::Package::Validate.validate_script script end |
#validate_prohibiting_processes(process_names) ⇒ Array<String>
Check multiple prohibiting_processes for validity
381 382 383 384 385 |
# File 'lib/d3/admin/validate.rb', line 381 def validate_prohibiting_processes(process_names) process_names = [] if process_names.to_s =~ /^n(one)?$/i names_as_array = JSS.to_s_and_a(process_names)[:arrayform] names_as_array.map { |procname| D3::Package::Validate.validate_prohibiting_process(procname) }.compact end |
#validate_report_type(type) ⇒ String
Check that a report type is valid
251 252 253 254 |
# File 'lib/d3/admin/validate.rb', line 251 def validate_report_type(type) raise ArgumentError, "Report type must be one of: #{D3::Admin::Report::REPORT_TYPES.join(', ')}" unless D3::Admin::Report::REPORT_TYPES.include? type type end |
#validate_revision(rev) ⇒ Integer
Confirm the validity of a revision. Raise an exception if invalid.
165 166 167 |
# File 'lib/d3/admin/validate.rb', line 165 def validate_revision(rev) D3::Package::Validate.validate_revision rev end |
#validate_scoped_groups(groups) ⇒ Object
266 267 268 |
# File 'lib/d3/admin/validate.rb', line 266 def validate_scoped_groups(groups) D3::Package::Validate.validate_groups groups end |
#validate_show_type(type) ⇒ String
Check that a show type is valid
260 261 262 263 |
# File 'lib/d3/admin/validate.rb', line 260 def validate_show_type(type) raise ArgumentError, "Package list must be one of: #{D3::Admin::Report::SHOW_TYPES.join(', ')}" unless D3::Admin::Report::SHOW_TYPES.include? type type end |
#validate_signing_idenitity(id) ⇒ Object
Validate Signing Identity ?
226 227 228 |
# File 'lib/d3/admin/validate.rb', line 226 def validate_signing_idenitity(id) id.is_a?(String) && id end |
#validate_signing_options(options) ⇒ Object
Validate Signing Options
231 232 233 |
# File 'lib/d3/admin/validate.rb', line 231 def () .is_a?(String) && end |
#validate_source_path(src) ⇒ Pathname
Check the validity of the local source path Raises an exception if not valid
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/d3/admin/validate.rb', line 176 def validate_source_path(src) raise JSS::InvalidDataError, 'Source path cannot be empty' if src.to_s.empty? src = Pathname.new(src.to_s). raise JSS::NoSuchItemError, "'#{src}' doesn't exist" unless src.exist? return src if src.to_s.end_with?('.dmg') || src.to_s =~ /\.m?pkg$/ # isn't a dmg or pkg, check that its a directory to use as a pkg root raise JSS::InvalidDataError, "#{src} isn't a .dmg or .pkg, but isn't a folder,\ncan't use it for building packages." unless src.directory? src end |
#validate_version(vers) ⇒ String
Confirm the validity of a version. Raise an exception if invalid.
154 155 156 |
# File 'lib/d3/admin/validate.rb', line 154 def validate_version(vers) D3::Package::Validate.validate_version vers end |
#validate_workspace(wkspc) ⇒ Pathname
Check the path given as a workspace for building pkgs
239 240 241 242 243 244 245 |
# File 'lib/d3/admin/validate.rb', line 239 def validate_workspace(wkspc) wkspc = Pathname.new(wkspc). raise JSS::NoSuchItemError, "Workspace folder '#{wkspc}' doesn't exist" unless wkspc.exist? raise JSS::InvalidDataError, "Workspace folder '#{wkspc}' isn't a folder" unless wkspc.directory? D3::Admin::Prefs.set_pref :workspace, wkspc wkspc end |
#validate_yes_no(yn) ⇒ Boolean
check the validity of a yes/no true/false reply
393 394 395 |
# File 'lib/d3/admin/validate.rb', line 393 def validate_yes_no(yn) D3::Package::Validate.validate_yes_no yn end |