Skip to content

Commit e269a17

Browse files
fix(workspace): make provider profile catalog scope-aware
Allow the same profile ID at platform and workspace scopes by introducing layered catalog entries where workspace profiles shadow platform profiles. Add source and scope fields to the ProviderProfile proto and CLI output. Migrate List/Get handlers to the catalog, fixing divergence with runtime profile resolution. Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent 93e30f5 commit e269a17

8 files changed

Lines changed: 932 additions & 154 deletions

File tree

‎crates/openshell-cli/src/run.rs‎

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,14 +5485,17 @@ pub async fn provider_list_profiles(
54855485
println!("{}", "Available Provider Profiles:".cyan().bold());
54865486
let id_width = provider_profile_id_width(&profiles);
54875487
let display_width = provider_profile_display_width(&profiles);
5488+
let source_width = provider_profile_source_width(&profiles);
5489+
let scope_width = provider_profile_scope_width(&profiles);
54885490
let mut current_category = i32::MIN;
5489-
for profile in profiles {
5491+
for profile in &profiles {
54905492
if profile.category != current_category {
54915493
current_category = profile.category;
54925494
println!();
54935495
println!(" {}", display_provider_category(current_category).bold());
5496+
print_provider_type_header(id_width, scope_width, source_width, display_width);
54945497
}
5495-
print_provider_type_row(&profile, id_width, display_width);
5498+
print_provider_type_row(profile, id_width, scope_width, source_width, display_width);
54965499
}
54975500

54985501
Ok(())
@@ -6066,6 +6069,7 @@ fn display_provider_category(category: i32) -> &'static str {
60666069

60676070
const PROVIDER_PROFILE_ID_MAX_WIDTH: usize = 32;
60686071
const PROVIDER_PROFILE_DISPLAY_MAX_WIDTH: usize = 40;
6072+
const PROVIDER_PROFILE_SOURCE_MAX_WIDTH: usize = 24;
60696073

60706074
fn provider_profile_id_width(profiles: &[ProviderProfile]) -> usize {
60716075
profiles
@@ -6097,16 +6101,61 @@ fn provider_profile_display_width(profiles: &[ProviderProfile]) -> usize {
60976101
.max(4)
60986102
}
60996103

6100-
fn print_provider_type_row(profile: &ProviderProfile, id_width: usize, display_width: usize) {
6104+
fn provider_profile_scope_width(profiles: &[ProviderProfile]) -> usize {
6105+
profiles
6106+
.iter()
6107+
.map(|profile| profile.scope.chars().count())
6108+
.max()
6109+
.unwrap_or(5)
6110+
.max(5)
6111+
}
6112+
6113+
fn provider_profile_source_width(profiles: &[ProviderProfile]) -> usize {
6114+
profiles
6115+
.iter()
6116+
.map(|profile| {
6117+
profile
6118+
.source
6119+
.chars()
6120+
.count()
6121+
.min(PROVIDER_PROFILE_SOURCE_MAX_WIDTH)
6122+
})
6123+
.max()
6124+
.unwrap_or(6)
6125+
.max(6)
6126+
}
6127+
6128+
fn print_provider_type_header(
6129+
id_width: usize,
6130+
scope_width: usize,
6131+
source_width: usize,
6132+
display_width: usize,
6133+
) {
6134+
let endpoints = "ENDPOINTS";
6135+
println!(
6136+
" {:<id_width$} {:<scope_width$} {:<source_width$} {:<display_width$} {endpoints}",
6137+
"ID", "SCOPE", "SOURCE", "NAME"
6138+
);
6139+
}
6140+
6141+
fn print_provider_type_row(
6142+
profile: &ProviderProfile,
6143+
id_width: usize,
6144+
scope_width: usize,
6145+
source_width: usize,
6146+
display_width: usize,
6147+
) {
61016148
let inference = if profile.inference_capable {
61026149
" inference"
61036150
} else {
61046151
""
61056152
};
61066153
let id = truncate_display(&profile.id, PROVIDER_PROFILE_ID_MAX_WIDTH);
6154+
let scope = &profile.scope;
6155+
let source = truncate_display(&profile.source, PROVIDER_PROFILE_SOURCE_MAX_WIDTH);
61076156
let display_name = truncate_display(&profile.display_name, PROVIDER_PROFILE_DISPLAY_MAX_WIDTH);
61086157
println!(
6109-
" {id:<id_width$} {display_name:<display_width$} endpoints: {:<2}{}",
6158+
" {id:<id_width$} {scope:<scope_width$} {source:<source_width$} {display_name:<display_width$} {:<2}{}",
61106159
profile.endpoints.len(),
61116160
inference
61126161
);

‎crates/openshell-providers/src/discovery.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ mod tests {
120120
discovery: DiscoveryProfile {
121121
credentials: vec!["api_key".to_string(), "secondary".to_string()],
122122
},
123+
source: String::new(),
124+
scope: String::new(),
123125
}
124126
}
125127

‎crates/openshell-providers/src/profiles.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ pub struct ProviderTypeProfile {
334334
pub inference_capable: bool,
335335
#[serde(default, skip_serializing_if = "discovery_is_empty")]
336336
pub discovery: DiscoveryProfile,
337+
#[serde(default, skip_serializing_if = "String::is_empty")]
338+
pub source: String,
339+
#[serde(default, skip_serializing_if = "String::is_empty")]
340+
pub scope: String,
337341
}
338342

339343
// Provider profile import/export is expected to be lossless for the network
@@ -378,6 +382,8 @@ impl ProviderTypeProfile {
378382
.as_ref()
379383
.map(discovery_from_proto)
380384
.unwrap_or_default(),
385+
source: profile.source.clone(),
386+
scope: profile.scope.clone(),
381387
}
382388
}
383389

@@ -513,6 +519,8 @@ impl ProviderTypeProfile {
513519
inference_capable: self.inference_capable,
514520
discovery: (!discovery_is_empty(&self.discovery))
515521
.then(|| discovery_to_proto(&self.discovery)),
522+
source: self.source.clone(),
523+
scope: self.scope.clone(),
516524
}
517525
}
518526

@@ -2982,6 +2990,8 @@ binaries: ["", /usr/bin/broken]
29822990
binaries: Vec::new(),
29832991
inference_capable: false,
29842992
discovery: DiscoveryProfile::default(),
2993+
source: String::new(),
2994+
scope: String::new(),
29852995
},
29862996
),
29872997
(
@@ -2998,6 +3008,8 @@ binaries: ["", /usr/bin/broken]
29983008
binaries: Vec::new(),
29993009
inference_capable: false,
30003010
discovery: DiscoveryProfile::default(),
3011+
source: String::new(),
3012+
scope: String::new(),
30013013
},
30023014
),
30033015
(
@@ -3014,6 +3026,8 @@ binaries: ["", /usr/bin/broken]
30143026
binaries: Vec::new(),
30153027
inference_capable: false,
30163028
discovery: DiscoveryProfile::default(),
3029+
source: String::new(),
3030+
scope: String::new(),
30173031
},
30183032
),
30193033
];

