-
Notifications
You must be signed in to change notification settings - Fork 4.6k
🎉 Source redshift: implement privileges check #9744
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a98a8e6
fix: postgres priviledge check for redshift
ethanve ee65b0d
add missing imports
alafanechere f17818c
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere fcecd98
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere 0396618
bump version
alafanechere 33ada8f
format
alafanechere 3ba2418
Update docs/integrations/sources/redshift.md
alafanechere 7ecc9e4
remove not used fields from query results
alafanechere 3d996e4
improve changelog
alafanechere 72690a7
create unreadable table
alafanechere fb2b6a6
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere 5eaf663
update documentation url in spec.json
alafanechere b079fdc
fix tests
alafanechere 4ce02a6
fix tests
alafanechere c945988
bump version to 0.3.8 in dockerfile
alafanechere b9b9227
Fix method override
tuliren 1c9ed2d
Limit schemas in jdbc test
tuliren 81591a2
Revert jdbc acceptance test change
tuliren ceba782
Fix sql statement
tuliren 81e73de
Fix empty stream name and wrong username
tuliren 1137d6a
Close the connection that queries for privileges in redshift
tuliren 0c3e8a7
Add more comment
tuliren f214661
fix SQL query to check privileges
alafanechere 7f2eec5
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere a7782f4
bump to 0.3.9
alafanechere d698334
fix SQL query to check privileges
alafanechere d940fc0
fix SQL query to check privileges
alafanechere 5285228
use specific test user
alafanechere 87d343e
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere cddf939
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere e29b817
make changes suggested by liren
alafanechere f7aa4f2
update source_specs.yaml
alafanechere b47cb35
Merge branch 'master' into augustin/fix/redshift-privileges
alafanechere 740c8bc
format
alafanechere File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
package io.airbyte.integrations.source.redshift; | ||
|
||
import static java.util.stream.Collectors.toSet; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.airbyte.commons.json.Jsons; | ||
|
@@ -12,9 +14,12 @@ | |
import io.airbyte.integrations.base.IntegrationRunner; | ||
import io.airbyte.integrations.base.Source; | ||
import io.airbyte.integrations.source.jdbc.AbstractJdbcSource; | ||
import io.airbyte.integrations.source.jdbc.dto.JdbcPrivilegeDto; | ||
import io.airbyte.integrations.source.relationaldb.TableInfo; | ||
import io.airbyte.protocol.models.CommonField; | ||
import java.sql.JDBCType; | ||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
@@ -93,6 +98,25 @@ public Set<String> getExcludedInternalNameSpaces() { | |
return Set.of("information_schema", "pg_catalog", "pg_internal", "catalog_history"); | ||
} | ||
|
||
@Override | ||
public Set<JdbcPrivilegeDto> getPrivilegesTableForCurrentUser(final JdbcDatabase database, final String schema) throws SQLException { | ||
return database.query(connection -> { | ||
final PreparedStatement ps = connection.prepareStatement( | ||
"SELECT DISTINCT table_catalog, table_schema, table_name, privilege_type\n" | ||
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. The values in column |
||
+ "FROM information_schema.table_privileges\n" | ||
+ "WHERE grantee = ? AND privilege_type = 'SELECT'"); | ||
ps.setString(1, database.getDatabaseConfig().get("username").asText()); | ||
return ps; | ||
}, sourceOperations::rowToJson) | ||
.collect(toSet()) | ||
.stream() | ||
.map(e -> JdbcPrivilegeDto.builder() | ||
.schemaName(e.get("table_schema").asText()) | ||
.tableName(e.get("table_name").asText()) | ||
.build()) | ||
.collect(toSet()); | ||
} | ||
|
||
public static void main(final String[] args) throws Exception { | ||
final Source source = new RedshiftSource(); | ||
LOGGER.info("starting source: {}", RedshiftSource.class); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
By the way, we no longer depend on these individual connector definitions. You don't need to update them any more. These files are still in our codebase for backward compatibility.
Actually I will check if we can remove all of them, since we already had that pseudo major version bump, and backward compatibility may not be needed.