[skip ci] rename parameter sudo in createUser
This commit is contained in:
parent
1cfe32bd08
commit
592dc53cc7
2 changed files with 11 additions and 14 deletions
|
@ -25,14 +25,14 @@ fun Prov.userExists(userName: String): Boolean {
|
||||||
fun Prov.createUser(
|
fun Prov.createUser(
|
||||||
userName: String,
|
userName: String,
|
||||||
password: Secret? = null,
|
password: Secret? = null,
|
||||||
sudo: Boolean = false,
|
userCanSudoWithoutPassword: Boolean = false,
|
||||||
copyAuthorizedSshKeysFromCurrentUser: Boolean = false
|
copyAuthorizedSshKeysFromCurrentUser: Boolean = false
|
||||||
): ProvResult = task {
|
): ProvResult = task {
|
||||||
if (!userExists(userName)) {
|
if (!userExists(userName)) {
|
||||||
cmd("sudo adduser --gecos \"First Last,RoomNumber,WorkPhone,HomePhone\" --disabled-password --home /home/$userName $userName")
|
cmd("sudo adduser --gecos \"First Last,RoomNumber,WorkPhone,HomePhone\" --disabled-password --home /home/$userName $userName")
|
||||||
}
|
}
|
||||||
password?.let { cmdNoLog("sudo echo \"$userName:${password.plain()}\" | sudo chpasswd") } ?: ProvResult(true)
|
password?.let { cmdNoLog("sudo echo \"$userName:${password.plain()}\" | sudo chpasswd") } ?: ProvResult(true)
|
||||||
if (sudo) {
|
if (userCanSudoWithoutPassword) {
|
||||||
makeUserSudoerWithNoSudoPasswordRequired(userName)
|
makeUserSudoerWithNoSudoPasswordRequired(userName)
|
||||||
}
|
}
|
||||||
val authorizedKeysFile = userHome() + ".ssh/authorized_keys"
|
val authorizedKeysFile = userHome() + ".ssh/authorized_keys"
|
||||||
|
|
|
@ -5,10 +5,7 @@ import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.creat
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContent
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.fileContent
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.*
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.keys.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSourceType
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.secret.SecretSourceType
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.configureUser
|
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.*
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.createUser
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.userExists
|
|
||||||
import org.domaindrivenarchitecture.provs.framework.ubuntu.user.base.userIsInGroupSudo
|
|
||||||
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ContainerTest
|
||||||
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
import org.domaindrivenarchitecture.provs.test.tags.ExtensiveContainerTest
|
||||||
|
@ -58,24 +55,24 @@ internal class ProvisionUserKtTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ContainerTest
|
@ContainerTest
|
||||||
fun createUserWithSudo() {
|
fun createUserWithSudoAndCopiedSshKey() {
|
||||||
// given
|
// given
|
||||||
val a = defaultTestContainer()
|
val prov = defaultTestContainer()
|
||||||
val newUser = "testnewsudouser3"
|
val newUser = "testnewsudouser4"
|
||||||
a.task {
|
prov.task {
|
||||||
createDir(".ssh")
|
createDir(".ssh")
|
||||||
createFile("~/.ssh/authorized_keys", "newdummykey")
|
createFile("~/.ssh/authorized_keys", "newdummykey")
|
||||||
}
|
}
|
||||||
|
|
||||||
// when
|
// when
|
||||||
val res = a.createUser(newUser, sudo = true, copyAuthorizedSshKeysFromCurrentUser = true)
|
val res = prov.createUser(newUser, userCanSudoWithoutPassword = true, copyAuthorizedSshKeysFromCurrentUser = true)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertTrue(res.success)
|
assertTrue(res.success)
|
||||||
assertTrue(a.userExists(newUser))
|
assertTrue(prov.userExists(newUser))
|
||||||
assertEquals("newdummykey", a.fileContent("/home/$newUser/.ssh/authorized_keys", sudo = true))
|
assertEquals("newdummykey", prov.fileContent("/home/$newUser/.ssh/authorized_keys", sudo = true))
|
||||||
|
|
||||||
// new user can sudo
|
// new user can sudo
|
||||||
assertTrue(a.cmd("sudo -H -u $newUser bash -c 'sudo echo \"I am \$USER, with uid \$UID\"' ").success)
|
assertTrue(prov.cmd("sudo -H -u $newUser bash -c 'sudo echo \"I am \$USER, with uid \$UID\"' ").success)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue