setting advanced parameters for Jdbc.getConnection

回眸只為那壹抹淺笑 提交于 2020-01-14 03:09:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!