static ConnectionConfig fromConnectionProperties()

in alloydb-jdbc-connector/src/main/java/com/google/cloud/alloydb/ConnectionConfig.java [48:92]


  static ConnectionConfig fromConnectionProperties(Properties props) {
    validateProperties(props);
    final String instanceNameStr = props.getProperty(ALLOYDB_INSTANCE_NAME, "");
    final InstanceName instanceName = InstanceName.parse(instanceNameStr);
    final String namedConnector = props.getProperty(ALLOYDB_NAMED_CONNECTOR);
    final String adminServiceEndpoint = props.getProperty(ALLOYDB_ADMIN_SERVICE_ENDPOINT);
    final String targetPrincipal = props.getProperty(ALLOYDB_TARGET_PRINCIPAL);
    final String delegatesStr = props.getProperty(ALLOYDB_DELEGATES);
    final List<String> delegates;
    if (delegatesStr != null && !delegatesStr.isEmpty()) {
      delegates = Arrays.asList(delegatesStr.split(","));
    } else {
      delegates = Collections.emptyList();
    }
    final String googleCredentialsPath = props.getProperty(ALLOYDB_GOOGLE_CREDENTIALS_PATH);
    final AuthType authType =
        Boolean.parseBoolean(props.getProperty(ENABLE_IAM_AUTH_PROPERTY))
            ? AuthType.IAM
            : AuthType.PASSWORD;
    final String quotaProject = props.getProperty(ALLOYDB_QUOTA_PROJECT);
    IpType ipType = IpType.PRIVATE;
    if (props.getProperty(ALLOYDB_IP_TYPE) != null) {
      ipType = IpType.valueOf(props.getProperty(ALLOYDB_IP_TYPE).toUpperCase(Locale.getDefault()));
    }
    RefreshStrategy refreshStrategy = RefreshStrategy.REFRESH_AHEAD;
    if (props.getProperty(ALLOYDB_REFRESH_STRATEGY) != null) {
      refreshStrategy =
          RefreshStrategy.valueOf(
              props.getProperty(ALLOYDB_REFRESH_STRATEGY).toUpperCase(Locale.getDefault()));
    }

    return new ConnectionConfig(
        instanceName,
        namedConnector,
        authType,
        ipType,
        new ConnectorConfig.Builder()
            .withTargetPrincipal(targetPrincipal)
            .withDelegates(delegates)
            .withAdminServiceEndpoint(adminServiceEndpoint)
            .withGoogleCredentialsPath(googleCredentialsPath)
            .withQuotaProject(quotaProject)
            .withRefreshStrategy(refreshStrategy)
            .build());
  }