Module: D3::Admin::Validate

Extended by:
Validate
Included in:
Validate
Defined in:
lib/d3/admin/validate.rb

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

Instance Method Summary collapse

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

Parameters:

  • value (String)

    the value from the user to check

  • validate_method (Symbol)

    the method to use to check the value

Returns:

  • (Array<Boolean, Object>)

    A two-item array. The first item is a Boolean representing the success of failure of the check. The second item is the validated input, if the check was good, or the error message if not.



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

See Also:

  • #validate_groups


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

Parameters:

  • basename (String)

Returns:

  • (String)

    the valid basename

Raises:

  • (JSS::NoSuchItemError)


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

Parameters:

  • cat (String)

    the category to check

Returns:

  • (String)

    the valid category



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

Parameters:

  • the (String, Integer)

    name, id, serialnumber, macaaddress, or udid of a computer in the JSS

Returns:

  • (Integer)

    the valid computer id

Raises:

  • (JSS::NoSuchItemError)


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

Parameters:

  • the (Symbol)

    CPU type to check

Returns:

  • (Symbol)

    the valid CPU type



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

Parameters:

  • edition (String)

    the edition to check

Returns:

  • (String)

    the valid, unique edition



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

See Also:

  • #validate_groups


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

Parameters:

  • pkg_to_check (String)

    a basename or edition

Returns:

Raises:

  • (JSS::NoSuchItemError)


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.

Parameters:

  • exp (Integer)

    the expiration to check

Returns:

  • (Integer)

    the valid expiration



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.

Parameters:

  • path (Pathname, String)

    the path to check

Returns:

  • (Pathname, nil)

    the valid path



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.

Parameters:

  • paths (Pathname, String, Array<String,Pathname>)

    the path(s) to check

Returns:

  • (Array<Pathname>)

    the valid path



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)

Parameters:

  • name (String)

    the name to check

Returns:

  • (String)

    the valid new file 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.

Parameters:

  • auto (Array)

    the array of auto groups

  • excl (Array)

    the array of excluded groups

Returns:

  • (True)

    true if there are no groups in common



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

Parameters:

  • Array (String, Array)

    or comma-separated list of OSes to check

Returns:

  • (Array)

    the valid OS list



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

Parameters:

  • type (String)

    the string to check

Returns:

  • (Symbol)

    :pkg or :dmg



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

Parameters:

  • pkg_to_check (String)

    a display name or JSS pkg id

Returns:



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

Parameters:

  • pkgid (String)

    the identifer

Returns:

  • (String)

    the valid identifier

Raises:

  • (JSS::InvalidDataError)


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

Parameters:

  • pfx (String)

    the prefix for the identifer

Returns:

  • (String)

    the cleaned-up identifier

Raises:

  • (JSS::InvalidDataError)


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

See Also:

  • D3::Admin::Validate.{JSS{JSS::Package{JSS::Package.validate_package_name}


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

See Also:

  • #validate_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

See Also:

  • #validate_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

See Also:

  • #validate_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

See Also:

  • #validate_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

Parameters:

  • process_names (String, Array<String>)

    A comma-separated String, or an Array of process names to be validated.

Returns:

  • (Array<String>)


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

Returns:

  • (String)

    the valid report type.

Raises:

  • (ArgumentError)


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.

Parameters:

  • rev (Integer)

    the revision to check

Returns:

  • (Integer)

    the valid revision



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

See Also:

  • Package::Validate.validate_groups


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

Returns:

  • (String)

    the valid show type.

Raises:

  • (ArgumentError)


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 validate_signing_options(options)
  options.is_a?(String) && options
end

.validate_source_path(src) ⇒ Pathname

Check the validity of the local source path Raises an exception if not valid

Parameters:

  • src (Pathname, String)

    the path to check

Returns:

  • (Pathname)

    the valid, fully-expanded path

Raises:

  • (JSS::InvalidDataError)


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).expand_path
  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.

Parameters:

  • vers (String)

    the version to check

Returns:

  • (String)

    An error message, or true if the value is ok



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

Returns:

  • (Pathname)

    the valid, full path to the workspace folder

Raises:

  • (JSS::NoSuchItemError)


239
240
241
242
243
244
245
# File 'lib/d3/admin/validate.rb', line 239

def validate_workspace(wkspc)
  wkspc = Pathname.new(wkspc).expand_path
  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

Parameters:

  • type (String, Boolean)

    the value to check

Returns:

  • (Boolean)


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

Parameters:

  • value (String)

    the value from the user to check

  • validate_method (Symbol)

    the method to use to check the value

Returns:

  • (Array<Boolean, Object>)

    A two-item array. The first item is a Boolean representing the success of failure of the check. The second item is the validated input, if the check was good, or the error message if not.



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

See Also:

  • #validate_groups


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

Parameters:

  • basename (String)

Returns:

  • (String)

    the valid basename

Raises:

  • (JSS::NoSuchItemError)


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

Parameters:

  • cat (String)

    the category to check

Returns:

  • (String)

    the valid category



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

Parameters:

  • the (String, Integer)

    name, id, serialnumber, macaaddress, or udid of a computer in the JSS

Returns:

  • (Integer)

    the valid computer id

Raises:

  • (JSS::NoSuchItemError)


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

Parameters:

  • the (Symbol)

    CPU type to check

Returns:

  • (Symbol)

    the valid CPU type



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

Parameters:

  • edition (String)

    the edition to check

Returns:

  • (String)

    the valid, unique edition



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

See Also:

  • #validate_groups


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

Parameters:

  • pkg_to_check (String)

    a basename or edition

Returns:

Raises:

  • (JSS::NoSuchItemError)


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.

Parameters:

  • exp (Integer)

    the expiration to check

Returns:

  • (Integer)

    the valid expiration



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.

Parameters:

  • path (Pathname, String)

    the path to check

Returns:

  • (Pathname, nil)

    the valid path



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.

Parameters:

  • paths (Pathname, String, Array<String,Pathname>)

    the path(s) to check

Returns:

  • (Array<Pathname>)

    the valid path



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)

