Class: Rails::Vault::JWT::TokenProvider::BaseProvider
- Inherits:
-
Object
- Object
- Rails::Vault::JWT::TokenProvider::BaseProvider
- Defined in:
- lib/rails/vault/jwt/token_provider/base_provider.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#expire_time ⇒ Object
readonly
Returns the value of attribute expire_time.
Instance Method Summary collapse
- #auth ⇒ Object
- #bearer_token ⇒ Object
- #client ⇒ Object
-
#initialize(*_args, bearer_role_name: nil, **_kwargs) ⇒ BaseProvider
constructor
A new instance of BaseProvider.
- #token ⇒ Object
- #token_expired? ⇒ Boolean
- #token_life_remaining ⇒ Object
- #token_valid? ⇒ Boolean
Constructor Details
#initialize(*_args, bearer_role_name: nil, **_kwargs) ⇒ BaseProvider
Returns a new instance of BaseProvider.
12 13 14 15 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 12 def initialize(*_args, bearer_role_name: nil, **_kwargs) @expire_time = DateTime.now @bearer_role_name = bearer_role_name || ENV.fetch('VAULT_BEARER_ROLE', '') end |
Instance Attribute Details
#expire_time ⇒ Object (readonly)
Returns the value of attribute expire_time.
10 11 12 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 10 def expire_time @expire_time end |
Instance Method Details
#auth ⇒ Object
17 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 17 def auth; end |
#bearer_token ⇒ Object
19 20 21 22 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 19 def bearer_token token client.logical.read("identity/oidc/token/#{@bearer_role_name}")&.data[:token] end |
#client ⇒ Object
47 48 49 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 47 def client @client ||= ::Vault::Client.new end |
#token ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 24 def token unless token_valid? auth_data = auth @token = auth_data.client_token @expire_time = DateTime.now + (auth_data.lease_duration / 86_400.0) client.token = @token end @token end |
#token_expired? ⇒ Boolean
35 36 37 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 35 def token_expired? DateTime.now > @expire_time end |
#token_life_remaining ⇒ Object
39 40 41 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 39 def token_life_remaining (@expire_time - DateTime.now) * 86_400.0 end |
#token_valid? ⇒ Boolean
43 44 45 |
# File 'lib/rails/vault/jwt/token_provider/base_provider.rb', line 43 def token_valid? !@token.nil? && !token_expired? end |