Skip to content

Commit

Permalink
Add sovereign cloud endpoints for PPAPI service
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu92 committed Dec 17, 2024
1 parent 1af6cf5 commit 8e7f72f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
"Cancel": "Cancel",
"Site runtime preview feature is not enabled.": "Site runtime preview feature is not enabled.",
"No workspace folder opened. Please open a site folder to preview.": "No workspace folder opened. Please open a site folder to preview.",
"Initializing site preview. Please try again after few seconds.": "Initializing site preview. Please try again after few seconds.",
"Website URL not found.": "Website URL not found.",
"Opening site preview...": "Opening site preview...",
"File might be referenced by name {0} here./{0} represents the name of the file": {
Expand Down
3 changes: 3 additions & 0 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ Return to this chat and @powerpages can help you write and edit your website cod
<trans-unit id="++CODE++08295f3385931e35c850b945e2ae04882452c4bf0dd575f70e95aaa6ed00daa9">
<source xml:lang="en">In your own words, describe what you need. You can get help with writing code for Power Pages sites in HTML, CSS, and JS languages.</source>
</trans-unit>
<trans-unit id="++CODE++15b09c32b0337229ff64c72f2ea9a3f8422fa20975ae494da863fd738554b1de">
<source xml:lang="en">Initializing site preview. Please try again after few seconds.</source>
</trans-unit>
<trans-unit id="++CODE++e992151b1efc99f93484c7d7f3076b66ab072a8af2383e96104cc597c971339c">
<source xml:lang="en">Insert code into editor</source>
</trans-unit>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
},
{
"command": "microsoft.powerplatform.pages.preview-site",
"category": "Powerpages",
"title": "%powerplatform.pages.previewSite.title%"
}
],
Expand Down
6 changes: 3 additions & 3 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export async function activate(
) || [];


let websiteURL: string | undefined = "";
let websiteURL: string | undefined = undefined;
const isSiteRuntimePreviewEnabled = PreviewSite.isSiteRuntimePreviewEnabled();

vscode.commands.executeCommand("setContext", "microsoft.powerplatform.pages.siteRuntimePreviewEnabled", isSiteRuntimePreviewEnabled);
Expand Down Expand Up @@ -282,11 +282,11 @@ export async function activate(

_telemetry.sendTelemetryEvent("EnableSiteRuntimePreview", {
isEnabled: isSiteRuntimePreviewEnabled.toString(),
websiteURL: websiteURL
websiteURL: websiteURL || "undefined"
});
oneDSLoggerWrapper.getLogger().traceInfo("EnableSiteRuntimePreview", {
isEnabled: isSiteRuntimePreviewEnabled.toString(),
websiteURL: websiteURL
websiteURL: websiteURL || "undefined"
});

_context.subscriptions.push(
Expand Down
7 changes: 6 additions & 1 deletion src/client/runtime-site-preview/PreviewSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ export class PreviewSite {
return;
}

if (!websiteURL || websiteURL === "") {
if (websiteURL === undefined) {
await vscode.window.showWarningMessage(vscode.l10n.t("Initializing site preview. Please try again after few seconds."));
return;
}

if (websiteURL === "") {
await vscode.window.showErrorMessage(vscode.l10n.t("Website URL not found."));
return;
}
Expand Down
29 changes: 27 additions & 2 deletions src/common/services/AuthenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,35 @@ 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
Expand Down Expand Up @@ -300,7 +325,7 @@ export async function powerPlatformAPIAuthentication(
firstTimeAuth = false
): Promise<string> {
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,
Expand Down
3 changes: 3 additions & 0 deletions src/common/services/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions src/common/services/PPAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,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;
Expand Down

0 comments on commit 8e7f72f

Please sign in to comment.