Skip to content

Commit

Permalink
Merge pull request #204 from Azure/add-mgmt-groups
Browse files Browse the repository at this point in the history
Filter by Management Groups
  • Loading branch information
DCMattyG authored Nov 2, 2023
2 parents 895240f + a747c79 commit 470bddc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
28 changes: 25 additions & 3 deletions engine/app/routers/argquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,25 @@
| project id, prefixes, resv = tags["ipam-res-id"]
"""

# SUBSCRIPTION = """
# resourcecontainers
# | where type =~ 'microsoft.resources/subscriptions'
# | extend quotaId = properties.subscriptionPolicies.quotaId
# | extend type = case(
# quotaId startswith "EnterpriseAgreement", "Enterprise Agreement",
# quotaId startswith "MSDNDevTest", "Dev/Test",
# quotaId startswith "MSDN_2014-09-0", "PAYGO",
# quotaId startswith "Internal", "Microsoft Internal",
# "Unknown"
# )
# | project name, id, type, subscription_id = subscriptionId, tenant_id = tenantId
# """

SUBSCRIPTION = """
ResourceContainers
| where type =~ 'microsoft.resources/subscriptions'
resourcecontainers
| where type=~ 'microsoft.resources/subscriptions'
| extend mgParent = properties.managementGroupAncestorsChain
| extend mgName = tostring(mgParent[0].name)
| extend quotaId = properties.subscriptionPolicies.quotaId
| extend type = case(
quotaId startswith "EnterpriseAgreement", "Enterprise Agreement",
Expand All @@ -17,7 +33,13 @@
quotaId startswith "Internal", "Microsoft Internal",
"Unknown"
)
| project name, id, type, subscription_id = subscriptionId, tenant_id = tenantId
| join kind=leftouter (
resourcecontainers
| where type =~ 'microsoft.management/managementgroups'
| extend mgDisplayName = iff((tostring(name) == tostring(tenantId)), "Tenant Root Group", name)
| project mgId = id, mgName = name, mgDisplayName
) on mgName
| project name, id, type, subscription_id = subscriptionId, mg_id = mgId, mg_name = mgDisplayName, tenant_id = tenantId
"""

SPACE = """
Expand Down
16 changes: 8 additions & 8 deletions engine/app/routers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,17 @@ async def subscription(
Get a list of Azure subscriptions.
"""

# subscription_list = await arg_query(authorization, admin, argquery.SUBSCRIPTION)
subscription_list = await arg_query(authorization, admin, argquery.SUBSCRIPTION)

if admin:
creds = await get_client_credentials()
else:
user_assertion=authorization.split(' ')[1]
creds = await get_obo_credentials(user_assertion)
# if admin:
# creds = await get_client_credentials()
# else:
# user_assertion=authorization.split(' ')[1]
# creds = await get_obo_credentials(user_assertion)

subscription_list = await get_subscriptions_sdk(creds)
# subscription_list = await get_subscriptions_sdk(creds)

await creds.close()
# await creds.close()

return subscription_list

Expand Down
2 changes: 1 addition & 1 deletion engine/app/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async def update_user(
user_data = copy.deepcopy(user_query[0])

try:
patch = jsonpatch.JsonPatch(updates)
patch = jsonpatch.JsonPatch([x.model_dump() for x in updates])
except jsonpatch.InvalidJsonPatch:
raise HTTPException(status_code=500, detail="Invalid JSON patch, please review and try again.")

Expand Down
6 changes: 5 additions & 1 deletion ui/src/features/exclusions/exclusions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ export default function ManageExclusions() {
{ name: "name", header: "Subscription Name", type: "string", flex: 1, visible: true },
{ name: "subscription_id", header: "Subscription ID", type: "string", flex: 1, visible: true },
{ name: "type", header: "Subscription Type", type: "string", flex: 0.75, visible: true },
{ name: "mg_name", header: "Management Group Name", type: "string", flex: 0.75, visible: true },
{ name: "mg_id", header: "Management Group ID", type: "string", flex: 0.75, visible: false },
{ name: "id", header: () => <HeaderMenu setting="exclusions"/> , width: 25, resizable: false, hideable: false, sortable: false, draggable: false, showColumnMenuTool: false, render: ({data}) => "", visible: true }
], []);

const filterValue = [
{ name: "name", operator: "contains", type: "string", value: "" },
{ name: "subscription_id", operator: "contains", type: "string", value: "" },
{ name: "type", operator: "contains", type: "string", value: "" }
{ name: "type", operator: "contains", type: "string", value: "" },
{ name: "mg_name", operator: "contains", type: "string", value: "" },
{ name: "mg_id", operator: "contains", type: "string", value: "" }
];

React.useEffect(() => {
Expand Down

0 comments on commit 470bddc

Please sign in to comment.