-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathfind_label_downgrades.py
More file actions
37 lines (25 loc) · 1.37 KB
/
Copy pathfind_label_downgrades.py
File metadata and controls
37 lines (25 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
List the tenant's Microsoft Purview sensitivity labels.
Shows each label's id, display name, priority, and enabled state —
useful for planning label baselines before applying them to sites/files.
Note: detecting label *downgrades* requires the audit log search API
(``/security/auditLog/queries``), which is not modeled by this SDK.
Requires delegated permission ``SecurityDataGovernance.Read.All`` (or
Purview compliance admin).
https://learn.microsoft.com/en-us/graph/api/resources/sensitivitylabel
"""
import argparse
from office365.graph_client import GraphClient
from tests.settings import client_id, client_secret, tenant
def main():
parser = argparse.ArgumentParser(description="List sensitivity labels")
parser.add_argument("--top", type=int, default=100, help="maximum number of labels (default 100)")
args = parser.parse_args()
client = GraphClient(tenant=tenant).with_client_secret(client_id, client_secret)
labels = client.security.data_security_and_governance.sensitivity_labels.top(args.top).get().execute_query()
print(f"Sensitivity labels ({len(labels)}):")
for label in sorted(labels, key=lambda label: label.priority or 0):
state = "enabled" if label.enabled else "disabled"
print(f" {label.display_name or label.name or '?':35s} priority={label.priority} {state} ({label.id})")
if __name__ == "__main__":
main()