MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_profiles

Function validate_profiles

crates/openshell-providers/src/profiles.rs:1012–1058  ·  view source on GitHub ↗
(profiles: &[ProviderTypeProfile])

Source from the content-addressed store, hash-verified

1010}
1011
1012fn validate_profiles(profiles: &[ProviderTypeProfile]) -> Result<(), ProfileError> {
1013 let diagnostics = validate_profile_set(
1014 &profiles
1015 .iter()
1016 .map(|profile| (String::new(), profile.clone()))
1017 .collect::<Vec<_>>(),
1018 );
1019 if let Some(diagnostic) = diagnostics.first() {
1020 if diagnostic.field == "id" && diagnostic.message == "provider profile id is required" {
1021 return Err(ProfileError::MissingId);
1022 }
1023 if diagnostic.field == "id"
1024 && diagnostic
1025 .message
1026 .starts_with("duplicate provider profile id")
1027 {
1028 return Err(ProfileError::DuplicateId(diagnostic.profile_id.clone()));
1029 }
1030 if diagnostic.field.starts_with("credentials.env_vars") {
1031 return Err(ProfileError::DuplicateCredentialEnvVar {
1032 id: diagnostic.profile_id.clone(),
1033 env_var: diagnostic
1034 .message
1035 .trim_start_matches("duplicate credential env var '")
1036 .trim_end_matches('\'')
1037 .to_string(),
1038 });
1039 }
1040 if diagnostic.field.starts_with("endpoints")
1041 && let Some(profile) = profiles
1042 .iter()
1043 .find(|profile| profile.id == diagnostic.profile_id)
1044 && let Some(endpoint) = profile
1045 .endpoints
1046 .iter()
1047 .find(|endpoint| !endpoint_is_valid(endpoint))
1048 {
1049 return Err(ProfileError::InvalidEndpoint {
1050 id: profile.id.clone(),
1051 host: endpoint.host.clone(),
1052 port: endpoint.port,
1053 });
1054 }
1055 }
1056
1057 Ok(())
1058}
1059
1060#[must_use]
1061pub fn normalize_profile_id(input: &str) -> Option<String> {

Callers 1

Calls 2

validate_profile_setFunction · 0.85
endpoint_is_validFunction · 0.85

Tested by

no test coverage detected