-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the ability to list eligible child resources for a given scope (#124
- Loading branch information
Showing
7 changed files
with
233 additions
and
1 deletion.
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
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
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,13 @@ | ||
$ az-pim role resources list --subscription 00000000-0000-0000-0000-000000000000 | ||
[ | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/DefaultResourceGroup-EUS", | ||
"name": "DefaultResourceGroup-EUS", | ||
"type": "resourcegroup" | ||
}, | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/DefaultResourceGroup-SUK", | ||
"name": "DefaultResourceGroup-SUK", | ||
"type": "resourcegroup" | ||
} | ||
] |
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
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,47 @@ | ||
use anyhow::Result; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
use std::collections::BTreeSet; | ||
|
||
use crate::scope::Scope; | ||
|
||
#[derive(Serialize, Deserialize, PartialOrd, Ord, PartialEq, Eq, Debug)] | ||
pub struct ChildResource { | ||
pub id: Scope, | ||
pub name: String, | ||
#[serde(rename = "type")] | ||
pub type_: String, | ||
} | ||
|
||
impl ChildResource { | ||
pub(crate) fn parse(data: &Value) -> Result<BTreeSet<Self>> { | ||
let mut results = BTreeSet::new(); | ||
|
||
if let Some(value) = data.get("value") { | ||
if let Some(value) = value.as_array() { | ||
for entry in value { | ||
let child_resource: ChildResource = serde_json::from_value(entry.clone())?; | ||
results.insert(child_resource); | ||
} | ||
} | ||
} | ||
|
||
Ok(results) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::ChildResource; | ||
use anyhow::Result; | ||
use insta::assert_json_snapshot; | ||
use serde_json::{from_str, Value}; | ||
|
||
#[test] | ||
fn test_child_resource_parse() -> Result<()> { | ||
let data: Value = from_str(include_str!("../tests/data/child-resources.json"))?; | ||
let result = ChildResource::parse(&data)?; | ||
assert_json_snapshot!(result); | ||
Ok(()) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/snapshots/azure_pim_cli__resources__tests__child_resource_parse.snap
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,16 @@ | ||
--- | ||
source: src/resources.rs | ||
expression: result | ||
--- | ||
[ | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group", | ||
"name": "DefaultResourceGroup-EUS", | ||
"type": "resourcegroup" | ||
}, | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group2", | ||
"name": "DefaultResourceGroup-EUS", | ||
"type": "resourcegroup" | ||
} | ||
] |
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,14 @@ | ||
{ | ||
"value": [ | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-resource-group", | ||
"name": "DefaultResourceGroup-EUS", | ||
"type": "resourcegroup" | ||
}, | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/my-resource-group2", | ||
"name": "DefaultResourceGroup-EUS", | ||
"type": "resourcegroup" | ||
} | ||
] | ||
} |