Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added default template Simplified options
- Loading branch information
Showing
11 changed files
with
123 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,6 @@ tmtags | |
coverage | ||
rdoc | ||
pkg | ||
.bundle | ||
|
||
## PROJECT::SPECIFIC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source :rubygems | ||
|
||
# Specify your gem's dependencies in rack-staging.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
rack-staging (0.1.0) | ||
|
||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bundler (>= 1.0.0.rc.5) | ||
rack-staging! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,2 @@ | ||
require 'rubygems' | ||
require 'rake' | ||
|
||
begin | ||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
gem.name = "staging" | ||
gem.summary = %Q{Protect you Rails application from anonymous and prying.} | ||
gem.description = %Q{Staging rack application purpose to protect you Rails application from anonymous and prying.} | ||
gem.email = "kossnocorp@gmail.com" | ||
gem.homepage = "http://github.com/kossnocorp/staging" | ||
gem.authors = ["Aleksandr Koss"] | ||
gem.version = '0.1' | ||
|
||
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0" | ||
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings | ||
end | ||
Jeweler::GemcutterTasks.new | ||
rescue LoadError | ||
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" | ||
end | ||
|
||
require 'rake/testtask' | ||
Rake::TestTask.new(:test) do |test| | ||
test.libs << 'lib' << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
|
||
begin | ||
require 'rcov/rcovtask' | ||
Rcov::RcovTask.new do |test| | ||
test.libs << 'test' | ||
test.pattern = 'test/**/test_*.rb' | ||
test.verbose = true | ||
end | ||
rescue LoadError | ||
task :rcov do | ||
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" | ||
end | ||
end | ||
|
||
task :test => :check_dependencies | ||
|
||
task :default => :test | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "staging #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end | ||
|
||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Hi! I'am rack middleware! | ||
# I was born for protect you staging application from anonymous and prying | ||
|
||
# My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com | ||
# Nice to MIT you! | ||
|
||
module Rack | ||
class Staging | ||
|
||
def initialize(app, options = {}) | ||
@app = app | ||
@options = options | ||
end | ||
|
||
def call(env) | ||
request = Rack::Request.new(env) | ||
|
||
# Check code in session and return Rails call if is valid | ||
return @app.call(env) if already_auth?(request) | ||
|
||
# If post method check :code_param value | ||
if request.post? and code_valid?(request.params["staging_code"]) | ||
request.session[:staging_code] = request.params["staging_code"] | ||
[301, {'Location' => '/'}, ''] # Redirect if code is valid | ||
else | ||
render_staging | ||
end | ||
end | ||
|
||
private | ||
# Render staging html file | ||
def render_staging | ||
[200, {'Content-Type' => 'text/html'}, [ | ||
::File.open(html_template, 'rb').read | ||
]] | ||
end | ||
|
||
def html_template | ||
@options[:template_path] || ::File.expand_path('../rack-staging/index.html', __FILE__) | ||
end | ||
|
||
# Validate code | ||
def code_valid?(code) | ||
@options[:code] == code | ||
end | ||
|
||
def already_auth?(request) | ||
code_valid?(request.session[:staging_code]) | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Staging protection</title> | ||
</head> | ||
<body onLoad='document.forms[0].elements[0].focus();' style='text-align: center; margin-top:100px'> | ||
<form action="/" method="post"> | ||
<label> | ||
<h1>Staging code</h1> | ||
<input name="staging_code" /> | ||
</label> | ||
<input type="submit" /> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Rack | ||
class Staging | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- encoding: utf-8 -*- | ||
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) | ||
require 'rack-staging/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "rack-staging" | ||
s.version = Rack::Staging::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Aleksandr Koss"] | ||
s.email = ["kossnocorp@gmail.com"] | ||
s.homepage = "http://github.com/kossnocorp/staging" | ||
s.summary = "Protect you Rails application from anonymous and prying." | ||
s.description = "Staging rack application purpose to protect you Rails application from anonymous and prying." | ||
|
||
s.required_rubygems_version = ">= 1.3.6" | ||
s.rubyforge_project = "rack-staging" | ||
|
||
s.add_development_dependency "bundler", ">= 1.0.0.rc.5" | ||
|
||
s.files = Dir.glob("{lib}/**/*") + %w[LICENSE] | ||
s.require_path = 'lib' | ||
end |
This file was deleted.
Oops, something went wrong.