bharos commented on code in PR #9839:
URL: https://github.com/apache/gravitino/pull/9839#discussion_r2752317485
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/CatalogWrapperForREST.java:
##########
@@ -238,6 +239,36 @@ private Credential getCredential(
return credential;
}
+ private boolean shouldGenerateCredential(
+ LoadTableResponse loadTableResponse, boolean requestCredential) {
+ if (!requestCredential) {
+ return false;
+ }
+ return !isLocalOrHdfsTable(loadTableResponse.tableMetadata());
+ }
+
+ private boolean isLocalOrHdfsTable(TableMetadata tableMetadata) {
+ return isLocalOrHdfsLocation(tableMetadata.location());
+ }
+
+ @VisibleForTesting
+ static boolean isLocalOrHdfsLocation(String location) {
+ if (StringUtils.isBlank(location)) {
+ return false;
+ }
Review Comment:
I think it's ok. If we want we could do
```
private boolean shouldGenerateCredential(
LoadTableResponse loadTableResponse, boolean requestCredential) {
if (!requestCredential) {
return false;
}
String location = loadTableResponse.tableMetadata().location();
// Fail fast on invalid locations
if (StringUtils.isBlank(location)) {
throw new IllegalArgumentException(
"Table location cannot be null or blank when requesting
credentials");
}
return !isLocalOrHdfsLocation(location);
}
@VisibleForTesting
static boolean isLocalOrHdfsLocation(String location) {
// Precondition: location is non-blank (enforced by caller)
URI uri;
try {
uri = URI.create(location);
} catch (IllegalArgumentException e) {
return false;
}
String scheme = uri.getScheme();
if (scheme == null) {
return true; // no scheme = local path
}
return "file".equalsIgnoreCase(scheme) || "hdfs".equalsIgnoreCase(scheme);
}
```
but your current code is ok as well with the assumption location should not
be null
Also add a comment for if scheme== null that no scheme means local path ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]