Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed May 21, 2012
0 parents commit b1dc5aa
Show file tree
Hide file tree
Showing 24 changed files with 495 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pkg/
*.gem
Gemfile.lock
spec/internal/log/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lang: ruby

rvm:
- 1.9.3

before_script:
- sh -c "psql -c 'create database ffcrm_cloudfuji_test;' -U postgres"
26 changes: 26 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
source :rubygems

gem 'bundler_local_development', :group => :development, :require => false
begin
require 'bundler_local_development'
rescue LoadError
end

gemspec

gem 'cloudfuji', :git => 'git://github.com/cloudfuji/cloudfuji_client.git'

group :test, :development do
gem 'pg' # Default database for testing
end

group :test do
gem 'rspec'
gem 'combustion'
gem 'factory_girl'
unless ENV["CI"]
gem 'ruby-debug', :platform => :mri_18
gem (RUBY_VERSION == "1.9.2" ? 'ruby-debug19' : 'debugger'), :platform => :mri_19
end
end

20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2011 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Errbit - Cloudfuji Integration
====================================

Integrates Errbit with the Cloudfuji hosting platform.

Copyright (c) 2012 Cloudfuji
27 changes: 27 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler.require :default, :development

task :environment do
Combustion.initialize!
end
Combustion::Application.load_tasks

class Combustion::Application
# Add migrations from all engines
Railties.engines.each do |engine|
config.paths['db/migrate'] += engine.paths['db/migrate'].existent
end
end

desc 'Default: run spec tests.'
task :default => :spec

# Let Combustion handle database preparation
Rake::Task["spec"].prerequisites.clear

Bundler::GemHelper.install_tasks
22 changes: 22 additions & 0 deletions app/models/err_observer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class ErrObserver < Mongoid::Observer
def after_create(err)
if ::Cloudfuji::Platform.on_cloudfuji?
human_message = issue_title(err.problem)
human_message += " see more at #{Rails.application.routes.url_helpers.app_err_url(err.problem.app, err, :host => ENV['CLOUDFUJI_DOMAIN'])}"
event = {
:category => :app,
:name => :errored,
:data => {
:human => human_message,
:source => "Errbit",
:url => Rails.application.routes.url_helpers.app_err_url(err.problem.app, err, :host => ENV['CLOUDFUJI_DOMAIN'])
}
}
::Cloudfuji::Event.publish(event)
end
end

def issue_title(problem)
"[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"
end
end
38 changes: 38 additions & 0 deletions app/models/notice_observer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class NoticeObserver < Mongoid::Observer
def after_create(notice)
if ::Cloudfuji::Platform.on_cloudfuji?
@notice = notice
@err = notice.err
@app = notice.problem.app

human_message = notice_title(notice.err.problem)
human_message += " see more at #{Rails.application.routes.url_helpers.app_err_url(@app, @notice.problem, :host => ENV['CLOUDFUJI_DOMAIN'])}"
event = {
:category => :app,
:name => :errored,
:data => {
:human => human_message,
:environment_name => @notice.environment_name,
:occurrences => @notice.problem.notices_count,
:message => @notice.message,
:app_backtrace => @notice.app_backtrace,
:request => @notice.request,
:source => "Errbit",
:url => Rails.application.routes.url_helpers.app_err_url(@app, @err, :host => ENV['CLOUDFUJI_DOMAIN'])
}
}

::Cloudfuji::Event.publish(event)

puts "Notifying: #{@app.watchers.inspect}"
@app.watchers.each do |watcher|
ido_id = watcher.user.ido_id
Cloudfuji::User.notify(ido_id, "Site Error", human_message, "site_error") unless ido_id.blank?
end
end
end

def notice_title(notice)
"[#{@app.name}][#{@notice.environment_name}] #{@notice.message}"
end
end
37 changes: 37 additions & 0 deletions app/views/users/_fields.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
= errors_for @user

.required
= f.label :name
= f.text_field :name

- if Errbit::Config.user_has_username
.required
= f.label :username
= f.text_field :username

.required
= f.label :email
= f.text_field :email

.required
= f.label 'Entries per page'
= f.select :per_page, [10, 20, 30, 50, 75, 100]

.required
= f.label :time_zone
= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones

- unless Cloudfuji::Platform.on_cloudfuji?
.required
= f.label :password
= f.password_field :password

.required
= f.label :password_confirmation
= f.password_field :password_confirmation

- if current_user.admin?
.checkbox
= f.check_box :admin
= f.label :admin, 'Admin?'

23 changes: 23 additions & 0 deletions app/views/users/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- content_for :title, 'Users'
- if not Devise.on_cloudfuji?
- content_for :action_bar do
%span= link_to('Add a New User', new_user_path, :class => 'add')

%table
%thead
%tr
%th Name
- if Errbit::Config.user_has_username
%th Username
%th.main Email
%th Admin?
%tbody
- @users.each do |user|
%tr
%td.nowrap= link_to user.name, user_path(user)
- if Errbit::Config.user_has_username
%td= user.username
%td= user.email
%td= user.admin? ? 'Y' : 'N'
= paginate @users

7 changes: 7 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rubygems'
require 'bundler'

Bundler.require :default, :development

Combustion.initialize!
run Combustion::Application
8 changes: 8 additions & 0 deletions config/cloudfuji.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"platform": "rails",
"platform_version": 3,
"ruby_version": "1.9.2",
"sql": false,
"mongodb": true,
"project_name": "errbit"
}
10 changes: 10 additions & 0 deletions config/initializers/cloudfuji.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'errbit/cloudfuji'

Errbit::Application.configure do
# Register observers to fire Cloudfuji events
config.mongoid.observers = :err_observer, :notice_observer

# Set default host for ActionMailer
default_host = ENV['ERRBIT_HOST'] || ENV['BUSHIDO_DOMAIN']
config.action_mailer.default_url_options = { :host => default_host } if default_host
end
28 changes: 28 additions & 0 deletions config/initializers/cloudfuji_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
if ENV['HOSTING_PLATFORM'] == 'cloudfuji'
require 'ostruct'
Errbit::Config = OpenStruct.new

puts "Loading Cloudfuji config"
Errbit::Config.host = ENV['CLOUDFUJI_DOMAIN']
Errbit::Config.email_from = ENV['SMTP_USER']
Errbit::Config.email_at_notices = [1,3,10] #ENV['ERRBIT_EMAIL_AT_NOTICES']
Errbit::Config.confirm_resolve_err = true
Errbit::Config.user_has_ido_id = true
Errbit::Config.allow_comments_with_issue_tracker = true

Errbit::Config.smtp_settings = {
:address => ENV["SMTP_SERVER"],
:port => ENV["SMTP_PORT"],
:authentication => ENV["SMTP_AUTHENTICATION"],
:user_name => ENV["SMTP_USER"],
:password => ENV["SMTP_PASSWORD"],
:domain => ENV["SMTP_DOMAIN"]
}

Errbit::Config.devise_modules = [:cloudfuji_authenticatable,
:rememberable,
:trackable,
:token_authenticatable]

puts "Devise modules: #{Errbit::Config.devise_modules.inspect}"
end
8 changes: 8 additions & 0 deletions config/mongoid.cloudfuji.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mongoid Configuration for MongoHQ on Cloudfuji
# ============================================

development:
uri: <%= ENV['MONGODB_URL'] %>

production:
uri: <%= ENV['MONGODB_URL'] %>
22 changes: 22 additions & 0 deletions errbit_cloudfuji.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
require 'errbit_cloudfuji/version'

Gem::Specification.new do |s|
s.name = 'errbit_cloudfuji'
s.authors = ['Sean Grove', 'Nathan Broadbent']
s.email = '[email protected]'
s.homepage = 'http://cloudfuji.com'
s.summary = 'Errbit - Cloudfuji Integration'
s.description = 'Integrates Errbit with the Cloudfuji hosting platform.'
s.files = `git ls-files`.split("\n")
s.version = Errbit::Cloudfuji::VERSION

s.add_development_dependency 'rspec-rails', '~> 2.6'
s.add_development_dependency 'capybara'
s.add_development_dependency 'combustion'

s.add_dependency 'cloudfuji', '>= 0.0.42'
s.add_dependency 'devise_cloudfuji_authenticatable'

end
71 changes: 71 additions & 0 deletions lib/errbit/cloudfuji.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module Errbit
module Cloudfuji
class << self
def enable_cloudfuji!
load_hooks!
extend_user!
extend_notice!
disable_devise_for_cloudfuji_controllers!
end

def extend_user!
puts "Extending the user model"
User.instance_eval do
validates_presence_of :ido_id
validates_uniqueness_of :ido_id
end

User.class_eval do
def cloudfuji_extra_attributes(extra_attributes)
self.name = "#{extra_attributes['first_name'].to_s} #{extra_attributes['last_name'].to_s}"
self.email = extra_attributes["email"]
self.admin = true
end
end
end

def extend_notice!
Notice.class_eval do
def publish_cloudfuji_event
human_message = "App at #{server_environment['hostname']} error"
::Cloudfuji::Event.publish({
:category => :app,
:name => :error,
:data => {
:human => human_message,
:source => "Errbit",
:url => "#{ENV['PUBLIC_URL']}/#tickets/#{self.to_param}"
}
})
end
end
end

def load_hooks!
Dir["#{Dir.pwd}/lib/cloudfuji/**/*.rb"].each { |file| require file }
end

# Temporary hack because all routes require authentication in
# Errbit
def disable_devise_for_cloudfuji_controllers!
puts "Disabling devise auth protection on cloudfuji controllers"

::Cloudfuji::DataController.instance_eval { before_filter :authenticate_user!, :except => [:index] }
::Cloudfuji::EnvsController.instance_eval { before_filter :authenticate_user!, :except => [:update] }
::Cloudfuji::MailController.instance_eval { before_filter :authenticate_user!, :except => [:index] }

puts "Devise checks disabled for Cloudfuji controllers"
end
end
end
end

if Cloudfuji::Platform.on_cloudfuji?
class CloudfujiRailtie < Rails::Railtie
config.to_prepare do
puts "Enabling Cloudfuji"
Errbit::Cloudfuji.enable_cloudfuji!
puts "Finished enabling Cloudfuji"
end
end
end
Loading

0 comments on commit b1dc5aa

Please sign in to comment.