From 2bc1e6117bffdf3fe588e6ff9ac5537f9381b6a1 Mon Sep 17 00:00:00 2001 From: Ashwani Kumar Date: Tue, 10 Dec 2024 16:12:52 +0530 Subject: [PATCH] added endpoints for soverign clouds for PPAPI service --- l10n/bundle.l10n.json | 2 +- loc/translations-export/vscode-powerplatform.xlf | 6 +++--- src/common/services/AuthenticationProvider.ts | 15 +++++++++++++-- src/common/services/Constants.ts | 3 +++ src/common/services/PPAPIService.ts | 10 ++++++++-- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 36ca2d22..d140c666 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -83,9 +83,9 @@ "Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.": "Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.", "Checking for active auth profile...": "Checking for active auth profile...", "@PowerPages is not yet available in your region.": "@PowerPages is not yet available in your region.", - "Failed to get site content from NL2Site service": "Failed to get site content from NL2Site service", "Generating webpages...": "Generating webpages...", "Generating a new Power Pages site...": "Generating a new Power Pages site...", + "Failed to create a new Power Pages site. Please try again.": "Failed to create a new Power Pages site. Please try again.", "Select Folder for new PCF Control/Do not translate 'PCF' as it is a product name.": { "message": "Select Folder for new PCF Control", "comment": [ diff --git a/loc/translations-export/vscode-powerplatform.xlf b/loc/translations-export/vscode-powerplatform.xlf index 5cba25db..6c16086c 100644 --- a/loc/translations-export/vscode-powerplatform.xlf +++ b/loc/translations-export/vscode-powerplatform.xlf @@ -143,6 +143,9 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca Explain the following code {% include 'Page Copy'%} + + Failed to create a new Power Pages site. Please try again. + Failed to create: {0}. {0} will be replaced by the error message. @@ -159,9 +162,6 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca Failed to get file ready for edit: {0} - - Failed to get site content from NL2Site service - Feature is not enabled for this geo. diff --git a/src/common/services/AuthenticationProvider.ts b/src/common/services/AuthenticationProvider.ts index 34c3bdb6..c083af3d 100644 --- a/src/common/services/AuthenticationProvider.ts +++ b/src/common/services/AuthenticationProvider.ts @@ -23,10 +23,21 @@ import { VSCODE_EXTENSION_PPAPI_WEBSITES_AUTHENTICATION_FAILED } from "./TelemetryConstants"; import { ERROR_CONSTANTS } from "../ErrorConstants"; -import { BAP_SERVICE_SCOPE_DEFAULT, INTELLIGENCE_SCOPE_DEFAULT, PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, PROVIDER_ID, SCOPE_OPTION_CONTACTS_READ, SCOPE_OPTION_DEFAULT, SCOPE_OPTION_OFFLINE_ACCESS, SCOPE_OPTION_USERS_READ_BASIC_ALL, ServiceEndpointCategory } from "./Constants"; +import { BAP_SERVICE_SCOPE_DEFAULT, INTELLIGENCE_SCOPE_DEFAULT, PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT, PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, PROVIDER_ID, SCOPE_OPTION_CONTACTS_READ, SCOPE_OPTION_DEFAULT, SCOPE_OPTION_OFFLINE_ACCESS, SCOPE_OPTION_USERS_READ_BASIC_ALL, ServiceEndpointCategory } from "./Constants"; import jwt_decode from 'jwt-decode'; import { showErrorDialog } from "../utilities/errorHandlerUtil"; +const serviceScopeMapping: { [key in ServiceEndpointCategory]: string } = { + [ServiceEndpointCategory.NONE]: "", + [ServiceEndpointCategory.PROD]: PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.PREPROD]: PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.TEST]: PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.MOONCAKE]: PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.GCC]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.DOD]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, + [ServiceEndpointCategory.HIGH]: PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT, +}; + export function getCommonHeadersForDataverse( accessToken: string, useOctetStreamContentType?: boolean @@ -300,7 +311,7 @@ export async function powerPlatformAPIAuthentication( firstTimeAuth = false ): Promise { let accessToken = ""; - const PPAPI_WEBSITES_ENDPOINT = [ServiceEndpointCategory.TEST, ServiceEndpointCategory.PREPROD].includes(serviceEndpointStamp) ? PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT : PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT; + const PPAPI_WEBSITES_ENDPOINT = serviceScopeMapping[serviceEndpointStamp]; try { let session = await vscode.authentication.getSession( PROVIDER_ID, diff --git a/src/common/services/Constants.ts b/src/common/services/Constants.ts index a77791ab..91119527 100644 --- a/src/common/services/Constants.ts +++ b/src/common/services/Constants.ts @@ -23,6 +23,9 @@ export const BAP_ENVIRONMENT_LIST_URL = `scopes/admin/environments?api-version={ export const PPAPI_WEBSITES_API_VERSION = '2022-03-01-preview'; export const PPAPI_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.com/.default"; export const PPAPI_PREPROD_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.preprod.powerplatform.com/.default"; +export const PPAPI_TEST_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.test.powerplatform.com/.default"; +export const PPAPI_MOONCAKE_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.cn/.default"; +export const PPAPI_GCC_HIGH_DOD_WEBSITES_SERVICE_SCOPE_DEFAULT = "https://api.powerplatform.us/.default"; export const PPAPI_WEBSITES_ENDPOINT = `{rootURL}/powerpages/environments/{environmentId}/websites`; export enum ServiceEndpointCategory { diff --git a/src/common/services/PPAPIService.ts b/src/common/services/PPAPIService.ts index 2079ff11..891cea03 100644 --- a/src/common/services/PPAPIService.ts +++ b/src/common/services/PPAPIService.ts @@ -47,11 +47,17 @@ export class PPAPIService { case ServiceEndpointCategory.PROD: ppapiEndpoint = "https://api.powerplatform.com"; break; - // All below endpoints are not supported yet case ServiceEndpointCategory.DOD: + ppapiEndpoint = "https://api.powerplatform.us"; + break; case ServiceEndpointCategory.GCC: - case ServiceEndpointCategory.HIGH: + ppapiEndpoint = "https://api.powerplatform.us"; + break; case ServiceEndpointCategory.MOONCAKE: + ppapiEndpoint = "https://api.powerplatform.cn"; + break; + // Below endpoints are not supported yet + case ServiceEndpointCategory.HIGH: default: sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_GET_PPAPI_WEBSITES_ENDPOINT_UNSUPPORTED_REGION, data: serviceEndpointStamp }); break;