Skip to content

Commit 1cd131d

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Add typescript method to configure auth (#463)
* Add method to configuration auth methods This puts the logic in a single place. * Regenerate client from commit cb21644 of spec repo Co-authored-by: Thomas Hervé <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 8d2640e commit 1cd131d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1636
-3820
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.5.1.dev2",
7-
"regenerated": "2022-01-11 17:17:44.666324",
8-
"spec_repo_commit": "f43ab25"
7+
"regenerated": "2022-01-11 17:39:01.533435",
8+
"spec_repo_commit": "cb21644"
99
},
1010
"v2": {
1111
"apigentools_version": "1.5.1.dev2",
12-
"regenerated": "2022-01-11 17:17:44.703678",
13-
"spec_repo_commit": "f43ab25"
12+
"regenerated": "2022-01-11 17:39:01.567195",
13+
"spec_repo_commit": "cb21644"
1414
}
1515
}
1616
}

.generator/templates/api/api.mustache

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// TODO: better import syntax?
22
import { BaseAPIRequestFactory, RequiredError } from './baseapi{{extensionForDeno}}';
3-
import {Configuration, getServer } from '../configuration{{extensionForDeno}}';
3+
import {Configuration, getServer, applySecurityAuthentication} from '../configuration{{extensionForDeno}}';
44
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http{{extensionForDeno}}';
55
import { logger } from "../../../index";
66
{{#platforms}}
@@ -148,17 +148,11 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
148148
);
149149
requestContext.setBody(serializedBody);
150150
{{/bodyParam}}
151-
152151
{{#hasAuthMethods}}
153-
let authMethod = null;
154-
{{/hasAuthMethods}}
155-
{{#authMethods}}
152+
156153
// Apply auth methods
157-
authMethod = _config.authMethods["{{name}}"]
158-
if (authMethod) {
159-
await authMethod.applySecurityAuthentication(requestContext);
160-
}
161-
{{/authMethods}}
154+
applySecurityAuthentication(_config, requestContext, [{{#authMethods}}"{{name}}"{{^-last}}, {{/-last}}{{/authMethods}}]);
155+
{{/hasAuthMethods}}
162156

163157
return requestContext;
164158
}

.generator/templates/configuration.mustache

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HttpLibrary, HttpConfiguration } from "./http/http{{extensionForDeno}}";
1+
import { HttpLibrary, HttpConfiguration, RequestContext } from "./http/http{{extensionForDeno}}";
22
import { DebugMiddleWare, Middleware, PromiseMiddleware, PromiseMiddlewareWrapper} from "./middleware{{extensionForDeno}}";
33
{{#frameworks}}
44
{{#fetch-api}}
@@ -160,3 +160,19 @@ export function setServerVariables(conf: Configuration, serverVariables: { [key:
160160
operationServers[op][0].setVariables(serverVariables);
161161
}
162162
}
163+
164+
/**
165+
* Apply given security authentication method if avaiable in configuration.
166+
*/
167+
export function applySecurityAuthentication<AuthMethodKey extends keyof AuthMethods> (
168+
conf: Configuration,
169+
requestContext: RequestContext,
170+
authMethods: AuthMethodKey[]
171+
): void {
172+
for (const authMethodName of authMethods) {
173+
const authMethod = conf.authMethods[authMethodName];
174+
if (authMethod) {
175+
authMethod.applySecurityAuthentication(requestContext);
176+
}
177+
}
178+
}

packages/datadog-api-client-v1/apis/AWSIntegrationApi.ts

Lines changed: 41 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// TODO: better import syntax?
22
import { BaseAPIRequestFactory, RequiredError } from "./baseapi";
3-
import { Configuration, getServer } from "../configuration";
3+
import {
4+
Configuration,
5+
getServer,
6+
applySecurityAuthentication,
7+
} from "../configuration";
48
import { RequestContext, HttpMethod, ResponseContext } from "../http/http";
59
import { ObjectSerializer } from "../models/ObjectSerializer";
610
import { ApiException } from "./exception";
@@ -59,17 +63,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
5963
);
6064
requestContext.setBody(serializedBody);
6165

62-
let authMethod = null;
6366
// Apply auth methods
64-
authMethod = _config.authMethods["apiKeyAuth"];
65-
if (authMethod) {
66-
await authMethod.applySecurityAuthentication(requestContext);
67-
}
68-
// Apply auth methods
69-
authMethod = _config.authMethods["appKeyAuth"];
70-
if (authMethod) {
71-
await authMethod.applySecurityAuthentication(requestContext);
72-
}
67+
applySecurityAuthentication(_config, requestContext, [
68+
"apiKeyAuth",
69+
"appKeyAuth",
70+
]);
7371

7472
return requestContext;
7573
}
@@ -114,17 +112,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
114112
);
115113
requestContext.setBody(serializedBody);
116114

117-
let authMethod = null;
118115
// Apply auth methods
119-
authMethod = _config.authMethods["apiKeyAuth"];
120-
if (authMethod) {
121-
await authMethod.applySecurityAuthentication(requestContext);
122-
}
123-
// Apply auth methods
124-
authMethod = _config.authMethods["appKeyAuth"];
125-
if (authMethod) {
126-
await authMethod.applySecurityAuthentication(requestContext);
127-
}
116+
applySecurityAuthentication(_config, requestContext, [
117+
"apiKeyAuth",
118+
"appKeyAuth",
119+
]);
128120

129121
return requestContext;
130122
}
@@ -169,17 +161,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
169161
);
170162
requestContext.setBody(serializedBody);
171163

172-
let authMethod = null;
173-
// Apply auth methods
174-
authMethod = _config.authMethods["apiKeyAuth"];
175-
if (authMethod) {
176-
await authMethod.applySecurityAuthentication(requestContext);
177-
}
178164
// Apply auth methods
179-
authMethod = _config.authMethods["appKeyAuth"];
180-
if (authMethod) {
181-
await authMethod.applySecurityAuthentication(requestContext);
182-
}
165+
applySecurityAuthentication(_config, requestContext, [
166+
"apiKeyAuth",
167+
"appKeyAuth",
168+
]);
183169

184170
return requestContext;
185171
}
@@ -224,17 +210,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
224210
);
225211
requestContext.setBody(serializedBody);
226212

227-
let authMethod = null;
228-
// Apply auth methods
229-
authMethod = _config.authMethods["apiKeyAuth"];
230-
if (authMethod) {
231-
await authMethod.applySecurityAuthentication(requestContext);
232-
}
233213
// Apply auth methods
234-
authMethod = _config.authMethods["appKeyAuth"];
235-
if (authMethod) {
236-
await authMethod.applySecurityAuthentication(requestContext);
237-
}
214+
applySecurityAuthentication(_config, requestContext, [
215+
"apiKeyAuth",
216+
"appKeyAuth",
217+
]);
238218

239219
return requestContext;
240220
}
@@ -279,17 +259,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
279259
);
280260
requestContext.setBody(serializedBody);
281261

282-
let authMethod = null;
283-
// Apply auth methods
284-
authMethod = _config.authMethods["apiKeyAuth"];
285-
if (authMethod) {
286-
await authMethod.applySecurityAuthentication(requestContext);
287-
}
288262
// Apply auth methods
289-
authMethod = _config.authMethods["appKeyAuth"];
290-
if (authMethod) {
291-
await authMethod.applySecurityAuthentication(requestContext);
292-
}
263+
applySecurityAuthentication(_config, requestContext, [
264+
"apiKeyAuth",
265+
"appKeyAuth",
266+
]);
293267

294268
return requestContext;
295269
}
@@ -340,17 +314,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
340314
);
341315
}
342316

343-
let authMethod = null;
344317
// Apply auth methods
345-
authMethod = _config.authMethods["apiKeyAuth"];
346-
if (authMethod) {
347-
await authMethod.applySecurityAuthentication(requestContext);
348-
}
349-
// Apply auth methods
350-
authMethod = _config.authMethods["appKeyAuth"];
351-
if (authMethod) {
352-
await authMethod.applySecurityAuthentication(requestContext);
353-
}
318+
applySecurityAuthentication(_config, requestContext, [
319+
"apiKeyAuth",
320+
"appKeyAuth",
321+
]);
354322

355323
return requestContext;
356324
}
@@ -392,17 +360,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
392360
);
393361
}
394362

395-
let authMethod = null;
396-
// Apply auth methods
397-
authMethod = _config.authMethods["apiKeyAuth"];
398-
if (authMethod) {
399-
await authMethod.applySecurityAuthentication(requestContext);
400-
}
401363
// Apply auth methods
402-
authMethod = _config.authMethods["appKeyAuth"];
403-
if (authMethod) {
404-
await authMethod.applySecurityAuthentication(requestContext);
405-
}
364+
applySecurityAuthentication(_config, requestContext, [
365+
"apiKeyAuth",
366+
"appKeyAuth",
367+
]);
406368

407369
return requestContext;
408370
}
@@ -427,17 +389,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
427389
requestContext.setHeaderParam("Accept", "application/json");
428390
requestContext.setHttpConfig(_config.httpConfig);
429391

430-
let authMethod = null;
431-
// Apply auth methods
432-
authMethod = _config.authMethods["apiKeyAuth"];
433-
if (authMethod) {
434-
await authMethod.applySecurityAuthentication(requestContext);
435-
}
436392
// Apply auth methods
437-
authMethod = _config.authMethods["appKeyAuth"];
438-
if (authMethod) {
439-
await authMethod.applySecurityAuthentication(requestContext);
440-
}
393+
applySecurityAuthentication(_config, requestContext, [
394+
"apiKeyAuth",
395+
"appKeyAuth",
396+
]);
441397

442398
return requestContext;
443399
}
@@ -508,17 +464,11 @@ export class AWSIntegrationApiRequestFactory extends BaseAPIRequestFactory {
508464
);
509465
requestContext.setBody(serializedBody);
510466

511-
let authMethod = null;
512467
// Apply auth methods
513-
authMethod = _config.authMethods["apiKeyAuth"];
514-
if (authMethod) {
515-
await authMethod.applySecurityAuthentication(requestContext);
516-
}
517-
// Apply auth methods
518-
authMethod = _config.authMethods["appKeyAuth"];
519-
if (authMethod) {
520-
await authMethod.applySecurityAuthentication(requestContext);
521-
}
468+
applySecurityAuthentication(_config, requestContext, [
469+
"apiKeyAuth",
470+
"appKeyAuth",
471+
]);
522472

523473
return requestContext;
524474
}

0 commit comments

Comments
 (0)