Skip to content

Commit

Permalink
chore: code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ttosta-google committed Oct 16, 2023
1 parent e779ed2 commit b57b171
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public String getAdminRootUrl() {
return adminRootUrl;
}

public String getlAdminServicePath() {
public String getAdminServicePath() {
return adminServicePath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public SqlAdminApiFetcher create(
if (config.getAdminRootUrl() != null) {
adminApiBuilder.setRootUrl(config.getAdminRootUrl());
}
if (config.getlAdminServicePath() != null) {
adminApiBuilder.setServicePath(config.getlAdminServicePath());
if (config.getAdminServicePath() != null) {
adminApiBuilder.setServicePath(config.getAdminServicePath());
}
return new SqlAdminApiFetcher(adminApiBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void testConfigFromProps() {
final List<IpType> wantIpTypes =
Arrays.asList(IpType.PSC, IpType.PRIVATE, IpType.PUBLIC); // PUBLIC is replaced with PRIMARY
final String ipTypes = "psc,Private,PUBLIC";
final String wantAdminRootUrl = "https://www.googleapis.com/";
final String wantAdminServicePath = "tasks/v1/";
final String wantAdminRootUrl = "https://googleapis.example.com/";
final String wantAdminServicePath = "sqladmin/";

Properties props = new Properties();
props.setProperty(ConnectionConfig.CLOUD_SQL_INSTANCE_PROPERTY, wantCsqlInstance);
Expand All @@ -59,7 +59,7 @@ public void testConfigFromProps() {
assertThat(c.getUnixSocketPath()).isEqualTo(wantUnixSocket);
assertThat(c.getIpTypes()).isEqualTo(wantIpTypes);
assertThat(c.getAdminRootUrl()).isEqualTo(wantAdminRootUrl);
assertThat(c.getlAdminServicePath()).isEqualTo(wantAdminServicePath);
assertThat(c.getAdminServicePath()).isEqualTo(wantAdminServicePath);
}

@Test
Expand All @@ -70,8 +70,8 @@ public void testConfigFromBuilder() {
final String wantUnixSocket = "/path/to/socket";
final List<IpType> wantIpTypes = Arrays.asList(IpType.PSC, IpType.PRIVATE, IpType.PUBLIC);
final AuthType wantAuthType = AuthType.PASSWORD;
final String wantAdminRootUrl = "https://www.googleapis.com/";
final String wantAdminServicePath = "tasks/v1/";
final String wantAdminRootUrl = "https://googleapis.example.com/";
final String wantAdminServicePath = "sqladmin/";

ConnectionConfig c =
new ConnectionConfig.Builder()
Expand All @@ -92,6 +92,6 @@ public void testConfigFromBuilder() {
assertThat(c.getUnixSocketPath()).isEqualTo(wantUnixSocket);
assertThat(c.getIpTypes()).isEqualTo(wantIpTypes);
assertThat(c.getAdminRootUrl()).isEqualTo(wantAdminRootUrl);
assertThat(c.getlAdminServicePath()).isEqualTo(wantAdminServicePath);
assertThat(c.getAdminServicePath()).isEqualTo(wantAdminServicePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public void testSetAdminUrl_FetchInstanceData_returnsIpAddresses()
throws ExecutionException, InterruptedException, GeneralSecurityException,
OperatorCreationException {

String adminRootUrl = "https://www.googleapis.com/";
String adminServicePath = "tasks/v1/";
String adminRootUrl = "https://googleapis.example.com/";
String adminServicePath = "sqladmin/";
String baseUrl = adminRootUrl + adminServicePath;
MockAdminApi mockAdminApi =
buildMockAdminApi(INSTANCE_CONNECTION_NAME, DATABASE_VERSION, baseUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public SqlAdminApiFetcher create(HttpRequestInitializer credentials, ConnectionC
if (config.getAdminRootUrl() != null) {
adminApiBuilder.setRootUrl(config.getAdminRootUrl());
}
if (config.getlAdminServicePath() != null) {
adminApiBuilder.setServicePath(config.getlAdminServicePath());
if (config.getAdminServicePath() != null) {
adminApiBuilder.setServicePath(config.getAdminServicePath());
}
return new SqlAdminApiFetcher(adminApiBuilder.build());
}
Expand Down
36 changes: 28 additions & 8 deletions docs/r2dbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,18 +270,38 @@ impersonates the TARGET_SERVICE_ACCOUNT.

## SQL Admin API URL

The Java Connector supports setting the SQL Admin API URL with the
`ADMIN_ROOT_URL` and `ADMIN_SERVICE_PATH` options. The `ADMIN_ROOT_URL`
option specifies the URL-encoded root URL of the service and the
`ADMIN_SERVICE_PATH` option specifies the URL-encoded service path of the
service.
The Java Connector supports setting the SQL Admin API URL with the
`ADMIN_ROOT_URL` and `ADMIN_SERVICE_PATH` options. This feature is used
by applications that need to connect to a Google Cloud API other than
the GCP public API.

The `ADMIN_ROOT_URL` option specifies the URL-encoded root URL of the
service, for example `"https://googleapis.example.com/"`. If the specified
root URL does not end with a "/" then a "/" is added to the end.

The `ADMIN_SERVICE_PATH` option specifies the URL-encoded service path of the
service, for example `"sqladmin/"`. It is allowed to be an empty string ""
or a forward slash "/", if it is a forward slash then it is treated as an
empty string. If the specified service path does not end with a "/" then a
"/" is added to the end. If the specified service path begins with a "/" then
the "/" is removed.

If these options are not set, the connector will use the public Google Cloud
API as follows:

```
DEFAULT_ROOT_URL = "https://sqladmin.googleapis.com/"
DEFAULT_SERVICE_PATH = ""
```

For more information, see the [underlying driver class documentation](https://cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.AbstractGoogleClient.Builder#com_google_api_client_googleapis_services_AbstractGoogleClient_Builder_setRootUrl_java_lang_String_).

### Example

```java
ConnectionFactoryOptions options=ConnectionFactoryOptions.builder()
.option(ADMIN_ROOT_URL, "https://www.googleapis.com/");
.option(ADMIN_SERVICE_PATH, "tasks/v1/")
ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
.option(ADMIN_ROOT_URL, "https://googleapis.example.com/");
.option(ADMIN_SERVICE_PATH, "sqladmin/")
// ...more connection options
.build;
```
Expand Down

0 comments on commit b57b171

Please sign in to comment.