-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add graphrbac example that demonstrates the deleted_applications_clie…
…nt (#924)
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |