@@ -5,12 +5,7 @@ import {
55 ZstdCompressorCallback ,
66} from "./http/http" ;
77import { 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" ;
149import {
1510 configureAuthMethods ,
1611 AuthMethods ,
@@ -21,7 +16,11 @@ import { logger } from "./logger";
2116export class Configuration {
2217 readonly baseServer ?: BaseServerConfiguration ;
2318 readonly serverIndex : number ;
19+ readonly serverVariables : { [ key : string ] : string } ;
2420 readonly operationServerIndices : { [ name : string ] : number } ;
21+ readonly operationServerVariables : {
22+ [ name : string ] : { [ key : string ] : string } ;
23+ } ;
2524 readonly httpApi : HttpLibrary ;
2625 readonly authMethods : AuthMethods ;
2726 readonly httpConfig : HttpConfiguration ;
@@ -37,7 +36,9 @@ export class Configuration {
3736 public constructor (
3837 baseServer : BaseServerConfiguration | undefined ,
3938 serverIndex : number ,
39+ serverVariables : { [ key : string ] : string } ,
4040 operationServerIndices : { [ name : string ] : number } ,
41+ operationServerVariables : { [ name : string ] : { [ key : string ] : string } } ,
4142 httpApi : HttpLibrary ,
4243 authMethods : AuthMethods ,
4344 httpConfig : HttpConfiguration ,
@@ -50,7 +51,9 @@ export class Configuration {
5051 ) {
5152 this . baseServer = baseServer ;
5253 this . serverIndex = serverIndex ;
54+ this . serverVariables = serverVariables ;
5355 this . operationServerIndices = operationServerIndices ;
56+ this . operationServerVariables = operationServerVariables ;
5457 this . httpApi = httpApi ;
5558 this . authMethods = authMethods ;
5659 this . httpConfig = httpConfig ;
@@ -65,46 +68,38 @@ export class Configuration {
6568 this . servers . push ( server . clone ( ) ) ;
6669 }
6770 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- }
7471 if ( backoffBase && backoffBase < 2 ) {
7572 throw new Error ( "Backoff base must be at least 2" ) ;
7673 }
7774 }
7875
79- setServerVariables ( serverVariables : { [ key : string ] : string } ) : void {
76+ getServerAndOverrides ( key : string ) : {
77+ server : BaseServerConfiguration ;
78+ overrides ?: { [ key : string ] : string } ;
79+ } {
8080 if ( this . baseServer !== undefined ) {
81- this . baseServer . setVariables ( serverVariables ) ;
82- return ;
81+ return { server : this . baseServer , overrides : this . serverVariables } ;
8382 }
8483
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 ;
9494 }
95+
96+ return { server, overrides } ;
9597 }
9698
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 } ;
108103 }
109104}
110105
@@ -121,9 +116,31 @@ export interface ConfigurationParameters {
121116 */
122117 serverIndex ?: number ;
123118 /**
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+ * }
125134 */
126135 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 } } ;
127144 /**
128145 * Custom `fetch` function
129146 */
@@ -172,7 +189,9 @@ export interface ConfigurationParameters {
172189 * If a property is not included in conf, a default is used:
173190 * - baseServer: null
174191 * - serverIndex: 0
192+ * - serverVariables: {}
175193 * - operationServerIndices: {}
194+ * - operationServerVariables: {}
176195 * - httpApi: IsomorphicFetchHttpLibrary
177196 * - authMethods: {}
178197 * - httpConfig: {}
@@ -186,9 +205,6 @@ export function createConfiguration(
186205 if ( typeof process !== "undefined" && process . env && process . env . DD_SITE ) {
187206 const serverConf = server1 . getConfiguration ( ) ;
188207 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- }
192208 }
193209
194210 const authMethods = conf . authMethods || { } ;
@@ -212,7 +228,9 @@ export function createConfiguration(
212228 const configuration = new Configuration (
213229 conf . baseServer ,
214230 conf . serverIndex || 0 ,
231+ conf . serverVariables || { } ,
215232 conf . operationServerIndices || { } ,
233+ conf . operationServerVariables || { } ,
216234 conf . httpApi || new DefaultHttpLibrary ( ) ,
217235 configureAuthMethods ( authMethods ) ,
218236 conf . httpConfig || { } ,
@@ -221,93 +239,7 @@ export function createConfiguration(
221239 conf . maxRetries || 3 ,
222240 conf . backoffBase || 2 ,
223241 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+ { } ,
311243 ) ;
312244 configuration . httpApi . zstdCompressorCallback = conf . zstdCompressorCallback ;
313245 configuration . httpApi . debug = configuration . debug ;
@@ -319,31 +251,6 @@ export function createConfiguration(
319251 return configuration ;
320252}
321253
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-
347254/**
348255 * Apply given security authentication method if avaiable in configuration.
349256 */
0 commit comments