Skip to content

Adding Old Constructor back to AKV Provider#675

Merged
cheenamalhotra merged 10 commits intomicrosoft:devfrom
cheenamalhotra:akv-old-constructor
May 25, 2018
Merged

Adding Old Constructor back to AKV Provider#675
cheenamalhotra merged 10 commits intomicrosoft:devfrom
cheenamalhotra:akv-old-constructor

Conversation

@cheenamalhotra
Copy link
Copy Markdown
Member

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.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 12, 2018

Codecov Report

Merging #675 into dev will decrease coverage by 0.06%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#JDBC42 47.94% <0%> (-0.03%) 2581 <0> (ø)
#JDBC43 47.89% <0%> (-0.11%) 2576 <0> (-6)
Impacted Files Coverage Δ Complexity Δ
...m/microsoft/sqlserver/jdbc/KeyVaultCredential.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...QLServerColumnEncryptionAzureKeyVaultProvider.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...m/microsoft/sqlserver/jdbc/SQLServerResultSet.java 33.21% <0%> (-0.4%) 245% <0%> (-3%)
...in/java/com/microsoft/sqlserver/jdbc/IOBuffer.java 54.53% <0%> (-0.2%) 0% <0%> (ø)
...m/microsoft/sqlserver/jdbc/SQLServerStatement.java 59.44% <0%> (-0.1%) 134% <0%> (-1%)
...rc/main/java/com/microsoft/sqlserver/jdbc/DDC.java 45.41% <0%> (ø) 107% <0%> (-1%) ⬇️
...om/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java 52.61% <0%> (+0.06%) 238% <0%> (-1%) ⬇️
...oft/sqlserver/jdbc/SQLServerPreparedStatement.java 50.68% <0%> (+0.24%) 157% <0%> (ø) ⬇️
...n/java/com/microsoft/sqlserver/jdbc/Parameter.java 62.76% <0%> (+0.83%) 63% <0%> (ø) ⬇️
...om/microsoft/sqlserver/jdbc/ReaderInputStream.java 46.06% <0%> (+1.12%) 17% <0%> (+1%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8cf4afb...e3bdaec. Read the comment docs.

@cheenamalhotra cheenamalhotra added this to the 6.5.2 milestone Apr 12, 2018
peterbae
peterbae previously approved these changes Apr 12, 2018
Copy link
Copy Markdown
Contributor

@peterbae peterbae left a 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.

*/
class KeyVaultCredential extends KeyVaultCredentials {

SQLServerKeyVaultAuthenticationCallback authenticationCallback = null;
Copy link
Copy Markdown
Contributor

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is executorService used?

Copy link
Copy Markdown
Member Author

@cheenamalhotra cheenamalhotra May 4, 2018

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.

Copy link
Copy Markdown
Contributor

@ulvii ulvii May 4, 2018

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.

String scope) {
AuthenticationResult token = getAccessTokenFromClientCredentials(authorization, resource, clientId, clientKey);
return token.getAccessToken();
if(authenticationCallback==null) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheenamalhotra cheenamalhotra changed the title Adding Old Constrcutor back to AKV Provider Adding Old Constructor back to AKV Provider May 10, 2018
Copy link
Copy Markdown
Contributor

@peterbae peterbae left a 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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting here?

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

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);
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member Author

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 {
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Member Author

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (null == authenticationCallback)

rene-ye
rene-ye previously approved these changes May 23, 2018
* @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'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This parameter"

* Constructor that takes a callback function to authenticate to AAD. This is used by KeyVaultClient at runtime to authenticate to Azure Key
* Vault.
*
* This constructor is present to maintain backwards compatibility with 6.0 version of the driver. Deprecated for removal in next Stable release.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"stable release"

@cheenamalhotra cheenamalhotra merged commit feaa8c3 into microsoft:dev May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants