takenoko-s3 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1ec694617212b452aa76af58121eb9c34e99b42
4
+ data.tar.gz: 5045778b376a756e0296bcb158fafd5a50278405
5
+ SHA512:
6
+ metadata.gz: e090e945aa336f847a137bace3cfdd1fc08e305c710b0826db9c36c387708e653b6647949d33c39f96ecebc18b73bc1323acb9be37f30077bcecdccac7861cf7
7
+ data.tar.gz: 7c7d6a22d438c4e206e44eb1944c50ef5268934a6ea7f200ca0e428438848a57d9e4f4db31336888ce793029b08ce4dec64c0202c8a9331874fbe5680223c210
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at khiem-nguyen@kayac.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in takenoko-s3.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Khiem Nguyen
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Takenoko::S3
2
+
3
+ Plugin for [Takenoko](https://github.com/khiemns54/takenoko) to work with AWS S3
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem 'takenoko-s3'
9
+ ```
10
+
11
+ Refer takenoko document for generate initializer and basic config
12
+ Additional global configuration:
13
+
14
+ Example: config/initializers/takenoko.rb
15
+
16
+ conf.s3.bucket = 'my_bucket'
17
+
18
+ |Option|Require|Default|Description|Value|Overwrite(*)|
19
+ |---|---|---|---|---|---|
20
+ |s3.aws_key_id|Require|nil|AWS key id|String|No|
21
+ |s3.aws_key_secret|Require|nil|AWS key secret|String|No|
22
+ |s3.to_s3|Optional|false|Allow all attached files to be uploaded to s3|bool|Yes|
23
+ |s3.bucket|Optional|nil|Bucket name|String|Yes|
24
+ |s3.file_location|Optional|attached_files|S3 location for uploaded files|String|Yes|
25
+ |s3.public|Optional|attached_files|Make public after uploading|String|Yes|
26
+
27
+ ##Usage
28
+
29
+ Takenoko
30
+
31
+ Takenoko.upload_table_to_s3(table_name)
32
+ Takenoko.upload_all_to_s3
33
+ Takenoko.download_and_upload_table_to_s3(table_name)
34
+ Takenoko.download_and_upload_all_to_s3
35
+
36
+ Rake
37
+
38
+ rake takenoko:upload_table_to_s3[table_name]
39
+ rake takenoko:upload_all_to_s3
40
+ rake takenoko:download_and_upload_table_to_s3[table_name]
41
+ rake takenoko:download_and_upload_all_to_s3
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "takenoko/s3"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ module Takenoko
2
+ module AttachHelper
3
+ extend self
4
+ def upload_to_s3(table_data)
5
+ return false unless table_data[:to_s3].present?
6
+ raise 'bucket must be set' if table_data[:bucket].blank?
7
+ raise 'attach_files empty' if table_data[:attach_files].blank?
8
+ bucket = Takenoko.s3.client.bucket(table_data[:bucket])
9
+ table_data[:attach_files].each do |col|
10
+ next unless col[:to_s3].present?
11
+ table_data[:rows].each do |row|
12
+ next if row[col[:column_name]].blank?
13
+ file_path = col[:download_location] + '/' + File.basename(row[col[:column_name]])
14
+ unless File.file?(file_path)
15
+ raise "File not found: #{file_path}, download first or use download_and_upload_to_s3"
16
+ end
17
+ file = File.open(file_path)
18
+ s3_path = col[:s3_folder]+ "/" + File.basename(row[col[:column_name]])
19
+ Rails.logger.info "Uploading to s3: #{file_path} -> #{s3_path}"
20
+ bucket.files.create({
21
+ key: s3_path,
22
+ body: file,
23
+ public: col[:s3_public]
24
+ })
25
+ end
26
+ end
27
+ return true
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog'
2
+ module Takenoko
3
+ module S3
4
+ class Client
5
+ def initialize(key,secret,region)
6
+ @config = {
7
+ provider: 'AWS',
8
+ aws_access_key_id: key,
9
+ aws_secret_access_key: secret,
10
+ region: region
11
+ }
12
+ end
13
+
14
+ def session
15
+ Fog::Storage.new @config
16
+ end
17
+
18
+ def buckets
19
+ session.directories
20
+ end
21
+
22
+ def bucket(bucket_name,folder_path=nil)
23
+ session.directories.get(bucket_name, prefix:folder_path )
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'takenoko'
2
+ module Takenoko
3
+ module MappingGenerator
4
+ extend self
5
+ table_filters << [
6
+ :set_s3_config, ->(name,table){
7
+ if (attach_files = table[:attach_files]).present?
8
+ table[:bucket] ||= Takenoko.s3.bucket
9
+ table[:to_s3] ||= Takenoko.s3.to_s3
10
+ table[:s3_public] ||= Takenoko.s3.s3_public
11
+ table[:s3_location] ||= Takenoko.s3.file_location + "/" + table[:table_name]
12
+ attach_files = attach_files.map do |col|
13
+ col[:to_s3] ||= table[:to_s3]
14
+ col[:s3_public] ||= table[:s3_public]
15
+ col[:s3_folder] = col[:s3_folder].present? ? table[:s3_location] + "/" + col[:s3_folder] : table[:s3_location]
16
+ end
17
+ end
18
+ }
19
+ ]
20
+ def test
21
+ self
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,35 @@
1
+ module Takenoko
2
+ extend self
3
+ def s3
4
+ S3
5
+ end
6
+
7
+ def upload_table_to_s3(table_name)
8
+ table_data = google_client.get_table(table_name)
9
+ raise "attach_files not set" unless table_data[:attach_files].present?
10
+ AttachHelper.upload_to_s3 table_data
11
+ end
12
+
13
+ def upload_all_to_s3
14
+ mapping_config[:tables].each do |table,conf|
15
+ next if conf[:attach_files].blank?
16
+ upload_table_to_s3 table
17
+ end
18
+ return true
19
+ end
20
+
21
+ def download_and_upload_table_to_s3(table_name)
22
+ table_data = google_client.get_table(table_name)
23
+ raise "attach_files not set" unless table_data[:attach_files].present?
24
+ AttachHelper.download table_data
25
+ AttachHelper.upload_to_s3 table_data
26
+ end
27
+
28
+ def download_and_upload_all_to_s3
29
+ mapping_config[:tables].each do |table,conf|
30
+ next if conf[:attach_files].blank?
31
+ download_and_upload_table_to_s3 table
32
+ end
33
+ return true
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ namespace :takenoko do
2
+
3
+ task :upload_table_to_s3,[:table] => :environment do |t, args|
4
+ Takenoko.upload_table_to_s3(args[:table])
5
+ end
6
+
7
+ task :upload_all_to_s3 => :environment do
8
+ Takenoko.upload_all_to_s3
9
+ end
10
+
11
+ task :download_and_upload_table_to_s3,[:table] => :environment do |t, args|
12
+ Takenoko.download_and_upload_table_to_s3(args[:table])
13
+ end
14
+
15
+ task :download_and_upload_all_to_s3 => :environment do
16
+ Takenoko.download_and_upload_all_to_s3
17
+ end
18
+
19
+ end
@@ -0,0 +1,5 @@
1
+ module Takenoko
2
+ module S3
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ require "takenoko"
2
+ require 'takenoko/mapping_generator'
3
+ require "takenoko/s3/takenoko"
4
+ require "takenoko/s3/attach_helper"
5
+ require "takenoko/s3/client"
6
+ require "takenoko/s3/mapping_generator"
7
+
8
+ module Takenoko
9
+ module S3
10
+ extend self
11
+ mattr_accessor :aws_key_id
12
+ @@aws_key_id = nil
13
+
14
+ mattr_accessor :aws_key_secret
15
+ @@aws_key_secret = nil
16
+
17
+ mattr_accessor :to_s3
18
+ @@to_s3 = false
19
+
20
+ mattr_accessor :region
21
+ @@region = "ap-northeast-1"
22
+
23
+ mattr_accessor :bucket
24
+ @@bucket = nil
25
+
26
+ mattr_accessor :file_location
27
+ @@file_location = "attached_files"
28
+
29
+ mattr_accessor :s3_public
30
+ @@s3_public = false
31
+
32
+ @@client = nil
33
+
34
+ def client
35
+ Client.new(aws_key_id,aws_key_secret,region)
36
+ end
37
+ end
38
+
39
+ class Railtie < Rails::Railtie
40
+ railtie_name :takenoko
41
+
42
+ rake_tasks do
43
+ load "takenoko/s3/tasks/takenoko.rake"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'takenoko/s3/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "takenoko-s3"
8
+ spec.version = Takenoko::S3::VERSION
9
+ spec.authors = ["KhiemNS"]
10
+ spec.email = ["khiem-nguyen@kayac.com"]
11
+
12
+ spec.summary = %q{S3 Uploader plugin for takenoko}
13
+ spec.description = %q{S3 Uploader plugin for takenoko}
14
+ spec.homepage = "https://github.com/khiemns54/takenoko-s3/tree/release/0.0.2"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_dependency "takenoko", "~> 0.2.2"
26
+ spec.add_dependency "fog", "~> 1.38.0"
27
+
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: takenoko-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - KhiemNS
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: takenoko
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: fog
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.38.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.38.0
83
+ description: S3 Uploader plugin for takenoko
84
+ email:
85
+ - khiem-nguyen@kayac.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/takenoko/s3.rb
100
+ - lib/takenoko/s3/attach_helper.rb
101
+ - lib/takenoko/s3/client.rb
102
+ - lib/takenoko/s3/mapping_generator.rb
103
+ - lib/takenoko/s3/takenoko.rb
104
+ - lib/takenoko/s3/tasks/takenoko.rake
105
+ - lib/takenoko/s3/version.rb
106
+ - takenoko-s3.gemspec
107
+ homepage: https://github.com/khiemns54/takenoko-s3/tree/release/0.0.2
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: S3 Uploader plugin for takenoko
131
+ test_files: []