Skip to content

Commit 102b23f

Browse files
authored
Merge pull request #64 from robinbraemer/feature/access-and-tunnel-support
Add Cloudflare Tunnel, Access Applications, and Access Service Tokens support
2 parents c4e1a34 + 2425c29 commit 102b23f

File tree

6 files changed

+479
-3
lines changed

6 files changed

+479
-3
lines changed

src/main/java/eu/roboflax/cloudflare/constants/Category.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,39 @@ public enum Category {
393393
LIST_WORKER_ROUTES( GET, "zones/{id-1}/workers/routes" ),
394394
GET_WORKER_ROUTE( GET, "zones/{id-1}/workers/routes/{id-2}" ),
395395
UPDATE_WORKER_ROUTE( PUT, "zones/{id-1}/workers/routes/{id-2}" ),
396-
DELETE_WORKER_ROUTE( DELETE, "zones/{id-1}/workers/routes/{id-2}" );
396+
DELETE_WORKER_ROUTE( DELETE, "zones/{id-1}/workers/routes/{id-2}" ),
397397

398-
private HttpMethod httpMethod;
399-
private String additionalPath;
398+
// Cloudflare Tunnel (Zero Trust)
399+
LIST_TUNNELS( GET, "accounts/{id-1}/cfd_tunnel" ),
400+
CREATE_TUNNEL( POST, "accounts/{id-1}/cfd_tunnel" ),
401+
TUNNEL_DETAILS( GET, "accounts/{id-1}/cfd_tunnel/{id-2}" ),
402+
UPDATE_TUNNEL( PATCH, "accounts/{id-1}/cfd_tunnel/{id-2}" ),
403+
DELETE_TUNNEL( DELETE, "accounts/{id-1}/cfd_tunnel/{id-2}" ),
404+
GET_TUNNEL_CONFIGURATION( GET, "accounts/{id-1}/cfd_tunnel/{id-2}/configurations" ),
405+
UPDATE_TUNNEL_CONFIGURATION( PUT, "accounts/{id-1}/cfd_tunnel/{id-2}/configurations" ),
406+
GET_TUNNEL_TOKEN( GET, "accounts/{id-1}/cfd_tunnel/{id-2}/token" ),
407+
LIST_TUNNEL_CONNECTIONS( GET, "accounts/{id-1}/cfd_tunnel/{id-2}/connections" ),
408+
DELETE_TUNNEL_CONNECTIONS( DELETE, "accounts/{id-1}/cfd_tunnel/{id-2}/connections" ),
409+
410+
// Access Service Tokens (Zero Trust)
411+
LIST_ACCESS_SERVICE_TOKENS( GET, "accounts/{id-1}/access/service_tokens" ),
412+
CREATE_ACCESS_SERVICE_TOKEN( POST, "accounts/{id-1}/access/service_tokens" ),
413+
ACCESS_SERVICE_TOKEN_DETAILS( GET, "accounts/{id-1}/access/service_tokens/{id-2}" ),
414+
UPDATE_ACCESS_SERVICE_TOKEN( PUT, "accounts/{id-1}/access/service_tokens/{id-2}" ),
415+
DELETE_ACCESS_SERVICE_TOKEN( DELETE, "accounts/{id-1}/access/service_tokens/{id-2}" ),
416+
REFRESH_ACCESS_SERVICE_TOKEN( POST, "accounts/{id-1}/access/service_tokens/{id-2}/refresh" ),
417+
ROTATE_ACCESS_SERVICE_TOKEN( POST, "accounts/{id-1}/access/service_tokens/{id-2}/rotate" ),
418+
419+
// Access Applications (Zero Trust)
420+
LIST_ACCESS_APPLICATIONS( GET, "accounts/{id-1}/access/apps" ),
421+
CREATE_ACCESS_APPLICATION( POST, "accounts/{id-1}/access/apps" ),
422+
ACCESS_APPLICATION_DETAILS( GET, "accounts/{id-1}/access/apps/{id-2}" ),
423+
UPDATE_ACCESS_APPLICATION( PUT, "accounts/{id-1}/access/apps/{id-2}" ),
424+
DELETE_ACCESS_APPLICATION( DELETE, "accounts/{id-1}/access/apps/{id-2}" ),
425+
REVOKE_ACCESS_APPLICATION_TOKENS( POST, "accounts/{id-1}/access/apps/{id-2}/revoke_tokens" );
426+
427+
private final HttpMethod httpMethod;
428+
private final String additionalPath;
400429

401430
Category( HttpMethod httpMethod, String additionalPath ) {
402431
this.httpMethod = httpMethod;
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/*
2+
* Copyright (c) RoboFlax. All rights reserved.
3+
* Use is subject to license terms.
4+
*/
5+
package eu.roboflax.cloudflare.objects.access;
6+
7+
import com.google.gson.annotations.Expose;
8+
import com.google.gson.annotations.SerializedName;
9+
import eu.roboflax.cloudflare.objects.Identifiable;
10+
import lombok.Getter;
11+
import lombok.Setter;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
13+
14+
import java.util.List;
15+
16+
/**
17+
* Represents a Cloudflare Access Application (Zero Trust).
18+
* Access applications define the resources protected by Cloudflare Access.
19+
*
20+
* @see <a href="https://developers.cloudflare.com/api/resources/zero_trust/subresources/access/subresources/applications/">Cloudflare API</a>
21+
*/
22+
@Getter
23+
@Setter
24+
public class AccessApplication implements Identifiable {
25+
26+
@SerializedName("id")
27+
@Expose
28+
private String id;
29+
30+
@SerializedName("aud")
31+
@Expose
32+
private String aud;
33+
34+
@SerializedName("name")
35+
@Expose
36+
private String name;
37+
38+
@SerializedName("domain")
39+
@Expose
40+
private String domain;
41+
42+
@SerializedName("type")
43+
@Expose
44+
private String type;
45+
46+
@SerializedName("session_duration")
47+
@Expose
48+
private String sessionDuration;
49+
50+
@SerializedName("allowed_idps")
51+
@Expose
52+
private List<String> allowedIdps;
53+
54+
@SerializedName("auto_redirect_to_identity")
55+
@Expose
56+
private Boolean autoRedirectToIdentity;
57+
58+
@SerializedName("enable_binding_cookie")
59+
@Expose
60+
private Boolean enableBindingCookie;
61+
62+
@SerializedName("http_only_cookie_attribute")
63+
@Expose
64+
private Boolean httpOnlyCookieAttribute;
65+
66+
@SerializedName("same_site_cookie_attribute")
67+
@Expose
68+
private String sameSiteCookieAttribute;
69+
70+
@SerializedName("logo_url")
71+
@Expose
72+
private String logoUrl;
73+
74+
@SerializedName("skip_interstitial")
75+
@Expose
76+
private Boolean skipInterstitial;
77+
78+
@SerializedName("app_launcher_visible")
79+
@Expose
80+
private Boolean appLauncherVisible;
81+
82+
@SerializedName("service_auth_401_redirect")
83+
@Expose
84+
private Boolean serviceAuth401Redirect;
85+
86+
@SerializedName("custom_deny_message")
87+
@Expose
88+
private String customDenyMessage;
89+
90+
@SerializedName("custom_deny_url")
91+
@Expose
92+
private String customDenyUrl;
93+
94+
@SerializedName("custom_non_identity_deny_url")
95+
@Expose
96+
private String customNonIdentityDenyUrl;
97+
98+
@SerializedName("tags")
99+
@Expose
100+
private List<String> tags;
101+
102+
@SerializedName("cors_headers")
103+
@Expose
104+
private CorsHeaders corsHeaders;
105+
106+
@SerializedName("created_at")
107+
@Expose
108+
private String createdAt;
109+
110+
@SerializedName("updated_at")
111+
@Expose
112+
private String updatedAt;
113+
114+
@Getter
115+
@Setter
116+
public static class CorsHeaders {
117+
@SerializedName("allowed_methods")
118+
@Expose
119+
private List<String> allowedMethods;
120+
121+
@SerializedName("allowed_origins")
122+
@Expose
123+
private List<String> allowedOrigins;
124+
125+
@SerializedName("allowed_headers")
126+
@Expose
127+
private List<String> allowedHeaders;
128+
129+
@SerializedName("allow_all_methods")
130+
@Expose
131+
private Boolean allowAllMethods;
132+
133+
@SerializedName("allow_all_origins")
134+
@Expose
135+
private Boolean allowAllOrigins;
136+
137+
@SerializedName("allow_all_headers")
138+
@Expose
139+
private Boolean allowAllHeaders;
140+
141+
@SerializedName("allow_credentials")
142+
@Expose
143+
private Boolean allowCredentials;
144+
145+
@SerializedName("max_age")
146+
@Expose
147+
private Integer maxAge;
148+
}
149+
150+
@Override
151+
public String toString() {
152+
return new ToStringBuilder(this)
153+
.append("id", id)
154+
.append("name", name)
155+
.append("domain", domain)
156+
.append("type", type)
157+
.append("sessionDuration", sessionDuration)
158+
.append("createdAt", createdAt)
159+
.toString();
160+
}
161+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (c) RoboFlax. All rights reserved.
3+
* Use is subject to license terms.
4+
*/
5+
package eu.roboflax.cloudflare.objects.access;
6+
7+
import com.google.gson.annotations.Expose;
8+
import com.google.gson.annotations.SerializedName;
9+
import eu.roboflax.cloudflare.objects.Identifiable;
10+
import lombok.Getter;
11+
import lombok.Setter;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
13+
14+
/**
15+
* Represents a Cloudflare Access Service Token (Zero Trust).
16+
* Service tokens allow automated systems to reach applications protected by Access.
17+
*
18+
* @see <a href="https://developers.cloudflare.com/api/resources/zero_trust/subresources/access/subresources/service_tokens/">Cloudflare API</a>
19+
*/
20+
@Getter
21+
@Setter
22+
public class AccessServiceToken implements Identifiable {
23+
24+
@SerializedName("id")
25+
@Expose
26+
private String id;
27+
28+
@SerializedName("name")
29+
@Expose
30+
private String name;
31+
32+
@SerializedName("client_id")
33+
@Expose
34+
private String clientId;
35+
36+
/**
37+
* Only returned when creating or rotating a token.
38+
* Store this securely - it cannot be retrieved again.
39+
*/
40+
@SerializedName("client_secret")
41+
@Expose
42+
private String clientSecret;
43+
44+
@SerializedName("created_at")
45+
@Expose
46+
private String createdAt;
47+
48+
@SerializedName("updated_at")
49+
@Expose
50+
private String updatedAt;
51+
52+
@SerializedName("expires_at")
53+
@Expose
54+
private String expiresAt;
55+
56+
@SerializedName("duration")
57+
@Expose
58+
private String duration;
59+
60+
@Override
61+
public String toString() {
62+
return new ToStringBuilder(this)
63+
.append("id", id)
64+
.append("name", name)
65+
.append("clientId", clientId)
66+
.append("createdAt", createdAt)
67+
.append("expiresAt", expiresAt)
68+
.append("duration", duration)
69+
.toString();
70+
}
71+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) RoboFlax. All rights reserved.
3+
* Use is subject to license terms.
4+
*/
5+
package eu.roboflax.cloudflare.objects.tunnel;
6+
7+
import com.google.gson.annotations.Expose;
8+
import com.google.gson.annotations.SerializedName;
9+
import eu.roboflax.cloudflare.objects.Identifiable;
10+
import lombok.Getter;
11+
import lombok.Setter;
12+
import org.apache.commons.lang3.builder.ToStringBuilder;
13+
14+
import java.util.List;
15+
16+
/**
17+
* Represents a Cloudflare Tunnel (Zero Trust).
18+
*
19+
* @see <a href="https://developers.cloudflare.com/api/resources/zero_trust/subresources/tunnels/">Cloudflare API</a>
20+
*/
21+
@Getter
22+
@Setter
23+
public class Tunnel implements Identifiable {
24+
25+
@SerializedName("id")
26+
@Expose
27+
private String id;
28+
29+
@SerializedName("account_tag")
30+
@Expose
31+
private String accountTag;
32+
33+
@SerializedName("name")
34+
@Expose
35+
private String name;
36+
37+
@SerializedName("status")
38+
@Expose
39+
private String status;
40+
41+
@SerializedName("created_at")
42+
@Expose
43+
private String createdAt;
44+
45+
@SerializedName("deleted_at")
46+
@Expose
47+
private String deletedAt;
48+
49+
@SerializedName("conns_active_at")
50+
@Expose
51+
private String connsActiveAt;
52+
53+
@SerializedName("conns_inactive_at")
54+
@Expose
55+
private String connsInactiveAt;
56+
57+
@SerializedName("tun_type")
58+
@Expose
59+
private String tunType;
60+
61+
@SerializedName("metadata")
62+
@Expose
63+
private Object metadata;
64+
65+
@SerializedName("connections")
66+
@Expose
67+
private List<TunnelConnection> connections;
68+
69+
@Override
70+
public String toString() {
71+
return new ToStringBuilder(this)
72+
.append("id", id)
73+
.append("accountTag", accountTag)
74+
.append("name", name)
75+
.append("status", status)
76+
.append("createdAt", createdAt)
77+
.append("tunType", tunType)
78+
.toString();
79+
}
80+
}

0 commit comments

Comments
 (0)