woro-s3 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f913887e7be5f55be50df0847fddd1d4247111e
4
+ data.tar.gz: f335886bd09526a91cff2a8d915efdf7f60c3aaa
5
+ SHA512:
6
+ metadata.gz: b24eea8c99ae7038d9a6ca592b4b86c530acbd39602df48d142ee57378886f6562533efa39148210095ceb55d79dfb5238e3bbb75b15bb240856a6ff6929334f
7
+ data.tar.gz: 5d64bc9fda30b966c1fe95fc79e6626b90e586d530d901358e0a714c46526b4a16d874a6c2ee2da2818e586bb6e5f7eb523df28e1cf56583cd5083e7cafb2d73
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in woro-s3.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem "rspec"
8
+ gem "rspec-nc"
9
+ gem 'fakefs'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ woro-s3 (0.0.1)
5
+ aws-sdk-v1
6
+ woro
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ aws-sdk-v1 (1.64.0)
12
+ json (~> 1.4)
13
+ nokogiri (>= 1.4.4)
14
+ commander (4.3.3)
15
+ highline (~> 1.7.2)
16
+ diff-lcs (1.2.5)
17
+ fakefs (0.6.7)
18
+ highline (1.7.2)
19
+ json (1.8.3)
20
+ mini_portile (0.6.2)
21
+ nokogiri (1.6.6.2)
22
+ mini_portile (~> 0.6.0)
23
+ rake (10.4.2)
24
+ rspec (3.3.0)
25
+ rspec-core (~> 3.3.0)
26
+ rspec-expectations (~> 3.3.0)
27
+ rspec-mocks (~> 3.3.0)
28
+ rspec-core (3.3.1)
29
+ rspec-support (~> 3.3.0)
30
+ rspec-expectations (3.3.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.3.0)
33
+ rspec-mocks (3.3.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.3.0)
36
+ rspec-nc (0.2.0)
37
+ rspec (>= 2.9)
38
+ terminal-notifier (>= 1.4)
39
+ rspec-support (3.3.0)
40
+ terminal-notifier (1.6.3)
41
+ woro (0.2.2)
42
+ commander
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.7)
49
+ fakefs
50
+ rake (~> 10.0)
51
+ rspec
52
+ rspec-nc
53
+ woro-s3!
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Daniel Senff
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # woro-s3
2
+
3
+ Gist-Adapter for Woro remote task management
4
+
5
+ Using Amazons's S3 to share them with colleagues.
6
+
7
+ ## Woro adapters
8
+
9
+ ## Usage
10
+
11
+
12
+ Once you are done writing the task and you want to execute it on the remote system.
13
+ First you have to push them online, in this case to Gist.
14
+
15
+ ```shell
16
+ $ woro push s3:cleanup_users
17
+ ```
18
+
19
+ _Attention, depending on whether you set up a Gist/Github login on
20
+ initialization. These tasks are online anonymous, but public, or
21
+ private under the specified Github account._
22
+
23
+ Now, to run a task remotely using Mina, specify the task:
24
+
25
+ ```shell
26
+ $ mina woro:run task=s3:cleanup_users
27
+ ```
28
+
29
+ Or to run it with Capistrano:
30
+
31
+ ```shell
32
+ $ cap woro:run task=s3:cleanup_users
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/woro-s3.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'woro'
2
+ require "woro-s3/version"
3
+ require 'woro/adapters/s3'
@@ -0,0 +1,5 @@
1
+ module Woro
2
+ module S3
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,117 @@
1
+ require 'aws-sdk-v1'
2
+
3
+ module Woro
4
+ module Adapters
5
+ # Adapter for managing remote task collection on AWS S3
6
+ class S3 < Base
7
+ # serialized configuration for AWS S3 access
8
+ attr_reader :s3_client, :bucket_name, :path
9
+
10
+ # Setup configuration for adapter
11
+ # Highline CLI helpers can be used for interactivity.
12
+ # @return [Hash] Configuration options
13
+ def self.setup
14
+ {
15
+ 'access_key_id' => ask('Access key id: '),
16
+ 'secret_access_key' => ask('Secret access key: '),
17
+ 'region' => ask('Region: ') { |q| q.default = 'eu-west-1' },
18
+ 'bucket_name' => ask('Bucket name: '),
19
+ 'path' => ask('Path within Bucket: ') { |q| q.default = '/' },
20
+ }
21
+ end
22
+
23
+ def initialize(options)
24
+ options.reject! { |k, v| [:path].include? k }
25
+ ::AWS.config options
26
+ @s3_client = ::AWS::S3::Client.new options
27
+ @bucket_name = options['bucket_name']
28
+ @path = options['path']
29
+ end
30
+
31
+ # Returns the list of rake files included in the remote collection.
32
+ # @return [Array] List of files
33
+ def list_files
34
+ remote_files
35
+ end
36
+
37
+ # Returns the list of rake files included in the remote collection
38
+ # with their contents.
39
+ # @return [Hash] List of files with their contents
40
+ def list_contents
41
+ {}.tap do |files|
42
+ remote_files do |file_name|
43
+ resp = get_object(file_name)
44
+ files[file_name] = { data: resp }
45
+ end
46
+ end
47
+ end
48
+
49
+ def list_keys_in(path)
50
+ [].tap do |keys|
51
+ list_objects(path)[:contents].each do |s3_object|
52
+ keys << s3_object[:key]
53
+ end
54
+ end
55
+ end
56
+
57
+ # Push this task's file content to S3 server.
58
+ # Existing contents by the same #file_name will be overriden.
59
+ def push(task)
60
+ create_object(task.file_name, task.read_task_file).inspect
61
+ { 'url' => "s3://#{bucket_name}#{path}#{task.file_name}" }
62
+ end
63
+
64
+ # The raw url is a permalink for downloading the content rake task within
65
+ # the Gist as a file.
66
+ # @param file_name [String] name of the file to retrieve the download url
67
+ # @return [String] HTTP-URL of addressed file within the gist collection
68
+ def raw_url(file_name)
69
+ bucket = AWS::S3::Bucket.new(bucket_name)
70
+ object = AWS::S3::S3Object.new(bucket, "#{path}#{file_name}")
71
+ object.url_for(:read)
72
+ end
73
+
74
+ protected
75
+
76
+ def remote_files
77
+ [].tap do |keys|
78
+ list_objects(path)[:contents].each do |s3_object|
79
+ file_name = s3_object[:key] if s3_object[:key].include?('.rake')
80
+ if file_name
81
+ keys << file_name.split('/').last
82
+ yield file_name.split('/').last
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def create_object_unless_present(key, data)
89
+ create_object(key, data) if list_keys_in(key).empty?
90
+ end
91
+
92
+ def get_object(key)
93
+ s3_client.get_object(bucket_name: bucket_name,
94
+ key: key)[:data]
95
+ end
96
+
97
+ def list_objects(prefix = nil)
98
+ s3_client.list_objects(bucket_name: bucket_name,
99
+ prefix: prefix)
100
+ end
101
+
102
+ def create_object(key, data)
103
+ s3_client.put_object(bucket_name: bucket_name,
104
+ key: "#{path}#{key}",
105
+ data: data)
106
+ end
107
+
108
+ def retrieve_file_data(file_name)
109
+ get_object(file_name)
110
+ end
111
+
112
+ def delete_object(key)
113
+ s3_client.delete_object(bucket_name: bucket_name, key: key)
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Woro::Adapters::S3 do
4
+
5
+ let(:task) { Woro::Task.new('create_user') }
6
+ subject do
7
+ options = { bucket_name: 's3-bucket', folder_name: 'snippets/' }
8
+ Woro::Adapters::S3.new(options)
9
+ end
10
+
11
+ before do
12
+ FakeFS.deactivate!
13
+ allow(subject).to receive(:get_object).once.and_return 'https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl'
14
+ end
15
+
16
+ after do
17
+ FakeFS.activate!
18
+ end
19
+
20
+ describe '#list_files' do
21
+ it 'returns list' do
22
+ expect(subject.list_files).to eq ["create_user.rake"]
23
+ end
24
+ end
25
+
26
+ describe '#push' do
27
+ it 'calls s3 services with correct params' do
28
+ File.open(task.file_path, 'w') do |f|
29
+ f.puts 'hey'
30
+ end
31
+ expected_hash = {
32
+ bucket_name: 's3-bucket',
33
+ prefix: 'snippets/',
34
+ key: key, data: task.file_name
35
+ }
36
+ expect(AWS::S3::Client).to receive(:put_object).with(expected_hash).and_return true
37
+ subject.push(task)
38
+ end
39
+ end
40
+
41
+ describe '#retrieve_file_data' do
42
+ it 'returns data hash from file' do
43
+ expected_hash = {
44
+ "size"=>932, "raw_url"=>"https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl", "type"=>"text/plain", "language"=>"Ruby", "truncated"=>false, "content"=>"namespace :woro do\n desc 'Create User'\n task create_user: :environment do\n # Code\n end\nend\n"
45
+ }
46
+ expect(subject.send(:retrieve_file_data, 'create_user.rake')).to eq expected_hash
47
+ end
48
+ end
49
+
50
+ describe '#raw_url' do
51
+ it 'returns raw_url of file' do
52
+ expected_url = "https://gist.githubusercontent.com/raw/365370/8c4d2d43d178df44f4c03a7f2ac0ff512853564e/ring.erl"
53
+ expect(subject.raw_url('create_user.rake')).to eq expected_url
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ require 'woro'
2
+ require 'woro-s3'
3
+ require 'fakefs/safe'
4
+ require 'aws-sdk-v1'
5
+
6
+ Dir[('./spec/support/**/*.rb')].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ config.color = true
10
+ config.order = 'random'
11
+
12
+ config.before(:each) do
13
+ FakeFS.activate!
14
+ FileUtils.mkdir_p 'config'
15
+ FileUtils.mkdir_p 'lib/woro_tasks'
16
+ FileUtils.mkdir_p 'lib/tasks'
17
+ end
18
+ end
data/woro-s3.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'woro-s3/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "woro-s3"
8
+ spec.version = Woro::S3::VERSION
9
+ spec.authors = ["Daniel Senff"]
10
+ spec.email = ["mail@danielsenff.de"]
11
+ spec.summary = %q{Adapter to Github's Gist for use in Woro remote task management}
12
+ spec.description = %q{Adapter to Github's Gist for use in Woro remote task management}
13
+ spec.homepage = "http://github.com/Dahie/woro-s3"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'aws-sdk-v1'
22
+ spec.add_dependency 'woro'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: woro-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Senff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-v1
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: woro
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Adapter to Github's Gist for use in Woro remote task management
70
+ email:
71
+ - mail@danielsenff.de
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Gemfile.lock
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - lib/woro-s3.rb
83
+ - lib/woro-s3/version.rb
84
+ - lib/woro/adapters/s3.rb
85
+ - spec/lib/woro/adapters/s3_spec.rb
86
+ - spec/spec_helper.rb
87
+ - woro-s3.gemspec
88
+ homepage: http://github.com/Dahie/woro-s3
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Adapter to Github's Gist for use in Woro remote task management
112
+ test_files:
113
+ - spec/lib/woro/adapters/s3_spec.rb
114
+ - spec/spec_helper.rb