‎crates/openshell-server/src/grpc/policy.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5206,6 +5206,8 @@ mod tests {
52065206
binaries: Vec::new(),
52075207
inference_capable: false,
52085208
discovery: None,
5209+
source: String::new(),
5210+
scope: String::new(),
52095211
}),
52105212
})
52115213
.await
@@ -5270,6 +5272,8 @@ mod tests {
52705272
}],
52715273
inference_capable: false,
52725274
discovery: None,
5275+
source: String::new(),
5276+
scope: String::new(),
52735277
}),
52745278
})
52755279
.await
@@ -5326,6 +5330,8 @@ mod tests {
53265330
binaries: Vec::new(),
53275331
inference_capable: false,
53285332
discovery: None,
5333+
source: String::new(),
5334+
scope: String::new(),
53295335
}),
53305336
})
53315337
.await
@@ -5722,6 +5728,8 @@ mod tests {
57225728
binaries: Vec::new(),
57235729
inference_capable: false,
57245730
discovery: None,
5731+
source: String::new(),
5732+
scope: String::new(),
57255733
}),
57265734
}
57275735
}
@@ -6021,6 +6029,8 @@ mod tests {
60216029
binaries: Vec::new(),
60226030
inference_capable: false,
60236031
discovery: None,
6032+
source: String::new(),
6033+
scope: String::new(),
60246034
}),
60256035
}
60266036
}
@@ -6259,6 +6269,8 @@ mod tests {
62596269
}],
62606270
inference_capable: false,
62616271
discovery: None,
6272+
source: String::new(),
6273+
scope: String::new(),
62626274
}),
62636275
}],
62646276
workspace: "default".to_string(),
@@ -8435,6 +8447,8 @@ mod tests {
84358447
}],
84368448
inference_capable: false,
84378449
discovery: None,
8450+
source: String::new(),
8451+
scope: String::new(),
84388452
}),
84398453
})
84408454
.await

0 commit comments

Comments
 (0)