cloudfuji 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +4 -0
  3. data/Gemfile +17 -0
  4. data/README.md +3 -0
  5. data/Rakefile +36 -0
  6. data/app/controllers/cloudfuji/data_controller.rb +33 -0
  7. data/app/controllers/cloudfuji/envs_controller.rb +31 -0
  8. data/app/controllers/cloudfuji/mail_controller.rb +37 -0
  9. data/bin/cloudfuji +86 -0
  10. data/cloudfuji.gemspec +26 -0
  11. data/config/routes.rb +1 -0
  12. data/lib/cloudfuji.rb +53 -0
  13. data/lib/cloudfuji/action_mailer.rb +35 -0
  14. data/lib/cloudfuji/app.rb +202 -0
  15. data/lib/cloudfuji/bar.rb +19 -0
  16. data/lib/cloudfuji/base.rb +23 -0
  17. data/lib/cloudfuji/command.rb +110 -0
  18. data/lib/cloudfuji/config.rb +12 -0
  19. data/lib/cloudfuji/data.rb +52 -0
  20. data/lib/cloudfuji/data_helper.rb +1 -0
  21. data/lib/cloudfuji/dns.rb +195 -0
  22. data/lib/cloudfuji/engine.rb +21 -0
  23. data/lib/cloudfuji/envs.rb +6 -0
  24. data/lib/cloudfuji/envs_helper.rb +1 -0
  25. data/lib/cloudfuji/event.rb +63 -0
  26. data/lib/cloudfuji/event_observer.rb +20 -0
  27. data/lib/cloudfuji/mail_helper.rb +1 -0
  28. data/lib/cloudfuji/mail_route.rb +186 -0
  29. data/lib/cloudfuji/middleware.rb +42 -0
  30. data/lib/cloudfuji/models.rb +59 -0
  31. data/lib/cloudfuji/notification.rb +0 -0
  32. data/lib/cloudfuji/orm/active_record.rb +44 -0
  33. data/lib/cloudfuji/orm/mongoid.rb +31 -0
  34. data/lib/cloudfuji/platform.rb +47 -0
  35. data/lib/cloudfuji/schema.rb +42 -0
  36. data/lib/cloudfuji/smtp.rb +24 -0
  37. data/lib/cloudfuji/user.rb +59 -0
  38. data/lib/cloudfuji/user_helper.rb +7 -0
  39. data/lib/cloudfuji/utils.rb +53 -0
  40. data/lib/cloudfuji/version.rb +4 -0
  41. data/lib/generators/active_record/cloudfuji_generator.rb +28 -0
  42. data/lib/generators/active_record/templates/migration.rb +20 -0
  43. data/lib/generators/cloudfuji/auth_migration_generator.rb +46 -0
  44. data/lib/generators/cloudfuji/cloudfuji_generator.rb +14 -0
  45. data/lib/generators/cloudfuji/hooks_generator.rb +43 -0
  46. data/lib/generators/cloudfuji/install_generator.rb +24 -0
  47. data/lib/generators/cloudfuji/mail_routes_generator.rb +45 -0
  48. data/lib/generators/cloudfuji/orm_helpers.rb +21 -0
  49. data/lib/generators/cloudfuji/routes_generator.rb +22 -0
  50. data/lib/generators/mongoid/cloudfuji_generator.rb +17 -0
  51. data/lib/generators/templates/README +5 -0
  52. data/lib/generators/templates/cloudfuji.rb +10 -0
  53. data/lib/hooks.rb +36 -0
  54. data/lib/rails/routes.rb +42 -0
  55. data/lib/tasks/cloudfuji.rake +6 -0
  56. data/spec/app_spec/controllers/envs_controller_spec.rb +25 -0
  57. data/spec/app_spec/controllers/mail_controller_spec.rb +28 -0
  58. data/spec/app_spec/integration/app_claim_spec.rb +16 -0
  59. data/spec/gem_spec/base_spec.rb +24 -0
  60. data/spec/gem_spec/command_spec.rb +181 -0
  61. data/spec/gem_spec/config_spec.rb +9 -0
  62. data/spec/gem_spec/data_spec.rb +13 -0
  63. data/spec/gem_spec/hooks_spec.rb +5 -0
  64. data/spec/gem_spec/mail_route_spec.rb +168 -0
  65. data/spec/gem_spec/platform_spec.rb +9 -0
  66. data/spec/gem_spec/user_spec.rb +45 -0
  67. data/spec/spec_helper.rb +21 -0
  68. data/spec/test_apps/rails-2.3/.gitignore +13 -0
  69. data/spec/test_apps/rails-2.3/Gemfile +13 -0
  70. data/spec/test_apps/rails-2.3/README +243 -0
  71. data/spec/test_apps/rails-2.3/Rakefile +10 -0
  72. data/spec/test_apps/rails-2.3/app/controllers/application_controller.rb +10 -0
  73. data/spec/test_apps/rails-2.3/app/helpers/application_helper.rb +3 -0
  74. data/spec/test_apps/rails-2.3/config/boot.rb +114 -0
  75. data/spec/test_apps/rails-2.3/config/environment.rb +41 -0
  76. data/spec/test_apps/rails-2.3/config/environments/development.rb +17 -0
  77. data/spec/test_apps/rails-2.3/config/environments/production.rb +28 -0
  78. data/spec/test_apps/rails-2.3/config/environments/test.rb +30 -0
  79. data/spec/test_apps/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
  80. data/spec/test_apps/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
  81. data/spec/test_apps/rails-2.3/config/initializers/inflections.rb +10 -0
  82. data/spec/test_apps/rails-2.3/config/initializers/mime_types.rb +5 -0
  83. data/spec/test_apps/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
  84. data/spec/test_apps/rails-2.3/config/initializers/session_store.rb +15 -0
  85. data/spec/test_apps/rails-2.3/config/locales/en.yml +5 -0
  86. data/spec/test_apps/rails-2.3/config/routes.rb +43 -0
  87. data/spec/test_apps/rails-2.3/db/seeds.rb +7 -0
  88. data/spec/test_apps/rails-2.3/doc/README_FOR_APP +2 -0
  89. data/spec/test_apps/rails-2.3/lib/tasks/rspec.rake +144 -0
  90. data/spec/test_apps/rails-2.3/public/404.html +30 -0
  91. data/spec/test_apps/rails-2.3/public/422.html +30 -0
  92. data/spec/test_apps/rails-2.3/public/500.html +30 -0
  93. data/spec/test_apps/rails-2.3/public/favicon.ico +0 -0
  94. data/spec/test_apps/rails-2.3/public/images/rails.png +0 -0
  95. data/spec/test_apps/rails-2.3/public/javascripts/application.js +2 -0
  96. data/spec/test_apps/rails-2.3/public/javascripts/controls.js +963 -0
  97. data/spec/test_apps/rails-2.3/public/javascripts/dragdrop.js +973 -0
  98. data/spec/test_apps/rails-2.3/public/javascripts/effects.js +1128 -0
  99. data/spec/test_apps/rails-2.3/public/javascripts/prototype.js +4320 -0
  100. data/spec/test_apps/rails-2.3/public/robots.txt +5 -0
  101. data/spec/test_apps/rails-2.3/script/about +4 -0
  102. data/spec/test_apps/rails-2.3/script/autospec +6 -0
  103. data/spec/test_apps/rails-2.3/script/console +3 -0
  104. data/spec/test_apps/rails-2.3/script/dbconsole +3 -0
  105. data/spec/test_apps/rails-2.3/script/destroy +3 -0
  106. data/spec/test_apps/rails-2.3/script/generate +3 -0
  107. data/spec/test_apps/rails-2.3/script/performance/benchmarker +3 -0
  108. data/spec/test_apps/rails-2.3/script/performance/profiler +3 -0
  109. data/spec/test_apps/rails-2.3/script/plugin +3 -0
  110. data/spec/test_apps/rails-2.3/script/runner +3 -0
  111. data/spec/test_apps/rails-2.3/script/server +3 -0
  112. data/spec/test_apps/rails-2.3/script/spec +10 -0
  113. data/spec/test_apps/rails-2.3/spec/all_spec.rb +5 -0
  114. data/spec/test_apps/rails-2.3/spec/rcov.opts +2 -0
  115. data/spec/test_apps/rails-2.3/spec/spec.opts +4 -0
  116. data/spec/test_apps/rails-2.3/spec/spec_helper.rb +83 -0
  117. data/spec/test_apps/rails-2.3/test/performance/browsing_test.rb +9 -0
  118. data/spec/test_apps/rails-2.3/test/test_helper.rb +38 -0
  119. data/spec/test_apps/rails-3.0/.gitignore +4 -0
  120. data/spec/test_apps/rails-3.0/.rspec +2 -0
  121. data/spec/test_apps/rails-3.0/Gemfile +10 -0
  122. data/spec/test_apps/rails-3.0/README +256 -0
  123. data/spec/test_apps/rails-3.0/Rakefile +7 -0
  124. data/spec/test_apps/rails-3.0/app/controllers/application_controller.rb +3 -0
  125. data/spec/test_apps/rails-3.0/app/controllers/static_controller.rb +4 -0
  126. data/spec/test_apps/rails-3.0/app/helpers/application_helper.rb +2 -0
  127. data/spec/test_apps/rails-3.0/app/helpers/static_helper.rb +2 -0
  128. data/spec/test_apps/rails-3.0/app/views/layouts/application.html.erb +14 -0
  129. data/spec/test_apps/rails-3.0/app/views/static/home.html.erb +1 -0
  130. data/spec/test_apps/rails-3.0/config.ru +4 -0
  131. data/spec/test_apps/rails-3.0/config/application.rb +46 -0
  132. data/spec/test_apps/rails-3.0/config/boot.rb +6 -0
  133. data/spec/test_apps/rails-3.0/config/environment.rb +5 -0
  134. data/spec/test_apps/rails-3.0/config/environments/development.rb +26 -0
  135. data/spec/test_apps/rails-3.0/config/environments/production.rb +49 -0
  136. data/spec/test_apps/rails-3.0/config/environments/test.rb +35 -0
  137. data/spec/test_apps/rails-3.0/config/initializers/backtrace_silencers.rb +7 -0
  138. data/spec/test_apps/rails-3.0/config/initializers/inflections.rb +10 -0
  139. data/spec/test_apps/rails-3.0/config/initializers/mime_types.rb +5 -0
  140. data/spec/test_apps/rails-3.0/config/initializers/secret_token.rb +7 -0
  141. data/spec/test_apps/rails-3.0/config/initializers/session_store.rb +8 -0
  142. data/spec/test_apps/rails-3.0/config/locales/en.yml +5 -0
  143. data/spec/test_apps/rails-3.0/config/routes.rb +62 -0
  144. data/spec/test_apps/rails-3.0/db/schema.rb +15 -0
  145. data/spec/test_apps/rails-3.0/db/seeds.rb +7 -0
  146. data/spec/test_apps/rails-3.0/doc/README_FOR_APP +2 -0
  147. data/spec/test_apps/rails-3.0/lib/tasks/.gitkeep +0 -0
  148. data/spec/test_apps/rails-3.0/public/404.html +26 -0
  149. data/spec/test_apps/rails-3.0/public/422.html +26 -0
  150. data/spec/test_apps/rails-3.0/public/500.html +26 -0
  151. data/spec/test_apps/rails-3.0/public/favicon.ico +0 -0
  152. data/spec/test_apps/rails-3.0/public/images/rails.png +0 -0
  153. data/spec/test_apps/rails-3.0/public/index.html +239 -0
  154. data/spec/test_apps/rails-3.0/public/javascripts/application.js +2 -0
  155. data/spec/test_apps/rails-3.0/public/javascripts/controls.js +965 -0
  156. data/spec/test_apps/rails-3.0/public/javascripts/dragdrop.js +974 -0
  157. data/spec/test_apps/rails-3.0/public/javascripts/effects.js +1123 -0
  158. data/spec/test_apps/rails-3.0/public/javascripts/prototype.js +6001 -0
  159. data/spec/test_apps/rails-3.0/public/javascripts/rails.js +191 -0
  160. data/spec/test_apps/rails-3.0/public/robots.txt +5 -0
  161. data/spec/test_apps/rails-3.0/public/stylesheets/.gitkeep +0 -0
  162. data/spec/test_apps/rails-3.0/script/rails +6 -0
  163. data/spec/test_apps/rails-3.0/spec/all_spec.rb +5 -0
  164. data/spec/test_apps/rails-3.0/spec/spec_helper.rb +78 -0
  165. data/spec/test_apps/rails-3.0/test/performance/browsing_test.rb +9 -0
  166. data/spec/test_apps/rails-3.0/test/test_helper.rb +13 -0
  167. data/spec/test_apps/rails-3.0/vendor/plugins/.gitkeep +0 -0
  168. data/tasks/cover_me.rake +11 -0
  169. data/test_app/spec/views/home.html.erb_spec.rb +15 -0
  170. metadata +261 -0
