Skip to content

Commit e1b298f

Browse files
committed
Remove memoization and add logging for credentials expiration
1 parent 139cb39 commit e1b298f

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

app/models/book_store.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,26 @@ def object_exists?(key:)
7575
private
7676

7777
def get_client
78-
@client = Aws::S3::Client.new(self.class.client_options) unless @client
79-
@client
78+
client = Aws::S3::Client.new(self.class.client_options)
79+
log_credential_info(client)
80+
client
8081
end
8182

8283
def get_resource
83-
@resource = Aws::S3::Resource.new(self.class.client_options) unless @resource
84-
@resource
84+
resource = Aws::S3::Resource.new(self.class.client_options)
85+
log_credential_info(resource.client)
86+
resource
87+
end
88+
89+
def log_credential_info(client)
90+
creds = client.config.credentials
91+
if creds.respond_to?(:expiration)
92+
Rails.logger.info("[BookStore] AWS credentials expiration: \\#{creds.expiration}")
93+
else
94+
Rails.logger.info("[BookStore] AWS credentials: \\#{creds.inspect}")
95+
end
96+
rescue => e
97+
Rails.logger.warn("[BookStore] Could not log AWS credential info: \\#{e}")
8598
end
8699

87100
end

0 commit comments

Comments
 (0)