cloudfuji 0.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +7 -0
- data/.rspec +4 -0
- data/Gemfile +17 -0
- data/README.md +3 -0
- data/Rakefile +36 -0
- data/app/controllers/cloudfuji/data_controller.rb +33 -0
- data/app/controllers/cloudfuji/envs_controller.rb +31 -0
- data/app/controllers/cloudfuji/mail_controller.rb +37 -0
- data/bin/cloudfuji +86 -0
- data/cloudfuji.gemspec +26 -0
- data/config/routes.rb +1 -0
- data/lib/cloudfuji.rb +53 -0
- data/lib/cloudfuji/action_mailer.rb +35 -0
- data/lib/cloudfuji/app.rb +202 -0
- data/lib/cloudfuji/bar.rb +19 -0
- data/lib/cloudfuji/base.rb +23 -0
- data/lib/cloudfuji/command.rb +110 -0
- data/lib/cloudfuji/config.rb +12 -0
- data/lib/cloudfuji/data.rb +52 -0
- data/lib/cloudfuji/data_helper.rb +1 -0
- data/lib/cloudfuji/dns.rb +195 -0
- data/lib/cloudfuji/engine.rb +21 -0
- data/lib/cloudfuji/envs.rb +6 -0
- data/lib/cloudfuji/envs_helper.rb +1 -0
- data/lib/cloudfuji/event.rb +63 -0
- data/lib/cloudfuji/event_observer.rb +20 -0
- data/lib/cloudfuji/mail_helper.rb +1 -0
- data/lib/cloudfuji/mail_route.rb +186 -0
- data/lib/cloudfuji/middleware.rb +42 -0
- data/lib/cloudfuji/models.rb +59 -0
- data/lib/cloudfuji/notification.rb +0 -0
- data/lib/cloudfuji/orm/active_record.rb +44 -0
- data/lib/cloudfuji/orm/mongoid.rb +31 -0
- data/lib/cloudfuji/platform.rb +47 -0
- data/lib/cloudfuji/schema.rb +42 -0
- data/lib/cloudfuji/smtp.rb +24 -0
- data/lib/cloudfuji/user.rb +59 -0
- data/lib/cloudfuji/user_helper.rb +7 -0
- data/lib/cloudfuji/utils.rb +53 -0
- data/lib/cloudfuji/version.rb +4 -0
- data/lib/generators/active_record/cloudfuji_generator.rb +28 -0
- data/lib/generators/active_record/templates/migration.rb +20 -0
- data/lib/generators/cloudfuji/auth_migration_generator.rb +46 -0
- data/lib/generators/cloudfuji/cloudfuji_generator.rb +14 -0
- data/lib/generators/cloudfuji/hooks_generator.rb +43 -0
- data/lib/generators/cloudfuji/install_generator.rb +24 -0
- data/lib/generators/cloudfuji/mail_routes_generator.rb +45 -0
- data/lib/generators/cloudfuji/orm_helpers.rb +21 -0
- data/lib/generators/cloudfuji/routes_generator.rb +22 -0
- data/lib/generators/mongoid/cloudfuji_generator.rb +17 -0
- data/lib/generators/templates/README +5 -0
- data/lib/generators/templates/cloudfuji.rb +10 -0
- data/lib/hooks.rb +36 -0
- data/lib/rails/routes.rb +42 -0
- data/lib/tasks/cloudfuji.rake +6 -0
- data/spec/app_spec/controllers/envs_controller_spec.rb +25 -0
- data/spec/app_spec/controllers/mail_controller_spec.rb +28 -0
- data/spec/app_spec/integration/app_claim_spec.rb +16 -0
- data/spec/gem_spec/base_spec.rb +24 -0
- data/spec/gem_spec/command_spec.rb +181 -0
- data/spec/gem_spec/config_spec.rb +9 -0
- data/spec/gem_spec/data_spec.rb +13 -0
- data/spec/gem_spec/hooks_spec.rb +5 -0
- data/spec/gem_spec/mail_route_spec.rb +168 -0
- data/spec/gem_spec/platform_spec.rb +9 -0
- data/spec/gem_spec/user_spec.rb +45 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/test_apps/rails-2.3/.gitignore +13 -0
- data/spec/test_apps/rails-2.3/Gemfile +13 -0
- data/spec/test_apps/rails-2.3/README +243 -0
- data/spec/test_apps/rails-2.3/Rakefile +10 -0
- data/spec/test_apps/rails-2.3/app/controllers/application_controller.rb +10 -0
- data/spec/test_apps/rails-2.3/app/helpers/application_helper.rb +3 -0
- data/spec/test_apps/rails-2.3/config/boot.rb +114 -0
- data/spec/test_apps/rails-2.3/config/environment.rb +41 -0
- data/spec/test_apps/rails-2.3/config/environments/development.rb +17 -0
- data/spec/test_apps/rails-2.3/config/environments/production.rb +28 -0
- data/spec/test_apps/rails-2.3/config/environments/test.rb +30 -0
- data/spec/test_apps/rails-2.3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/cookie_verification_secret.rb +7 -0
- data/spec/test_apps/rails-2.3/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-2.3/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-2.3/config/initializers/new_rails_defaults.rb +21 -0
- data/spec/test_apps/rails-2.3/config/initializers/session_store.rb +15 -0
- data/spec/test_apps/rails-2.3/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-2.3/config/routes.rb +43 -0
- data/spec/test_apps/rails-2.3/db/seeds.rb +7 -0
- data/spec/test_apps/rails-2.3/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-2.3/lib/tasks/rspec.rake +144 -0
- data/spec/test_apps/rails-2.3/public/404.html +30 -0
- data/spec/test_apps/rails-2.3/public/422.html +30 -0
- data/spec/test_apps/rails-2.3/public/500.html +30 -0
- data/spec/test_apps/rails-2.3/public/favicon.ico +0 -0
- data/spec/test_apps/rails-2.3/public/images/rails.png +0 -0
- data/spec/test_apps/rails-2.3/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-2.3/public/javascripts/controls.js +963 -0
- data/spec/test_apps/rails-2.3/public/javascripts/dragdrop.js +973 -0
- data/spec/test_apps/rails-2.3/public/javascripts/effects.js +1128 -0
- data/spec/test_apps/rails-2.3/public/javascripts/prototype.js +4320 -0
- data/spec/test_apps/rails-2.3/public/robots.txt +5 -0
- data/spec/test_apps/rails-2.3/script/about +4 -0
- data/spec/test_apps/rails-2.3/script/autospec +6 -0
- data/spec/test_apps/rails-2.3/script/console +3 -0
- data/spec/test_apps/rails-2.3/script/dbconsole +3 -0
- data/spec/test_apps/rails-2.3/script/destroy +3 -0
- data/spec/test_apps/rails-2.3/script/generate +3 -0
- data/spec/test_apps/rails-2.3/script/performance/benchmarker +3 -0
- data/spec/test_apps/rails-2.3/script/performance/profiler +3 -0
- data/spec/test_apps/rails-2.3/script/plugin +3 -0
- data/spec/test_apps/rails-2.3/script/runner +3 -0
- data/spec/test_apps/rails-2.3/script/server +3 -0
- data/spec/test_apps/rails-2.3/script/spec +10 -0
- data/spec/test_apps/rails-2.3/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-2.3/spec/rcov.opts +2 -0
- data/spec/test_apps/rails-2.3/spec/spec.opts +4 -0
- data/spec/test_apps/rails-2.3/spec/spec_helper.rb +83 -0
- data/spec/test_apps/rails-2.3/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-2.3/test/test_helper.rb +38 -0
- data/spec/test_apps/rails-3.0/.gitignore +4 -0
- data/spec/test_apps/rails-3.0/.rspec +2 -0
- data/spec/test_apps/rails-3.0/Gemfile +10 -0
- data/spec/test_apps/rails-3.0/README +256 -0
- data/spec/test_apps/rails-3.0/Rakefile +7 -0
- data/spec/test_apps/rails-3.0/app/controllers/application_controller.rb +3 -0
- data/spec/test_apps/rails-3.0/app/controllers/static_controller.rb +4 -0
- data/spec/test_apps/rails-3.0/app/helpers/application_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/helpers/static_helper.rb +2 -0
- data/spec/test_apps/rails-3.0/app/views/layouts/application.html.erb +14 -0
- data/spec/test_apps/rails-3.0/app/views/static/home.html.erb +1 -0
- data/spec/test_apps/rails-3.0/config.ru +4 -0
- data/spec/test_apps/rails-3.0/config/application.rb +46 -0
- data/spec/test_apps/rails-3.0/config/boot.rb +6 -0
- data/spec/test_apps/rails-3.0/config/environment.rb +5 -0
- data/spec/test_apps/rails-3.0/config/environments/development.rb +26 -0
- data/spec/test_apps/rails-3.0/config/environments/production.rb +49 -0
- data/spec/test_apps/rails-3.0/config/environments/test.rb +35 -0
- data/spec/test_apps/rails-3.0/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/inflections.rb +10 -0
- data/spec/test_apps/rails-3.0/config/initializers/mime_types.rb +5 -0
- data/spec/test_apps/rails-3.0/config/initializers/secret_token.rb +7 -0
- data/spec/test_apps/rails-3.0/config/initializers/session_store.rb +8 -0
- data/spec/test_apps/rails-3.0/config/locales/en.yml +5 -0
- data/spec/test_apps/rails-3.0/config/routes.rb +62 -0
- data/spec/test_apps/rails-3.0/db/schema.rb +15 -0
- data/spec/test_apps/rails-3.0/db/seeds.rb +7 -0
- data/spec/test_apps/rails-3.0/doc/README_FOR_APP +2 -0
- data/spec/test_apps/rails-3.0/lib/tasks/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/public/404.html +26 -0
- data/spec/test_apps/rails-3.0/public/422.html +26 -0
- data/spec/test_apps/rails-3.0/public/500.html +26 -0
- data/spec/test_apps/rails-3.0/public/favicon.ico +0 -0
- data/spec/test_apps/rails-3.0/public/images/rails.png +0 -0
- data/spec/test_apps/rails-3.0/public/index.html +239 -0
- data/spec/test_apps/rails-3.0/public/javascripts/application.js +2 -0
- data/spec/test_apps/rails-3.0/public/javascripts/controls.js +965 -0
- data/spec/test_apps/rails-3.0/public/javascripts/dragdrop.js +974 -0
- data/spec/test_apps/rails-3.0/public/javascripts/effects.js +1123 -0
- data/spec/test_apps/rails-3.0/public/javascripts/prototype.js +6001 -0
- data/spec/test_apps/rails-3.0/public/javascripts/rails.js +191 -0
- data/spec/test_apps/rails-3.0/public/robots.txt +5 -0
- data/spec/test_apps/rails-3.0/public/stylesheets/.gitkeep +0 -0
- data/spec/test_apps/rails-3.0/script/rails +6 -0
- data/spec/test_apps/rails-3.0/spec/all_spec.rb +5 -0
- data/spec/test_apps/rails-3.0/spec/spec_helper.rb +78 -0
- data/spec/test_apps/rails-3.0/test/performance/browsing_test.rb +9 -0
- data/spec/test_apps/rails-3.0/test/test_helper.rb +13 -0
- data/spec/test_apps/rails-3.0/vendor/plugins/.gitkeep +0 -0
- data/tasks/cover_me.rake +11 -0
- data/test_app/spec/views/home.html.erb_spec.rb +15 -0
- metadata +261 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#:nodoc:
|
|
2
|
+
source "http://rubygems.org"
|
|
3
|
+
|
|
4
|
+
# Specify your gem's dependencies in cloudfuji.gemspec
|
|
5
|
+
gemspec
|
|
6
|
+
|
|
7
|
+
gem "sqlite3-ruby"
|
|
8
|
+
gem "rails", "~> 3.0.7"
|
|
9
|
+
|
|
10
|
+
group :development, :test do
|
|
11
|
+
# gem "webrat", "0.7.2", :require => false
|
|
12
|
+
# gem "mocha", :require => false
|
|
13
|
+
gem "rspec-rails", "~> 2.7.0"
|
|
14
|
+
gem "configatron", "> 2.8.3"
|
|
15
|
+
gem "cover_me"
|
|
16
|
+
gem "ci_reporter"
|
|
17
|
+
end
|
data/README.md
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'rake/testtask'
|
|
2
|
+
require 'rspec/core/rake_task'
|
|
3
|
+
require 'bundler'
|
|
4
|
+
require 'ci/reporter/rake/rspec'
|
|
5
|
+
Bundler::GemHelper.install_tasks
|
|
6
|
+
|
|
7
|
+
Dir['tasks/**/*.rake'].each { |rake| load rake }
|
|
8
|
+
|
|
9
|
+
desc "Default: run all specs"
|
|
10
|
+
task :default => :all_specs
|
|
11
|
+
|
|
12
|
+
desc "Run all specs"
|
|
13
|
+
task :all_specs do
|
|
14
|
+
Rake::Task["spec"].execute
|
|
15
|
+
Rake::Task["dummy_specs"].execute
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
desc "run unit tests in dummy apps"
|
|
19
|
+
task :dummy_specs do
|
|
20
|
+
Dir['spec/test_apps/**/Rakefile'].each do |rakefile|
|
|
21
|
+
directory_name = File.dirname(rakefile)
|
|
22
|
+
sh <<-CMD
|
|
23
|
+
cd #{directory_name} && bundle exec rake
|
|
24
|
+
CMD
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
desc "run unit tests for gem only"
|
|
29
|
+
RSpec::Core::RakeTask.new('spec') do |t|
|
|
30
|
+
t.pattern = '**/gem_spec/*_spec.rb'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if ENV["RAILS_ENV"] != "production"
|
|
35
|
+
require 'ci/reporter/rake/rspec'
|
|
36
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
class DataController < ApplicationController
|
|
3
|
+
|
|
4
|
+
# POST /cloudfuji/data/
|
|
5
|
+
def index
|
|
6
|
+
@key = params.delete("key")
|
|
7
|
+
if ENV["CLOUDFUJI_APP_KEY"] != @key
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.html { render :layout => false, :text => true, :status => :forbidden }
|
|
10
|
+
format.json { render :status => 401 }
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
puts "Idobus Data rec'd: #{params.inspect}"
|
|
16
|
+
puts params["category"].inspect
|
|
17
|
+
|
|
18
|
+
hook_data = {}
|
|
19
|
+
hook_data["category"] = params["category"]
|
|
20
|
+
hook_data["event"] = params["event"]
|
|
21
|
+
hook_data["data"] = params["data"]
|
|
22
|
+
|
|
23
|
+
puts "Firing with: #{hook_data.inspect}"
|
|
24
|
+
event = "#{params['category']}.#{params['event']}".gsub('.', '_').to_sym
|
|
25
|
+
|
|
26
|
+
Cloudfuji::Data.fire(hook_data, event)
|
|
27
|
+
|
|
28
|
+
respond_to do |format|
|
|
29
|
+
format.json {render :json => {'acknowledged' => true}, :status => 200}
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Cloudfuji
|
|
2
|
+
class EnvsController < ApplicationController
|
|
3
|
+
# PUT /cloudfuji/envs/:id
|
|
4
|
+
def update
|
|
5
|
+
if ENV["CLOUDFUJI_APP_KEY"] != params[:key] or params[:id] == "CLOUDFUJI_KEY"
|
|
6
|
+
respond_to do |format|
|
|
7
|
+
format.html { render :layout => false, :text => true, :status => :forbidden }
|
|
8
|
+
format.json { render :status => :unprocessable_entity }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
else
|
|
12
|
+
|
|
13
|
+
var = params[:id].upcase
|
|
14
|
+
|
|
15
|
+
ENV[var] = params[:value]
|
|
16
|
+
@value = ENV[var]
|
|
17
|
+
|
|
18
|
+
respond_to do |format|
|
|
19
|
+
if @value != ENV[var]
|
|
20
|
+
format.html{render :layout => false, :text => true, :status => :unprocessable_entity}
|
|
21
|
+
format.json{render :status => :unprocessable_entity}
|
|
22
|
+
else
|
|
23
|
+
Cloudfuji::Data.fire(var, {var => ENV[var]})
|
|
24
|
+
format.html{render :text => true}
|
|
25
|
+
format.json{render :json => {var => ENV[var]}}
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
module Cloudfuji
|
|
3
|
+
class MailController < ApplicationController
|
|
4
|
+
|
|
5
|
+
# POST /cloudfuji/mail
|
|
6
|
+
def index
|
|
7
|
+
puts "Handling email!"
|
|
8
|
+
mail = {}
|
|
9
|
+
attachments = []
|
|
10
|
+
|
|
11
|
+
# Strip the attachments first
|
|
12
|
+
params.keys.each do |key|
|
|
13
|
+
attachments << params.delete(key) if key =~ /attachment-\d+/
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Copy the params to the hook data
|
|
17
|
+
(params.keys - ["controller", "action"]).each do |param|
|
|
18
|
+
mail[param.downcase] = params[param]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
mail["attachments"] = attachments
|
|
22
|
+
|
|
23
|
+
puts "params: #{params.inspect}"
|
|
24
|
+
puts "mail: #{mail.inspect}"
|
|
25
|
+
|
|
26
|
+
# Output for debugging remotely
|
|
27
|
+
Cloudfuji::Mailroute.pretty_print_routes
|
|
28
|
+
puts "Finished routing"
|
|
29
|
+
|
|
30
|
+
# Mailroute is in charge of figuring out which callback to trigger
|
|
31
|
+
Cloudfuji::Mailroute.routes.process(mail)
|
|
32
|
+
|
|
33
|
+
result = {:success => true, :message => nil, :data => {}}
|
|
34
|
+
render :text => result.to_json, :status => 200
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
data/bin/cloudfuji
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
begin
|
|
3
|
+
require 'cloudfuji'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
$: << File.expand_path("../../lib", __FILE__)
|
|
6
|
+
require 'cloudfuji'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
options = {}
|
|
10
|
+
|
|
11
|
+
commands = [:login, :remove_account, :claim, :list, :create, :show, :start, :stop, :restart, :update, :open, :logs, :add_var, :remove_var, :ssh_key, :api_key].sort_by {|s| s.to_s}
|
|
12
|
+
|
|
13
|
+
help_docs = {
|
|
14
|
+
:login => "cloudfuji login - Authorizes this machine to work under your Cloudfuji account",
|
|
15
|
+
:api_key => "cloudfuji api_key - Prints out your Cloudfuji API key for use elsewhere (in the cloudfuji development webapp, for example)",
|
|
16
|
+
:remove_account => "cloudfuji remove_account - Removes all Cloudfuji information from this machine",
|
|
17
|
+
:list => "cloudfuji list - List all of your deployed Cloudfuji apps",
|
|
18
|
+
:claim => "cloudfuji claim [NAME] - Claim a running Cloudfuji app as your own",
|
|
19
|
+
:create => "cloudfuji create [URL] - Deploy a Cloudfuji app from a git repository in URL",
|
|
20
|
+
:show => "cloudfuji show [NAME] - Provide a detailed view of the Cloudfuji app",
|
|
21
|
+
:start => "cloudfuji start [NAME] - Turns the app on if it's been shut down for any reason",
|
|
22
|
+
:stop => "cloudfuji stop [NAME] - Turns the app off to prevent any access",
|
|
23
|
+
:restart => "cloudfuji restart [NAME] - Performace a stop and start in succession" ,
|
|
24
|
+
:update => "cloudfuji update [NAME] - Will stop the running cloudfuji app, pull from the url originally supplied to the app, update in place, and start back up",
|
|
25
|
+
:open => "cloudfuji open [NAME] - Open browser window to the running Cloudfuji app",
|
|
26
|
+
:create => "cloudfuji create [NAME] - Creates a new app",
|
|
27
|
+
:logs => "cloudfuji logs [NAME] - Retrieves all of the logs for an app and returns them in a JSON structure",
|
|
28
|
+
:ssh_key => "cloudfuji ssh_key [NAME] - Retrieves ssh_key for NAME, only needed for private repos (e.g. on github)",
|
|
29
|
+
:add_var => "cloudfuji add_var [NAME] [KEY] [VALUE] - Adds an environmental variable for an app to use",
|
|
30
|
+
:remove_var => "cloudfuji remove_var [NAME] [KEY] - Removes an existing environmental variable from an app"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
OptionParser.new do |opts|
|
|
34
|
+
opts.banner = "Usage: cloudfuji <command>"
|
|
35
|
+
|
|
36
|
+
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
|
|
37
|
+
options[:verbose] = v
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
opts.on("-h", "--help [command]", commands, "Help (this screen)") do |h|
|
|
41
|
+
if h.nil?
|
|
42
|
+
puts opts
|
|
43
|
+
puts "Supported commands: #{commands.join(', ')}"
|
|
44
|
+
exit
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
puts help_docs[h]
|
|
48
|
+
exit
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
opts.on_tail("-V", "--version", "Show version") do
|
|
52
|
+
puts Cloudfuji::VERSION.join('.')
|
|
53
|
+
exit
|
|
54
|
+
end
|
|
55
|
+
end.parse!
|
|
56
|
+
|
|
57
|
+
command = ARGV.first
|
|
58
|
+
|
|
59
|
+
if command
|
|
60
|
+
case command.downcase.to_sym
|
|
61
|
+
|
|
62
|
+
when :claim then Cloudfuji::App.claim(ARGV[1])
|
|
63
|
+
when :list then Cloudfuji::App.list()
|
|
64
|
+
when :create then Cloudfuji::App.create(ARGV[1])
|
|
65
|
+
when :show then Cloudfuji::App.show(ARGV[1])
|
|
66
|
+
when :start then Cloudfuji::App.start(ARGV[1])
|
|
67
|
+
when :stop then Cloudfuji::App.stop(ARGV[1])
|
|
68
|
+
when :restart then Cloudfuji::App.restart(ARGV[1])
|
|
69
|
+
when :update then Cloudfuji::App.update(ARGV[1])
|
|
70
|
+
when :open then Cloudfuji::App.open(ARGV[1])
|
|
71
|
+
|
|
72
|
+
when :add_domain then Cloudfuji::App.add_domain(ARGV[1], ARGV[2])
|
|
73
|
+
when :remove_domain then Cloudfuji::App.remove_domain(ARGV[1])
|
|
74
|
+
when :add_var then Cloudfuji::App.add_var(ARGV[1], ARGV[2], ARGV[3])
|
|
75
|
+
when :remove_var then Cloudfuji::App.remove_var(ARGV[1], ARGV[2])
|
|
76
|
+
when :clear_logs then Cloudfuji::App.clear_logs(ARGV[1])
|
|
77
|
+
when :logs then Cloudfuji::App.logs(ARGV[1])
|
|
78
|
+
when :ssh_key then Cloudfuji::App.ssh_key(ARGV[1])
|
|
79
|
+
else
|
|
80
|
+
puts "I don't know how to '#{command}'"
|
|
81
|
+
puts "I do know how to do these though: #{commands.join(', ')}"
|
|
82
|
+
end
|
|
83
|
+
else
|
|
84
|
+
puts "usage: cloudfuji <command>\n\nSee cloudfuji -h for more detailed instructions"
|
|
85
|
+
puts "Supported commands: #{commands.join(', ')}"
|
|
86
|
+
end
|
data/cloudfuji.gemspec
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
3
|
+
require "cloudfuji/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |s|
|
|
6
|
+
s.name = "cloudfuji"
|
|
7
|
+
s.version = Cloudfuji::VERSION
|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
|
9
|
+
s.authors = ["Sean Grove", "Kev Zettler"]
|
|
10
|
+
s.email = ["support@cloudfuji.com","s@cloudfuji.com"]
|
|
11
|
+
s.homepage = "https://github.com/sgrove/cloudfujigem"
|
|
12
|
+
s.summary = %q{Cloudfuji integration}
|
|
13
|
+
s.description = %q{A module for integrating the Cloudfuji platform into a rails app}
|
|
14
|
+
|
|
15
|
+
s.add_dependency "rest-client", ">=1.6.1"
|
|
16
|
+
s.add_dependency "json", ">=1.4.6"
|
|
17
|
+
s.add_dependency "highline", ">=1.6.1"
|
|
18
|
+
s.add_dependency "orm_adapter", "~> 0.0.3"
|
|
19
|
+
|
|
20
|
+
s.rubyforge_project = "cloudfuji"
|
|
21
|
+
|
|
22
|
+
s.files = `git ls-files`.split("\n")
|
|
23
|
+
s.test_files = `git ls-files -- {test,test_app,spec,features}/*`.split("\n")
|
|
24
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
25
|
+
s.require_paths = ["lib"]
|
|
26
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
data/lib/cloudfuji.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Cloudfuji #:nodoc:
|
|
2
|
+
require 'optparse'
|
|
3
|
+
require 'rest_client'
|
|
4
|
+
require 'json'
|
|
5
|
+
require 'highline/import'
|
|
6
|
+
require 'orm_adapter'
|
|
7
|
+
require 'cloudfuji/engine'
|
|
8
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
9
|
+
require "action_dispatch"
|
|
10
|
+
end
|
|
11
|
+
require "rails/routes"
|
|
12
|
+
require "cloudfuji/base"
|
|
13
|
+
require "cloudfuji/bar"
|
|
14
|
+
require "cloudfuji/config"
|
|
15
|
+
require "cloudfuji/smtp"
|
|
16
|
+
|
|
17
|
+
require "hooks"
|
|
18
|
+
require "cloudfuji/platform"
|
|
19
|
+
require "cloudfuji/utils"
|
|
20
|
+
require "cloudfuji/command"
|
|
21
|
+
require "cloudfuji/app"
|
|
22
|
+
require "cloudfuji/user"
|
|
23
|
+
require "cloudfuji/event"
|
|
24
|
+
require "cloudfuji/version"
|
|
25
|
+
require "cloudfuji/envs"
|
|
26
|
+
require "cloudfuji/data"
|
|
27
|
+
require "cloudfuji/middleware"
|
|
28
|
+
require "cloudfuji/models"
|
|
29
|
+
require "cloudfuji/schema"
|
|
30
|
+
require "cloudfuji/event_observer"
|
|
31
|
+
require "cloudfuji/mail_route"
|
|
32
|
+
require "cloudfuji/user_helper"
|
|
33
|
+
|
|
34
|
+
# Manually require the controllers for rails 2
|
|
35
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 2
|
|
36
|
+
base_dir = "#{File.dirname(__FILE__)}/.."
|
|
37
|
+
|
|
38
|
+
require "#{base_dir}/app/controllers/cloudfuji/data_controller"
|
|
39
|
+
require "#{base_dir}/app/controllers/cloudfuji/mail_controller"
|
|
40
|
+
require "#{base_dir}/app/controllers/cloudfuji/envs_controller"
|
|
41
|
+
require "cloudfuji/action_mailer"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if defined?(Rails) && Rails::VERSION::MAJOR == 3
|
|
45
|
+
Cloudfuji::SMTP.setup_action_mailer_smtp!
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Default way to setup Cloudfuji. Run rails generate cloudfuji_install to create
|
|
49
|
+
# a fresh initializer with all configuration values.
|
|
50
|
+
def self.setup
|
|
51
|
+
yield self
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module ActionMailer
|
|
2
|
+
class Base
|
|
3
|
+
private
|
|
4
|
+
def perform_delivery_cloudfuji(mail)
|
|
5
|
+
if mail.to.nil?
|
|
6
|
+
unless logger.nil?
|
|
7
|
+
logger.error "This mail isn't addressed to anyone! Dropping"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
return false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
#result = Cloudfuji::App.mail_allowed?
|
|
14
|
+
result = {"success" => true}
|
|
15
|
+
|
|
16
|
+
if result
|
|
17
|
+
logger.info result.inspect unless logger.nil?
|
|
18
|
+
if result["success"] == true
|
|
19
|
+
Cloudfuji::SMTP.setup_action_mailer_smtp!
|
|
20
|
+
|
|
21
|
+
unless logger.nil?
|
|
22
|
+
logger.info "App allowed to send email, sending via SMTP"
|
|
23
|
+
logger.info "Sending:"
|
|
24
|
+
logger.info mail.inspect
|
|
25
|
+
__send__("perform_delivery_smtp", mail) if perform_deliveries
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
logger.info "Unable to send email: #{result['message']}" unless logger.nil?
|
|
29
|
+
end
|
|
30
|
+
else
|
|
31
|
+
logger.info "Unable to contact Cloudfuji to verify email credentials" unless logger.nil?
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
# Check if the app is allowed to send emails
|
|
191
|
+
# Apps are rate-limited according to their tier
|
|
192
|
+
def mail_allowed?
|
|
193
|
+
Cloudfuji::Command.get_command(Cloudfuji::Base.allowed_email_url)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def ssh_key #:nodoc:
|
|
198
|
+
get({:gift => "ssh_key"})["ssh_key"]
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|