@@ -0,0 +1,19 @@
1
+ module Cloudfuji
2
+ # Cloudfuji::Bar
3
+ class Bar
4
+ # Default to showing the bar on all paths
5
+ @@bar_paths = [/.*/]
6
+
7
+ def self.set_bar_display_paths(*paths)
8
+ @@bar_paths = paths
9
+ end
10
+
11
+ def self.in_bar_display_path?(env)
12
+ @@bar_paths.each do |path_regex|
13
+ return true if env['PATH_INFO'] =~ path_regex
14
+ end
15
+
16
+ return false
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ module Cloudfuji
2
+ class Base
3
+ class << self
4
+ url_pairs = {
5
+ :unity=>[:valid, :exists, :invite, :pending_invites, :remove, :notify],
6
+ :email=>[:send, :allowed]
7
+ }
8
+
9
+ def notify_user_url
10
+ "#{Cloudfuji::Platform.host}/notifications.json"
11
+ end
12
+
13
+ # NOTE Cannot use define_singleton_method since ruby 1.8 compatibility is a must
14
+ url_pairs.each_pair do |prefix, method_names|
15
+ method_names.each do |method_name|
16
+ define_method "#{method_name}_#{prefix}_url".to_sym do
17
+ "#{Cloudfuji::Platform.host}/#{prefix}/#{Cloudfuji::Config.api_version}/#{method_name}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,110 @@
1
+ module Cloudfuji
2
+ class Command #:nodoc:
3
+ @@last_request = nil
4
+ @@request_count = 0
5
+ @@last_request_successful = true
6
+
7
+ class << self
8
+ def request_count
9
+ @@request_count
10
+ end
11
+
12
+ def get_command(url, params={})
13
+ @@request_count += 1
14
+ params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil?
15
+
16
+ begin
17
+ raw = RestClient.get(url, {:params => params, :accept => :json})
18
+ rescue # => e
19
+ # puts e.inspect
20
+ @@last_request_successful = false
21
+ return nil
22
+ end
23
+
24
+ @@last_request_successful = true
25
+ @@last_request = JSON(raw)
26
+ end
27
+
28
+ def post_command(url, params)
29
+ @@request_count += 1
30
+
31
+ unless Cloudfuji::Platform.key.nil?
32
+ params["auth_token"] ||= Cloudfuji::Platform.key
33
+ end
34
+
35
+ begin
36
+ puts "RestClient.post(#{url}, #{params.to_json}, :content_type => :json, :accept => :json)"
37
+ raw = RestClient.post(url, params.to_json, :content_type => :json, :accept => :json)
38
+ rescue => e
39
+ puts e.inspect
40
+ @@last_request_successful = false
41
+ return nil
42
+ end
43
+
44
+ @@last_request_successful = true
45
+ @@last_request = JSON(raw)
46
+ end
47
+
48
+ def put_command(url, params, meta={})
49
+ @@request_count += 1
50
+
51
+ if meta[:force]
52
+ params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil?
53
+
54
+ begin
55
+ raw = RestClient.put(url, params.to_json, :content_type => :json)
56
+ rescue # => e
57
+ # puts e.inspect
58
+ @@last_request_successful = false
59
+ return nil
60
+ end
61
+
62
+ else
63
+ params.merge!({:auth_token => Cloudfuji::Platform.key}) if params[:auth_token].nil? unless Cloudfuji::Platform.key.nil?
64
+
65
+ begin
66
+ raw = RestClient.put(url, params.to_json, :content_type => :json)
67
+ rescue # => e
68
+ #puts e.inspect
69
+ @@last_request_successful = false
70
+ return nil
71
+ end
72
+ end
73
+
74
+ @@last_request_successful = true
75
+ @@last_request = JSON.parse raw
76
+ end
77
+
78
+ def show_response(response)
79
+ show_messages response
80
+ show_errors response
81
+ end
82
+
83
+ def show_messages(response)
84
+ if response["messages"]
85
+ puts "Messages:"
86
+ response["messages"].each_with_index do |error, counter|
87
+ puts "\t#{counter + 1}. #{error}"
88
+ end
89
+ end
90
+ end
91
+
92
+ def show_errors(response)
93
+ if response["errors"]
94
+ puts "Errors:"
95
+ response["errors"].each_with_index do |error, counter|
96
+ puts "\t#{counter + 1}. #{error}"
97
+ end
98
+ end
99
+ end
100
+
101
+ def last_command_successful?
102
+ @@last_request_successful
103
+ end
104
+
105
+ def last_command_errored?
106
+ not last_command_successful?
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,12 @@
1
+ module Cloudfuji
2
+ class Config
3
+
4
+ # API version defaults to v1
5
+ # Passing prefix "v" to ensure that developers assume it's a string. For future advantage when using API versions like 1.6.23
6
+ @api_version = "v1"
7
+
8
+ class << self
9
+ attr_accessor :api_version
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,52 @@
1
+ module Cloudfuji
2
+ class Data #:nodoc:
3
+ @@observers = []
4
+
5
+ def self.add_observer(observer)
6
+ puts "Subscribing #{observer} to Cloudfuji data calls"
7
+ @@observers << observer
8
+ end
9
+
10
+ def self.fire(data, event)
11
+ puts "Cloudfuji Hooks Firing #{event} with => #{data.inspect}"
12
+
13
+ processed = false
14
+
15
+ @@observers.each do |observer|
16
+ puts "#{observer}.respond_to?(#{event}) => #{observer.respond_to?(event)}"
17
+
18
+ if observer.respond_to?(event)
19
+ processed = true
20
+
21
+ # Make a copy of the data so it's not mutated as the events
22
+ # pass through the observers
23
+ observer.instance_variable_set("@params", data.dup)
24
+
25
+ result = observer.send(event)
26
+
27
+ # Allow an observer to halt event propagation
28
+ if result == :halt
29
+ puts "Observer #{observer} halted event propagation"
30
+ break
31
+ end
32
+ end
33
+ end
34
+
35
+ # We've checked all the observers to see if they respond to the
36
+ # named events, so if the event is still unprocessed then let's
37
+ # fall back on the first catch_all event we find
38
+ if !processed
39
+ @@observers.each do |observer|
40
+ if observer.respond_to?(:catch_all)
41
+ observer.instance_variable_set("@params", data.dup)
42
+
43
+ observer.send(:catch_all)
44
+ break
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+
@@ -0,0 +1 @@
1
+ # Automatically required by the data_controller
@@ -0,0 +1,195 @@
1
+ module Cloudfuji
2
+ # Cloudfuji::App provides all of the methods to interact with the app it's included in,
3
+ # and only contains class methods. Each method will check for the most recent data,
4
+ # so it's possible the data may change between two separate calls.
5
+ class App
6
+ class << self
7
+ def app_url #:nodoc:
8
+ "#{Cloudfuji::Platform.host}/apps/#{Cloudfuji::Platform.name}.json"
9
+ end
10
+
11
+
12
+ def get(params={}) #:nodoc:
13
+ Cloudfuji::Command.get_command(app_url, params)
14
+ end
15
+
16
+
17
+ def put(command, params={}) #:nodoc:
18
+ params[:command] = command
19
+
20
+ Cloudfuji::Command.put_command(app_url, params)
21
+ end
22
+
23
+
24
+ # Get all of the information related to the current app, returns a hash
25
+ def show
26
+ result = get
27
+ end
28
+
29
+
30
+ # Starts a currently stopped app
31
+ # ==== Example Scenario
32
+ # You may want to use this when recieving a \<tt>rake cloudfuji:message</tt> event to
33
+ # start up your app for an incoming message
34
+ def start
35
+ put :start
36
+ end
37
+
38
+
39
+ # Stops an app.
40
+ # ==== Example Scenario
41
+ # Use this if you want to put your application in 'maintenance mode'.
42
+ def stop
43
+ put :stop
44
+ end
45
+
46
+
47
+ # Stops (if started) and then starts an app
48
+ # ==== Example Scenario
49
+ # if you've added environmental variables to an application and need the app
50
+ # to restart to pick them up, use this.
51
+ def restart # :nodoc:
52
+ put :restart
53
+ end
54
+
55
+ # Claims an app for the current Cloudfuji user
56
+ # Raises an exception if app is launched anonymously
57
+ # ==== Example Scenario
58
+ # Integrate Cloudfuji app claiming behavior directly into your app to help
59
+ # conversion rates
60
+ def claim
61
+ put :claim
62
+ end
63
+
64
+
65
+ # Updates the app to the latest git checkout, using the branch the app
66
+ # was initially dpeloyed from
67
+ # ==== Example Scenario
68
+ # Allow your users to upgrade to the latest version via a link directly in your application
69
+ def update
70
+ put :update
71
+ end
72
+
73
+
74
+ # Add an environmental variable
75
+ # ==== Example Scenario
76
+ # Allows your app to easily integrate into third-party services, e.g. mixpanel.
77
+ # A user can enter their own API key, and you can activate your mixpanel code.
78
+ def add_var(key, value)
79
+ put :add_var, {:key => key, :value => value}
80
+ if Cloudfuji::Command.last_command_successful?
81
+ ENV[key.upcase] = value
82
+ end
83
+ end
84
+
85
+
86
+ # Remove an environmental variable
87
+ # ==== Example Scenario
88
+ #
89
+ def remove_var(key)
90
+ put :remove_var, {:key => key}
91
+ if Cloudfuji::Command.last_command_successful?
92
+ ENV[key.upcase] = nil
93
+ end
94
+ end
95
+
96
+
97
+ # List all custom domains belonging to the current application
98
+ # ==== Example Scenario
99
+ # A CMS may want to use this if hosting multiple sites
100
+ def domains
101
+ get()["app"]["domains"]
102
+ end
103
+
104
+
105
+ # Returns the current subdomain of the app, whether that's the default
106
+ # (e.g. "happy-rabbit-12") or a custom-set subdomain ("my-example")
107
+ # ==== Example Scenario
108
+ # A CMS will use this to know which subdomain to respond to
109
+ def subdomain
110
+ get()["app"]["subdomain"]
111
+ end
112
+
113
+
114
+ # Check if a subdomain of cloudfuji.com is currently available
115
+ # ==== Example Scenario
116
+ # An application may want to change its subdomain to something user-chosen;
117
+ # use this before-hand to ensure it's available
118
+ def subdomain_available?(subdomain)
119
+ begin
120
+ return put :subdomain_available?, {:subdomain => subdomain}
121
+ rescue RestClient::UnprocessableEntity
122
+ return false
123
+ end
124
+ end
125
+
126
+
127
+ # Set the cloudfuji.com subdomain of an application
128
+ # ==== Example Scenario
129
+ # An app is initially launched to a randomly-generated subdomain, but may
130
+ # want to move to something more memorable for a given user.
131
+ def set_subdomain(subdomain)
132
+ result = put :set_subdomain!, {:subdomain => subdomain}
133
+ if Cloudfuji::Command.last_command_successful?
134
+ ENV["CLOUDFUJI_SUBDOMAIN"] = subdomain
135
+ ENV["PUBLIC_URL"] = "http://#{subdomain}.#{ENV['APP_TLD']}/"
136
+ return result
137
+ end
138
+
139
+ result
140
+ end
141
+
142
+
143
+ # Adds a domain to the Cloudfuji webrecords for an app. The app \<b>must</b>
144
+ # be a premium-app in order to add domains
145
+ # ==== Example Scenario
146
+ # If after launching a CMS a user decides to use a custom domain, an app
147
+ # can allow a user to customize it directly without resorting to the Cloudfuji
148
+ # app control panel.
149
+ def add_domain(domain)
150
+ put :add_domain!, {:domain => domain}
151
+ end
152
+
153
+
154
+ # Removes a custom domain from the Cloudfuji webrecords. Only works if the
155
+ # custom domain:
156
+ # * belongs to the current user
157
+ # * points at the current app
158
+ # ==== Example Scenario
159
+ # A user may decide to migrate a domain to a different app. This allows an app
160
+ # to remove it from its records without resorting to the Cloudfuji app
161
+ # control panel
162
+ def remove_domain(domain)
163
+ put :remove_domain!, {:domain => domain}
164
+ end
165
+
166
+
167
+ # Clear out the given log
168
+ # ==== Example Scenario
169
+ # An app may keep its production log for analysis by the end-user, but the
170
+ # user may want to clear out the irrelevant past logs.
171
+ def clear_log!(name)
172
+ put :clear_log!, {:name => name}
173
+ end
174
+
175
+
176
+ # Get all of the new logs. Returns a hash of the form {:name_of_log_X => "content of log X"}
177
+ # On Cloudfuji, there are by default the following logs:
178
+ # * access - Any page hit or asset request
179
+ # * error - Any error we had serving the page/asset
180
+ # * production - Output from the rails server
181
+ # * cloudfuji - logs from the cloudfuji deploy, update, start/stop process
182
+ #--
183
+ # TODO: Update to use the new logs controller
184
+ #++
185
+ def logs
186
+ get({:gift => "logs"})
187
+ end
188
+
189
+
190
+ def ssh_key #:nodoc:
191
+ get({:gift => "ssh_key"})["ssh_key"]
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,21 @@
1
+ require 'cloudfuji'
2
+
3
+ if defined?(Rails) && Rails::VERSION::MAJOR == 3
4
+ require 'rails'
5
+ require 'rails/routes'
6
+
7
+ module Cloudfuji
8
+ class Engine < Rails::Engine
9
+
10
+ initializer "cloudfuji.add_middleware" do |app|
11
+ # Only include our middleware if its on our platform
12
+ unless ENV['CLOUDFUJI_APP'].nil?
13
+ app.middleware.use Cloudfuji::Middleware
14
+ end
15
+ end
16
+ end
17
+ end
18
+ else
19
+ # Rails 2 handling
20
+ Rails.configuration.middleware.use 'Cloudfuji::Middleware'
21
+ end
@@ -0,0 +1,6 @@
1
+ module Cloudfuji
2
+ class Envs #:nodoc:
3
+ extend Hooks
4
+ end
5
+ end
6
+