Class: RightScale::RightScriptAttachment

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/right_agent/core_payload_types/right_script_attachment.rb

Overview

RightScript attachment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Serializable

included

Constructor Details

#initialize(*args) ⇒ RightScriptAttachment

Returns a new instance of RightScriptAttachment.



49
50
51
52
53
54
55
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 49

def initialize(*args)
  @url       = args[0] if args.size > 0
  @file_name = args[1] if args.size > 1
  @etag      = args[2] if args.size > 2
  @token     = args[3] if args.size > 3
  @digest    = args[4] if args.size > 4
end

Instance Attribute Details

#digestObject

(String) Content digest



47
48
49
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 47

def digest
  @digest
end

#etagObject

(String) Cache identifier



41
42
43
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 41

def etag
  @etag
end

#file_nameObject

(String) Attachment file name



38
39
40
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 38

def file_name
  @file_name
end

#tokenObject

(Binary string) Repose token for attachment



44
45
46
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 44

def token
  @token
end

#urlObject

(String) S3 attachment URL



35
36
37
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 35

def url
  @url
end

Class Method Details

.hash_for(url, filename, etag) ⇒ Object

Return the Repose hash for the given URL/filename/ETag triple.

Parameters

url(String)

URL to request

filename(String)

local filename

etag(String)

expected ETag

Return

String

hashed token suitable for communicating to Repose



89
90
91
92
93
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 89

def self.hash_for(url, filename, etag)
  uri = URI::parse(url).dup
  uri.query = nil
  Digest::SHA1.hexdigest("#{uri}\000#{etag}")
end

Instance Method Details

#fill_out(session) ⇒ Object

Fill out the session cookie appropriately for this attachment.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 68

def fill_out(session)
  session['scope'] = "attachments"
  if @digest
    session['resource'] = @digest
  else
    session['resource'] = to_hash
    session['url'] = @url
    session['etag'] = @etag
  end
  @token = session.to_s
end

#serialized_membersObject

Array of serialized fields given to constructor



58
59
60
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 58

def serialized_members
  [ @url, @file_name, @etag, @token, @digest ]
end

#to_hashObject

Return the Repose hash for this attachment.



63
64
65
# File 'lib/right_agent/core_payload_types/right_script_attachment.rb', line 63

def to_hash
  RightScriptAttachment.hash_for(@url, @file_name, @etag)
end