Skip to content

Commit

Permalink
Enable server public key retrieval in python scripts (#10413)
Browse files Browse the repository at this point in the history
When using an un-encrypted connection MySQL 8 requires password encryption that uses the server public key. The client enables retrieval of the server public key by passing 'get-server-public-key' in the connection URL. The python mysqlclient library passes as a parameter named  'MYSQL_OPT_GET_SERVER_PUBLIC_KEY' to the MySQL C-library.
  • Loading branch information
pvannierop authored Oct 2, 2023
1 parent bbfcb53 commit ac5a3a6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/src/main/scripts/importer/cbioportal_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,16 +1092,20 @@ def get_db_cursor(portal_properties: PortalProperties):
"user": portal_properties.database_user,
"passwd": portal_properties.database_pw
}
if url_elements.query["useSSL"] == "true":
connection_kwargs['ssl'] = {"ssl_mode": True}
if url_elements.query.get("useSSL") == "true":
connection_kwargs['ssl_mode'] = 'REQUIRED'
connection_kwargs['ssl'] = {"ssl_mode": True}
else:
connection_kwargs['ssl_mode'] = 'DISABLED'
connection_kwargs['ssl_mode'] = 'DISABLED'
if url_elements.query.get("get-server-public-key") == "true":
connection_kwargs['ssl'] = {
'MYSQL_OPT_GET_SERVER_PUBLIC_KEY': True
}
connection = MySQLdb.connect(**connection_kwargs)
except MySQLdb.Error as exception:
print(exception, file=ERROR_FILE)
message = (
"--> Error connecting to server with URL"
"--> Error connecting to server with URL: "
+ portal_properties.database_url)
print(message, file=ERROR_FILE)
raise ConnectionError(message) from exception
Expand Down

0 comments on commit ac5a3a6

Please sign in to comment.