Class: Puppet::FileBucketFile::File

Inherits:
Indirector::Code show all
Includes:
Util::Checksums
Defined in:
lib/puppet/indirector/file_bucket_file/file.rb

Constant Summary

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

Util::Docs::HEADER_LEVELS

Instance Attribute Summary

Attributes included from Util::Docs

#doc, #nodoc

Instance Method Summary collapse

Methods included from Util::Checksums

#checksum?, #ctime, #ctime_file, #known_checksum_types, #md5, #md5_file, #md5_hex_length, #md5_stream, #md5lite, #md5lite_file, #mtime, #mtime_file, #mtime_stream, #none, #none_file, #none_stream, #sha1, #sha1_file, #sha1_hex_length, #sha1_stream, #sha1lite, #sha1lite_file, #sha256, #sha256_file, #sha256_hex_length, #sha256_stream, #sha256lite, #sha256lite_file, #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?, activerecord_version, benchmark, binread, chuser, classproxy, deterministic_rand, execfail, execpipe, execute, exit_on_fail, logmethods, memory, path_to_uri, pretty_backtrace, proxy, replace_file, safe_posix_fork, symbolizehash, thinmark, 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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 12

def find(request)
  checksum, files_original_path = request_to_checksum_and_path(request)
  contents_file = path_for(request.options[:bucket_path], checksum, 'contents')
  paths_file = path_for(request.options[:bucket_path], checksum, 'paths')

  if Puppet::FileSystem.exist?(contents_file) && matches(paths_file, files_original_path)
    if request.options[:diff_with]
      other_contents_file = path_for(request.options[:bucket_path], request.options[:diff_with], 'contents')
      raise "could not find diff_with #{request.options[:diff_with]}" unless Puppet::FileSystem.exist?(other_contents_file)
      return `diff #{Puppet::FileSystem.path_string(contents_file).inspect} #{Puppet::FileSystem.path_string(other_contents_file).inspect}`
    else
      Puppet.info "FileBucket read #{checksum}"
      model.new(Puppet::FileSystem.binread(contents_file))
    end
  else
    nil
  end
end

#head(request) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 31

def head(request)
  checksum, files_original_path = request_to_checksum_and_path(request)
  contents_file = path_for(request.options[:bucket_path], checksum, 'contents')
  paths_file = path_for(request.options[:bucket_path], checksum, 'paths')

  Puppet::FileSystem.exist?(contents_file) && matches(paths_file, files_original_path)
end

#save(request) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 39

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



51
52
53
# File 'lib/puppet/indirector/file_bucket_file/file.rb', line 51

def validate_key(request)
  # There are no ACLs on filebucket files so validating key is not important
end