Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove BaseModel since it breaks equals/hashCode contract #112

Merged
merged 21 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f6e3b49
#23 Remove BaseModel since it breaks equals/hashCode contract
Weltraumschaf Jan 26, 2024
dad835c
#23 Use native types as model's field types
Weltraumschaf Jan 26, 2024
531480f
#23 Make constant private which is only used local
Weltraumschaf Jan 26, 2024
50b3175
#23 Reformat Java code
Weltraumschaf Jan 26, 2024
6912e55
#23 Add missing tests for model's equalsQueryString()
Weltraumschaf Jan 26, 2024
a4a21e1
#23 Reduce code duplication in equalsQueryString() implememtations
Weltraumschaf Jan 26, 2024
2a49a8a
#23 Also return false if id value in query params is null
Weltraumschaf Jan 26, 2024
14b33e2
#23 Give the Class a Better Name and Documentation
Weltraumschaf Feb 2, 2024
e926804
#23 Give the PaginatedResult Also an Upper Bound
Weltraumschaf Feb 2, 2024
01a958d
#23 Add Default Values to Prevent NPEs
Weltraumschaf Feb 2, 2024
8b098aa
#23 Add More Questions to PaginatedResult
Weltraumschaf Feb 2, 2024
fdd130c
#23 Clean Test Code
Weltraumschaf Feb 2, 2024
b0dc5ae
#23 Document Requirement for Null Values
Weltraumschaf Feb 2, 2024
f97b4ae
#23 Remove Unnecessary Code Clutter
Weltraumschaf Feb 2, 2024
6f6a2ab
#23 Clean Code
Weltraumschaf Feb 2, 2024
8772a60
#23 Clean Test Code
Weltraumschaf Feb 2, 2024
490e584
#23 Add TODO Hint to Remove Checked Exceptions from Public API
Weltraumschaf Feb 5, 2024
52cbd44
#23 Add Identical Behaviour Likethe Others Implementations Have
Weltraumschaf Feb 6, 2024
146c324
#23 Fix copy Paste Error in JavaDoc
Weltraumschaf Feb 6, 2024
4381585
Add Missing JavaDoc to PagianteResult Fileds
Weltraumschaf Feb 6, 2024
ed5fa7c
Add Missing JavaDoc to ScanFile
Weltraumschaf Feb 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.securecodebox</groupId>
<artifactId>defectdojo-client</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>DefectDojo Client Java</name>
<description>
Expand Down
392 changes: 196 additions & 196 deletions src/main/java/io/securecodebox/persistence/defectdojo/ScanType.java

Large diffs are not rendered by default.

239 changes: 121 additions & 118 deletions src/main/java/io/securecodebox/persistence/defectdojo/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
package io.securecodebox.persistence.defectdojo.config;

import io.securecodebox.persistence.defectdojo.exception.ConfigException;
import lombok.*;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

/**
* Configures the DefectDojo client
Expand All @@ -14,133 +17,133 @@
@ToString
@EqualsAndHashCode
public final class Config {
/**
* Default for {@link #maxPageCountForGets}
*/
static final int DEFAULT_MAX_PAGE_COUNT_FOR_GETS = 100;
/**
* Null pattern object.
*/
public static final Config NULL = new Config("", "", DEFAULT_MAX_PAGE_COUNT_FOR_GETS);

/**
* URL of the host which serves the DefectDojo API.
* <p>
* It is only allowed to configure the base URL (e.g. {@literal "https://defectdojo.securecodebox.io/"} without
* any path. The path to the concrete API endpoints are maintained by this client library itself.
* </p>
*/
@NonNull
private final String url;

/**
* API key to authorize against the DefectDojo API.
*/
@NonNull
private final String apiKey;

/**
* How many pages of objects are fetched from the DefectDojo API
* <p>
* This setting is to avoid out of memory scenarios.
* </p>
* <p>
* Defaults to {@link #DEFAULT_MAX_PAGE_COUNT_FOR_GETS}.
* </p>
*/
private final int maxPageCountForGets;

