Skip to content

Commit

Permalink
Update subscription_client_resource.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
angusmcleod committed Sep 18, 2024
1 parent 6370b97 commit 7abd304
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions app/models/subscription_client_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@ class SubscriptionClientResource < ActiveRecord::Base
has_many :subscriptions, foreign_key: "resource_id", class_name: "SubscriptionClientSubscription", dependent: :destroy

def get_source_url(bucket)
return nil unless access_key_id && secret_access_key
return nil unless access_key_id && secret_access_key && s3_client
return nil unless can_access_bucket?(bucket)

"s3://#{access_key_id}:#{secret_access_key}@#{bucket}"
end

def can_access_bucket?(bucket)
begin
s3_client.head_bucket(bucket: bucket)
rescue Aws::S3::Errors::BadRequest,
Aws::S3::Errors::Forbidden,
Aws::S3::Errors::NotFound => e
return false
end
s3_client.head_bucket(bucket: bucket)
true
rescue Aws::S3::Errors::BadRequest,
Aws::S3::Errors::Forbidden,
Aws::S3::Errors::NotFound
false
end

def s3_client
Expand Down

0 comments on commit 7abd304

Please sign in to comment.