cloudfiles_cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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 ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cloudfiles_cli.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jacob Atzen
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 ADDED
@@ -0,0 +1,34 @@
1
+ # CloudfilesCli
2
+
3
+ A small utility for interacting with files stored on Rackspace Cloudfiles
4
+
5
+ ## Installation
6
+
7
+ Install it:
8
+
9
+ $ gem install cloudfiles_cli
10
+
11
+ ## Usage
12
+
13
+ Basic usage:
14
+
15
+ $ cloudfiles_cli help
16
+
17
+ Either pass in credentials on the command line:
18
+
19
+ $ cloudfiles_cli upload --username=john --api-key=something --auth-url=https://lon.identity.api.rackspacecloud.com/v2.0 my_dir some_file.txt remote_filename.txt
20
+
21
+ Or use environment variables:
22
+
23
+ $ export CLOUDFILES_USERNAME=john
24
+ $ export CLOUDFILES_API_KEY=something
25
+ $ export CLOUDFILES_AUTH_URL=https://lon.identity.api.rackspacecloud.com/v2.0
26
+ $ cloudfiles_cli upload my_dir some_file.txt remote_filename.txt
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
4
+
5
+ require "cloudfiles_cli"
6
+
7
+ # Start the CLI
8
+ CloudfilesCli::Cli.start(ARGV)
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/cloudfiles_cli/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jacob Atzen"]
6
+ gem.email = ["jacob@incremental.dk"]
7
+ gem.description = %q{Simple utility for uploading and downloading files from Cloudfiles}
8
+ gem.summary = %q{Easily upload and download files from Cloudfiles}
9
+ gem.homepage = "https://github.com/lokalebasen/cloudfiles_cli"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "cloudfiles_cli"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = CloudfilesCli::VERSION
17
+ gem.add_dependency "thor"
18
+ gem.add_dependency "fog"
19
+ gem.executables << 'cloudfiles_cli'
20
+ end
@@ -0,0 +1,19 @@
1
+ module CloudfilesCli
2
+ class Cli < Thor
3
+ desc "download CONTAINER REMOTE_FILENAME [LOCAL_FILENAME]", "Download a file"
4
+ option :username
5
+ option :api_key
6
+ option :auth_url
7
+ def download(container, remote_filename, local_filename=nil)
8
+ Transactions.new(Config.new(options)).download(container, remote_filename, local_filename || File.basename(remote_filename))
9
+ end
10
+
11
+ desc "upload CONTAINER LOCAL_FILENAME [REMOTE_FILENAME]", "Upload a file"
12
+ option :username
13
+ option :api_key
14
+ option :auth_url
15
+ def upload(container, local_filename, remote_filename=nil)
16
+ Transactions.new(Config.new(options)).upload(container, local_filename, remote_filename || File.basename(local_filename))
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ module CloudfilesCli
2
+ class Config
3
+ attr_reader :options
4
+ def initialize(options)
5
+ @options = options
6
+ end
7
+
8
+ def username
9
+ options[:username] || ENV['CLOUDFILES_USERNAME'] || raise("No username provided")
10
+ end
11
+
12
+ def api_key
13
+ options[:api_key] || ENV['CLOUDFILES_API_KEY'] || raise("No api key provided")
14
+ end
15
+
16
+ def auth_url
17
+ options[:auth_url] || ENV['CLOUDFILES_AUTH_URL'] || raise("No auth url provided")
18
+ end
19
+
20
+ def hash
21
+ {
22
+ :rackspace_username => username,
23
+ :rackspace_api_key => api_key,
24
+ :rackspace_auth_url => auth_url
25
+ }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module CloudfilesCli
2
+ class Transactions
3
+ attr_reader :config
4
+
5
+ def initialize(config)
6
+ @config = config
7
+ end
8
+
9
+ def connection
10
+ @cf ||= Fog::Storage.new(config.hash.merge(:provider => 'Rackspace'))
11
+ end
12
+
13
+ def upload(container_name, localfile, remotefile)
14
+ container = connection.directories.get(container_name)
15
+ object = container.files.create(
16
+ :key => remotefile, :body => File.open(localfile)
17
+ )
18
+ end
19
+
20
+ def download(container_name, remotefile, localfile)
21
+ container = connection.directories.get(container_name)
22
+ object = container.files.get(remotefile)
23
+ IO.binwrite(localfile, object.body)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module CloudfilesCli
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "thor"
3
+ require "date"
4
+ require 'fog'
5
+ require "cloudfiles_cli/version"
6
+ require "cloudfiles_cli/cli"
7
+ require "cloudfiles_cli/config"
8
+ require "cloudfiles_cli/transactions"
9
+
10
+ module CloudfilesCli
11
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cloudfiles_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jacob Atzen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Simple utility for uploading and downloading files from Cloudfiles
47
+ email:
48
+ - jacob@incremental.dk
49
+ executables:
50
+ - cloudfiles_cli
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - bin/cloudfiles_cli
60
+ - cloudfiles_cli.gemspec
61
+ - lib/cloudfiles_cli.rb
62
+ - lib/cloudfiles_cli/cli.rb
63
+ - lib/cloudfiles_cli/config.rb
64
+ - lib/cloudfiles_cli/transactions.rb
65
+ - lib/cloudfiles_cli/version.rb
66
+ homepage: https://github.com/lokalebasen/cloudfiles_cli
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Easily upload and download files from Cloudfiles
90
+ test_files: []