Class: RubySnowflake::Client::KeyPairJwtAuthManager
- Inherits:
-
Object
- Object
- RubySnowflake::Client::KeyPairJwtAuthManager
- Defined in:
- lib/ruby_snowflake/client/key_pair_jwt_auth_manager.rb
Instance Method Summary collapse
-
#initialize(organization, account, user, private_key, jwt_token_ttl) ⇒ KeyPairJwtAuthManager
constructor
requires text of a PEM formatted RSA private key.
- #jwt_token ⇒ Object
Constructor Details
#initialize(organization, account, user, private_key, jwt_token_ttl) ⇒ KeyPairJwtAuthManager
requires text of a PEM formatted RSA private key
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_snowflake/client/key_pair_jwt_auth_manager.rb', line 11 def initialize(organization, account, user, private_key, jwt_token_ttl) @organization = organization @account = account @user = user @private_key_pem = private_key @jwt_token_ttl = jwt_token_ttl # start with an expired value to force creation @token_expires_at = Time.now.to_i - 1 @token_semaphore = Concurrent::Semaphore.new(1) end |
Instance Method Details
#jwt_token ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ruby_snowflake/client/key_pair_jwt_auth_manager.rb', line 23 def jwt_token return @token unless jwt_token_expired? @token_semaphore.acquire do now = Time.now.to_i @token_expires_at = now + @jwt_token_ttl private_key = OpenSSL::PKey.read(@private_key_pem) payload = { :iss => "#{@organization.upcase}-#{@account.upcase}.#{@user}.#{public_key_fingerprint}", :sub => "#{@organization.upcase}-#{@account.upcase}.#{@user}", :iat => now, :exp => @token_expires_at } @token = JWT.encode payload, private_key, "RS256" end end |