Skip to content

Commit ec0b159

Browse files
committed
deploy/run env var
1 parent 01183a8 commit ec0b159

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import base64
2+
import json
3+
4+
from agentex.lib.sdk.config.agent_manifest import AgentManifest
5+
6+
7+
# Base 64 encode principal dictionary
8+
def _encode_principal_context(manifest: AgentManifest):
9+
if manifest.auth is None:
10+
return None
11+
12+
principal = manifest.auth.principal
13+
if principal is None:
14+
return None
15+
16+
json_str = json.dumps(principal, separators=(',', ':'))
17+
encoded_bytes = base64.b64encode(json_str.encode('utf-8'))
18+
return encoded_bytes.decode('utf-8')

src/agentex/lib/cli/handlers/deploy_handlers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
from pydantic import BaseModel, Field
99
from rich.console import Console
1010

11+
from agentex.lib.cli.handlers.auth_handlers import _encode_principal_context
1112
from agentex.lib.cli.utils.exceptions import DeploymentError, HelmError
1213
from agentex.lib.cli.utils.kubectl_utils import check_and_switch_cluster_context
14+
from agentex.lib.environment_variables import EnvVarKeys
1315
from agentex.lib.sdk.config.agent_config import AgentConfig
1416
from agentex.lib.sdk.config.agent_manifest import AgentManifest
1517
from agentex.lib.sdk.config.deployment_config import ClusterConfig
@@ -163,10 +165,13 @@ def merge_deployment_configs(
163165
helm_values[TEMPORAL_WORKER_KEY]["secretEnvVars"] = secret_env_vars
164166

165167
# Set the agent_config env vars first to the helm values and so then it can be overriden by the cluster config
168+
encoded_principal = _encode_principal_context(manifest)
166169
if agent_config.env:
167170
helm_values["env"] = agent_config.env
168171
if TEMPORAL_WORKER_KEY in helm_values:
169172
helm_values[TEMPORAL_WORKER_KEY]["env"] = agent_config.env
173+
if encoded_principal:
174+
helm_values["env"][EnvVarKeys.AUTH_PRINCIPAL_B64] = encoded_principal
170175

171176
if manifest.deployment and manifest.deployment.imagePullSecrets:
172177
pull_secrets = [

src/agentex/lib/cli/handlers/run_handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
from rich.console import Console
77
from rich.panel import Panel
88

9+
from agentex.lib.cli.handlers.auth_handlers import _encode_principal_context
910
from agentex.lib.cli.handlers.cleanup_handlers import (
1011
cleanup_agent_workflows,
1112
should_cleanup_on_restart
1213
)
14+
from agentex.lib.environment_variables import EnvVarKeys
1315
from agentex.lib.sdk.config.agent_manifest import AgentManifest
1416
from agentex.lib.utils.logging import make_logger
1517

@@ -427,6 +429,11 @@ def create_agent_environment(manifest: AgentManifest) -> dict[str, str]:
427429
"ACP_PORT": str(manifest.local_development.agent.port),
428430
}
429431

432+
# Add authorization principal if set
433+
encoded_principal = _encode_principal_context(manifest)
434+
if encoded_principal:
435+
env_vars[EnvVarKeys.AUTH_PRINCIPAL_B64] = encoded_principal
436+
430437
# Add description if available
431438
if manifest.agent.description:
432439
env_vars["AGENT_DESCRIPTION"] = manifest.agent.description

src/agentex/lib/environment_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EnvVarKeys(str, Enum):
2727
# Workflow Configuraiton
2828
WORKFLOW_NAME = "WORKFLOW_NAME"
2929
WORKFLOW_TASK_QUEUE = "WORKFLOW_TASK_QUEUE"
30-
BASE64_AUTH_PRINCIPAL = "BASE64_AUTH_PRINCIPAL"
30+
AUTH_PRINCIPAL_B64 = "AUTH_PRINCIPAL_B64"
3131

3232

3333
class Environment(str, Enum):

src/agentex/lib/sdk/config/agent_manifest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from agentex.lib.sdk.config.agent_config import AgentConfig
1717
from agentex.lib.sdk.config.build_config import BuildConfig
18-
from agentex.lib.sdk.config.deployment_config import DeploymentConfig
18+
from agentex.lib.sdk.config.deployment_config import DeploymentConfig, AuthenticationConfig
1919
from agentex.lib.sdk.config.local_development_config import LocalDevelopmentConfig
2020
from agentex.lib.utils.logging import make_logger
2121
from agentex.lib.utils.model_utils import BaseModel
@@ -36,6 +36,7 @@ class AgentManifest(BaseModel):
3636
deployment: DeploymentConfig | None = Field(
3737
default=None, description="Deployment configuration for the agent"
3838
)
39+
auth: AuthenticationConfig | None = Field(default=None, description="Authentication configuration")
3940

4041
def context_manager(self, build_context_root: Path) -> BuildContextManager:
4142
"""

src/agentex/lib/sdk/config/deployment_config.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, Dict
22

33
from pydantic import Field
44

@@ -90,6 +90,10 @@ class ClusterConfig(BaseModel):
9090
)
9191

9292

93+
class AuthenticationConfig(BaseModel):
94+
principal: Dict[str, Any] = Field(description="Principal used for authorization on registration")
95+
96+
9397
class InjectedImagePullSecretValues(BaseModel):
9498
"""Values for image pull secrets"""
9599

0 commit comments

Comments
 (0)