Skip to content

Commit 9673a07

Browse files
committed
fix: support custom-host for azure plugin to support privatelink
1 parent 67efbb2 commit 9673a07

File tree

7 files changed

+62
-12
lines changed

7 files changed

+62
-12
lines changed

package-lock.json

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"hono": "^4.6.10",
5454
"jose": "^6.0.11",
5555
"patch-package": "^8.0.0",
56+
"undici": "^7.10.0",
5657
"ws": "^8.18.0",
5758
"zod": "^3.22.4"
5859
},

plugins/azure/contentSafety.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Agent } from 'undici';
12
import {
23
HookEventType,
34
PluginContext,
@@ -63,7 +64,7 @@ export const handler: PluginHandler<{
6364

6465
const apiVersion = parameters.apiVersion || '2024-11-01';
6566

66-
const url = `https://${credentials.resourceName}.cognitiveservices.azure.com/contentsafety/text:analyze?api-version=${apiVersion}`;
67+
const url = `${credentials.customHost || `https://${credentials.resourceName}.cognitiveservices.azure.com`}/contentsafety/text:analyze?api-version=${apiVersion}`;
6768

6869
const { token, error: tokenError } = await getAccessToken(
6970
credentials as any,
@@ -80,6 +81,16 @@ export const handler: PluginHandler<{
8081
};
8182
}
8283

84+
let agent: Agent | null = null;
85+
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost.
86+
if (credentials.customHost) {
87+
agent = new Agent({
88+
connect: {
89+
rejectUnauthorized: false,
90+
},
91+
});
92+
}
93+
8394
const headers: Record<string, string> = {
8495
'Content-Type': 'application/json',
8596
'User-Agent': 'portkey-ai-plugin/',
@@ -100,7 +111,12 @@ export const handler: PluginHandler<{
100111
const timeout = parameters.timeout || 5000;
101112
let response;
102113
try {
103-
response = await post(url, request, { headers }, timeout);
114+
response = await post(
115+
url,
116+
request,
117+
{ headers, dispatcher: agent },
118+
timeout
119+
);
104120
} catch (e) {
105121
return { error: e, verdict: true, data };
106122
}

plugins/azure/manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@
123123
"tenantId": {
124124
"type": "string",
125125
"description": "Tenant ID for Azure Entra ID authentication"
126+
},
127+
"customHost": {
128+
"type": "string",
129+
"description": "Custom host for Azure AI services (Private Link etc.)"
126130
}
127131
},
128132
"anyOf": [

plugins/azure/pii.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Agent } from 'undici';
12
import {
23
HookEventType,
34
PluginContext,
@@ -29,7 +30,7 @@ const redact = async (
2930

3031
const apiVersion = parameters.apiVersion || '2024-11-01';
3132

32-
const url = `https://${credentials?.resourceName}.cognitiveservices.azure.com/language/:analyze-text?api-version=${apiVersion}`;
33+
const url = `${credentials?.customHost || `https://${credentials?.resourceName}.cognitiveservices.azure.com`}/language/:analyze-text?api-version=${apiVersion}`;
3334

3435
const { token, error: tokenError } = await getAccessToken(
3536
credentials as any,
@@ -53,8 +54,23 @@ const redact = async (
5354
throw new Error('Unable to get access token');
5455
}
5556

57+
let agent: Agent | null = null;
58+
// privatelink doesn't contain a valid certificate, skipping verification if it's customHost.
59+
if (credentials?.customHost) {
60+
agent = new Agent({
61+
connect: {
62+
rejectUnauthorized: false,
63+
},
64+
});
65+
}
66+
5667
const timeout = parameters.timeout || 5000;
57-
const response = await post(url, body, { headers }, timeout);
68+
const response = await post(
69+
url,
70+
body,
71+
{ headers, dispatcher: agent },
72+
timeout
73+
);
5874
return response;
5975
};
6076

plugins/azure/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export interface AzureCredentials {
55
clientId?: string;
66
clientSecret?: string;
77
tenantId?: string;
8+
customHost?: string;
89
}

plugins/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { HookEventType, PluginContext } from './types';
22

33
interface PostOptions extends RequestInit {
44
headers?: Record<string, string>;
5+
[key: string]: any;
56
}
67

78
export interface ErrorResponse {

0 commit comments

Comments
 (0)