class_docstr: Execute statements against Amazon Redshift.
  
  This hook requires the redshift_conn_id connection.
  
  Note: For AWS IAM authentication, use iam in the extra connection parameters
  and set it to true. Leave the password field empty. This will use the
  "aws_default" connection to get the temporary token unless you override
  with aws_conn_id when initializing the hook.
  The cluster-identifier is extracted from the beginning of
  the host field, so is optional. It can however be overridden in the extra field.
  extras example: ``{"iam":true}``
  
  :param redshift_conn_id: reference to
      :ref:`Amazon Redshift connection id<howto/connection:redshift>`
  
  .. note::
      get_sqlalchemy_engine() and get_uri() depend on sqlalchemy-amazon-redshift
class_docstr_tok: ["Execute","statements","against","Amazon","Redshift",".","This","hook","requires","the","redshift_conn_id","connection",".","Note",":","For","AWS","IAM","authentication",",","use","iam","in","the","extra","connection","parameters","and","set","it","to","true",".","Leave","the","password","field","empty",".","This","will","use","the","''","aws_default","''","connection","to","get","the","temporary","token","unless","you","override","with","aws_conn_id","when","initializing","the","hook",".","The","cluster-identifier","is","extracted","from","the","beginning","of","the","host","field",",","so","is","optional",".","It","can","however","be","overridden","in","the","extra","field",".","extras","example",":","``","{","``","iam","''",":","true","}","``",":","param","redshift_conn_id",":","reference","to",":","ref",":","`","Amazon","Redshift","connection","id","<","howto\/connection",":","redshift",">","`","..","note",":",":","get_sqlalchemy_engine","(",")","and","get_uri","(",")","depend","on","sqlalchemy-amazon-redshift"]
docstr: Retrieve a temporary password to connect to Redshift.
  
  Port is required. If none is provided, default is used for each service.
docstr_tok: ["Retrieve","a","temporary","password","to","connect","to","Redshift",".","Port","is","required",".","If","none","is","provided",",","default","is","used","for","each","service","."]
code: def get_iam_token(self, conn: Connection) -> tuple[str, str, int]:
      """Retrieve a temporary password to connect to Redshift.
  
      Port is required. If none is provided, default is used for each service.
      """
      port = conn.port or 5439
      is_serverless = conn.extra_dejson.get("is_serverless", False)
      if is_serverless:
          serverless_work_group = conn.extra_dejson.get(
              "serverless_work_group"
          )
          if not serverless_work_group:
              raise AirflowException(
                  "Please set serverless_work_group in redshift connection to use IAM with"
                  " Redshift Serverless."
              )
          serverless_token_duration_seconds = conn.extra_dejson.get(
              "serverless_token_duration_seconds", 3600
          )
          redshift_serverless_client = AwsBaseHook(
              aws_conn_id=self.aws_conn_id,
              client_type="redshift-serverless",
          ).conn
          # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift-serverless/client/get_credentials.html#get-credentials
          cluster_creds = redshift_serverless_client.get_credentials(
              dbName=conn.schema,
              workgroupName=serverless_work_group,
              durationSeconds=serverless_token_duration_seconds,
          )
          token = cluster_creds["dbPassword"]
          login = cluster_creds["dbUser"]
      else:
          # Pull the custer-identifier from the beginning of the Redshift URL
          # ex. my-cluster.ccdre4hpd39h.us-east-1.redshift.amazonaws.com returns my-cluster
          cluster_identifier = conn.extra_dejson.get(
              "cluster_identifier"
          )
          if not cluster_identifier:
              if conn.host:
                  cluster_identifier = conn.host.split(".", 1)[0]
              else:
                  raise AirflowException(
                      "Please set cluster_identifier or host in redshift connection."
                  )
          redshift_client = AwsBaseHook(
              aws_conn_id=self.aws_conn_id, client_type="redshift"
          ).conn
          # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift.html#Redshift.Client.get_cluster_credentials
          cluster_creds = redshift_client.get_cluster_credentials(
              DbUser=conn.login,
              DbName=conn.schema,
              ClusterIdentifier=cluster_identifier,
              AutoCreate=False,
          )
          token = cluster_creds["DbPassword"]
          login = cluster_creds["DbUser"]
      return login, token, port
  
imports: from __future__ import annotations
  from functools import cached_property
  from typing import TYPE_CHECKING
  import redshift_connector
  from redshift_connector import Connection
  from sqlalchemy import create_engine
  from sqlalchemy.engine.url import URL
  from airflow.exceptions import AirflowException
  from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
  from airflow.providers.common.sql.hooks.sql import DbApiHook
label_desc: Use image node_id 5 for calling the RedshiftSQLHook obj's underlying member method code with example usage: obj.get_iam_token(conn) and returns: login,  token,  port