Java Code Examples for com.google.cloud.NoCredentials#getInstance()

The following examples show how to use com.google.cloud.NoCredentials#getInstance() . 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
Source File: GcpDatastoreAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
GcpDatastoreAutoConfiguration(GcpDatastoreProperties gcpDatastoreProperties,
		GcpProjectIdProvider projectIdProvider,
		CredentialsProvider credentialsProvider) throws IOException {

	this.projectId = (gcpDatastoreProperties.getProjectId() != null)
			? gcpDatastoreProperties.getProjectId()
			: projectIdProvider.getProjectId();
	this.namespace = gcpDatastoreProperties.getNamespace();

	String hostToConnect = gcpDatastoreProperties.getHost();
	if (gcpDatastoreProperties.getEmulator().isEnabled()) {
		hostToConnect = "localhost:" + gcpDatastoreProperties.getEmulator().getPort();
		LOGGER.info("Connecting to a local datastore emulator.");
	}

	if (hostToConnect == null) {
		this.credentials = (gcpDatastoreProperties.getCredentials().hasKey()
				? new DefaultCredentialsProvider(gcpDatastoreProperties)
				: credentialsProvider).getCredentials();
	}
	else {
		// Use empty credentials with Datastore Emulator.
		this.credentials = NoCredentials.getInstance();
	}

	this.host = hostToConnect;
}
 
Example 2
Source File: EntityManagerFactory.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates and returns the credentials from the given connection parameters.
 * 
 * @param parameters
 *          the connection parameters
 * @return the credentials for authenticating with the Datastore service.
 * @throws IOException
 *           if any error occurs such as not able to read the credentials file.
 */
private static Credentials getCredentials(ConnectionParameters parameters) throws IOException {
  if (parameters.isEmulator()) {
    return NoCredentials.getInstance();
  }
  InputStream jsonCredentialsStream = parameters.getJsonCredentialsStream();
  if (jsonCredentialsStream != null) {
    return ServiceAccountCredentials.fromStream(jsonCredentialsStream);
  }
  File jsonCredentialsFile = parameters.getJsonCredentialsFile();
  if (jsonCredentialsFile != null) {
    return ServiceAccountCredentials.fromStream(new FileInputStream(jsonCredentialsFile));
  }
  return ServiceAccountCredentials.getApplicationDefault();
}
 
Example 3
Source File: GcpDatastoreAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
public CredentialsProvider credentialsProvider() {
	return () -> NoCredentials.getInstance();
}
 
Example 4
Source File: GcpDatastoreAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
public CredentialsProvider credentialsProvider() {
	return () -> NoCredentials.getInstance();
}
 
Example 5
Source File: GcpDatastoreAutoConfigurationTests.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Bean
public CredentialsProvider credentialsProvider() {
	return () -> NoCredentials.getInstance();
}