Skip to content

Commit

Permalink
Merge pull request #58 from dokku/master
Browse files Browse the repository at this point in the history
Release 0.12.0
  • Loading branch information
josegonzalez authored Dec 19, 2020
2 parents ba9a901 + d32b2c2 commit 91329f3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 18 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ All notable changes to this project will be documented in this file.

### Changed

## [0.12.0] - 2020-12-19

### Added

- @josegonzalez add support for removing ssh keys by fingerprint
- @josegonzalez add support for help and version flags …

## [0.11.0] - 2020-05-06

### Changed
Expand Down Expand Up @@ -141,7 +148,8 @@ All notable changes to this project will be documented in this file.
- @michaelshobbs update build image in README
- @jvanbaarsen Only add SSH key if it doesn't already exists

[unreleased]: https://github.com/dokku/sshcommand/compare/v0.11.0...HEAD
[unreleased]: https://github.com/dokku/sshcommand/compare/v0.12.0...HEAD
[0.12.0]: https://github.com/dokku/sshcommand/compare/v0.11.0...v0.12.0
[0.11.0]: https://github.com/dokku/sshcommand/compare/v0.10.0...v0.11.0
[0.10.0]: https://github.com/dokku/sshcommand/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/dokku/sshcommand/compare/v0.8.0...v0.9.0
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ MAINTAINER_NAME = Jose Diaz-Gonzalez
REPOSITORY = sshcommand
HARDWARE = $(shell uname -m)
SYSTEM_NAME = $(shell uname -s | tr '[:upper:]' '[:lower:]')
BASE_VERSION ?= 0.11.0
BASE_VERSION ?= 0.12.0
IMAGE_NAME ?= $(MAINTAINER)/$(REPOSITORY)
PACKAGECLOUD_REPOSITORY ?= dokku/dokku-betafish

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ ssh ls@server <your-args>
## Commands

