@@ -5,12 +5,7 @@ import {
5
5
ZstdCompressorCallback ,
6
6
} from "./http/http" ;
7
7
import { IsomorphicFetchHttpLibrary as DefaultHttpLibrary } from "./http/isomorphic-fetch" ;
8
- import {
9
- BaseServerConfiguration ,
10
- server1 ,
11
- servers ,
12
- operationServers ,
13
- } from "./servers" ;
8
+ import { BaseServerConfiguration , server1 , servers } from "./servers" ;
14
9
import {
15
10
configureAuthMethods ,
16
11
AuthMethods ,
@@ -21,7 +16,11 @@ import { logger } from "./logger";
21
16
export class Configuration {
22
17
readonly baseServer ?: BaseServerConfiguration ;
23
18
readonly serverIndex : number ;
19
+ readonly serverVariables : { [ key : string ] : string } ;
24
20
readonly operationServerIndices : { [ name : string ] : number } ;
21
+ readonly operationServerVariables : {
22
+ [ name : string ] : { [ key : string ] : string } ;
23
+ } ;
25
24
readonly httpApi : HttpLibrary ;
26
25
readonly authMethods : AuthMethods ;
27
26
readonly httpConfig : HttpConfiguration ;
@@ -37,7 +36,9 @@ export class Configuration {
37
36
public constructor (
38
37
baseServer : BaseServerConfiguration | undefined ,
39
38
serverIndex : number ,
39
+ serverVariables : { [ key : string ] : string } ,
40
40
operationServerIndices : { [ name : string ] : number } ,
41
+ operationServerVariables : { [ name : string ] : { [ key : string ] : string } } ,
41
42
httpApi : HttpLibrary ,
42
43
authMethods : AuthMethods ,
43
44
httpConfig : HttpConfiguration ,
@@ -50,7 +51,9 @@ export class Configuration {
50
51
) {
51
52
this . baseServer = baseServer ;
52
53
this . serverIndex = serverIndex ;
54
+ this . serverVariables = serverVariables ;
53
55
this . operationServerIndices = operationServerIndices ;
56
+ this . operationServerVariables = operationServerVariables ;
54
57
this . httpApi = httpApi ;
55
58
this . authMethods = authMethods ;
56
59
this . httpConfig = httpConfig ;
@@ -65,46 +68,38 @@ export class Configuration {
65
68
this . servers . push ( server . clone ( ) ) ;
66
69
}
67
70
this . operationServers = { } ;
68
- for ( const endpoint in operationServers ) {
69
- this . operationServers [ endpoint ] = [ ] ;
70
- for ( const server of operationServers [ endpoint ] ) {
71
- this . operationServers [ endpoint ] . push ( server . clone ( ) ) ;
72
- }
73
- }
74
71
if ( backoffBase && backoffBase < 2 ) {
75
72
throw new Error ( "Backoff base must be at least 2" ) ;
76
73
}
77
74
}
78
75
79
- setServerVariables ( serverVariables : { [ key : string ] : string } ) : void {
76
+ getServerAndOverrides ( key : string ) : {
77
+ server : BaseServerConfiguration ;
78
+ overrides ?: { [ key : string ] : string } ;
79
+ } {
80
80
if ( this . baseServer !== undefined ) {
81
- this . baseServer . setVariables ( serverVariables ) ;
82
- return ;
81
+ return { server : this . baseServer , overrides : this . serverVariables } ;
83
82
}
84
83
85
- const index = this . serverIndex ;
86
- this . servers [ index ] . setVariables ( serverVariables ) ;
87
-
88
- for ( const op in this . operationServers ) {
89
- const index =
90
- op in this . operationServerIndices
91
- ? this . operationServerIndices [ op ]
92
- : this . serverIndex ;
93
- this . operationServers [ op ] [ index ] . setVariables ( serverVariables ) ;
84
+ let server : BaseServerConfiguration ;
85
+ let overrides : { [ key : string ] : string } | undefined ;
86
+ if ( key in this . operationServers ) {
87
+ const index = this . operationServerIndices [ key ] || 0 ;
88
+ server = this . operationServers [ key ] [ index ] ;
89
+ overrides = this . operationServerVariables [ key ] ;
90
+ } else {
91
+ const index = this . serverIndex ;
92
+ server = this . servers [ index ] ;
93
+ overrides = this . serverVariables ;
94
94
}
95
+
96
+ return { server, overrides } ;
95
97
}
96
98
97
- getServer ( endpoint : string ) : BaseServerConfiguration {
98
- if ( this . baseServer !== undefined ) {
99
- return this . baseServer ;
100
- }
101
- const index =
102
- endpoint in this . operationServerIndices
103
- ? this . operationServerIndices [ endpoint ]
104
- : this . serverIndex ;
105
- return endpoint in operationServers
106
- ? this . operationServers [ endpoint ] [ index ]
107
- : this . servers [ index ] ;
99
+ addOperationServers ( operationServers : {
100
+ [ key : string ] : BaseServerConfiguration [ ] ;
101
+ } ) : void {
102
+ this . operationServers = { ...operationServers , ...this . operationServers } ;
108
103
}
109
104
}
110
105
@@ -121,9 +116,31 @@ export interface ConfigurationParameters {
121
116
*/
122
117
serverIndex ?: number ;
123
118
/**
124
- * Default index of a server to use for an operation from the predefined server operation map
119
+ * Default server variables to override the default server variables
120
+ * Example:
121
+ * ```
122
+ * {
123
+ * "site": "datadoghq.com",
124
+ * }
125
+ */
126
+ serverVariables ?: { [ name : string ] : string } ;
127
+ /**
128
+ * Default index of a server to use for an operation from the API server list
129
+ * Key is the `{ApiName}.{ApiVersion}.{OperationName}`, value is the index of the server to use. Example:
130
+ * ```
131
+ * {
132
+ * "IPRangesApi.v1.getIPRanges": 0,
133
+ * }
125
134
*/
126
135
operationServerIndices ?: { [ name : string ] : number } ;
136
+ /**
137
+ * Operation servers. Key is the `{ApiName}.{ApiVersion}.{OperationName}`, value is the object of variables to use. Example:
138
+ * ```
139
+ * {
140
+ * "IPRangesApi.v1.getIPRanges": { site: "datadoghq.com" },
141
+ * }
142
+ */
143
+ operationServerVariables ?: { [ name : string ] : { [ key : string ] : string } } ;
127
144
/**
128
145
* Custom `fetch` function
129
146
*/
@@ -172,7 +189,9 @@ export interface ConfigurationParameters {
172
189
* If a property is not included in conf, a default is used:
173
190
* - baseServer: null
174
191
* - serverIndex: 0
192
+ * - serverVariables: {}
175
193
* - operationServerIndices: {}
194
+ * - operationServerVariables: {}
176
195
* - httpApi: IsomorphicFetchHttpLibrary
177
196
* - authMethods: {}
178
197
* - httpConfig: {}
@@ -186,9 +205,6 @@ export function createConfiguration(
186
205
if ( typeof process !== "undefined" && process . env && process . env . DD_SITE ) {
187
206
const serverConf = server1 . getConfiguration ( ) ;
188
207
server1 . setVariables ( { site : process . env . DD_SITE } as typeof serverConf ) ;
189
- for ( const op in operationServers ) {
190
- operationServers [ op ] [ 0 ] . setVariables ( { site : process . env . DD_SITE } ) ;
191
- }
192
208
}
193
209
194
210
const authMethods = conf . authMethods || { } ;
@@ -212,7 +228,9 @@ export function createConfiguration(
212
228
const configuration = new Configuration (
213
229
conf . baseServer ,
214
230
conf . serverIndex || 0 ,
231
+ conf . serverVariables || { } ,
215
232
conf . operationServerIndices || { } ,
233
+ conf . operationServerVariables || { } ,
216
234
conf . httpApi || new DefaultHttpLibrary ( ) ,
217
235
configureAuthMethods ( authMethods ) ,
218
236
conf . httpConfig || { } ,
@@ -221,93 +239,7 @@ export function createConfiguration(
221
239
conf . maxRetries || 3 ,
222
240
conf . backoffBase || 2 ,
223
241
conf . backoffMultiplier || 2 ,
224
- {
225
- "v2.createAWSAccount" : false ,
226
- "v2.createNewAWSExternalID" : false ,
227
- "v2.deleteAWSAccount" : false ,
228
- "v2.getAWSAccount" : false ,
229
- "v2.listAWSAccounts" : false ,
230
- "v2.listAWSNamespaces" : false ,
231
- "v2.updateAWSAccount" : false ,
232
- "v2.listAWSLogsServices" : false ,
233
- "v2.createMonitorNotificationRule" : false ,
234
- "v2.deleteMonitorNotificationRule" : false ,
235
- "v2.getMonitorNotificationRule" : false ,
236
- "v2.getMonitorNotificationRules" : false ,
237
- "v2.updateMonitorNotificationRule" : false ,
238
- "v2.cancelHistoricalJob" : false ,
239
- "v2.convertJobResultToSignal" : false ,
240
- "v2.deleteHistoricalJob" : false ,
241
- "v2.getFinding" : false ,
242
- "v2.getHistoricalJob" : false ,
243
- "v2.getRuleVersionHistory" : false ,
244
- "v2.getSBOM" : false ,
245
- "v2.listFindings" : false ,
246
- "v2.listHistoricalJobs" : false ,
247
- "v2.listVulnerabilities" : false ,
248
- "v2.listVulnerableAssets" : false ,
249
- "v2.muteFindings" : false ,
250
- "v2.runHistoricalJob" : false ,
251
- "v2.createSLOReportJob" : false ,
252
- "v2.getSLOReport" : false ,
253
- "v2.getSLOReportJobStatus" : false ,
254
- "v2.createOpenAPI" : false ,
255
- "v2.deleteOpenAPI" : false ,
256
- "v2.getOpenAPI" : false ,
257
- "v2.listAPIs" : false ,
258
- "v2.updateOpenAPI" : false ,
259
- "v2.cancelDataDeletionRequest" : false ,
260
- "v2.createDataDeletionRequest" : false ,
261
- "v2.getDataDeletionRequests" : false ,
262
- "v2.createDORADeployment" : false ,
263
- "v2.createDORAIncident" : false ,
264
- "v2.createIncident" : false ,
265
- "v2.createIncidentIntegration" : false ,
266
- "v2.createIncidentTodo" : false ,
267
- "v2.createIncidentType" : false ,
268
- "v2.deleteIncident" : false ,
269
- "v2.deleteIncidentIntegration" : false ,
270
- "v2.deleteIncidentTodo" : false ,
271
- "v2.deleteIncidentType" : false ,
272
- "v2.getIncident" : false ,
273
- "v2.getIncidentIntegration" : false ,
274
- "v2.getIncidentTodo" : false ,
275
- "v2.getIncidentType" : false ,
276
- "v2.listIncidentAttachments" : false ,
277
- "v2.listIncidentIntegrations" : false ,
278
- "v2.listIncidents" : false ,
279
- "v2.listIncidentTodos" : false ,
280
- "v2.listIncidentTypes" : false ,
281
- "v2.searchIncidents" : false ,
282
- "v2.updateIncident" : false ,
283
- "v2.updateIncidentAttachments" : false ,
284
- "v2.updateIncidentIntegration" : false ,
285
- "v2.updateIncidentTodo" : false ,
286
- "v2.updateIncidentType" : false ,
287
- "v2.getAggregatedConnections" : false ,
288
- "v2.createPipeline" : false ,
289
- "v2.deletePipeline" : false ,
290
- "v2.getPipeline" : false ,
291
- "v2.listPipelines" : false ,
292
- "v2.updatePipeline" : false ,
293
- "v2.validatePipeline" : false ,
294
- "v2.createScorecardOutcomesBatch" : false ,
295
- "v2.createScorecardRule" : false ,
296
- "v2.deleteScorecardRule" : false ,
297
- "v2.listScorecardOutcomes" : false ,
298
- "v2.listScorecardRules" : false ,
299
- "v2.updateScorecardRule" : false ,
300
- "v2.createIncidentService" : false ,
301
- "v2.deleteIncidentService" : false ,
302
- "v2.getIncidentService" : false ,
303
- "v2.listIncidentServices" : false ,
304
- "v2.updateIncidentService" : false ,
305
- "v2.createIncidentTeam" : false ,
306
- "v2.deleteIncidentTeam" : false ,
307
- "v2.getIncidentTeam" : false ,
308
- "v2.listIncidentTeams" : false ,
309
- "v2.updateIncidentTeam" : false ,
310
- } ,
242
+ { } ,
311
243
) ;
312
244
configuration . httpApi . zstdCompressorCallback = conf . zstdCompressorCallback ;
313
245
configuration . httpApi . debug = configuration . debug ;
@@ -319,31 +251,6 @@ export function createConfiguration(
319
251
return configuration ;
320
252
}
321
253
322
- export function getServer (
323
- conf : Configuration ,
324
- endpoint : string ,
325
- ) : BaseServerConfiguration {
326
- logger . warn (
327
- "getServer is deprecated, please use Configuration.getServer instead." ,
328
- ) ;
329
- return conf . getServer ( endpoint ) ;
330
- }
331
-
332
- /**
333
- * Sets the server variables.
334
- *
335
- * @param serverVariables key/value object representing the server variables (site, name, protocol, ...)
336
- */
337
- export function setServerVariables (
338
- conf : Configuration ,
339
- serverVariables : { [ key : string ] : string } ,
340
- ) : void {
341
- logger . warn (
342
- "setServerVariables is deprecated, please use Configuration.setServerVariables instead." ,
343
- ) ;
344
- return conf . setServerVariables ( serverVariables ) ;
345
- }
346
-
347
254
/**
348
255
* Apply given security authentication method if avaiable in configuration.
349
256
*/
0 commit comments