diff --git a/lib/actions/images.rb b/lib/actions/images.rb index 46b5683..a53568c 100644 --- a/lib/actions/images.rb +++ b/lib/actions/images.rb @@ -1,7 +1,9 @@ # Images get '/:project/images' do - @@images ||= @ec2.describe_images.find_all{|x| x[:aws_image_type] == 'machine'} + @@images ||= @ec2.describe_images_by_owner('self') + # @@images ||= @ec2.describe_images_by_executable_by('self') + # @@images ||= @ec2.describe_images.find_all{|x| x[:aws_image_type] == 'machine'} @i386 = @@images.find_all{|x| x[:aws_architecture] == 'i386'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] } @x86_64 = @@images.find_all{|x| x[:aws_architecture] == 'x86_64'}.sort {|x,y| x[:aws_location] <=> y[:aws_location] } erb :images diff --git a/lib/actions/s3.rb b/lib/actions/s3.rb index 97a4c7c..6ab0a8d 100644 --- a/lib/actions/s3.rb +++ b/lib/actions/s3.rb @@ -1,5 +1,4 @@ # S3 - get '/:project/buckets' do @buckets = @s3.buckets.map{|b| { :name => b.name, :location => (b.location != '' ? b.location : 'US') } } erb :buckets @@ -21,13 +20,9 @@ get '/:project/bucket/:bucket_name/keys' do @bucket = @s3.bucket(params[:bucket_name]) - @keys = @bucket.keys + @keys = @bucket.keys.collect { |key| + { :link => "http://#{params[:bucket_name]}.s3.amazonaws.com/#{key}", + :name => key.name } + } erb :s3_keys -end - -get '/:project/bucket/*/key/*' do - bucket_name = request.path_info.split('/')[2] - key_name = request.path_info.split('/')[4] - @bucket = @s3.bucket(bucket_name) - send_data(@bucket.get(key_name)) end \ No newline at end of file diff --git a/lib/helpers.rb b/lib/helpers.rb index c074a99..c75ca7d 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -37,7 +37,8 @@ def time_ago_or_time_stamp(from_time, to_time = Time.now, include_seconds = true end def table(collection, *columns) - raise 'Collection element is not a hash' if collection.first.class != Hash + return '' if collection.size == 0 + raise 'Collection element is not a Hash' if collection.first.class != Hash if columns == [] # auto load a list of keys first = collection.first diff --git a/public/style.css b/public/style.css index af84c8d..11027ec 100644 --- a/public/style.css +++ b/public/style.css @@ -70,4 +70,9 @@ table.list th { background-color: #D3EDEE; color: #4F6B83; font-size: 0.7em; pad table.list th.short { width: 130px; } table.list td { background-color: #fff; text-align: left; font-size:0.9em; padding: 5px; vertical-align: top;} table.list td.options { width: 200px; } -table.list tr.alt td { background-color: #F5FAFA; } \ No newline at end of file +table.list tr.alt td { background-color: #F5FAFA; } + +form { margin-bottom: 10px; padding: 5px; background-color: #eee;} +form select, +form input { border:1px solid #999; } +form input { padding: 1px; font-size: 0.9em; position: relative; top: -1px;} \ No newline at end of file diff --git a/snail.rb b/snail.rb index 6c85b1e..a0b68b8 100755 --- a/snail.rb +++ b/snail.rb @@ -1,5 +1,10 @@ #!/usr/bin/env ruby +# first, check required files so any user gets instant notification that something is wrong +CONFIG_FILE = "config/snail.yml" +def abort(msg); puts msg; exit(1); end +abort('Could not find config/snail.yml file.') if !File.exists?(CONFIG_FILE) + require 'rubygems' # make sure we're using the right version of gems gem 'sinatra', :version => '0.9.4' @@ -15,7 +20,7 @@ Dir["lib/actions/*.rb"].each { |x| load x } # set s3_config -config_file = YAML.load_file("config/snail.yml") +config_file = YAML.load_file(CONFIG_FILE) set :config, config_file set :projects, config_file.keys @@ -27,7 +32,7 @@ @ec2 = RightAws::Ec2.new(config['aws_key'], config['aws_secret']) @s3 = RightAws::S3.new(config['aws_key'], config['aws_secret']) else - redirect '/projects' if first != 'projects' and !File.exists?("public#{request.path}") + redirect '/projects' if first != 'projects' and !File.exists?("public#{request.path}") and !request.path.include?('__sinatra__') end end diff --git a/views/_layout_footer.erb b/views/_layout_footer.erb index 6f5a459..5a2c144 100644 --- a/views/_layout_footer.erb +++ b/views/_layout_footer.erb @@ -1 +1 @@ -snail (on github) \ No newline at end of file +snail (on github) \ No newline at end of file diff --git a/views/buckets.erb b/views/buckets.erb index 91ce461..8807cfe 100644 --- a/views/buckets.erb +++ b/views/buckets.erb @@ -1,12 +1,12 @@
<%= table(@buckets) do |bucket| result = link_to('view', "/#{@project}/bucket/#{bucket[:name]}/keys") - result << ' ' + link_to('delete', "/#{@project}/bucket/#{bucket[:name]}/delete") + result << ' | ' + link_to('destroy', "/#{@project}/bucket/#{bucket[:name]}/delete", :onclick => "return confirm('Are you sure you want to delete bucket #{bucket[:name]}?')") end %> diff --git a/views/groups.erb b/views/groups.erb index 17def69..dc8452c 100644 --- a/views/groups.erb +++ b/views/groups.erb @@ -17,22 +17,9 @@ ) %>You have no current instances.
-<%= link_to 'Choose an image', '/images' %> to launch a new instance.
+<%= link_to 'Choose an image', "/#{@project}/images" %> to launch a new instance.
<% end %> \ No newline at end of file diff --git a/views/keys.erb b/views/keys.erb index a0492ce..2ce2571 100644 --- a/views/keys.erb +++ b/views/keys.erb @@ -3,16 +3,13 @@<%= link_to image_tag('add.png', :alt => 'Create a new Key Pair'), '#',:onclick => "$('#add_key').toggle()" %> Create a new SSH Key Pair
<%= key.name %> | <%= link_to('link', key.public_link) %> <%= link_to 'download', "/#{@project}/bucket/#{@bucket.name}/key/#{key.name}" %> |