Skip to content

Commit

Permalink
add graphrbac example that demonstrates the deleted_applications_clie…
Browse files Browse the repository at this point in the history
…nt (#924)
  • Loading branch information
bmc-msft authored Jul 13, 2022
1 parent ab6ea18 commit d1df8f9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions services/svc/graphrbac/examples/purge_deleted_apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Hard deletes AAD app registrations that are deleted
cargo run --example purge_deleted_apps -- "startswith(displayName,'fretang')"
*/

use azure_identity::AzureCliCredential;
use azure_svc_graphrbac::ClientBuilder;
use futures::stream::StreamExt;
use std::{env::args, sync::Arc};

#[tokio::main]
async fn main() -> azure_core::Result<()> {
let filter = args().nth(1).expect("missing filter");
let credential = Arc::new(AzureCliCredential {});
let tenant_id = AzureCliCredential::get_tenant()?;

let client = ClientBuilder::new(credential).build().deleted_applications_client();

let mut stream = client.list(&tenant_id).filter(filter).into_stream();
while let Some(apps) = stream.next().await {
let apps = apps?;
for app in apps.value {
println!("{:?}", app.display_name);
let obj_id = app.directory_object.object_id.expect("missing object id");
client.hard_delete(obj_id, &tenant_id).into_future().await?;
}
}

Ok(())
}

0 comments on commit d1df8f9

Please sign in to comment.