Skip to content

Commit 3625b01

Browse files
committed
update
1 parent e67a916 commit 3625b01

File tree

7 files changed

+92
-290
lines changed

7 files changed

+92
-290
lines changed

Apim/ApiProduct/PolicyBuilder.ts

+55-42
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isPrd } from '../../Common/AzureEnv';
22
import { getIpsRange } from '../../VNet/Helper';
3+
import { organization } from '../../Common/StackEnv';
34

45
const defaultRateLimit = isPrd ? 60 : 120;
56
const enableApimEventHub = false;
@@ -85,16 +86,20 @@ const getInClientCertValidate = ({
8586
verifyCert,
8687
}: ClientCertProps) =>
8788
` <choose>
88-
<when condition="@(context.Request.Certificate == null${verifyCert
89-
? ' || !context.Request.Certificate.VerifyNoRevocation()'
90-
: ''
91-
}${issuer ? ` || context.Request.Certificate.Issuer != "${issuer}"` : ''
92-
}${subject
93-
? ` || context.Request.Certificate.SubjectName.Name != "${subject}"`
94-
: ''
95-
}${thumbprint
96-
? ` || context.Request.Certificate.Thumbprint != "${thumbprint}"`
97-
: ''
89+
<when condition="@(context.Request.Certificate == null${
90+
verifyCert
91+
? ' || !context.Request.Certificate.VerifyNoRevocation()'
92+
: ''
93+
}${
94+
issuer ? ` || context.Request.Certificate.Issuer != "${issuer}"` : ''
95+
}${
96+
subject
97+
? ` || context.Request.Certificate.SubjectName.Name != "${subject}"`
98+
: ''
99+
}${
100+
thumbprint
101+
? ` || context.Request.Certificate.Thumbprint != "${thumbprint}"`
102+
: ''
98103
})" >
99104
<return-response>
100105
<set-status code="403" reason="Invalid client certificate" />
@@ -141,7 +146,8 @@ const getEventHubPolicy = ({
141146

142147
const rs = `
143148
<set-variable name="message-id" value="@(Guid.NewGuid())" />
144-
${enableIpStack
149+
${
150+
enableIpStack
145151
? `
146152
<set-variable name="ipstackBaseUrl" value="@("${azFuncUrl}?ipAddress=" + context.Request.IpAddress)" />
147153
<send-request mode="new" response-variable-name="ipstackResponse" timeout="2" ignore-error="true">
@@ -152,7 +158,7 @@ const getEventHubPolicy = ({
152158
</set-header>
153159
</send-request>`
154160
: ''
155-
}
161+
}
156162
157163
<log-to-eventhub logger-id="${eventHubName}" partition-id="0">@{
158164
string accountId = "";
@@ -180,20 +186,22 @@ const getEventHubPolicy = ({
180186
}
181187
182188
string ipLocation = "";
183-
${enableIpStack
184-
? `
189+
${
190+
enableIpStack
191+
? `
185192
try {
186193
var ipstackResponse = ((IResponse)context.Variables["ipstackResponse"]);
187194
if (ipstackResponse.StatusCode == 200) {
188195
ipLocation = (((IResponse)context.Variables["ipstackResponse"]).Body?.As<JObject>()["country_name"]).ToString();
189196
}
190197
}catch {}`
191-
: ''
192-
}
198+
: ''
199+
}
193200
194201
string clientThumbprint = "";
195-
${captureClientCertThumbprint
196-
? `
202+
${
203+
captureClientCertThumbprint
204+
? `
197205
string xCert = context.Request.Headers.GetValueOrDefault("X-ARR-ClientCert", "");
198206
if(context.Request.Certificate != null){
199207
clientThumbprint = context.Request.Certificate.Thumbprint;
@@ -203,8 +211,8 @@ ${captureClientCertThumbprint
203211
}
204212
else{ clientThumbprint = "Not found";}
205213
`
206-
: ''
207-
}
214+
: ''
215+
}
208216
209217
return new JObject(
210218
new JProperty("MessageId", context.Variables["message-id"]),
@@ -335,9 +343,11 @@ interface CheckHeaders {
335343
const checkHeaderPolicy = ({ checkHeaders }: CheckHeaders) => {
336344
return checkHeaders
337345
.map((c) => {
338-
return `<check-header name="${c.name
339-
}" failed-check-httpcode="401" failed-check-error-message="The header ${c.name
340-
} is not found" ignore-case="true">
346+
return `<check-header name="${
347+
c.name
348+
}" failed-check-httpcode="401" failed-check-error-message="The header ${
349+
c.name
350+
} is not found" ignore-case="true">
341351
${c.value ? c.value.map((v) => `<value>${v}</value>`).join('\n') : ''}
342352
</check-header>`;
343353
})
@@ -398,7 +408,8 @@ export const getPolicies = ({
398408
const inbound = new Array<string>();
399409
const outbound = new Array<string>();
400410

401-
const getProps = <T>(p: T) => (typeof p === 'boolean' ? {} : p);
411+
const getProps = <T>(p: T | boolean) =>
412+
(typeof p === 'boolean' ? {} : p) as T;
402413

403414
if (enableClientIpHeader) {
404415
inbound.push(setClientIpHeader());
@@ -505,27 +516,29 @@ export const getPolicies = ({
505516
<set-header name="X-AspNet-Version" exists-action="delete" />
506517
507518
${outbound.join('\n')}
508-
${enableApimEventHub && props.logEventHubName
509-
? getEventHubPolicy({
510-
eventHubName: props.logEventHubName,
511-
azFuncUrl: props.azFuncUrl,
512-
azFuncKey: props.azFuncKey,
513-
captureClientCertThumbprint: props.captureClientCertThumbprint,
514-
})
515-
: ''
516-
}
519+
${
520+
enableApimEventHub && props.logEventHubName
521+
? getEventHubPolicy({
522+
eventHubName: props.logEventHubName,
523+
azFuncUrl: props.azFuncUrl,
524+
azFuncKey: props.azFuncKey,
525+
captureClientCertThumbprint: props.captureClientCertThumbprint,
526+
})
527+
: ''
528+
}
517529
</outbound>
518530
<on-error>
519531
<base />
520-
${enableApimEventHub && props.logEventHubName
521-
? getEventHubPolicy({
522-
eventHubName: props.logEventHubName,
523-
azFuncUrl: props.azFuncUrl,
524-
azFuncKey: props.azFuncKey,
525-
captureClientCertThumbprint: props.captureClientCertThumbprint,
526-
})
527-
: ''
528-
}
532+
${
533+
enableApimEventHub && props.logEventHubName
534+
? getEventHubPolicy({
535+
eventHubName: props.logEventHubName,
536+
azFuncUrl: props.azFuncUrl,
537+
azFuncKey: props.azFuncKey,
538+
captureClientCertThumbprint: props.captureClientCertThumbprint,
539+
})
540+
: ''
541+
}
529542
</on-error>
530543
</policies>`;
531544
};

KubeX/Apps/Hoppscotch.ts

-191
This file was deleted.

0 commit comments

Comments
 (0)