Skip to content

Commit 3e8e94f

Browse files
committed
fixup! Replace gcs.use-access-token with gcs.auth-type configuration
1 parent 4ddeb0e commit 3e8e94f

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

docs/src/main/sphinx/object-storage/file-system-gcs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ Cloud Storage:
6868

6969
* - Property
7070
- Description
71+
* - `gcs.use-access-token`
72+
- Flag to set usage of a client-provided OAuth 2.0 token to access Google
73+
Cloud Storage. Defaults to `false`, deprecated to use `gcs.auth-type` instead.
7174
* - `gcs.auth-type`
7275
- Authentication type to use for Google Cloud Storage access. Default to `DEFAULT`.
7376
Supported values are:

lib/trino-filesystem-gcs/src/main/java/io/trino/filesystem/gcs/GcsFileSystemConfig.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import io.airlift.configuration.Config;
1717
import io.airlift.configuration.ConfigDescription;
1818
import io.airlift.configuration.ConfigSecuritySensitive;
19-
import io.airlift.configuration.LegacyConfig;
2019
import io.airlift.configuration.validation.FileExists;
2120
import io.airlift.units.DataSize;
2221
import io.airlift.units.Duration;
@@ -30,27 +29,15 @@
3029
import java.util.Optional;
3130
import java.util.concurrent.TimeUnit;
3231

32+
import static com.google.common.base.Preconditions.checkArgument;
3333
import static io.airlift.units.DataSize.Unit.MEGABYTE;
34-
import static java.util.Locale.ENGLISH;
3534

3635
public class GcsFileSystemConfig
3736
{
3837
public enum AuthType
3938
{
4039
ACCESS_TOKEN,
4140
DEFAULT;
42-
43-
// Ensures backward compatibility with gcs.use-access-token config
44-
// TRUE is mapped to ACCESS_TOKEN
45-
// FALSE is mapped to DEFAULT
46-
public static AuthType fromString(String value)
47-
{
48-
return switch (value.toUpperCase(ENGLISH)) {
49-
case "TRUE" -> ACCESS_TOKEN;
50-
case "FALSE" -> DEFAULT;
51-
default -> valueOf(value.toUpperCase(ENGLISH));
52-
};
53-
}
5441
}
5542

5643
private DataSize readBlockSize = DataSize.of(2, MEGABYTE);
@@ -61,7 +48,8 @@ public static AuthType fromString(String value)
6148
private String projectId;
6249
private Optional<String> endpoint = Optional.empty();
6350

64-
private AuthType authType = AuthType.DEFAULT;
51+
private boolean useGcsAccessToken;
52+
private AuthType authType;
6553
private String jsonKey;
6654
private String jsonKeyFilePath;
6755
private int maxRetries = 20;
@@ -157,17 +145,37 @@ public GcsFileSystemConfig setEndpoint(Optional<String> endpoint)
157145
@NotNull
158146
public AuthType getAuthType()
159147
{
160-
return authType;
148+
return Optional.ofNullable(authType).orElse(AuthType.DEFAULT);
161149
}
162150

163-
@LegacyConfig("gcs.use-access-token")
164151
@Config("gcs.auth-type")
165152
public GcsFileSystemConfig setAuthType(AuthType authType)
166153
{
167154
this.authType = authType;
168155
return this;
169156
}
170157

158+
@Deprecated
159+
public boolean isUseGcsAccessToken()
160+
{
161+
return useGcsAccessToken;
162+
}
163+
164+
@Deprecated
165+
@Config("gcs.use-access-token")
166+
public GcsFileSystemConfig setUseGcsAccessToken(boolean useGcsAccessToken)
167+
{
168+
checkArgument(authType == null, "Cannot set both gcs.use-access-token and gcs.auth-type");
169+
this.useGcsAccessToken = useGcsAccessToken;
170+
if (useGcsAccessToken) {
171+
this.authType = AuthType.ACCESS_TOKEN;
172+
}
173+
else {
174+
this.authType = AuthType.DEFAULT;
175+
}
176+
return this;
177+
}
178+
171179
@Nullable
172180
public String getJsonKey()
173181
{

lib/trino-filesystem-gcs/src/test/java/io/trino/filesystem/gcs/TestGcsFileSystemConfig.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static io.airlift.units.DataSize.Unit.MEGABYTE;
3232
import static java.util.concurrent.TimeUnit.MILLISECONDS;
3333
import static java.util.concurrent.TimeUnit.SECONDS;
34+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
3435

3536
public class TestGcsFileSystemConfig
3637
{
@@ -44,7 +45,8 @@ void testDefaults()
4445
.setBatchSize(100)
4546
.setProjectId(null)
4647
.setEndpoint(Optional.empty())
47-
.setAuthType(AuthType.DEFAULT)
48+
.setUseGcsAccessToken(false)
49+
.setAuthType(null)
4850
.setJsonKey(null)
4951
.setJsonKeyFilePath(null)
5052
.setMaxRetries(20)
@@ -88,7 +90,18 @@ void testExplicitPropertyMappings()
8890
.setMinBackoffDelay(new Duration(20, MILLISECONDS))
8991
.setMaxBackoffDelay(new Duration(20, MILLISECONDS))
9092
.setApplicationId("application id");
91-
assertFullMapping(properties, expected, Set.of("gcs.json-key", "gcs.json-key-file-path"));
93+
assertFullMapping(properties, expected, Set.of("gcs.json-key", "gcs.json-key-file-path", "gcs.use-access-token"));
94+
}
95+
96+
@Test
97+
void testSetUseGcsAccessTokenWithAuthType()
98+
{
99+
assertThatThrownBy(() -> new GcsFileSystemConfig().setAuthType(AuthType.ACCESS_TOKEN).setUseGcsAccessToken(true))
100+
.isInstanceOf(IllegalArgumentException.class)
101+
.hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type");
102+
assertThatThrownBy(() -> new GcsFileSystemConfig().setAuthType(AuthType.DEFAULT).setUseGcsAccessToken(false))
103+
.isInstanceOf(IllegalArgumentException.class)
104+
.hasMessage("Cannot set both gcs.use-access-token and gcs.auth-type");
92105
}
93106

94107
@Test

0 commit comments

Comments
 (0)