Skip to content

Commit c63e923

Browse files
committed
feat: deploy with API key authentication
Signed-off-by: Xie Zhihao <[email protected]>
1 parent 9d42b34 commit c63e923

File tree

8 files changed

+46
-4
lines changed

8 files changed

+46
-4
lines changed

veadk/cli/cli_deploy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
type=click.Choice(["local", "mysql"]),
5050
help="Backend for short-term memory",
5151
)
52+
@click.option(
53+
"--auth-method",
54+
default="none",
55+
type=click.Choice(["none", "api-key"]),
56+
help="=Authentication method for agent",
57+
)
5258
@click.option("--use-adk-web", is_flag=True, help="Whether to use ADK Web")
5359
@click.option("--path", default=".", help="Local project path")
5460
def deploy(
@@ -60,6 +66,7 @@ def deploy(
6066
veapig_upstream_name: str,
6167
short_term_memory_backend: str,
6268
use_adk_web: bool,
69+
auth_method: str,
6370
path: str,
6471
) -> None:
6572
"""Deploy a user project to Volcengine FaaS application.
@@ -90,6 +97,8 @@ def deploy(
9097
short_term_memory_backend: Backend type for short-term memory storage.
9198
Choices are 'local' or 'mysql'
9299
use_adk_web: Flag to enable ADK Web interface for the deployed agent
100+
auth_method: Authentication for the agent.
101+
Choices are 'none', 'api-key' or 'oauth2'.
93102
path: Local directory path containing the VeADK project to deploy
94103
95104
Note:
@@ -131,6 +140,7 @@ def deploy(
131140
"veapig_service_name": veapig_service_name,
132141
"veapig_upstream_name": veapig_upstream_name,
133142
"use_adk_web": use_adk_web,
143+
"auth_method": auth_method,
134144
"veadk_version": VERSION,
135145
}
136146

veadk/cli/cli_init.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,33 @@ def _render_prompts() -> dict[str, Any]:
6161
deploy_mode = click.prompt(
6262
"Enter your choice", type=click.Choice(deploy_mode_options.keys())
6363
)
64+
use_adk_web = deploy_mode == "2"
65+
66+
auth_method_options = {
67+
"1": "None",
68+
"2": "API key",
69+
}
70+
auth_methods = {
71+
"1": "none",
72+
"2": "api-key",
73+
}
74+
75+
click.echo("Choose an authentication method:")
76+
for key, value in auth_method_options.items():
77+
click.echo(f" {key}. {value}")
78+
79+
auth_method_idx = click.prompt(
80+
"Enter your choice", type=click.Choice(auth_method_options.keys())
81+
)
82+
auth_method = auth_methods[auth_method_idx]
6483

6584
return {
6685
"vefaas_application_name": vefaas_application_name,
6786
"veapig_instance_name": veapig_instance_name,
6887
"veapig_service_name": veapig_service_name,
6988
"veapig_upstream_name": veapig_upstream_name,
70-
"use_adk_web": deploy_mode == "2",
89+
"use_adk_web": use_adk_web,
90+
"auth_method": auth_method,
7191
"veadk_version": VERSION,
7292
}
7393

veadk/cloud/cloud_agent_engine.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def deploy(
197197
gateway_name: str = "",
198198
gateway_service_name: str = "",
199199
gateway_upstream_name: str = "",
200+
auth_method: str = "none",
200201
use_adk_web: bool = False,
201202
local_test: bool = False,
202203
) -> CloudApp:
@@ -210,6 +211,7 @@ def deploy(
210211
gateway_name (str, optional): Custom gateway resource name. Defaults to timestamped.
211212
gateway_service_name (str, optional): Custom service name. Defaults to timestamped.
212213
gateway_upstream_name (str, optional): Custom upstream name. Defaults to timestamped.
214+
auth_method (str, optional): Authentication for the agent. Defaults to none.
213215
use_adk_web (bool): Enable ADK Web configuration. Defaults to False.
214216
local_test (bool): Perform FastAPI server test before deploy. Defaults to False.
215217
@@ -232,6 +234,10 @@ def deploy(
232234
# prevent deepeval writing operations
233235
veadk_environments["DEEPEVAL_TELEMETRY_OPT_OUT"] = "YES"
234236

237+
enable_key_auth = False
238+
if auth_method == "api-key":
239+
enable_key_auth = True
240+
235241
if use_adk_web:
236242
veadk_environments["USE_ADK_WEB"] = "True"
237243
else:
@@ -258,6 +264,7 @@ def deploy(
258264
gateway_name=gateway_name,
259265
gateway_service_name=gateway_service_name,
260266
gateway_upstream_name=gateway_upstream_name,
267+
enable_key_auth=enable_key_auth,
261268
)
262269
_ = function_id # for future use
263270

veadk/integrations/ve_faas/template/cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"veapig_service_name": "",
99
"veapig_upstream_name": "",
1010
"use_adk_web": false,
11+
"auth_method": "none",
1112
"veadk_version": ""
1213
}

veadk/integrations/ve_faas/template/{{cookiecutter.local_dir_name}}/deploy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async def main():
8484
gateway_service_name="{{cookiecutter.veapig_service_name}}",
8585
gateway_upstream_name="{{cookiecutter.veapig_upstream_name}}",
8686
use_adk_web={{cookiecutter.use_adk_web}},
87+
auth_method="{{cookiecutter.auth_method}}",
8788
local_test=False, # Set to True for local testing before deploy to VeFaaS
8889
)
8990
print(f"VeFaaS application ID: {cloud_app.vefaas_application_id}")

veadk/integrations/ve_faas/ve_faas.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414

1515
import json
16-
import os
1716
import time
1817

1918
import requests
@@ -141,9 +140,8 @@ def _create_application(
141140
gateway_name: str,
142141
upstream_name: str,
143142
service_name: str,
143+
enable_key_auth: bool = False,
144144
):
145-
enable_key_auth = os.getenv("VEFAAS_ENABLE_KEY_AUTH", "true").lower() == "true"
146-
147145
response = ve_request(
148146
request_body={
149147
"Name": application_name,
@@ -386,6 +384,7 @@ def deploy(
386384
gateway_name: str = "",
387385
gateway_service_name: str = "",
388386
gateway_upstream_name: str = "",
387+
enable_key_auth: bool = False,
389388
) -> tuple[str, str, str]:
390389
"""Deploy an agent project to VeFaaS service.
391390
@@ -395,6 +394,7 @@ def deploy(
395394
gateway_name (str, optional): Gateway name. Defaults to "".
396395
gateway_service_name (str, optional): Gateway service name. Defaults to "".
397396
gateway_upstream_name (str, optional): Gateway upstream name. Defaults to "".
397+
enable_key_auth (bool, optional): Enable key auth. Defaults to False.
398398
399399
Returns:
400400
tuple[str, str, str]: (url, app_id, function_id)
@@ -439,6 +439,7 @@ def deploy(
439439
gateway_name,
440440
gateway_upstream_name,
441441
gateway_service_name,
442+
enable_key_auth,
442443
)
443444

444445
logger.info(f"VeFaaS application {name} with ID {app_id} created.")

veadk/integrations/ve_faas/web_template/cookiecutter.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"veapig_service_name": "",
77
"veapig_upstream_name": "",
88
"use_adk_web": false,
9+
"auth_method": "none",
910
"veadk_version": "",
1011
"_copy_without_render": [
1112
"*.html",

veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/deploy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async def main():
2727
gateway_service_name="{{cookiecutter.veapig_service_name}}",
2828
gateway_upstream_name="{{cookiecutter.veapig_upstream_name}}",
2929
use_adk_web={{cookiecutter.use_adk_web}},
30+
auth_method="{{cookiecutter.auth_method}}",
3031
local_test=False, # Set to True for local testing before deploy to VeFaaS
3132
)
3233
print(f"VeFaaS application ID: {cloud_app.vefaas_application_id}")

0 commit comments

Comments
 (0)