Source:
public static AnviltopOptions fromConfiguration(Configuration configuration) throws IOException { AnviltopOptions.Builder optionsBuilder = new AnviltopOptions.Builder(); String projectId = configuration.get(PROJECT_ID_KEY); Preconditions.checkArgument( !Strings.isNullOrEmpty(projectId), String.format("Project ID must be supplied via %s", PROJECT_ID_KEY)); optionsBuilder.setProjectId(projectId); String host = configuration.get(ANVILTOP_HOST_KEY); Preconditions.checkArgument( !Strings.isNullOrEmpty(host), String.format("API endpoint host must be supplied via %s", ANVILTOP_HOST_KEY)); optionsBuilder.setHost(host); int port = configuration.getInt(ANVILTOP_PORT_KEY, DEFAULT_ANVILTOP_PORT); optionsBuilder.setPort(port); try { if (configuration.getBoolean( ANVILTOP_USE_SERVICE_ACCOUNTS_KEY, ANVILTOP_USE_COMPUTE_CREDENTIAL_DEFAULT)) { String serviceAccountEmail = configuration.get(ANVILTOP_SERVICE_ACCOUNT_EMAIL_KEY); if (!Strings.isNullOrEmpty(serviceAccountEmail)) { String keyfileLocation = configuration.get(ANVILTOP_SERVICE_ACCOUNT_P12_KEYFILE_LOCATION_KEY); Preconditions.checkState( !Strings.isNullOrEmpty(keyfileLocation), "Key file location must be specified when setting service account email"); optionsBuilder.setCredential( CredentialFactory.getCredentialFromPrivateKeyServiceAccount( serviceAccountEmail, keyfileLocation)); } else { optionsBuilder.setCredential(CredentialFactory.getCredentialFromMetadataServiceAccount()); } } else if (configuration.getBoolean( ANVILTOP_NULL_CREDENTIAL_ENABLE_KEY, ANVILTOP_NULL_CREDENTIAL_ENABLE_DEFAULT)) { optionsBuilder.setCredential(null); } } catch (GeneralSecurityException gse) { throw new IOException("Failed to acquire credential.", gse); } return optionsBuilder.build(); }

Target:
public static AnviltopOptions fromConfiguration(Configuration configuration) throws IOException { AnviltopOptions.Builder optionsBuilder = new AnviltopOptions.Builder(); String projectId = configuration.get(PROJECT_ID_KEY); Preconditions.checkArgument( !Strings.isNullOrEmpty(projectId), String.format("Project ID must be supplied via %s", PROJECT_ID_KEY)); optionsBuilder.setProjectId(projectId); String host = configuration.get(ANVILTOP_HOST_KEY); Preconditions.checkArgument( !Strings.isNullOrEmpty(host), String.format("API endpoint host must be supplied via %s", ANVILTOP_HOST_KEY)); optionsBuilder.setHost(host); int port = configuration.getInt(ANVILTOP_PORT_KEY, DEFAULT_ANVILTOP_PORT); optionsBuilder.setPort(port); try { if (configuration.getBoolean( ANVILTOP_USE_SERVICE_ACCOUNTS_KEY, ANVILTOP_USE_SERVICE_ACCOUNTS_DEFAULT)) { String serviceAccountEmail = configuration.get(ANVILTOP_SERVICE_ACCOUNT_EMAIL_KEY); if (!Strings.isNullOrEmpty(serviceAccountEmail)) { String keyfileLocation = configuration.get(ANVILTOP_SERVICE_ACCOUNT_P12_KEYFILE_LOCATION_KEY); Preconditions.checkState( !Strings.isNullOrEmpty(keyfileLocation), "Key file location must be specified when setting service account email"); optionsBuilder.setCredential( CredentialFactory.getCredentialFromPrivateKeyServiceAccount( serviceAccountEmail, keyfileLocation)); } else { optionsBuilder.setCredential(CredentialFactory.getCredentialFromMetadataServiceAccount()); } } else if (configuration.getBoolean( ANVILTOP_NULL_CREDENTIAL_ENABLE_KEY, ANVILTOP_NULL_CREDENTIAL_ENABLE_DEFAULT)) { optionsBuilder.setCredential(null); } else { throw new IllegalStateException( "Either service account or null credentials must be enabled"); } } catch (GeneralSecurityException gse) { throw new IOException("Failed to acquire credential.", gse); } return optionsBuilder.build(); }