-
Notifications
You must be signed in to change notification settings - Fork 426
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
Adding Old Constructor back to AKV Provider #675
Adding Old Constructor back to AKV Provider #675
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #675 +/- ##
============================================
- Coverage 48.08% 48.02% -0.07%
+ Complexity 2586 2582 -4
============================================
Files 114 114
Lines 26578 26601 +23
Branches 4453 4454 +1
============================================
- Hits 12781 12775 -6
- Misses 11664 11689 +25
- Partials 2133 2137 +4
Continue to review full report at Codecov.
|
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.
I tested the code and read through the logic, LGTM. Thanks for the implementation.
@@ -24,20 +24,30 @@ | |||
*/ | |||
class KeyVaultCredential extends KeyVaultCredentials { | |||
|
|||
SQLServerKeyVaultAuthenticationCallback authenticationCallback = null; |
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.
Indentation.
* when an error occurs | ||
*/ | ||
public SQLServerColumnEncryptionAzureKeyVaultProvider(SQLServerKeyVaultAuthenticationCallback authenticationCallback, | ||
ExecutorService executorService) throws SQLServerException { |
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.
Where is executorService
used?
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.
executorService
is not consumed here because the KeyVaultClientImpl
now manages its own KeyVaultClientService
as here. These services are used by Retrofit to make Rest Calls.
The only reason of adding this here was to retain the old constructor params used by current applications in industry to allow no change upgrade of JDBC Driver version, but can be removed as well.
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.
Could lead to confusions. Let's make sure we discuss this with Jakub.
public String doAuthenticate(String authorization, | ||
String resource, | ||
String scope) { | ||
AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId, clientKey); | ||
return token.getAccessToken(); | ||
if(authenticationCallback==null) { |
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.
Maybe we could try to avoid multiple returns?
https://github.com/Microsoft/mssql-jdbc/blob/dev/Coding_Guidelines.md
… old Constructor and added a new constructor with 1 param
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.
Other than these two comments, I approve.
SQLServerKeyVaultAuthenticationCallback authenticationCallback = null; | ||
String clientId = null; | ||
String clientKey = null; | ||
String accessToken = null; |
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.
formatting here?
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.
That's how mssql-jdbc formatter works here.
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 what happens when you apply the formatter.
SQLServerKeyVaultAuthenticationCallback authenticationCallback = null;
String clientId = null;
String clientKey = null;
String accessToken = null;
RestClient restClient = new RestClient.Builder(new OkHttpClient.Builder(), new Retrofit.Builder()).withBaseUrl(baseUrl) | ||
.withCredentials(credentials).withSerializerAdapter(new AzureJacksonAdapter()) | ||
.withResponseBuilderFactory(new AzureResponseBuilder.Factory()).build(); | ||
keyVaultClient = new KeyVaultClient(restClient); |
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.
If both SQLServerColumnEncryptionAzureKeyVaultProvider constructors do exactly the same thing, maybe refactor the inner part so we don't duplicate code?
...actually, we would have to revert that in our next release when we remove the deprecated API. in that case, just have the SQLServerColumnEncryptionAzureKeyVaultProvider with ExecutorService in its parameter call the other SQLServerColumnEncryptionAzureKeyVaultProvider constructor.
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.
Fixed
*/ | ||
@Deprecated | ||
public SQLServerColumnEncryptionAzureKeyVaultProvider(SQLServerKeyVaultAuthenticationCallback authenticationCallback, | ||
ExecutorService executorService) throws SQLServerException { |
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.
Since we aren't doing anything with the executor, and the constructor is just here for backwards compatibility, shouldn't we make a call to SQLServerColumnEncryptionAzureKeyVaultProvider(SQLServerKeyVaultAuthenticationCallback authenticationCallback)
? This might confuse people who are stepping through the code, thinking there is a very small change somewhere and that's why there are separate functions.
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.
Fixed
AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId, clientKey); | ||
return token.getAccessToken(); | ||
String accessToken; | ||
if (authenticationCallback == null) { |
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.
if (null == authenticationCallback)
* @param authenticationCallback | ||
* - Callback function used for authenticating to AAD. | ||
* @param executorService | ||
* - The ExecutorService, previously used to create the keyVaultClient, but not in use anymore. - This param can be passed as 'null' |
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 parameter"
* Vault. | ||
* | ||
* This constructor is present to maintain backwards compatibility with 6.0 version of the driver. Deprecated for removal in next Stable release. |
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.
"stable release"
This PR adds back the old Constructor for SQLServerColumnEncryptionAzureKeyVaultProvider as below:
SQLServerColumnEncryptionAzureKeyVaultProvider akvProvider = new SQLServerColumnEncryptionAzureKeyVaultProvider(authenticationCallback, service);
This constructor was removed in PR #397 due to changed HttpClient implementation in AKV library version 1.0.0. With this PR we add backwards compatibility to applications using old AKV libraries with 6.0 and 6.2.1 driver versions and will now be able to upgrade without making any changes to code.