Skip to content

Commit

Permalink
perf(auth): add nofitication for addAuthConfig command (#13064)
Browse files Browse the repository at this point in the history
* perf(auth): add nofitication for addAuthConfig command

* fix: fix message and remove useless import

* fix: add localization
  • Loading branch information
KennethBWSong authored Jan 20, 2025
1 parent 8289a05 commit 0ade4f8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/cli/src/commands/models/addAuthConfig.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { commands, strings } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { ProjectFolderOption } from "../common";
import { getFxCore } from "../../activate";
import { AddAuthActionInputs, AddAuthActionOptions } from "@microsoft/teamsfx-core";
import { logger } from "../../commonlib/logger";

export const addAuthConfigCommand: CLICommand = {
name: "auth-config",
Expand All @@ -18,6 +19,7 @@ export const addAuthConfigCommand: CLICommand = {
const inputs = ctx.optionValues as AddAuthActionInputs;
const core = getFxCore();
const res = await core.addAuthAction(inputs);
logger.info(strings.command.add["auth-config"].notification);
return res;
},
};
5 changes: 5 additions & 0 deletions packages/cli/src/resource/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"FoundNotTrust": "Local Certificate is found but not trusted.",
"Success": "Local Certificate is found and is trusted."
}
},
"add":{
"auth-config": {
"notification": "Teams Toolkit has successfully updated your project configuration (teamsapp.yaml) files with added action to support authentication flow. You can proceed to remote provision."
}
}
}
}
4 changes: 2 additions & 2 deletions packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@
"error.kiota.FailedToGenerateAuthActions": "Unable to parse Open API spec and generate Auth actions in teamsapp.yml. Manually update the yml files, if required.",
"core.addAuthActionQuestion.ApiSpecLocation.title": "Select an OpenAPI Description Document",
"core.addAuthActionQuestion.ApiSpecLocation.placeholder": "Select an option",
"core.addAuthActionQuestion.ApiOperation.title": "Select an OpenAPI Description Document",
"core.addAuthActionQuestion.ApiOperation.placeholder": "Select an option",
"core.addAuthActionQuestion.ApiOperation.title": "Select an API to Add Auth Configuration",
"core.addAuthActionQuestion.ApiOperation.placeholder": "Select one or multiple options",
"core.addAuthActionQuestion.authName.title": "Input the Name of Auth Configuration"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface AddAuthActionInputs extends Inputs {
"plugin-manifest-path"?: string;
/** @description Select an OpenAPI Description Document */
"openapi-spec-location"?: string;
/** @description Select an OpenAPI Description Document */
/** @description Select an API to Add Auth Configuration */
"api-operation"?: string[];
/** @description Input the Name of Auth Configuration */
"auth-name"?: string;
Expand Down
4 changes: 3 additions & 1 deletion packages/vscode-extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,5 +599,7 @@
"teamstoolkit.walkthroughs.buildIntelligentApps.intelligentAppResources.description": "Explore these resources to build intelligent apps and enhance your development projects\n🗒️ [Generative AI for Beginners](https://github.com/microsoft/generative-ai-for-beginners/tree/main)\n✨ [Retrieval Augmented Generation (RAG)](https://learn.microsoft.com/en-us/azure/search/retrieval-augmented-generation-overview)\n📚 [AI Learning and Community Hub](https://learn.microsoft.com/en-us/ai/)",
"teamstoolkit.m365.needSignIn.message": "You need to sign in your Microsoft 365 account.",
"teamstoolkit.handler.createPluginWithManifest.error.missingParameter": "Invalid parameter in the createPluginWithManifest command. Usage: createPluginWithManifest(API_SPEC_PATH:string, PLUGIN_MANIFEST_PATH: string, { lastCommand: string }, OUTPUT_FOLDER?: string). Valid values for LAST_COMMAND: createPluginWithManifest, createDeclarativeCopilotWithManifest.",
"teamstoolkit.error.KiotaNotInstalled": "You need to install Microsoft Kiota extension with minimum version %s to use this feature."
"teamstoolkit.error.KiotaNotInstalled": "You need to install Microsoft Kiota extension with minimum version %s to use this feature.",
"teamstoolkit.handeler.addAuthConfig.notification": "Teams Toolkit has successfully updated your project configuration (teamsapp.yaml and teamsapp.local.yaml) files with added action to support authentication flow. You can proceed to remote provision.",
"teamstoolkit.handeler.addAuthConfig.notification.provision": "Provision"
}
14 changes: 13 additions & 1 deletion packages/vscode-extension/src/handlers/lifecycleHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,19 @@ export async function copilotPluginAddAPIHandler(args: any[]) {
export async function addAuthActionHandler(...args: unknown[]) {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.AddAuthActionStart, getTriggerFromProperty(args));
const inputs = getSystemInputs();
return await runCommand(Stage.addAuthAction, inputs);
const result = await runCommand(Stage.addAuthAction, inputs);
void vscode.window
.showInformationMessage(
localize("teamstoolkit.handeler.addAuthConfig.notification"),
localize("teamstoolkit.handeler.addAuthConfig.notification.provision")
)
.then((selection) => {
if (selection === "Provision") {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.ProvisionFromAddAuthConfig);
void runCommand(Stage.provision);
}
});
return result;
}

function handleTriggerKiotaCommand(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export enum TelemetryEvent {

AddAuthActionStart = "add-auth-action-start",
AddAuthAction = "add-auth-action",
ProvisionFromAddAuthConfig = "provision-from-add-auth-config",
}

export enum TelemetryProperty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,16 @@ describe("Lifecycle handlers", () => {

it("happy path", async () => {
sandbox.stub(globalVariables, "core").value(new MockCore());
const addPluginHanlder = sandbox.spy(globalVariables.core, "addAuthAction");

const showMessageStub = sandbox
.stub(vscode.window, "showInformationMessage")
.callsFake((title: string, ...items: any[]) => {
return Promise.resolve(items[0]);
});
const addAuthAction = sandbox.spy(globalVariables.core, "addAuthAction");
const provisionction = sandbox.spy(globalVariables.core, "provisionResources");
await addAuthActionHandler();

sinon.assert.calledOnce(addPluginHanlder);
sandbox.assert.calledOnce(addAuthAction);
sandbox.assert.calledOnce(provisionction);
});
});
});

0 comments on commit 0ade4f8

Please sign in to comment.