mls 1.7.0 → 1.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61267aa211891a0f0f6d22339b6997745fa532cdb4d50390b5b8645cfb887ffe
4
- data.tar.gz: 1df8ded07de72295b7ea2852323cb51838398c77a2a782dffa0c6b4ff03c2c0b
3
+ metadata.gz: ac6d0d6ddd4d6b888fc8b8340eae0ab697a99a6aa4368ac8d7596974fb169c6b
4
+ data.tar.gz: dbcc04dd676749244ff3bb20f30a2b1874dd66106d89f01a815feabbcd602fc1
5
5
  SHA512:
6
- metadata.gz: 169618f8b6f8aec727b99d2a4a893cdcd292ae925095f57df1431d28f72d1fde6a6a3891b65505abd935de9268a5c8b639b1f5c72393c7bff72ee4391c790593
7
- data.tar.gz: 983cc885eb785faa6dc33e4dce9246b368b9519ab4d451aca20708e0fc47f282401d9238ed5fbc8b33ef253b8715df88200247768b1b72882d17c819a8b143d7
6
+ metadata.gz: 92927db2d0dd6856cc80a9fbd3ef4930aa359252597bf197890614e659dc6090cab727baf8384f1fd875b1cf4a3f31fb211f6d8838a21ca15d52287fcef42f4a
7
+ data.tar.gz: ba932bc2c69e00d6d998c0bbd78a058f96a9351934d943b88ebedeb94c0d138bfda5f8c2e9a39cbec01056e8ee9b477fe0522ab3059cb3b400accaf2ea04c21d
data/bin/mls CHANGED
@@ -21,18 +21,26 @@ when "documents:migrate"
21
21
  exit 1
22
22
  end
23
23
 
24
- b2 = MLS::CLI::Storage::B2.new(MLS::CLI.options[:b2])
25
- Document.where(excludes: 'b2/sha256').find_each do |document|
24
+ b2 = StandardStorage::B2.new(MLS::CLI.options[:b2])
25
+ shas = []
26
+
27
+ Document.where(provider: {excludes: 'b2/sha256'}).limit(1000).each do |document|
28
+ next if shas.include?(document.sha256)
26
29
  if document.sha256 && File.exists?(File.join(directory, MLS::CLI::Documents.partition(document.sha256)))
