|
| 1 | +import pandas as pd |
| 2 | +import requests |
| 3 | +from sempy._utils._log import log |
| 4 | +from sempy_labs._helper_functions import get_pbi_token_headers |
| 5 | + |
| 6 | + |
| 7 | +def _list_endorsements_or_favorites(type: str = "endorsements"): |
| 8 | + |
| 9 | + headers = get_pbi_token_headers() |
| 10 | + |
| 11 | + endorsement_map = { |
| 12 | + 0: "None", |
| 13 | + 1: "Promoted", |
| 14 | + 2: "Certified", |
| 15 | + 3: "Master data", |
| 16 | + } |
| 17 | + |
| 18 | + base_payload = { |
| 19 | + "filter": "Favorites" if "favorite" in type.lower() else "endorsement", |
| 20 | + "supportedTypes": [], |
| 21 | + "orderBy": "Default", |
| 22 | + } |
| 23 | + |
| 24 | + configs = [ |
| 25 | + {"configurations": ["Environment", "Variables"]}, |
| 26 | + { |
| 27 | + "solutions": [ |
| 28 | + "HealthDataManager", |
| 29 | + "HLSCohort", |
| 30 | + "RetailDataManager", |
| 31 | + "SustainabilityDataManager", |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "processes": [ |
| 36 | + "DataFlow", |
| 37 | + "CopyJob", |
| 38 | + "DatabricksCatalog", |
| 39 | + "DataFactory", |
| 40 | + "DataflowFabric", |
| 41 | + "DBTItem", |
| 42 | + "EventStream", |
| 43 | + "FunctionSet", |
| 44 | + "GraphQL", |
| 45 | + "KustoQueryWorkbench", |
| 46 | + "LLMPlugin", |
| 47 | + "MLExperiment", |
| 48 | + "MLModel", |
| 49 | + "MountedDataFactory", |
| 50 | + "MountedRelationalDatabase", |
| 51 | + "OperationalAgents", |
| 52 | + "Pipeline", |
| 53 | + "ApacheAirflowProject", |
| 54 | + "ReflexProject", |
| 55 | + "SparkJobDefinition", |
| 56 | + "SynapseNotebook", |
| 57 | + ] |
| 58 | + }, |
| 59 | + {"insights": ["PowerBIReport", "PaginatedReport", "Dashboard"]}, |
| 60 | + { |
| 61 | + "insights2": [ |
| 62 | + "App", |
| 63 | + "DataExploration", |
| 64 | + "DigitalTwinBuilder", |
| 65 | + "GraphQuerySet", |
| 66 | + "KustoDashboard", |
| 67 | + "LLMPlugin", |
| 68 | + "Map", |
| 69 | + "Ontology", |
| 70 | + "OperationalAgents", |
| 71 | + "OrgApp", |
| 72 | + ] |
| 73 | + }, |
| 74 | + { |
| 75 | + "data": [ |
| 76 | + "Model", |
| 77 | + "Sql", |
| 78 | + "CosmosDB", |
| 79 | + "DatabricksCatalog", |
| 80 | + "GraphIndex", |
| 81 | + "KustoDatabase", |
| 82 | + "KustoEventHouse", |
| 83 | + "Lakehouse", |
| 84 | + "MountedRelationalDatabase", |
| 85 | + "PgSQLDbNative", |
| 86 | + "SnowflakeDatabase", |
| 87 | + "SqlAnalyticsEndpoint", |
| 88 | + "SQLDbNative", |
| 89 | + "Warehouse", |
| 90 | + "WarehouseSnapshot", |
| 91 | + "Lakewarehouse", |
| 92 | + "MountedWarehouse", |
| 93 | + "Datawarehouse", |
| 94 | + ] |
| 95 | + }, |
| 96 | + ] |
| 97 | + |
| 98 | + rows = [] |
| 99 | + for c in configs: |
| 100 | + config_name, supported_types = next(iter(c.items())) |
| 101 | + |
| 102 | + payload = {**base_payload, "supportedTypes": supported_types} |
| 103 | + |
| 104 | + response_list = requests.post( |
| 105 | + "https://df-msit-scus-redirect.analysis.windows.net/metadata/datahub/V2/artifacts", |
| 106 | + headers=headers, |
| 107 | + json=payload, |
| 108 | + ).json() |
| 109 | + |
| 110 | + for item in response_list: |
| 111 | + owner = item.get("ownerUser", {}) |
| 112 | + artifact_endorsement = item.get("artifactEndorsement", {}).get("stage", 0) |
| 113 | + rows.append( |
| 114 | + { |
| 115 | + "Item Name": item.get("displayName"), |
| 116 | + "Item Id": item.get("artifactObjectId"), |
| 117 | + "Workspace Name": item.get("workspaceName"), |
| 118 | + "Workspace Id": item.get("workspaceObjectId"), |
| 119 | + "Item Type": item.get("artifactType"), |
| 120 | + "Owner": ( |
| 121 | + f"{owner.get('givenName')} {owner.get('familyName')}" |
| 122 | + if owner |
| 123 | + else None |
| 124 | + ), |
| 125 | + "Owner Email Address": owner.get("emailAddress"), |
| 126 | + "Endorsement": endorsement_map.get(artifact_endorsement), |
| 127 | + "Sensitivity Label": item.get( |
| 128 | + "artifactInformationProtection", {} |
| 129 | + ).get("name"), |
| 130 | + } |
| 131 | + ) |
| 132 | + |
| 133 | + return pd.DataFrame(rows) |
| 134 | + |
| 135 | + |
| 136 | +@log |
| 137 | +def list_endorsements() -> pd.DataFrame: |
| 138 | + """ |
| 139 | + Lists all endorsed items. |
| 140 | +
|
| 141 | + Returns |
| 142 | + ------- |
| 143 | + pandas.DataFrame |
| 144 | + A pandas DataFrame containing the list of endorsed items. |
| 145 | + """ |
| 146 | + |
| 147 | + return _list_endorsements_or_favorites(type="endorsements") |
| 148 | + |
| 149 | + |
| 150 | +@log |
| 151 | +def list_favorites() -> pd.DataFrame: |
| 152 | + """ |
| 153 | + Lists all favorite items. |
| 154 | +
|
| 155 | + Returns |
| 156 | + ------- |
| 157 | + pandas.DataFrame |
| 158 | + A pandas DataFrame containing the list of favorite items. |
| 159 | + """ |
| 160 | + |
| 161 | + return _list_endorsements_or_favorites(type="favorites") |
0 commit comments