-
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 role assignment parsing support (#99)
- Loading branch information
Showing
4 changed files
with
104 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,57 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Debug, Serialize)] | ||
pub(crate) struct Assignments { | ||
pub(crate) value: Vec<Assignment>, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Serialize)] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Assignment { | ||
pub id: String, | ||
pub name: String, | ||
pub properties: Properties, | ||
#[serde(rename = "type")] | ||
pub type_: String, | ||
} | ||
|
||
#[derive(Deserialize, Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
#[serde(deny_unknown_fields)] | ||
pub struct Properties { | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub condition: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub condition_version: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub created_on: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub created_by: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub updated_on: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub updated_by: Option<String>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub description: Option<String>, | ||
pub role_definition_id: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub delegated_managed_identity_resource_id: Option<String>, | ||
pub principal_id: String, | ||
pub principal_type: String, | ||
pub scope: String, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::Assignments; | ||
use anyhow::Result; | ||
use insta::assert_json_snapshot; | ||
|
||
#[test] | ||
fn test_deserialization() -> Result<()> { | ||
const DATA: &str = include_str!("../tests/data/assignments.json"); | ||
let data: Assignments = serde_json::from_str(DATA)?; | ||
assert_json_snapshot!(data); | ||
Ok(()) | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/snapshots/azure_pim_cli__assignments__tests__deserialization.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,23 @@ | ||
--- | ||
source: src/assignments.rs | ||
expression: data | ||
--- | ||
{ | ||
"value": [ | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/00000000-0000-0000-0000-000000000001", | ||
"name": "00000000-0000-0000-0000-000000000001", | ||
"properties": { | ||
"createdOn": "2023-10-10T19:09:15.2878306Z", | ||
"createdBy": "", | ||
"updatedOn": "2023-10-10T19:09:15.2878306Z", | ||
"updatedBy": "", | ||
"roleDefinitionId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-0000-000000000002", | ||
"principalId": "c2104d9b-8c91-4f28-8a0a-5909d768818c", | ||
"principalType": "ServicePrincipal", | ||
"scope": "/subscriptions/00000000-0000-0000-0000-000000000000" | ||
}, | ||
"type": "Microsoft.Authorization/roleAssignments" | ||
} | ||
] | ||
} |
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,23 @@ | ||
{ | ||
"value": [ | ||
{ | ||
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleAssignments/00000000-0000-0000-0000-000000000001", | ||
"name": "00000000-0000-0000-0000-000000000001", | ||
"properties": { | ||
"condition": null, | ||
"conditionVersion": null, | ||
"createdBy": "", | ||
"createdOn": "2023-10-10T19:09:15.2878306Z", | ||
"delegatedManagedIdentityResourceId": null, | ||
"description": null, | ||
"principalId": "c2104d9b-8c91-4f28-8a0a-5909d768818c", | ||
"principalType": "ServicePrincipal", | ||
"roleDefinitionId": "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Authorization/roleDefinitions/00000000-0000-0000-0000-000000000002", | ||
"scope": "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
"updatedBy": "", | ||
"updatedOn": "2023-10-10T19:09:15.2878306Z" | ||
}, | ||
"type": "Microsoft.Authorization/roleAssignments" | ||
} | ||
] | ||
} |