private OAuth2Credentials extractCredentials()

in cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/SpannerConnectionFactoryProvider.java [177:202]


  private OAuth2Credentials extractCredentials(ConnectionFactoryOptions options) {

    Set<Option<?>> foundSecurityOptions = new HashSet<>();
    for (Option<?> option : SECURITY_OPTIONS) {
      if (options.hasOption(option)) {
        foundSecurityOptions.add(option);
      }
    }

    if (foundSecurityOptions.size() > 1) {
      throw new IllegalArgumentException(
          "Please provide at most one authentication option. Found: " + foundSecurityOptions);
    }

    if (options.hasOption(OAUTH_TOKEN)) {
      return this.credentialsHelper.getOauthCredentials((String) options.getValue(OAUTH_TOKEN));
    } else if (options.hasOption(CREDENTIALS)) {
      return this.credentialsHelper.getFileCredentials((String) options.getValue(CREDENTIALS));
    } else if (options.hasOption(GOOGLE_CREDENTIALS)) {
      return (OAuth2Credentials) options.getValue(GOOGLE_CREDENTIALS);
    } else if (options.hasOption(USE_PLAIN_TEXT)) {
      return NoCredentials.getInstance();
    }

    return this.credentialsHelper.getDefaultCredentials();
  }