fixed issue #3

This commit is contained in:
2025-04-13 17:33:50 +02:00
parent f5ba156c49
commit 34ea8e1b62
3 changed files with 17 additions and 16 deletions
@@ -35,15 +35,22 @@ abstract class CfBasicHttpClient {
private final String baseUrl;
private final String authEmail;
private final String authKey;
private final String authToken;
private final ObjectMapper objectMapper;
CfBasicHttpClient(String baseUrl, String authEmail, String authKey, String authToken) {
CfBasicHttpClient(String baseUrl, String authEmail, String authKey) {
if (baseUrl == null || baseUrl.isBlank()) {
throw new IllegalArgumentException("Base URL must not be null or blank!");
}
if (authEmail == null || authEmail.isBlank()) {
throw new IllegalArgumentException("Authentication email must not be null or blank!");
}
if (authKey == null || authKey.isBlank()) {
throw new IllegalArgumentException("Authentication key must not be null or blank!");
}
this.baseUrl = baseUrl;
this.authEmail = authEmail;
this.authKey = authKey;
this.authToken = authToken;
this.objectMapper = initObjectMapper();
}
@@ -67,7 +74,6 @@ abstract class CfBasicHttpClient {
HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.getMimeType());
request.addHeader("X-Auth-Email", authEmail);
request.addHeader("X-Auth-Key", authKey);
request.addHeader("X-Auth-Token", authToken);
})
.build();
}
@@ -53,10 +53,9 @@ public class CfDnsClient extends CfBasicHttpClient {
* authentication.
* @param authKey The API key of the Cloudflare account, used as part of the authentication
* process.
* @param authToken The API token for accessing specific resources within the Cloudflare account.
*/
public CfDnsClient(String authEmail, String authKey, String authToken) {
this(DEFAULT_BASEURL, authEmail, authKey, authToken);
public CfDnsClient(String authEmail, String authKey) {
this(DEFAULT_BASEURL, authEmail, authKey);
}
/**
@@ -67,10 +66,9 @@ public class CfDnsClient extends CfBasicHttpClient {
* authentication.
* @param authKey The API key of the Cloudflare account, used as part of the authentication
* process.
* @param authToken The API token for accessing specific resources within the Cloudflare account.
*/
public CfDnsClient(String baseUrl, String authEmail, String authKey, String authToken) {
this(true, baseUrl, authEmail, authKey, authToken);
public CfDnsClient(String baseUrl, String authEmail, String authKey) {
this(true, baseUrl, authEmail, authKey);
}
/**
@@ -82,15 +80,13 @@ public class CfDnsClient extends CfBasicHttpClient {
* @param baseUrl The base URL for the Cloudflare API endpoint.
* @param authEmail The email associated with the Cloudflare account for authentication.
* @param authKey The API key for authenticating the client with Cloudflare services.
* @param authToken The authentication token used for authorized access to Cloudflare API.
*/
public CfDnsClient(
boolean emptyResultThrowsException,
String baseUrl,
String authEmail,
String authKey,
String authToken) {
super(baseUrl, authEmail, authKey, authToken);
String authKey) {
super(baseUrl, authEmail, authKey);
this.emptyResultThrowsException = emptyResultThrowsException;
}
@@ -21,9 +21,8 @@ public class CfClientTest {
private final String email = System.getenv("API_EMAIL");
private final String apiKey = System.getenv("API_KEY");
private final String apiToken = System.getenv("API_TOKEN");
private final CfDnsClient client = new CfDnsClient(email, apiKey, apiToken);
private final CfDnsClient client = new CfDnsClient(email, apiKey);
@Test
void testList() throws Exception {