-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Hive GCS to pass JSON key as a config #17892
Changes from 4 commits
1532ee9
867a230
e2dfaa9
e55631c
a7d3f8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,29 @@ | |
import io.airlift.configuration.ConfigDescription; | ||
import io.airlift.configuration.validation.FileExists; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
public class HiveGcsConfig | ||
{ | ||
private boolean useGcsAccessToken; | ||
private String jsonKeyFilePath; | ||
|
||
public boolean isUseGcsAccessToken() | ||
{ | ||
return useGcsAccessToken; | ||
} | ||
|
||
@Config("hive.gcs.use-access-token") | ||
@ConfigDescription("Use client-provided OAuth token to access Google Cloud Storage") | ||
public HiveGcsConfig setUseGcsAccessToken(boolean useGcsAccessToken) | ||
{ | ||
this.useGcsAccessToken = useGcsAccessToken; | ||
return this; | ||
} | ||
|
||
@Nullable | ||
@FileExists | ||
public String getJsonKeyFilePath() | ||
{ | ||
|
@@ -36,16 +54,12 @@ public HiveGcsConfig setJsonKeyFilePath(String jsonKeyFilePath) | |
return this; | ||
} | ||
|
||
public boolean isUseGcsAccessToken() | ||
public void validate() | ||
{ | ||
return useGcsAccessToken; | ||
} | ||
// This cannot be normal validation, as it would make it impossible to write TestHiveGcsConfig.testExplicitPropertyMappings | ||
|
||
@Config("hive.gcs.use-access-token") | ||
@ConfigDescription("Use client-provided OAuth token to access Google Cloud Storage") | ||
public HiveGcsConfig setUseGcsAccessToken(boolean useGcsAccessToken) | ||
{ | ||
this.useGcsAccessToken = useGcsAccessToken; | ||
return this; | ||
if (useGcsAccessToken) { | ||
checkState(jsonKeyFilePath == null, "Cannot specify 'hive.gcs.json-key-file-path' when 'hive.gcs.use-access-token' is set"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about the other way around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they are mutually exclusive, and i don't think it matters which way around i write it? |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,6 @@ | |
import io.trino.spi.connector.ConnectorSession; | ||
import org.apache.hadoop.fs.Path; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
@@ -50,14 +48,14 @@ public class GcsStorageFactory | |
|
||
private final HdfsEnvironment hdfsEnvironment; | ||
private final boolean useGcsAccessToken; | ||
@Nullable | ||
private final Optional<GoogleCredential> jsonGoogleCredential; | ||
|
||
@Inject | ||
public GcsStorageFactory(HdfsEnvironment hdfsEnvironment, HiveGcsConfig hiveGcsConfig) | ||
throws IOException | ||
{ | ||
this.hdfsEnvironment = requireNonNull(hdfsEnvironment, "hdfsEnvironment is null"); | ||
hiveGcsConfig.validate(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. airlift supports standard bean validation, so i don't think so normally it works awesome There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think the proper solution would be to split this into two config classes, and make one bound conditionally. |
||
this.useGcsAccessToken = hiveGcsConfig.isUseGcsAccessToken(); | ||
String jsonKeyFilePath = hiveGcsConfig.getJsonKeyFilePath(); | ||
if (jsonKeyFilePath != null) { | ||
|
@@ -88,7 +86,7 @@ public Storage create(ConnectorSession session, String path) | |
} | ||
} | ||
else { | ||
credential = jsonGoogleCredential.get(); | ||
credential = jsonGoogleCredential.orElseThrow(() -> new IllegalStateException("GCS credentials not configured")); | ||
findepi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return new Storage.Builder(httpTransport, JacksonFactory.getDefaultInstance(), new RetryHttpInitializer(credential, APPLICATION_NAME)) | ||
.setApplicationName(APPLICATION_NAME) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update
hive-gcs-tutorial.rst
? Follow-up is fine though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's follow-up. Docs would need to have good advice on where this can be used, which is tricky.