Skip to content

Commit 2da8c8c

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Add default environment loading in clients (#721)
* Add default env loading * Use x-env-name * Move instantiation * Regenerate client from commit 55a2c8a of spec repo Co-authored-by: Thomas Hervé <thomas.herve@datadoghq.com> 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 <packages@datadoghq.com>
1 parent 6e617d0 commit 2da8c8c

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

+95
-3209
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.4.1.dev6",
7-
"regenerated": "2021-03-29 13:59:41.507485",
8-
"spec_repo_commit": "2f79ff1"
7+
"regenerated": "2021-03-30 06:59:58.819267",
8+
"spec_repo_commit": "55a2c8a"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev6",
12-
"regenerated": "2021-03-29 14:00:32.407265",
13-
"spec_repo_commit": "2f79ff1"
12+
"regenerated": "2021-03-30 07:00:43.519619",
13+
"spec_repo_commit": "55a2c8a"
1414
}
1515
}
1616
}

.generator/templates/Configuration.mustache

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
package {{invokerPackage}};
44

5+
import java.util.HashMap;
6+
57
{{>generatedAnnotation}}
68
public class Configuration {
7-
private static ApiClient defaultApiClient = new ApiClient();
9+
private static ApiClient defaultApiClient;
810
911
/**
1012
* Get the default API client, which would be used when creating API
@@ -13,6 +15,32 @@ public class Configuration {
1315
* @return Default API client
1416
*/
1517
public static ApiClient getDefaultApiClient() {
18+
if (defaultApiClient != null) {
19+
return defaultApiClient;
20+
}
21+
defaultApiClient = new ApiClient();
22+
23+
// Configure the Datadog site to send API calls to
24+
String site = System.getenv("DD_SITE");
25+
if (site != null) {
26+
HashMap<String, String> serverVariables = new HashMap<String, String>();
27+
serverVariables.put("site", site);
28+
defaultApiClient.setServerVariables(serverVariables);
29+
}
30+
// Configure API key authorization
31+
HashMap<String, String> secrets = new HashMap<String, String>();
32+
{{#authMethods}}
33+
{{#isApiKey}}
34+
{{#isKeyInHeader}}
35+
String {{name}} = System.getenv("{{vendorExtensions.x-env-name}}");
36+
if ({{name}} != null) {
37+
secrets.put("{{name}}", {{name}});
38+
}
39+
{{/isKeyInHeader}}
40+
{{/isApiKey}}
41+
{{/authMethods}}
42+
defaultApiClient.configureApiKeys(secrets);
43+
1644
return defaultApiClient;
1745
}
1846

.generator/templates/libraries/jersey2/api_doc.mustache

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,6 @@ import {{{package}}}.{{{classname}}};
4343
public class Example {
4444
public static void main(String[] args) {
4545
ApiClient defaultClient = Configuration.getDefaultApiClient();
46-
// Configure the Datadog site to send API calls to
47-
HashMap<String, String> serverVariables = new HashMap<String, String>();
48-
String site = System.getenv("DD_SITE");
49-
if (site != null) {
50-
serverVariables.put("site", site);
51-
defaultClient.setServerVariables(serverVariables);
52-
}
53-
// Configure API key authorization: {{{name}}}
54-
HashMap<String, String> secrets = new HashMap<String, String>();
55-
{{#hasAuthMethods}}
56-
{{#authMethods}}
57-
{{#isApiKey}}
58-
secrets.put("{{{name}}}", System.getenv("{{{vendorExtensions.x-env-name}}}"));
59-
{{/isApiKey}}
60-
{{/authMethods}}
61-
{{/hasAuthMethods}}
62-
defaultClient.configureApiKeys(secrets);
6346
6447
{{{classname}}} apiInstance = new {{{classname}}}(defaultClient);
6548
{{#allParams}}

api/openapi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12129,12 +12129,12 @@ components:
1212912129
in: header
1213012130
name: DD-API-KEY
1213112131
type: apiKey
12132-
x-env-name: DD_CLIENT_API_KEY
12132+
x-env-name: DD_API_KEY
1213312133
appKeyAuth:
1213412134
description: Your Datadog APP Key.
1213512135
in: header
1213612136
name: DD-APPLICATION-KEY
1213712137
type: apiKey
12138-
x-env-name: DD_CLIENT_APP_KEY
12138+
x-env-name: DD_APP_KEY
1213912139
x-group-parameters: true
1214012140

api_docs/v1/AuthenticationApi.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ import com.datadog.api.v1.client.api.AuthenticationApi;
3131
public class Example {
3232
public static void main(String[] args) {
3333
ApiClient defaultClient = Configuration.getDefaultApiClient();
34-
// Configure the Datadog site to send API calls to
35-
HashMap<String, String> serverVariables = new HashMap<String, String>();
36-
String site = System.getenv("DD_SITE");
37-
if (site != null) {
38-
serverVariables.put("site", site);
39-
defaultClient.setServerVariables(serverVariables);
40-
}
41-
// Configure API key authorization:
42-
HashMap<String, String> secrets = new HashMap<String, String>();
43-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
44-
defaultClient.configureApiKeys(secrets);
4534

4635
AuthenticationApi apiInstance = new AuthenticationApi(defaultClient);
4736
try {

api_docs/v1/AwsIntegrationApi.md

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
4242
public class Example {
4343
public static void main(String[] args) {
4444
ApiClient defaultClient = Configuration.getDefaultApiClient();
45-
// Configure the Datadog site to send API calls to
46-
HashMap<String, String> serverVariables = new HashMap<String, String>();
47-
String site = System.getenv("DD_SITE");
48-
if (site != null) {
49-
serverVariables.put("site", site);
50-
defaultClient.setServerVariables(serverVariables);
51-
}
52-
// Configure API key authorization:
53-
HashMap<String, String> secrets = new HashMap<String, String>();
54-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
55-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
56-
defaultClient.configureApiKeys(secrets);
5745

5846
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
5947
AWSAccount body = new AWSAccount(); // AWSAccount | AWS Request Object
@@ -125,18 +113,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
125113
public class Example {
126114
public static void main(String[] args) {
127115
ApiClient defaultClient = Configuration.getDefaultApiClient();
128-
// Configure the Datadog site to send API calls to
129-
HashMap<String, String> serverVariables = new HashMap<String, String>();
130-
String site = System.getenv("DD_SITE");
131-
if (site != null) {
132-
serverVariables.put("site", site);
133-
defaultClient.setServerVariables(serverVariables);
134-
}
135-
// Configure API key authorization:
136-
HashMap<String, String> secrets = new HashMap<String, String>();
137-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
138-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
139-
defaultClient.configureApiKeys(secrets);
140116

141117
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
142118
AWSTagFilterCreateRequest body = new AWSTagFilterCreateRequest(); // AWSTagFilterCreateRequest | Set an AWS tag filter using an `aws_account_identifier`, `namespace`, and filtering string. Namespace options are `application_elb`, `elb`, `lambda`, `network_elb`, `rds`, `sqs`, and `custom`.
@@ -207,18 +183,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
207183
public class Example {
208184
public static void main(String[] args) {
209185
ApiClient defaultClient = Configuration.getDefaultApiClient();
210-
// Configure the Datadog site to send API calls to
211-
HashMap<String, String> serverVariables = new HashMap<String, String>();
212-
String site = System.getenv("DD_SITE");
213-
if (site != null) {
214-
serverVariables.put("site", site);
215-
defaultClient.setServerVariables(serverVariables);
216-
}
217-
// Configure API key authorization:
218-
HashMap<String, String> secrets = new HashMap<String, String>();
219-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
220-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
221-
defaultClient.configureApiKeys(secrets);
222186

223187
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
224188
AWSAccount body = new AWSAccount(); // AWSAccount | Your Datadog role delegation name. For more information about your AWS account Role name, see the [Datadog AWS integration configuration info](https://github.com/DataDog/documentation/blob/master/integrations/amazon_web_services/#installation).
@@ -289,18 +253,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
289253
public class Example {
290254
public static void main(String[] args) {
291255
ApiClient defaultClient = Configuration.getDefaultApiClient();
292-
// Configure the Datadog site to send API calls to
293-
HashMap<String, String> serverVariables = new HashMap<String, String>();
294-
String site = System.getenv("DD_SITE");
295-
if (site != null) {
296-
serverVariables.put("site", site);
297-
defaultClient.setServerVariables(serverVariables);
298-
}
299-
// Configure API key authorization:
300-
HashMap<String, String> secrets = new HashMap<String, String>();
301-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
302-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
303-
defaultClient.configureApiKeys(secrets);
304256

305257
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
306258
AWSAccount body = new AWSAccount(); // AWSAccount | AWS request object
@@ -372,18 +324,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
372324
public class Example {
373325
public static void main(String[] args) {
374326
ApiClient defaultClient = Configuration.getDefaultApiClient();
375-
// Configure the Datadog site to send API calls to
376-
HashMap<String, String> serverVariables = new HashMap<String, String>();
377-
String site = System.getenv("DD_SITE");
378-
if (site != null) {
379-
serverVariables.put("site", site);
380-
defaultClient.setServerVariables(serverVariables);
381-
}
382-
// Configure API key authorization:
383-
HashMap<String, String> secrets = new HashMap<String, String>();
384-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
385-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
386-
defaultClient.configureApiKeys(secrets);
387327

388328
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
389329
AWSTagFilterDeleteRequest body = new AWSTagFilterDeleteRequest(); // AWSTagFilterDeleteRequest | Delete a tag filtering entry for a given AWS account and `dd-aws` namespace.
@@ -454,18 +394,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
454394
public class Example {
455395
public static void main(String[] args) {
456396
ApiClient defaultClient = Configuration.getDefaultApiClient();
457-
// Configure the Datadog site to send API calls to
458-
HashMap<String, String> serverVariables = new HashMap<String, String>();
459-
String site = System.getenv("DD_SITE");
460-
if (site != null) {
461-
serverVariables.put("site", site);
462-
defaultClient.setServerVariables(serverVariables);
463-
}
464-
// Configure API key authorization:
465-
HashMap<String, String> secrets = new HashMap<String, String>();
466-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
467-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
468-
defaultClient.configureApiKeys(secrets);
469397

470398
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
471399
String accountId = "accountId_example"; // String | Only return AWS accounts that matches this `account_id`.
@@ -542,18 +470,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
542470
public class Example {
543471
public static void main(String[] args) {
544472
ApiClient defaultClient = Configuration.getDefaultApiClient();
545-
// Configure the Datadog site to send API calls to
546-
HashMap<String, String> serverVariables = new HashMap<String, String>();
547-
String site = System.getenv("DD_SITE");
548-
if (site != null) {
549-
serverVariables.put("site", site);
550-
defaultClient.setServerVariables(serverVariables);
551-
}
552-
// Configure API key authorization:
553-
HashMap<String, String> secrets = new HashMap<String, String>();
554-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
555-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
556-
defaultClient.configureApiKeys(secrets);
557473

558474
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
559475
String accountId = "accountId_example"; // String | Only return AWS filters that matches this `account_id`.
@@ -624,18 +540,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
624540
public class Example {
625541
public static void main(String[] args) {
626542
ApiClient defaultClient = Configuration.getDefaultApiClient();
627-
// Configure the Datadog site to send API calls to
628-
HashMap<String, String> serverVariables = new HashMap<String, String>();
629-
String site = System.getenv("DD_SITE");
630-
if (site != null) {
631-
serverVariables.put("site", site);
632-
defaultClient.setServerVariables(serverVariables);
633-
}
634-
// Configure API key authorization:
635-
HashMap<String, String> secrets = new HashMap<String, String>();
636-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
637-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
638-
defaultClient.configureApiKeys(secrets);
639543

640544
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
641545
try {
@@ -700,18 +604,6 @@ import com.datadog.api.v1.client.api.AwsIntegrationApi;
700604
public class Example {
701605
public static void main(String[] args) {
702606
ApiClient defaultClient = Configuration.getDefaultApiClient();
703-
// Configure the Datadog site to send API calls to
704-
HashMap<String, String> serverVariables = new HashMap<String, String>();
705-
String site = System.getenv("DD_SITE");
706-
if (site != null) {
707-
serverVariables.put("site", site);
708-
defaultClient.setServerVariables(serverVariables);
709-
}
710-
// Configure API key authorization:
711-
HashMap<String, String> secrets = new HashMap<String, String>();
712-
secrets.put("apiKeyAuth", System.getenv("DD_CLIENT_API_KEY"));
713-
secrets.put("appKeyAuth", System.getenv("DD_CLIENT_APP_KEY"));
714-
defaultClient.configureApiKeys(secrets);
715607

716608
AwsIntegrationApi apiInstance = new AwsIntegrationApi(defaultClient);
717609
AWSAccount body = new AWSAccount(); // AWSAccount | AWS request object

0 commit comments

Comments
 (0)