Class: Ridley::SandboxUploader Private
- Inherits:
-
Object
- Object
- Ridley::SandboxUploader
- Includes:
- Celluloid
- Defined in:
- lib/ridley/sandbox_uploader.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #client_key ⇒ Object readonly private
- #client_name ⇒ Object readonly private
- #options ⇒ Object readonly private
Class Method Summary collapse
-
.checksum(path) ⇒ String
private
Return the checksum of the contents of the file at the given filepath.
-
.checksum64(path) ⇒ String
private
Return a base64 encoded checksum of the contents of the given file.
- .checksum_io(io, digest) ⇒ String private
Instance Method Summary collapse
-
#initialize(client_name, client_key, options = {}) ⇒ SandboxUploader
constructor
private
A new instance of SandboxUploader.
-
#upload(sandbox, chk_id, path) ⇒ Hash?
private
Upload one file into the sandbox for the given checksum id.
Constructor Details
#initialize(client_name, client_key, options = {}) ⇒ SandboxUploader
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of SandboxUploader.
45 46 47 48 49 |
# File 'lib/ridley/sandbox_uploader.rb', line 45 def initialize(client_name, client_key, = {}) @client_name = client_name @client_key = client_key @options = end |
Instance Attribute Details
#client_key ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/ridley/sandbox_uploader.rb', line 42 def client_key @client_key end |
#client_name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/ridley/sandbox_uploader.rb', line 41 def client_name @client_name end |
#options ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
43 44 45 |
# File 'lib/ridley/sandbox_uploader.rb', line 43 def @options end |
Class Method Details
.checksum(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the checksum of the contents of the file at the given filepath
12 13 14 |
# File 'lib/ridley/sandbox_uploader.rb', line 12 def checksum(path) File.open(path, 'rb') { |f| checksum_io(f, Digest::MD5.new) } end |
.checksum64(path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a base64 encoded checksum of the contents of the given file. This is the expected format of sandbox checksums given to the Chef Server.
23 24 25 |
# File 'lib/ridley/sandbox_uploader.rb', line 23 def checksum64(path) Base64.encode64([checksum(path)].pack("H*")).strip end |
.checksum_io(io, digest) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 |
# File 'lib/ridley/sandbox_uploader.rb', line 31 def checksum_io(io, digest) while chunk = io.read(1024 * 8) digest.update(chunk) end digest.hexdigest end |
Instance Method Details
#upload(sandbox, chk_id, path) ⇒ Hash?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Upload one file into the sandbox for the given checksum id
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 88 89 90 91 92 93 |
# File 'lib/ridley/sandbox_uploader.rb', line 60 def upload(sandbox, chk_id, path) checksum = sandbox.checksum(chk_id) unless checksum[:needs_upload] return nil end headers = { 'Content-Type' => 'application/x-binary', 'content-md5' => self.class.checksum64(path) } contents = File.open(path, 'rb') { |f| f.read } url = URI(checksum[:url]) upload_path = url.path url.path = "" # versions prior to OSS Chef 11 will strip the port to upload the file to in the checksum # url returned. This will ensure we are uploading to the proper location. if sandbox.send(:resource).connection.foss? url.port = URI(sandbox.send(:resource).connection.server_url).port end begin Faraday.new(url, self.) do |c| c.response :chef_response c.response :follow_redirects c.request :chef_auth, self.client_name, self.client_key c.adapter :net_http end.put(upload_path, contents, headers) rescue Ridley::Errors::HTTPError => ex abort(ex) end end |