5
5
6
6
import {
7
7
OpenSearchClient ,
8
+ OpenSearchDashboardsRequest ,
8
9
SavedObjectsBulkCreateObject ,
9
10
SavedObjectsBulkResponse ,
10
11
SavedObjectsBulkUpdateObject ,
@@ -51,7 +52,10 @@ export class DataSourceSavedObjectsClientWrapper {
51
52
return await wrapperOptions . client . create ( type , attributes , options ) ;
52
53
}
53
54
54
- const encryptedAttributes = await this . validateAndEncryptAttributes ( attributes ) ;
55
+ const encryptedAttributes = await this . validateAndEncryptAttributes (
56
+ attributes ,
57
+ wrapperOptions . request
58
+ ) ;
55
59
56
60
return await wrapperOptions . client . create ( type , encryptedAttributes , options ) ;
57
61
} ;
@@ -70,7 +74,7 @@ export class DataSourceSavedObjectsClientWrapper {
70
74
71
75
return {
72
76
...object ,
73
- attributes : await this . validateAndEncryptAttributes ( attributes ) ,
77
+ attributes : await this . validateAndEncryptAttributes ( attributes , wrapperOptions . request ) ,
74
78
} ;
75
79
} )
76
80
) ;
@@ -152,8 +156,11 @@ export class DataSourceSavedObjectsClientWrapper {
152
156
private endpointBlockedIps ?: string [ ]
153
157
) { }
154
158
155
- private async validateAndEncryptAttributes < T = unknown > ( attributes : T ) {
156
- await this . validateAttributes ( attributes ) ;
159
+ private async validateAndEncryptAttributes < T = unknown > (
160
+ attributes : T ,
161
+ request ?: OpenSearchDashboardsRequest
162
+ ) {
163
+ await this . validateAttributes ( attributes , request ) ;
157
164
158
165
const { endpoint, auth } = attributes ;
159
166
@@ -257,11 +264,14 @@ export class DataSourceSavedObjectsClientWrapper {
257
264
}
258
265
}
259
266
260
- private async validateAttributes < T = unknown > ( attributes : T ) {
267
+ private async validateAttributes < T = unknown > (
268
+ attributes : T ,
269
+ request ?: OpenSearchDashboardsRequest
270
+ ) {
261
271
const { title, endpoint, auth } = attributes ;
262
272
263
273
this . validateTitle ( title ) ;
264
- await this . validateEndpoint ( endpoint , attributes as DataSourceAttributes ) ;
274
+ await this . validateEndpoint ( endpoint , attributes as DataSourceAttributes , request ) ;
265
275
await this . validateAuth ( auth ) ;
266
276
}
267
277
@@ -279,7 +289,11 @@ export class DataSourceSavedObjectsClientWrapper {
279
289
}
280
290
}
281
291
282
- private async validateEndpoint ( endpoint : string , attributes : DataSourceAttributes ) {
292
+ private async validateEndpoint (
293
+ endpoint : string ,
294
+ attributes : DataSourceAttributes ,
295
+ request ?: OpenSearchDashboardsRequest
296
+ ) {
283
297
if ( ! isValidURL ( endpoint , this . endpointBlockedIps ) ) {
284
298
throw SavedObjectsErrorHelpers . createBadRequestError (
285
299
'"endpoint" attribute is not valid or allowed'
@@ -290,6 +304,7 @@ export class DataSourceSavedObjectsClientWrapper {
290
304
savedObjects : { } as any ,
291
305
cryptography : this . cryptography ,
292
306
testClientDataSourceAttr : attributes as DataSourceAttributes ,
307
+ request,
293
308
authRegistry : await this . authRegistryPromise ,
294
309
customApiSchemaRegistryPromise : this . customApiSchemaRegistryPromise ,
295
310
} ) ;
@@ -298,6 +313,7 @@ export class DataSourceSavedObjectsClientWrapper {
298
313
299
314
await dataSourceValidator . validate ( ) ;
300
315
} catch ( err : any ) {
316
+ this . logger . error ( err ) ;
301
317
throw SavedObjectsErrorHelpers . createBadRequestError (
302
318
`endpoint is not valid OpenSearch endpoint`
303
319
) ;
0 commit comments