Skip to content

Commit

Permalink
Ensure public network is explicitly disabled when needed
Browse files Browse the repository at this point in the history
Closes: #53

Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
  • Loading branch information
rkosegi committed Sep 22, 2022
1 parent e903c33 commit 5cb45cb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import cloud.dnation.jenkins.plugins.hetzner.client.HetznerApi;
import cloud.dnation.jenkins.plugins.hetzner.client.IdentifiableResource;
import cloud.dnation.jenkins.plugins.hetzner.client.Meta;
import cloud.dnation.jenkins.plugins.hetzner.client.PublicNetRequest;
import cloud.dnation.jenkins.plugins.hetzner.client.ServerDetail;
import cloud.dnation.jenkins.plugins.hetzner.client.SshKeyDetail;
import cloud.dnation.jenkins.plugins.hetzner.connect.ConnectivityType;
Expand Down Expand Up @@ -241,6 +242,12 @@ public HetznerServerInfo createServer(HetznerServerAgent agent) {
} else {
networkId = getNetworkIdForLabelExpression(agent.getTemplate().getNetwork());
}
if (ct == ConnectivityType.PRIVATE) {
final PublicNetRequest pn = new PublicNetRequest();
pn.setEnableIpv4(false);
pn.setEnableIpv6(false);
createServerRequest.setPublicNet(pn);
}
createServerRequest.setNetworks(Lists.newArrayList(networkId));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,7 @@
package cloud.dnation.jenkins.plugins.hetzner.connect;

import hudson.model.AbstractDescribableImpl;
import lombok.Getter;

public abstract class AbstractConnectivity extends AbstractDescribableImpl<AbstractConnectivity> {

public AbstractConnectivity(ConnectivityType type) {
this.type = type;
}

@Getter
protected final transient ConnectivityType type;
public abstract ConnectivityType getType();
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import lombok.NoArgsConstructor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

@NoArgsConstructor(onConstructor = @__({@DataBoundConstructor}))
public class Both extends AbstractConnectivity{
@DataBoundConstructor
public Both() {
super(ConnectivityType.BOTH);
public ConnectivityType getType() {
return ConnectivityType.BOTH;
}

@Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import lombok.NoArgsConstructor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

@NoArgsConstructor(onConstructor = @__({@DataBoundConstructor}))
public class PrivateOnly extends AbstractConnectivity {
@DataBoundConstructor
public PrivateOnly() {
super(ConnectivityType.PRIVATE);
public ConnectivityType getType() {
return ConnectivityType.PRIVATE;
}

@Extension
@Symbol("private-only")
public static final class DescriptorImpl extends Descriptor<AbstractConnectivity> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
import hudson.model.Descriptor;
import lombok.NoArgsConstructor;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;

public class PublicOnly extends AbstractConnectivity{
@DataBoundConstructor
public PublicOnly() {
super(ConnectivityType.PUBLIC);
@NoArgsConstructor(onConstructor = @__({@DataBoundConstructor}))
public class PublicOnly extends AbstractConnectivity {
public ConnectivityType getType() {
return ConnectivityType.PUBLIC;
}

@Extension
Expand Down

0 comments on commit 5cb45cb

Please sign in to comment.