Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>21</source>
<target>21</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand Down Expand Up @@ -124,7 +124,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.26</version>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/eu/roboflax/cloudflare/CloudflareAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public ExecutorService getThreadPool() {
return threadPool;
}


public void close( long timeout, TimeUnit unit ) {
getRestClient().close();
if ( threadPool != null )
Expand Down
68 changes: 31 additions & 37 deletions src/main/java/eu/roboflax/cloudflare/CloudflareRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public class CloudflareRequest {
* The http request still was successful. If you used a CloudflareCallback for this request then onFailure will be executed.
* Otherwise if you have a CloudflareResponse object you can still use .getJson() to retrieve further information.
*/
public static final String ERROR_CLOUDFLARE_FAILURE = "Cloudflare was unable to perform your request and couldn't determine the result of the requested/passed information. " +
"Maybe you built the request wrong or something different.";

public static final String ERROR_CLOUDFLARE_FAILURE = """
Cloudflare was unable to perform your request and couldn't determine the result of the requested/passed information. \
Maybe you built the request wrong or something different.""";

public CloudflareRequest( ) {
}
Expand Down Expand Up @@ -248,45 +248,39 @@ public CloudflareRequest pagination( Pagination pagination ) {
}

private HttpResponse<String> sendRequest( ) {
switch ( checkNotNull( httpMethod, ERROR_INVALID_HTTP_METHOD ) ) {
case GET:
return cloudflareAccess.getRestClient()
.get( categoryPath() )
.queryString( queryStrings )
.asString();
case POST:
return cloudflareAccess.getRestClient()
.post( categoryPath() )
.queryString( queryStrings )
.body( body.toString() )
.asString();
case DELETE:
return cloudflareAccess.getRestClient()
.delete( categoryPath() )
.queryString( queryStrings )
.body( body.toString() )
.asString();
case PUT:
return cloudflareAccess.getRestClient()
.put( categoryPath() )
.queryString( queryStrings )
.body( body.toString() )
.asString();
case PATCH:
return cloudflareAccess.getRestClient()
.patch( categoryPath() )
.queryString( queryStrings )
.body( body.toString() )
.asString();
default:
throw new IllegalStateException( "Should never happen because other http methods are blocked." );
}
return switch (checkNotNull(httpMethod, ERROR_INVALID_HTTP_METHOD)) {
case GET -> cloudflareAccess.getRestClient()
.get(categoryPath())
.queryString(queryStrings)
.asString();
case POST -> cloudflareAccess.getRestClient()
.post(categoryPath())
.queryString(queryStrings)
.body(body.toString())
.asString();
case DELETE -> cloudflareAccess.getRestClient()
.delete(categoryPath())
.queryString(queryStrings)
.body(body.toString())
.asString();
case PUT -> cloudflareAccess.getRestClient()
.put(categoryPath())
.queryString(queryStrings)
.body(body.toString())
.asString();
case PATCH -> cloudflareAccess.getRestClient()
.patch(categoryPath())
.queryString(queryStrings)
.body(body.toString())
.asString();
default -> throw new IllegalStateException("Should never happen because other http methods are blocked.");
};
}

private Pair<HttpResponse<String>, JsonObject> response( ) {
if ( response == null ) {
HttpResponse<String> httpResponse = sendRequest();
JsonElement parsed = new JsonParser().parse( httpResponse.getBody() );
JsonElement parsed = new JsonParser().parse( httpResponse.body() );
// Check if parsing was successful, gson returns json null if failed
if ( parsed.isJsonNull() )
throw new IllegalStateException( ERROR_PARSING_JSON );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,44 @@
/**
* Configuration for a {@link eu.roboflax.cloudflare.CloudflareAccess} object.
*/
@Getter
@Setter
public class CloudflareConfig {

private String xAuthKey;
private String xAuthEmail;

private String xAuthToken;

private ExecutorService threadPool;
private Integer maxThreads;

public record CloudflareConfig(
@Getter String xAuthKey,
@Getter String xAuthEmail,
@Getter String xAuthToken,
@Getter ExecutorService threadPool,
@Getter Integer maxThreads
) {

//
// Key + Email auth
//

public CloudflareConfig( String xAuthKey, String xAuthEmail ) {
this.xAuthKey = xAuthKey;
this.xAuthEmail = xAuthEmail;
public CloudflareConfig(String xAuthKey, String xAuthEmail) {
this(xAuthKey, xAuthEmail, null, null, null);
}

public CloudflareConfig( String xAuthKey, String xAuthEmail, @Nullable Integer maxThreads ) {
this(xAuthKey, xAuthEmail);
this.maxThreads = maxThreads;
public CloudflareConfig(String xAuthKey, String xAuthEmail, @Nullable Integer maxThreads) {
this(xAuthKey, xAuthEmail, null, null, maxThreads);
}

public CloudflareConfig( String xAuthKey, String xAuthEmail, @Nullable ExecutorService threadPool ) {
this(xAuthKey, xAuthEmail);
this.threadPool = threadPool;
public CloudflareConfig(String xAuthKey, String xAuthEmail, @Nullable ExecutorService threadPool) {
this(xAuthKey, xAuthEmail, null, threadPool, null);
}

//
// Token auth
//

public CloudflareConfig( String xAuthToken ) {
this.xAuthToken = xAuthToken;
public CloudflareConfig(String xAuthToken) {
this(null, null, xAuthToken, null, null);
}

public CloudflareConfig( String xAuthToken, @Nullable Integer maxThreads ) {
this(xAuthToken);
this.maxThreads = maxThreads;
public CloudflareConfig(String xAuthToken, @Nullable Integer maxThreads) {
this(null, null, xAuthToken, null, maxThreads);
}

public CloudflareConfig( String xAuthToken, @Nullable ExecutorService threadPool ) {
this(xAuthToken);
this.threadPool = threadPool;
public CloudflareConfig(String xAuthToken, @Nullable ExecutorService threadPool) {
this(null, null, xAuthToken, threadPool, null);
}

/**
Expand All @@ -70,22 +60,26 @@ public CloudflareConfig( String xAuthToken, @Nullable ExecutorService threadPool
* @return the new CloudflareAccess
*/
public CloudflareAccess createAccess() {
if ( this.xAuthToken != null ) {
if ( this.threadPool != null ) {
return new CloudflareAccess(this.xAuthToken, this.threadPool);
return switch (xAuthToken != null ? 1 : 2) {
case 1 -> {
if (this.threadPool != null) {
yield new CloudflareAccess(this.xAuthToken, this.threadPool);
}
if (this.maxThreads != null) {
yield new CloudflareAccess(this.xAuthToken, this.maxThreads);
}
yield new CloudflareAccess(this.xAuthToken);
}
if ( this.maxThreads != null ) {
return new CloudflareAccess(this.xAuthToken, this.maxThreads);
case 2 -> {
if (this.threadPool != null) {
yield new CloudflareAccess(this.xAuthKey, this.xAuthEmail, this.threadPool);
}
if (this.maxThreads != null) {
yield new CloudflareAccess(this.xAuthKey, this.xAuthEmail, this.maxThreads);
}
yield new CloudflareAccess(this.xAuthKey, this.xAuthEmail);
}
return new CloudflareAccess(this.xAuthToken);
}
if ( this.threadPool != null ) {
return new CloudflareAccess(this.xAuthKey, this.xAuthEmail, this.threadPool);
}
if ( this.maxThreads != null ) {
return new CloudflareAccess(this.xAuthKey, this.xAuthEmail, this.maxThreads);
}
return new CloudflareAccess(this.xAuthKey, this.xAuthEmail);
default -> throw new IllegalStateException();
};
}
}

4 changes: 2 additions & 2 deletions src/main/java/eu/roboflax/cloudflare/constants/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@ public enum Category {
UPDATE_WORKER_ROUTE( PUT, "zones/{id-1}/workers/routes/{id-2}" ),
DELETE_WORKER_ROUTE( DELETE, "zones/{id-1}/workers/routes/{id-2}" );

private HttpMethod httpMethod;
private String additionalPath;
private final HttpMethod httpMethod;
private final String additionalPath;

Category( HttpMethod httpMethod, String additionalPath ) {
this.httpMethod = httpMethod;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/eu/roboflax/cloudflare/constants/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

public enum Match {
ALL, ANY

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*/
public interface Identifiable {

String getId( );
String getId();
}
14 changes: 7 additions & 7 deletions src/main/java/eu/roboflax/cloudflare/objects/ResultInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class ResultInfo {
public Integer totalCount;

@Override
public String toString( ) {
return new ToStringBuilder( this )
.append( "page", page )
.append( "perPage", perPage )
.append( "count", count )
.append( "totalCount", totalCount ).toString();
public String toString() {
return new ToStringBuilder(this)
.append("page", page)
.append("perPage", perPage)
.append("count", count)
.append("totalCount", totalCount).toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public class AccessRule implements Identifiable {
private String modifiedOn;

@Override
public String toString( ) {
return new ToStringBuilder( this ).append( "id", id ).append( "notes", notes ).append( "allowedModes", allowedModes ).append( "Mode", mode ).append( "configuration", configuration ).append( "scope", scope ).append( "createdOn", createdOn ).append( "modifiedOn", modifiedOn ).toString();
public String toString() {
return new ToStringBuilder(this).append("id", id).append("notes", notes).append("allowedModes", allowedModes).append("Mode", mode).append("configuration", configuration).append("scope", scope).append("createdOn", createdOn).append("modifiedOn", modifiedOn).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class Configuration {
private String value;

@Override
public String toString( ) {
return new ToStringBuilder( this ).append( "target", target ).append( "value", value ).toString();
public String toString() {
return new ToStringBuilder(this).append("target", target).append("value", value).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Scope implements Identifiable {
private String type;

@Override
public String toString( ) {
return new ToStringBuilder( this ).append( "id", id ).append( "email", email ).append( "type", type ).toString();
public String toString() {
return new ToStringBuilder(this).append("id", id).append("email", email).append("type", type).toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

import eu.roboflax.cloudflare.objects.Identifiable;

import java.util.Map;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package eu.roboflax.cloudflare.objects.crypto.customhostname;

public enum Type {
dv // domain validation
dv; // domain validation
}
30 changes: 15 additions & 15 deletions src/main/java/eu/roboflax/cloudflare/objects/dns/DNSRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,20 @@ public class DNSRecord implements Identifiable {
private Meta meta;

@Override
public String toString( ) {
return new ToStringBuilder( this )
.append( "id", id )
.append( "type", type )
.append( "name", name )
.append( "content", content )
.append( "proxiable", proxiable )
.append( "proxied", proxied )
.append( "ttl", ttl )
.append( "locked", locked )
.append( "zoneId", zoneId )
.append( "zoneName", zoneName )
.append( "modifiedOn", modifiedOn )
.append( "createdOn", createdOn )
.append( "meta", meta ).toString();
public String toString() {
return new ToStringBuilder(this)
.append("id", id)
.append("type", type)
.append("name", name)
.append("content", content)
.append("proxiable", proxiable)
.append("proxied", proxied)
.append("ttl", ttl)
.append("locked", locked)
.append("zoneId", zoneId)
.append("zoneName", zoneName)
.append("modifiedOn", modifiedOn)
.append("createdOn", createdOn)
.append("meta", meta).toString();
}
}
9 changes: 4 additions & 5 deletions src/main/java/eu/roboflax/cloudflare/objects/dns/Meta.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public class Meta {
private Boolean managedByApps;

@Override
public String toString( ) {
return new ToStringBuilder( this )
.append( "autoAdded", autoAdded )
.append( "managedByApps", managedByApps ).toString();
public String toString() {
return new ToStringBuilder(this)
.append("autoAdded", autoAdded)
.append("managedByApps", managedByApps).toString();
}

}
Loading