in quick_start/utils.py [0:0]
def create_application_certificate_connection_string(cls, cluster_url: str) -> KustoConnectionStringBuilder:
"""
Generates Kusto Connection String based on 'AppCertificate' Authentication Mode.
:param cluster_url: Url of cluster to connect to
:return: AppCertificate Kusto Connection String
"""
# TODO (config - optional): App ID & tenant, path to public certificate and path to private certificate pem file to authenticate with
app_id = os.environ.get("APP_ID")
app_tenant = os.environ.get("APP_TENANT")
private_key_pem_file_path = os.environ.get("PRIVATE_KEY_PEM_FILE_PATH")
cert_thumbprint = os.environ.get("CERT_THUMBPRINT")
public_cert_file_path = os.environ.get("PUBLIC_CERT_FILE_PATH") # Only used for "Subject Name and Issuer" auth
public_certificate = None
pem_certificate = None
try:
with open(private_key_pem_file_path, "r") as pem_file:
pem_certificate = pem_file.read()
except Exception as ex:
Utils.error_handler(f"Failed to load PEM file from {private_key_pem_file_path}", ex)
if public_cert_file_path:
try:
with open(public_cert_file_path, "r") as cert_file:
public_certificate = cert_file.read()
except Exception as ex:
Utils.error_handler(f"Failed to load public certificate file from {public_cert_file_path}", ex)
return KustoConnectionStringBuilder.with_aad_application_certificate_sni_authentication(
cluster_url, app_id, pem_certificate, public_certificate, cert_thumbprint, app_tenant
)
else:
return KustoConnectionStringBuilder.with_aad_application_certificate_authentication(
cluster_url, app_id, pem_certificate, cert_thumbprint, app_tenant
)