Class: EyServicesFake::ReacharoundAwsm

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_services_fake/reacharound_awsm.rb

Defined Under Namespace

Classes: Account, App, AppDeployment, Application, Environment, User

Instance Method Summary collapse

Instance Method Details

#appObject



21
22
23
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 21

def app
  Application
end

#base_urlObject



29
30
31
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 29

def base_url
  "http://cloud.engineyard.com"
end

#create_app_deployment(sso_account_id, app_name, env_name, framework_env) ⇒ Object



84
85
86
87
88
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 84

def create_app_deployment(, app_name, env_name, framework_env)
  app = App.create(:name => app_name)
  env = Environment.create(:name => env_name, :framework_env => framework_env, :aws_region => 'us-east-1')
  AppDeployment.create(:account_id => , :app_id => app.id, :environment_id => env.id)
end

#create_sso_account(sso_user) ⇒ Object



63
64
65
66
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 63

def (sso_user)
  Account.create(:owner_id => sso_user.id, :name => 'some-account')
  (sso_user)
end

#deprovision_service(provisioned_service_id) ⇒ Object



162
163
164
165
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 162

def deprovision_service(provisioned_service_id)
  provisioned_service = ProvisionedService.get(provisioned_service_id)
  @connection.delete(provisioned_service.url)
end

#disable_service(service_id, sso_account_id, service_account_id) ⇒ Object



125
126
127
128
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 125

def disable_service(service_id, , )
   = ServiceAccount.get()
  @connection.delete(.url)
end

#enable_service(service_id, sso_account_id) ⇒ Object

Normal implmentations of AWSM would not be posting to service_accounts_url; they would be posting to private API to say that they wish to create a service account but this is reacharound AWSM, and so it plays the role of tresfiestas internals here def enable_service(connection, sso_account, service_hash)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 94

def enable_service(service_id, )
  url_gen = EyServicesFake::URL_GEN
   = ServiceAccount.create(:sso_account_id => , :active => false, :service_id => service_id, :dashboard_notifications_url => "#{base_url}/dashboard_notifications_url")
  service = Service.get(service_id)
  creation_attributes = {
    :id             => .id,
    :name           => Account.get().name,
    :url            => url_gen.(service, ),
    :messages_url   => url_gen.messages(service, ),
    :invoices_url   => url_gen.invoices(service, ),
  }
  @connection.post(service.service_accounts_url, creation_attributes) do |result, location|
    .active = true
    if result["service_account"]
      .provisioned_services_url = result["service_account"]['provisioned_services_url']
      .configuration_url = result["service_account"]['configuration_url']
      .url = result["service_account"]['url']
      .configuration_required = result["service_account"]['configuration_required']
      .users_url = result["service_account"]['users_url']
    end
    if result["message"] && result["message"]["message_type"]
      Message.create(
        :service_account_id => .id,
        :message_type => result["message"]["message_type"],
        :subject => result["message"]["subject"],
        :body => result["message"]["body"])
    end
    .save
  end
end

#find_app_deployment(sso_account_id) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 68

def find_app_deployment()
  app_deployment = AppDeployment.first(:account_id => )
  app_deployment && {
    :id => app_deployment.id,
    :app => {
      :id => app_deployment.app.id,
      :name => app_deployment.app.name,
    },
    :environment => {
      :id => app_deployment.environment.id,
      :name => app_deployment.environment.name,
      :framework_env => app_deployment.environment.framework_env,
      :aws_region => app_deployment.environment.aws_region
    }
  }
end

#find_sso_account(sso_user) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 56

def (sso_user)
   = sso_user.accounts.first
   && {
    :id => .id,
    :name => .name,
  }
end

#provision_service(sso_account_id, service_account_id, app_deployment_id) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 130

