Skip to content

Commit

Permalink
Backward compatibility with legacy config path
Browse files Browse the repository at this point in the history
  • Loading branch information
atmoz committed Jun 25, 2017
1 parent 177d7ae commit c4fd217
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This is an automated build linked with the [debian](https://hub.docker.com/_/deb

# Usage

- Required: define users as command arguments, STDIN or mounted in `/etc/sftp-users.conf`
- Required: define users as command arguments, STDIN or mounted in `/etc/sftp/users.conf`
(syntax: `user:pass[:e][:uid[:gid[:dir1[,dir2]...]]]...`).
- Set UID/GID manually for your users if you want them to make changes to
your mounted volumes with permissions matching your host filesystem.
Expand Down Expand Up @@ -74,7 +74,7 @@ OpenSSH client, run: `sftp -P 2222 foo@<host-ip>`

```
docker run \
-v /host/users.conf:/etc/sftp/sftp-users.conf:ro \
-v /host/users.conf:/etc/sftp/users.conf:ro \
-v mySftpVolume:/home \
-v /host/ssh_host_rsa_key:/etc/ssh/ssh_host_rsa_key \
-v /host/ssh_host_rsa_key.pub:/etc/ssh/ssh_host_rsa_key.pub \
Expand Down
12 changes: 10 additions & 2 deletions entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
set -e
export DEBIAN_FRONTEND=noninteractive

userConfPath="/etc/sftp/sftp-users.conf"
userConfFinalPath="/var/run/sftp/sftp-users.conf"
userConfPath="/etc/sftp/users.conf"
userConfPathLegacy="/etc/sftp-users.conf"
userConfFinalPath="/var/run/sftp/users.conf"

function printHelp() {
echo "Add users as command arguments, STDIN or mounted in $userConfPath"
Expand Down Expand Up @@ -96,8 +97,15 @@ if [ "$1" == "--readme" ]; then
exit 0
fi

# Backward compatibility with legacy config path
if [ ! -f "$userConfPath" -a -f "$userConfPathLegacy" ]; then
mkdir -p "$(dirname $userConfPath)"
ln -s "$userConfPathLegacy" "$userConfPath"
fi

# Create users only on first run
if [ ! -f "$userConfFinalPath" ]; then
mkdir -p "$(dirname $userConfFinalPath)"

# Append mounted config to final config
if [ -f "$userConfPath" ]; then
Expand Down
38 changes: 33 additions & 5 deletions tests/run
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function beforeTest() {

echo "test::$(id -u):$(id -g):dir1,dir2" >> "$tmpDir/users"
$sudo docker run \
-v "$tmpDir/users:/etc/sftp-users.conf:ro" \
-v "$tmpDir/users:/etc/sftp/users.conf:ro" \
-v "$scriptDir/id_rsa.pub":/home/test/.ssh/keys/id_rsa.pub:ro \
-v "$tmpDir":/home/test/share \
--name "$sftpContainerName" \
Expand Down Expand Up @@ -96,19 +96,19 @@ function runSftpCommands() {

function waitForServer() {
containerName="$1"
echo -n "Waiting for $containerName to open port 22 "
echo -n "Waiting for $containerName to open port 22 ..."

for i in {1..30}; do
sleep 1
ip="$(getSftpIp $containerName)"
echo -n "."
if nc -z $ip 22; then
echo " OK"
if [ -n "$ip" ] && nc -z $ip 22; then
echo " OPEN"
return 0;
fi
done

echo " FAIL"
echo " TIMEOUT"
return 1
}

Expand Down Expand Up @@ -189,6 +189,34 @@ function testMinimalContainerStart() {
fi
}

function testLegacyConfigPath() {
$skipAllTests && skip && return 0

tmpContainerName="$sftpContainerName""_legacy"

echo "test::$(id -u):$(id -g)" >> "$tmpDir/legacy_users"
$sudo docker run \
-v "$tmpDir/legacy_users:/etc/sftp-users.conf:ro" \
--name "$tmpContainerName" \
--expose 22 \
-d "$sftpImageName" \
> "$redirect"

waitForServer $tmpContainerName

ps="$($sudo docker ps -q -f name="$tmpContainerName")"
assertNotEqual "$ps" ""

if [ "$output" != "quiet" ]; then
$sudo docker logs "$tmpContainerName"
fi

if [ "$cleanup" == "cleanup" ]; then
$sudo docker rm -fv "$tmpContainerName" > "$redirect"
fi
}


# Bind-mount folder using script in /etc/sftp.d/
function testCustomContainerStart() {
$skipAllTests && skip && return 0
Expand Down

0 comments on commit c4fd217

Please sign in to comment.