class_docstr: Base for interaction with Databricks.
  
  :param databricks_conn_id: Reference to the :ref:`Databricks connection <howto/connection:databricks>`.
  :param timeout_seconds: The amount of time in seconds the requests library
      will wait before timing-out.
  :param retry_limit: The number of times to retry the connection in case of
      service outages.
  :param retry_delay: The number of seconds to wait between retries (it
      might be a floating point number).
  :param retry_args: An optional dictionary with arguments passed to ``tenacity.Retrying`` class.
class_docstr_tok: ["Base","for","interaction","with","Databricks",".",":","param","databricks_conn_id",":","Reference","to","the",":","ref",":","`","Databricks","connection","<","howto\/connection",":","databricks",">","`",".",":","param","timeout_seconds",":","The","amount","of","time","in","seconds","the","requests","library","will","wait","before","timing-out",".",":","param","retry_limit",":","The","number","of","times","to","retry","the","connection","in","case","of","service","outages",".",":","param","retry_delay",":","The","number","of","seconds","to","wait","between","retries","(","it","might","be","a","floating","point","number",")",".",":","param","retry_args",":","An","optional","dictionary","with","arguments","passed","to","``","tenacity.Retrying","``","class","."]
docstr: Get AAD token for given resource.
  
  Supports managed identity or service principal auth.
  :param resource: resource to issue token to
  :return: AAD token, or raise an exception
docstr_tok: ["Get","AAD","token","for","given","resource",".","Supports","managed","identity","or","service","principal","auth",".",":","param","resource",":","resource","to","issue","token","to",":","return",":","AAD","token",",","or","raise","an","exception"]
code: def _get_aad_token(self, resource: str) -> str:
      """
      Get AAD token for given resource.
  
      Supports managed identity or service principal auth.
      :param resource: resource to issue token to
      :return: AAD token, or raise an exception
      """
      aad_token = self.oauth_tokens.get(resource)
      if aad_token and self._is_oauth_token_valid(aad_token):
          return aad_token["access_token"]
  
      self.log.info(
          "Existing AAD token is expired, or going to expire soon. Refreshing..."
      )
      try:
          for attempt in self._get_retry_object():
              with attempt:
                  if self.databricks_conn.extra_dejson.get(
                      "use_azure_managed_identity", False
                  ):
                      params = {
                          "api-version": "2018-02-01",
                          "resource": resource,
                      }
                      resp = requests.get(
                          AZURE_METADATA_SERVICE_TOKEN_URL,
                          params=params,
                          headers={
                              **self.user_agent_header,
                              "Metadata": "true",
                          },
                          timeout=self.token_timeout_seconds,
                      )
                  else:
                      tenant_id = self.databricks_conn.extra_dejson[
                          "azure_tenant_id"
                      ]
                      data = {
                          "grant_type": "client_credentials",
                          "client_id": self.databricks_conn.login,
                          "resource": resource,
                          "client_secret": self.databricks_conn.password,
                      }
                      azure_ad_endpoint = (
                          self.databricks_conn.extra_dejson.get(
                              "azure_ad_endpoint",
                              AZURE_DEFAULT_AD_ENDPOINT,
                          )
                      )
                      resp = requests.post(
                          AZURE_TOKEN_SERVICE_URL.format(
                              azure_ad_endpoint, tenant_id
                          ),
                          data=data,
                          headers={
                              **self.user_agent_header,
                              "Content-Type": "application/x-www-form-urlencoded",
                          },
                          timeout=self.token_timeout_seconds,
                      )
  
                  resp.raise_for_status()
                  jsn = resp.json()
  
                  self._is_oauth_token_valid(jsn)
                  self.oauth_tokens[resource] = jsn
                  break
      except RetryError:
          raise AirflowException(
              f"API requests to Azure failed {self.retry_limit} times. Giving up."
          )
      except requests_exceptions.HTTPError as e:
          msg = f"Response: {e.response.content.decode()}, Status Code: {e.response.status_code}"
          raise AirflowException(msg)
  
      return jsn["access_token"]
  
imports: from __future__ import annotations
  import copy
  import platform
  import time
  from functools import cached_property
  from typing import TYPE_CHECKING, Any
  from urllib.parse import urlsplit
  import aiohttp
  import requests
  from requests import PreparedRequest, exceptions
  from requests.auth import AuthBase, HTTPBasicAuth
  from requests.exceptions import JSONDecodeError
  from tenacity import AsyncRetrying, RetryError, Retrying, retry_if_exception, stop_after_attempt, wait_exponential
  from airflow import __version__
  from airflow.exceptions import AirflowException
  from airflow.hooks.base import BaseHook
  from airflow.providers_manager import ProvidersManager
label_desc: Use image node_id 11 for calling the BaseDatabricksHook obj's underlying member method code with example usage: obj._get_aad_token(resource) and returns: jsn, aad_token