Skip to content

Commit

Permalink
[NB Auto] Remove endpoint (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzhao8888 committed Jun 3, 2023
1 parent 3b22357 commit c85137c
Showing 1 changed file with 20 additions and 181 deletions.
Expand Up @@ -24,26 +24,14 @@
"3. Azure Log Analytics Data Queries\n",
"4. Save result to Microsoft Sentinel Dynamic Summaries"
],
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## 1. Warm-up"
],
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "code",
Expand All @@ -63,21 +51,7 @@
],
"outputs": [],
"execution_count": null,
"metadata": {
"gather": {
"logged": 1632434528751
},
"jupyter": {
"outputs_hidden": false,
"source_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
},
"collapsed": true
}
"metadata": {}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -148,72 +122,11 @@
" re.compile(regex_str)\n",
" results = re.findall(regex_str, comumn_name)\n",
" if results:\n",
" return True\n",
"\n",
"from msrest.authentication import BasicTokenAuthentication\n",
"from azure.core.pipeline.policies import BearerTokenCredentialPolicy\n",
"from azure.core.pipeline import PipelineRequest, PipelineContext\n",
"from azure.core.pipeline.transport import HttpRequest\n",
"from azure.identity import DefaultAzureCredential\n",
"\n",
"class AzureIdentityCredentialAdapter(BasicTokenAuthentication):\n",
" def __init__(self, credential=None, resource_id=\"https://management.azure.com/.default\", **kwargs):\n",
" \"\"\"Adapt any azure-identity credential to work with SDK that needs azure.common.credentials or msrestazure.\n",
" Default resource is ARM (syntax of endpoint v2)\n",
" :param credential: Any azure-identity credential (DefaultAzureCredential by default)\n",
" :param str resource_id: The scope to use to get the token (default ARM)\n",
" \"\"\"\n",
" super(AzureIdentityCredentialAdapter, self).__init__(None)\n",
" if credential is None:\n",
" credential = DefaultAzureCredential()\n",
" self._policy = BearerTokenCredentialPolicy(credential, resource_id, **kwargs)\n",
"\n",
" def _make_request(self):\n",
" return PipelineRequest(\n",
" HttpRequest(\n",
" \"AzureIdentityCredentialAdapter\",\n",
" \"https://fakeurl\"\n",
" ),\n",
" PipelineContext(None)\n",
" )\n",
"\n",
" def set_token(self):\n",
" \"\"\"Ask the azure-core BearerTokenCredentialPolicy policy to get a token.\n",
" Using the policy gives us for free the caching system of azure-core.\n",
" We could make this code simpler by using private method, but by definition\n",
" I can't assure they will be there forever, so mocking a fake call to the policy\n",
" to extract the token, using 100% public API.\"\"\"\n",
" request = self._make_request()\n",
" self._policy.on_request(request)\n",
" # Read Authorization, and get the second part after Bearer\n",
" token = request.http_request.headers[\"Authorization\"].split(\" \", 1)[1]\n",
" self.token = {\"access_token\": token}\n",
"\n",
" def get_token(self):\n",
" \"\"\"Get access token.\"\"\"\n",
" return self.token\n",
" \n",
" def signed_session(self, session=None):\n",
" self.set_token()\n",
" return super(AzureIdentityCredentialAdapter, self).signed_session(session)"
" return True\n"
],
"outputs": [],
"execution_count": null,
"metadata": {
"gather": {
"logged": 1632434530603
},
"jupyter": {
"outputs_hidden": false,
"source_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
},
"collapsed": true
}
"metadata": {}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -362,30 +275,14 @@
],
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## 2. Azure Authentication"
],
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "code",
Expand All @@ -405,15 +302,6 @@
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
},
"tags": [
"parameters"
]
Expand All @@ -431,37 +319,20 @@
" tenant_id=tenant_id, \r\n",
" client_id=client_id, \r\n",
" client_secret=client_secret)\r\n",
"cred = AzureIdentityCredentialAdapter(credential)\r\n",
"access_token = credential.get_token(resource_uri + \"/.default\")\r\n",
"token = access_token[0]\r\n",
"la_data_client = LogsQueryClient(credential=credential, endpoint=resource_uri)"
"la_data_client = LogsQueryClient(credential=credential)"
],
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## 3. Azure Log Analytics Data Queries"
],
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "code",
Expand Down Expand Up @@ -549,30 +420,14 @@
],
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## 4. Save result to Microsoft Sentinel Dynamic Summaries"
],
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "code",
Expand All @@ -593,17 +448,7 @@
],
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
},
{
"cell_type": "code",
Expand All @@ -616,26 +461,20 @@
],
"outputs": [],
"execution_count": null,
"metadata": {
"jupyter": {
"source_hidden": false,
"outputs_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
}
"metadata": {}
}
],
"metadata": {
"language_info": {
"name": "python"
},
"kernelspec": {
"name": "synapse_pyspark",
"language": "Python",
"display_name": "Synapse PySpark"
},
"language_info": {
"name": "python"
"kernel_info": {
"name": "synapse_pyspark"
},
"description": null,
"save_output": true,
Expand Down

0 comments on commit c85137c

Please sign in to comment.