Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions libs/ferriskey-cli-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,17 @@ impl FerriskeyClient {
Ok(())
}

/// The server ignores the `clientId` query filter on this route and
/// always returns the full list, so the match is done client-side.
pub fn get_client(
&self,
realm: &str,
client_id: &str,
) -> Result<Option<ClientRepresentation>, FerriskeyClientError> {
let url = format!(
"{}?clientId={}",
self.endpoint(&format!("realms/{realm}/clients")),
client_id
);
let mut results: Vec<ClientRepresentation> = self.get_list(&url)?;
Ok(results.drain(..).next())
let results = self.list_clients(realm)?;
Ok(results
.into_iter()
.find(|client| client.client_id.as_deref() == Some(client_id)))
}

pub fn list_users(&self, realm: &str) -> Result<Vec<UserRepresentation>, FerriskeyClientError> {
Expand Down
16 changes: 10 additions & 6 deletions libs/ferriskey-cli-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,24 +114,28 @@ fn delete_client(
inline_context: Option<StoredContext>,
args: ClientDeleteArgs,
) -> Result<()> {
confirm(
&format!("Delete client '{}'?", args.client_id),
args.force,
)?;
let context = resolve_context(context_override, inline_context)?;
let realm = resolve_realm(&context, args.realm.clone())?;
let client = auth_client(&context)?;
let found = client
.get_client(&realm, &args.client_id)?
.ok_or_else(|| ClientCommandError::ClientNotFound(args.client_id.clone()))?;

let uuid = found
.id
.clone()
.ok_or_else(|| ClientCommandError::ClientNotFound(args.client_id.clone()))?;
let resolved_client_id = found.client_id.unwrap_or_else(|| args.client_id.clone());

// Show what is actually about to be deleted, not just what was asked
// for — the two can differ if the lookup resolved something unexpected.
confirm(
&format!("Delete client '{resolved_client_id}' (id: {uuid})?"),
args.force,
)?;
client.delete_client(&realm, &uuid)?;
render_message(
output_format,
&format!("client '{}' deleted", args.client_id),
&format!("client '{resolved_client_id}' deleted"),
)
}

Expand Down
Loading