Skip to content

Commit fb37c73

Browse files
committed
keylimectl: Use API v3.0 when --push-model is passed
Use the API version v3.0 for verifier requests when --push-model is passed. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
1 parent 599e769 commit fb37c73

File tree

2 files changed

+74
-10
lines changed

2 files changed

+74
-10
lines changed

keylimectl/src/client/verifier.rs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,16 @@ pub struct VerifierClient {
159159
#[derive(Debug)]
160160
pub struct VerifierClientBuilder<'a> {
161161
config: Option<&'a Config>,
162+
override_api_version: Option<String>,
162163
}
163164

164165
impl<'a> VerifierClientBuilder<'a> {
165166
/// Create a new builder instance
166167
pub fn new() -> Self {
167-
Self { config: None }
168+
Self {
169+
config: None,
170+
override_api_version: None,
171+
}
168172
}
169173

170174
/// Set the configuration for the client
@@ -173,19 +177,40 @@ impl<'a> VerifierClientBuilder<'a> {
173177
self
174178
}
175179

180+
/// Override the API version after detection
181+
///
182+
/// This allows you to override the detected API version for specific
183+
/// operations while still benefiting from detection for component
184+
/// discovery. Useful for push-model where verifier needs v3.0 but
185+
/// other components may use different versions.
186+
pub fn override_api_version(mut self, version: &str) -> Self {
187+
self.override_api_version = Some(version.to_string());
188+
self
189+
}
190+
176191
/// Build the VerifierClient with automatic API version detection
177192
///
178193
/// This is the recommended way to create a client for production use,
179194
/// as it will automatically detect the optimal API version supported
180195
/// by the verifier service.
196+
///
197+
/// If `override_api_version()` was called, the detected version will
198+
/// be overridden after detection completes.
181199
pub async fn build(self) -> Result<VerifierClient, KeylimectlError> {
182200
let config = self.config.ok_or_else(|| {
183201
KeylimectlError::validation(
184202
"Configuration is required for VerifierClient",
185203
)
186204
})?;
187205

188-
VerifierClient::new(config).await
206+
let mut client = VerifierClient::new(config).await?;
207+
208+
// Override API version if specified
209+
if let Some(version) = self.override_api_version {
210+
client.api_version = version;
211+
}
212+
213+
Ok(client)
189214
}
190215
}
191216

@@ -1965,6 +1990,32 @@ mod tests {
19651990
assert_eq!(client.api_version, "3.0");
19661991
}
19671992

1993+
#[tokio::test]
1994+
async fn test_builder_override_api_version() {
1995+
let config = create_test_config();
1996+
let client = VerifierClient::builder()
1997+
.config(&config)
1998+
.override_api_version("3.0")
1999+
.build()
2000+
.await;
2001+
2002+
assert!(client.is_ok());
2003+
let client = client.unwrap();
2004+
// Should use the overridden version
2005+
assert_eq!(client.api_version, "3.0");
2006+
}
2007+
2008+
#[tokio::test]
2009+
async fn test_builder_without_override() {
2010+
let config = create_test_config();
2011+
let client =
2012+
VerifierClient::builder().config(&config).build().await;
2013+
2014+
// This will fail to connect but we can check the structure
2015+
// In a real scenario, it would detect the version
2016+
assert!(client.is_ok() || client.is_err());
2017+
}
2018+
19682019
#[test]
19692020
fn test_base_url_construction_with_different_versions() {
19702021
let config = create_test_config();

keylimectl/src/commands/agent.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -774,23 +774,36 @@ async fn add_agent(
774774
// Step 2: Determine API version and enrollment approach
775775
output.step(2, 4, "Detecting verifier API version");
776776

777-
let verifier_client = VerifierClient::builder()
778-
.config(config)
779-
.build()
780-
.await
781-
.map_err(|e| {
777+
// Build verifier client with detection, then override to v3.0 if push_model is set
778+
let mut verifier_client_builder =
779+
VerifierClient::builder().config(config);
780+
781+
// For push model, we need to use API v3.0 for verifier requests
782+
if params.push_model {
783+
verifier_client_builder =
784+
verifier_client_builder.override_api_version("3.0");
785+
}
786+
787+
let verifier_client =
788+
verifier_client_builder.build().await.map_err(|e| {
782789
CommandError::resource_error("verifier", e.to_string())
783790
})?;
784791

785792
let api_version =
786793
verifier_client.api_version().parse::<f32>().unwrap_or(2.1);
787794

788795
// Use push model if explicitly requested via --push-model flag
789-
// This skips direct agent communication but still uses the detected API version
790-
// for verifier requests
796+
// This skips direct agent communication and uses API v3.0 for verifier requests
791797
let is_push_model = params.push_model;
792798

793-
debug!("Detected API version: {api_version}, using push model: {is_push_model}");
799+
debug!(
800+
"Detected API version: {}, using API version: {api_version}, push model: {is_push_model}",
801+
if is_push_model {
802+
"auto-detected (overridden to 3.0)"
803+
} else {
804+
&format!("{api_version}")
805+
}
806+
);
794807

795808
// Determine agent connection details (needed for pull model)
796809
let (agent_ip, agent_port) = if !is_push_model {

0 commit comments

Comments
 (0)