@microsoft/teamsfx-core 1.0.0 → 1.0.1-alpha.fa070464.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/common/armInterface.d.ts +1 -0
- package/build/common/armInterface.d.ts.map +1 -1
- package/build/core/error.d.ts +1 -0
- package/build/core/error.d.ts.map +1 -1
- package/build/core/error.js +5 -1
- package/build/core/error.js.map +1 -1
- package/build/core/index.d.ts.map +1 -1
- package/build/core/index.js +41 -4
- package/build/core/index.js.map +1 -1
- package/build/core/middleware/envInfoWriter.d.ts.map +1 -1
- package/build/core/middleware/envInfoWriter.js +2 -0
- package/build/core/middleware/envInfoWriter.js.map +1 -1
- package/build/plugins/resource/aad/v2/index.d.ts +3 -0
- package/build/plugins/resource/aad/v2/index.d.ts.map +1 -1
- package/build/plugins/resource/aad/v2/index.js +9 -0
- package/build/plugins/resource/aad/v2/index.js.map +1 -1
- package/build/plugins/resource/appstudio/index.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/index.js +15 -5
- package/build/plugins/resource/appstudio/index.js.map +1 -1
- package/build/plugins/resource/appstudio/interfaces/IAppDefinition.d.ts +6 -2
- package/build/plugins/resource/appstudio/interfaces/IAppDefinition.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/plugin.d.ts +1 -1
- package/build/plugins/resource/appstudio/plugin.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/plugin.js +123 -36
- package/build/plugins/resource/appstudio/plugin.js.map +1 -1
- package/build/plugins/resource/appstudio/utils/telemetry.d.ts +1 -0
- package/build/plugins/resource/appstudio/utils/telemetry.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/utils/telemetry.js +1 -0
- package/build/plugins/resource/appstudio/utils/telemetry.js.map +1 -1
- package/build/plugins/resource/appstudio/v2/index.d.ts +3 -0
- package/build/plugins/resource/appstudio/v2/index.d.ts.map +1 -1
- package/build/plugins/resource/appstudio/v2/index.js +9 -0
- package/build/plugins/resource/appstudio/v2/index.js.map +1 -1
- package/build/plugins/resource/index.d.ts +1 -0
- package/build/plugins/resource/index.d.ts.map +1 -1
- package/build/plugins/resource/index.js +1 -0
- package/build/plugins/resource/index.js.map +1 -1
- package/build/plugins/resource/keyvault/constants.d.ts +35 -0
- package/build/plugins/resource/keyvault/constants.d.ts.map +1 -0
- package/build/plugins/resource/keyvault/constants.js +42 -0
- package/build/plugins/resource/keyvault/constants.js.map +1 -0
- package/build/plugins/resource/keyvault/index.d.ts +14 -0
- package/build/plugins/resource/keyvault/index.d.ts.map +1 -0
- package/build/plugins/resource/keyvault/index.js +60 -0
- package/build/plugins/resource/keyvault/index.js.map +1 -0
- package/build/plugins/resource/keyvault/plugin.d.ts +6 -0
- package/build/plugins/resource/keyvault/plugin.d.ts.map +1 -0
- package/build/plugins/resource/keyvault/plugin.js +31 -0
- package/build/plugins/resource/keyvault/plugin.js.map +1 -0
- package/build/plugins/resource/keyvault/result.d.ts +9 -0
- package/build/plugins/resource/keyvault/result.d.ts.map +1 -0
- package/build/plugins/resource/keyvault/result.js +21 -0
- package/build/plugins/resource/keyvault/result.js.map +1 -0
- package/build/plugins/resource/keyvault/utils/telemetry.d.ts +17 -0
- package/build/plugins/resource/keyvault/utils/telemetry.d.ts.map +1 -0
- package/build/plugins/resource/keyvault/utils/telemetry.js +45 -0
- package/build/plugins/resource/keyvault/utils/telemetry.js.map +1 -0
- package/build/plugins/resource/simpleauth/v2/index.d.ts +7 -6
- package/build/plugins/resource/simpleauth/v2/index.d.ts.map +1 -1
- package/build/plugins/resource/simpleauth/v2/index.js +12 -6
- package/build/plugins/resource/simpleauth/v2/index.js.map +1 -1
- package/build/plugins/resource/utils4v2.d.ts +2 -1
- package/build/plugins/resource/utils4v2.d.ts.map +1 -1
- package/build/plugins/resource/utils4v2.js +26 -1
- package/build/plugins/resource/utils4v2.js.map +1 -1
- package/build/plugins/solution/fx-solution/ResourcePluginContainer.d.ts +1 -0
- package/build/plugins/solution/fx-solution/ResourcePluginContainer.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/ResourcePluginContainer.js +1 -0
- package/build/plugins/solution/fx-solution/ResourcePluginContainer.js.map +1 -1
- package/build/plugins/solution/fx-solution/arm.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/arm.js +41 -22
- package/build/plugins/solution/fx-solution/arm.js.map +1 -1
- package/build/plugins/solution/fx-solution/commonQuestions.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/commonQuestions.js.map +1 -1
- package/build/plugins/solution/fx-solution/constants.d.ts +1 -1
- package/build/plugins/solution/fx-solution/constants.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/constants.js +2 -2
- package/build/plugins/solution/fx-solution/constants.js.map +1 -1
- package/build/plugins/solution/fx-solution/question.d.ts +2 -1
- package/build/plugins/solution/fx-solution/question.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/question.js +10 -3
- package/build/plugins/solution/fx-solution/question.js.map +1 -1
- package/build/plugins/solution/fx-solution/solution.d.ts +1 -3
- package/build/plugins/solution/fx-solution/solution.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/solution.js +33 -544
- package/build/plugins/solution/fx-solution/solution.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/adaptor.d.ts +3 -0
- package/build/plugins/solution/fx-solution/v2/adaptor.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/adaptor.js +45 -7
- package/build/plugins/solution/fx-solution/v2/adaptor.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/checkPermission.d.ts +5 -0
- package/build/plugins/solution/fx-solution/v2/checkPermission.d.ts.map +1 -0
- package/build/plugins/solution/fx-solution/v2/checkPermission.js +185 -0
- package/build/plugins/solution/fx-solution/v2/checkPermission.js.map +1 -0
- package/build/plugins/solution/fx-solution/v2/collaborationUtil.d.ts +20 -0
- package/build/plugins/solution/fx-solution/v2/collaborationUtil.d.ts.map +1 -0
- package/build/plugins/solution/fx-solution/v2/collaborationUtil.js +83 -0
- package/build/plugins/solution/fx-solution/v2/collaborationUtil.js.map +1 -0
- package/build/plugins/solution/fx-solution/v2/executor.d.ts +1 -0
- package/build/plugins/solution/fx-solution/v2/executor.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/executor.js +17 -1
- package/build/plugins/solution/fx-solution/v2/executor.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/getQuestions.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/getQuestions.js +2 -1
- package/build/plugins/solution/fx-solution/v2/getQuestions.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/grantPermission.d.ts +5 -0
- package/build/plugins/solution/fx-solution/v2/grantPermission.d.ts.map +1 -0
- package/build/plugins/solution/fx-solution/v2/grantPermission.js +200 -0
- package/build/plugins/solution/fx-solution/v2/grantPermission.js.map +1 -0
- package/build/plugins/solution/fx-solution/v2/listAllCollaborators.d.ts +5 -0
- package/build/plugins/solution/fx-solution/v2/listAllCollaborators.d.ts.map +1 -0
- package/build/plugins/solution/fx-solution/v2/listAllCollaborators.js +118 -0
- package/build/plugins/solution/fx-solution/v2/listAllCollaborators.js.map +1 -0
- package/build/plugins/solution/fx-solution/v2/listCollaborator.d.ts +8 -0
- package/build/plugins/solution/fx-solution/v2/listCollaborator.d.ts.map +1 -0
- package/build/plugins/solution/fx-solution/v2/listCollaborator.js +195 -0
- package/build/plugins/solution/fx-solution/v2/listCollaborator.js.map +1 -0
- package/build/plugins/solution/fx-solution/v2/provision.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/provision.js +23 -6
- package/build/plugins/solution/fx-solution/v2/provision.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/solution.d.ts +4 -0
- package/build/plugins/solution/fx-solution/v2/solution.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/solution.js +8 -0
- package/build/plugins/solution/fx-solution/v2/solution.js.map +1 -1
- package/build/plugins/solution/fx-solution/v2/utils.d.ts +3 -1
- package/build/plugins/solution/fx-solution/v2/utils.d.ts.map +1 -1
- package/build/plugins/solution/fx-solution/v2/utils.js +6 -1
- package/build/plugins/solution/fx-solution/v2/utils.js.map +1 -1
- package/package.json +4 -3
- package/resource/strings.json +1 -0
- package/templates/plugins/resource/bot/bicep/botConfiguration.template.bicep +10 -0
- package/templates/plugins/resource/function/bicep/functionConfiguration.template.bicep +5 -0
- package/templates/plugins/resource/keyvault/bicep/keyVaultProvision.template.bicep +53 -0
- package/templates/plugins/resource/keyvault/bicep/provision.template.bicep +13 -0
- package/templates/plugins/resource/simpleauth/bicep/simpleAuthConfiguration.template.bicep +5 -0
|
@@ -10,7 +10,6 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
// Licensed under the MIT license.
|
|
11
11
|
const lib_1 = require("@feathersjs/hooks/lib");
|
|
12
12
|
const teamsfx_api_1 = require("@microsoft/teamsfx-api");
|
|
13
|
-
const axios_1 = tslib_1.__importDefault(require("axios"));
|
|
14
13
|
const fs = tslib_1.__importStar(require("fs-extra"));
|
|
15
14
|
const mustache_1 = tslib_1.__importDefault(require("mustache"));
|
|
16
15
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -18,7 +17,6 @@ const typedi_1 = require("typedi");
|
|
|
18
17
|
const util = tslib_1.__importStar(require("util"));
|
|
19
18
|
const constants_1 = require("../../../common/constants");
|
|
20
19
|
const localSettingsConstants_1 = require("../../../common/localSettingsConstants");
|
|
21
|
-
const permissionInterface_1 = require("../../../common/permissionInterface");
|
|
22
20
|
const tools_1 = require("../../../common/tools");
|
|
23
21
|
const core_1 = require("../../../core");
|
|
24
22
|
const errorHandler_1 = require("../../../core/middleware/errorHandler");
|
|
@@ -35,8 +33,11 @@ const util_1 = require("./utils/util");
|
|
|
35
33
|
const executeUserTask_1 = require("./v2/executeUserTask");
|
|
36
34
|
const utils_1 = require("./v2/utils");
|
|
37
35
|
const provision_1 = require("./v2/provision");
|
|
36
|
+
const grantPermission_1 = require("./v2/grantPermission");
|
|
37
|
+
const checkPermission_1 = require("./v2/checkPermission");
|
|
38
|
+
const listAllCollaborators_1 = require("./v2/listAllCollaborators");
|
|
39
|
+
const listCollaborator_1 = require("./v2/listCollaborator");
|
|
38
40
|
const scaffolding_1 = require("./v2/scaffolding");
|
|
39
|
-
const __1 = require("../../..");
|
|
40
41
|
const telemetry_1 = require("../../../common/telemetry");
|
|
41
42
|
const _1 = require(".");
|
|
42
43
|
const constants_3 = require("../../../common/constants");
|
|
@@ -59,6 +60,7 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
59
60
|
this.FunctionPlugin = typedi_1.Container.get(ResourcePluginContainer_1.ResourcePlugins.FunctionPlugin);
|
|
60
61
|
this.SqlPlugin = typedi_1.Container.get(ResourcePluginContainer_1.ResourcePlugins.SqlPlugin);
|
|
61
62
|
this.ApimPlugin = typedi_1.Container.get(ResourcePluginContainer_1.ResourcePlugins.ApimPlugin);
|
|
63
|
+
this.KeyVaultPlugin = typedi_1.Container.get(ResourcePluginContainer_1.ResourcePlugins.KeyVaultPlugin);
|
|
62
64
|
this.LocalDebugPlugin = typedi_1.Container.get(ResourcePluginContainer_1.ResourcePlugins.LocalDebugPlugin);
|
|
63
65
|
this.runningState = SolutionRunningState.Idle;
|
|
64
66
|
}
|
|
@@ -298,7 +300,7 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
298
300
|
*
|
|
299
301
|
*/
|
|
300
302
|
async provision(ctx) {
|
|
301
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
303
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
302
304
|
const canProvision = this.checkWhetherSolutionIsIdle();
|
|
303
305
|
if (canProvision.isErr()) {
|
|
304
306
|
return canProvision;
|
|
@@ -336,13 +338,18 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
336
338
|
(_f = ctx.ui) === null || _f === void 0 ? void 0 : _f.showMessage("info", msg, false);
|
|
337
339
|
}
|
|
338
340
|
(_g = ctx.envInfo.state.get(constants_2.GLOBAL_CONFIG)) === null || _g === void 0 ? void 0 : _g.set(constants_2.SOLUTION_PROVISION_SUCCEEDED, true);
|
|
341
|
+
if (!this.isAzureProject(ctx) && tools_1.isMultiEnvEnabled()) {
|
|
342
|
+
const appStudioTokenJson = await ((_h = ctx.appStudioToken) === null || _h === void 0 ? void 0 : _h.getJsonObject());
|
|
343
|
+
(_j = ctx.envInfo.state
|
|
344
|
+
.get(constants_2.GLOBAL_CONFIG)) === null || _j === void 0 ? void 0 : _j.set(_1.REMOTE_TEAMS_APP_TENANT_ID, appStudioTokenJson.tid);
|
|
345
|
+
}
|
|
339
346
|
}
|
|
340
347
|
else {
|
|
341
348
|
if (!tools_1.isUserCancelError(provisionResult.error) &&
|
|
342
349
|
!tools_1.isCheckAccountError(provisionResult.error)) {
|
|
343
|
-
const msg = util.format(tools_1.getStrings().solution.ProvisionFailNotice, (
|
|
344
|
-
(
|
|
345
|
-
(
|
|
350
|
+
const msg = util.format(tools_1.getStrings().solution.ProvisionFailNotice, (_k = ctx.projectSettings) === null || _k === void 0 ? void 0 : _k.appName);
|
|
351
|
+
(_l = ctx.logProvider) === null || _l === void 0 ? void 0 : _l.error(msg);
|
|
352
|
+
(_m = ctx.envInfo.state.get(constants_2.GLOBAL_CONFIG)) === null || _m === void 0 ? void 0 : _m.set(constants_2.SOLUTION_PROVISION_SUCCEEDED, false);
|
|
346
353
|
}
|
|
347
354
|
}
|
|
348
355
|
return provisionResult;
|
|
@@ -925,509 +932,16 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
925
932
|
}
|
|
926
933
|
}
|
|
927
934
|
async grantPermission(ctx) {
|
|
928
|
-
|
|
929
|
-
(_a = ctx.telemetryReporter) === null || _a === void 0 ? void 0 : _a.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.GrantPermissionStart, {
|
|
930
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
931
|
-
});
|
|
932
|
-
const progressBar = (_b = ctx.ui) === null || _b === void 0 ? void 0 : _b.createProgressBar("Granting permission", 1);
|
|
933
|
-
try {
|
|
934
|
-
const result = await this.getCurrentUserInfo(ctx);
|
|
935
|
-
if (result.isErr()) {
|
|
936
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, result.error, ctx.telemetryReporter));
|
|
937
|
-
}
|
|
938
|
-
const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
|
|
939
|
-
if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
|
|
940
|
-
if (((_c = ctx.answers) === null || _c === void 0 ? void 0 : _c.platform) === teamsfx_api_1.Platform.CLI) {
|
|
941
|
-
(_d = ctx.ui) === null || _d === void 0 ? void 0 : _d.showMessage("warn", stateResult.message, false);
|
|
942
|
-
}
|
|
943
|
-
else if (((_e = ctx.answers) === null || _e === void 0 ? void 0 : _e.platform) === teamsfx_api_1.Platform.VSCode) {
|
|
944
|
-
(_f = ctx.logProvider) === null || _f === void 0 ? void 0 : _f.warning(stateResult.message);
|
|
945
|
-
}
|
|
946
|
-
return teamsfx_api_1.ok({
|
|
947
|
-
state: stateResult.state,
|
|
948
|
-
message: stateResult.message,
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
const email = ctx.answers["email"];
|
|
952
|
-
if (!email || email === result.value.userPrincipalName) {
|
|
953
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnUserError(new Error("Collaborator's email cannot be null or same as current user"), constants_2.SolutionSource, constants_2.SolutionError.EmailCannotBeEmptyOrSame), ctx.telemetryReporter));
|
|
954
|
-
}
|
|
955
|
-
const userInfo = await this.getUserInfo(ctx, email);
|
|
956
|
-
if (!userInfo) {
|
|
957
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnUserError(new Error("Cannot find user in current tenant, please check whether your email address is correct"), constants_2.SolutionSource, constants_2.SolutionError.CannotFindUserInCurrentTenant), ctx.telemetryReporter));
|
|
958
|
-
}
|
|
959
|
-
progressBar === null || progressBar === void 0 ? void 0 : progressBar.start();
|
|
960
|
-
progressBar === null || progressBar === void 0 ? void 0 : progressBar.next(`Grant permission for user ${email}`);
|
|
961
|
-
const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
|
|
962
|
-
this.AadPlugin,
|
|
963
|
-
this.AppStudioPlugin,
|
|
964
|
-
]);
|
|
965
|
-
const grantPermissionWithCtx = pluginsWithCtx.map(([plugin, context]) => {
|
|
966
|
-
return [
|
|
967
|
-
(plugin === null || plugin === void 0 ? void 0 : plugin.grantPermission)
|
|
968
|
-
? (ctx) => plugin.grantPermission.bind(plugin)(ctx, userInfo)
|
|
969
|
-
: undefined,
|
|
970
|
-
context,
|
|
971
|
-
plugin.name,
|
|
972
|
-
];
|
|
973
|
-
});
|
|
974
|
-
if (((_g = ctx.answers) === null || _g === void 0 ? void 0 : _g.platform) === teamsfx_api_1.Platform.CLI) {
|
|
975
|
-
const aadAppTenantId = (_j = (_h = ctx.envInfo.state) === null || _h === void 0 ? void 0 : _h.get(constants_2.PluginNames.AAD)) === null || _j === void 0 ? void 0 : _j.get(constants_2.REMOTE_TENANT_ID);
|
|
976
|
-
const envName = ctx.envInfo.envName;
|
|
977
|
-
if (!envName) {
|
|
978
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), constants_2.SolutionSource, constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
|
|
979
|
-
}
|
|
980
|
-
const message = [
|
|
981
|
-
{ content: `Account to grant permission: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
982
|
-
{ content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
983
|
-
{
|
|
984
|
-
content: `Starting grant permission for environment: `,
|
|
985
|
-
color: teamsfx_api_1.Colors.BRIGHT_WHITE,
|
|
986
|
-
},
|
|
987
|
-
{ content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
988
|
-
{ content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
989
|
-
{ content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
990
|
-
];
|
|
991
|
-
(_k = ctx.ui) === null || _k === void 0 ? void 0 : _k.showMessage("info", message, false);
|
|
992
|
-
}
|
|
993
|
-
const results = await executor_1.executeConcurrently("", grantPermissionWithCtx);
|
|
994
|
-
const permissions = [];
|
|
995
|
-
const errors = [];
|
|
996
|
-
for (const result of results) {
|
|
997
|
-
if (result.isErr()) {
|
|
998
|
-
errors.push(result);
|
|
999
|
-
continue;
|
|
1000
|
-
}
|
|
1001
|
-
if (result && result.value) {
|
|
1002
|
-
for (const res of result.value) {
|
|
1003
|
-
permissions.push(res);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
let errorMsg = "";
|
|
1008
|
-
if (errors.length > 0) {
|
|
1009
|
-
errorMsg += `Failed to grant permission for the below resources to user: ${email}.\n Resource details: \n`;
|
|
1010
|
-
for (const fxError of errors) {
|
|
1011
|
-
errorMsg += fxError.error.message + "\n";
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
if (((_l = ctx.answers) === null || _l === void 0 ? void 0 : _l.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1015
|
-
for (const permission of permissions) {
|
|
1016
|
-
const message = [
|
|
1017
|
-
{ content: `${(_m = permission.roles) === null || _m === void 0 ? void 0 : _m.join(",")} `, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1018
|
-
{ content: "permission has been granted to ", color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1019
|
-
{ content: permission.name, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1020
|
-
{ content: ", Resource ID: ", color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1021
|
-
{ content: `${permission.resourceId}`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1022
|
-
];
|
|
1023
|
-
(_o = ctx.ui) === null || _o === void 0 ? void 0 : _o.showMessage("info", message, false);
|
|
1024
|
-
}
|
|
1025
|
-
(_p = ctx.ui) === null || _p === void 0 ? void 0 : _p.showMessage("info", `\nSkip grant permission for Azure resources. You may want to handle that via Azure portal. `, false);
|
|
1026
|
-
if (errorMsg) {
|
|
1027
|
-
for (const fxError of errors) {
|
|
1028
|
-
(_q = ctx.ui) === null || _q === void 0 ? void 0 : _q.showMessage("error", errorMsg, false);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
if (errorMsg) {
|
|
1033
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.GrantPermission, teamsfx_api_1.returnUserError(new Error(errorMsg), constants_2.SolutionSource, constants_2.SolutionError.FailedToGrantPermission), ctx.telemetryReporter));
|
|
1034
|
-
}
|
|
1035
|
-
(_r = ctx.telemetryReporter) === null || _r === void 0 ? void 0 : _r.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.GrantPermission, {
|
|
1036
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1037
|
-
[constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
|
|
1038
|
-
});
|
|
1039
|
-
return teamsfx_api_1.ok({
|
|
1040
|
-
state: permissionInterface_1.CollaborationState.OK,
|
|
1041
|
-
userInfo: userInfo,
|
|
1042
|
-
permissions,
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
finally {
|
|
1046
|
-
await (progressBar === null || progressBar === void 0 ? void 0 : progressBar.end(true));
|
|
1047
|
-
this.runningState = SolutionRunningState.Idle;
|
|
1048
|
-
}
|
|
935
|
+
return grantPermission_1.grantPermission({ apiVersion: 1, ctx });
|
|
1049
936
|
}
|
|
1050
937
|
async checkPermission(ctx) {
|
|
1051
|
-
|
|
1052
|
-
(_a = ctx.telemetryReporter) === null || _a === void 0 ? void 0 : _a.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.CheckPermissionStart, {
|
|
1053
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1054
|
-
});
|
|
1055
|
-
try {
|
|
1056
|
-
const result = await this.getCurrentUserInfo(ctx);
|
|
1057
|
-
if (result.isErr()) {
|
|
1058
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.CheckPermission, result.error, ctx.telemetryReporter));
|
|
1059
|
-
}
|
|
1060
|
-
const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
|
|
1061
|
-
if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
|
|
1062
|
-
if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1063
|
-
(_c = ctx.ui) === null || _c === void 0 ? void 0 : _c.showMessage("warn", stateResult.message, false);
|
|
1064
|
-
}
|
|
1065
|
-
return teamsfx_api_1.ok({
|
|
1066
|
-
state: stateResult.state,
|
|
1067
|
-
message: stateResult.message,
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
const userInfo = result.value;
|
|
1071
|
-
const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
|
|
1072
|
-
this.AadPlugin,
|
|
1073
|
-
this.AppStudioPlugin,
|
|
1074
|
-
]);
|
|
1075
|
-
const checkPermissionWithCtx = pluginsWithCtx.map(([plugin, context]) => {
|
|
1076
|
-
return [
|
|
1077
|
-
(plugin === null || plugin === void 0 ? void 0 : plugin.checkPermission)
|
|
1078
|
-
? (ctx) => plugin.checkPermission.bind(plugin)(ctx, userInfo)
|
|
1079
|
-
: undefined,
|
|
1080
|
-
context,
|
|
1081
|
-
plugin.name,
|
|
1082
|
-
];
|
|
1083
|
-
});
|
|
1084
|
-
if (((_d = ctx.answers) === null || _d === void 0 ? void 0 : _d.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1085
|
-
const aadAppTenantId = (_f = (_e = ctx.envInfo.state) === null || _e === void 0 ? void 0 : _e.get(constants_2.PluginNames.AAD)) === null || _f === void 0 ? void 0 : _f.get(constants_2.REMOTE_TENANT_ID);
|
|
1086
|
-
const envName = ctx.envInfo.envName;
|
|
1087
|
-
if (!envName) {
|
|
1088
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.CheckPermission, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), constants_2.SolutionSource, constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
|
|
1089
|
-
}
|
|
1090
|
-
const message = [
|
|
1091
|
-
{ content: `Account used to check: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1092
|
-
{ content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1093
|
-
{
|
|
1094
|
-
content: `Starting check permission for environment: `,
|
|
1095
|
-
color: teamsfx_api_1.Colors.BRIGHT_WHITE,
|
|
1096
|
-
},
|
|
1097
|
-
{ content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1098
|
-
{ content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1099
|
-
{ content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1100
|
-
];
|
|
1101
|
-
(_g = ctx.ui) === null || _g === void 0 ? void 0 : _g.showMessage("info", message, false);
|
|
1102
|
-
}
|
|
1103
|
-
const results = await executor_1.executeConcurrently("", checkPermissionWithCtx);
|
|
1104
|
-
const permissions = [];
|
|
1105
|
-
const errors = [];
|
|
1106
|
-
for (const result of results) {
|
|
1107
|
-
if (result.isErr()) {
|
|
1108
|
-
errors.push(result);
|
|
1109
|
-
continue;
|
|
1110
|
-
}
|
|
1111
|
-
if (result && result.value) {
|
|
1112
|
-
for (const res of result.value) {
|
|
1113
|
-
permissions.push(res);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
let errorMsg = "";
|
|
1118
|
-
if (errors.length > 0) {
|
|
1119
|
-
errorMsg += `Failed to check permission for the below resources.\n Resource details: \n`;
|
|
1120
|
-
for (const fxError of errors) {
|
|
1121
|
-
errorMsg += fxError.error.message + "\n";
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
if (((_h = ctx.answers) === null || _h === void 0 ? void 0 : _h.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1125
|
-
for (const permission of permissions) {
|
|
1126
|
-
const message = [
|
|
1127
|
-
{ content: `Resource ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1128
|
-
{ content: (_j = permission.resourceId) !== null && _j !== void 0 ? _j : "undefined", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1129
|
-
{ content: `, Resource Name: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1130
|
-
{ content: permission.name, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1131
|
-
{ content: `, Permission: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1132
|
-
{
|
|
1133
|
-
content: permission.roles ? permission.roles.toString() : "undefined" + "\n",
|
|
1134
|
-
color: teamsfx_api_1.Colors.BRIGHT_MAGENTA,
|
|
1135
|
-
},
|
|
1136
|
-
];
|
|
1137
|
-
(_k = ctx.ui) === null || _k === void 0 ? void 0 : _k.showMessage("info", message, false);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
if (errorMsg) {
|
|
1141
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.CheckPermission, teamsfx_api_1.returnUserError(new Error(errorMsg), constants_2.SolutionSource, constants_2.SolutionError.FailedToCheckPermission), ctx.telemetryReporter));
|
|
1142
|
-
}
|
|
1143
|
-
const aadPermission = permissions.find((permission) => permission.name === "Azure AD App");
|
|
1144
|
-
const teamsAppPermission = permissions.find((permission) => permission.name === "Teams App");
|
|
1145
|
-
(_l = ctx.telemetryReporter) === null || _l === void 0 ? void 0 : _l.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.CheckPermission, {
|
|
1146
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1147
|
-
[constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
|
|
1148
|
-
[constants_2.SolutionTelemetryProperty.AadPermission]: (aadPermission === null || aadPermission === void 0 ? void 0 : aadPermission.roles)
|
|
1149
|
-
? aadPermission.roles.join(";")
|
|
1150
|
-
: "undefined",
|
|
1151
|
-
[constants_2.SolutionTelemetryProperty.TeamsAppPermission]: (teamsAppPermission === null || teamsAppPermission === void 0 ? void 0 : teamsAppPermission.roles)
|
|
1152
|
-
? teamsAppPermission.roles.join(";")
|
|
1153
|
-
: "undefined",
|
|
1154
|
-
});
|
|
1155
|
-
return teamsfx_api_1.ok({
|
|
1156
|
-
state: permissionInterface_1.CollaborationState.OK,
|
|
1157
|
-
permissions,
|
|
1158
|
-
});
|
|
1159
|
-
}
|
|
1160
|
-
finally {
|
|
1161
|
-
this.runningState = SolutionRunningState.Idle;
|
|
1162
|
-
}
|
|
938
|
+
return checkPermission_1.checkPermission({ apiVersion: 1, ctx });
|
|
1163
939
|
}
|
|
1164
940
|
async listAllCollaborators(ctx) {
|
|
1165
|
-
|
|
1166
|
-
try {
|
|
1167
|
-
(_a = ctx.telemetryReporter) === null || _a === void 0 ? void 0 : _a.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListAllCollaboratorsStart, {
|
|
1168
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1169
|
-
});
|
|
1170
|
-
const collaboratorsResult = {};
|
|
1171
|
-
const envs = await __1.environmentManager.listEnvConfigs(ctx.root);
|
|
1172
|
-
if (envs.isErr()) {
|
|
1173
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListAllCollaborators, envs.error, ctx.telemetryReporter));
|
|
1174
|
-
}
|
|
1175
|
-
const result = await this.getCurrentUserInfo(ctx);
|
|
1176
|
-
if (result.isErr()) {
|
|
1177
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListAllCollaborators, result.error, ctx.telemetryReporter));
|
|
1178
|
-
}
|
|
1179
|
-
const userInfo = result.value;
|
|
1180
|
-
for (const env of envs.value) {
|
|
1181
|
-
try {
|
|
1182
|
-
const envInfo = await __1.environmentManager.loadEnvInfo(ctx.root, ctx.cryptoProvider, env);
|
|
1183
|
-
if (envInfo.isErr()) {
|
|
1184
|
-
throw envInfo.error;
|
|
1185
|
-
}
|
|
1186
|
-
ctx.envInfo = envInfo.value;
|
|
1187
|
-
const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
|
|
1188
|
-
if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
|
|
1189
|
-
if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1190
|
-
(_c = ctx.ui) === null || _c === void 0 ? void 0 : _c.showMessage("warn", stateResult.message, false);
|
|
1191
|
-
}
|
|
1192
|
-
collaboratorsResult[env] = {
|
|
1193
|
-
state: stateResult.state,
|
|
1194
|
-
message: stateResult.message,
|
|
1195
|
-
};
|
|
1196
|
-
continue;
|
|
1197
|
-
}
|
|
1198
|
-
const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
|
|
1199
|
-
this.AppStudioPlugin,
|
|
1200
|
-
this.AadPlugin,
|
|
1201
|
-
]);
|
|
1202
|
-
const listCollaboratorWithCtx = pluginsWithCtx.map(([plugin, context]) => {
|
|
1203
|
-
return [
|
|
1204
|
-
(plugin === null || plugin === void 0 ? void 0 : plugin.listCollaborator)
|
|
1205
|
-
? (ctx) => plugin.listCollaborator.bind(plugin)(ctx, userInfo)
|
|
1206
|
-
: undefined,
|
|
1207
|
-
context,
|
|
1208
|
-
plugin.name,
|
|
1209
|
-
];
|
|
1210
|
-
});
|
|
1211
|
-
const results = await executor_1.executeConcurrently("", listCollaboratorWithCtx);
|
|
1212
|
-
const errors = [];
|
|
1213
|
-
for (const result of results) {
|
|
1214
|
-
if (result.isErr()) {
|
|
1215
|
-
errors.push(result);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
let errorMsg = "";
|
|
1219
|
-
if (errors.length > 0) {
|
|
1220
|
-
errorMsg += `Failed to list collaborator for the project.\n Error details: \n`;
|
|
1221
|
-
for (const fxError of errors) {
|
|
1222
|
-
errorMsg += fxError.error.message + "\n";
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
if (errorMsg) {
|
|
1226
|
-
collaboratorsResult[env] = {
|
|
1227
|
-
state: permissionInterface_1.CollaborationState.ERROR,
|
|
1228
|
-
error: teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListAllCollaborators, teamsfx_api_1.returnUserError(new Error(errorMsg), constants_2.SolutionSource, constants_2.SolutionError.FailedToListCollaborator), ctx.telemetryReporter)),
|
|
1229
|
-
};
|
|
1230
|
-
continue;
|
|
1231
|
-
}
|
|
1232
|
-
const teamsAppOwners = results[0].isErr() ? [] : results[0].value;
|
|
1233
|
-
const aadOwners = results[1].isErr() ? [] : results[1].value;
|
|
1234
|
-
const collaborators = [];
|
|
1235
|
-
for (const teamsAppOwner of teamsAppOwners) {
|
|
1236
|
-
const aadOwner = aadOwners.find((owner) => owner.userObjectId === teamsAppOwner.userObjectId);
|
|
1237
|
-
collaborators.push({
|
|
1238
|
-
// For guest account, aadOwner.userPrincipalName will be user's email, and is easy to read.
|
|
1239
|
-
userPrincipalName: (_e = (_d = aadOwner === null || aadOwner === void 0 ? void 0 : aadOwner.userPrincipalName) !== null && _d !== void 0 ? _d : teamsAppOwner.userPrincipalName) !== null && _e !== void 0 ? _e : teamsAppOwner.userObjectId,
|
|
1240
|
-
userObjectId: teamsAppOwner.userObjectId,
|
|
1241
|
-
isAadOwner: aadOwner ? true : false,
|
|
1242
|
-
aadResourceId: aadOwner ? aadOwner.resourceId : undefined,
|
|
1243
|
-
teamsAppResourceId: teamsAppOwner.resourceId,
|
|
1244
|
-
});
|
|
1245
|
-
}
|
|
1246
|
-
const aadOwnerCount = collaborators.filter((collaborator) => collaborator.aadResourceId && collaborator.isAadOwner).length;
|
|
1247
|
-
(_f = ctx.telemetryReporter) === null || _f === void 0 ? void 0 : _f.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListAllCollaborators, {
|
|
1248
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1249
|
-
[constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
|
|
1250
|
-
[constants_2.SolutionTelemetryProperty.CollaboratorCount]: collaborators.length.toString(),
|
|
1251
|
-
[constants_2.SolutionTelemetryProperty.AadOwnerCount]: aadOwnerCount.toString(),
|
|
1252
|
-
[constants_2.SolutionTelemetryProperty.Env]: tools_1.getHashedEnv(env),
|
|
1253
|
-
});
|
|
1254
|
-
collaboratorsResult[env] = {
|
|
1255
|
-
collaborators: collaborators,
|
|
1256
|
-
state: permissionInterface_1.CollaborationState.OK,
|
|
1257
|
-
};
|
|
1258
|
-
}
|
|
1259
|
-
catch (error) {
|
|
1260
|
-
collaboratorsResult[env] = {
|
|
1261
|
-
state: permissionInterface_1.CollaborationState.ERROR,
|
|
1262
|
-
error: teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListAllCollaborators, teamsfx_api_1.returnUserError(error, constants_2.SolutionSource, constants_2.SolutionError.FailedToListCollaborator), ctx.telemetryReporter)),
|
|
1263
|
-
};
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
return teamsfx_api_1.ok(collaboratorsResult);
|
|
1267
|
-
}
|
|
1268
|
-
finally {
|
|
1269
|
-
this.runningState = SolutionRunningState.Idle;
|
|
1270
|
-
}
|
|
941
|
+
return listAllCollaborators_1.listAllCollaborators({ apiVersion: 1, ctx });
|
|
1271
942
|
}
|
|
1272
943
|
async listCollaborator(ctx) {
|
|
1273
|
-
|
|
1274
|
-
(_a = ctx.telemetryReporter) === null || _a === void 0 ? void 0 : _a.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListCollaboratorStart, {
|
|
1275
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1276
|
-
});
|
|
1277
|
-
try {
|
|
1278
|
-
const result = await this.getCurrentUserInfo(ctx);
|
|
1279
|
-
if (result.isErr()) {
|
|
1280
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListCollaborator, result.error, ctx.telemetryReporter));
|
|
1281
|
-
}
|
|
1282
|
-
const stateResult = await this.getCurrentCollaborationState(ctx, result.value);
|
|
1283
|
-
if (stateResult.state != permissionInterface_1.CollaborationState.OK) {
|
|
1284
|
-
if (((_b = ctx.answers) === null || _b === void 0 ? void 0 : _b.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1285
|
-
(_c = ctx.ui) === null || _c === void 0 ? void 0 : _c.showMessage("warn", stateResult.message, false);
|
|
1286
|
-
}
|
|
1287
|
-
else if (((_d = ctx.answers) === null || _d === void 0 ? void 0 : _d.platform) === teamsfx_api_1.Platform.VSCode) {
|
|
1288
|
-
(_e = ctx.logProvider) === null || _e === void 0 ? void 0 : _e.warning(stateResult.message);
|
|
1289
|
-
}
|
|
1290
|
-
return teamsfx_api_1.ok({
|
|
1291
|
-
state: stateResult.state,
|
|
1292
|
-
message: stateResult.message,
|
|
1293
|
-
});
|
|
1294
|
-
}
|
|
1295
|
-
const userInfo = result.value;
|
|
1296
|
-
const pluginsWithCtx = this.getPluginAndContextArray(ctx, [
|
|
1297
|
-
this.AppStudioPlugin,
|
|
1298
|
-
this.AadPlugin,
|
|
1299
|
-
]);
|
|
1300
|
-
const listCollaboratorWithCtx = pluginsWithCtx.map(([plugin, context]) => {
|
|
1301
|
-
return [
|
|
1302
|
-
(plugin === null || plugin === void 0 ? void 0 : plugin.listCollaborator)
|
|
1303
|
-
? (ctx) => plugin.listCollaborator.bind(plugin)(ctx, userInfo)
|
|
1304
|
-
: undefined,
|
|
1305
|
-
context,
|
|
1306
|
-
plugin.name,
|
|
1307
|
-
];
|
|
1308
|
-
});
|
|
1309
|
-
const envName = ctx.envInfo.envName;
|
|
1310
|
-
if (!envName) {
|
|
1311
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListCollaborator, teamsfx_api_1.returnSystemError(new Error("Failed to get env name."), constants_2.SolutionSource, constants_2.SolutionError.FailedToGetEnvName), ctx.telemetryReporter));
|
|
1312
|
-
}
|
|
1313
|
-
const results = await executor_1.executeConcurrently("", listCollaboratorWithCtx);
|
|
1314
|
-
const errors = [];
|
|
1315
|
-
for (const result of results) {
|
|
1316
|
-
if (result.isErr()) {
|
|
1317
|
-
errors.push(result);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
let errorMsg = "";
|
|
1321
|
-
if (errors.length > 0) {
|
|
1322
|
-
errorMsg += `Failed to list collaborator for the project.\n Error details: \n`;
|
|
1323
|
-
for (const fxError of errors) {
|
|
1324
|
-
errorMsg += fxError.error.message + "\n";
|
|
1325
|
-
}
|
|
1326
|
-
}
|
|
1327
|
-
if (errorMsg) {
|
|
1328
|
-
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.ListCollaborator, teamsfx_api_1.returnUserError(new Error(errorMsg), constants_2.SolutionSource, constants_2.SolutionError.FailedToListCollaborator), ctx.telemetryReporter));
|
|
1329
|
-
}
|
|
1330
|
-
const teamsAppOwners = results[0].isErr() ? [] : results[0].value;
|
|
1331
|
-
const aadOwners = results[1].isErr() ? [] : results[1].value;
|
|
1332
|
-
const collaborators = [];
|
|
1333
|
-
const teamsAppId = (_g = (_f = teamsAppOwners[0]) === null || _f === void 0 ? void 0 : _f.resourceId) !== null && _g !== void 0 ? _g : "";
|
|
1334
|
-
const aadAppId = (_j = (_h = aadOwners[0]) === null || _h === void 0 ? void 0 : _h.resourceId) !== null && _j !== void 0 ? _j : "";
|
|
1335
|
-
const aadAppTenantId = (_l = (_k = ctx.envInfo.state) === null || _k === void 0 ? void 0 : _k.get(constants_2.PluginNames.AAD)) === null || _l === void 0 ? void 0 : _l.get(constants_2.REMOTE_TENANT_ID);
|
|
1336
|
-
for (const teamsAppOwner of teamsAppOwners) {
|
|
1337
|
-
const aadOwner = aadOwners.find((owner) => owner.userObjectId === teamsAppOwner.userObjectId);
|
|
1338
|
-
collaborators.push({
|
|
1339
|
-
// For guest account, aadOwner.userPrincipalName will be user's email, and is easy to read.
|
|
1340
|
-
userPrincipalName: (_o = (_m = aadOwner === null || aadOwner === void 0 ? void 0 : aadOwner.userPrincipalName) !== null && _m !== void 0 ? _m : teamsAppOwner.userPrincipalName) !== null && _o !== void 0 ? _o : teamsAppOwner.userObjectId,
|
|
1341
|
-
userObjectId: teamsAppOwner.userObjectId,
|
|
1342
|
-
isAadOwner: aadOwner ? true : false,
|
|
1343
|
-
aadResourceId: aadOwner ? aadOwner.resourceId : undefined,
|
|
1344
|
-
teamsAppResourceId: teamsAppOwner.resourceId,
|
|
1345
|
-
});
|
|
1346
|
-
}
|
|
1347
|
-
if (((_p = ctx.answers) === null || _p === void 0 ? void 0 : _p.platform) === teamsfx_api_1.Platform.CLI || ((_q = ctx.answers) === null || _q === void 0 ? void 0 : _q.platform) === teamsfx_api_1.Platform.VSCode) {
|
|
1348
|
-
const message = [
|
|
1349
|
-
{ content: `Listing M365 permissions\n`, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1350
|
-
{ content: `Account used to check: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1351
|
-
{ content: userInfo.userPrincipalName + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1352
|
-
{
|
|
1353
|
-
content: `Starting list all teams app owners for environment: `,
|
|
1354
|
-
color: teamsfx_api_1.Colors.BRIGHT_WHITE,
|
|
1355
|
-
},
|
|
1356
|
-
{ content: `${envName}\n`, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1357
|
-
{ content: `Tenant ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1358
|
-
{ content: aadAppTenantId + "\n", color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1359
|
-
{ content: `M365 Teams App (ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1360
|
-
{ content: teamsAppId, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1361
|
-
{ content: `), SSO AAD App (ID: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1362
|
-
{ content: aadAppId, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA },
|
|
1363
|
-
{ content: `)\n`, color: teamsfx_api_1.Colors.BRIGHT_WHITE },
|
|
1364
|
-
];
|
|
1365
|
-
for (const collaborator of collaborators) {
|
|
1366
|
-
message.push({ content: `Teams App Owner: `, color: teamsfx_api_1.Colors.BRIGHT_WHITE }, { content: collaborator.userPrincipalName, color: teamsfx_api_1.Colors.BRIGHT_MAGENTA }, { content: `. `, color: teamsfx_api_1.Colors.BRIGHT_WHITE });
|
|
1367
|
-
if (!collaborator.isAadOwner) {
|
|
1368
|
-
message.push({ content: `(Not owner of SSO AAD app)`, color: teamsfx_api_1.Colors.BRIGHT_YELLOW });
|
|
1369
|
-
}
|
|
1370
|
-
message.push({ content: "\n", color: teamsfx_api_1.Colors.BRIGHT_WHITE });
|
|
1371
|
-
}
|
|
1372
|
-
if (((_r = ctx.answers) === null || _r === void 0 ? void 0 : _r.platform) === teamsfx_api_1.Platform.CLI) {
|
|
1373
|
-
(_s = ctx.ui) === null || _s === void 0 ? void 0 : _s.showMessage("info", message, false);
|
|
1374
|
-
}
|
|
1375
|
-
else if (((_t = ctx.answers) === null || _t === void 0 ? void 0 : _t.platform) === teamsfx_api_1.Platform.VSCode) {
|
|
1376
|
-
(_u = ctx.logProvider) === null || _u === void 0 ? void 0 : _u.info(message);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
const aadOwnerCount = collaborators.filter((collaborator) => collaborator.aadResourceId && collaborator.isAadOwner).length;
|
|
1380
|
-
(_v = ctx.telemetryReporter) === null || _v === void 0 ? void 0 : _v.sendTelemetryEvent(constants_2.SolutionTelemetryEvent.ListCollaborator, {
|
|
1381
|
-
[constants_2.SolutionTelemetryProperty.Component]: constants_2.SolutionTelemetryComponentName,
|
|
1382
|
-
[constants_2.SolutionTelemetryProperty.Success]: constants_2.SolutionTelemetrySuccess.Yes,
|
|
1383
|
-
[constants_2.SolutionTelemetryProperty.CollaboratorCount]: collaborators.length.toString(),
|
|
1384
|
-
[constants_2.SolutionTelemetryProperty.AadOwnerCount]: aadOwnerCount.toString(),
|
|
1385
|
-
[constants_2.SolutionTelemetryProperty.Env]: tools_1.getHashedEnv(envName),
|
|
1386
|
-
});
|
|
1387
|
-
return teamsfx_api_1.ok({
|
|
1388
|
-
collaborators: collaborators,
|
|
1389
|
-
state: permissionInterface_1.CollaborationState.OK,
|
|
1390
|
-
});
|
|
1391
|
-
}
|
|
1392
|
-
finally {
|
|
1393
|
-
this.runningState = SolutionRunningState.Idle;
|
|
1394
|
-
}
|
|
1395
|
-
}
|
|
1396
|
-
async getCurrentUserInfo(ctx) {
|
|
1397
|
-
const user = await this.getUserInfo(ctx);
|
|
1398
|
-
if (!user) {
|
|
1399
|
-
return teamsfx_api_1.err(teamsfx_api_1.returnSystemError(new Error("Failed to retrieve current user info from graph token"), constants_2.SolutionSource, constants_2.SolutionError.FailedToRetrieveUserInfo));
|
|
1400
|
-
}
|
|
1401
|
-
return teamsfx_api_1.ok(user);
|
|
1402
|
-
}
|
|
1403
|
-
getCurrentCollaborationState(ctx, user) {
|
|
1404
|
-
var _a, _b;
|
|
1405
|
-
const canProcess = this.checkWhetherSolutionIsIdle();
|
|
1406
|
-
if (canProcess.isErr()) {
|
|
1407
|
-
return {
|
|
1408
|
-
state: permissionInterface_1.CollaborationState.SolutionIsNotIdle,
|
|
1409
|
-
message: canProcess.error.message,
|
|
1410
|
-
};
|
|
1411
|
-
}
|
|
1412
|
-
const provisioned = this.checkWetherProvisionSucceeded(ctx.envInfo.state);
|
|
1413
|
-
if (!provisioned) {
|
|
1414
|
-
const warningMsg = "The resources have not been provisioned yet. Please provision the resources first.";
|
|
1415
|
-
return {
|
|
1416
|
-
state: permissionInterface_1.CollaborationState.NotProvisioned,
|
|
1417
|
-
message: warningMsg,
|
|
1418
|
-
};
|
|
1419
|
-
}
|
|
1420
|
-
const aadAppTenantId = (_b = (_a = ctx.envInfo.state) === null || _a === void 0 ? void 0 : _a.get(constants_2.PluginNames.AAD)) === null || _b === void 0 ? void 0 : _b.get(constants_2.REMOTE_TENANT_ID);
|
|
1421
|
-
if (!aadAppTenantId || user.tenantId != aadAppTenantId) {
|
|
1422
|
-
const warningMsg = "Tenant id of your account and the provisioned Azure AD app does not match. Please check whether you logined with wrong account.";
|
|
1423
|
-
return {
|
|
1424
|
-
state: permissionInterface_1.CollaborationState.M365TenantNotMatch,
|
|
1425
|
-
message: warningMsg,
|
|
1426
|
-
};
|
|
1427
|
-
}
|
|
1428
|
-
return {
|
|
1429
|
-
state: permissionInterface_1.CollaborationState.OK,
|
|
1430
|
-
};
|
|
944
|
+
return listCollaborator_1.listCollaborator({ apiVersion: 1, ctx });
|
|
1431
945
|
}
|
|
1432
946
|
loadTeamsAppTenantId(ctx, isLocalDebug, appStudioToken) {
|
|
1433
947
|
return utils_1.parseTeamsAppTenantId(appStudioToken).andThen((teamsAppTenantId) => {
|
|
@@ -1461,10 +975,12 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1461
975
|
const functionPlugin = this.FunctionPlugin;
|
|
1462
976
|
const sqlPlugin = this.SqlPlugin;
|
|
1463
977
|
const apimPlugin = this.ApimPlugin;
|
|
978
|
+
const keyVaultPlugin = this.KeyVaultPlugin;
|
|
1464
979
|
const alreadyHaveFunction = selectedPlugins.includes(functionPlugin.name);
|
|
1465
980
|
const alreadyHaveSQL = selectedPlugins.includes(sqlPlugin.name);
|
|
1466
981
|
const alreadyHaveAPIM = selectedPlugins.includes(apimPlugin.name);
|
|
1467
|
-
const
|
|
982
|
+
const alreadyHavekeyVault = selectedPlugins.includes(keyVaultPlugin.name);
|
|
983
|
+
const addQuestion = question_1.createAddAzureResourceQuestion(alreadyHaveFunction, alreadyHaveSQL, alreadyHaveAPIM, alreadyHavekeyVault);
|
|
1468
984
|
const addAzureResourceNode = new teamsfx_api_1.QTreeNode(addQuestion);
|
|
1469
985
|
// there two cases to add function re-scaffold: 1. select add function 2. select add sql and function is not selected when creating
|
|
1470
986
|
if (functionPlugin.getQuestionsForUserTask) {
|
|
@@ -1480,7 +996,9 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1480
996
|
}
|
|
1481
997
|
else {
|
|
1482
998
|
// if not function activated, select any option will trigger function question
|
|
1483
|
-
azure_function.condition = {
|
|
999
|
+
azure_function.condition = {
|
|
1000
|
+
containsAny: [question_1.AzureResourceApim.id, question_1.AzureResourceFunction.id, question_1.AzureResourceSQL.id],
|
|
1001
|
+
};
|
|
1484
1002
|
}
|
|
1485
1003
|
if (azure_function.data)
|
|
1486
1004
|
addAzureResourceNode.addChild(azure_function);
|
|
@@ -1622,9 +1140,11 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1622
1140
|
const functionPlugin = this.FunctionPlugin;
|
|
1623
1141
|
const sqlPlugin = this.SqlPlugin;
|
|
1624
1142
|
const apimPlugin = this.ApimPlugin;
|
|
1143
|
+
const keyVaultPlugin = this.KeyVaultPlugin;
|
|
1625
1144
|
const alreadyHaveFunction = selectedPlugins === null || selectedPlugins === void 0 ? void 0 : selectedPlugins.includes(functionPlugin.name);
|
|
1626
1145
|
const alreadyHaveSql = selectedPlugins === null || selectedPlugins === void 0 ? void 0 : selectedPlugins.includes(sqlPlugin.name);
|
|
1627
1146
|
const alreadyHaveApim = selectedPlugins === null || selectedPlugins === void 0 ? void 0 : selectedPlugins.includes(apimPlugin.name);
|
|
1147
|
+
const alreadyHaveKeyVault = selectedPlugins === null || selectedPlugins === void 0 ? void 0 : selectedPlugins.includes(keyVaultPlugin.name);
|
|
1628
1148
|
const addResourcesAnswer = ctx.answers[question_1.AzureSolutionQuestionNames.AddResources];
|
|
1629
1149
|
if (!addResourcesAnswer) {
|
|
1630
1150
|
return teamsfx_api_1.err(teamsfx_api_1.returnUserError(new Error(`answer of ${question_1.AzureSolutionQuestionNames.AddResources} is empty!`), constants_2.SolutionSource, constants_2.SolutionError.InvalidInput));
|
|
@@ -1632,6 +1152,7 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1632
1152
|
const addSQL = addResourcesAnswer.includes(question_1.AzureResourceSQL.id);
|
|
1633
1153
|
const addFunc = addResourcesAnswer.includes(question_1.AzureResourceFunction.id);
|
|
1634
1154
|
const addApim = addResourcesAnswer.includes(question_1.AzureResourceApim.id);
|
|
1155
|
+
const addKeyVault = addResourcesAnswer.includes(question_1.AzureResourceKeyVault.id);
|
|
1635
1156
|
if ((alreadyHaveSql && addSQL) || (alreadyHaveApim && addApim)) {
|
|
1636
1157
|
const e = teamsfx_api_1.returnUserError(new Error("SQL/APIM is already added."), constants_2.SolutionSource, constants_2.SolutionError.AddResourceNotSupport);
|
|
1637
1158
|
return teamsfx_api_1.err(util_1.sendErrorTelemetryThenReturnError(constants_2.SolutionTelemetryEvent.AddResource, e, ctx.telemetryReporter));
|
|
@@ -1660,6 +1181,12 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1660
1181
|
notifications.push(question_1.AzureResourceApim.label);
|
|
1661
1182
|
addNewResoruceToProvision = true;
|
|
1662
1183
|
}
|
|
1184
|
+
if (addKeyVault && !alreadyHaveKeyVault) {
|
|
1185
|
+
pluginsToScaffold.push(keyVaultPlugin);
|
|
1186
|
+
azureResource.push(question_1.AzureResourceKeyVault.id);
|
|
1187
|
+
notifications.push(question_1.AzureResourceKeyVault.label);
|
|
1188
|
+
addNewResoruceToProvision = true;
|
|
1189
|
+
}
|
|
1663
1190
|
if (notifications.length > 0) {
|
|
1664
1191
|
if (tools_1.isArmSupportEnabled() && addNewResoruceToProvision) {
|
|
1665
1192
|
executeUserTask_1.showUpdateArmTemplateNotice(ctx.ui);
|
|
@@ -1974,44 +1501,6 @@ let TeamsAppSolution = class TeamsAppSolution {
|
|
|
1974
1501
|
applicationIdUri: configResult.value.applicationIdUri,
|
|
1975
1502
|
});
|
|
1976
1503
|
}
|
|
1977
|
-
async getUserInfo(ctx, email) {
|
|
1978
|
-
var _a, _b;
|
|
1979
|
-
const currentUser = await ((_a = ctx.graphTokenProvider) === null || _a === void 0 ? void 0 : _a.getJsonObject());
|
|
1980
|
-
if (!currentUser) {
|
|
1981
|
-
return undefined;
|
|
1982
|
-
}
|
|
1983
|
-
const tenantId = currentUser["tid"];
|
|
1984
|
-
let aadId = currentUser["oid"];
|
|
1985
|
-
let userPrincipalName = currentUser["unique_name"];
|
|
1986
|
-
let displayName = currentUser["name"];
|
|
1987
|
-
const isAdministrator = true;
|
|
1988
|
-
if (email) {
|
|
1989
|
-
const graphToken = await ((_b = ctx.graphTokenProvider) === null || _b === void 0 ? void 0 : _b.getAccessToken());
|
|
1990
|
-
const instance = axios_1.default.create({
|
|
1991
|
-
baseURL: "https://graph.microsoft.com/v1.0",
|
|
1992
|
-
});
|
|
1993
|
-
instance.defaults.headers.common["Authorization"] = `Bearer ${graphToken}`;
|
|
1994
|
-
const res = await instance.get(`/users?$filter=startsWith(mail,'${email}') or startsWith(userPrincipalName, '${email}')`);
|
|
1995
|
-
if (!res || !res.data || !res.data.value) {
|
|
1996
|
-
return undefined;
|
|
1997
|
-
}
|
|
1998
|
-
const collaborator = res.data.value.find((user) => user.mail.toLowerCase() === email.toLowerCase() ||
|
|
1999
|
-
user.userPrincipalName.toLowerCase() === email.toLowerCase());
|
|
2000
|
-
if (!collaborator) {
|
|
2001
|
-
return undefined;
|
|
2002
|
-
}
|
|
2003
|
-
aadId = collaborator.id;
|
|
2004
|
-
userPrincipalName = collaborator.userPrincipalName;
|
|
2005
|
-
displayName = collaborator.displayName;
|
|
2006
|
-
}
|
|
2007
|
-
return {
|
|
2008
|
-
tenantId,
|
|
2009
|
-
aadId,
|
|
2010
|
-
userPrincipalName,
|
|
2011
|
-
displayName,
|
|
2012
|
-
isAdministrator,
|
|
2013
|
-
};
|
|
2014
|
-
}
|
|
2015
1504
|
};
|
|
2016
1505
|
tslib_1.__decorate([
|
|
2017
1506
|
lib_1.hooks([errorHandler_1.ErrorHandlerMW]),
|