1
0
Fork 0
mirror of synced 2024-12-12 18:35:46 -05:00

Support transcrypt (#197)

Support is inherently provided by `enter`, which supports a command.
I've added a `transcrypt` command, which is really just an alias
under-the-hood for "enter transcrypt".
This commit is contained in:
Tim Byrne 2020-02-21 08:05:56 -06:00
parent ee9ffb6828
commit 4b99ece480
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
3 changed files with 28 additions and 9 deletions

View file

@ -96,6 +96,7 @@ def supported_commands():
'introspect',
'list',
'perms',
'transcrypt',
'upgrade',
'version',
]

View file

@ -1,4 +1,4 @@
"""Test git-crypt"""
"""Test external encryption commands"""
import pytest
@ -8,15 +8,21 @@ import pytest
[False, 'installed', 'installed-but-failed'],
ids=['not-installed', 'installed', 'installed-but-failed']
)
def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
"""git-crypt tests"""
@pytest.mark.parametrize(
'cmd,var', [
['git_crypt', 'GIT_CRYPT_PROGRAM'],
['transcrypt', 'TRANSCRYPT_PROGRAM'],
],
ids=['git-crypt', 'transcrypt'])
def test_ext_encryption(runner, yadm, paths, tmpdir, crypt, cmd, var):
"""External encryption tests"""
paths.repo.ensure(dir=True)
bindir = tmpdir.mkdir('bin')
pgm = bindir.join('test-git-crypt')
pgm = bindir.join('test-ext-crypt')
if crypt:
pgm.write(f'#!/bin/sh\necho git-crypt ran\n')
pgm.write(f'#!/bin/sh\necho ext-crypt ran\n')
pgm.chmod(0o775)
if crypt == 'installed-but-failed':
pgm.write('false\n', mode='a')
@ -24,8 +30,8 @@ def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
script = f"""
YADM_TEST=1 source {yadm}
YADM_REPO={paths.repo}
GIT_CRYPT_PROGRAM="{pgm}"
git_crypt "param1"
{var}="{pgm}"
{cmd} "param1"
"""
run = runner(command=['bash'], inp=script)
@ -35,7 +41,7 @@ def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
assert run.failure
else:
assert run.success
assert run.out.strip() == 'git-crypt ran'
assert run.out.strip() == 'ext-crypt ran'
else:
assert run.failure
assert f"command '{pgm}' cannot be located" in run.out

14
yadm
View file

@ -42,6 +42,7 @@ GPG_PROGRAM="gpg"
GIT_PROGRAM="git"
AWK_PROGRAM=("gawk" "awk")
GIT_CRYPT_PROGRAM="git-crypt"
TRANSCRYPT_PROGRAM="transcrypt"
J2CLI_PROGRAM="j2"
ENVTPL_PROGRAM="envtpl"
LSB_RELEASE_PROGRAM="lsb_release"
@ -86,7 +87,7 @@ function main() {
# parse command line arguments
local retval=0
internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|git-crypt|help|init|introspect|list|perms|upgrade|version)$"
internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|git-crypt|help|init|introspect|list|perms|transcrypt|upgrade|version)$"
if [ -z "$*" ] ; then
# no argumnts will result in help()
help
@ -934,6 +935,11 @@ function git_crypt() {
enter "${GIT_CRYPT_PROGRAM} $*"
}
function transcrypt() {
require_transcrypt
enter "${TRANSCRYPT_PROGRAM} $*"
}
function enter() {
command="$*"
require_shell
@ -1023,6 +1029,7 @@ Commands:
yadm perms - Fix perms for private files
yadm enter [COMMAND] - Run sub-shell with GIT variables set
yadm git-crypt [OPTIONS] - Run git-crypt commands for the yadm repo
yadm transcrypt [OPTIONS] - Run transcrypt commands for the yadm repo
Files:
\$HOME/.config/yadm/config - yadm's configuration file
@ -1083,6 +1090,7 @@ init
introspect
list
perms
transcrypt
upgrade
version
EOF
@ -1908,6 +1916,10 @@ function require_git_crypt() {
command -v "$GIT_CRYPT_PROGRAM" &> /dev/null ||
error_out "This functionality requires git-crypt to be installed, but the command '$GIT_CRYPT_PROGRAM' cannot be located."
}
function require_transcrypt() {
command -v "$TRANSCRYPT_PROGRAM" &> /dev/null ||
error_out "This functionality requires transcrypt to be installed, but the command '$TRANSCRYPT_PROGRAM' cannot be located."
}
function bootstrap_available() {
[ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return
return 1