Skip to content

Commit 2158f50

Browse files
authored
Merge pull request #130 from dokku/josegonzalez-patch-1
fix: add missing ability to filter ssh keys when listing in json format
2 parents fd08aea + 3212f72 commit 2158f50

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

sshcommand

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ sshcommand-list() {
214214
's/^command="FINGERPRINT=(\S+) NAME=(\\"|)(.*)\2 `.*",(\S+).*/{ "fingerprint": "\1", "name": "\3", "SSHCOMMAND_ALLOWED_KEYS": "\4" }/p' \
215215
"$userhome/.ssh/authorized_keys" | tr '\n' ',' | sed '$s/,$/\n/')
216216

217-
echo "[${data}]"
217+
if [[ -n "$NAME" ]]; then
218+
echo "[${data}]" | jq -cM --arg NAME "$NAME" 'map( select (.name == $NAME) )'
219+
else
220+
echo "[${data}]"
221+
fi
218222
else
219223
OUTPUT="$(sed --silent --regexp-extended \
220224
's/^command="FINGERPRINT=(\S+) NAME=(\\"|)(.*)\2 `.*",(\S+).*/\1 NAME="\3" SSHCOMMAND_ALLOWED_KEYS="\4"/p' \

tests/unit/core.bats

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,12 @@ check_custom_allowed_keys() {
205205
assert_failure
206206

207207
cp tests/unit/fixtures/authorized_keys/input_variants "/home/${TEST_USER}/.ssh/authorized_keys"
208-
run bash -c "sshcommand list $TEST_USER md5"
208+
run bash -c "sshcommand list $TEST_USER '' json"
209209
echo "output: $output"
210210
echo "status: $status"
211211
assert_equal \
212212
"$(head -n1 tests/unit/fixtures/authorized_keys/sshcommand_list_expected_json_output)" \
213-
"$(sshcommand list "$TEST_USER" md5 json)"
213+
"$(sshcommand list "$TEST_USER" "" json)"
214214
}
215215

216216
@test "(core) sshcommand list (authorized_keys format variants)" {
@@ -226,13 +226,13 @@ check_custom_allowed_keys() {
226226

227227
@test "(core) sshcommand list (json output)" {
228228
cp tests/unit/fixtures/authorized_keys/input_variants "/home/${TEST_USER}/.ssh/authorized_keys"
229-
run bash -c "sshcommand list $TEST_USER json"
229+
run bash -c "sshcommand list $TEST_USER md5 json"
230230
echo "output: $output"
231231
echo "status: $status"
232232

233233
assert_equal \
234-
"$(cat tests/unit/fixtures/authorized_keys/sshcommand_list_expected_json_output)" \
235-
"$(sshcommand list "$TEST_USER" json)"
234+
"$(cat tests/unit/fixtures/authorized_keys/sshcommand_list_expected_json_output_md5_filtered)" \
235+
"$(sshcommand list "$TEST_USER" "md5" json)"
236236
rm "/home/${TEST_USER}/.ssh/authorized_keys"
237237
}
238238

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"fingerprint":"2a:f7:39:1c:63:80:c4:9e:a8:92:ec:e6:94:91:fa:c0","name":"md5","SSHCOMMAND_ALLOWED_KEYS":"no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding"}]

0 commit comments

Comments
 (0)