{ "cells": [ { "cell_type": "code", "source": [ "appconfigurationstore = \"\"\r\n", "featureflag = \"\"\r\n", "fallbackvalue = False\r\n", "keyvault = \"\"\r\n", "keyvaultlinkedservice = \"\"" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": true }, "nteract": { "transient": { "deleting": false } }, "tags": [ "parameters" ] } }, { "cell_type": "code", "source": [ "import json\r\n", "import requests\r\n", "\r\n", "from azure.appconfiguration import AzureAppConfigurationClient\r\n", "from azure.identity import ClientSecretCredential" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": true }, "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "azure_ad_tenant_id = mssparkutils.credentials.getSecret(keyvault, \"azure-tenant-id\", keyvaultlinkedservice)\r\n", "sp_client_id = mssparkutils.credentials.getSecret(keyvault, \"synw-notebook-sp-client-id\", keyvaultlinkedservice)\r\n", "sp_client_secret = mssparkutils.credentials.getSecret(keyvault, \"synw-notebook-sp-client-secret\", keyvaultlinkedservice)" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "appConfigurationCredential = ClientSecretCredential(azure_ad_tenant_id, sp_client_id, sp_client_secret)\r\n", "\r\n", "appConfigurationClient = AzureAppConfigurationClient(\r\n", " base_url=f\"https://{appconfigurationstore}.azconfig.io\",\r\n", " credential=appConfigurationCredential\r\n", ")" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "try:\r\n", " feature = appConfigurationClient.get_configuration_setting(\r\n", " key=f\".appconfig.featureflag/{featureflag}\"\r\n", " )\r\n", "except:\r\n", " mssparkutils.notebook.exit(fallbackvalue)" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "enabled = json.loads(feature.value)[\"enabled\"]" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } } } }, { "cell_type": "code", "source": [ "mssparkutils.notebook.exit(enabled)" ], "outputs": [], "execution_count": null, "metadata": { "jupyter": { "source_hidden": false, "outputs_hidden": false }, "nteract": { "transient": { "deleting": false } } } } ], "metadata": { "kernelspec": { "name": "synapse_pyspark", "display_name": "Synapse PySpark" }, "language_info": { "name": "python" }, "save_output": false, "synapse_widget": { "version": "0.1", "state": {} } }, "nbformat": 4, "nbformat_minor": 2 }