discourse_subscription_client 0.1.3 → 0.1.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f069fe8f7e5ca4e06fca3133df12ad2a67599b3d175ad644b9ab346437adc93f
|
4
|
+
data.tar.gz: c1a8b49c041741767cd37016d3bde41fc23138b23837b74ff2a3c00b80f24fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5efe845b7c65951a24bae6a4697db67f48ac528e089aa1182c1594fc1698a4eb1ae7e1fc44f1be82b55603f369d07dd8ad5f665049f2ab96a6ad835710032f5
|
7
|
+
data.tar.gz: b510d995e599fb23af27447a3e84e6cdbf9c16957fd8b59dfc4d416e8074ddcdbb6fa729d447774e54a6559f4de27fda987ae71f7beb64f1da4dfbd2d40961b9
|
@@ -1,18 +1,52 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
3
5
|
class SubscriptionClientResource < ActiveRecord::Base
|
4
6
|
belongs_to :supplier, class_name: "SubscriptionClientSupplier"
|
5
7
|
has_many :notices, class_name: "SubscriptionClientNotice", as: :notice_subject, dependent: :destroy
|
6
8
|
has_many :subscriptions, foreign_key: "resource_id", class_name: "SubscriptionClientSubscription", dependent: :destroy
|
9
|
+
|
10
|
+
def get_source_url(bucket)
|
11
|
+
return nil unless access_key_id && secret_access_key
|
12
|
+
return nil unless can_access_bucket?(bucket)
|
13
|
+
|
14
|
+
"s3://#{access_key_id}:#{secret_access_key}@#{bucket}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def can_access_bucket?(bucket)
|
18
|
+
begin
|
19
|
+
s3_client.head_bucket(bucket: bucket)
|
20
|
+
rescue Aws::S3::Errors::BadRequest,
|
21
|
+
Aws::S3::Errors::Forbidden,
|
22
|
+
Aws::S3::Errors::NotFound => e
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def s3_client
|
29
|
+
@s3_client ||= begin
|
30
|
+
return nil unless access_key_id && secret_access_key
|
31
|
+
|
32
|
+
Aws::S3::Client.new(
|
33
|
+
region: "us-east-1",
|
34
|
+
access_key_id: access_key_id,
|
35
|
+
secret_access_key: secret_access_key
|
36
|
+
)
|
37
|
+
end
|
38
|
+
end
|
7
39
|
end
|
8
40
|
|
9
41
|
# == Schema Information
|
10
42
|
#
|
11
43
|
# Table name: subscription_client_resources
|
12
44
|
#
|
13
|
-
# id
|
14
|
-
# supplier_id
|
15
|
-
# name
|
16
|
-
# created_at
|
17
|
-
# updated_at
|
45
|
+
# id :bigint not null, primary key
|
46
|
+
# supplier_id :bigint
|
47
|
+
# name :string not null
|
48
|
+
# created_at :datetime not null
|
49
|
+
# updated_at :datetime not null
|
50
|
+
# access_key_id :string
|
51
|
+
# secret_access_key :string
|
18
52
|
#
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angus McLeod
|
@@ -220,6 +220,20 @@ dependencies:
|
|
220
220
|
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: aws-sdk-s3
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - ">="
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
223
237
|
description: Adds a backend subscription client to a Discourse plugin.
|
224
238
|
email:
|
225
239
|
- angus@mcleod.org.au
|