Skip to content

Commit 9880ba5

Browse files
yaozheng-fangclaude
andcommitted
fix(runtime): don't generate an API key name for custom_jwt deploys
`_prepare_runtime_config` generated (and logged "Generated API key name:") an API key whenever `runtime_apikey_name` was "Auto", regardless of auth type. For `custom_jwt`, the gateway authorizes via JWT and never uses an API key (`_build_authorizer_config_for_create` only reads the name in the key_auth branch), so the generated key was unused and the log line was misleading. Skip generation/logging when auth type is custom_jwt. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0d8f01c commit 9880ba5

2 files changed

Lines changed: 58 additions & 2 deletions

File tree

agentkit/toolkit/runners/ve_agentkit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,11 @@ def _prepare_runtime_config(self, config: VeAgentkitRunnerConfig) -> bool:
585585
f"Generated role name: {config.runtime_role_name}"
586586
)
587587

588-
# Generate API key name if not provided
589-
if (
588+
# Generate API key name if not provided. Skipped for custom_jwt: the
589+
# gateway authorizes via JWT and never uses an API key (see
590+
# _build_authorizer_config_for_create), so generating one here only
591+
# produced a misleading "Generated API key name" line.
592+
if config.runtime_auth_type != AUTH_TYPE_CUSTOM_JWT and (
590593
config.runtime_apikey_name == AUTO_CREATE_VE
591594
or not config.runtime_apikey_name
592595
):
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) 2026 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""`_prepare_runtime_config` API-key-name generation is gated on auth type."""
16+
17+
from agentkit.toolkit.config.constants import (
18+
AUTH_TYPE_CUSTOM_JWT,
19+
AUTH_TYPE_KEY_AUTH,
20+
AUTO_CREATE_VE,
21+
)
22+
from agentkit.toolkit.runners.ve_agentkit import (
23+
VeAgentkitRunnerConfig,
24+
VeAgentkitRuntimeRunner,
25+
)
26+
27+
28+
def _config(auth_type: str) -> VeAgentkitRunnerConfig:
29+
# Pin name/role so only the API-key-name branch is exercised.
30+
return VeAgentkitRunnerConfig(
31+
runtime_name="rt",
32+
runtime_role_name="role",
33+
runtime_apikey_name=AUTO_CREATE_VE,
34+
runtime_auth_type=auth_type,
35+
)
36+
37+
38+
def test_custom_jwt_does_not_generate_api_key_name():
39+
runner = VeAgentkitRuntimeRunner()
40+
cfg = _config(AUTH_TYPE_CUSTOM_JWT)
41+
42+
assert runner._prepare_runtime_config(cfg) is True
43+
# custom_jwt authorizes via JWT, so no API key name is generated.
44+
assert cfg.runtime_apikey_name == AUTO_CREATE_VE
45+
46+
47+
def test_key_auth_still_generates_api_key_name():
48+
runner = VeAgentkitRuntimeRunner()
49+
cfg = _config(AUTH_TYPE_KEY_AUTH)
50+
51+
assert runner._prepare_runtime_config(cfg) is True
52+
# key_auth uses the API key name, so it is generated (no longer "Auto").
53+
assert cfg.runtime_apikey_name not in (AUTO_CREATE_VE, "")

0 commit comments

Comments
 (0)