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

feat: cli uninstall #11917

Merged
merged 36 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
656cfc5
feat: cli uninstall
anchenyi Jun 27, 2024
416f78a
fix: remove unused import
anchenyi Jun 27, 2024
4358b1c
feat: update
anchenyi Jun 27, 2024
5be046c
feat: update
anchenyi Jun 27, 2024
eeef614
refactor: naming
anchenyi Jun 27, 2024
7e2c9fd
refactor: naming
anchenyi Jun 27, 2024
43f5e8f
fix: naming
anchenyi Jun 27, 2024
9f955bf
fix: ut
anchenyi Jun 28, 2024
e38c8c2
feat: add ut
anchenyi Jun 28, 2024
d5c8b0b
feat: update
anchenyi Jun 28, 2024
c1053cf
fix: ut
anchenyi Jun 28, 2024
0d18a62
fix: ut
anchenyi Jun 28, 2024
4549f1e
fix: ut
anchenyi Jun 28, 2024
3cf6c8b
fix: naming
anchenyi Jun 28, 2024
1e03886
fix: ut
anchenyi Jun 28, 2024
d258b77
fix: naming
anchenyi Jun 28, 2024
57858ee
fix: ut
anchenyi Jun 28, 2024
68dcf75
fix: envVars
anchenyi Jul 1, 2024
3333b4a
fix: ut
anchenyi Jul 1, 2024
bf57126
Merge branch 'dev' into anchenyi/feat_cli_uninstall
anchenyi Jul 1, 2024
7761707
style: comments
anchenyi Jul 1, 2024
63cafce
fix: comments
anchenyi Jul 1, 2024
41b3bae
fix: comments
anchenyi Jul 3, 2024
88ce8ad
fix: comments
anchenyi Jul 8, 2024
b977856
fix: comments
anchenyi Jul 8, 2024
0dca1a6
fix: comments
anchenyi Jul 8, 2024
5705b1c
fix: comments
anchenyi Jul 8, 2024
7f800e5
Merge branch 'dev' into anchenyi/feat_cli_uninstall
anchenyi Jul 8, 2024
daea514
fix: comments
anchenyi Jul 8, 2024
bbbb693
fix: user cancel and comments
anchenyi Jul 8, 2024
0c3f930
Merge branch 'dev' into anchenyi/feat_cli_uninstall
anchenyi Jul 8, 2024
22b9836
fix: example
anchenyi Jul 8, 2024
291674e
fix: description
anchenyi Jul 8, 2024
674e521
fix: comments
anchenyi Jul 8, 2024
0a1ca57
fix: comments
anchenyi Jul 8, 2024
9b36f36
fix: comments
anchenyi Jul 8, 2024
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
19 changes: 19 additions & 0 deletions packages/cli/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
"${workspaceFolder}/../api/build/**/*.js"
],
"console": "integratedTerminal"
},
{
"type": "pwa-node",
"request": "launch",
"name": "Launch uninstall command",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/cli.js",
"args": ["uninstall"],
"outFiles": [
"${workspaceFolder}/lib/**/*.js",
"${workspaceFolder}/../fx-core/build/**/*.js",
"${workspaceFolder}/../api/build/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/lib/**/*.js",
"${workspaceFolder}/../fx-core/build/**/*.js",
"${workspaceFolder}/../api/build/**/*.js"
],
"console": "integratedTerminal"
}
]
}
35 changes: 19 additions & 16 deletions packages/cli/src/commands/models/m365Unacquire.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand, err, ok } from "@microsoft/teamsfx-api";
import { PackageService } from "@microsoft/teamsfx-core";
import { CLICommand, Platform, err, ok } from "@microsoft/teamsfx-api";
Fixed Show fixed Hide fixed
import { PackageService, UninstallInputs } from "@microsoft/teamsfx-core";
Fixed Show fixed Hide fixed
import { logger } from "../../commonlib/logger";
import { MissingRequiredOptionError } from "../../error";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { m365utils, sideloadingServiceEndpoint } from "./m365Sideloading";
import { getFxCore } from "../../activate";

export const m365UnacquireCommand: CLICommand = {
name: "uninstall",
Expand All @@ -23,35 +24,37 @@
description: commands.uninstall.options["manifest-id"],
type: "string",
},
{
name: "env",
description: commands.uninstall.options["env"],
type: "string",
},
],
examples: [
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --title-id U_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
description: "Remove the acquired M365 App by Title ID",
},
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -i false --m365-app --app-refistration --bot-framework-registration`,
description: "Remove the acquired M365 App by Manifest ID",
},
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --env xxx -i false --m365-app --app-refistration --bot-framework-registration`,
description: "Remove the acquired M365 App by local env",
},
],
telemetry: {
event: TelemetryEvent.M365Unacquire,
},
defaultInteractiveOption: false,
defaultInteractiveOption: true,
handler: async (ctx) => {
const packageService = new PackageService(sideloadingServiceEndpoint, logger);
let titleId = ctx.optionValues["title-id"] as string;
const manifestId = ctx.optionValues["manifest-id"] as string;
if (titleId === undefined && manifestId === undefined) {
return err(
new MissingRequiredOptionError(ctx.command.fullName, `--title-id or --manifest-id`)
);
}
const tokenAndUpn = await m365utils.getTokenAndUpn();
if (titleId === undefined) {
titleId = await packageService.retrieveTitleId(tokenAndUpn[0], manifestId);
const inputs = ctx.optionValues as UninstallInputs;
const core = getFxCore();
const res = await core.uninstall(inputs);
if (res.isErr()) {
return err(res.error);
}
await packageService.unacquire(tokenAndUpn[0], titleId);
return ok(undefined);
},
};
3 changes: 2 additions & 1 deletion packages/cli/src/resource/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@
"description": "Remove an acquired M365 App.",
"options": {
"title-id": "Title ID of the acquired M365 App.",
"manifest-id": "Manifest ID of the acquired M365 App."
"manifest-id": "Manifest ID of the acquired M365 App.",
"env": "Env of the acquired M365 App."
}
},
"update": {
Expand Down
24 changes: 24 additions & 0 deletions packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,30 @@
"core.copilot.addAPI.success": "%s have(has) been successfully added to %s",
"core.copilot.addAPI.InjectAPIKeyActionFailed": "Inject API key action to teamsapp.yaml file unsuccessful, make sure the file contains teamsApp/create action in provision section.",
"core.copilot.addAPI.InjectOAuthActionFailed": "Inject OAuth action to teamsapp.yaml file unsuccessful, make sure the file contains teamsApp/create action in provision section.",
"core.uninstall.botNotFound": "Cannot find bot using the manifest ID %s",
"core.uninstall.confirm.tdp": "App registration of manifest ID: %s will be uninstalled. Please confirm.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.confirm.m365App": "M365 App of Title ID: %s will be uninstalled. Please confirm.",
"core.uninstall.confirm.bot": "Bot framework registration of bot ID: %s will be uninstalled. Please confirm.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.confirm.cancel.tdp": "App registration uninstallation cancelled.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.confirm.cancel.m365App": "M365 App uninstallation cancelled.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.confirm.cancel.bot": "Bot framework registration uninstallation cancelled.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.success.tdp": "App registration of manifest ID: %s has been successfully uninstalled.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.success.m365App": "M365 App of Title ID: %s has been successfully uninstalled.",
"core.uninstall.success.delayWarning": "The uninstallation of the M365 app might have some delay.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.success.bot": "Bot framework registration of bot ID: %s has been successfully uninstalled.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstall.failed.titleId": "Failed to find the Title ID. This app is probably not installed.",
anchenyi marked this conversation as resolved.
Show resolved Hide resolved
"core.uninstallQuestion.manifestId": "Manifest ID",
"core.uninstallQuestion.env": "Env",
"core.uninstallQuestion.titleId": "Title ID",
"core.uninstallQuestion.chooseMode": "Choose uninstall mode",
"core.uninstallQuestion.manifestIdMode": "By Manfest ID",
"core.uninstallQuestion.envMode": "By Env",
"core.uninstallQuestion.titleIdMode": "By Title ID",
"core.uninstallQuestion.chooseOption": "Choose resources to uninstall",
"core.uninstallQuestion.m365Option": "M365 app",
"core.uninstallQuestion.tdpOption": "App registration",
"core.uninstallQuestion.botOption": "Bot framework registration",
"core.uninstallQuestion.projectPath": "Project path",
"ui.select.LoadingOptionsPlaceholder": "Loading options ...",
"ui.select.LoadingDefaultPlaceholder": "Loading default value ...",
"error.aad.manifest.NameIsMissing": "name is missing\n",
Expand Down
10 changes: 9 additions & 1 deletion packages/fx-core/src/client/teamsDevPortalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,15 @@ export class TeamsDevPortalClient {
}
throw new Error(`Cannot get the app definition with app ID ${teamsAppId}`);
}

@hooks([ErrorContextMW({ source: "Teams", component: "TeamsDevPortalClient" })])
async getBotId(token: string, teamsAppId: string): Promise<string | undefined> {
const app = await this.getApp(token, teamsAppId);
if (app?.bots?.length && app.bots.length > 0) {
return app.bots[0].botId;
}
TOOLS.logProvider?.error(`botId not found. Input: ${teamsAppId}`);
return undefined;
}
@hooks([ErrorContextMW({ source: "Teams", component: "TeamsDevPortalClient" })])
async getAppPackage(token: string, teamsAppId: string): Promise<any> {
TOOLS.logProvider?.info("Downloading app package for app " + teamsAppId);
Expand Down
Loading
Loading