swift_ingest 0.4.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b1cb53e75b3c578cf1467810cf7e8eab045dc212
4
+ data.tar.gz: 382850d36c7540f821cd1d779b396fdde8cf7c4a
5
+ SHA512:
6
+ metadata.gz: 4fd55f3751603cfd19eb03b302aa3c2bc696b3252511143091dac506cb756179b7a00cf7c419ff51c704173e0440fcbc88be440f6c556c424d3fd716956bc2d7
7
+ data.tar.gz: b3708cbe8a2059195b23d5f0caed393b65610b5443598790eb432a3048bf5d7454d64389e3b4a2103dcae4fbfc98f3e602f46797d35576a58a732ce488a27dfc
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
@@ -0,0 +1,90 @@
1
+ # List of cops can be found here:
2
+ # https://github.com/bbatsov/rubocop/blob/master/config/default.yml
3
+ # https://github.com/bbatsov/rubocop/blob/master/config/disabled.yml
4
+ # https://github.com/bbatsov/rubocop/blob/master/config/enabled.yml
5
+ require: rubocop-rspec
6
+
7
+ AllCops:
8
+ DisplayCopNames: true
9
+ DisplayStyleGuide: true
10
+ Exclude:
11
+ - 'tmp/**/*'
12
+ - 'vendor/**/*'
13
+ ExtraDetails: true
14
+ TargetRubyVersion: 2.3
15
+
16
+ # readability is Actually Good
17
+ Layout/EmptyLinesAroundClassBody:
18
+ EnforcedStyle: empty_lines_except_namespace
19
+
20
+ Layout/IndentationConsistency:
21
+ Enabled: true
22
+ EnforcedStyle: normal
23
+
24
+ # A calculated magnitude based on number of assignments,
25
+ # branches, and conditions.
26
+ Metrics/AbcSize:
27
+ Enabled: false
28
+
29
+ Metrics/ClassLength:
30
+ Max: 500 # default 100
31
+
32
+ # A complexity metric that is strongly correlated to the number
33
+ # of test cases needed to validate a method.
34
+ Metrics/CyclomaticComplexity:
35
+ Enabled: false
36
+
37
+ Metrics/LineLength:
38
+ Enabled: true
39
+ Max: 120 # default is 80
40
+
41
+ # Avoid methods longer than 10 lines of code.
42
+ Metrics/MethodLength:
43
+ Enabled: false
44
+
45
+ Metrics/BlockLength:
46
+ Enabled: false
47
+
48
+ Metrics/ModuleLength:
49
+ Max: 500 # default 100
50
+
51
+ # A complexity metric geared towards measuring complexity for a human reader.
52
+ Metrics/PerceivedComplexity:
53
+ Enabled: false
54
+
55
+ # indentation is an endangered resource
56
+ Style/ClassAndModuleChildren:
57
+ EnforcedStyle: compact
58
+
59
+ Style/Documentation:
60
+ Enabled: false
61
+
62
+ Style/Filename:
63
+ Exclude:
64
+ - Dangerfile
65
+ - Rakefile
66
+ - Gemfile
67
+
68
+ # Checks if there is a magic comment to enforce string literals
69
+ Style/FrozenStringLiteralComment:
70
+ Enabled: false
71
+
72
+ # Perfer to use // but %r can be better in certain scenarios
73
+ Style/RegexpLiteral:
74
+ Enabled: false
75
+
76
+ Style/SymbolArray:
77
+ Enabled: false
78
+
79
+ # Use %w or %W for arrays of words.
80
+ Style/WordArray:
81
+ Enabled: false
82
+
83
+ RSpec/ExampleLength:
84
+ Enabled: false
85
+
86
+ RSpec/MultipleExpectations:
87
+ Enabled: false
88
+
89
+ RSpec/DescribedClass:
90
+ EnforcedStyle: explicit
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ sudo: false
3
+ cache: bundler
4
+
5
+ before_install:
6
+ - gem install bundler
7
+ - gem update bundler
8
+
9
+ rvm:
10
+ - 2.3.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in swift_ingest.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 University of Alberta Libraries
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.
@@ -0,0 +1,57 @@
1
+ # SWIFT ingest Ruby gem
2
+ Ruby gem for storing files in swift openstack storage
3
+
4
+ ![Ruby Swift Ingest gem Diagram](docs/images/overview.png)
5
+
6
+ ## Requirements
7
+
8
+ Swift_Ingest supports Ruby 2.3.1+
9
+
10
+ ## Installation
11
+
12
+ Swift_Ingest is hosted on rubygems.org. Therefore it can be installed via:
13
+
14
+ ```bash
15
+ gem install swift_ingest
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ This gem in indented to be used from other ruby programs.
21
+ Typical usage involves creating new SwiftIngest object
22
+
23
+ ```bash
24
+ swift_depositer = SwiftIngest::Ingestor.new(username: 'user',
25
+ password: 'secret',
26
+ tenant: 'test',
27
+ auth_url: 'http://www.example.com:8080/auth/v1.0',
28
+ project: 'MYPROJ')
29
+
30
+ ```
31
+
32
+ then using newly created oject to deposit object into swift repository:
33
+
34
+ ```bash
35
+ swift_depositer.deposit_file(myfile_file, 'MY_CONTAINER')
36
+ ```
37
+ ## Testing
38
+
39
+ To run the test suite:
40
+
41
+ ```bash
42
+ bundle install
43
+ bundle exec rake
44
+ ```
45
+
46
+ This will run both rspec and rubocop together.
47
+
48
+ To run rspec by itself:
49
+
50
+ ```bash
51
+ bundle exec rspec
52
+ ```
53
+ To run rubocop by itself:
54
+
55
+ ```bash
56
+ bundle exec rubocop
57
+ ```
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new do |r|
6
+ r.verbose = false
7
+ end
8
+
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: [:spec, :rubocop]
Binary file
@@ -0,0 +1,16 @@
1
+ require 'swift_ingest/version'
2
+ require 'swift_ingest/ingestor'
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+
6
+ module SwiftIngest
7
+ DEFAULTS = {
8
+ tenant: 'tester',
9
+ username: 'test:tester',
10
+ password: 'testing',
11
+ auth_url: 'http://www.example.com:8080/auth/v1.0',
12
+ project: 'ERA',
13
+ project_name: 'ERA',
14
+ project_domain_name: 'default'
15
+ }.freeze
16
+ end
@@ -0,0 +1,84 @@
1
+ require 'swift_ingest/version'
2
+ require 'openstack'
3
+ require 'mysql2'
4
+
5
+ class SwiftIngest::Ingestor
6
+
7
+ attr_reader :swift_connection, :project
8
+
9
+ def initialize(connection = {})
10
+ extra_opt = { auth_method: 'password',
11
+ service_type: 'object-store' }
12
+ options = SwiftIngest::DEFAULTS.merge(connection).merge(extra_opt)
13
+ options[:api_key] = options.delete :password
14
+
15
+ @swift_connection = OpenStack::Connection.create(options)
16
+ @project = connection[:project]
17
+
18
+ # connect to the database
19
+ @dbcon = if ENV['DB_HOST'] && ENV['DB_USER'] && ENV['DB_PASSWORD'] && ENV['DB_DATABASE']
20
+ Mysql2::Client.new(host: ENV['DB_HOST'],
21
+ username: ENV['DB_USER'],
22
+ password: ENV['DB_PASSWORD'],
23
+ database: ENV['DB_DATABASE'])
24
+ end
25
+ end
26
+
27
+ def get_file_from_swit(file_name, swift_container)
28
+ deposited_file = nil
29
+ file_base_name = File.basename(file_name, '.*')
30
+ container = swift_connection.container(swift_container)
31
+ deposited_file = container.object(file_base_name) if container.object_exists?(file_base_name)
32
+ deposited_file
33
+ end
34
+
35
+ def deposit_file(file_name, swift_container, custom_metadata = {})
36
+ file_base_name = File.basename(file_name, '.*')
37
+ checksum = Digest::MD5.file(file_name).hexdigest
38
+ container = swift_connection.container(swift_container)
39
+
40
+ # Add swift metadata with in accordance to AIP spec:
41
+ # https://docs.google.com/document/d/154BqhDPAdGW-I9enrqLpBYbhkF9exX9lV3kMaijuwPg/edit#
42
+ metadata = {
43
+ project: @project,
44
+ project_id: file_base_name,
45
+ promise: 'bronze',
46
+ aip_version: '1.0'
47
+ }.merge(custom_metadata)
48
+
49
+ # ruby-openstack wants all keys of the metadata to be named like
50
+ # "X-Object-Meta-{{Key}}" so update them
51
+ metadata.transform_keys! { |key| "X-Object-Meta-#{key}" }
52
+
53
+ if container.object_exists?(file_base_name)
54
+ # temporary solution until fixed in upstream:
55
+ # for update: construct hash for key/value pairs as strings,
56
+ # and metadata as additional key/value string pairs in the hash
57
+ headers = { 'etag' => checksum,
58
+ 'content-type' => 'application/x-tar' }.merge(metadata)
59
+ deposited_file = container.object(file_base_name)
60
+ deposited_file.write(File.open(file_name), headers)
61
+ else
62
+ # for creating new: construct hash with symbols as keys, add metadata as a hash within the header hash
63
+ headers = { etag: checksum,
64
+ content_type: 'application/x-tar',
65
+ metadata: metadata }
66
+ deposited_file = container.create_object(file_base_name, headers, File.open(file_name))
67
+ end
68
+
69
+ return deposited_file unless @dbcon
70
+
71
+ # update db with deposited file info
72
+ @dbcon.query("INSERT INTO archiveEvent(project, container, ingestTime, \
73
+ objectIdentifier, objectChecksum, objectSize) \
74
+ VALUES('#{@project}', '#{swift_container}', now(), '#{file_base_name}', '#{checksum}', \
75
+ '#{File.size(file_name)}')")
76
+ custom_metadata.each do |key, value|
77
+ @dbcon.query("INSERT INTO customMetadata(eventId, propertyName, propertyValue) \
78
+ VALUES(LAST_INSERT_ID(), '#{key}', '#{value}' )")
79
+ end
80
+
81
+ deposited_file
82
+ end
83
+
84
+ end
@@ -0,0 +1,3 @@
1
+ module SwiftIngest
2
+ VERSION = '0.4.1'.freeze
3
+ end
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'swift_ingest/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'swift_ingest'
7
+ s.version = SwiftIngest::VERSION
8
+ s.date = '2017-08-31'
9
+ s.authors = ['DI Team U of A']
10
+ s.email = 'strilets@ualberta.ca'
11
+
12
+ s.summary = 'This is gems that allows depositing files into openstack swift repository'
13
+ s.description = 'Gem to deposit files into swift reposiroty'
14
+ s.homepage = 'http://rubygems.org/gems/swift_ingest'
15
+ s.license = 'MIT'
16
+
17
+ s.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ s.bindir = 'exe'
21
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ s.require_paths = ['lib']
23
+
24
+ s.required_ruby_version = '>= 2.3.1'
25
+
26
+ s.add_runtime_dependency 'activesupport', '~> 5.0'
27
+ s.add_runtime_dependency 'mysql2', '~> 0.4.6'
28
+ s.add_runtime_dependency 'openstack', '~> 3.3', '>= 3.3.10'
29
+
30
+ s.add_development_dependency 'bundler', '~> 1.14'
31
+ s.add_development_dependency 'pry', '~> 0.10', '>= 0.10.4'
32
+ s.add_development_dependency 'rake', '~> 12.0'
33
+ s.add_development_dependency 'rspec', '~> 3.0'
34
+ s.add_development_dependency 'rubocop', '~> 0.45'
35
+ s.add_development_dependency 'rubocop-rspec', '~> 1.10'
36
+ s.add_development_dependency 'vcr', '~> 3.0'
37
+ s.add_development_dependency 'webmock', '~> 2.1'
38
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: swift_ingest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.1
5
+ platform: ruby
6
+ authors:
7
+ - DI Team U of A
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: openstack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.3.10
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '3.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 3.3.10
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.14'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.14'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.10'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 0.10.4
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '0.10'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 0.10.4
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '12.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '12.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rspec
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: rubocop
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '0.45'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '0.45'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rubocop-rspec
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '1.10'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '1.10'
151
+ - !ruby/object:Gem::Dependency
152
+ name: vcr
153
+ requirement: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - "~>"
156
+ - !ruby/object:Gem::Version
157
+ version: '3.0'
158
+ type: :development
159
+ prerelease: false
160
+ version_requirements: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - "~>"
163
+ - !ruby/object:Gem::Version
164
+ version: '3.0'
165
+ - !ruby/object:Gem::Dependency
166
+ name: webmock
167
+ requirement: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '2.1'
172
+ type: :development
173
+ prerelease: false
174
+ version_requirements: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - "~>"
177
+ - !ruby/object:Gem::Version
178
+ version: '2.1'
179
+ description: Gem to deposit files into swift reposiroty
180
+ email: strilets@ualberta.ca
181
+ executables: []
182
+ extensions: []
183
+ extra_rdoc_files: []
184
+ files:
185
+ - ".gitignore"
186
+ - ".rubocop.yml"
187
+ - ".travis.yml"
188
+ - Gemfile
189
+ - LICENSE
190
+ - README.md
191
+ - Rakefile
192
+ - docs/images/overview.png
193
+ - lib/swift_ingest.rb
194
+ - lib/swift_ingest/ingestor.rb
195
+ - lib/swift_ingest/version.rb
196
+ - swift_ingest.gemspec
197
+ homepage: http://rubygems.org/gems/swift_ingest
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: 2.3.1
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.6.13
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: This is gems that allows depositing files into openstack swift repository
221
+ test_files: []