Java Code Examples for com.google.cloud.sql.CredentialFactory

The following examples show how to use com.google.cloud.sql.CredentialFactory. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void setSystemProperties(File credentialsLocationFile) {
	// This should happen if the Spring resource isn't in the filesystem, but a URL,
	// classpath file, etc.
	if (credentialsLocationFile == null) {
		LOGGER.info("The private key of the Google Cloud SQL credential must "
				+ "be in a file on the filesystem.");
		return;
	}

	System.setProperty(SqlCredentialFactory.CREDENTIAL_LOCATION_PROPERTY_NAME,
			credentialsLocationFile.getAbsolutePath());

	// If there are specified credentials, tell sockets factory to use them.
	System.setProperty(CredentialFactory.CREDENTIAL_FACTORY_PROPERTY,
			SqlCredentialFactory.class.getName());
}
 
Example 2
private void setCredentialsEncodedKeyProperty(GcpCloudSqlProperties gcpCloudSqlProperties) {
	Credentials credentials = gcpCloudSqlProperties.getCredentials();

	if (credentials.getEncodedKey() == null) {
		LOGGER.info("SQL properties contain no encoded key. Can't set credentials.");
		return;
	}

	System.setProperty(SqlCredentialFactory.CREDENTIAL_ENCODED_KEY_PROPERTY_NAME,
			credentials.getEncodedKey());

	System.setProperty(CredentialFactory.CREDENTIAL_FACTORY_PROPERTY,
			SqlCredentialFactory.class.getName());
}
 
Example 3
Source Project: nomulus   Source File: CloudSqlCredentialSupplier.java    License: Apache License 2.0 4 votes vote down vote up
/** Initialize the supplier with given credential json and scopes. */
public static void setupCredentialSupplier(Credential credential) {
  System.setProperty(
      CredentialFactory.CREDENTIAL_FACTORY_PROPERTY, CloudSqlCredentialSupplier.class.getName());
  CloudSqlCredentialSupplier.credential = credential;
}