discourse_subscription_client 0.1.4 → 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: ea189a1e70964148ffbcad4fb0ee45b8274c77d84b0dedf06f785108666090eb
4
- data.tar.gz: d275e4c8551df79ebace036fbc1550715f1b7220bc4c9c6cb1cb552b7b9cfe25
3
+ metadata.gz: f069fe8f7e5ca4e06fca3133df12ad2a67599b3d175ad644b9ab346437adc93f
4
+ data.tar.gz: c1a8b49c041741767cd37016d3bde41fc23138b23837b74ff2a3c00b80f24fc0
5
5
  SHA512:
6
- metadata.gz: 5c5dd6fe8540cc4644e8e35d2f22b61f91c9f3ae5286c4b7a33e99f2a4c5be8facd9dd260f88c2da92b0d869e090d7cb440a990f87db1330634dd0a4327b8364
7
- data.tar.gz: 0f8e839f5c58e48c10850917154f7febcec84a3f004f098c672776521889fa29fb8e05d6366664ba9a3326d0816862bb71f70553258c050da016463e9bd3f59d
6
+ metadata.gz: f5efe845b7c65951a24bae6a4697db67f48ac528e089aa1182c1594fc1698a4eb1ae7e1fc44f1be82b55603f369d07dd8ad5f665049f2ab96a6ad835710032f5
7
+ data.tar.gz: b510d995e599fb23af27447a3e84e6cdbf9c16957fd8b59dfc4d416e8074ddcdbb6fa729d447774e54a6559f4de27fda987ae71f7beb64f1da4dfbd2d40961b9
@@ -1,13 +1,41 @@
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
7
9
 
8
- def source_url(bucket)
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
+
9
14
  "s3://#{access_key_id}:#{secret_access_key}@#{bucket}"
10
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
11
39
  end
12
40
 
13
41
  # == Schema Information
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  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
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