From f4d657aabd8cd0e8b22a2fd579af75409e5d7d80 Mon Sep 17 00:00:00 2001 From: Andrea Turli Date: Tue, 8 Jan 2013 19:17:29 +0100 Subject: [PATCH] added support to assign passwordless right to the default node user --- .../virtualbox/functions/NodeCreator.java | 13 +++-- .../statements/PasswordlessSudo.java | 54 +++++++++++++++++++ .../statements/PasswordlessTest.java | 37 +++++++++++++ 3 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 labs/virtualbox/src/main/java/org/jclouds/virtualbox/statements/PasswordlessSudo.java create mode 100644 labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/PasswordlessTest.java diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java index 4ce43c55ba..f1d0326e1c 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/NodeCreator.java @@ -49,6 +49,7 @@ import org.jclouds.virtualbox.domain.NetworkSpec; import org.jclouds.virtualbox.domain.NodeSpec; import org.jclouds.virtualbox.domain.VmSpec; import org.jclouds.virtualbox.statements.DeleteGShadowLock; +import org.jclouds.virtualbox.statements.PasswordlessSudo; import org.jclouds.virtualbox.util.MachineController; import org.jclouds.virtualbox.util.MachineUtils; import org.jclouds.virtualbox.util.NetworkUtils; @@ -157,15 +158,19 @@ public class NodeCreator implements Function(cloned, - cloneName, credentials); + return new NodeAndInitialCredentials(cloned, cloneName, credentials); + } private NodeMetadata buildPartialNodeMetadata(IMachine clone) { @@ -180,7 +185,7 @@ public class NodeCreator implements Function functionDependencies(OsFamily family) { + return ImmutableList.of(); + } + + @Override + public String render(OsFamily family) { + if (checkNotNull(family, "family") == OsFamily.WINDOWS) + throw new UnsupportedOperationException("windows not yet implemented"); + return String.format("touch /etc/sudoers.d/passwordless && echo \"%s ALL = NOPASSWD: ALL\" > /etc/sudoers.d/passwordless && chmod 0440 /etc/sudoers.d/passwordless", user); + } + +} diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/PasswordlessTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/PasswordlessTest.java new file mode 100644 index 0000000000..3c4c235f4e --- /dev/null +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/statements/PasswordlessTest.java @@ -0,0 +1,37 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.jclouds.virtualbox.statements; + +import static org.testng.Assert.assertEquals; + +import org.jclouds.scriptbuilder.domain.OsFamily; +import org.testng.annotations.Test; + +public class PasswordlessTest { + + + @Test + public void testApplyPasswordlessSudo() { + PasswordlessSudo passwordlessSudo = new PasswordlessSudo("barack"); + assertEquals(passwordlessSudo.render(OsFamily.UNIX), + "touch /etc/sudoers.d/passwordless && echo \"barack ALL = NOPASSWD: ALL\" > /etc/sudoers.d/passwordless && chmod 0440 /etc/sudoers.d/passwordless"); + } + +}