Skip to content

Commit 5b00f22

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents b7583d8 + 34db2c6 commit 5b00f22

File tree

3 files changed

+44
-27
lines changed

3 files changed

+44
-27
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "veadk-python"
3-
version = "0.2.23"
3+
version = "0.2.24"
44
description = "Volcengine agent development kit, integrations with Volcengine cloud services."
55
readme = "README.md"
66
requires-python = ">=3.10"

veadk/integrations/ve_identity/identity_client.py

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,38 +67,55 @@ def _refresh_creds(self: IdentityClient):
6767
"VOLCENGINE_SESSION_TOKEN", ""
6868
)
6969

70-
# If credentials are not available, try to get from VeFaaS IAM
71-
if not (ak and sk):
70+
# Helper function to attempt VeFaaS IAM credential retrieval
71+
def try_get_vefaas_credentials():
72+
"""Attempt to retrieve credentials from VeFaaS IAM."""
7273
try:
73-
logger.info(
74-
"Credentials not found in environment, attempting to fetch from VeFaaS IAM..."
75-
)
74+
logger.info("Attempting to fetch credentials from VeFaaS IAM...")
7675
ve_iam_cred = get_credential_from_vefaas_iam()
77-
ak = ve_iam_cred.access_key_id
78-
sk = ve_iam_cred.secret_access_key
79-
session_token = ve_iam_cred.session_token
80-
logger.info("Successfully retrieved credentials from VeFaaS IAM")
76+
return (
77+
ve_iam_cred.access_key_id,
78+
ve_iam_cred.secret_access_key,
79+
ve_iam_cred.session_token,
80+
)
8181
except FileNotFoundError as e:
8282
logger.warning(f"VeFaaS IAM credentials not available: {e}")
8383
except Exception as e:
8484
logger.warning(f"Failed to retrieve credentials from VeFaaS IAM: {e}")
85+
return None
8586

86-
if not session_token and ak and sk:
87-
role_trn = self._get_iam_role_trn_from_vefaas_iam()
88-
if not role_trn:
89-
role_trn = os.getenv("RUNTIME_IAM_ROLE_TRN", "")
90-
# If there is no session_token and role_trn is configured, execute AssumeRole
91-
if role_trn:
92-
try:
93-
logger.info(
94-
f"No session token found, attempting AssumeRole with role: {role_trn}"
95-
)
96-
sts_credentials = self._assume_role(ak, sk, role_trn)
97-
ak = sts_credentials.access_key_id
98-
sk = sts_credentials.secret_access_key
99-
session_token = sts_credentials.session_token
100-
except ApiException as e:
101-
logger.warning(f"Failed to assume role: {e.reason}")
87+
# If no AK/SK, try to get from VeFaaS IAM
88+
if not (ak and sk):
89+
logger.info(
90+
"Credentials not found in environment, attempting to fetch from VeFaaS IAM..."
91+
)
92+
credentials = try_get_vefaas_credentials()
93+
if credentials:
94+
ak, sk, session_token = credentials
95+
96+
# If we have AK/SK but no session token, try to get complete credentials
97+
if ak and sk and not session_token:
98+
# First attempt: try VeFaaS IAM
99+
credentials = try_get_vefaas_credentials()
100+
if credentials:
101+
ak, sk, session_token = credentials
102+
103+
# Second attempt: if still no session token, try AssumeRole
104+
if not session_token:
105+
role_trn = self._get_iam_role_trn_from_vefaas_iam() or os.getenv(
106+
"RUNTIME_IAM_ROLE_TRN", ""
107+
)
108+
109+
if role_trn:
110+
try:
111+
logger.info(f"Attempting AssumeRole with role: {role_trn}")
112+
sts_credentials = self._assume_role(ak, sk, role_trn)
113+
ak = sts_credentials.access_key_id
114+
sk = sts_credentials.secret_access_key
115+
session_token = sts_credentials.session_token
116+
logger.info("Successfully obtained credentials via AssumeRole")
117+
except Exception as e:
118+
logger.warning(f"Failed to assume role: {e}")
102119

103120
# Update configuration with the credentials
104121
self._api_client.api_client.configuration.ak = ak

veadk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
VERSION = "0.2.23"
15+
VERSION = "0.2.24"

0 commit comments

Comments
 (0)