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: 7100f3f61c70ca7b6c85e41160a7f06c4c1222aa55c69fc4772dc0053b1e381a
4
- data.tar.gz: 63c8355e974192f6642e63699ddc14bbe7fb176cd0456776e04560b04a579657
3
+ metadata.gz: f069fe8f7e5ca4e06fca3133df12ad2a67599b3d175ad644b9ab346437adc93f
4
+ data.tar.gz: c1a8b49c041741767cd37016d3bde41fc23138b23837b74ff2a3c00b80f24fc0
5
5
  SHA512:
6
- metadata.gz: 07b49001753c66976c6bd4f8aef241813179e7895356a3f776b6d596869fb7904a6d2fdbacc01d8cad3450e9a432a59e8fd2f440a008e356a9a0652eb4f7abc1
7
- data.tar.gz: bfcff448a51fe8b32354d497bc4901edf7839d0ba5e53f304a268762ef9314cae19de0a1ee1e36b87c989f28b2daff2d8485ff38dc238d42dc4ef47e7b2677c0
6
+ metadata.gz: f5efe845b7c65951a24bae6a4697db67f48ac528e089aa1182c1594fc1698a4eb1ae7e1fc44f1be82b55603f369d07dd8ad5f665049f2ab96a6ad835710032f5
7
+ data.tar.gz: b510d995e599fb23af27447a3e84e6cdbf9c16957fd8b59dfc4d416e8074ddcdbb6fa729d447774e54a6559f4de27fda987ae71f7beb64f1da4dfbd2d40961b9
@@ -47,7 +47,7 @@ module DiscourseSubscriptionClient
47
47
 
48
48
  def destroy
49
49
  if @supplier.destroy_authorization
50
- render json: success_json.merge(supplier: @supplier.reload)
50
+ render json: success_json.merge(supplier_id: @supplier.id)
51
51
  else
52
52
  render json: failed_json
53
53
  end
@@ -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 :bigint not null, primary key
14
- # supplier_id :bigint
15
- # name :string not null
16
- # created_at :datetime not null
17
- # updated_at :datetime not null
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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiscourseSubscriptionClient
4
- VERSION = "0.1.3"
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.3
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