Puppet Function: simplib::passgen::legacy::remove
- Defined in:
- lib/puppet/functions/simplib/passgen/legacy/remove.rb
- Function type:
- Ruby 4.x API
Overview
Removes a generated password, history and stored attributes
-
Password info is stored in files on the local file system at ‘Puppet.settings/simp/environments/$environment/simp_autofiles/gen_passwd/`.
-
Password is stored in a file named for the identifier.
-
Salt is stored in a separate file named <identifier>.salt`.
-
Backups of the password and salt are files ending with ‘.last’.
-
-
Removes all password and salt files for the identifier.
-
Terminates catalog compilation if any password files cannot be removed by the user.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/puppet/functions/simplib/passgen/legacy/remove.rb', line 12 Puppet::Functions.create_function(:'simplib::passgen::legacy::remove') do # @param identifier Unique `String` to identify the password usage. # Must conform to the following: # * Identifier must contain only the following characters: # * a-z # * A-Z # * 0-9 # * The following special characters: # * `._:-` for the legacy implementation # * `._:-/` for the simpkv-enabled implementation # * Identifier may not contain '/./' or '/../' sequences. # # @return [Nil] # @raise Exception any legacy password file cannot be removed # dispatch :remove do required_param 'String[1]', :identifier end def remove(identifier) settings = call_function('simplib::passgen::legacy::common_settings') keydir = settings['keydir'] password_files = [ File.join(keydir, identifier), File.join(keydir, "#{identifier}.salt"), File.join(keydir, "#{identifier}.last"), File.join(keydir, "#{identifier}.salt.last"), File.join(keydir, "#{identifier}.last.last"), File.join(keydir, "#{identifier}.salt.last.last") ] failures = [] password_files.each do |file| if File.exist?(file) begin File.unlink(file) rescue Exception => e failures << "#{file}: #{e.}" end end end unless failures.empty? msg = "Unable to remove all files:\n#{failures.join("\n")}" raise("simplib::passgen::legacy::delete failed: #{msg}") end end end |