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

fix(vsc): format vscode #1057

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/vscode-extension/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
extends: ["@shared/eslint-config"]
extends: ["@shared/eslint-config"],
};
2 changes: 1 addition & 1 deletion packages/vscode-extension/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
...require("@shared/prettier-config"),
endOfLine: "crlf"
endOfLine: "crlf",
};
18 changes: 14 additions & 4 deletions packages/vscode-extension/src/commonlib/appStudioCodeSpaceLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class AppStudioCodeSpaceLogin extends login implements AppStudioTokenProv
}

async setStatusChangeCallback(
statusChange: (status: string, token?: string, accountInfo?: Record<string, unknown>) => Promise<void>
statusChange: (
status: string,
token?: string,
accountInfo?: Record<string, unknown>
) => Promise<void>
): Promise<boolean> {
AppStudioCodeSpaceLogin.statusChange = statusChange;
const session = await this.tryAuthenticate(false);
Expand All @@ -82,13 +86,15 @@ export class AppStudioCodeSpaceLogin extends login implements AppStudioTokenProv
const tokenJson = this.parseToken(session.accessToken);
await AppStudioCodeSpaceLogin.statusChange("SignedIn", session.accessToken, tokenJson);
}

return new Promise((resolve) => {
resolve(true);
});
}

private async tryAuthenticate(createIfNone: boolean): Promise<vscode.AuthenticationSession | undefined> {
private async tryAuthenticate(
createIfNone: boolean
): Promise<vscode.AuthenticationSession | undefined> {
return vscode.authentication
.getSession("microsoft", scopes, { createIfNone: createIfNone })
.then((session: vscode.AuthenticationSession | undefined) => {
Expand All @@ -110,7 +116,11 @@ export class AppStudioCodeSpaceLogin extends login implements AppStudioTokenProv
const session = await this.tryAuthenticate(false);
if (session && session.accessToken) {
const tokenJson = await this.getJsonObject();
return Promise.resolve({ status: signedIn, token: session.accessToken, accountInfo: tokenJson });
return Promise.resolve({
status: signedIn,
token: session.accessToken,
accountInfo: tokenJson,
});
} else {
return Promise.resolve({ status: signedOut, token: undefined, accountInfo: undefined });
}
Expand Down
36 changes: 25 additions & 11 deletions packages/vscode-extension/src/commonlib/appStudioLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const afterCacheAccess = getAfterCacheAccess(scopes, accountName);

const cachePlugin = {
beforeCacheAccess,
afterCacheAccess
afterCacheAccess,
};

const config = {
auth: {
clientId: "7ea7c24c-b1f6-4a20-9d11-9ae12e9e7ac0",
authority: "https://login.microsoftonline.com/common"
authority: "https://login.microsoftonline.com/common",
},
system: {
loggerOptions: {
Expand All @@ -41,12 +41,12 @@ const config = {
VsCodeLogInstance.info(message);
},
piiLoggingEnabled: false,
logLevel: LogLevel.Error
}
logLevel: LogLevel.Error,
},
},
cache: {
cachePlugin
}
cachePlugin,
},
};

export class AppStudioLogin extends login implements AppStudioTokenProvider {
Expand Down Expand Up @@ -85,7 +85,11 @@ export class AppStudioLogin extends login implements AppStudioTokenProvider {
const userConfirmation: boolean = await this.doesUserConfirmLogin();
if (!userConfirmation) {
// throw user cancel error
throw new UserError(ExtensionErrors.UserCancel, StringResources.vsc.common.userCancel, "Login");
throw new UserError(
ExtensionErrors.UserCancel,
StringResources.vsc.common.userCancel,
"Login"
);
}
AppStudioLogin.codeFlowInstance.status = loggingIn;
this.notifyStatus();
Expand Down Expand Up @@ -125,7 +129,11 @@ export class AppStudioLogin extends login implements AppStudioTokenProvider {
async signout(): Promise<boolean> {
const userConfirmation = await this.doesUserConfirmSignout();
if (!userConfirmation) {
throw new UserError(ExtensionErrors.UserCancel, StringResources.vsc.common.userCancel, "SignOut");
throw new UserError(
ExtensionErrors.UserCancel,
StringResources.vsc.common.userCancel,
"SignOut"
);
}
await AppStudioLogin.codeFlowInstance.logout();
if (AppStudioLogin.statusChange !== undefined) {
Expand All @@ -145,12 +153,14 @@ export class AppStudioLogin extends login implements AppStudioTokenProvider {
do {
userSelected = await vscode.window.showInformationMessage(
message,
{modal: true},
{ modal: true },
signin,
readMore
);
if (userSelected === readMore) {
vscode.env.openExternal(vscode.Uri.parse("https://developer.microsoft.com/en-us/microsoft-365/dev-program"));
vscode.env.openExternal(
vscode.Uri.parse("https://developer.microsoft.com/en-us/microsoft-365/dev-program")
);
}
} while (userSelected === readMore);
return Promise.resolve(userSelected === signin);
Expand All @@ -169,7 +179,11 @@ export class AppStudioLogin extends login implements AppStudioTokenProvider {
}

async setStatusChangeCallback(
statusChange: (status: string, token?: string, accountInfo?: Record<string, unknown>) => Promise<void>
statusChange: (
status: string,
token?: string,
accountInfo?: Record<string, unknown>
) => Promise<void>
): Promise<boolean> {
AppStudioLogin.statusChange = statusChange;
await AppStudioLogin.codeFlowInstance.reloadCache();
Expand Down
76 changes: 44 additions & 32 deletions packages/vscode-extension/src/commonlib/azureLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
if (!AzureAccountManager.instance) {
AzureAccountManager.instance = new AzureAccountManager();
}

return AzureAccountManager.instance;
}

Expand All @@ -52,9 +52,8 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
* @returns the instance of TokenCredentialsBase
*/
getAccountCredential(showDialog = true): TokenCredentialsBase | undefined {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
if (azureAccount.status === "LoggedIn") {
if (azureAccount.subscriptions.length > 0) {
if (AzureAccountManager.tenantId) {
Expand Down Expand Up @@ -117,9 +116,8 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
}

private isUserLogin(): boolean {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
return azureAccount.status === "LoggedIn";
}

Expand All @@ -128,17 +126,20 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
const userConfirmation: boolean = await this.doesUserConfirmLogin();
if (!userConfirmation) {
// throw user cancel error
throw new UserError(ExtensionErrors.UserCancel, StringResources.vsc.common.userCancel, "Login");
throw new UserError(
ExtensionErrors.UserCancel,
StringResources.vsc.common.userCancel,
"Login"
);
}
}
await vscode.commands.executeCommand("azure-account.login");
}

private doGetAccountCredentialAsync(): Promise<TokenCredentialsBase | undefined> {
if (this.isUserLogin()) {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
// Choose one tenant credential when users have multi tenants. (TODO, need to optize after UX design)
// 1. When azure-account-extension has at least one subscription, return the first one credential.
// 2. When azure-account-extension has no subscription and has at at least one session, return the first session credential.
Expand Down Expand Up @@ -188,12 +189,16 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
do {
userSelected = await vscode.window.showInformationMessage(
message,
{modal: true},
{ modal: true },
signin,
readMore
);
if (userSelected === readMore) {
vscode.env.openExternal(vscode.Uri.parse("https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/create-subscription"));
vscode.env.openExternal(
vscode.Uri.parse(
"https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/create-subscription"
)
);
}
} while (userSelected === readMore);

Expand Down Expand Up @@ -236,7 +241,11 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
const userConfirmation: boolean = await this.doesUserConfirmSignout();
if (!userConfirmation) {
// throw user cancel error
throw new UserError(ExtensionErrors.UserCancel, StringResources.vsc.common.userCancel, "SignOut");
throw new UserError(
ExtensionErrors.UserCancel,
StringResources.vsc.common.userCancel,
"SignOut"
);
}
await vscode.commands.executeCommand("azure-account.logout");
AzureAccountManager.tenantId = undefined;
Expand Down Expand Up @@ -267,9 +276,8 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
*/
async listSubscriptions(): Promise<SubscriptionInfo[]> {
await this.getAccountCredentialAsync();
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
const arr: SubscriptionInfo[] = [];
if (azureAccount.status === "LoggedIn") {
if (azureAccount.subscriptions.length > 0) {
Expand All @@ -278,7 +286,7 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
arr.push({
subscriptionId: item.subscription.subscriptionId!,
subscriptionName: item.subscription.displayName!,
tenantId: item.session.tenantId!
tenantId: item.session.tenantId!,
});
}
}
Expand All @@ -291,9 +299,8 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
*/
async setSubscription(subscriptionId: string): Promise<void> {
if (this.isUserLogin()) {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
for (let i = 0; i < azureAccount.subscriptions.length; ++i) {
const item = azureAccount.subscriptions[i];
if (item.subscription.subscriptionId == subscriptionId) {
Expand All @@ -303,13 +310,16 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
}
}
}
throw new UserError(ExtensionErrors.UnknownSubscription, StringResources.vsc.azureLogin.unknownSubscription, "Login");
throw new UserError(
ExtensionErrors.UnknownSubscription,
StringResources.vsc.azureLogin.unknownSubscription,
"Login"
);
}

getAzureAccount(): AzureAccount {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
return azureAccount;
}

Expand All @@ -319,19 +329,21 @@ export class AzureAccountManager extends login implements AzureAccountProvider {
const credential = await this.doGetAccountCredentialAsync();
const token = await credential?.getToken();
const accountJson = await this.getJsonObject();
return Promise.resolve({ status: signedIn, token: token?.accessToken, accountInfo: accountJson });
return Promise.resolve({
status: signedIn,
token: token?.accessToken,
accountInfo: accountJson,
});
} else if (azureAccount.status === loggingIn) {
return Promise.resolve({ status: signingIn, token: undefined, accountInfo: undefined});
}
else {
return Promise.resolve({ status: signingIn, token: undefined, accountInfo: undefined });
} else {
return Promise.resolve({ status: signedOut, token: undefined, accountInfo: undefined });
}
}

async addStatusChangeEvent() {
const azureAccount: AzureAccount = vscode.extensions.getExtension<AzureAccount>(
"ms-vscode.azure-account"
)!.exports;
const azureAccount: AzureAccount =
vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
azureAccount.onStatusChanged(async (event) => {
if (event === loggedOut) {
if (AzureAccountManager.statusChange !== undefined) {
Expand Down
4 changes: 3 additions & 1 deletion packages/vscode-extension/src/commonlib/cacheAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export function getAfterCacheAccess(scopes: string[], accountName: string) {
if (key.indexOf(scopes[0].toLowerCase()) != -1) {
fs.writeFile(accountPath + accountName, data.AccessToken[key][homeAccountId], (err) => {
if (err) {
VsCodeLogInstance.error(StringResources.vsc.cacheAccess.saveHomeAccountIdFail + err.message);
VsCodeLogInstance.error(
StringResources.vsc.cacheAccess.saveHomeAccountIdFail + err.message
);
}
});
}
Expand Down
Loading