```shell
sshcommand create <USER> <COMMAND> # Creates a user forced to run command when SSH connects
sshcommand acl-add <USER> <NAME> <KEY_FILE> # Adds named SSH key to user from STDIN or argument
sshcommand acl-remove <USER> <NAME> # Removes SSH key by name
sshcommand list <USER> [<NAME>] [<OUTPUT_TYPE>] # Lists SSH keys by user, an optional name and a optional output format (JSON)
sshcommand help <COMMAND> # Shows help information
sshcommand version # Shows version
sshcommand create <USER> <COMMAND> # Creates a local system user and installs sshcommand skeleton
sshcommand acl-add <USER> <NAME> <KEY_FILE> # Adds named SSH key to user from STDIN or argument
sshcommand acl-remove <USER> <NAME> # Removes SSH key by name
sshcommand acl-remove-by-fingerprint <USER> <FINGERPRINT> # Removes SSH key by fingerprint
sshcommand list <USER> [<NAME>] [<OUTPUT_TYPE>] # Lists SSH keys by user, an optional name and a optional output format (JSON)
sshcommand help <COMMAND> # Shows help information
sshcommand version # Shows version
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sshcommand",
"version": "0.11.0",
"version": "0.12.0",
"description": "Turn SSH into a thin client specifically for your app",
"global": "true",
"install": "cp sshcommand /usr/local/bin && chmod +x /usr/local/bin/sshcommand",
Expand Down
44 changes: 35 additions & 9 deletions sshcommand
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn-args() {
fn-desc() {
declare desc="Inspect a function's description"
desc=""
eval "$(type "$1" | grep desc | head -1)"; echo $desc
eval "$(type "$1" | grep desc | head -1)"; echo "$desc"
}

fn-info() {
Expand Down Expand Up @@ -177,6 +177,22 @@ sshcommand-acl-remove() {
sed --in-place "/ NAME=\\\\\"$NAME\\\\\" /d" "$USERHOME/.ssh/authorized_keys"
}

sshcommand-acl-remove-by-fingerprint() {
declare desc="Removes SSH key by fingerprint"
declare USER="$1" FINGERPRINT="$2"
local USERHOME

if [[ -z "$USER" ]] || [[ -z "$FINGERPRINT" ]]; then
log-fail "Usage: sshcommand acl-remove-by-fingerprint" "$(fn-args "sshcommand-acl-remove-by-fingerprint")"
fi

getent passwd "$USER" > /dev/null || false
USERHOME=$(sh -c "echo ~$USER")

# shellcheck disable=SC1117
sed --in-place "\#\"FINGERPRINT=$FINGERPRINT #d" "$USERHOME/.ssh/authorized_keys"
}

sshcommand-list() {
declare desc="Lists SSH keys by user, an optional name and a optional output format (JSON)"
declare userhome USER="$1" NAME="$2" OUTPUT_TYPE="${3:-$2}"
Expand Down Expand Up @@ -216,12 +232,13 @@ sshcommand-help() {

echo "sshcommand ${SSHCOMMAND_VERSION}"
echo ""
printf " %-10s %-30s %s\\n" "create" "$(fn-args "sshcommand-create")" "$(fn-desc "sshcommand-create")"
printf " %-10s %-30s %s\\n" "acl-add" "$(fn-args "sshcommand-acl-add")" "$(fn-desc "sshcommand-acl-add")"
printf " %-10s %-30s %s\\n" "acl-remove" "$(fn-args "sshcommand-acl-remove")" "$(fn-desc "sshcommand-acl-remove")"
printf " %-10s %-30s %s\\n" "list" "$(fn-args "sshcommand-list")" "$(fn-desc "sshcommand-list")"
printf " %-10s %-30s %s\\n" "help" "$(fn-args "sshcommand-help")" "$(fn-desc "sshcommand-help")"
printf " %-10s %-30s %s\\n" "version" "$(fn-args "sshcommand-version")" "$(fn-desc "sshcommand-version")"
printf " %-25s %-30s %s\\n" "create" "$(fn-args "sshcommand-create")" "$(fn-desc "sshcommand-create")"
printf " %-25s %-30s %s\\n" "acl-add" "$(fn-args "sshcommand-acl-add")" "$(fn-desc "sshcommand-acl-add")"
printf " %-25s %-30s %s\\n" "acl-remove" "$(fn-args "sshcommand-acl-remove")" "$(fn-desc "sshcommand-acl-remove")"
printf " %-25s %-30s %s\\n" "acl-remove-by-fingerprint" "$(fn-args "sshcommand-acl-remove-by-fingerprint")" "$(fn-desc "sshcommand-acl-remove-by-fingerprint")"
printf " %-25s %-30s %s\\n" "list" "$(fn-args "sshcommand-list")" "$(fn-desc "sshcommand-list")"
printf " %-25s %-30s %s\\n" "help" "$(fn-args "sshcommand-help")" "$(fn-desc "sshcommand-help")"
printf " %-25s %-30s %s\\n" "version" "$(fn-args "sshcommand-version")" "$(fn-desc "sshcommand-version")"
}

sshcommand-version() {
Expand All @@ -230,12 +247,21 @@ sshcommand-version() {
}

main() {
if [[ -z "$1" ]]; then
declare COMMAND_SUFFIX="$1"
if [[ -z "$COMMAND_SUFFIX" ]]; then
sshcommand-help "$@"
exit 1
fi

local cmd="sshcommand-$1"
if [[ "$COMMAND_SUFFIX" == "-h" ]] || [[ "$COMMAND_SUFFIX" == "--help" ]]; then
COMMAND_SUFFIX="help"
fi

if [[ "$COMMAND_SUFFIX" == "-v" ]] || [[ "$COMMAND_SUFFIX" == "--version" ]]; then
COMMAND_SUFFIX="version"
fi

local cmd="sshcommand-$COMMAND_SUFFIX"
shift 1

if declare -f "$cmd" > /dev/null; then
Expand Down

0 comments on commit 91329f3

Please sign in to comment.