Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a87680

Browse filesBrowse files
committed
added support for SQL Auth
1 parent 71ab614 commit 8a87680
Copy full SHA for 8a87680

File tree

1 file changed

+17
-8
lines changed
Filter options

1 file changed

+17
-8
lines changed

‎python/utilities.py

Copy file name to clipboardExpand all lines: python/utilities.py
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@
55
from azure import identity
66

77
def get_mssql_connection():
8-
logging.info('Getting MSSQL connection')
9-
logging.info(' - Getting EntraID credentials...')
8+
print('Getting MSSQL connection')
109
mssql_connection_string = os.environ["MSSQL"]
11-
credential = identity.DefaultAzureCredential(exclude_interactive_browser_credential=False)
12-
token_bytes = credential.get_token("https://database.windows.net/.default").token.encode("UTF-16-LE")
13-
token_struct = struct.pack(f'<I{len(token_bytes)}s', len(token_bytes), token_bytes)
14-
SQL_COPT_SS_ACCESS_TOKEN = 1256 # This connection option is defined by microsoft in msodbcsql.h
15-
logging.info(' - Connecting to MSSQL...')
16-
conn = pyodbc.connect(mssql_connection_string, attrs_before={SQL_COPT_SS_ACCESS_TOKEN: token_struct})
10+
print(mssql_connection_string)
11+
if any(s in mssql_connection_string.lower() for s in ["uid"]):
12+
print(' - Using SQL Server authentication')
13+
attrs_before = None
14+
else:
15+
print(' - Getting EntraID credentials...')
16+
mssql_connection_string = os.environ["MSSQL"]
17+
credential = identity.DefaultAzureCredential(exclude_interactive_browser_credential=False)
18+
token_bytes = credential.get_token("https://database.windows.net/.default").token.encode("UTF-16-LE")
19+
token_struct = struct.pack(f'<I{len(token_bytes)}s', len(token_bytes), token_bytes)
20+
SQL_COPT_SS_ACCESS_TOKEN = 1256 # This connection option is defined by microsoft in msodbcsql.h
21+
attrs_before = {SQL_COPT_SS_ACCESS_TOKEN: token_struct}
22+
23+
print(' - Connecting to MSSQL...')
24+
conn = pyodbc.connect(mssql_connection_string, attrs_before=attrs_before)
25+
1726
return conn

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.