-
Notifications
You must be signed in to change notification settings - Fork 76
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
Don't require secret id in user if already given in jdbc url #17
Open
dmcgillen
wants to merge
2
commits into
aws:master
Choose a base branch
from
dmcgillen:use-jdbc-url-secret-as-user
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -354,16 +354,29 @@ public Connection connect(String url, Properties info) throws SQLException { | |
return null; | ||
} | ||
|
||
String unwrappedUrl = ""; | ||
if (url.startsWith(SCHEME)) { // If this is a URL in the correct scheme, unwrap it | ||
unwrappedUrl = unwrapUrl(url); | ||
String unwrappedUrl = unwrapUrl(url); | ||
|
||
if (info != null && info.getProperty("user") != null) { | ||
String credentialsSecretId = info.getProperty("user"); | ||
try { | ||
return connectWithSecret(unwrappedUrl, info, credentialsSecretId); | ||
} catch (InterruptedException e) { | ||
// User driven exception. Throw a runtime exception. | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
return getWrappedDriver().connect(unwrappedUrl, info); | ||
} | ||
|
||
} else { // Else, assume this is a secret ID and try to retrieve it | ||
String secretString = secretCache.getSecretString(url); | ||
if (StringUtils.isNullOrEmpty(secretString)) { | ||
throw new IllegalArgumentException("URL " + url + " is not a valid URL starting with scheme " + | ||
SCHEME + " or a valid retrievable secret ID "); | ||
} | ||
|
||
String unwrappedUrl = ""; | ||
try { | ||
JsonNode jsonObject = mapper.readTree(secretString); | ||
String endpoint = jsonObject.get("host").asText(); | ||
|
@@ -376,18 +389,14 @@ public Connection connect(String url, Properties info) throws SQLException { | |
// Most likely to occur in the event that the data is not JSON. This is more of a user error. | ||
throw new RuntimeException(INVALID_SECRET_STRING_JSON); | ||
} | ||
} | ||
|
||
if (info != null && info.getProperty("user") != null) { | ||
String credentialsSecretId = info.getProperty("user"); | ||
try { | ||
return connectWithSecret(unwrappedUrl, info, credentialsSecretId); | ||
return connectWithSecret(unwrappedUrl, info, url); | ||
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. And in the case a user is using a secret as the jdbc url, just use that value rather than looking in user. |
||
} catch (InterruptedException e) { | ||
// User driven exception. Throw a runtime exception. | ||
throw new RuntimeException(e); | ||
} | ||
} else { | ||
return getWrappedDriver().connect(unwrappedUrl, info); | ||
|
||
} | ||
} | ||
|
||
|
This file contains 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.
This is existing code that was previously after this
if
. It only applies if you are using a full jdbc url with the scheme, so I've moved it up here.