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

Upgrade Resource & Storage SDK to T2 #1050

Merged
merged 13 commits into from
Feb 4, 2022
Merged

Upgrade Resource & Storage SDK to T2 #1050

merged 13 commits into from
Feb 4, 2022

Conversation

nturinski
Copy link
Member

A couple of changes to implement this:

  • list() now uses an PagedAsyncIterableIterator instead of Promise<IPartialList<T>. This means I can't just do an await list() anymore, which is why I have the helper function to help load all of the resources. Might be worth to do a loadByPage(numOfResources) helper function later too.
  • All T2 packages use a new type of credential called coreAuth.TokenCredential. This uses getToken rather than signRequest so I made a type compatible with both so createAzureClient could be used with both T1 and T2 ManagementClients.
  • They changed how to import the Models now to import individual models rather than the entire Model namespace.

Tested this with Functions Create (Advanced) and Container Apps. It still lists and creates resource groups and storage accounts, so I think everything is working? Container Apps uses the new T2 appservice package and those seem to be working as well, meaning the credentials are compatible with T1 and T2 azure sdk packages.

@nturinski nturinski requested a review from a team as a code owner January 27, 2022 19:49
ui/src/wizard/StorageAccountNameStep.ts Outdated Show resolved Hide resolved
ui/src/wizard/ResourceGroupCreateStep.ts Outdated Show resolved Hide resolved
ui/index.d.ts Outdated Show resolved Hide resolved
ui/src/utils/uiUtils.ts Outdated Show resolved Hide resolved
ui/src/wizard/StorageAccountNameStep.ts Outdated Show resolved Hide resolved
@nturinski
Copy link
Member Author

Changed quite a bit so I won't honor these previous approvals 😅

Relies on this PR https://github.com/microsoft/vscode-azure-account/pull/418/files

* @param options - The options used to configure any requests this
* TokenCredential implementation might make.
*/
getToken(scopes?: string | string[], options?: any): Promise<any | null>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this returns Promise<any | null> instead of Promise<TokenResponse | AccessToken | null>? Even though we do the same thing for signRequest above and return Promise<any>

Copy link
Member Author

Choose a reason for hiding this comment

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

It's to keep it more loose so that other versions of credentials could be accepted. For example, BasicAuthenticationCredentials returns WebResourceLike whereas the ServiceClientCredentials returns WebResource. We originally did that for signRequest because different versions of "@azure/ms-rest-js" would change the credential interface. I figured the same could happen with getToken.

Here's an example with the typing screwing up here: Azure/azure-sdk-for-js#10045

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that version of signRequest that returns WebResource is older? It looks like the current version returns WebResourceLike: https://github.com/Azure/ms-rest-js/blob/f6f0d92d79a1dfa8d92ff0891b88bc6b7a349e69/lib/credentials/serviceClientCredentials.ts

Comment on lines 48 to 64

export type CloudShellStatus = 'Connecting' | 'Connected' | 'Disconnected';

export interface UploadOptions {
contentLength?: number;
progress?: Progress<{ message?: string; increment?: number }>;
token?: CancellationToken;
}

export interface CloudShell {
readonly status: CloudShellStatus;
readonly onStatusChanged: Event<CloudShellStatus>;
readonly waitForConnection: () => Promise<boolean>;
readonly terminal: Promise<Terminal>;
readonly session: Promise<AzureSession>;
readonly uploadFile: (filename: string, stream: ReadStream, options?: UploadOptions) => Promise<void>;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I vote we remove these lines (and the CloudShell related line in AzureAccountExtensionApi above) since they aren't used right now in the UI package

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, sure. I just copied the new api from the Azure Account extension because I didn't really want to mess with it 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly, but unless these are reexported from vscode-azureextensionui, I'd just leave them...

ui/index.d.ts Outdated
@@ -1409,7 +1420,8 @@ export interface IMinimumServiceClientOptions {
requestPolicyFactories?: any[] | ((defaultRequestPolicyFactories: any[]) => (void | any[]));
}

export type AzExtGenericClientInfo = AzExtServiceClientCredentials | { credentials: AzExtServiceClientCredentials; environment: Environment; } | undefined;
export type AzExtGenericCredentials = BasicAuthenticationCredentials | TokenCredentials | AzExtServiceClientCredentials;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused why BasicAuthenticationCredentials and TokenCredentials are introduced here. They implement the ServiceClientCredentials interface and that interface just gives us signRequest which is already included in the AzExtServiceClientCredentials type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we have two different createClient helper functions, createGenericClient and createAzureClient.

Originally the azureCredentials were similar enough to basic credential types, but since we're introducing getToken as a requirement to create azure clients to ensure T1&T2 compatability, it would force those requirements on any generic client we create

For example, we used to make a GitHub client with createGenericClient but it wouldn't have required getToken.

I'm not sure if that 100% made sense so feel free to ping me and I can explain it better 😓

ui/index.d.ts Outdated Show resolved Hide resolved
ui/index.d.ts Outdated Show resolved Hide resolved
ui/index.d.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@wwlorey wwlorey left a comment

Choose a reason for hiding this comment

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

giphy

@nturinski nturinski merged commit d3b4e61 into main Feb 4, 2022
@nturinski nturinski deleted the nat/t2packages branch February 4, 2022 22:42
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.

4 participants