Skip to content

Commit 4b74d6e

Browse files
committed
Separate StorageCredential/Credential
1 parent e153903 commit 4b74d6e

File tree

7 files changed

+38
-16
lines changed

7 files changed

+38
-16
lines changed

aws/src/main/java/org/apache/iceberg/aws/s3/S3FileIO.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class S3FileIO
105105
private MetricsContext metrics = MetricsContext.nullMetrics();
106106
private final AtomicBoolean isResourceClosed = new AtomicBoolean(false);
107107
private transient StackTraceElement[] createStack;
108-
private List<? extends StorageCredential> storageCredentials = ImmutableList.of();
108+
private List<StorageCredential> storageCredentials = ImmutableList.of();
109109

110110
/**
111111
* No-arg constructor to load the FileIO dynamically.
@@ -565,13 +565,13 @@ private boolean recoverObject(ObjectVersion version, String bucket) {
565565
}
566566

567567
@Override
568-
public void setCredentials(List<? extends StorageCredential> credentials) {
568+
public void setCredentials(List<StorageCredential> credentials) {
569569
Preconditions.checkArgument(credentials != null, "Invalid storage credentials: null");
570570
this.storageCredentials = credentials;
571571
}
572572

573573
@Override
574-
public List<? extends StorageCredential> credentials() {
574+
public List<StorageCredential> credentials() {
575575
return ImmutableList.copyOf(storageCredentials);
576576
}
577577

core/src/main/java/org/apache/iceberg/CatalogUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public static FileIO loadFileIO(
372372
String impl,
373373
Map<String, String> properties,
374374
Object hadoopConf,
375-
List<? extends StorageCredential> storageCredentials) {
375+
List<StorageCredential> storageCredentials) {
376376
LOG.info("Loading custom FileIO implementation: {}", impl);
377377
DynConstructors.Ctor<FileIO> ctor;
378378
try {

core/src/main/java/org/apache/iceberg/io/SupportsStorageCredentials.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
public interface SupportsStorageCredentials {
2424

25-
void setCredentials(List<? extends StorageCredential> credentials);
25+
void setCredentials(List<StorageCredential> credentials);
2626

27-
List<? extends StorageCredential> credentials();
27+
List<StorageCredential> credentials();
2828
}

core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Set;
2828
import java.util.function.BiFunction;
2929
import java.util.function.Function;
30+
import java.util.stream.Collectors;
3031
import org.apache.iceberg.BaseTable;
3132
import org.apache.iceberg.CatalogProperties;
3233
import org.apache.iceberg.CatalogUtil;
@@ -54,6 +55,8 @@
5455
import org.apache.iceberg.io.CloseableGroup;
5556
import org.apache.iceberg.io.FileIO;
5657
import org.apache.iceberg.io.FileIOTracker;
58+
import org.apache.iceberg.io.ImmutableStorageCredential;
59+
import org.apache.iceberg.io.StorageCredential;
5760
import org.apache.iceberg.metrics.MetricsReporter;
5861
import org.apache.iceberg.metrics.MetricsReporters;
5962
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
@@ -972,7 +975,16 @@ private FileIO newFileIO(
972975
return ioBuilder.apply(context, properties);
973976
} else {
974977
String ioImpl = properties.getOrDefault(CatalogProperties.FILE_IO_IMPL, DEFAULT_FILE_IO_IMPL);
975-
return CatalogUtil.loadFileIO(ioImpl, properties, conf, storageCredentials);
978+
List<StorageCredential> credentials =
979+
storageCredentials.stream()
980+
.map(
981+
c ->
982+
ImmutableStorageCredential.builder()
983+
.prefix(c.prefix())
984+
.config(c.config())
985+
.build())
986+
.collect(Collectors.toList());
987+
return CatalogUtil.loadFileIO(ioImpl, properties, conf, credentials);
976988
}
977989
}
978990

core/src/main/java/org/apache/iceberg/rest/credentials/Credential.java

+13-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@
1818
*/
1919
package org.apache.iceberg.rest.credentials;
2020

21-
import org.apache.iceberg.io.StorageCredential;
21+
import java.util.Map;
22+
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
2223
import org.immutables.value.Value;
2324

24-
@SuppressWarnings("immutables:incompat")
2525
@Value.Immutable
26-
public interface Credential extends StorageCredential {}
26+
public interface Credential {
27+
String prefix();
28+
29+
Map<String, String> config();
30+
31+
@Value.Check
32+
default void validate() {
33+
Preconditions.checkArgument(!prefix().isEmpty(), "Invalid prefix: must be non-empty");
34+
Preconditions.checkArgument(!config().isEmpty(), "Invalid config: must be non-empty");
35+
}
36+
}

core/src/test/java/org/apache/iceberg/TestCatalogUtil.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public void report(MetricsReport report) {}
522522
public static class TestFileIOWithStorageCredentials
523523
implements FileIO, SupportsStorageCredentials {
524524

525-
private List<? extends StorageCredential> storageCredentials;
525+
private List<StorageCredential> storageCredentials;
526526

527527
public TestFileIOWithStorageCredentials() {}
528528

@@ -540,12 +540,12 @@ public OutputFile newOutputFile(String path) {
540540
public void deleteFile(String path) {}
541541

542542
@Override
543-
public void setCredentials(List<? extends StorageCredential> credentials) {
543+
public void setCredentials(List<StorageCredential> credentials) {
544544
this.storageCredentials = credentials;
545545
}
546546

547547
@Override
548-
public List<? extends StorageCredential> credentials() {
548+
public List<StorageCredential> credentials() {
549549
return storageCredentials;
550550
}
551551
}

gcp/src/main/java/org/apache/iceberg/gcp/gcs/GCSFileIO.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class GCSFileIO implements DelegateFileIO, SupportsStorageCredentials {
7575
private final AtomicBoolean isResourceClosed = new AtomicBoolean(false);
7676
private SerializableMap<String, String> properties = null;
7777
private OAuth2RefreshCredentialsHandler refreshHandler = null;
78-
private List<? extends StorageCredential> storageCredentials = ImmutableList.of();
78+
private List<StorageCredential> storageCredentials = ImmutableList.of();
7979

8080
/**
8181
* No-arg constructor to load the FileIO dynamically.
@@ -263,13 +263,13 @@ private void internalDeleteFiles(Stream<BlobId> blobIdsToDelete) {
263263
}
264264

265265
@Override
266-
public void setCredentials(List<? extends StorageCredential> credentials) {
266+
public void setCredentials(List<StorageCredential> credentials) {
267267
Preconditions.checkArgument(credentials != null, "Invalid storage credentials: null");
268268
this.storageCredentials = credentials;
269269
}
270270

271271
@Override
272-
public List<? extends StorageCredential> credentials() {
272+
public List<StorageCredential> credentials() {
273273
return ImmutableList.copyOf(storageCredentials);
274274
}
275275

0 commit comments

Comments
 (0)