Class: EyServicesFake::MockBackend
- Inherits:
-
Object
- Object
- EyServicesFake::MockBackend
- Defined in:
- lib/ey_services_fake/mock_backend.rb
Instance Attribute Summary collapse
-
#actors ⇒ Object
readonly
Returns the value of attribute actors.
Class Method Summary collapse
Instance Method Summary collapse
- #actor(role) ⇒ Object
- #app ⇒ Object
- #app_deployment ⇒ Object
- #app_for(actor_name) ⇒ Object
- #awsm ⇒ Object
- #destroy_provisioned_service ⇒ Object
- #destroy_service_account ⇒ Object
-
#initialize(actors) ⇒ MockBackend
constructor
A new instance of MockBackend.
- #latest_invoice ⇒ Object
- #latest_status_message ⇒ Object
- #partner ⇒ Object
- #provisioned_service ⇒ Object
- #provisioned_service_sso_url ⇒ Object
- #reset! ⇒ Object
- #send_invoice(invoices_url, total_amount_cent, line_item_description) ⇒ Object
- #send_message(message_url, message_type, message_subject, message_body = nil) ⇒ Object
- #service ⇒ Object
- #service_account ⇒ Object
- #service_account_sso_url ⇒ Object
- #service_enablement ⇒ Object
- #sso_account ⇒ Object
- #sso_user ⇒ Object
- #trigger_mock_user_delete ⇒ Object
- #trigger_mock_user_update(new_email) ⇒ Object
Constructor Details
#initialize(actors) ⇒ MockBackend
Returns a new instance of MockBackend.
61 62 63 |
# File 'lib/ey_services_fake/mock_backend.rb', line 61 def initialize(actors) @actors = actors end |
Instance Attribute Details
#actors ⇒ Object (readonly)
Returns the value of attribute actors.
60 61 62 |
# File 'lib/ey_services_fake/mock_backend.rb', line 60 def actors @actors end |
Class Method Details
.setup!(actors = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ey_services_fake/mock_backend.rb', line 9 def self.setup!(actors = {}) unless actors[:awsm] require 'ey_services_fake/reacharound_awsm' actors[:awsm] = ReacharoundAwsm.new end unless actors[:service_provider] require 'ey_services_fake/mocking_bird_service' actors[:service_provider] = MockingBirdService.new end unless actors[:tresfiestas] actors[:tresfiestas] = tresfiestas_fake.new end new(actors) end |
.tresfiestas_fake ⇒ Object
4 5 6 7 |
# File 'lib/ey_services_fake/mock_backend.rb', line 4 def self.tresfiestas_fake require 'ey_services_fake/tresfiestas_fake' TresfiestasFake end |
Instance Method Details
#actor(role) ⇒ Object
65 66 67 |
# File 'lib/ey_services_fake/mock_backend.rb', line 65 def actor(role) @actors[role] or raise "No actor registered as #{role}, I have #{@actors.keys.inspect}" end |
#app ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ey_services_fake/mock_backend.rb', line 49 def app this = self @app ||= Rack::Builder.new do this.actors.each do |k, actor| map "#{actor.base_url}/" do run this.app_for(k) end end end end |
#app_deployment ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/ey_services_fake/mock_backend.rb', line 157 def app_deployment app_deployment_hash = actor(:awsm).find_app_deployment(sso_account[:id]) unless app_deployment_hash actor(:awsm).create_app_deployment(sso_account[:id], "myapp", "myenv", "production") app_deployment_hash = actor(:awsm).find_app_deployment(sso_account[:id]) end app_deployment_hash end |
#app_for(actor_name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ey_services_fake/mock_backend.rb', line 24 def app_for(actor_name) this = self @apps ||= {} @apps[actor_name] ||= Rack::Builder.new do this.actors.each do |k, actor| if actor.respond_to?(:extra_middlewares) self.instance_eval(&actor.extra_middlewares) end end if ENV["REQUEST_DEBUG"] require 'request_visualizer' use RequestVisualizer do |str| found = str this.actors.each do |k, actor| if str.match(actor.base_url) found = k.to_s end end found end end run this.actors[actor_name].app end end |
#awsm ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/ey_services_fake/mock_backend.rb', line 77 def awsm awsm_hash = actor(:tresfiestas).find_awsm unless awsm_hash awsm_hash = actor(:tresfiestas).create_awsm(actor(:awsm).base_url, app_for(:awsm)) actor(:awsm).setup(awsm_hash[:auth_id], awsm_hash[:auth_key], actor(:tresfiestas).base_url, app_for(:tresfiestas)) end awsm_hash end |
#destroy_provisioned_service ⇒ Object
178 179 180 |
# File 'lib/ey_services_fake/mock_backend.rb', line 178 def destroy_provisioned_service actor(:awsm).deprovision_service(provisioned_service[:id]) end |
#destroy_service_account ⇒ Object
153 154 155 |
# File 'lib/ey_services_fake/mock_backend.rb', line 153 def destroy_service_account actor(:awsm).disable_service(service[:id], service_account[:sso_account][:id], service_account[:id]) end |
#latest_invoice ⇒ Object
182 183 184 |
# File 'lib/ey_services_fake/mock_backend.rb', line 182 def latest_invoice actor(:tresfiestas).latest_invoice end |
#latest_status_message ⇒ Object
186 187 188 |
# File 'lib/ey_services_fake/mock_backend.rb', line 186 def actor(:tresfiestas). end |
#partner ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ey_services_fake/mock_backend.rb', line 86 def partner partner_hash = actor(:tresfiestas).find_partner(sso_user) unless partner_hash partner_hash = actor(:tresfiestas).create_partner(sso_user, actor(:service_provider).base_url, app_for(:service_provider)) @actors.values.each do |actor| if actor.respond_to?(:service_provider_setup) actor.service_provider_setup(partner_hash[:auth_id], partner_hash[:auth_key], actor(:service_provider).base_url, app_for(:service_provider)) end end actor(:service_provider).setup(partner_hash[:auth_id], partner_hash[:auth_key], actor(:tresfiestas).base_url, app_for(:tresfiestas)) end partner_hash end |
#provisioned_service ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ey_services_fake/mock_backend.rb', line 166 def provisioned_service service_account_hash = self.service_account sso_account_hash = service_account_hash[:sso_account] app_deployment_hash = self.app_deployment provisioned_service_hash = actor(:tresfiestas).find_provisioned_service(service_account_hash[:id], app_deployment_hash[:id]) unless provisioned_service_hash actor(:awsm).provision_service(sso_account_hash[:id], service_account_hash[:id], app_deployment_hash[:id]) provisioned_service_hash = actor(:tresfiestas).find_provisioned_service(service_account_hash[:id], app_deployment_hash[:id]) end provisioned_service_hash.merge(:service_account => service_account_hash, :app_deployment => app_deployment_hash) end |
#provisioned_service_sso_url ⇒ Object
202 203 204 |
# File 'lib/ey_services_fake/mock_backend.rb', line 202 def provisioned_service_sso_url actor(:awsm).provisioned_service_sso_url(service_account[:id], app_deployment[:id], sso_user, sso_account[:id]) end |
#reset! ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/ey_services_fake/mock_backend.rb', line 69 def reset! @app = nil @apps = nil @actors.values.each do |v| v.reset! end end |
#send_invoice(invoices_url, total_amount_cent, line_item_description) ⇒ Object
194 195 196 |
# File 'lib/ey_services_fake/mock_backend.rb', line 194 def send_invoice(invoices_url, total_amount_cent, line_item_description) actor(:service_provider).send_invoice(invoices_url, total_amount_cent, line_item_description) end |
#send_message(message_url, message_type, message_subject, message_body = nil) ⇒ Object
190 191 192 |
# File 'lib/ey_services_fake/mock_backend.rb', line 190 def (, , , = nil) actor(:service_provider).(, , , ) end |
#service ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ey_services_fake/mock_backend.rb', line 100 def service partner_hash = self.partner service_hash = actor(:tresfiestas).find_service(partner_hash[:id]) unless service_hash actor(:service_provider).register_service(partner_hash[:registration_url]) service_hash = actor(:tresfiestas).find_service(partner_hash[:id]) end if actor(:tresfiestas).respond_to?(:document_service) service_hash.merge!(:service_doc => actor(:tresfiestas).document_service(service_hash[:id])) end service_hash.merge(:partner => partner_hash) end |
#service_account ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ey_services_fake/mock_backend.rb', line 141 def service_account service_enablement_hash = self.service_enablement sso_account_hash = service_enablement_hash[:sso_account] service_hash = service_enablement_hash[:service] service_account_hash = actor(:tresfiestas).find_service_account(service_hash[:id], sso_account_hash[:id]) unless service_account_hash actor(:awsm).enable_service(service_hash[:id], sso_account_hash[:id]) service_account_hash = actor(:tresfiestas).find_service_account(service_hash[:id], sso_account_hash[:id]) end service_account_hash.merge(:name => sso_account_hash[:name], :service => service_hash, :sso_account => sso_account_hash) end |
#service_account_sso_url ⇒ Object
198 199 200 |
# File 'lib/ey_services_fake/mock_backend.rb', line 198 def service_account_sso_url actor(:awsm).service_account_sso_url(service[:id], sso_user, sso_account[:id]) end |
#service_enablement ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ey_services_fake/mock_backend.rb', line 128 def service_enablement sso_account_hash = self.sso_account service_hash = self.service unless actor(:tresfiestas).service_available_for_account?(service_hash[:id], sso_account_hash[:id]) actor(:tresfiestas).make_service_available_for_account(service_hash[:id], sso_account_hash[:id]) end { :service => service_hash, :sso_account => sso_account_hash, } end |
#sso_account ⇒ Object
118 119 120 121 122 123 124 125 126 |
# File 'lib/ey_services_fake/mock_backend.rb', line 118 def sso_account awsm #need to have setup awsm before you can create accounts! sso_user_something = sso_user #the sso_user is a somehting, not necessarily a hash sso_account_hash = actor(:awsm).find_sso_account(sso_user_something) unless sso_account_hash sso_account_hash = actor(:awsm).create_sso_account(sso_user_something) end sso_account_hash end |
#sso_user ⇒ Object
113 114 115 116 |
# File 'lib/ey_services_fake/mock_backend.rb', line 113 def sso_user awsm actor(:awsm).sso_user #allows for nils (some implementations of AWSM may decide this is ok) end |
#trigger_mock_user_delete ⇒ Object
210 211 212 |
# File 'lib/ey_services_fake/mock_backend.rb', line 210 def trigger_mock_user_delete actor(:tresfiestas).trigger_mock_user_delete(sso_user) end |
#trigger_mock_user_update(new_email) ⇒ Object
206 207 208 |
# File 'lib/ey_services_fake/mock_backend.rb', line 206 def trigger_mock_user_update(new_email) actor(:tresfiestas).trigger_mock_user_update(sso_user, new_email) end |