Skip to content

Commit

Permalink
Prep for 2.3.0 release (#96)
Browse files Browse the repository at this point in the history
* Implemented UserAgentFilter and Policy on CreateTunnel and from config. Rename TunnelIPRestrictions classes (bug), not plural in ngrok docs. Add us-cal-1 region. Ensure list in Builders are immutable. Minor documentation updates.
  • Loading branch information
alexdlaird committed Apr 8, 2024
1 parent 6d1b3ea commit cd588dc
Show file tree
Hide file tree
Showing 16 changed files with 698 additions and 233 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:

env:
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
NGROK_DOMAIN: ${{ secrets.NGROK_DOMAIN }}
NGROK_HTTP_EDGE: ${{ secrets.NGROK_HTTP_EDGE }}
NGROK_TCP_EDGE: ${{ secrets.NGROK_TCP_EDGE }}
NGROK_API_KEY: ${{ secrets.NGROK_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:

env:
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
NGROK_DOMAIN: ${{ secrets.NGROK_DOMAIN }}
NGROK_HTTP_EDGE: ${{ secrets.NGROK_HTTP_EDGE }}
NGROK_TCP_EDGE: ${{ secrets.NGROK_TCP_EDGE }}
NGROK_API_KEY: ${{ secrets.NGROK_API_KEY }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:

env:
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
NGROK_DOMAIN: ${{ secrets.NGROK_DOMAIN }}
NGROK_HTTP_EDGE: ${{ secrets.NGROK_HTTP_EDGE }}
NGROK_TCP_EDGE: ${{ secrets.NGROK_TCP_EDGE }}
NGROK_API_KEY: ${{ secrets.NGROK_API_KEY }}
Expand Down
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https://github.com/alexdlaird/java-ngrok/compare/2.2.16...HEAD)
## [Unreleased](https://github.com/alexdlaird/java-ngrok/compare/2.3.0...HEAD)

## [2.3.0](https://github.com/alexdlaird/java-ngrok/compare/2.2.16...2.3.0) - 2024-04-08
### Added
- Support for `domain ` configuration when building [CreateTunnel](https://javadoc.io/static/com.github.alexdlaird/java-ngrok/2.2.17/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/CreateTunnel.Builder.html#withDomain(java.lang.String)).
- Support for `domain ` configuration when building [CreateTunnel](https://javadoc.io/static/com.github.alexdlaird/java-ngrok/2.3.0/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/CreateTunnel.Builder.html#withDomain(java.lang.String)).
- Support for `user_agent_filter ` configuration when building [CreateTunnel](https://javadoc.io/static/com.github.alexdlaird/java-ngrok/2.3.0/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/CreateTunnel.Builder.html#withUserAgentFilter(com.github.alexdlaird.ngrok.protocol.TunnelUserAgentFilter)).
- Support for `policy ` configuration when building [CreateTunnel](https://javadoc.io/static/com.github.alexdlaird/java-ngrok/2.3.0/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/CreateTunnel.Builder.html#withPolicy(com.github.alexdlaird.ngrok.protocol.TunnelPolicy)).
- `us-cal-1` to [Region](https://javadoc.io/doc/com.github.alexdlaird/java-ngrok/2.3.0/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/Region.html).
- Test cases for TLS tunnels.
- Build improvements.

### Fixed
- `ngrok` config value `ip_restriction` was incorrectly plural in previous versions of `java-ngrok`. Value is now interpreted as singular to align with [the `ngrok` docs](https://ngrok.com/docs/agent/config/#http-configuration), and classes and methods associated with it, like [TunnelIPRestriction](https://javadoc.io/doc/com.github.alexdlaird/java-ngrok/2.3.0/com.github.alexdlaird.ngrok/com/github/alexdlaird/ngrok/protocol/TunnelIPRestriction.html), have been renamed.

## [2.2.16](https://github.com/alexdlaird/java-ngrok/compare/2.2.15...2.2.16) - 2024-03-24
### Added
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group "com.github.alexdlaird"
version "2.2.16"
version "2.3.0"

java {
withJavadocJar()
Expand Down
137 changes: 110 additions & 27 deletions src/main/java/com/github/alexdlaird/ngrok/protocol/CreateTunnel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.alexdlaird.ngrok.NgrokClient;
import com.github.alexdlaird.ngrok.conf.JavaNgrokConfig;
import com.github.alexdlaird.ngrok.installer.NgrokVersion;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -71,8 +72,11 @@ public class CreateTunnel {
private final String terminateAt;
private final TunnelHeader requestHeader;
private final TunnelHeader responseHeader;
private final TunnelIPRestrictions ipRestrictions;
private final TunnelIPRestriction ipRestriction;
private final TunnelVerifyWebhook verifyWebhook;
private final TunnelUserAgentFilter userAgentFilter;
private final TunnelPolicy policyInbound;
private final TunnelPolicy policyOutbound;
private final List<String> labels;

private CreateTunnel(final Builder builder) {
Expand Down Expand Up @@ -103,8 +107,11 @@ private CreateTunnel(final Builder builder) {
this.terminateAt = builder.terminateAt;
this.requestHeader = builder.requestHeader;
this.responseHeader = builder.responseHeader;
this.ipRestrictions = builder.ipRestrictions;
this.ipRestriction = builder.ipRestriction;
this.verifyWebhook = builder.verifyWebhook;
this.userAgentFilter = builder.userAgentFilter;
this.policyInbound = builder.policyInbound;
this.policyOutbound = builder.policyOutbound;
this.labels = builder.labels;
}

Expand Down Expand Up @@ -301,8 +308,8 @@ public TunnelHeader getResponseHeader() {
/**
* Get the IP restrictions for the tunnel.
*/
public TunnelIPRestrictions getIpRestrictions() {
return ipRestrictions;
public TunnelIPRestriction getIpRestriction() {
return ipRestriction;
}

/**
Expand All @@ -313,7 +320,29 @@ public TunnelVerifyWebhook getVerifyWebhook() {
}

/**
* Get the labels.
* Get the UserAgent filters.
*/
public TunnelUserAgentFilter getUserAgentFilter() {
return userAgentFilter;
}

/**
* Get the inbound policy.
*/
public TunnelPolicy getPolicyInbound() {
return policyInbound;
}

/**
* Get the outbound policy.
*/
public TunnelPolicy getPolicyOutbound() {
return policyOutbound;
}

/**
* Get the labels. Note that labels can only be provisioned from the <code>ngrok</code> config file and not the
* Builder.
*/
public List<String> getLabels() {
return labels;
Expand Down Expand Up @@ -355,8 +384,11 @@ public static class Builder {
private String terminateAt;
private TunnelHeader requestHeader;
private TunnelHeader responseHeader;
private TunnelIPRestrictions ipRestrictions;
private TunnelIPRestriction ipRestriction;
private TunnelVerifyWebhook verifyWebhook;
private TunnelUserAgentFilter userAgentFilter;
private TunnelPolicy policyInbound;
private TunnelPolicy policyOutbound;
private List<String> labels;

/**
Expand Down Expand Up @@ -415,8 +447,11 @@ public Builder(final CreateTunnel createTunnel) {
this.terminateAt = createTunnel.terminateAt;
this.requestHeader = createTunnel.requestHeader;
this.responseHeader = createTunnel.responseHeader;
this.ipRestrictions = createTunnel.ipRestrictions;
this.ipRestriction = createTunnel.ipRestriction;
this.verifyWebhook = createTunnel.verifyWebhook;
this.userAgentFilter = createTunnel.userAgentFilter;
this.policyInbound = createTunnel.policyInbound;
this.policyOutbound = createTunnel.policyOutbound;
}

/**
Expand Down Expand Up @@ -587,7 +622,7 @@ public Builder withSchemes(final List<String> schemes) {
throw new IllegalArgumentException("Cannot set both 'schemes' and 'bindTls'.");
}

this.schemes = schemes;
this.schemes = Collections.unmodifiableList(schemes);
return this;
}

Expand All @@ -601,98 +636,122 @@ public Builder withBasicAuth(final List<String> basicAuth) {
throw new IllegalArgumentException("Cannot set both 'auth' and 'basicAuth'.");
}

this.basicAuth = basicAuth;
this.basicAuth = Collections.unmodifiableList(basicAuth);
return this;
}

/**
* Set of OAuth settings to enable OAuth authentication on the tunnel endpoint.
*/
public Builder withOAuth(TunnelOAuth oauth) {
public Builder withOAuth(final TunnelOAuth oauth) {
this.oauth = oauth;
return this;
}

/**
* The circuit breaker trigger.
*/
public Builder withCircuitBreaker(Float circuitBreaker) {
public Builder withCircuitBreaker(final Float circuitBreaker) {
this.circuitBreaker = circuitBreaker;
return this;
}

/**
* Whether compression is enabled on this tunnel.
*/
public Builder withCompression(Boolean compression) {
public Builder withCompression(final Boolean compression) {
this.compression = compression;
return this;
}

/**
* The path to the TLS certificate authority to verify client certs.
*/
public Builder withMutualTlsCas(String mutualTlsCas) {
public Builder withMutualTlsCas(final String mutualTlsCas) {
this.mutualTlsCas = mutualTlsCas;
return this;
}

/**
* The proxy proto.
*/
public Builder withProxyProto(String proxyProto) {
public Builder withProxyProto(final String proxyProto) {
this.proxyProto = proxyProto;
return this;
}

/**
* Whether ingress connections are converted to TCP upstream.
*/
public Builder withWebsocketTcpConverter(Boolean websocketTcpConverter) {
public Builder withWebsocketTcpConverter(final Boolean websocketTcpConverter) {
this.websocketTcpConverter = websocketTcpConverter;
return this;
}

/**
* The termination point.
*/
public Builder withTerminateAt(String terminateAt) {
public Builder withTerminateAt(final String terminateAt) {
this.terminateAt = terminateAt;
return this;
}

/**
* The Headers to be added or removed from requests.
*/
public Builder withRequestHeader(TunnelHeader requestHeader) {
public Builder withRequestHeader(final TunnelHeader requestHeader) {
this.requestHeader = requestHeader;
return this;
}

/**
* The Headers to be added or removed from responses.
*/
public Builder withResponseHeader(TunnelHeader responseHeader) {
public Builder withResponseHeader(final TunnelHeader responseHeader) {
this.responseHeader = responseHeader;
return this;
}

/**
* The IP restrictions for the tunnel.
*/
public Builder withIpRestrictions(TunnelIPRestrictions ipRestrictions) {
this.ipRestrictions = ipRestrictions;
public Builder withIpRestriction(final TunnelIPRestriction ipRestriction) {
this.ipRestriction = ipRestriction;
return this;
}

/**
* The signature for webhooks.
*/
public Builder withVerifyWebhook(TunnelVerifyWebhook verifyWebhook) {
public Builder withVerifyWebhook(final TunnelVerifyWebhook verifyWebhook) {
this.verifyWebhook = verifyWebhook;
return this;
}

/**
* The UserAgent filter for the tunnel.
*/
public Builder withUserAgentFilter(final TunnelUserAgentFilter userAgentFilter) {
this.userAgentFilter = userAgentFilter;
return this;
}

/**
* The inbound policy for the tunnel.
*/
public Builder withPolicyInbound(final TunnelPolicy policyInbound) {
this.policyInbound = policyInbound;
return this;
}

/**
* The outbound policy for the tunnel.
*/
public Builder withPolicyOutbound(final TunnelPolicy policyOutbound) {
this.policyOutbound = policyOutbound;
return this;
}

/**
* Populate any <code>null</code> attributes (except for <code>name</code>) in this Builder with values from
* the given <code>tunnelDefinition</code>.
Expand Down Expand Up @@ -744,10 +803,14 @@ public Builder withTunnelDefinition(Map<String, Object> tunnelDefinition) {
this.metadata = (String) tunnelDefinition.get("metadata");
}
if (isNull(this.schemes) && tunnelDefinition.containsKey("schemes")) {
this.schemes = (List<String>) tunnelDefinition.get("schemes");
this.schemes = Collections.unmodifiableList(
(List<String>) tunnelDefinition.get("schemes")
);
}
if (isNull(this.basicAuth) && tunnelDefinition.containsKey("basic_auth")) {
this.basicAuth = (List<String>) tunnelDefinition.get("basic_auth");
this.basicAuth = Collections.unmodifiableList(
(List<String>) tunnelDefinition.get("basic_auth")
);
}
if (isNull(this.oauth) && tunnelDefinition.containsKey("oauth")) {
this.oauth = new TunnelOAuth.Builder((Map<String, Object>) tunnelDefinition.get("oauth")).build();
Expand Down Expand Up @@ -782,22 +845,42 @@ public Builder withTunnelDefinition(Map<String, Object> tunnelDefinition) {
.Builder((Map<String, Object>) tunnelDefinition.get("response_header"))
.build();
}
if (isNull(this.ipRestrictions) && tunnelDefinition.containsKey("ip_restrictions")) {
this.ipRestrictions = new TunnelIPRestrictions
.Builder((Map<String, Object>) tunnelDefinition.get("ip_restrictions"))
if (isNull(this.ipRestriction) && tunnelDefinition.containsKey("ip_restriction")) {
this.ipRestriction = new TunnelIPRestriction
.Builder((Map<String, Object>) tunnelDefinition.get("ip_restriction"))
.build();
}
if (isNull(this.verifyWebhook) && tunnelDefinition.containsKey("verify_webhook")) {
this.verifyWebhook = new TunnelVerifyWebhook
.Builder((Map<String, Object>) tunnelDefinition.get("verify_webhook"))
.build();
}
if (isNull(this.userAgentFilter) && tunnelDefinition.containsKey("user_agent_filter")) {
this.userAgentFilter = new TunnelUserAgentFilter
.Builder((Map<String, Object>) tunnelDefinition.get("user_agent_filter"))
.build();
}
if (tunnelDefinition.containsKey("policy")) {
final Map<String, Object> policy = (Map<String, Object>) tunnelDefinition.get("policy");
if (isNull(this.policyInbound) && policy.containsKey("inbound")) {
this.policyInbound = new TunnelPolicy
.Builder((Map<String, Object>) policy.get("inbound"))
.build();
}
if (isNull(this.policyOutbound) && policy.containsKey("outbound")) {
this.policyOutbound = new TunnelPolicy
.Builder((Map<String, Object>) policy.get("outbound"))
.build();
}
}
if (tunnelDefinition.containsKey("labels")) {
if (nonNull(bindTls)) {
throw new IllegalArgumentException("'bindTls' cannot be set when 'labels' is also on the "
+ "tunnel definition.");
}
this.labels = (List<String>) tunnelDefinition.get("labels");
this.labels = Collections.unmodifiableList(
(List<String>) tunnelDefinition.get("labels")
);
}

// Returning this to allow chained configuration of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum Region {

@SerializedName("us")
US,
@SerializedName("us-cal-1")
US_CAL_1,
@SerializedName("eu")
EU,
@SerializedName("ap")
Expand Down
Loading

0 comments on commit cd588dc

Please sign in to comment.