@@ -650,7 +650,9 @@ pub(super) async fn resolve_dynamic_credentials_with_catalog(
650650
651651 let profile_id =
652652 normalize_provider_type ( & provider. r#type ) . unwrap_or ( provider. r#type . as_str ( ) ) ;
653- let Some ( profile) = get_provider_type_profile_with_catalog ( catalog, profile_id) else {
653+ let Some ( profile) =
654+ get_provider_type_profile_for_scope ( catalog, profile_id, & provider. profile_workspace )
655+ else {
654656 continue ;
655657 } ;
656658
@@ -1092,7 +1094,9 @@ fn dynamic_token_grant_bindings_for_provider_with_catalog(
10921094) -> Vec < DynamicTokenGrantBinding > {
10931095 let provider_name = provider. object_name ( ) . to_string ( ) ;
10941096 let profile_id = normalize_provider_type ( & provider. r#type ) . unwrap_or ( provider. r#type . as_str ( ) ) ;
1095- let Some ( profile) = get_provider_type_profile_with_catalog ( catalog, profile_id) else {
1097+ let Some ( profile) =
1098+ get_provider_type_profile_for_scope ( catalog, profile_id, & provider. profile_workspace )
1099+ else {
10961100 return Vec :: new ( ) ;
10971101 } ;
10981102 dynamic_token_grant_bindings_for_profile ( & provider_name, & profile. to_proto ( ) )
@@ -1759,6 +1763,14 @@ pub(super) fn get_provider_type_profile_with_catalog(
17591763 catalog. get_type_profile ( id)
17601764}
17611765
1766+ pub ( super ) fn get_provider_type_profile_for_scope (
1767+ catalog : & EffectiveProviderProfileCatalog ,
1768+ id : & str ,
1769+ profile_workspace : & str ,
1770+ ) -> Option < ProviderTypeProfile > {
1771+ catalog. get_type_profile_for_scope ( id, profile_workspace)
1772+ }
1773+
17621774#[ cfg( test) ]
17631775pub ( super ) async fn get_provider_type_profile (
17641776 store : & Store ,
@@ -1796,7 +1808,11 @@ fn provider_refresh_defaults(
17961808 provider : & Provider ,
17971809 credential_key : & str ,
17981810) -> Option < CredentialRefreshProfile > {
1799- let profile = get_provider_type_profile_with_catalog ( catalog, & provider. r#type ) ?;
1811+ let profile = get_provider_type_profile_for_scope (
1812+ catalog,
1813+ & provider. r#type ,
1814+ & provider. profile_workspace ,
1815+ ) ?;
18001816 profile
18011817 . credentials
18021818 . iter ( )
@@ -1819,7 +1835,9 @@ fn resolved_additional_output_keys(
18191835 provider : & Provider ,
18201836 credential_key : & str ,
18211837) -> HashMap < String , String > {
1822- let Some ( profile) = get_provider_type_profile_with_catalog ( catalog, & provider. r#type ) else {
1838+ let Some ( profile) =
1839+ get_provider_type_profile_for_scope ( catalog, & provider. r#type , & provider. profile_workspace )
1840+ else {
18231841 return HashMap :: new ( ) ;
18241842 } ;
18251843 profile. resolved_additional_output_keys ( credential_key)
@@ -9282,4 +9300,102 @@ mod tests {
92829300 "workspace profile should NOT appear in global list"
92839301 ) ;
92849302 }
9303+
9304+ #[ tokio:: test]
9305+ async fn global_profile_provider_resolves_platform_profile_at_runtime ( ) {
9306+ let state = test_server_state ( ) . await ;
9307+
9308+ let mut platform_profile = custom_profile ( "scope-test" ) ;
9309+ platform_profile. display_name = "Platform Version" . to_string ( ) ;
9310+ handle_import_provider_profiles (
9311+ & state,
9312+ Request :: new ( ImportProviderProfilesRequest {
9313+ profiles : vec ! [ ProviderProfileImportItem {
9314+ profile: Some ( platform_profile) ,
9315+ source: "scope-test.yaml" . to_string( ) ,
9316+ } ] ,
9317+ workspace : String :: new ( ) ,
9318+ } ) ,
9319+ )
9320+ . await
9321+ . unwrap ( ) ;
9322+
9323+ let mut ws_profile = custom_profile ( "scope-test" ) ;
9324+ ws_profile. display_name = "Workspace Version" . to_string ( ) ;
9325+ handle_import_provider_profiles (
9326+ & state,
9327+ Request :: new ( ImportProviderProfilesRequest {
9328+ profiles : vec ! [ ProviderProfileImportItem {
9329+ profile: Some ( ws_profile) ,
9330+ source: "scope-test.yaml" . to_string( ) ,
9331+ } ] ,
9332+ workspace : "default" . to_string ( ) ,
9333+ } ) ,
9334+ )
9335+ . await
9336+ . unwrap ( ) ;
9337+
9338+ let catalog = state
9339+ . provider_profile_sources
9340+ . snapshot_catalog ( state. store . as_ref ( ) , "default" )
9341+ . await
9342+ . unwrap ( ) ;
9343+
9344+ let global_result = catalog. get_type_profile_for_scope ( "scope-test" , "" ) ;
9345+ assert ! ( global_result. is_some( ) ) ;
9346+ assert_eq ! (
9347+ global_result. unwrap( ) . display_name,
9348+ "Platform Version" ,
9349+ "provider with profile_workspace='' should resolve platform profile"
9350+ ) ;
9351+ }
9352+
9353+ #[ tokio:: test]
9354+ async fn normal_provider_resolves_workspace_shadow_at_runtime ( ) {
9355+ let state = test_server_state ( ) . await ;
9356+
9357+ let mut platform_profile = custom_profile ( "scope-test-ws" ) ;
9358+ platform_profile. display_name = "Platform Version" . to_string ( ) ;
9359+ handle_import_provider_profiles (
9360+ & state,
9361+ Request :: new ( ImportProviderProfilesRequest {
9362+ profiles : vec ! [ ProviderProfileImportItem {
9363+ profile: Some ( platform_profile) ,
9364+ source: "scope-test-ws.yaml" . to_string( ) ,
9365+ } ] ,
9366+ workspace : String :: new ( ) ,
9367+ } ) ,
9368+ )
9369+ . await
9370+ . unwrap ( ) ;
9371+
9372+ let mut ws_profile = custom_profile ( "scope-test-ws" ) ;
9373+ ws_profile. display_name = "Workspace Version" . to_string ( ) ;
9374+ handle_import_provider_profiles (
9375+ & state,
9376+ Request :: new ( ImportProviderProfilesRequest {
9377+ profiles : vec ! [ ProviderProfileImportItem {
9378+ profile: Some ( ws_profile) ,
9379+ source: "scope-test-ws.yaml" . to_string( ) ,
9380+ } ] ,
9381+ workspace : "default" . to_string ( ) ,
9382+ } ) ,
9383+ )
9384+ . await
9385+ . unwrap ( ) ;
9386+
9387+ let catalog = state
9388+ . provider_profile_sources
9389+ . snapshot_catalog ( state. store . as_ref ( ) , "default" )
9390+ . await
9391+ . unwrap ( ) ;
9392+
9393+ let ws_result = catalog. get_type_profile_for_scope ( "scope-test-ws" , "default" ) ;
9394+ assert ! ( ws_result. is_some( ) ) ;
9395+ assert_eq ! (
9396+ ws_result. unwrap( ) . display_name,
9397+ "Workspace Version" ,
9398+ "provider with profile_workspace='default' should resolve workspace profile"
9399+ ) ;
9400+ }
92859401}
0 commit comments