Skip to content

Commit

Permalink
#6 - Support Unix OS - use socat and su
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay.Pianikov authored and Nikolay.Pianikov committed Nov 23, 2016
1 parent 3604d3b commit 831ed3c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 26 deletions.
11 changes: 1 addition & 10 deletions cmd/runAs.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#!/bin/bash

echo param1=$1
echo param2=$2
echo param3=$3

args=$(cat "$1")
command=$2
password=$3

echo args=$args
echo command=$command
echo password=$password

echo -e "$password\n" | sudo --preserve-env --set-home --stdin $args $command
#sudo --preserve-env -set-home --stdin $args #scommand
(sleep .3; echo "$password") | socat - EXEC:'su -c $command $args',pty,ctty,setsid
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import jetbrains.buildServer.util.Converter;
import org.jetbrains.annotations.NotNull;

public class UnixSettingsGenerator implements ResourceGenerator<Settings> {
public class LinuxSettingsGenerator implements ResourceGenerator<Settings> {
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String USER_CMD_KEY = "--user";

@NotNull
@Override
Expand All @@ -18,8 +17,6 @@ public String create(@NotNull final Settings settings) {

final String user = settings.getUser();
if(!StringUtil.isEmptyOrSpaces(user)) {
sb.append(USER_CMD_KEY);
sb.append(' ');
sb.append(settings.getUser());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@
<constructor-arg type="java.lang.String" value=".cmd"/>
</bean>

<!-- Unix -->
<!-- Linux -->
<bean class="jetbrains.buildServer.runAs.agent.ShGenerator" id="shGenerator"/>
<bean class="jetbrains.buildServer.runAs.agent.UnixSettingsGenerator" id="unixSettingsGenerator"/>
<bean class="jetbrains.buildServer.runAs.agent.RunAsPlatformSpecificSetupBuilder" id="runAsUnixSetupBuilder">
<bean class="jetbrains.buildServer.runAs.agent.LinuxSettingsGenerator" id="linuxSettingsGenerator"/>
<bean class="jetbrains.buildServer.runAs.agent.RunAsPlatformSpecificSetupBuilder" id="runAsLinuxSetupBuilder">
<constructor-arg ref="beforeBuildPublisher"/>
<constructor-arg ref="unixSettingsGenerator"/>
<constructor-arg ref="linuxSettingsGenerator"/>
<constructor-arg ref="shGenerator"/>
<constructor-arg type="java.lang.String" value=".sh"/>
</bean>


<bean class="jetbrains.buildServer.runAs.agent.RunAsSetupBuilder" id="runAsSetupBuilder">
<constructor-arg ref="runAsWindowsSetupBuilder"/>
<constructor-arg ref="runAsUnixSetupBuilder"/>
<constructor-arg ref="runAsLinuxSetupBuilder"/>
</bean>

<bean class="jetbrains.buildServer.runAs.agent.RunAsBuildCommandLineProcessorAdapter" id="runAsBuildCommandLineProcessorAdapter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import static org.assertj.core.api.BDDAssertions.then;

public class UnixSettingsGeneratorTest {
public class LinuxSettingsGeneratorTest {
private static final String ourlineSeparator = System.getProperty("line.separator");
private Mockery myCtx;

Expand All @@ -24,7 +24,7 @@ public void setUp()
@Test()
public void shouldGenerateContent() {
// Given
final String expectedContent = "--user nik";
final String expectedContent = "nik";
final List<CommandLineArgument> additionalArgs = Arrays.asList(new CommandLineArgument("arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("arg 2", CommandLineArgument.Type.PARAMETER));

final ResourceGenerator<Settings> instance = createInstance();
Expand All @@ -40,6 +40,6 @@ public void shouldGenerateContent() {
@NotNull
private ResourceGenerator<Settings> createInstance()
{
return new UnixSettingsGenerator();
return new LinuxSettingsGenerator();
}
}
2 changes: 1 addition & 1 deletion runAs-agent/src/test/resources/testng-runAs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<test name="dotNet-testRunner">
<classes>
<class name="jetbrains.buildServer.runAs.agent.WindowsSettingsGeneratorTest"/>
<class name="jetbrains.buildServer.runAs.agent.UnixSettingsGeneratorTest"/>
<class name="jetbrains.buildServer.runAs.agent.LinuxSettingsGeneratorTest"/>
<class name="jetbrains.buildServer.runAs.agent.CmdGeneratorTest"/>
<class name="jetbrains.buildServer.runAs.agent.ShGeneratorTest"/>
<class name="jetbrains.buildServer.runAs.agent.ExecutableFilePublisherTest"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</style>

<tr>
<td colspan="2"><em>This build feature allows running build steps under the specified Windows user account.</em></td>
<td colspan="2"><em>This build feature allows running build steps under the specified user account.</em></td>
</tr>

<tr>
Expand All @@ -17,7 +17,7 @@
<props:textProperty name="${bean.runAsUserKey}" className="longField"/>
</div>
<span class="error" id="error_${bean.runAsUserKey}"></span>
<span class="smallNote">Specify the user name in the formats "username" or "doman\username" or "username@domain"</span>
<span class="smallNote">Specify the user name."</span>
</td>
</tr>

Expand All @@ -28,6 +28,6 @@
<props:passwordProperty name="${bean.runAsPasswordKey}" className="longField"/>
</div>
<span class="error" id="error_${bean.runAsPasswordKey}"></span>
<span class="smallNote">Specify the user's password for agents under the Windows OS and current user's password for Linux.</span>
<span class="smallNote">Specify the password.</span>
</td>
</tr>

0 comments on commit 831ed3c

Please sign in to comment.