Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the way to get STS endpoint in EKS hook #45520

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions providers/src/airflow/providers/amazon/aws/hooks/eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from botocore.signers import RequestSigner

from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.providers.amazon.aws.hooks.sts import StsHook
from airflow.utils import yaml
from airflow.utils.json import AirflowJsonEncoder

Expand Down Expand Up @@ -612,8 +613,7 @@ def generate_config_file(
def fetch_access_token_for_cluster(self, eks_cluster_name: str) -> str:
session = self.get_session()
service_id = self.conn.meta.service_model.service_id
sts_client = session.client("sts")
sts_url = f"{sts_client.meta.endpoint_url}/?Action=GetCallerIdentity&Version=2011-06-15"
sts_url = f"{StsHook().conn_client_meta.endpoint_url}/?Action=GetCallerIdentity&Version=2011-06-15"

signer = RequestSigner(
service_id=service_id,
Expand Down
8 changes: 3 additions & 5 deletions providers/tests/amazon/aws/hooks/test_eks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from pathlib import Path
from typing import TYPE_CHECKING
from unittest import mock
from unittest.mock import Mock
from urllib.parse import urlsplit

import pytest
Expand Down Expand Up @@ -1284,14 +1283,13 @@ def test_generate_config_file(self, mock_conn, aws_conn_id, region_name, expecte
}

@mock.patch("airflow.providers.amazon.aws.hooks.eks.RequestSigner")
@mock.patch("airflow.providers.amazon.aws.hooks.eks.StsHook")
@mock.patch("airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook.conn")
@mock.patch("airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook.get_session")
def test_fetch_access_token_for_cluster(self, mock_get_session, mock_conn, mock_signer):
def test_fetch_access_token_for_cluster(self, mock_get_session, mock_conn, mock_sts_hook, mock_signer):
mock_signer.return_value.generate_presigned_url.return_value = "http://example.com"
mock_get_session.return_value.region_name = "us-east-1"
client = Mock()
client.meta.endpoint_url = "https://sts.us-east-1.amazonaws.com"
mock_get_session.return_value.client.return_value = client
mock_sts_hook.return_value.conn_client_meta.endpoint_url = "https://sts.us-east-1.amazonaws.com"
hook = EksHook()
token = hook.fetch_access_token_for_cluster(eks_cluster_name="test-cluster")
mock_signer.assert_called_once_with(
Expand Down