问题
I'd like to connect securely to SQL Google Cloud Platform using Google Apps Script. However, I'm not sure how to set the parameters _serverSslCertificate, _clientSslCertificate
, and clientSslKey
of Jdbc.getConnection
method. I already downloaded cert and key files.
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAlj6vYtt6F8rv254sllmvGogSYwzS0JaB6Yezji6Ab+gmZPLc
dyfNIg4PTe8YCz45RnJ+8VVklTQ4K/MFzsB6nilNMDSFRCAfRmytQkioEFlgzdL+
...
JOyb/68aCqHHStwlpCUTH40Iqh3kneiQ1be2XigxjllMSYkuH/ebZw==
-----END RSA PRIVATE KEY-----
How should I assign a string literal to _serverSslCertificate
? For example...
var serverSslCert = '-----BEGIN RSA PRIVATE KEY-----\n\
MIIEpAIBAAKCAQEAlj6vYtt6F8rv254sllmvGogSYwzS0JaB6Yezji6Ab+gmZPLc\n\
dyfNIg4PTe8YCz45RnJ+8VVklTQ4K/MFzsB6nilNMDSFRCAfRmytQkioEFlgzdL+\n\
...
JOyb/68aCqHHStwlpCUTH40Iqh3kneiQ1be2XigxjllMSYkuH/ebZw==\n\
-----END RSA PRIVATE KEY-----';
回答1:
The certs are send in the info parameter of getConnection(url,info). https://developers.google.com/apps-script/reference/jdbc/jdbc#getconnectionurl-info
Example:
var serverSslCert = PropertiesService.getScriptProperties().getProperty("serverSslCert");
var sqlInfo = {_serverSslCertificate: serverSslCert,
_clientSslCertificate:"...",
_clientSslKey:"..."
};
var conn = Jdbc.getConnection('jdbc:mysql://yoursqlserver.example.com:3306/database_name',
sqlInfo);
There are some Google Cloud SQL specific connection methods in the JDBC service though.
https://developers.google.com/apps-script/reference/jdbc/jdbc#getcloudsqlconnectionurl-info
https://developers.google.com/apps-script/reference/jdbc/jdbc#getconnectionurl-username-password
来源:https://stackoverflow.com/questions/34891556/setting-advanced-parameters-for-jdbc-getconnection