GitHub user Nik435 edited a comment on the discussion: Database Connection via 
Azure.Identity Azure SQL Server

Hi @aitor0307,
I’ve found a solution to my problem. I’m using the function 
DB-Connection_mutator and overriding it in the supereset value YAML 
configuration, similar to the following approach:

    # Connection string overwrite with authentication token 
    connection_string = 
'Driver={};Server=tcp:{}.database.windows.net,1433;Database={};Encrypt=yes;TrustServerCertificate=no;Connection
 Timeout=30'.format(DRIVER_NAME_SQLSERVER, SERVER_NAME_SQLSERVER, 
DATABASE_NAME_SQLSERVER)
    credential = DefaultAzureCredential()

    def DB_CONNECTION_MUTATOR(uri, params, username, security_manager, source):
      if SERVER_NAME_SQLSERVER in f"{uri}":
          token_bytes = 
credential.get_token(TOKEN_URL).token.encode("UTF-16-LE")
          token_struct = struct.pack(f'<I{len(token_bytes)}s', 
len(token_bytes), token_bytes)

          uri = "mssql+pyodbc:///?odbc_connect={0}".format(connection_string)

          connect_args = {}
          connect_args["attrs_before"] = {SQL_COPT_SS_ACCESS_TOKEN: 
token_struct}
          params["connect_args"] = connect_args
      return uri, params
      
That worked for our approach

GitHub link: 
https://github.com/apache/superset/discussions/33419#discussioncomment-14836380

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to