-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathConfig.java
50 lines (39 loc) · 1.51 KB
/
Config.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2021 iteratec GmbH
// SPDX-FileCopyrightText: 2023 iteratec GmbH
//
// SPDX-License-Identifier: Apache-2.0
package io.securecodebox.persistence.defectdojo.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import java.util.Optional;
@Getter
@ToString
@AllArgsConstructor
public class Config {
private final String url;
private final String apiKey;
private final String username;
/**
* Determines how many apiPages of Objects are fetched before giving up and failing to avoid outOfMemory scenarios.
*/
private final int maxPageCountForGets;
/**
* If not null, the id should be used instead of the username.
*/
private final Long userId;
public Config(String url, String apiKey, String username, int maxPageCountForGets) {
this(url, apiKey, username, maxPageCountForGets, null);
}
public static Config fromEnv() {
String url = System.getenv("DEFECTDOJO_URL");
String username = System.getenv("DEFECTDOJO_USERNAME");
String apiKey = System.getenv("DEFECTDOJO_APIKEY");
Long userId = Optional.ofNullable(System.getenv("DEFECTDOJO_USER_ID")).map(Long::parseLong).orElse(null);
int maxPageCountForGets = 100;
if (System.getenv("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS") != null) {
maxPageCountForGets = Integer.parseInt(System.getenv("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS"));
}
return new Config(url, apiKey, username, maxPageCountForGets, userId);
}
}