-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,245 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
module Aws | ||
# @api private | ||
# A simple thread safe LRU cache | ||
class LRUCache | ||
# @param [Hash] options | ||
# @option options [Integer] :max_entries (100) Maximum number of entries | ||
# @option options [Integer] :expiration (nil) Expiration time in seconds | ||
def initialize(options = {}) | ||
@max_entries = options[:max_entries] || 100 | ||
@expiration = options[:expiration] | ||
@entries = {} | ||
@mutex = Mutex.new | ||
end | ||
|
||
# @param [String] key | ||
# @return [Object] | ||
def [](key) | ||
@mutex.synchronize do | ||
value = @entries[key] | ||
if value | ||
@entries.delete(key) | ||
@entries[key] = value unless value.expired? | ||
end | ||
@entries[key]&.value | ||
end | ||
end | ||
|
||
# @param [String] key | ||
# @param [Object] value | ||
def []=(key, value) | ||
@mutex.synchronize do | ||
@entries.shift unless @entries.size < @max_entries | ||
# delete old value if exists | ||
@entries.delete(key) | ||
@entries[key] = Entry.new(value: value, expiration: @expiration) | ||
@entries[key].value | ||
end | ||
end | ||
|
||
# @param [String] key | ||
# @return [Boolean] | ||
def key?(key) | ||
@mutex.synchronize do | ||
@entries.delete(key) if @entries.key?(key) && @entries[key].expired? | ||
@entries.key?(key) | ||
end | ||
end | ||
|
||
def clear | ||
@mutex.synchronize do | ||
@entries.clear | ||
end | ||
end | ||
|
||
# @api private | ||
class Entry | ||
def initialize(options = {}) | ||
@value = options[:value] | ||
@expiration = options[:expiration] | ||
@created_time = Time.now | ||
end | ||
|
||
# @return [Object] | ||
attr_reader :value | ||
|
||
def expired? | ||
return false unless @expiration | ||
|
||
Time.now - @created_time > @expiration | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
gems/aws-sdk-s3/lib/aws-sdk-s3/access_grants_credentials.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'set' | ||
|
||
module Aws | ||
module S3 | ||
# @api private | ||
class AccessGrantsCredentials | ||
include CredentialProvider | ||
include RefreshingCredentials | ||
|
||
def initialize(options = {}) | ||
@client = options[:client] | ||
@get_data_access_params = {} | ||
options.each_pair do |key, value| | ||
if self.class.get_data_access_options.include?(key) | ||
@get_data_access_params[key] = value | ||
end | ||
end | ||
@async_refresh = true | ||
super | ||
end | ||
|
||
# @return [S3Control::Client] | ||
attr_reader :client | ||
|
||
# @return [String] | ||
attr_reader :matched_grant_target | ||
|
||
private | ||
|
||
def refresh | ||
c = @client.get_data_access(@get_data_access_params) | ||
credentials = c.credentials | ||
@matched_grant_target = c.matched_grant_target | ||
@credentials = Credentials.new( | ||
credentials.access_key_id, | ||
credentials.secret_access_key, | ||
credentials.session_token | ||
) | ||
@expiration = credentials.expiration | ||
end | ||
|
||
class << self | ||
|
||
# @api private | ||
def get_data_access_options | ||
@gdao ||= begin | ||
input = Aws::S3Control::Client.api.operation(:get_data_access).input | ||
Set.new(input.shape.member_names) | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.