/**
* Convenience constructor which sets {@link #DEFAULT_MAX_PAGE_COUNT_FOR_GETS}
*
* @param url not {@code null}
* @param apiKey not {@code null}
*/
public Config(final @NonNull String url, final @NonNull String apiKey) {
this(url, apiKey, DEFAULT_MAX_PAGE_COUNT_FOR_GETS);
/**
* Default for {@link #maxPageCountForGets}
*/
static final int DEFAULT_MAX_PAGE_COUNT_FOR_GETS = 100;
/**
* Null pattern object.
*/
public static final Config NULL = new Config("", "", DEFAULT_MAX_PAGE_COUNT_FOR_GETS);

/**
* URL of the host which serves the DefectDojo API.
* <p>
* It is only allowed to configure the base URL (e.g. {@literal "https://defectdojo.securecodebox.io/"} without
* any path. The path to the concrete API endpoints are maintained by this client library itself.
* </p>
*/
@NonNull
private final String url;

/**
* API key to authorize against the DefectDojo API.
*/
@NonNull
private final String apiKey;

/**
* How many pages of objects are fetched from the DefectDojo API
* <p>
* This setting is to avoid out of memory scenarios.
* </p>
* <p>
* Defaults to {@link #DEFAULT_MAX_PAGE_COUNT_FOR_GETS}.
* </p>
*/
private final int maxPageCountForGets;

/**
* Convenience constructor which sets {@link #DEFAULT_MAX_PAGE_COUNT_FOR_GETS}
*
* @param url not {@code null}
* @param apiKey not {@code null}
*/
public Config(final @NonNull String url, final @NonNull String apiKey) {
this(url, apiKey, DEFAULT_MAX_PAGE_COUNT_FOR_GETS);
}

/**
* Dedicated constructor
*
* @param url not {@code null}
* @param apiKey not {@code null}
* @param maxPageCountForGets not less than 1
*/
public Config(final @NonNull String url, final @NonNull String apiKey, final int maxPageCountForGets) {
super();
this.url = url;
this.apiKey = apiKey;
this.maxPageCountForGets = validateIsGreaterZero(maxPageCountForGets, "maxPageCountForGets");
}

private static int validateIsGreaterZero(final int number, final String name) {
if (number < 1) {
throw new IllegalArgumentException(String.format("%s must be greater than 0!", name));
}

/**
* Dedicated constructor
*
* @param url not {@code null}
* @param apiKey not {@code null}
* @param maxPageCountForGets not less than 1
*/
public Config(final @NonNull String url, final @NonNull String apiKey, final int maxPageCountForGets) {
super();
this.url = url;
this.apiKey = apiKey;
this.maxPageCountForGets = validateIsGreaterZero(maxPageCountForGets, "maxPageCountForGets");
}

private static int validateIsGreaterZero(final int number, final String name) {
if (number < 1) {
throw new IllegalArgumentException(String.format("%s must be greater than 0!", name));
}

return number;
return number;
}

/**
* Creates config from environment variables
*
* @return never {@code null}
*/
public static Config fromEnv() {
final var url = findRequiredEnvVar(EnvVars.DEFECTDOJO_URL);
final var apiKey = findRequiredEnvVar(EnvVars.DEFECTDOJO_APIKEY);
final int maxPageCountForGets;

if (hasEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS)) {
try {
maxPageCountForGets = Integer.parseInt(findEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS));
} catch (final NumberFormatException e) {
throw new ConfigException(String.format("Given value for environment variable '%s' is not a valid number! Given was '%s'.", EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS.literal, findEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS)),
e);
}
} else {
maxPageCountForGets = DEFAULT_MAX_PAGE_COUNT_FOR_GETS;
}

/**
* Creates config from environment variables
*
* @return never {@code null}
*/
public static Config fromEnv() {
final var url = findRequiredEnvVar(EnvVars.DEFECTDOJO_URL);
final var apiKey = findRequiredEnvVar(EnvVars.DEFECTDOJO_APIKEY);
final int maxPageCountForGets;

if (hasEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS)) {
try {
maxPageCountForGets = Integer.parseInt(findEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS));
} catch (final NumberFormatException e) {
throw new ConfigException(String.format("Given value for environment variable '%s' is not a valid number! Given was '%s'.", EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS.literal, findEnvVar(EnvVars.DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS)),
e);
}
} else {
maxPageCountForGets = DEFAULT_MAX_PAGE_COUNT_FOR_GETS;
}

return new Config(url, apiKey, maxPageCountForGets);
}
return new Config(url, apiKey, maxPageCountForGets);
}

private static boolean hasEnvVar(final @NonNull EnvVars name) {
return findEnvVar(name) != null;
}
private static boolean hasEnvVar(final @NonNull EnvVars name) {
return findEnvVar(name) != null;
}

private static String findEnvVar(final @NonNull EnvVars name) {
return System.getenv(name.literal);
}
private static String findEnvVar(final @NonNull EnvVars name) {
return System.getenv(name.literal);
}

private static String findRequiredEnvVar(final @NonNull EnvVars name) {
final var envVar = System.getenv(name.literal);
private static String findRequiredEnvVar(final @NonNull EnvVars name) {
final var envVar = System.getenv(name.literal);

if (envVar == null) {
throw new ConfigException(String.format("Missing environment variable '%s'!", name.literal));
}
return envVar;
if (envVar == null) {
throw new ConfigException(String.format("Missing environment variable '%s'!", name.literal));
}

return envVar;
}

/**
* Enumerates the available environment variables to configure the client
*/
public enum EnvVars {
DEFECTDOJO_URL("DEFECTDOJO_URL"),
DEFECTDOJO_APIKEY("DEFECTDOJO_APIKEY"),
DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS");
/**
* Enumerates the available environment variables to configure the client
* Literal name of configuration environment name
* <p>
* We use an own value to hold the actual value, so that refactoring the enum name does
* not break the published API of env var names.
* </p>
*/
public enum EnvVars {
DEFECTDOJO_URL("DEFECTDOJO_URL"),
DEFECTDOJO_APIKEY("DEFECTDOJO_APIKEY"),
DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS("DEFECTDOJO_MAX_PAGE_COUNT_FOR_GETS");
/**
* Literal name of configuration environment name
* <p>
* We use an own value to hold the actual value, so that refactoring the enum name does
* not break the published API of env var names.
* </p>
*/
private final String literal;

EnvVars(final String literal) {
this.literal = literal;
}
private final String literal;

EnvVars(final String literal) {
this.literal = literal;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
* Indicates a missing {@link io.securecodebox.persistence.defectdojo.config.Config config property}
*/
public final class ConfigException extends RuntimeException {
public ConfigException(final String message) {
super(message);
}
public ConfigException(final String message, final Throwable cause) {
super(message, cause);
}
public ConfigException(final String message) {
super(message);
}

public ConfigException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
package io.securecodebox.persistence.defectdojo.exception;

public final class PersistenceException extends RuntimeException {
public PersistenceException(String message) {
super(message);
}
public PersistenceException(String message) {
super(message);
}

public PersistenceException(String message, Throwable cause) {
super(message, cause);
}
public PersistenceException(String message, Throwable cause) {
super(message, cause);
}
}
Loading