From 1fc83bd50b2f078ad4a392e717b1863b396366d4 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 6 Aug 2024 02:59:50 +0530 Subject: [PATCH 1/5] Changed for AAD Id --- src/client/extension.ts | 10 +++++++--- src/client/pac/PacTypes.ts | 18 ++++++++++++++++++ src/client/pac/PacWrapper.ts | 6 +++++- src/common/OneDSLoggerTelemetry/oneDSLogger.ts | 1 + 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 6cdbe8a5..9c7575c1 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -42,6 +42,7 @@ import { IArtemisAPIOrgResponse } from "../common/services/Interfaces"; import { ArtemisService } from "../common/services/ArtemisService"; import { workspaceContainsPortalConfigFolder } from "../common/utilities/PathFinderUtil"; import { getPortalsOrgURLs } from "../common/utilities/WorkspaceInfoFinderUtil"; +import { SUCCESS } from "../common/constants"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -192,9 +193,12 @@ export async function activate( const orgID = orgDetails.OrgId; const artemisResponse = await ArtemisService.fetchArtemisResponse(orgID, _telemetry); if (artemisResponse !== null && artemisResponse.length > 0) { - const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; - oneDSLoggerWrapper.instantiate(geoName, geoLongName); - oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName }); + const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth(); + if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) { + const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; + oneDSLoggerWrapper.instantiate(geoName, geoLongName); + oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName, principalObjectId: pacActiveAuth.Results?.EntraIDObjectId }); + } } }) ); diff --git a/src/client/pac/PacTypes.ts b/src/client/pac/PacTypes.ts index b4960914..c05d968c 100644 --- a/src/client/pac/PacTypes.ts +++ b/src/client/pac/PacTypes.ts @@ -72,4 +72,22 @@ export type ActiveOrgOutput = { EnvironmentId: string, } +export type ActiveAuthOutput = { + Type: string, + Cloud: string, + TenantId: string, + TenantCountry: string, + User: string, + EntraIDObjectId: string, + PUID: string, + TokenExpires: string, + EnvironmentGeo: string, + EnvironmentId: string, + EnvironmentType: string, + OrganizationId: string, + OrganizationUniqueName: string, + OrganizationFriendlyName: string, +} + +export type PacAuthWhoOutput = PacOutputWithResult; export type PacOrgWhoOutput = PacOutputWithResult; diff --git a/src/client/pac/PacWrapper.ts b/src/client/pac/PacWrapper.ts index 2fd655bb..884b2503 100644 --- a/src/client/pac/PacWrapper.ts +++ b/src/client/pac/PacWrapper.ts @@ -10,7 +10,7 @@ import * as fs from "fs-extra"; import { ChildProcessWithoutNullStreams, spawn } from "child_process"; import { BlockingQueue } from "../../common/utilities/BlockingQueue"; import { ITelemetry } from "../../common/OneDSLoggerTelemetry/telemetry/ITelemetry"; -import { PacOutput, PacAdminListOutput, PacAuthListOutput, PacSolutionListOutput, PacOrgListOutput, PacOrgWhoOutput } from "./PacTypes"; +import { PacOutput, PacAdminListOutput, PacAuthListOutput, PacSolutionListOutput, PacOrgListOutput, PacOrgWhoOutput, PacAuthWhoOutput } from "./PacTypes"; import { v4 } from "uuid"; import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper"; @@ -168,6 +168,10 @@ export class PacWrapper { return this.executeCommandAndParseResults(new PacArguments("org", "who")); } + public async activeAuth(): Promise { + return this.executeCommandAndParseResults(new PacArguments("auth", "who")); + } + public async pcfInit(outputDirectory: string): Promise { return this.executeCommandAndParseResults(new PacArguments("pcf", "init", "--outputDirectory", outputDirectory)); } diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 4eb69d43..743d0039 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -380,6 +380,7 @@ export class OneDSLogger implements ITelemetryLogger { OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).OrgId; OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).EnvironmentId; OneDSLogger.contextInfo.orgGeo = JSON.parse(envelope.data.eventInfo).orgGeo; + OneDSLogger.userInfo.oid = JSON.parse(envelope.data.eventInfo).principalObjectId; // TODO: Populate website id OneDSLogger.contextInfo.websiteId = 'test' } From 07533e863040325711151fe219fcd2409d03ca67 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 6 Aug 2024 13:34:57 +0530 Subject: [PATCH 2/5] Updates --- src/client/extension.ts | 10 ++++++--- src/client/pac/PacTypes.ts | 21 +++++-------------- .../OneDSLoggerTelemetry/oneDSLogger.ts | 2 +- .../telemetryConstants.ts | 2 ++ 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 9c7575c1..fa26a3a7 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -43,6 +43,7 @@ import { ArtemisService } from "../common/services/ArtemisService"; import { workspaceContainsPortalConfigFolder } from "../common/utilities/PathFinderUtil"; import { getPortalsOrgURLs } from "../common/utilities/WorkspaceInfoFinderUtil"; import { SUCCESS } from "../common/constants"; +import { AadIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants"; let client: LanguageClient; let _context: vscode.ExtensionContext; @@ -194,11 +195,14 @@ export async function activate( const artemisResponse = await ArtemisService.fetchArtemisResponse(orgID, _telemetry); if (artemisResponse !== null && artemisResponse.length > 0) { const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth(); + let AadIdObject; if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) { - const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; - oneDSLoggerWrapper.instantiate(geoName, geoLongName); - oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName, principalObjectId: pacActiveAuth.Results?.EntraIDObjectId }); + AadIdObject = pacActiveAuth.Results.filter(obj => obj.Key === AadIdKey); } + const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; + oneDSLoggerWrapper.instantiate(geoName, geoLongName); + oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName, AadId: AadIdObject?.[0]?.Value }); + } }) ); diff --git a/src/client/pac/PacTypes.ts b/src/client/pac/PacTypes.ts index c05d968c..d18e62b6 100644 --- a/src/client/pac/PacTypes.ts +++ b/src/client/pac/PacTypes.ts @@ -72,22 +72,11 @@ export type ActiveOrgOutput = { EnvironmentId: string, } +export type PacOrgWhoOutput = PacOutputWithResult; + export type ActiveAuthOutput = { - Type: string, - Cloud: string, - TenantId: string, - TenantCountry: string, - User: string, - EntraIDObjectId: string, - PUID: string, - TokenExpires: string, - EnvironmentGeo: string, - EnvironmentId: string, - EnvironmentType: string, - OrganizationId: string, - OrganizationUniqueName: string, - OrganizationFriendlyName: string, + Key: string, + Value: string } -export type PacAuthWhoOutput = PacOutputWithResult; -export type PacOrgWhoOutput = PacOutputWithResult; +export type PacAuthWhoOutput = PacOutputWithResultList; diff --git a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts index 743d0039..0402ea8a 100644 --- a/src/common/OneDSLoggerTelemetry/oneDSLogger.ts +++ b/src/common/OneDSLoggerTelemetry/oneDSLogger.ts @@ -380,7 +380,7 @@ export class OneDSLogger implements ITelemetryLogger { OneDSLogger.contextInfo.orgId = JSON.parse(envelope.data.eventInfo).OrgId; OneDSLogger.contextInfo.envId = JSON.parse(envelope.data.eventInfo).EnvironmentId; OneDSLogger.contextInfo.orgGeo = JSON.parse(envelope.data.eventInfo).orgGeo; - OneDSLogger.userInfo.oid = JSON.parse(envelope.data.eventInfo).principalObjectId; + OneDSLogger.userInfo.oid = JSON.parse(envelope.data.eventInfo).AadId; // TODO: Populate website id OneDSLogger.contextInfo.websiteId = 'test' } diff --git a/src/common/OneDSLoggerTelemetry/telemetryConstants.ts b/src/common/OneDSLoggerTelemetry/telemetryConstants.ts index 9e934e65..eab9ad97 100644 --- a/src/common/OneDSLoggerTelemetry/telemetryConstants.ts +++ b/src/common/OneDSLoggerTelemetry/telemetryConstants.ts @@ -38,3 +38,5 @@ export enum GeoNames { } // Custom telemetry feature flag export const CUSTOM_TELEMETRY_FOR_POWER_PAGES_SETTING_NAME = 'enableTelemetry'; + +export const AadIdKey= 'Entra ID Object Id:'; \ No newline at end of file From b3ef63a2c2f2c9bc19ad4ee2ff410f25801b8fab Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Tue, 6 Aug 2024 16:42:29 +0530 Subject: [PATCH 3/5] Removing extra line --- src/client/extension.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index fa26a3a7..016de840 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -202,7 +202,6 @@ export async function activate( const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; oneDSLoggerWrapper.instantiate(geoName, geoLongName); oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName, AadId: AadIdObject?.[0]?.Value }); - } }) ); From 91bdecb1ce28bf6b8ae14e063df748f89ad1a2a4 Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Thu, 8 Aug 2024 13:14:21 +0530 Subject: [PATCH 4/5] change --- src/client/extension.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index 016de840..b070ccc8 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -201,7 +201,11 @@ export async function activate( } const { geoName, geoLongName } = artemisResponse[0]?.response as unknown as IArtemisAPIOrgResponse; oneDSLoggerWrapper.instantiate(geoName, geoLongName); - oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, { ...orgDetails, orgGeo: geoName, AadId: AadIdObject?.[0]?.Value }); + let initContext: object = {...orgDetails, orgGeo: geoName}; + if(AadIdObject?.[0]?.Value){ + initContext = { ...initContext, AadId: AadIdObject[0].Value} + } + oneDSLoggerWrapper.getLogger().traceInfo(desktopTelemetryEventNames.DESKTOP_EXTENSION_INIT_CONTEXT, initContext); } }) ); From f0e11834621bf7de6083b00333d87e3ec78daa8f Mon Sep 17 00:00:00 2001 From: Shivika Gupta Date: Thu, 8 Aug 2024 17:09:57 +0530 Subject: [PATCH 5/5] Adding null check --- src/client/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/extension.ts b/src/client/extension.ts index f5bfd04d..df44d599 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -196,7 +196,7 @@ export async function activate( const pacActiveAuth = await pacTerminal.getWrapper()?.activeAuth(); let AadIdObject; if ((pacActiveAuth && pacActiveAuth.Status === SUCCESS)) { - AadIdObject = pacActiveAuth.Results.filter(obj => obj.Key === AadIdKey); + AadIdObject = pacActiveAuth.Results?.filter(obj => obj.Key === AadIdKey); } const { geoName, geoLongName } = artemisResponse.response; oneDSLoggerWrapper.instantiate(geoName, geoLongName);