Class: ChefServerApi::SandboxFile
- Inherits:
-
Object
- Object
- ChefServerApi::SandboxFile
- Defined in:
- app/models/sandbox_file.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#expected_checksum ⇒ Object
readonly
Returns the value of attribute expected_checksum.
-
#sandbox_id ⇒ Object
readonly
Returns the value of attribute sandbox_id.
Instance Method Summary collapse
- #actual_checksum ⇒ Object
- #commit_to(destination_file_path) ⇒ Object
-
#initialize(input, params = {}) ⇒ SandboxFile
constructor
A new instance of SandboxFile.
- #invalid_file? ⇒ Boolean
- #invalid_params? ⇒ Boolean
- #invalid_sandbox? ⇒ Boolean
- #resource_params ⇒ Object
- #sandbox ⇒ Object
Constructor Details
#initialize(input, params = {}) ⇒ SandboxFile
Returns a new instance of SandboxFile.
29 30 31 32 33 34 35 |
# File 'app/models/sandbox_file.rb', line 29 def initialize(input, params={}) @input = input @sandbox_id = params[:sandbox_id] @expected_checksum = params[:checksum] @sandbox_loaded = false @error = nil end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
27 28 29 |
# File 'app/models/sandbox_file.rb', line 27 def error @error end |
#expected_checksum ⇒ Object (readonly)
Returns the value of attribute expected_checksum.
26 27 28 |
# File 'app/models/sandbox_file.rb', line 26 def expected_checksum @expected_checksum end |
#sandbox_id ⇒ Object (readonly)
Returns the value of attribute sandbox_id.
25 26 27 |
# File 'app/models/sandbox_file.rb', line 25 def sandbox_id @sandbox_id end |
Instance Method Details
#actual_checksum ⇒ Object
57 58 59 60 61 62 |
# File 'app/models/sandbox_file.rb', line 57 def actual_checksum @actual_checksum ||= begin @input.rewind Chef::ChecksumCache.instance.generate_md5_checksum(@input) end end |
#commit_to(destination_file_path) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/models/sandbox_file.rb', line 49 def commit_to(destination_file_path) if @input.respond_to?(:path) && @input.path commit_tempfile_to(destination_file_path) else commit_stringio_to(destination_file_path) end end |
#invalid_file? ⇒ Boolean
64 65 66 67 68 69 70 |
# File 'app/models/sandbox_file.rb', line 64 def invalid_file? if expected_checksum != actual_checksum @error = "Uploaded file is invalid: expected a md5 sum '#{expected_checksum}', but it was '#{actual_checksum}'" else false end end |
#invalid_params? ⇒ Boolean
72 73 74 75 76 77 78 79 80 |
# File 'app/models/sandbox_file.rb', line 72 def invalid_params? if @sandbox_id.nil? @error = "Cannot upload file with checksum '#{expected_checksum}': you must provide a sandbox_id" elsif @expected_checksum.nil? @error = "Cannot upload file to sandbox '#{sandbox_id}': you must provide the file's checksum" else false end end |
#invalid_sandbox? ⇒ Boolean
82 83 84 85 86 87 88 89 90 |
# File 'app/models/sandbox_file.rb', line 82 def invalid_sandbox? if sandbox.nil? @error = "Cannot find sandbox with id '#{sandbox_id}' in the database" elsif !sandbox.member?(@expected_checksum) @error = "Cannot upload file: checksum '#{expected_checksum}' isn't a part of sandbox '#{sandbox_id}'" else false end end |
#resource_params ⇒ Object
37 38 39 |
# File 'app/models/sandbox_file.rb', line 37 def resource_params {:sandbox_id => sandbox_id, :checksum => expected_checksum} end |
#sandbox ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/models/sandbox_file.rb', line 41 def sandbox unless @sandbox_loaded load_sandbox @sandbox_loaded = true end @sandbox end |