Class: Aws::ASMR::Cache
- Inherits:
-
Struct
- Object
- Struct
- Aws::ASMR::Cache
- Defined in:
- lib/aws/asmr/cache.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
#session_token ⇒ Object
Returns the value of attribute session_token.
Class Method Summary collapse
Instance Method Summary collapse
- #expiration_time ⇒ Object
- #expired? ⇒ Boolean
- #save!(assume_role_arn) ⇒ Object
- #shell_variables ⇒ Object
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id
6 7 8 |
# File 'lib/aws/asmr/cache.rb', line 6 def access_key_id @access_key_id end |
#expiration ⇒ Object
Returns the value of attribute expiration
6 7 8 |
# File 'lib/aws/asmr/cache.rb', line 6 def expiration @expiration end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key
6 7 8 |
# File 'lib/aws/asmr/cache.rb', line 6 def secret_access_key @secret_access_key end |
#session_token ⇒ Object
Returns the value of attribute session_token
6 7 8 |
# File 'lib/aws/asmr/cache.rb', line 6 def session_token @session_token end |
Class Method Details
.base ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/aws/asmr/cache.rb', line 11 def base @base ||= begin if File.exist?(PATH) JSON.parse(File.read(PATH)) else {} end end end |
.destroy! ⇒ Object
32 33 34 |
# File 'lib/aws/asmr/cache.rb', line 32 def destroy! File.exist?(PATH) && File.delete(PATH) end |
.first ⇒ Object
21 22 23 24 |
# File 'lib/aws/asmr/cache.rb', line 21 def first k,v = base.first get(k) end |
.get(assume_role_arn) ⇒ Object
26 27 28 29 30 |
# File 'lib/aws/asmr/cache.rb', line 26 def get(assume_role_arn) cache = base[assume_role_arn] && new(base[assume_role_arn]) return nil unless cache cache.expired? ? nil : cache end |
Instance Method Details
#expiration_time ⇒ Object
37 38 39 40 |
# File 'lib/aws/asmr/cache.rb', line 37 def expiration_time return nil unless expiration expiration.is_a?(Time) ? expiration : Time.parse(expiration) end |
#expired? ⇒ Boolean
42 43 44 45 |
# File 'lib/aws/asmr/cache.rb', line 42 def expired? return true unless expiration_time expiration_time < (Time.now+60*5) end |
#save!(assume_role_arn) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/aws/asmr/cache.rb', line 47 def save!(assume_role_arn) FileUtils.mkdir_p(Pathname.new(PATH).dirname) self.class.base[assume_role_arn] = to_h File.open(PATH, 'w') do |f| f.puts(JSON.pretty_generate(self.class.base)) end end |
#shell_variables ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/aws/asmr/cache.rb', line 55 def shell_variables { AWS_ACCESS_KEY_ID: access_key_id, AWS_SECRET_ACCESS_KEY: secret_access_key, AWS_SESSION_TOKEN: session_token, }.map{|k,v| "#{k}=#{v}"} end |