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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ComputeEngineInstance extends AbstractCloudSlave {
private final WindowsConfiguration windowsConfig;
private final boolean createSnapshot;
private final boolean oneShot;
private final boolean blockProjectSSHKeys;
private final boolean ignoreProxy;
private final String javaExecPath;
private final GoogleKeyPair sshKeyPair;
Expand All @@ -70,6 +71,7 @@ private ComputeEngineInstance(
@Nullable WindowsConfiguration windowsConfig,
boolean createSnapshot,
boolean oneShot,
boolean blockProjectSSHKeys,
boolean ignoreProxy,
int numExecutors,
Mode mode,
Expand Down Expand Up @@ -99,6 +101,7 @@ private ComputeEngineInstance(
this.windowsConfig = windowsConfig;
this.createSnapshot = createSnapshot;
this.oneShot = oneShot;
this.blockProjectSSHKeys = blockProjectSSHKeys;
this.ignoreProxy = ignoreProxy;
this.javaExecPath = javaExecPath;
this.sshKeyPair = sshKeyPair;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
@Log
public class InstanceConfiguration implements Describable<InstanceConfiguration> {
public static final String GUEST_ATTRIBUTES_METADATA_KEY = "enable-guest-attributes";
public static final String BLOCK_PROJECT_SSH_KEYS_METADATA_KEY = "block-project-ssh-keys";
public static final String SSH_METADATA_KEY = "ssh-keys";
public static final Long DEFAULT_BOOT_DISK_SIZE_GB = 10L;
public static final Integer DEFAULT_NUM_EXECUTORS = 1;
Expand Down Expand Up @@ -143,6 +144,7 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
private String bootDiskSizeGbStr;
private boolean oneShot;
private String template;
private boolean blockProjectSSHKeys;
// Optional not possible due to serialization requirement
@Nullable private WindowsConfiguration windowsConfiguration;
private boolean createSnapshot;
Expand Down Expand Up @@ -230,6 +232,11 @@ public void setCreateSnapshot(boolean createSnapshot) {
this.createSnapshot = createSnapshot && this.oneShot;
}

@DataBoundSetter
public void setBlockProjectSSHKeys(boolean blockProjectSSHKeys) {
this.blockProjectSSHKeys = blockProjectSSHKeys;
}

public static Integer intOrDefault(String toParse, Integer defaultTo) {
Integer toReturn;
try {
Expand Down Expand Up @@ -342,6 +349,7 @@ public ComputeEngineInstance provision() throws IOException {
.launchTimeout(getLaunchTimeoutMillis())
.javaExecPath(javaExecPath)
.sshKeyPair(sshKeyPair)
.blockProjectSSHKeys(blockProjectSSHKeys)
.build();
} catch (Descriptor.FormException fe) {
log.log(Level.WARNING, "Error provisioning instance: " + fe.getMessage(), fe);
Expand Down Expand Up @@ -430,6 +438,12 @@ private Metadata newMetadata() {
metadata
.getItems()
.add(new Metadata.Items().setKey(GUEST_ATTRIBUTES_METADATA_KEY).setValue("TRUE"));
metadata
.getItems()
.add(
new Metadata.Items()
.setKey(BLOCK_PROJECT_SSH_KEYS_METADATA_KEY)
.setValue(String.valueOf(blockProjectSSHKeys)));
return metadata;
}

Expand Down Expand Up @@ -975,6 +989,7 @@ public InstanceConfiguration build() {
instanceConfiguration.setRemoteFs(this.remoteFs);
instanceConfiguration.setJavaExecPath(this.javaExecPath);
instanceConfiguration.setCloud(this.cloud);
instanceConfiguration.setBlockProjectSSHKeys(this.blockProjectSSHKeys);
if (googleLabels != null) {
instanceConfiguration.appendLabels(this.googleLabels);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,16 @@ public void testInstanceModel() throws Exception {
assertTrue(guestAttributes.isPresent());
assertEquals(guestAttributes.get(), "TRUE");

Optional<String> blockProjectSSHKeys =
instance.getMetadata().getItems().stream()
.filter(
item ->
item.getKey().equals(InstanceConfiguration.BLOCK_PROJECT_SSH_KEYS_METADATA_KEY))
.map(item -> item.getValue())
.findFirst();
assertTrue(blockProjectSSHKeys.isPresent());
assertEquals("false", blockProjectSSHKeys.get());

// Network
assertEquals(SUBNETWORK_NAME, instance.getNetworkInterfaces().get(0).getSubnetwork());
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static void init() throws Exception {
.numExecutorsStr(NUM_EXECUTORS)
.labels(LABEL)
.oneShot(false)
.blockProjectSSHKeys(true)
.createSnapshot(false)
.template(NULL_TEMPLATE)
.googleLabels(label)
Expand Down Expand Up @@ -142,4 +143,17 @@ public void testGuestAttributesEnabled() {
assertTrue(guestAttributes.isPresent());
assertEquals(guestAttributes.get(), "TRUE");
}

@Test
public void testBlockProjectSSHKeysEnabled() {
Optional<String> blockProjectSSHKeys =
instance.getMetadata().getItems().stream()
.filter(
item ->
item.getKey().equals(InstanceConfiguration.BLOCK_PROJECT_SSH_KEYS_METADATA_KEY))
.map(item -> item.getValue())
.findFirst();
assertTrue(blockProjectSSHKeys.isPresent());
assertEquals("true", blockProjectSSHKeys.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jenkins:
remoteFs: agent
javaExecPath: "java"
oneShot: true
blockProjectSSHKeys: false
createSnapshot: false
region: "https://www.googleapis.com/compute/v1/projects/gce-jenkins/regions/europe-west1"
zone: "https://www.googleapis.com/compute/v1/projects/gce-jenkins/zones/europe-west1-a"
Expand Down