Skip to content

Commit

Permalink
perf: add confirm ui for api key (#10408)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethBWSong authored Nov 24, 2023
1 parent 5f6831f commit 4a50152
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/fx-core/resource/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@
"core.createProjectQuestion.apiSpecInputUrl.label": "Enter OpenAPI Description Document Location",
"core.createProjectQuestion.OpenAIPluginDomain": "OpenAI Plugin Manifest",
"core.createProjectQuestion.OpenAIPluginDomain.placeholder": "Enter your website domain or manifest URL",
"core.createaProjectQuestion.ApiKey": "Client secret for API key in OpenAPI specification",
"core.createProjectQuestion.ApiKey": "Enter API Key in OpenAPI Description Document",
"core.createProjectQuestion.ApiKeyConfirm": "Teams Toolkit will upload the API key to Teams Developer Portal. The API key will be used by Teams client to securely access your API in runtime when API-Based Message Extension is triggered. Teams Toolkit will not store your API key.",
"core.createProjectQuestion.invalidApiKey.message": "Client secret is invalid. The length of secret should be >= 10 and <= 128",
"core.createProjectQuestion.invalidUrl.message": "Enter a valid HTTP URL without authentication to access your OpenAPI description document.",
"core.createProjectQuestion.apiSpec.operation.title": "Select Operation(s) Teams Can Interact with",
Expand Down
2 changes: 2 additions & 0 deletions packages/fx-core/src/component/driver/apiKey/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { SpecParser } from "../../../common/spec-parser";
import { getAbsolutePath } from "../../utils/common";
import { ApiKeyFailedToGetDomainError } from "./error/apiKeyFailedToGetDomain";
import { isApiKeyEnabled, isMultipleParametersEnabled } from "../../../common/featureFlags";
import { TelemetryUtils } from "../teamsApp/utils/telemetry";

const actionName = "apiKey/register"; // DO NOT MODIFY the name
const helpLink = "https://aka.ms/teamsfx-actions/apiKey-register";
Expand All @@ -51,6 +52,7 @@ export class CreateApiKeyDriver implements StepDriver {

try {
context.logProvider?.info(getLocalizedString(logMessageKeys.startExecuteDriver, actionName));
TelemetryUtils.init(context);

if (!outputEnvVarNames) {
throw new OutputEnvironmentVariableUndefinedError(actionName);
Expand Down
17 changes: 16 additions & 1 deletion packages/fx-core/src/question/other.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AppPackageFolderName,
AzureAccountProvider,
BuildFolderName,
ConfirmQuestion,
DynamicPlatforms,
IQTreeNode,
Inputs,
Expand Down Expand Up @@ -918,13 +919,22 @@ export function resourceGroupQuestionNode(
};
}

export function apiSpecApiKeyConfirmQestion(): ConfirmQuestion {
return {
name: QuestionNames.ApiSpecApiKeyConfirm,
title: getLocalizedString("core.createProjectQuestion.ApiKeyConfirm"),
type: "confirm",
default: true,
};
}

export function apiSpecApiKeyQuestion(): IQTreeNode {
return {
data: {
type: "text",
name: QuestionNames.ApiSpecApiKey,
cliShortName: "k",
title: getLocalizedString("core.createaProjectQuestion.ApiKey"),
title: getLocalizedString("core.createProjectQuestion.ApiKey"),
cliDescription: "Api key for OpenAPI spec.",
forgetLastValue: true,
validation: {
Expand Down Expand Up @@ -956,5 +966,10 @@ export function apiSpecApiKeyQuestion(): IQTreeNode {
!inputs.clientSecret
);
},
children: [
{
data: apiSpecApiKeyConfirmQestion(),
},
],
};
}
1 change: 1 addition & 0 deletions packages/fx-core/src/question/questionNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum QuestionNames {
ApiOperation = "api-operation",
MeArchitectureType = "me-architecture",
ApiSpecApiKey = "api-key",
ApiSpecApiKeyConfirm = "api-key-confirm",

Features = "features",
Env = "env",
Expand Down
4 changes: 3 additions & 1 deletion packages/fx-core/tests/question/question.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ describe("selectAadManifestQuestion", async () => {
});
});

describe("resourceGroupQuestionNode", async () => {
describe("apiKeyQuestion", async () => {
const sandbox = sinon.createSandbox();
let mockedEnvRestore: RestoreFn = () => {};
afterEach(() => {
Expand All @@ -972,6 +972,8 @@ describe("resourceGroupQuestionNode", async () => {
const condition = question.condition;
const res = await (condition as ConditionFunc)(inputs);
assert.equal(res, true);
const confirmQuesion = question.children![0];
assert.equal(confirmQuesion.data.name, "api-key-confirm");
});

it("will not pop up question due to api key exists", async () => {
Expand Down

0 comments on commit 4a50152

Please sign in to comment.