staging 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/README.textile +37 -0
- data/Rakefile +56 -0
- data/lib/staging.rb +56 -0
- metadata +59 -0
data/.document
ADDED
data/.gitignore
ADDED
data/README.textile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
h1. Staging Gem
|
2
|
+
|
3
|
+
Staging rack application purpose to protect you Rails application from anonymous and prying.
|
4
|
+
|
5
|
+
h1. Usage
|
6
|
+
|
7
|
+
h2. Examples
|
8
|
+
|
9
|
+
h3. In you Rails initilizer
|
10
|
+
|
11
|
+
<pre><code>config.middleware.use 'Rack::Staging',
|
12
|
+
:template_path => "#{RAILS_ROOT}/app/views/staging/index.html",
|
13
|
+
:auth_codes => [ 'Hfgo_JHg+47', 'dh_JHg_ra988', 'fd-m*nKJ_DE7'] # Basic setup</code></pre>
|
14
|
+
|
15
|
+
<pre><code>config.middleware.use 'Staging',
|
16
|
+
:session_key => :staging_auth, # Custom session key
|
17
|
+
:code_param => :staging_code", # Custom input name (<input name="staging_code" />), defult is :code
|
18
|
+
:template_path => "#{RAILS_ROOT}/app/views/staging/index.html",
|
19
|
+
:auth_codes => [ 'Hfgo_JHg+47', 'dh_JHg_ra988', 'fd-m*nKJ_DE7']</code></pre>
|
20
|
+
|
21
|
+
h3. In you staging template (“#{RAILS_ROOT}/app/views/staging/index.html”)
|
22
|
+
|
23
|
+
<pre><code><html>
|
24
|
+
<head>
|
25
|
+
<title>Staging application</title>
|
26
|
+
</head>
|
27
|
+
<body>
|
28
|
+
<h1>Please input staging code</h1>
|
29
|
+
<form action="/" method="post">
|
30
|
+
<input name="code" />
|
31
|
+
<input type="submit" />
|
32
|
+
</form>
|
33
|
+
</body>
|
34
|
+
</html></code></pre>
|
35
|
+
|
36
|
+
h3. … and now you are ready to protected staging!
|
37
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "staging"
|
8
|
+
gem.summary = %Q{Protect you Rails application from anonymous and prying.}
|
9
|
+
gem.description = %Q{Staging rack application purpose to protect you Rails application from anonymous and prying.}
|
10
|
+
gem.email = "kossnocorp@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/kossnocorp/staging"
|
12
|
+
gem.authors = ["Aleksandr Koss"]
|
13
|
+
gem.version = '0.1'
|
14
|
+
|
15
|
+
#gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "staging #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
56
|
+
|
data/lib/staging.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Hi! I'am rack middleware!
|
2
|
+
# I was born for protect you staging application from anonymous and prying
|
3
|
+
|
4
|
+
# My author's name was Aleksandr Koss. Mail him at kossnocorp@gmail.com
|
5
|
+
# Nice to MIT you!
|
6
|
+
|
7
|
+
module Rack
|
8
|
+
class Staging
|
9
|
+
def initialize app, options = {}
|
10
|
+
@app = app
|
11
|
+
@options = {
|
12
|
+
:session_key => :staging_auth,
|
13
|
+
:code_param => :code
|
14
|
+
}.merge options
|
15
|
+
end
|
16
|
+
|
17
|
+
def call env
|
18
|
+
request = Rack::Request.new env
|
19
|
+
|
20
|
+
# Check code in session and return Rails call if is valid
|
21
|
+
|
22
|
+
return @app.call env if \
|
23
|
+
request.session[@options[:session_key]] != nil and
|
24
|
+
request.session[@options[:session_key]] != '' and
|
25
|
+
code_valid? request.session[@options[:session_key]]
|
26
|
+
|
27
|
+
# If post method check :code_param value
|
28
|
+
|
29
|
+
if request.post? and code_valid? request.params[@options[:code_param].to_s]
|
30
|
+
request.session[@options[:session_key]] =
|
31
|
+
request.params[@options[:code_param].to_s]
|
32
|
+
|
33
|
+
[301, {'Location' => '/'}, ''] # Redirect if code is valid
|
34
|
+
else
|
35
|
+
render_staging
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# Render staging html file
|
42
|
+
|
43
|
+
def render_staging
|
44
|
+
[200, {'Content-Type' => 'text/html'}, [
|
45
|
+
::File.open(@options[:template_path], 'rb').read
|
46
|
+
]]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Validate code
|
50
|
+
|
51
|
+
def code_valid? code
|
52
|
+
@options[:auth_codes].include? code
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: staging
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.1"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aleksandr Koss
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-22 00:00:00 +06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Staging rack application purpose to protect you Rails application from anonymous and prying.
|
17
|
+
email: kossnocorp@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.textile
|
24
|
+
files:
|
25
|
+
- .document
|
26
|
+
- .gitignore
|
27
|
+
- README.textile
|
28
|
+
- Rakefile
|
29
|
+
- lib/staging.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/kossnocorp/staging
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Protect you Rails application from anonymous and prying.
|
58
|
+
test_files: []
|
59
|
+
|