2727from veadk .integrations .ve_identity .identity_client import IdentityClient
2828
2929
30+ def _get_default_region () -> str :
31+ """Get the default region from VeADK configuration.
32+
33+ Returns:
34+ The configured region from VeIdentityConfig, or "cn-beijing" as fallback.
35+ """
36+ try :
37+ from veadk .config import settings
38+ return settings .veidentity .region
39+ except Exception :
40+ # Fallback to default if config loading fails
41+ return "cn-beijing"
42+
43+
3044class AuthConfig (BaseModel , ABC ):
3145 """Base authentication configuration."""
3246
3347 model_config = {"arbitrary_types_allowed" : True }
3448
3549 provider_name : str
3650 identity_client : Optional [IdentityClient ] = None
37- region : str = "cn-beijing"
51+ region : str = None # Will be set to default from config if not provided
52+
53+ def __init__ (self , ** data ):
54+ """Initialize AuthConfig with default region from VeADK config if not provided."""
55+ if 'region' not in data or data ['region' ] is None :
56+ data ['region' ] = _get_default_region ()
57+ super ().__init__ (** data )
3858
3959 @field_validator ("provider_name" )
4060 @classmethod
@@ -138,9 +158,20 @@ def auth_type(self) -> str:
138158def api_key_auth (
139159 provider_name : str ,
140160 identity_client : Optional [IdentityClient ] = None ,
141- region : str = "cn-beijing" ,
161+ region : Optional [ str ] = None ,
142162) -> ApiKeyAuthConfig :
143- """Create an API key authentication configuration."""
163+ """Create an API key authentication configuration.
164+
165+ Args:
166+ provider_name: Name of the credential provider.
167+ identity_client: Optional IdentityClient instance.
168+ region: VolcEngine region. If not provided, uses the region from VeADK config.
169+
170+ Returns:
171+ ApiKeyAuthConfig instance.
172+ """
173+ if region is None :
174+ region = _get_default_region ()
144175 return ApiKeyAuthConfig (
145176 provider_name = provider_name , identity_client = identity_client , region = region
146177 )
@@ -149,9 +180,20 @@ def api_key_auth(
149180def workload_auth (
150181 provider_name : str ,
151182 identity_client : Optional [IdentityClient ] = None ,
152- region : str = "cn-beijing" ,
183+ region : Optional [ str ] = None ,
153184) -> WorkloadAuthConfig :
154- """Create a workload authentication configuration."""
185+ """Create a workload authentication configuration.
186+
187+ Args:
188+ provider_name: Name of the credential provider.
189+ identity_client: Optional IdentityClient instance.
190+ region: VolcEngine region. If not provided, uses the region from VeADK config.
191+
192+ Returns:
193+ WorkloadAuthConfig instance.
194+ """
195+ if region is None :
196+ region = _get_default_region ()
155197 return WorkloadAuthConfig (
156198 provider_name = provider_name , identity_client = identity_client , region = region
157199 )
@@ -167,9 +209,27 @@ def oauth2_auth(
167209 on_auth_url : Optional [Callable [[str ], Any ]] = None ,
168210 oauth2_auth_poller : Optional [Callable [[Any ], OAuth2AuthPoller ]] = None ,
169211 identity_client : Optional [IdentityClient ] = None ,
170- region : str = "cn-beijing" ,
212+ region : Optional [ str ] = None ,
171213) -> OAuth2AuthConfig :
172- """Create an OAuth2 authentication configuration."""
214+ """Create an OAuth2 authentication configuration.
215+
216+ Args:
217+ provider_name: Name of the credential provider.
218+ scopes: List of OAuth2 scopes.
219+ auth_flow: Authentication flow type ("M2M" or "USER_FEDERATION").
220+ callback_url: Optional callback URL for OAuth2.
221+ force_authentication: Whether to force authentication.
222+ response_for_auth_required: Response to return when auth is required.
223+ on_auth_url: Callback function for auth URL.
224+ oauth2_auth_poller: Callback function for auth polling.
225+ identity_client: Optional IdentityClient instance.
226+ region: VolcEngine region. If not provided, uses the region from VeADK config.
227+
228+ Returns:
229+ OAuth2AuthConfig instance.
230+ """
231+ if region is None :
232+ region = _get_default_region ()
173233 return OAuth2AuthConfig (
174234 provider_name = provider_name ,
175235 scopes = scopes ,
0 commit comments