1
1
import { isPrd } from '../../Common/AzureEnv' ;
2
2
import { getIpsRange } from '../../VNet/Helper' ;
3
+ import { organization } from '../../Common/StackEnv' ;
3
4
4
5
const defaultRateLimit = isPrd ? 60 : 120 ;
5
6
const enableApimEventHub = false ;
@@ -85,16 +86,20 @@ const getInClientCertValidate = ({
85
86
verifyCert,
86
87
} : ClientCertProps ) =>
87
88
` <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
+ : ''
98
103
} )" >
99
104
<return-response>
100
105
<set-status code="403" reason="Invalid client certificate" />
@@ -141,7 +146,8 @@ const getEventHubPolicy = ({
141
146
142
147
const rs = `
143
148
<set-variable name="message-id" value="@(Guid.NewGuid())" />
144
- ${ enableIpStack
149
+ ${
150
+ enableIpStack
145
151
? `
146
152
<set-variable name="ipstackBaseUrl" value="@("${ azFuncUrl } ?ipAddress=" + context.Request.IpAddress)" />
147
153
<send-request mode="new" response-variable-name="ipstackResponse" timeout="2" ignore-error="true">
@@ -152,7 +158,7 @@ const getEventHubPolicy = ({
152
158
</set-header>
153
159
</send-request>`
154
160
: ''
155
- }
161
+ }
156
162
157
163
<log-to-eventhub logger-id="${ eventHubName } " partition-id="0">@{
158
164
string accountId = "";
@@ -180,20 +186,22 @@ const getEventHubPolicy = ({
180
186
}
181
187
182
188
string ipLocation = "";
183
- ${ enableIpStack
184
- ? `
189
+ ${
190
+ enableIpStack
191
+ ? `
185
192
try {
186
193
var ipstackResponse = ((IResponse)context.Variables["ipstackResponse"]);
187
194
if (ipstackResponse.StatusCode == 200) {
188
195
ipLocation = (((IResponse)context.Variables["ipstackResponse"]).Body?.As<JObject>()["country_name"]).ToString();
189
196
}
190
197
}catch {}`
191
- : ''
192
- }
198
+ : ''
199
+ }
193
200
194
201
string clientThumbprint = "";
195
- ${ captureClientCertThumbprint
196
- ? `
202
+ ${
203
+ captureClientCertThumbprint
204
+ ? `
197
205
string xCert = context.Request.Headers.GetValueOrDefault("X-ARR-ClientCert", "");
198
206
if(context.Request.Certificate != null){
199
207
clientThumbprint = context.Request.Certificate.Thumbprint;
@@ -203,8 +211,8 @@ ${captureClientCertThumbprint
203
211
}
204
212
else{ clientThumbprint = "Not found";}
205
213
`
206
- : ''
207
- }
214
+ : ''
215
+ }
208
216
209
217
return new JObject(
210
218
new JProperty("MessageId", context.Variables["message-id"]),
@@ -335,9 +343,11 @@ interface CheckHeaders {
335
343
const checkHeaderPolicy = ( { checkHeaders } : CheckHeaders ) => {
336
344
return checkHeaders
337
345
. 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">
341
351
${ c . value ? c . value . map ( ( v ) => `<value>${ v } </value>` ) . join ( '\n' ) : '' }
342
352
</check-header>` ;
343
353
} )
@@ -398,7 +408,8 @@ export const getPolicies = ({
398
408
const inbound = new Array < string > ( ) ;
399
409
const outbound = new Array < string > ( ) ;
400
410
401
- const getProps = < T > ( p : T ) => ( typeof p === 'boolean' ? { } : p ) ;
411
+ const getProps = < T > ( p : T | boolean ) =>
412
+ ( typeof p === 'boolean' ? { } : p ) as T ;
402
413
403
414
if ( enableClientIpHeader ) {
404
415
inbound . push ( setClientIpHeader ( ) ) ;
@@ -505,27 +516,29 @@ export const getPolicies = ({
505
516
<set-header name="X-AspNet-Version" exists-action="delete" />
506
517
507
518
${ 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
+ }
517
529
</outbound>
518
530
<on-error>
519
531
<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
+ }
529
542
</on-error>
530
543
</policies>` ;
531
544
} ;
0 commit comments