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 Service Principal token.
docstr_tok: ["Get","Service","Principal","token","."]
code: def _get_sp_token(self, resource: str) -> str:
      """Get Service Principal token."""
      sp_token = self.oauth_tokens.get(resource)
      if sp_token and self._is_oauth_token_valid(sp_token):
          return sp_token["access_token"]
  
      self.log.info(
          "Existing Service Principal token is expired, or going to expire soon. Refreshing..."
      )
      try:
          for attempt in self._get_retry_object():
              with attempt:
                  resp = requests.post(
                      resource,
                      auth=HTTPBasicAuth(
                          self.databricks_conn.login,
                          self.databricks_conn.password,
                      ),
                      data="grant_type=client_credentials&scope=all-apis",
                      headers={
                          **self.user_agent_header,
                          "Content-Type": "application/x-www-form-urlencoded",
                      },
                      timeout=self.token_timeout_seconds,
                  )
  
                  resp.raise_for_status()
                  jsn = resp.json()
                  jsn["expires_on"] = int(
                      time.time() + jsn["expires_in"]
                  )
  
                  self._is_oauth_token_valid(jsn)
                  self.oauth_tokens[resource] = jsn
                  break
      except RetryError:
          raise AirflowException(
              f"API requests to Databricks 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 10 for calling the BaseDatabricksHook obj's underlying member method code with example usage: obj._get_sp_token(resource) and returns: jsn, sp_token