sploder 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,59 @@
1
+ require 'aws-sdk'
2
+
3
+ module Sploder
4
+ class Bucket
5
+ def create (name, key, secret)
6
+ s3 = AWS::S3.new(
7
+ :access_key_id => key,
8
+ :secret_access_key => secret)
9
+ s3.buckets.create(name)
10
+ puts "Bucket #{name} created"
11
+ end
12
+
13
+ def delete (bucket_name, key, secret)
14
+ s3 = AWS::S3.new(
15
+ :access_key_id => key,
16
+ :secret_access_key => secret)
17
+ bucket = s3.buckets[bucket_name]
18
+ bucket.delete!
19
+ puts "The bucket, #{bucket_name}, was deleted. Permanently."
20
+ end
21
+
22
+ # The following methods do nothing. They will in the future.
23
+ def host_website (bucket_name, index, error, key, secret)
24
+ s3 = AWS::S3.new(
25
+ :access_key_id => key,
26
+ :secret_access_key => secret)
27
+
28
+ # Get the bucket
29
+ bucket = s3.buckets[bucket_name]
30
+
31
+ # Set default index and error documents
32
+ unless index
33
+ index = "index.html"
34
+ end
35
+
36
+ unless error
37
+ error = "error.html"
38
+ end
39
+
40
+ bucket.configure_website do |cfg|
41
+ cfg.index_document_suffix = index
42
+ cfg.error_document_key = error
43
+ end
44
+
45
+ puts "All set! #{bucket_name} is now configured as a web host"
46
+ end
47
+
48
+ def end_hosting (bucket_name, key, secret)
49
+ s3 = AWS::S3.new(
50
+ :access_key_id => key,
51
+ :secret_access_key => secret)
52
+
53
+ # Get bucket
54
+ bucket = s3.buckets[bucket_name]
55
+ bucket.remove_website_configuration
56
+ puts "Web hosting has been disabled for #{bucket_name}"
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,37 @@
1
+ require 'aws-sdk'
2
+
3
+ module Sploder
4
+ class List
5
+ def default (key, secret)
6
+ s3 = AWS::S3.new(
7
+ :access_key_id => key,
8
+ :secret_access_key => secret)
9
+ s3.buckets.each do |bucket|
10
+ puts bucket.name
11
+ end
12
+ end
13
+
14
+ def list_bucket_contents (bucket_name, prefix, key, secret)
15
+ s3 = AWS::S3.new(
16
+ :access_key_id => key,
17
+ :secret_access_key => secret)
18
+
19
+ # Access the specified bucket
20
+ bucket = s3.buckets[bucket_name]
21
+
22
+ if prefix.nil?
23
+ bucket.objects.each do |obj|
24
+ puts obj.key
25
+ end
26
+ exit 0
27
+ end
28
+ files = bucket.objects.with_prefix(prefix).collect(&:key)
29
+ files.each do |obj|
30
+ puts obj
31
+ end
32
+
33
+ #tree = s3.objects.with_prefix( prefix ).as_tree
34
+ #directories = tree.children.select(&:branch?).collect(&:prefix)
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'yaml'
2
+
3
+ module Sploder
4
+ class Setup
5
+ def run (key, secret)
6
+ puts "Setup class loaded?"
7
+ file = File.expand_path('.sploder', '~')
8
+ File.open(file, 'w') do |f|
9
+ f.puts "key: #{key}\nsecret: #{secret}"
10
+ end
11
+ puts "Settings saved"
12
+ end
13
+
14
+ def load_settings
15
+ settings_file = File.expand_path('.sploder', '~')
16
+ settings = YAML.load_file(settings_file)
17
+ return settings
18
+ end
19
+
20
+ def settings_exist
21
+ file = File.expand_path('.sploder', '~')
22
+ unless File.exist?(file)
23
+ puts "Please run 'sploder --setup' before using Sploder"
24
+ exit 1
25
+ end
26
+ return true
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+ require 'aws-sdk'
3
+
4
+ module Sploder
5
+ class Upload
6
+ def run (bucket, file, path, acl, key, secret)
7
+ unless bucket && file
8
+ puts "Usage: sploder <BUCKET_NAME> <FILE_NAME> | Optional: <S3_PATH> <ACL_POLICY>"
9
+ exit 1
10
+ end
11
+
12
+ unless acl
13
+ acl = "public_read"
14
+ end
15
+
16
+ unless path
17
+ path = ''
18
+ end
19
+
20
+ s3 = AWS::S3.new(
21
+ :access_key_id => key,
22
+ :secret_access_key => secret)
23
+
24
+ bucket = s3.buckets[bucket]
25
+ basename = File.basename(file)
26
+ upload = bucket.objects["#{path}#{basename}"]
27
+ upload.write(:file => file, :acl => acl)
28
+ puts "Uploaded #{file} to: "
29
+ puts upload.public_url
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Sploder
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sploder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -67,15 +67,13 @@ executables:
67
67
  extensions: []
68
68
  extra_rdoc_files: []
69
69
  files:
70
- - .gitignore
71
- - Gemfile
72
- - LICENSE.txt
73
- - README.md
74
- - Rakefile
75
- - lib/sploder.rb
76
- - lib/sploder/version.rb
77
- - sploder.gemspec
78
70
  - bin/sploder
71
+ - lib/sploder/bucket.rb
72
+ - lib/sploder/list.rb
73
+ - lib/sploder/setup.rb
74
+ - lib/sploder/upload.rb
75
+ - lib/sploder/version.rb
76
+ - lib/sploder.rb
79
77
  homepage: http://sploder.cleverlabs.info
80
78
  licenses: []
81
79
  post_install_message:
@@ -96,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
94
  version: '0'
97
95
  requirements: []
98
96
  rubyforge_project:
99
- rubygems_version: 1.8.25
97
+ rubygems_version: 1.8.24
100
98
  signing_key:
101
99
  specification_version: 3
102
100
  summary: Easily upload files to S3, create buckets, set ACL, and more
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sploder.gemspec
4
- gemspec
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Bill Patrianakos
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,110 +0,0 @@
1
- # Sploder
2
-
3
- Sploder is the S3 uploader. It is meant to help you perform a handful of common operations with S3 quickly, without ever having to leave the command line.
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'sploder'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install sploder
18
-
19
- Or manually with
20
-
21
- $ git clone https://github.com/billpatrianakos/sploder.git
22
- $ cd sploder/sploder
23
- $ gem build sploder.gemspec
24
- $ gem install sploder-0.X.X.gem # Please change to the version of Sploder you've downloaded - 0.3.3 as of this writing
25
-
26
- ## Usage
27
-
28
- The [official documentation is here](http://sploder.cleverlabs.info) and explains the usage more in depth.
29
-
30
- ### Setup & connect to S3
31
-
32
- Before Sploder will do anything you need to give it access to your S3 account. This is really simple. Just run `sploder --setup` and Sploder will walk you through the rest. You'll need your AWS access key ID and secret key to use Sploder. The prompts look like this:
33
-
34
- ![Sploder setup wizard](https://webassets.s3.amazonaws.com/blog_posts/setup.gif "Sploder setup wizard in action")
35
-
36
- Sploder saves your information in a hidden file called `.sploder` in your home (~/) directory whether you're on Windows, Linux, or Mac. If your AWS credentials ever change just run `--setup` again to give Sploder the new ones. Don't want Sploder to know your S3 credentials? Just delete the config file (`sudo rm ~/.sploder` - Sploder can't connect to S3 without this file though).
37
-
38
- ### Upload a file
39
-
40
- Uploads are what Sploder was made for. In particular, it shines when it comes to being able to quickly share files from the command line. Give Sploder a bucket name and file and Sploder will upload it and return the URL where it can be accessed for easy sharing. If you don't want your files to have public-read permissions just change the ACL policy as explained below.
41
-
42
- The `--upload` or `-u` flag take a maximum of 4 arguments. 2 are required and 2 are optional. 2 have flags and 2 don't. Here's an example using all options:
43
-
44
- ```
45
- sploder --upload mybucket path/to/myfile.ext -p testing/somefolder -a private
46
- ```
47
-
48
- The first two arguments after the `--upload` flag are the name of your bucket and the path to the file you want to upload. They are required and must come in that order.
49
-
50
- `-p`, also known as `--path` is the path *within your S3 bucket* you want your file uploaded to. So if you uploaded a photo and wanted it to go into `yourbucketurl/2013/photos/` then you'd use the `-p` flag and write `2013/photos/`. The path argument is optional. If you do use it, remember that __your path must not have a leading slash and must have a trailing slash__. Sploder will accept paths with a leading slash and no trailing slash because S3 allows them but you'll end up with some weird final paths like `https://mybucket.amazonaws.com//foldermyfile.ext`. And it'll work! But it's not good for organization.
51
-
52
- `-a` or `--acl` is the ACL policy you want to give the file you're uploading. This flag is optional and defaults to *public_read*. Sploder accepts the following ACL policies:
53
-
54
- * __public_read__ (Default, no need to specify an ACL if you want this)
55
-
56
- * __private__ - Only you can access the file
57
-
58
- * __public_read_write__ - This is dumb. Don't do this unless you know what you're doing. The whole world can read and write to your file.
59
-
60
- * __authenticated_read__ - Only logged in users can read the file? See the AWS docs to know for sure.
61
-
62
- ### Listing avilable buckets
63
-
64
- `--list` or `-l` will return a list of your S3 buckets. Simple as that. No other flags or options here. Just a simple `sploder --list` or `sploder -l` will do the trick.
65
-
66
- ### Create a new bucket
67
-
68
- `--create` or `-c` creates a new bucket within your account. If the bucket name is not available an error will be returned. The `--create` flag takes one other flag, the `--name or -n` flag. Usage is as follows:
69
-
70
- ```
71
- sploder --create -n my-new-s3-bucket
72
- ```
73
-
74
- If all went well Sploder will let you know the bucket has been created.
75
-
76
- ![Creating a bucket](http://sploder.cleverlabs.info/img/design/create.png "Creating a new bucket")
77
-
78
- If you want to confirm your bucket has been created (I'm not sure why you wouldn't just trust Sploder) you can run `sploder --list` right after `--create` has finished.
79
-
80
- ### Deleting buckets
81
-
82
- `--delete` or `-d` will delete a bucket along with everything in it. Because deleting a bucket is irreversible and deletes everything within it, I made it so that fat-fingering `-d` won't automatically destroy all your precious files and instead you'll have to confirm deletion. Running `sploder --delete` will start a prompt that will first ask you for the name of the bucket and then ask you to confirm that you're sure you really want to delete the bucket along with everything in it. Below is a screenshot of all 3 steps (running `-d`, typing in the bucket name, and confirming) after they've been completed:
83
-
84
- ![Sploder delete prompts](http://sploder.cleverlabs.info/img/design/delete.png "Sploder slows you down when deleting a bucket to reduce the chances of accidental deletion")
85
-
86
- ### Exploring bucket contents
87
-
88
- `--explore` or `-e` invokes the bucket explorer feature. This feature is under heavy development and doesn't work. But I'm still shipping it because I know you're all smart enough to add on to the Sploder::Bucket class methods for exploring buckets to make it work. This is a feature that I want a lot so you can be sure I'll be adding this feature soon.
89
-
90
- ## Support
91
-
92
- You can get support from these sources (in order of importance)
93
-
94
- * The [official Sploder site](http://sploder.cleverlabs.info) has complete documentation for usage and is *the place* for all future updates, docs, release info, and everything else.
95
-
96
- * You can run `sploder` to get help from the command line. Using `sploder --help` or `sploder -h` will give you more information too.
97
-
98
- * The [wiki](https://github.com/billpatrianakos/sploder/wiki) will document basic usage. It's basically the same as this readme.
99
-
100
- ## Roadmap
101
-
102
- The 1.0 release will contain the same features that the current 0.3.3 version contains plus full support for listing the contents of buckets and paths within buckets through the `--explore` command. I believe that a good tool serves its purpose then gets out of the way. Because of this, I don't plan to add any more features to Sploder after `--explore` is implemented and instead focus on improving the existing codebase. If you have a feature request and it's a good idea that fits with the philosophy of Sploder I'd be happy to implement it but right now I can't think of anything else you could want from a tool like this.
103
-
104
- ## Contributing
105
-
106
- 1. Fork it
107
- 2. Create your feature branch (`git checkout -b my-new-feature`)
108
- 3. Commit your changes (`git commit -am 'Add some feature'`)
109
- 4. Push to the branch (`git push origin my-new-feature`)
110
- 5. Create new Pull Request
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,24 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'sploder/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "sploder"
8
- gem.version = Sploder::VERSION
9
- gem.authors = ["Bill Patrianakos"]
10
- gem.email = ["bill@billpatrianakos.me"]
11
- gem.description = 'Sploder is the S3 uploader'
12
- gem.summary = 'Easily upload files to S3, create buckets, set ACL, and more'
13
- gem.homepage = "http://sploder.cleverlabs.info"
14
-
15
- gem.files = `git ls-files`.split($/)
16
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
- gem.require_paths = ["lib"]
18
-
19
- gem.add_dependency "trollop"
20
- gem.add_dependency "aws-sdk"
21
- gem.add_dependency "highline"
22
- gem.executables << 'sploder'
23
- #gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
24
- end