Parameters:

  • name (String)

    the name to check

Returns:

  • (String)

    the valid new file 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.

Parameters:

  • auto (Array)

    the array of auto groups

  • excl (Array)

    the array of excluded groups

Returns:

  • (True)

    true if there are no groups in common



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

Parameters:

  • Array (String, Array)

    or comma-separated list of OSes to check

Returns:

  • (Array)

    the valid OS list



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

Parameters:

  • type (String)

    the string to check

Returns:

  • (Symbol)

    :pkg or :dmg



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

Parameters:

  • pkg_to_check (String)

    a display name or JSS pkg id

Returns:



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

Parameters:

  • pkgid (String)

    the identifer

Returns:

  • (String)

    the valid identifier

Raises:

  • (JSS::InvalidDataError)


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

Parameters:

  • pfx (String)

    the prefix for the identifer

Returns:

  • (String)

    the cleaned-up identifier

Raises:

  • (JSS::InvalidDataError)


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

See Also:

  • D3::Admin::Validate.{JSS{JSS::Package{JSS::Package.validate_package_name}


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

See Also:

  • #validate_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

See Also:

  • #validate_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

See Also:

  • #validate_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

See Also:

  • #validate_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

Parameters:

  • process_names (String, Array<String>)

    A comma-separated String, or an Array of process names to be validated.

Returns:

  • (Array<String>)


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

Returns:

  • (String)

    the valid report type.

Raises:

  • (ArgumentError)


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.

Parameters:

  • rev (Integer)

    the revision to check

Returns:

  • (Integer)

    the valid revision



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

See Also:

  • Package::Validate.validate_groups


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

Returns:

  • (String)

    the valid show type.

Raises:

  • (ArgumentError)


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 validate_signing_options(options)
  options.is_a?(String) && options
end

#validate_source_path(src) ⇒ Pathname

Check the validity of the local source path Raises an exception if not valid

Parameters:

  • src (Pathname, String)

    the path to check

Returns:

  • (Pathname)

    the valid, fully-expanded path

Raises:

  • (JSS::InvalidDataError)


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).expand_path
  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.

Parameters:

  • vers (String)

    the version to check

Returns:

  • (String)

    An error message, or true if the value is ok



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

Returns:

  • (Pathname)

    the valid, full path to the workspace folder

Raises:

  • (JSS::NoSuchItemError)


239
240
241
242
243
244
245
# File 'lib/d3/admin/validate.rb', line 239

def validate_workspace(wkspc)
  wkspc = Pathname.new(wkspc).expand_path
  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

Parameters:

  • type (String, Boolean)

    the value to check

Returns:

  • (Boolean)


393
394
395
# File 'lib/d3/admin/validate.rb', line 393

def validate_yes_no(yn)
  D3::Package::Validate.validate_yes_no yn
end