Skip to content

Commit a605e89

Browse files
WeltraumschafManuelNeuer
authored andcommitted
#36 Document al the settings and some finals
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent c441bc2 commit a605e89

File tree

1 file changed

+69
-11
lines changed
  • src/main/java/io/securecodebox/persistence/defectdojo/config

1 file changed

+69
-11
lines changed

src/main/java/io/securecodebox/persistence/defectdojo/config/Config.java

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,102 @@
77

88
import lombok.AllArgsConstructor;
99
import lombok.Getter;
10+
import lombok.NonNull;
1011
import lombok.ToString;
1112

1213
import java.util.Optional;
1314

15+
/**
16+
* Configures the DefectDojo client
17+
*/
1418
@Getter
1519
@ToString
1620
@AllArgsConstructor
17-
public class Config {
21+
public final class Config {
22+
/**
23+
* Default for {@link #maxPageCountForGets}
24+
*/
25+
private static final int DEFAULT_MAX_PAGE_COUNT_FOR_GETS = 100;
26+
/**
27+
* URL of the host which serves the DefectDojo API.
28+
* <p>
29+
* It is only allowed to configure the base URL (e.g. {@literal "https://defectdojo.securecodebox.io/"} without
30+
* any path. The path to the concrete API endpoints are maintained by this client library itself.
31+
* </p>
32+
*/
1833
private final String url;
19-
34+
/**
35+
* API key to authorize against the DefectDojo API.
36+
*/
2037
private final String apiKey;
21-
38+
/**
39+
* This name is used to set the creator of entities created in DefectDojo (findings etc.).
40+
* <p>
41+
* Since DefectDojo requires the id of the user this client lib must do a lookup to determine the according id.
42+
* This does not work, if the user does nit have appropriate privileges. In this case you can set the {@link #userId}
43+
* directly with the appropriate id of the user you want as creator.
44+
* </p>
45+
*
46+
* @deprecated Must not be used anymore because we determine the userid via user_profile API endpoint.
47+
*/
48+
@Deprecated
2249
private final String username;
2350

2451
/**
25-
* Determines how many apiPages of Objects are fetched before giving up and failing to avoid outOfMemory scenarios.
52+
* How many pages of objects are fetched from the DefectDojo API
53+
* <p>
54+
* This setting is to avoid out of memory scenarios.
55+
* </p>
56+
* <p>
57+
* Defaults to {@link #DEFAULT_MAX_PAGE_COUNT_FOR_GETS}.
58+
* </p>
2659
*/
2760
private final int maxPageCountForGets;
2861

2962
/**
30-
* If not null, the id should be used instead of the username.
63+
* Overwrite the creator by userid
64+
* <p>
65+
* <strong>IMPORTANT</strong>: If this is set (not {@code null}) the {@link #username} is ignored!
66+
* </p>
67+
* <p>
68+
* This option is necessary, if the user belonging to the {@link #apiKey} has no privilege to determine it's userid.
69+
* </p>
70+
*
71+
* @deprecated Must not be used anymore because we determine the userid via user_profile API endpoint.
3172
*/
73+
@Deprecated
3274
private final Long userId;
3375

34-
public Config(String url, String apiKey, String username, int maxPageCountForGets) {
76+
/**
77+
* Default constructor which sets {@link #userId} to {@code null}
78+
*
79+
* @param url not {@code null}
80+
* @param apiKey not {@code null}
81+
* @param username not {@code null}
82+
* @param maxPageCountForGets not less than 1
83+
*/
84+
public Config(final @NonNull String url, final @NonNull String apiKey, final @NonNull String username, final int maxPageCountForGets) {
85+
// FIXME: Implement check that maxPageCountForGets is not less than 1
3586
this(url, apiKey, username, maxPageCountForGets, null);
3687
}
3788

89+
/**
90+
* Creates config from environment variables
91+
*
92+
* @return never {@code null}
93+
*/
3894
public static Config fromEnv() {
39-
String url = System.getenv("DEFECTDOJO_URL");
40-
String username = System.getenv("DEFECTDOJO_USERNAME");
41-
String apiKey = System.getenv("DEFECTDOJO_APIKEY");
42-
Long userId = Optional.ofNullable(System.getenv("DEFECTDOJO_USER_ID")).map(Long::parseLong).orElse(null);
95+
final var url = System.getenv("DEFECTDOJO_URL");
96+
final var username = System.getenv("DEFECTDOJO_USERNAME");
97+
final var apiKey = System.getenv("DEFECTDOJO_APIKEY");
98+
final var userId = Optional.ofNullable(System.getenv("DEFECTDOJO_USER_ID")).map(Long::parseLong).orElse(null);
99+
100+
int maxPageCountForGets = DEFAULT_MAX_PAGE_COUNT_FOR_GETS;
43101

44-
int maxPageCountForGets = 100;
45102
if (System.getenv("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS") != null) {
46103
maxPageCountForGets = Integer.parseInt(System.getenv("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS"));
47104
}
105+
48106
return new Config(url, apiKey, username, maxPageCountForGets, userId);
49107
}
50108
}

0 commit comments

Comments
 (0)