27
- b2.upload_file(documents.sha256, File.open(File.join(directory, MLS::CLI::Documents.partition(document.sha256))), {
30
+ b2.write(document.sha256, File.open(File.join(directory, MLS::CLI::Documents.partition(document.sha256))), {
28
31
  filename: document.filename,
29
32
  sha1: document.sha1,
30
33
  content_type: document.content_type,
31
34
  size: document.size
32
35
  })
36
+
37
+ Documents.where(md5: document.md5).find_each do |d|
38
+ next if d.sha256 != document.sha256
39
+ d.update!(provider: d.provider + ['b2/sha256'])
40
+ end
41
+ shas << document.sha256
33
42
  end
34
43
  end
35
- when "documents:check"
36
44
  else
37
45
  puts "Usage: mls documents:backup dir [options...]"
38
- end
46
+ end
@@ -35,7 +35,7 @@ module MLS::CLI
35
35
  MLS::CLI.options[:b2] = {
36
36
  account_id: URI.unescape(url.user),
37
37
  application_key: URI.unescape(url.password),
38
- bucket: URI.unescape(url.host)
38
+ bucket: URI.unescape(url.host),
39
39
  prefix: url.path&.empty? ? url.path : nil
40
40
  }
41
41
  url.query.split('&').each do |qp|
@@ -56,5 +56,5 @@ module MLS::CLI
56
56
 
57
57
  end
58
58
 
59
- require File.expand_path('../cli/storage', __FILE__)
59
+ require 'standard_storage'
60
60
  require File.expand_path('../cli/documents', __FILE__)
@@ -45,7 +45,7 @@ module MLS::CLI::Documents
45
45
  end
46
46
 
47
47
  if document.provider.nil? || document.provider.include?('s3/hash_key')
48
- storage_engine = MLS::CLI::Storage::S3.new(MLS::CLI.options[:s3])
48
+ storage_engine = StandardStorage::S3.new(MLS::CLI.options[:s3])
49
49
  key = 'hash_key'
50
50
  else
51
51
  raise 'unkown storage engine'
@@ -67,6 +67,4 @@ module MLS::CLI::Documents
67
67
  end
68
68
  end
69
69
 
70
- end
71
-
72
-
70
+ end
@@ -19,11 +19,11 @@ class Document < MLS::Model
19
19
  end
20
20
 
21
21
  def url(style=:original)
22
- MLS.config['document_host'].gsub(/\/$/, '') + '/' + path(style)
22
+ File.join(MLS.config['document_host'].gsub(/\/$/, ''), path(style))
23
23
  end
24
24
 
25
25
  def path(style=:original)
26
- "#{partition(style == :original ? hash_key : "#{hash_key}-#{style}")}"
26
+ File.join("documents", "#{partition(style == :original ? hash_key : "#{hash_key}-#{style}")}")
27
27
  end
28
28
 
29
29
  def partition(value)
@@ -4,6 +4,7 @@ class Task < MLS::Model
4
4
  belongs_to :subject, :polymorphic => true
5
5
  belongs_to :account
6
6
  belongs_to :source
7
+ belongs_to :team
7
8
 
8
9
  has_many :events
9
10
  has_many :mistakes
@@ -1,6 +1,7 @@
1
1
  class Team < MLS::Model
2
-
3
- has_and_belongs_to_many :accounts
2
+
4
3
  belongs_to :organization
5
-
4
+ has_and_belongs_to_many :accounts
5
+ has_many :tasks
6
+
6
7
  end
@@ -13,20 +13,37 @@ class MLS::Railtie < Rails::Railtie
13
13
 
14
14
  initializer 'mls' do |app|
15
15
 
16
- url = app.config.mls.fetch('url') { app.secrets.mls }
16
+ configs = if app.secrets.mls.is_a?(String)
17
+ h = ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(app.secrets.mls).to_hash.symbolize_keys
18
+ h[:api_key] = h.delete(:username)
19
+ if h[:adapter] != 'sunstone'
20
+ h[:use_ssl] = h[:adapter] == 'https'
21
+ h[:adapter] = 'sunstone'
22
+ end
23
+ h
24
+ elsif app.config_for(:mls)['url']
25
+ ActiveSupport::Deprecation.warn("Using mls.yml has been deprecated. Move to secrets.yml")
26
+ h = ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(app.config_for(:mls)['url']).to_hash.symbolize_keys
27
+ h[:api_key] = h.delete(:username)
28
+ if h[:adapter] != 'sunstone'
29
+ h[:use_ssl] = h[:adapter] == 'https'
30
+ h[:adapter] = 'sunstone'
31
+ end
32
+ h
33
+ else
34
+ app.secrets.mls
35
+ end
36
+
37
+
17
38
  user_agent = []
18
39
  user_agent << app.config.mls.fetch('user_agent') {
19
40
  app.class.name.split('::')[0..-2].join('::')
20
41
  }
21
42
  user_agent << "Rails/#{Rails.version}"
43
+ configs[:user_agent] = user_agent.compact.join(' ')
22
44
 
23
45
 
24
- MLS::Model.establish_connection({
25
- adapter: 'sunstone',
26
- url: url,
27
- user_agent: user_agent.compact.join(' ')
28
- })
29
-
46
+ MLS::Model.establish_connection(configs)
30
47
  end
31
48
 
32
- end
49
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mls"
6
- s.version = '1.7.0'
6
+ s.version = '1.8.0'
7
7
  s.authors = ["Jon Bracy", "James R. Bracy"]
8
8
  s.email = ["jon@42floors.com", "james@42floors.com"]
9
9
  s.homepage = "http://mls.42floors.com"
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.add_development_dependency 'sdoc-templates-42floors'
32
32
 
33
33
  # Runtime
34
+ s.add_runtime_dependency 'standardstorage'
34
35
  s.add_runtime_dependency 'phony'
35
36
  s.add_runtime_dependency 'arel-extensions'
36
37
  s.add_runtime_dependency 'rgeo', '>= 0.4.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-07-18 00:00:00.000000000 Z
12
+ date: 2019-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -165,6 +165,20 @@ dependencies:
165
165
  - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: standardstorage
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :runtime
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
168
182
  - !ruby/object:Gem::Dependency
169
183
  name: phony
170
184
  requirement: !ruby/object:Gem::Requirement
@@ -252,9 +266,6 @@ files:
252
266
  - lib/mls.rb
253
267
  - lib/mls/cli.rb
254
268
  - lib/mls/cli/documents.rb
255
- - lib/mls/cli/storage.rb
256
- - lib/mls/cli/storage/b2.rb
257
- - lib/mls/cli/storage/s3.rb
258
269
  - lib/mls/comment.rb
259
270
  - lib/mls/models/account.rb
260
271
  - lib/mls/models/accounts_region.rb
@@ -1,2 +0,0 @@
1
- require File.expand_path('../storage/s3', __FILE__)
2
- require File.expand_path('../storage/b2', __FILE__)
@@ -1,87 +0,0 @@
1
- require 'b2'
2
-
3
- module MLS::CLI::Storage
4
- class B2
5
-
6
- def initialize(configs = {})
7
- @configs = configs
8
- @configs[:prefix] ||= ""
9
-
10
- @client = B2::Bucket.new({
11
- 'bucketId' => configs[:bucket_id]
12
- }, B2.new({
13
- account_id: configs[:account_id],
14
- application_key: configs[:application_key]
15
- }))
16
- end
17
-
18
- def local?
19
- false
20
- end
21
-
22
- # def url(key)
23
- # [host, destination(key)].join('/')
24
- # end
25
-
26
- # def host
27
- # h = @configs[:bucket_host_alias] || "https://s3.amazonaws.com/#{@configs[:bucket]}"
28
- # h.delete_suffix('/')
29
- # end
30
-
31
- def destination(key)
32
- "#{@configs[:prefix]}#{partition(key)}".gsub(/^\//, '')
33
- end
34
-
35
- def exists?(key)
36
- @client.has_key?(destination(key))
37
- end
38
-
39
- def write(key, file, meta_info)
40
- file = file.tempfile if file.is_a?(ActionDispatch::Http::UploadedFile)
41
- file = File.open(file) if file.is_a?(String)
42
-
43
- @client.upload_file(key, file, mime_type: meta_info[:content_type], sha1: meta_info[:sha1], content_disposition: "inline; filename=\"#{meta_info[:filename]}\"")
44
- end
45
-
46
- def download(key, to=nil, &block)
47
- @client.download(destination(key), to, &block)
48
- end
49
-
50
- def delete(key)
51
- @client.delete!(key)
52
- end
53
-
54
- def copy_to_tempfile(key)
55
- tmpfile = Tempfile.new([File.basename(key), File.extname(key)], binmode: true)
56
- download(key, tmpfile.path)
57
- if block_given?
58
- begin
59
- yield(tmpfile)
60
- ensure
61
- tmpfile.close!
62
- end
63
- else
64
- tmpfile
65
- end
66
- end
67
-
68
- def partition(value)
69
- return value unless @configs[:partition]
70
- split = value.scan(/.{1,4}/)
71
- split.shift(@configs[:partition_depth] || 3).join("/") + split.join("")
72
- end
73
-
74
- def sha1(key)
75
- @client.file(destination(key)).sha1
76
- end
77
-
78
- def last_modified(key)
79
- @client.file(destination(key)).uploaded_at
80
- end
81
-
82
- def mime_type(key)
83
- @client.file(destination(key)).mime_type
84
- end
85
-
86
- end
87
- end
@@ -1,99 +0,0 @@
1
- require 'aws-sdk-s3'
2
-
3
- module MLS::CLI::Storage
4
- class S3
5
-
6
- def initialize(configs = {})
7
- @configs = configs
8
- @configs[:region] ||= 'us-east-1'
9
- @configs[:prefix] ||= ""
10
-
11
- @client = Aws::S3::Client.new({
12
- access_key_id: configs[:access_key_id],
13
- secret_access_key: configs[:secret_access_key],
14
- region: configs[:region]
15
- })
16
- end
17
-
18
- def object_for(key)
19
- Aws::S3::Object.new(@configs[:bucket], key, client: @client)
20
- end
21
-
22
- def local?
23
- false
24
- end
25
-
26
- def url(key)
27
- [host, destination(key)].join('/')
28
- end
29
-
30
- def host
31
- h = @configs[:bucket_host_alias] || "https://s3.amazonaws.com/#{@configs[:bucket]}"
32
- h.delete_suffix('/')
33
- end
34
-
35
- def destination(key)
36
- "#{@configs[:prefix]}#{partition(key)}".gsub(/^\//, '')#delete_prefix('/')
37
- end
38
-
39
- def exists?(key)
40
- object_for(destination(key)).exists?
41
- end
42
-
43
- # def write(key, file, meta_info)
44
- # file = file.tempfile if file.is_a?(ActionDispatch::Http::UploadedFile)
45
- #
46
- # object_for(destination(key)).upload_file(file, {
47
- # :acl => 'public-read',
48
- # :content_disposition => "inline; filename=\"#{meta_info[:filename]}\"",
49
- # :content_type => meta_info[:content_type]
50
- # })
51
- # end
52
-
53
- def read(key, &block)
54
- object_for(destination(key)).get()
55
- end
56
-
57
- def cp(key, path)
58
- object_for(destination(key)).get({ response_target: path })
59
- true
60
- end
61
-
62
- def delete(key)
63
- object_for(destination(key)).delete
64
- end
65
-
66
- def copy_to_tempfile(key)
67
- tmpfile = Tempfile.new([File.basename(key), File.extname(key)], binmode: true)
68
- cp(key, tmpfile.path)
69
- if block_given?
70
- begin
71
- yield(tmpfile)
72
- ensure
73
- tmpfile.close!
74
- end
75
- else
76
- tmpfile
77
- end
78
- end
79
-
80
- def partition(value)
81
- return value unless @configs[:partition]
82
- split = value.scan(/.{1,4}/)
83
- split.shift(@configs[:partition_depth] || 3).join("/") + split.join("")
84
- end
85
-
86
- def md5(key)
87
- object_for(destination(key)).etag
88
- end
89
-
90
- def last_modified(key)
91
- object_for(destination(key)).last_modified
92
- end
93
-
94
- def mime_type(key)
95
- object_for(destination(key)).content_type
96
- end
97
-
98
- end
99
- end