Class: AzCliTokenProvider
- Inherits:
-
AbstractTokenProvider
- Object
- AbstractTokenProvider
- AzCliTokenProvider
- Defined in:
- lib/fluent/plugin/auth/azcli_tokenprovider.rb
Instance Method Summary collapse
- #acquire_token(resource) ⇒ Object
-
#fetch_token ⇒ Object
Use get_token from base class for token retrieval.
-
#initialize(outconfiguration) ⇒ AzCliTokenProvider
constructor
A new instance of AzCliTokenProvider.
- #locate_azure_cli ⇒ Object
Methods inherited from AbstractTokenProvider
#get_health_status, #get_token, #health_status, #log_health_status
Constructor Details
#initialize(outconfiguration) ⇒ AzCliTokenProvider
Returns a new instance of AzCliTokenProvider.
10 11 12 13 |
# File 'lib/fluent/plugin/auth/azcli_tokenprovider.rb', line 10 def initialize(outconfiguration) super(outconfiguration) @resource = outconfiguration.kusto_endpoint end |
Instance Method Details
#acquire_token(resource) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fluent/plugin/auth/azcli_tokenprovider.rb', line 27 def acquire_token(resource) az_cli = locate_azure_cli # Properly escape the Azure CLI executable path to prevent command injection escaped_az_cli = Shellwords.escape(az_cli) escaped_resource = Shellwords.escape(resource) cmd = [escaped_az_cli, 'account', 'get-access-token', '--resource', escaped_resource, '--output', 'json'] stdout, stderr, status = Open3.capture3(*cmd) raise "Failed to acquire Azure CLI token: #{stderr.strip}" if !status.success? && !status.success? JSON.parse(stdout) rescue Errno::ENOENT raise "Azure CLI not found. Please install Azure CLI and run 'az login'." end |
#fetch_token ⇒ Object
Use get_token from base class for token retrieval
17 18 19 20 21 22 23 24 25 |
# File 'lib/fluent/plugin/auth/azcli_tokenprovider.rb', line 17 def fetch_token token = acquire_token(@resource) raise "No valid Azure CLI token found for resource: #{@resource}" unless token { access_token: token['accessToken'], expires_in: (Time.parse(token['expiresOn']) - Time.now).to_i } end |
#locate_azure_cli ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fluent/plugin/auth/azcli_tokenprovider.rb', line 41 def locate_azure_cli exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = File.join(path, "az#{ext}") return exe if File.executable?(exe) && !File.directory?(exe) end end raise "Azure CLI executable 'az' not found in PATH." end |