Skip to content

Commit 72bf88b

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 6ce3101 commit 72bf88b

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

@@ -2916,6 +2924,8 @@ binaries: ["", /usr/bin/broken]
29162924
binaries: Vec::new(),
29172925
inference_capable: false,
29182926
discovery: DiscoveryProfile::default(),
2927+
source: String::new(),
2928+
scope: String::new(),
29192929
},
29202930
),
29212931
(
@@ -2932,6 +2942,8 @@ binaries: ["", /usr/bin/broken]
29322942
binaries: Vec::new(),
29332943
inference_capable: false,
29342944
discovery: DiscoveryProfile::default(),
2945+
source: String::new(),
2946+
scope: String::new(),
29352947
},
29362948
),
29372949
(
@@ -2948,6 +2960,8 @@ binaries: ["", /usr/bin/broken]
29482960
binaries: Vec::new(),
29492961
inference_capable: false,
29502962
discovery: DiscoveryProfile::default(),
2963+
source: String::new(),
2964+
scope: String::new(),
29512965
},
29522966
),
29532967
];

‎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
@@ -5679,6 +5685,8 @@ mod tests {
56795685
binaries: Vec::new(),
56805686
inference_capable: false,
56815687
discovery: None,
5688+
source: String::new(),
5689+
scope: String::new(),
56825690
}),
56835691
}
56845692
}
@@ -5978,6 +5986,8 @@ mod tests {
59785986
binaries: Vec::new(),
59795987
inference_capable: false,
59805988
discovery: None,
5989+
source: String::new(),
5990+
scope: String::new(),
59815991
}),
59825992
}
59835993
}
@@ -6216,6 +6226,8 @@ mod tests {
62166226
}],
62176227
inference_capable: false,
62186228
discovery: None,
6229+
source: String::new(),
6230+
scope: String::new(),
62196231
}),
62206232
}],
62216233
workspace: "default".to_string(),
@@ -8392,6 +8404,8 @@ mod tests {
83928404
}],
83938405
inference_capable: false,
83948406
discovery: None,
8407+
source: String::new(),
8408+
scope: String::new(),
83958409
}),
83968410
})
83978411
.await

0 commit comments

Comments
 (0)