Skip to content

Commit 728dc50

Browse files
committed
resolve_sensitivity_label_id
1 parent 74fc580 commit 728dc50

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/sempy_labs/graph/_sensitivity_labels.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
_base_api,
66
_create_dataframe,
77
_update_dataframe_datatypes,
8+
_is_valid_uuid,
89
)
910
from sempy._utils._log import log
1011

@@ -79,3 +80,41 @@ def list_sensitivity_labels(user: Optional[str | UUID] = None) -> pd.DataFrame:
7980
_update_dataframe_datatypes(dataframe=df, column_map=columns)
8081

8182
return df
83+
84+
85+
@log
86+
def resolve_sensitivity_label_id(
87+
label: str | UUID, user: Optional[str | UUID] = None
88+
) -> UUID | None:
89+
"""
90+
Resolve a sensitivity label name or ID to its corresponding sensitivity label ID.
91+
92+
Service Principal Authentication is required (see `here <https://github.com/microsoft/semantic-link-labs/blob/main/notebooks/Service%20Principal.ipynb>`_ for examples).
93+
94+
Parameters
95+
----------
96+
label : str | uuid.UUID
97+
The name or ID of the sensitivity label.
98+
user : str | uuid.UUID, default=None
99+
The user ID or user principal name.
100+
101+
Returns
102+
-------
103+
uuid.UUID | None
104+
The ID of the sensitivity label if found, otherwise None.
105+
"""
106+
107+
if _is_valid_uuid(label):
108+
return str(label)
109+
110+
df = list_sensitivity_labels(user=user)
111+
112+
if df.empty:
113+
return None
114+
115+
# Try to find the label by name
116+
label_row = df[df["Sensitivity Label Name"] == label]
117+
if not label_row.empty:
118+
return label_row["Sensitivity Label Id"].iloc[0]
119+
120+
return None

0 commit comments

Comments
 (0)