Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
forces you into a setup if no config provided
Browse files Browse the repository at this point in the history
  • Loading branch information
moomerman committed Oct 28, 2008
1 parent f2ba3ed commit 045335a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body {
#instances .odd {background-color:#A6CDDE;}

#images .image {margin-bottom:10px;}
#images .odd {background-color:#A6CDDE;}
#images .odd {background-color:#E7EFF4;}

.add_rule {display:none; margin:5px; padding:5px;}
#add_key {display:none;}
Expand Down
40 changes: 28 additions & 12 deletions snail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,43 @@
Dir["lib/*.rb"].each { |x| load x }

configure do
begin
config = YAML.load_file("snail.yml")
rescue
end
if config
AWS_KEY = config['aws_key']
AWS_SECRET = config['aws_secret']
@@ec2 = RightAws::Ec2.new(AWS_KEY, AWS_SECRET)
@@s3 = RightAws::S3.new(AWS_KEY, AWS_SECRET)
end
set_option :sessions, true
@@session_keys = {}
@@config = YAML.load_file("snail.yml") rescue nil || false
end

before do
@ec2 = @@ec2
@s3 = @@s3
if session[:key] and @@session_keys[session[:key]]
@ec2 = @@session_keys[session[:key]][:ec2]
@s3 = @@session_keys[session[:key]][:s3]
elsif @@config
@@session_keys[@@config['aws_key']] ||= {
:ec2 => RightAws::Ec2.new(@@config['aws_key'], @@config['aws_secret']),
:s3 => RightAws::S3.new(@@config['aws_key'], @@config['aws_secret'])
}
session[:key] = @@config['aws_key']
else
redirect '/setup' unless request.path_info =~ /\/setup/ or request.path_info =~ /.css/
end
end

helpers do
include Helpers
end

get '/setup' do
erb :setup
end

post '/setup' do
@@session_keys[params[:key]] = {
:ec2 => RightAws::Ec2.new(params[:key], params[:secret]),
:s3 => RightAws::S3.new(params[:key], params[:secret])
}
session[:key] = params[:key]
redirect '/instances'
end

get '/' do
redirect '/instances'
end
Expand Down
10 changes: 10 additions & 0 deletions views/setup.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div id="setup" class="lightbox" style="display:block">
<h2>Snail Setup</h2>
<p>Enter your amazon web service keys for this session. Your keys will not be stored anywhere.</p>
<form action="/setup" method="POST">
<p>Amazon Key: <input type="text" name="key" /></p>
<p>Secret Key: <input type="text" name="secret" /></p>
<p><input type="submit" value="setup"/></p>
</form>
</div>
<div id="overlay" class="lightbox_overlay" style="display:block" />

0 comments on commit 045335a

Please sign in to comment.