class Azure::Auth::TokenProvider::AzureCliTokenSource
A token source that gets token using cli tool az
Constants
- AZ_GET_TOKEN
- BASH
- DEFAULT_AZ_PATH
Public Instance Methods
token(resource)
click to toggle source
Returns an access token from cli tool az @param resource [Stirng] Azure
resource URI string. @return [AzureMSITokenProvider::Token]
# File lib/azure/auth/token_provider/azure_cli_token_source.rb, line 45 def token(resource) if Gem.win_platform? token_windows(resource) else token_nix(resource) end end
Private Instance Methods
parse_json_token(token_src)
click to toggle source
# File lib/azure/auth/token_provider/azure_cli_token_source.rb, line 75 def parse_json_token(token_src) token_hash = JSON.parse(token_src) Token.new( token_hash['accessToken'], Time.parse(token_hash['expiresOn']), token_hash['tokenType'], read_ext(token_hash) ) end
read_ext(token_hash)
click to toggle source
# File lib/azure/auth/token_provider/azure_cli_token_source.rb, line 85 def read_ext(token_hash) { subscription: token_hash['subscription'], tenant: token_hash['tenant'] } end
token_nix(resource)
click to toggle source
Calls az on *nix OS @return [AzureMSITokenProvider::Token]
# File lib/azure/auth/token_provider/azure_cli_token_source.rb, line 64 def token_nix(resource) Open3.popen2( { 'PATH' => DEFAULT_AZ_PATH }, "#{BASH} #{AZ_GET_TOKEN} --resource #{resource}" ) do |_, o, t| return nil unless t.value == 0 return parse_json_token(o.read) end end
token_windows(_resource)
click to toggle source
Calls az on windows OS @return [AzureMSITokenProvider::Token]
# File lib/azure/auth/token_provider/azure_cli_token_source.rb, line 57 def token_windows(_resource) # TODO nil end