def provision_service(, , app_deployment_id)
  url_gen = EyServicesFake::URL_GEN
  provisioned_service = ProvisionedService.create(:app_deployment_id => app_deployment_id.to_i, :active => false, :service_account_id => .to_i, :dashboard_notifications_url => "#{base_url}/dashboard_notifications_url")
   = ServiceAccount.get()
  app_deployment = AppDeployment.get(app_deployment_id)
  app = app_deployment.app
  environment = app_deployment.environment
  provision_attribtues = {
    :url          => url_gen.partner_provisioned_service(, provisioned_service),
    :messages_url => url_gen.messages(.service, , provisioned_service),
    :app          => {:id => app.id, :name => app.name},
    :environment  => {:id => environment.id, :name => environment.name, :framework_env => environment.framework_env, :aws_region => environment.aws_region},
  }
  @connection.post(.provisioned_services_url, provision_attribtues) do |result, location|
    provisioned_service.active = true
    if result['provisioned_service']
      provisioned_service.vars = result['provisioned_service']["vars"]
      provisioned_service.configuration_url = result['provisioned_service']["configuration_url"]
      provisioned_service.configuration_required = result['provisioned_service']["configuration_required"]
      provisioned_service.url = result['provisioned_service']["url"]
      if result["message"] && result["message"]["message_type"]
        Message.create(
          :provisioned_service_id => provisioned_service.id,
          :message_type => result["message"]["message_type"],
          :subject => result["message"]["subject"],
          :body => result["message"]["body"])
      end
    end
    provisioned_service.save
  end
end

#provisioned_service_sso_url(service_account_id, app_deployment_id, sso_user, sso_account_id) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 189

def provisioned_service_sso_url(, app_deployment_id, sso_user, )
   = ServiceAccount.get()
  partner = .service.partner
  provisioned_service = ProvisionedService.first(:app_deployment_id => app_deployment_id)
  configuration_url = provisioned_service.configuration_url
  params = {
    'timestamp' => Time.now.iso8601,
    'ey_user_id' => sso_user.external_service_id,
    'ey_user_name' => "Person Name",
    'ey_return_to_url' => "https://cloud.engineyard.com/dashboard",
    'access_level' => 'owner',
  }
  if .users_url
    params['ey_user_email'] = sso_user.email
  end
  require 'cgi'
  EY::ApiHMAC::SSO.sign(configuration_url,
                        params,
                        partner.auth_id,
                        partner.auth_key)
end

#reset!Object



25
26
27
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 25

def reset!
  #no-op
end

#service_account_sso_url(service_id, sso_user, sso_account_id) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 167

def (service_id, sso_user, )
   = ServiceAccount.first(
    :sso_account_id => , :service_id => service_id)
  partner = .service.partner
  configuration_url = .configuration_url
  params = {
    'timestamp' => Time.now.iso8601,
    'ey_user_id' => sso_user.external_service_id,
    'ey_user_name' => "Person Name",
    'ey_return_to_url' => "https://cloud.engineyard.com/dashboard",
    'access_level' => 'owner',
  }
  if .users_url
    params['ey_user_email'] = sso_user.email
  end
  require 'cgi'
  EY::ApiHMAC::SSO.sign(configuration_url,
                        params,
                        partner.auth_id,
                        partner.auth_key)
end

#service_provider_setup(auth_id, auth_key, service_provider_url, service_provider_rackapp) ⇒ Object



44
45
46
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 44

def service_provider_setup(auth_id, auth_key, service_provider_url, service_provider_rackapp)
  @connection = EY::ApiHMAC::AuthedConnection.new(auth_id, auth_key).tap{|c| c.backend = service_provider_rackapp}
end

#setup(auth_id, auth_key, tresfiestas_url, tresfiestas_rackapp) ⇒ Object



47
48
49
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 47

def setup(auth_id, auth_key, tresfiestas_url, tresfiestas_rackapp)
  #ignored... we don't talk to tresfiestas, we talk to service_provider
end

#sso_userObject



51
52
53
54
# File 'lib/ey_services_fake/reacharound_awsm.rb', line 51

def sso_user
  the_one_email = "[email protected]"
  User.first(:email => the_one_email) || User.create(:email => the_one_email, :external_service_id => Object.new.object_id)
end