Class: Puppet::FileBucketFile::File
- Inherits:
-
Indirector::Code
- Object
- Indirector::Terminus
- Indirector::Code
- Puppet::FileBucketFile::File
- Includes:
- Util::Checksums, Util::Diff
- Defined in:
- lib/puppet/indirector/file_bucket_file/file.rb
Constant Summary
Constants included from Util::Execution
Util::Execution::NoOptionsSpecified
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE
Constants included from Util::POSIX
Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS
Constants included from Util::SymbolicFileMode
Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit
Constants included from Util::Docs
Instance Attribute Summary
Attributes included from Util::Docs
Instance Method Summary collapse
- #find(request) ⇒ Object
- #head(request) ⇒ Object
- #list(request) ⇒ Object
- #save(request) ⇒ Object
- #validate_key(request) ⇒ Object
Methods included from Util::Diff
diff, #lcs_diff, #string_file_diff
Methods included from Util::Execution
execfail, execpipe, execute, ruby_path
Methods included from Util::Checksums
checksum?, checksum_file, checksum_stream, ctime, ctime?, ctime_file, ctime_stream, known_checksum_types, md5, md5?, md5_file, md5_hex_length, md5_stream, md5lite, md5lite?, md5lite_file, md5lite_hex_length, md5lite_stream, mtime, mtime?, mtime_file, mtime_stream, none, none?, none_file, none_stream, sha1, sha1?, sha1_file, sha1_hex_length, sha1_stream, sha1lite, sha1lite?, sha1lite_file, sha1lite_hex_length, sha1lite_stream, sha256, sha256?, sha256_file, sha256_hex_length, sha256_stream, sha256lite, sha256lite?, sha256lite_file, sha256lite_hex_length, sha256lite_stream, sumdata, sumtype
Methods inherited from Indirector::Terminus
abstract_terminus?, #allow_remote_requests?, const2name, #indirection, indirection_name, inherited, #initialize, mark_as_abstract_terminus, model, #model, #name, name2const, register_terminus_class, terminus_class, terminus_classes, #terminus_type, #validate, #validate_model
Methods included from Util::InstanceLoader
#instance_docs, #instance_hash, #instance_load, #instance_loader, #instance_loading?, #loaded_instance, #loaded_instances
Methods included from Util
absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Util::SymbolicFileMode
#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?
Methods included from Util::Docs
#desc, #dochook, #doctable, #markdown_definitionlist, #markdown_header, #nodoc?, #pad, scrub
Constructor Details
This class inherits a constructor from Puppet::Indirector::Terminus
Instance Method Details
#find(request) ⇒ Object
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 |
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 14 def find(request) request.[:bucket_path] ||= Puppet[:bucketdir] # If filebucket mode is 'list' if request.[:list_all] return nil unless ::File.exists?(request.[:bucket_path]) return list(request) end checksum, files_original_path = request_to_checksum_and_path(request) contents_file = path_for(request.[:bucket_path], checksum, 'contents') paths_file = path_for(request.[:bucket_path], checksum, 'paths') if Puppet::FileSystem.exist?(contents_file) && matches(paths_file, files_original_path) if request.[:diff_with] other_contents_file = path_for(request.[:bucket_path], request.[:diff_with], 'contents') raise _("could not find diff_with %{diff}") % { diff: request.[:diff_with] } unless Puppet::FileSystem.exist?(other_contents_file) raise _("Unable to diff on this platform") unless Puppet[:diff] != "" return diff(Puppet::FileSystem.path_string(contents_file), Puppet::FileSystem.path_string(other_contents_file)) else Puppet.info _("FileBucket read %{checksum}") % { checksum: checksum } model.new(Puppet::FileSystem.binread(contents_file)) end else nil end end |
#head(request) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 89 def head(request) checksum, files_original_path = request_to_checksum_and_path(request) contents_file = path_for(request.[:bucket_path], checksum, 'contents') paths_file = path_for(request.[:bucket_path], checksum, 'paths') Puppet::FileSystem.exist?(contents_file) && matches(paths_file, files_original_path) end |
#list(request) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 40 def list(request) if request.remote? raise Puppet::Error, _("Listing remote file buckets is not allowed") end fromdate = request.[:fromdate] || "0:0:0 1-1-1970" todate = request.[:todate] || Time.now.strftime("%F %T") begin to = Time.parse(todate) rescue ArgumentError raise Puppet::Error, _("Error while parsing 'todate'") end begin from = Time.parse(fromdate) rescue ArgumentError raise Puppet::Error, _("Error while parsing 'fromdate'") end # Setting hash's default value to [], needed by the following loop bucket = Hash.new {[]} msg = "" # Get all files with mtime between 'from' and 'to' Pathname.new(request.[:bucket_path]).find { |item| if item.file? and item.basename.to_s == "paths" filenames = item.read.strip.split("\n") filestat = Time.parse(item.stat.mtime.to_s) if from <= filestat and filestat <= to filenames.each do |filename| bucket[filename] += [[ item.stat.mtime , item.parent.basename ]] end end end } # Sort the results bucket.each { |filename, contents| contents.sort_by! do |item| # NOTE: Ruby 2.4 may reshuffle item order even if the keys in sequence are sorted already item[0] end } # Build the output message. Sorted by names then by dates bucket.sort.each { |filename,contents| contents.each { |mtime, chksum| date = mtime.strftime("%F %T") msg += "#{chksum} #{date} #{filename}\n" } } return model.new(msg) end |
#save(request) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 97 def save(request) instance = request.instance _, files_original_path = request_to_checksum_and_path(request) contents_file = path_for(instance.bucket_path, instance.checksum_data, 'contents') paths_file = path_for(instance.bucket_path, instance.checksum_data, 'paths') save_to_disk(instance, files_original_path, contents_file, paths_file) # don't echo the request content back to the agent model.new('') end |
#validate_key(request) ⇒ Object
109 110 111 |
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 109 def validate_key(request) # There are no ACLs on filebucket files so validating key is not important end |