1
1
from __future__ import annotations
2
2
3
3
from pathlib import Path
4
- from typing import Optional
4
+ from typing import List , Optional
5
5
6
+ from pydantic import field_validator , ValidationInfo
6
7
from pydantic_settings import BaseSettings , SettingsConfigDict
7
8
8
9
from agno .api .schemas .workspace import WorkspaceSchema
11
12
class WorkspaceSettings (BaseSettings ):
12
13
"""Workspace settings that can be used by any resource in the workspace."""
13
14
14
- # Workspace name: only used for naming cloud resources
15
+ # Workspace name
15
16
ws_name : str
16
17
# Path to the workspace root
17
18
ws_root : Path
18
19
# Workspace git repo url
19
20
ws_repo : Optional [str ] = None
20
- # default env for agno ws commands
21
+
22
+ # -*- Workspace Environments
23
+ dev_env : str = "dev"
24
+ dev_key : Optional [str ] = None
25
+ stg_env : str = "stg"
26
+ stg_key : Optional [str ] = None
27
+ prd_env : str = "prd"
28
+ prd_key : Optional [str ] = None
29
+
30
+ # default env for `agno ws` commands
21
31
default_env : Optional [str ] = "dev"
22
- # default infra for agno ws commands
32
+ # default infra for ` agno ws` commands
23
33
default_infra : Optional [str ] = None
24
34
25
- # Image Settings
35
+ # -*- Image Settings
26
36
# Repository for images
27
37
image_repo : str = "agnohq"
28
38
# 'Name:tag' for the image
@@ -36,7 +46,7 @@ class WorkspaceSettings(BaseSettings):
36
46
# Force pull images in FROM
37
47
force_pull_images : bool = False
38
48
39
- # ag cli settings
49
+ # -*- `ag` cli settings
40
50
# Set to True if Agno should continue creating
41
51
# resources after a resource creation has failed
42
52
continue_on_create_failure : bool = False
@@ -48,16 +58,69 @@ class WorkspaceSettings(BaseSettings):
48
58
# resources after a resource patch has failed
49
59
continue_on_patch_failure : bool = False
50
60
51
- # AWS settings
61
+ # -*- AWS settings
52
62
# Region for AWS resources
53
63
aws_region : Optional [str ] = None
54
64
# Profile for AWS resources
55
65
aws_profile : Optional [str ] = None
66
+ # Availability Zones for AWS resources
67
+ aws_az1 : Optional [str ] = None
68
+ aws_az2 : Optional [str ] = None
69
+ aws_az3 : Optional [str ] = None
70
+ # Subnets for AWS resources
71
+ aws_subnet_ids : Optional [List [str ]] = None
72
+ # Security Groups for AWS resources
73
+ aws_security_group_ids : Optional [List [str ]] = None
56
74
57
- # Other Settings
75
+ # -*- Other Settings
58
76
# Use cached resource if available, i.e. skip resource creation if the resource already exists
59
77
use_cache : bool = True
60
78
# WorkspaceSchema provided by the api
61
79
ws_schema : Optional [WorkspaceSchema ] = None
62
80
63
81
model_config = SettingsConfigDict (extra = "allow" )
82
+
83
+ @field_validator ("dev_key" , mode = "before" )
84
+ def set_dev_key (cls , dev_key , info : ValidationInfo ):
85
+ if dev_key is not None :
86
+ return dev_key
87
+
88
+ ws_name = info .data .get ("ws_name" )
89
+ if ws_name is None :
90
+ raise ValueError ("ws_name invalid" )
91
+
92
+ dev_env = info .data .get ("dev_env" )
93
+ if dev_env is None :
94
+ raise ValueError ("dev_env invalid" )
95
+
96
+ return f"{ ws_name } -{ dev_env } "
97
+
98
+ @field_validator ("stg_key" , mode = "before" )
99
+ def set_stg_key (cls , stg_key , info : ValidationInfo ):
100
+ if stg_key is not None :
101
+ return stg_key
102
+
103
+ ws_name = info .data .get ("ws_name" )
104
+ if ws_name is None :
105
+ raise ValueError ("ws_name invalid" )
106
+
107
+ stg_env = info .data .get ("stg_env" )
108
+ if stg_env is None :
109
+ raise ValueError ("stg_env invalid" )
110
+
111
+ return f"{ ws_name } -{ stg_env } "
112
+
113
+ @field_validator ("prd_key" , mode = "before" )
114
+ def set_prd_key (cls , prd_key , info : ValidationInfo ):
115
+ if prd_key is not None :
116
+ return prd_key
117
+
118
+ ws_name = info .data .get ("ws_name" )
119
+ if ws_name is None :
120
+ raise ValueError ("ws_name invalid" )
121
+
122
+ prd_env = info .data .get ("prd_env" )
123
+ if prd_env is None :
124
+ raise ValueError ("prd_env invalid" )
125
+
126
+ return f"{ ws_name } -{ prd_env } "
0 commit comments