Skip to content

Commit

Permalink
handle optional cluster category
Browse files Browse the repository at this point in the history
  • Loading branch information
OEvgeny committed Aug 8, 2023
1 parent 2819d1c commit cef0ea1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const PVA_GOV_APP_ID = '9315aedd-209b-43b3-b149-2abff6a95d59';
export const PVA_GCC_HIGH_APP_ID = '69c6e40c-465f-4154-987d-da5cba10734e';

export type PowerVirtualAgentsMetadata = IContentProviderMetadata & {
clusterCategory:
clusterCategory?:
| 'Dev'
| 'Prv'
| 'Test'
Expand Down Expand Up @@ -199,7 +199,7 @@ export class PowerVirtualAgentsProvider extends ExternalContentProvider<PowerVir
)}]`;
}
if (clusterCategory) {
deepLink += dialogId && triggerId ? '&' : '?' + `cluster=${clusterCategory}`;
deepLink += deepLink.includes('?') ? '&' : '?' + `cluster=${clusterCategory}`;
}
// base64 encode to make parsing on the client side easier
return Buffer.from(deepLink, 'utf-8').toString('base64');
Expand Down
12 changes: 8 additions & 4 deletions extensions/pvaPublish/src/node/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const publish = async (
envId,
tenantId,
deleteMissingDependencies = false, // publish behavior
clusterCategory,
} = config;
const { comment = '' } = metadata;

Expand All @@ -45,7 +46,7 @@ export const publish = async (
if (!base) {
throw new Error('Base URL is not supplied in published target');
}
const creds = getAuthCredentials(base, tenantId);
const creds = getAuthCredentials(base, tenantId, clusterCategory);
const accessToken = await getAccessToken(creds);

// write the .zip to a buffer in memory
Expand Down Expand Up @@ -148,6 +149,7 @@ export const getStatus = async (
botId,
envId,
tenantId,
clusterCategory,
} = config;
const botProjectId = project.id || '';

Expand All @@ -168,7 +170,7 @@ export const getStatus = async (
if (!base) {
throw new Error('Base URL is not supplied in published target');
}
const creds = getAuthCredentials(base, tenantId);
const creds = getAuthCredentials(base, tenantId, clusterCategory);
const accessToken = await getAccessToken(creds);

// check the status for the publish job
Expand Down Expand Up @@ -224,12 +226,13 @@ export const history = async (
botId,
envId,
tenantId,
clusterCategory,
} = config;

try {
// authenticate with PVA
const base = baseUrl;
const creds = getAuthCredentials(base, tenantId);
const creds = getAuthCredentials(base, tenantId, clusterCategory);
const accessToken = await getAccessToken(creds);

// get the publish history for the bot
Expand Down Expand Up @@ -259,11 +262,12 @@ export const pull = async (
botId,
envId,
tenantId,
clusterCategory,
} = config;
try {
// authenticate with PVA
const base = baseUrl;
const creds = getAuthCredentials(base, tenantId);
const creds = getAuthCredentials(base, tenantId, clusterCategory);
const accessToken = await getAccessToken(creds);

// fetch zip containing bot content
Expand Down
10 changes: 6 additions & 4 deletions extensions/pvaPublish/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import { ClusterCategory } from './types';
export const getAuthCredentials = (baseUrl = '', tenantId?: string, clusterCategory?: ClusterCategory) => {
const host = new URL(baseUrl).host;
clusterCategory = (process.env.COMPOSER_PVA_CLUSTER as ClusterCategory) ?? clusterCategory;
if (['Test', 'Preprod', 'Dev'].includes(clusterCategory) || host === 'bots.int.customercareintelligence.net') {
logger.log('Using INT / PPE auth credentials.');
return AUTH_CREDENTIALS.INT;
} else if (host === 'bots.ppe.customercareintelligence.net') {
if (
['Test', 'Preprod', 'Dev'].includes(clusterCategory) ||
host.includes('.int.') ||
host.includes('.ppe.') ||
host.includes('.test.')
) {
logger.log('Using INT / PPE auth credentials.');
return AUTH_CREDENTIALS.INT;
} else if (['Gov'].includes(clusterCategory) || host === 'gcc.api.powerva.microsoft.us') {
Expand Down

0 comments on commit cef0ea1

Please sign in to comment.