Skip to content
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

Updated CryptographyServiceClient to preserve the HTTP port if provided in a key identifier. #24539

Merged
merged 4 commits into from
Oct 5, 2021

Conversation

vcolin7
Copy link
Member

@vcolin7 vcolin7 commented Oct 5, 2021

Fixes: #24508.

@vcolin7 vcolin7 self-assigned this Oct 5, 2021
@vcolin7 vcolin7 requested a review from samvaity as a code owner October 5, 2021 08:46
@ghost ghost added the KeyVault label Oct 5, 2021
@azure-sdk
Copy link
Collaborator

API changes have been detected in com.azure:azure-security-keyvault-keys. You can review API changes here

API changes

+         public CryptographyAsyncClient getCryptographyAsyncClient(String keyName) 
+         public CryptographyAsyncClient getCryptographyAsyncClient(String keyName, String keyVersion) 
+         public CryptographyClient getCryptographyClient(String keyName) 
+         public CryptographyClient getCryptographyClient(String keyName, String keyVersion) 

Copy link
Member

@maorleger maorleger left a comment

Choose a reason for hiding this comment

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

🚀 - just one suggestion

@@ -797,6 +797,11 @@ private void unpackAndValidateId(String keyId) {
URL url = new URL(keyId);
String[] tokens = url.getPath().split("/");
String endpoint = url.getProtocol() + "://" + url.getHost();

if (url.getPort() != -1) {
endpoint += ":" + url.getPort();
Copy link
Member

Choose a reason for hiding this comment

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

If supported by versions of Java we support,
have you looked at https://docs.oracle.com/javase/7/docs/api/java/net/URL.html#getAuthority()? It will return both host and port (if port is provided)

String endpoint = url.getProtocol() + "://" + url.getAuthority();

Copy link
Member Author

Choose a reason for hiding this comment

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

Great suggestion, thank you Maor!

Copy link
Member Author

@vcolin7 vcolin7 Oct 5, 2021

Choose a reason for hiding this comment

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

@maorleger Now that I think about it, getAuthority() also includes username and password information if present on the URL, would we want to include any of that in the key identifier in case somebody actually includes it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll play it safe and use getHost() and getPort() for now.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense! Sorry, was afk

@vcolin7 vcolin7 merged commit c938534 into Azure:main Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQ] Port should not be removed from Key Vault Key Id when Cryptography Client is initialized
3 participants