Class: CloudFormation::Bridge::Request

Inherits:
Object
  • Object
show all
Includes:
Names
Defined in:
lib/cloud_formation/bridge/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, logger = Util::LOGGER) ⇒ Request

Returns a new instance of Request.



14
15
16
17
# File 'lib/cloud_formation/bridge/request.rb', line 14

def initialize(request, logger = Util::LOGGER)
  @request = request
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



12
13
14
# File 'lib/cloud_formation/bridge/request.rb', line 12

def logger
  @logger
end

#requestObject (readonly)

Returns the value of attribute request.



12
13
14
# File 'lib/cloud_formation/bridge/request.rb', line 12

def request
  @request
end

Instance Method Details

#build_response(response = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/cloud_formation/bridge/request.rb', line 87

def build_response(response = {})
  {
    FIELDS::STATUS => RESULTS::SUCCESS,
    FIELDS::PHYSICAL_RESOURCE_ID => response[FIELDS::PHYSICAL_RESOURCE_ID] || physical_resource_id || generate_physical_id,
    FIELDS::STACK_ID => stack_id,
    FIELDS::REQUEST_ID => request_id,
    FIELDS::LOGICAL_RESOURCE_ID => logical_resource_id,
  }.merge(response)
end

#create?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/cloud_formation/bridge/request.rb', line 23

def create?
  request_type == TYPES::CREATE
end

#delete?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cloud_formation/bridge/request.rb', line 27

def delete?
  request_type == TYPES::DELETE
end

#fail!(message) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/cloud_formation/bridge/request.rb', line 67

def fail!(message)
  response = build_response(
    FIELDS::REASON => message,
    FIELDS::STATUS => RESULTS::FAILED,
  )

  HttpBridge.put(request_url, response)
end

#generate_physical_idObject



97
98
99
# File 'lib/cloud_formation/bridge/request.rb', line 97

def generate_physical_id
  "#{logical_resource_id}-#{SecureRandom.uuid}"
end

#logical_resource_idObject



51
52
53
# File 'lib/cloud_formation/bridge/request.rb', line 51

def logical_resource_id
  request[FIELDS::LOGICAL_RESOURCE_ID]
end

#old_resource_propertiesObject



63
64
65
# File 'lib/cloud_formation/bridge/request.rb', line 63

def old_resource_properties
  request[FIELDS::OLD_RESOURCE_PROPERTIES]
end

#physical_resource_idObject



55
56
57
# File 'lib/cloud_formation/bridge/request.rb', line 55

def physical_resource_id
  request[FIELDS::PHYSICAL_RESOURCE_ID]
end

#request_idObject



43
44
45
# File 'lib/cloud_formation/bridge/request.rb', line 43

def request_id
  request[FIELDS::REQUEST_ID]
end

#request_typeObject



31
32
33
# File 'lib/cloud_formation/bridge/request.rb', line 31

def request_type
  request[FIELDS::REQUEST_TYPE]
end

#request_urlObject



35
36
37
# File 'lib/cloud_formation/bridge/request.rb', line 35

def request_url
  request[FIELDS::RESPONSE_URL]
end

#resource_propertiesObject



59
60
61
# File 'lib/cloud_formation/bridge/request.rb', line 59

def resource_properties
  request[FIELDS::RESOURCE_PROPERTIES]
end

#resource_typeObject



47
48
49
# File 'lib/cloud_formation/bridge/request.rb', line 47

def resource_type
  request[FIELDS::RESOURCE_TYPE]
end

#stack_idObject



39
40
41
# File 'lib/cloud_formation/bridge/request.rb', line 39

def stack_id
  request[FIELDS::STACK_ID]
end

#succeed!(response = {}) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/cloud_formation/bridge/request.rb', line 76

def succeed!(response = {})
  actual_response = case response
    when Hash
      build_response(response)
    else
      build_response
  end

  HttpBridge.put(request_url, actual_response)
end

#update?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/cloud_formation/bridge/request.rb', line 19

def update?
  request_type == TYPES::UPDATE
end