-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Storage] Use @azure/core-http in @azure/storage-* libraries to support @azure/identity #3853
[Storage] Use @azure/core-http in @azure/storage-* libraries to support @azure/identity #3853
Conversation
That would be valuable! |
/cc @XiaoningLiu I think this is a good start for enabling azure-identity. We can discuss better integration with current credentials in Storage but that may need to happen after this preview if it's taking longer to implement. |
*/ | ||
include?: ListQueuesIncludeType; | ||
include?: ListQueuesIncludeType[]; |
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 looks breaking too. I wonder whether the original generated code is wrong, or intentionally changed to a singleton, as the only valid type here is 'metadata'
. @XiaoningLiu do you remember anything?
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.
Looks like it's represented as array
in the OpenAPI json:
"ListQueuesInclude": {
"name": "include",
"in": "query",
"required": false,
"type": "array",
"collectionFormat": "csv",
"items": {
"type": "string",
"enum": [
"metadata"
],
"x-ms-enum": {
"name": "ListQueuesIncludeType",
"modelAsString": false
}
},
"x-ms-parameter-location": "method",
"description": "Include this parameter to specify that the queues's metadata be returned as part of the response body."
},
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 believe this is a swagger breaking change introduced in https://msazure.visualstudio.com/One/_git/Storage-XStore/commit/76530600659f4d591d65266c74b2d96c785c3015?_a=compare&path=%2Fsrc%2FXFE%2FOpenApi%2FMicrosoft.QueueStorage%2Fpreview%2F2018-03-28%2Fqueue.json
We can take this change. But please update BreakingChange.md for this.
b1c0b01
to
bcf748f
Compare
I had a great idea for the naming conflict regarding BTW, in https://github.com/azure/azure-sdk-for-js#authentication , it recommends to use @azure/ms-rest-nodeauth and @azure/ms-rest-browserauth for authentication. What's the relationship between them with @azure/identity? In reply to: 502846562 [](ancestors = 502846562) |
@david Wilson For core-http change, do we need a newer autorest.typescript version? If so, please update the autorest.typescript version here. Refers to: sdk/storage/storage-queue/package.json:21 in bcf748f. [](commit_id = bcf748f, deletion_comment = False) |
Is there any autorest generator configuration change? If so, please update swagger/readmd.md, and any configurations defined in package.json |
d108cc9
to
393f796
Compare
@XiaoningLiu Thanks for the great feedback! I've made some of the changes you requested and also added Regarding the AutoRest changes, I'm currently working out of the No configuration changes are needed for the |
393f796
to
d605dad
Compare
1aecdd6
to
dbceed4
Compare
b7d999c
to
6313f3c
Compare
getToken(_scopes: string | string[], _options?: GetTokenOptions): Promise<AccessToken | null> { | ||
return Promise.resolve({ | ||
token: this.token, | ||
expiresOnTimestamp: Date.now() + 2 * 60 * 1000 // 2 Minutes |
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.
expiresOnTimestamp [](start = 6, length = 18)
We should assume token provided in RawTokenCredential
will never expired, because it's up to customers refreshing token string value.
Can we set it to infinity?
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.
We've implemented token refreshing based on expiration time in BearerTokenAuthenticationPolicy
so since it's possible for the user to change the token
, we need a relatively short expiration so we aren't using an out of date token.
One possibility is that I could change that caching code to always ask for the current token when expiresOnTimestamp
is set to 0
.
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 am correct, RawTokenCredential
is a simple wrapper for bearer token string. It needs manually refresh by customers upodating token
property.
I'm not sure what happens after 2 mins timeout. Because RawTokenCredential
doesn't define any token refresh logic.
So what will hapen after 2mins timeout? Will underlayer just call getToken
again? If so, this call can be optimized by setting up an infinite token..
In reply to: 295116310 [](ancestors = 295116310)
@jeremymeng Can you help open an issue to track the authentication merging between storage SDK and @azure/identity? `Credential | TokenCredential' works to compatible with @azure/identity, but still feels not perfect, we can resolve this later before track2 GA. |
0996dde
to
36cd16f
Compare
Finally completed work on I've taken the PR out of Draft state so feel free to take a final look over this whenever you have a chance. I'll also review everything in more detail and make some tweaks if necessary. |
Can I get a sense of what code bloat you're getting when converting to ES2015? I know ES5 is pretty rough, but I'm having a hard time understanding where things go really wrong. The following code let x = {
async getToken(): Promise<Token> {
return token;
}
}; is emitted as follows in ES2015 "use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
let x = {
getToken() {
return __awaiter(this, void 0, void 0, function* () {
return token;
});
}
}; and when using import * as tslib from "tslib";
let x = {
getToken() {
return tslib.__awaiter(this, void 0, void 0, function* () {
return token;
});
}
}; So can you give me an example of where things explode? |
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 am fine with async function. I don't thin the discussion should block this PR. |
OK, I've updated everything based on all of the review feedback so far. A summary of the latest changes:
@XiaoningLiu, let me know if you have any final comments, otherwise I'll get this merged first thing Monday morning Pacific time. Thanks! |
import { BlobServiceClient, SharedKeyCredential } from "../../src"; // Change to "@azure/storage-blob" in your package | ||
import { DefaultAzureCredential } from "@azure/identity"; | ||
|
||
async function main() { |
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.
main [](start = 15, length = 4)
Is "Ad" or "Aad"? is this file name azureAdAuth.ts
correct?
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 called it "azureAd" to refer to "Azure Active Directory", though I can see how having "aad" explicitly could make things clearer. I'll ask someone about this and will rename these files after the PR gets merged if necessary.
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.
Added several minor comments. Please make sure all test cases and samples provided works. Other looks good!
@HarshaNalluru @jeremymeng PR triggered checks skip all storage tests. Is this expected? Considering we added mocking test already, can we enable tests against PRs?
Thanks @XiaoningLiu, I've made updates to address your feedback. Once CI goes green I will get this merged. Thanks everyone! |
Created a new issue - #4036 |
This PR updates the
@azure/storage-*
libraries to use the new@azure/core-http
and itsTokenCredential
interface so that the@azure/identity
library's credential implementations can be used with it. The largest part of the changes is switching from@azure/ms-rest-js
to@azure/core-http
and the changes to the generated code from using an updatedautorest.typescript
.The real meat of the changes is in the
*Client
classes likeQueueClient
where I add an additionalTokenCredential
type option for thecredential
argument and then set up the pipeline differently inPipeline.ts
depending on which credential has been passed.Questions for Reviewers
samples/
folder strictly for showing how to use@azure/identity
with this library?Tasks
TokenCredential
toRawTokenCredential
storage-blob
andstorage-file
@azure/identity
in samples for all 3 librariesPipeline
uses aBearerTokenAuthenticationPolicy
when aTokenCredential
is passedServiceCallback<void>
BreakingChange.md
if necessary to mention spec change ([Storage] Use @azure/core-http in @azure/storage-* libraries to support @azure/identity #3853 (comment))