com.github.alexdlaird.ngrok.protocol.TunnelIPRestriction Maven / Gradle / Ivy
/*
* Copyright (c) 2021-2024 Alex Laird
*
* SPDX-License-Identifier: MIT
*/
package com.github.alexdlaird.ngrok.protocol;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* An object that represents IP restriction for a {@link CreateTunnel}.
*/
public class TunnelIPRestriction {
private final List allowCidrs;
private final List denyCidrs;
private TunnelIPRestriction(final Builder builder) {
this.allowCidrs = builder.allowCidrs;
this.denyCidrs = builder.denyCidrs;
}
/**
* Get the list of allowed CIDRs.
*/
public List getAllowCidrs() {
return allowCidrs;
}
/**
* Get the list of denied CIDRs.
*/
public List getDenyCidrs() {
return denyCidrs;
}
/**
* Builder for a {@link TunnelIPRestriction}.
*/
public static class Builder {
private List allowCidrs;
private List denyCidrs;
/**
* Construct a TunnelIPRestriction Builder.
*/
public Builder() {
}
/**
* Construct a TunnelIPRestriction Builder from tunnel definition of ip_restriction
.
*
* @param tunnelIPRestrictionDefinition The map of Tunnel IP restriction attributes.
*/
public Builder(final Map tunnelIPRestrictionDefinition) {
if (tunnelIPRestrictionDefinition.containsKey("allow_cidrs")) {
this.allowCidrs = Collections.unmodifiableList(
(List) tunnelIPRestrictionDefinition.get("allow_cidrs")
);
}
if (tunnelIPRestrictionDefinition.containsKey("deny_cidrs")) {
this.denyCidrs = Collections.unmodifiableList(
(List) tunnelIPRestrictionDefinition.get("deny_cidrs")
);
}
}
/**
* The list of allowed CIDRs.
*/
public TunnelIPRestriction.Builder withAllowCidrs(final List allowCidrs) {
this.allowCidrs = Collections.unmodifiableList(allowCidrs);
return this;
}
/**
* The list of denied CIDRs.
*/
public TunnelIPRestriction.Builder withDenyCidrs(final List denyCidrs) {
this.denyCidrs = Collections.unmodifiableList(denyCidrs);
return this;
}
/**
* Build the {@link TunnelIPRestriction}.
*/
public TunnelIPRestriction build() {
return new TunnelIPRestriction(this);
}
}
}