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:
parent
ee9ffb6828
commit
4b99ece480
3 changed files with 28 additions and 9 deletions
|
@ -96,6 +96,7 @@ def supported_commands():
|
||||||
'introspect',
|
'introspect',
|
||||||
'list',
|
'list',
|
||||||
'perms',
|
'perms',
|
||||||
|
'transcrypt',
|
||||||
'upgrade',
|
'upgrade',
|
||||||
'version',
|
'version',
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
"""Test git-crypt"""
|
"""Test external encryption commands"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -8,15 +8,21 @@ import pytest
|
||||||
[False, 'installed', 'installed-but-failed'],
|
[False, 'installed', 'installed-but-failed'],
|
||||||
ids=['not-installed', 'installed', 'installed-but-failed']
|
ids=['not-installed', 'installed', 'installed-but-failed']
|
||||||
)
|
)
|
||||||
def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
|
@pytest.mark.parametrize(
|
||||||
"""git-crypt tests"""
|
'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)
|
paths.repo.ensure(dir=True)
|
||||||
bindir = tmpdir.mkdir('bin')
|
bindir = tmpdir.mkdir('bin')
|
||||||
pgm = bindir.join('test-git-crypt')
|
pgm = bindir.join('test-ext-crypt')
|
||||||
|
|
||||||
if 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)
|
pgm.chmod(0o775)
|
||||||
if crypt == 'installed-but-failed':
|
if crypt == 'installed-but-failed':
|
||||||
pgm.write('false\n', mode='a')
|
pgm.write('false\n', mode='a')
|
||||||
|
@ -24,8 +30,8 @@ def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
|
||||||
script = f"""
|
script = f"""
|
||||||
YADM_TEST=1 source {yadm}
|
YADM_TEST=1 source {yadm}
|
||||||
YADM_REPO={paths.repo}
|
YADM_REPO={paths.repo}
|
||||||
GIT_CRYPT_PROGRAM="{pgm}"
|
{var}="{pgm}"
|
||||||
git_crypt "param1"
|
{cmd} "param1"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
run = runner(command=['bash'], inp=script)
|
run = runner(command=['bash'], inp=script)
|
||||||
|
@ -35,7 +41,7 @@ def test_git_crypt(runner, yadm, paths, tmpdir, crypt):
|
||||||
assert run.failure
|
assert run.failure
|
||||||
else:
|
else:
|
||||||
assert run.success
|
assert run.success
|
||||||
assert run.out.strip() == 'git-crypt ran'
|
assert run.out.strip() == 'ext-crypt ran'
|
||||||
else:
|
else:
|
||||||
assert run.failure
|
assert run.failure
|
||||||
assert f"command '{pgm}' cannot be located" in run.out
|
assert f"command '{pgm}' cannot be located" in run.out
|
14
yadm
14
yadm
|
@ -42,6 +42,7 @@ GPG_PROGRAM="gpg"
|
||||||
GIT_PROGRAM="git"
|
GIT_PROGRAM="git"
|
||||||
AWK_PROGRAM=("gawk" "awk")
|
AWK_PROGRAM=("gawk" "awk")
|
||||||
GIT_CRYPT_PROGRAM="git-crypt"
|
GIT_CRYPT_PROGRAM="git-crypt"
|
||||||
|
TRANSCRYPT_PROGRAM="transcrypt"
|
||||||
J2CLI_PROGRAM="j2"
|
J2CLI_PROGRAM="j2"
|
||||||
ENVTPL_PROGRAM="envtpl"
|
ENVTPL_PROGRAM="envtpl"
|
||||||
LSB_RELEASE_PROGRAM="lsb_release"
|
LSB_RELEASE_PROGRAM="lsb_release"
|
||||||
|
@ -86,7 +87,7 @@ function main() {
|
||||||
|
|
||||||
# parse command line arguments
|
# parse command line arguments
|
||||||
local retval=0
|
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
|
if [ -z "$*" ] ; then
|
||||||
# no argumnts will result in help()
|
# no argumnts will result in help()
|
||||||
help
|
help
|
||||||
|
@ -934,6 +935,11 @@ function git_crypt() {
|
||||||
enter "${GIT_CRYPT_PROGRAM} $*"
|
enter "${GIT_CRYPT_PROGRAM} $*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function transcrypt() {
|
||||||
|
require_transcrypt
|
||||||
|
enter "${TRANSCRYPT_PROGRAM} $*"
|
||||||
|
}
|
||||||
|
|
||||||
function enter() {
|
function enter() {
|
||||||
command="$*"
|
command="$*"
|
||||||
require_shell
|
require_shell
|
||||||
|
@ -1023,6 +1029,7 @@ Commands:
|
||||||
yadm perms - Fix perms for private files
|
yadm perms - Fix perms for private files
|
||||||
yadm enter [COMMAND] - Run sub-shell with GIT variables set
|
yadm enter [COMMAND] - Run sub-shell with GIT variables set
|
||||||
yadm git-crypt [OPTIONS] - Run git-crypt commands for the yadm repo
|
yadm git-crypt [OPTIONS] - Run git-crypt commands for the yadm repo
|
||||||
|
yadm transcrypt [OPTIONS] - Run transcrypt commands for the yadm repo
|
||||||
|
|
||||||
Files:
|
Files:
|
||||||
\$HOME/.config/yadm/config - yadm's configuration file
|
\$HOME/.config/yadm/config - yadm's configuration file
|
||||||
|
@ -1083,6 +1090,7 @@ init
|
||||||
introspect
|
introspect
|
||||||
list
|
list
|
||||||
perms
|
perms
|
||||||
|
transcrypt
|
||||||
upgrade
|
upgrade
|
||||||
version
|
version
|
||||||
EOF
|
EOF
|
||||||
|
@ -1908,6 +1916,10 @@ function require_git_crypt() {
|
||||||
command -v "$GIT_CRYPT_PROGRAM" &> /dev/null ||
|
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."
|
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() {
|
function bootstrap_available() {
|
||||||
[ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return
|
[ -f "$YADM_BOOTSTRAP" ] && [ -x "$YADM_BOOTSTRAP" ] && return
|
||||||
return 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue