discourse_subscription_client 0.1.9 → 0.1.11
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 462389d7e4335458e1f6606ce6877abccc6df5999e71a947bcd926c176df0e6e
|
4
|
+
data.tar.gz: 8df679514b5492438b34c22ec8c0346d34ebbd18c05722f2c8669c1decf807c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f29355c411d5a6c5d5f8ce55c12edf8573402dc8d9a04e061e331223fd87b9071ae26f8267613771c5b4ef782db4d980c9a229d3c410bb24d0e7a652d33457c3
|
7
|
+
data.tar.gz: eb485af0a0d55f09b2afd1aa101246b25deccb52b56453a37ff72ca9affcf0e770c09b840cfe1715adf9122cef5b8d2181d5acb57c5e1741fed46cebe55a7195
|
@@ -1,38 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "aws-sdk-s3"
|
4
|
-
|
5
3
|
class SubscriptionClientResource < ActiveRecord::Base
|
6
4
|
belongs_to :supplier, class_name: "SubscriptionClientSupplier"
|
7
5
|
has_many :notices, class_name: "SubscriptionClientNotice", as: :notice_subject, dependent: :destroy
|
8
6
|
has_many :subscriptions, foreign_key: "resource_id", class_name: "SubscriptionClientSubscription", dependent: :destroy
|
9
7
|
|
10
|
-
def
|
11
|
-
|
12
|
-
return nil unless can_access_bucket?(bucket)
|
13
|
-
|
14
|
-
"s3://#{CGI.escapeURIComponent(access_key_id)}:#{CGI.escapeURIComponent(secret_access_key)}@#{bucket}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def can_access_bucket?(bucket)
|
18
|
-
s3_client.head_bucket(bucket: bucket)
|
19
|
-
true
|
20
|
-
rescue Aws::S3::Errors::BadRequest,
|
21
|
-
Aws::S3::Errors::Forbidden,
|
22
|
-
Aws::S3::Errors::NotFound
|
23
|
-
false
|
24
|
-
end
|
25
|
-
|
26
|
-
def s3_client
|
27
|
-
@s3_client ||= begin
|
28
|
-
return nil unless access_key_id && secret_access_key
|
29
|
-
|
30
|
-
Aws::S3::Client.new(
|
31
|
-
region: "us-east-1",
|
32
|
-
access_key_id: access_key_id,
|
33
|
-
secret_access_key: secret_access_key
|
34
|
-
)
|
35
|
-
end
|
8
|
+
def region
|
9
|
+
"us-east-1"
|
36
10
|
end
|
37
11
|
end
|
38
12
|
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
5
|
+
module DiscourseSubscriptionClient
|
6
|
+
class S3Gem
|
7
|
+
attr_reader :plugin_name, :access_key_id, :secret_access_key, :region, :bucket
|
8
|
+
|
9
|
+
def initialize(opts = {})
|
10
|
+
@plugin_name = opts[:plugin_name]
|
11
|
+
@access_key_id = opts[:access_key_id]
|
12
|
+
@secret_access_key = opts[:secret_access_key]
|
13
|
+
@region = opts[:region]
|
14
|
+
@bucket = opts[:bucket]
|
15
|
+
end
|
16
|
+
|
17
|
+
def ready?
|
18
|
+
plugin_name && access_key_id && secret_access_key && region && bucket && can_access_bucket?
|
19
|
+
end
|
20
|
+
|
21
|
+
def install(gems)
|
22
|
+
return unless ready?
|
23
|
+
|
24
|
+
write_gemrc
|
25
|
+
|
26
|
+
gems.each do |gem_slug, version|
|
27
|
+
klass = gem_slug.to_s.underscore.classify
|
28
|
+
gem_name = gem_slug.to_s.dasherize
|
29
|
+
opts = { require_name: gem_slug.to_s.gsub(/_/, "/"), config: gemrc_path }
|
30
|
+
load(plugin_path, gem_name, version, opts)
|
31
|
+
end
|
32
|
+
ensure
|
33
|
+
remove_gemrc
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
# Compare PluginGem.load
|
39
|
+
def load(path, name, version, opts = nil)
|
40
|
+
opts ||= {}
|
41
|
+
|
42
|
+
gems_path = File.dirname(path) + "/gems/#{RUBY_VERSION}"
|
43
|
+
spec_path = "#{gems_path}/specifications"
|
44
|
+
spec_file = spec_path + "/#{name}-#{version}"
|
45
|
+
|
46
|
+
if PluginGem.platform_variants(spec_file).find(&File.method(:exist?)).blank?
|
47
|
+
command =
|
48
|
+
"gem install #{name} -v #{version} -i #{gems_path} --no-document --ignore-dependencies --no-user-install --config-file #{opts[:config]}"
|
49
|
+
puts command
|
50
|
+
Bundler.with_unbundled_env { puts `#{command}` }
|
51
|
+
end
|
52
|
+
|
53
|
+
spec_file_variant = PluginGem.platform_variants(spec_file).find(&File.method(:exist?))
|
54
|
+
if spec_file_variant.present?
|
55
|
+
Gem.path << gems_path
|
56
|
+
Gem::Specification.load(spec_file_variant).activate
|
57
|
+
require opts[:require_name]
|
58
|
+
else
|
59
|
+
puts "You are specifying the gem #{name} in #{path}, however it does not exist!"
|
60
|
+
puts "Looked for: \n- #{PluginGem.platform_variants(spec_file).join("\n- ")}"
|
61
|
+
exit(-1)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def can_access_bucket?
|
66
|
+
client.head_bucket(bucket: bucket)
|
67
|
+
true
|
68
|
+
rescue Aws::S3::Errors::BadRequest, Aws::S3::Errors::Forbidden, Aws::S3::Errors::NotFound => e
|
69
|
+
false
|
70
|
+
end
|
71
|
+
|
72
|
+
def client
|
73
|
+
@client ||=
|
74
|
+
begin
|
75
|
+
return nil unless region && access_key_id && secret_access_key
|
76
|
+
|
77
|
+
Aws::S3::Client.new(
|
78
|
+
region: region,
|
79
|
+
access_key_id: access_key_id,
|
80
|
+
secret_access_key: secret_access_key
|
81
|
+
)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def gemrc
|
86
|
+
{
|
87
|
+
sources: ["s3://#{bucket}/", "https://rubygems.org/"],
|
88
|
+
s3_source: {
|
89
|
+
"#{bucket}": {
|
90
|
+
id: access_key_id,
|
91
|
+
secret: secret_access_key,
|
92
|
+
region: region
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def write_gemrc
|
99
|
+
File.write(gemrc_path, gemrc.to_yaml)
|
100
|
+
end
|
101
|
+
|
102
|
+
def remove_gemrc
|
103
|
+
File.delete(gemrc_path) if File.exist?(gemrc_path)
|
104
|
+
end
|
105
|
+
|
106
|
+
def gemrc_path
|
107
|
+
File.join(Rails.root, "tmp", ".gemrc")
|
108
|
+
end
|
109
|
+
|
110
|
+
def plugin_path
|
111
|
+
@plugin_path ||= Discourse.plugins_by_name[plugin_name].path
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: discourse_subscription_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
@@ -282,6 +282,7 @@ files:
|
|
282
282
|
- lib/discourse_subscription_client/notices.rb
|
283
283
|
- lib/discourse_subscription_client/request.rb
|
284
284
|
- lib/discourse_subscription_client/resources.rb
|
285
|
+
- lib/discourse_subscription_client/s3_gem.rb
|
285
286
|
- lib/discourse_subscription_client/subscriptions.rb
|
286
287
|
- lib/discourse_subscription_client/subscriptions/result.rb
|
287
288
|
- lib/discourse_subscription_client/subscriptions/update_result.rb
|