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

Commit

Permalink
support for uploading and removing files from s3
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbunsch committed Sep 23, 2009
1 parent 112a548 commit d6e34c9
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/actions/groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@

get '/:project/group/:group_name/delete' do
@ec2.delete_security_group(params[:group_name])
redirect '/groups'
redirect "/#{@project}/groups"
end

get '/:project/group/:group_name/revoke' do
if params[:group]
@ec2.revoke_security_group_named_ingress(params[:group_name], params[:owner], params[:group])
else
@ec2.revoke_security_group_IP_ingress(params[:group_name], params[:from], params[:to], params[:protocol], params[:ip])
@ec2.revoke_security_group_IP_ingress(params[:group_name], params[:from_port], params[:to_port], params[:protocol], params[:cidr_ips])
end
redirect '/groups'
redirect "/#{@project}/groups"
end

post '/:project/group/:group_name/authorize' do
@ec2.authorize_security_group_IP_ingress(params[:group_name], params[:from], params[:to], params[:protocol], params[:ip])
redirect '/groups'
redirect "/#{@project}/groups"
end

post '/:project/group' do
@ec2.create_security_group(params[:name], params[:description])
redirect '/groups'
redirect "/#{@project}/groups"
end
2 changes: 1 addition & 1 deletion lib/actions/keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

get '/:project/key/:key_name/delete' do
@ec2.delete_key_pair(params[:key_name])
redirect '/keys'
redirect "/#{@project}/keys"
end

post '/:project/key' do
Expand Down
20 changes: 19 additions & 1 deletion lib/actions/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,27 @@

get '/:project/bucket/:bucket_name/keys' do
@bucket = @s3.bucket(params[:bucket_name])
@keys = @bucket.keys.collect { |key|
@keys = @bucket.keys('max-keys' => 100).collect { |key|
{ :link => "http://#{params[:bucket_name]}.s3.amazonaws.com/#{key}",
:name => key.name }
}
erb :s3_keys
end

post '/:project/bucket/:bucket_name/upload' do
if params[:bucket] and params[:bucket][:upload]
filename = params[:bucket][:upload][:filename]
file_data = params[:bucket][:upload][:tempfile].read
@s3.bucket(params[:bucket_name]).put(filename, file_data)
end
redirect "/#{@project}/bucket/#{params[:bucket_name]}/keys"
end


get '/:project/bucket/:bucket_name/key/:key_name/delete' do
if params[:bucket_name] and params[:key_name]
bucket = @s3.bucket(params[:bucket_name] )
RightAws::S3::Key.new(bucket, params[:key_name]).delete
end
redirect "/#{@project}/bucket/#{params[:bucket_name]}/keys"
end
4 changes: 4 additions & 0 deletions lib/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ def table(collection, *columns)
html << "\n</table>"
end

def to_query(hash = {})
raise 'Not a hash' if hash.class != Hash
hash.keys.collect { |key| "#{key}=#{hash[key]}" }.join('&amp;')
end
end
4 changes: 2 additions & 2 deletions spec/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
it 'should render table with no columns' do
result = table(@collection)
result.include?('<tr><th>name</th><th>email</th><th>id</th></tr>').should == true
result.include?('<tr><td>Foo</td><td>[email protected]</td><td>11</td><tr>').should == true
result.include?('<tr class="alt"><td>Foo</td><td>[email protected]</td><td>11</td><tr>').should == true
end

it 'should render table with a block' do
result = table(@collection) { |item| 'copy' }
result.include?('<tr><th>name</th><th>email</th><th>id</th><th>options</th></tr>').should == true
result.include?('<tr><td>Foo</td><td>[email protected]</td><td>11</td><td>copy</td><tr>').should == true
result.include?('<tr class="alt"><td>Foo</td><td>[email protected]</td><td>11</td><td>copy</td><tr>').should == true
end

it 'should render table with columns and block' do
Expand Down
4 changes: 2 additions & 2 deletions views/groups.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
) %>
<br/><br/>

<%= table(group[:aws_perms]) %>
<%= table(group[:aws_perms]) { |perm| link_to('Revoke', "/#{@project}/group/#{group[:aws_group_name]}/revoke?#{to_query(perm)}")} %>



<%= link_to'+ Add new rule', '#', :onclick => "$('#add_rule_#{group[:aws_group_name]}').toggle()" %>

<div id="add_rule_<%= group[:aws_group_name] %>" class="add_rule">
<form action="/group/<%= group[:aws_group_name] %>/authorize" method="POST">
<form action="/<%= @project %>/group/<%= group[:aws_group_name] %>/authorize" method="POST">
<select name="protocol">
<option value="tcp">tcp</option>
<option value="udp">udp</option>
Expand Down
2 changes: 1 addition & 1 deletion views/keys.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

<%= table(@keys, :aws_key_name) { |key| link_to(
image_tag('minus.png', :alt => 'Delete Key Pair'),
"/key/#{key[:aws_key_name]}/delete", :onclick => "return confirm('Delete Key: Are you sure?')"
"/#{@project}/key/#{key[:aws_key_name]}/delete", :onclick => "return confirm('Delete Key: Are you sure?')"
)} %>
7 changes: 6 additions & 1 deletion views/s3_keys.erb
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
<%= table(@keys) { |key| link_to('link', key[:link]) } %>
<form enctype="multipart/form-data" action="/<%= @project %>/bucket/<%= params[:bucket_name] %>/upload" method="post">
File: <input type="file" name="bucket[upload]" value="" />

<input type="submit" value="Upload">
</form>
<%= table(@keys) { |key| link_to('link', key[:link]) + ' ' + link_to('delete', "/#{@project}/bucket/#{params[:bucket_name]}/key/#{key[:name]}/delete") } %>

0 comments on commit d6e34c9

Please sign in to comment.