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

Added token credential for queue #4673

Merged
merged 20 commits into from
Aug 13, 2019
Merged

Added token credential for queue #4673

merged 20 commits into from
Aug 13, 2019

Conversation

sima-zhu
Copy link
Contributor

No description provided.

@sima-zhu sima-zhu self-assigned this Jul 29, 2019
@kurtzeborn kurtzeborn added Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files) labels Jul 30, 2019
import java.util.TreeMap;


public final class Utility {
Copy link
Member

Choose a reason for hiding this comment

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

If this is being copied from my PR to add a common package for storage make this package private as it will be replaced in the future.

Same comment for the public methods in this class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Done.

@@ -86,7 +86,8 @@ public QueueClient createClientWithCredential() {
QueueClient queueClient = new QueueClientBuilder()
.endpoint("https://${accountName}.queue.core.windows.net")
.queueName("myqueue")
.credential(SASTokenCredential.fromQuery("{SASTokenQueryParams}"))
.credential(SASTokenCredential.fromQueryParameters(
Copy link
Member

Choose a reason for hiding this comment

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

Let's simplify these examples and assume that SASTokenCredential.fromSASTokenString is used. There will be more changes to SASTokenCredential creation once Files and Queues have the ability to generate their own SAS tokens.

Copy link
Member

@jaschrep-msft jaschrep-msft left a comment

Choose a reason for hiding this comment

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

A few changes need to be copied across relevant files.

SASTokenCredential credential = SASTokenCredential.fromQuery(fullURL.getQuery());
if (credential != null) {
this.sasTokenCredential = credential;
this.sasTokenCredential = SASTokenCredential.fromQueryParameters(Utility.parseQueryString(fullURL.getQuery()));
Copy link
Member

Choose a reason for hiding this comment

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

Why are we parsing a query string into a map just to pass it into a method that turns it back into a query string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agreed with take the string directly. Moved it logic to SasTokenCredential for current use. Alan will have another common module PR which will take care the token as a whole.

Copy link
Contributor

Choose a reason for hiding this comment

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

One possible reason this was happening is for validation. We do something similar with permissions (parse the permissions string passed to validate it and then immediately toString it). If there is any sort of validation logic in either parseQueryString or fromQueryString, I'd recommend keeping this as is and adding a comment. If there's nothing of value and it's just a complete waste of cpu time, then I'm fine changing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line has been changed from Alan's common module PR.
I don't think it is good to address this only for queue.
If it is necessary, then we need to file a new issue to address this overall.

@@ -83,6 +86,7 @@
private HttpLogDetailLevel logLevel;
private RetryPolicy retryPolicy;
private Configuration configuration;
private TokenCredential tokenCredential;
Copy link
Member

Choose a reason for hiding this comment

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

Can you put this up with the other credential declarations so they're all together? Also, can we name the field bearerTokenCredential? That way, compared with the name sasTokenCredential, they both have qualifiers and it doesn't sound like one's a generic version of the other.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed the tokenCred as suggested.

* @return a mapping of query string pieces as key-value pairs.
*/
public static TreeMap<String, String> parseQueryString(final String queryString) {
TreeMap<String, String> pieces = new TreeMap<>(String::compareTo);
Copy link
Member

Choose a reason for hiding this comment

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

Declare as Map instead of TreeMap. I don't see the justification for declaring implementation details.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline with @alzimmermsft , this is introduced by previous change.
I would like to keep it as it is, as there is no hurt to the functionality. We will make decision in common module PR.

import java.util.TreeMap;


public final class Utility {
Copy link
Member

Choose a reason for hiding this comment

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

This class feels like it should be in common package, not queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alan has another PR to extract the common module.
I copied over some of the necessary one to support the Preview 2 release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sima-zhu and others added 5 commits July 30, 2019 16:58
* Renamed StorageClient to BlobServiceClient

* Cleanup README

* Fix README example links

* Fixed XML serialization issue
* Added links REST API documentation
@sima-zhu sima-zhu requested a review from jaschrep-msft July 30, 2019 23:59
Copy link
Contributor

@rickle-msft rickle-msft left a comment

Choose a reason for hiding this comment

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

:shipit:

@sima-zhu sima-zhu merged commit bfa50bc into Azure:master Aug 13, 2019
@sima-zhu sima-zhu deleted the tokenCred branch August 13, 2019 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants