Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial version

  • Loading branch information...
commit 3fb0a65f31a24f22cad9ae0d4041d075ab1fb41f 0 parents
@samuelkadolph authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
3  Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (C) 2011 by Samuel Kadolph
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
23 README.md
@@ -0,0 +1,23 @@
+# s3cmd
+
+## Installing
+
+### Recommended
+
+```
+gem install s3cmd
+```
+
+### Edge
+
+```
+git clone https://github.com/samuelkadolph/s3cmd
+cd s3cmd && rake install
+```
+
+## Usage
+
+```
+s3cmd create-bucket foo
+s3cmd put foo abc/def somefile
+```
1  Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
4 bin/s3cmd
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+
+require "s3cmd"
+S3Cmd::Main.start
71 lib/s3cmd.rb
@@ -0,0 +1,71 @@
+require "rubygems"
+require "aws"
+require "proxifier/env"
+require "thor"
+
+module S3Cmd
+ require "s3cmd/version"
+
+ class Main < Thor
+ desc "list-buckets", "lists all of your buckets"
+ def list_buckets
+ puts s3.buckets
+ end
+
+ desc "create-bucket name", "creates a bucket"
+ method_option :region, :default => "US"
+ def create_bucket(name)
+ bucket = s3.bucket(name, true)
+ end
+
+ desc "list-keys bucket", "list the keys of a bucket"
+ def list_keys(bucket)
+ puts s3.bucket(bucket).keys
+ end
+
+ desc "get bucket key", "get the file for the key from the bucket"
+ def get(bucket, key)
+ bucket = s3.bucket(bucket)
+ $stdout << bucket.get(key)
+ end
+
+ desc "put bucket key file", "puts a file for the key in the bucket"
+ def put(bucket, key, file)
+ bucket = s3.bucket(bucket)
+ File.open(file, "r") { |f| bucket.put(key, f) }
+ end
+
+ private
+ def s3
+ @s3 ||= begin
+ access_key, secret_key = nil, nil
+
+ if ENV["AWS_CREDENTIAL_FILE"]
+ File.open(ENV["AWS_CREDENTIAL_FILE"]) do |file|
+ file.lines.each do |line|
+ access_key = $1 if line =~ /^AWSAccessKeyId=(.*)$/
+ secret_key = $1 if line =~ /^AWSSecretKey=(.*)$/
+ end
+ end
+ elsif ENV["AWS_ACCESS_KEY"] || ENV["AWS_SECRET_KEY"]
+ access_key = ENV["AWS_ACCESS_KEY"]
+ secret_key = ENV["AWS_SECRET_KEY"]
+ end
+
+ unless access_key
+ $stderr.puts "AWS_CREDENTIAL_FILE must containt AWSAccessKeyId or AWS_ACCESS_KEY must be set"
+ exit 1
+ end
+ unless secret_key
+ $stderr.puts "AWS_CREDENTIAL_FILE must containt AWSSecretKey or AWS_SECRET_KEY must be set"
+ exit 1
+ end
+
+ logger = Logger.new(STDERR)
+ logger.level = Logger::FATAL
+
+ Aws::S3.new(access_key, secret_key, :logger => logger)
+ end
+ end
+ end
+end
3  lib/s3cmd/version.rb
@@ -0,0 +1,3 @@
+module S3Cmd
+ VERSION = "1.0.0"
+end
24 s3cmd.gemspec
@@ -0,0 +1,24 @@
+$:.push File.expand_path("../lib", __FILE__)
+require "s3cmd/version"
+
+Gem::Specification.new do |s|
+ s.name = "s3cmd"
+ s.version = S3Cmd::VERSION
+ s.authors = ["Samuel Kadolph"]
+ s.email = ["samuel@kadolph.com"]
+ s.homepage = "https://github.com/samuelkadolph/s3cmd"
+ s.summary = %q{Simple cli tool for interacting with S3.}
+ s.description = <<-DESC
+Provides a s3cmd binary that allows you to create and list buckets as well as list the keys of a bucket and get and upload files
+to s3.
+DESC
+
+ s.required_ruby_version = ">= 1.8.7"
+
+ s.files = Dir["bin/*", "lib/**/*"] + ["LICENSE", "README.md"]
+ s.executables = ["s3cmd"]
+
+ s.add_dependency "aws", "~> 2.5.6"
+ s.add_dependency "proxifier"
+ s.add_dependency "thor", "~> 0.14.6"
+end
Please sign in to comment.
Something went wrong with that request. Please try again.