Skip to content

Commit

Permalink
Major refactor + validation
Browse files Browse the repository at this point in the history
  • Loading branch information
elliot40404 committed Sep 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 499e505 commit b13b01e
Showing 321 changed files with 43,109 additions and 1,680 deletions.
21 changes: 5 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -4,27 +4,16 @@ GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
BINARY_DIR=bin
BUILD_FLAGS=-v

ifeq ($(OS),Windows_NT)
CLEAN_CMD = del /Q $(BINARY_DIR)\*.* && rmdir /S /Q $(BINARY_DIR)
else
CLEAN_CMD = rm -rf $(BINARY_DIR)
endif
CLEAN_CMD = del /Q $(BINARY_DIR)\*.* && rmdir /S /Q $(BINARY_DIR)

# Targets
all: windows

windows:
$(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_DIR)/ssm.exe main.go

linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_DIR)/ssm main.go
all: build

mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_DIR)/ssm main.go
build:
$(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_DIR)/ssm.exe ./cmd/ssm

install:
$(GOCMD) install $(BUILD_FLAGS)
$(GOCMD) install $(BUILD_FLAGS) ./cmd/ssm

clean:
$(GOCLEAN)
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# SSM - THE SECURE SHELL MANAGER
# SSM - Simple SSH Manager

```
_____ _____ _____
```
_____ _____ _____
| __| __| |
|__ |__ | | | |
|_____|_____|_|_|_|
SSM - THE SECURE SHELL MANAGER
SSM - SIMPLE SSH MANAGER
- Elliot
```

## About

I am learning Go and wanted to make something useful. I have a lot of servers that I need to SSH into and I wanted a way to manage them, so I decided to make a simple SSH manager.

> NOTE
> This is still a work in progress so there may be bugs. Please feel free to report them
## Directory structure

```
@@ -22,6 +29,7 @@ SSM - THE SECURE SHELL MANAGER
├── id_rsa // private key **
└── id_rsa.pub // public key **
```

> `*` - Required
> `**` SSH keys are not required if you use password authorization
@@ -47,3 +55,40 @@ Host compute
User ubuntu
Port 4444
```

## Usage

```
NAME:
ssm - ssh config manager
USAGE:
ssm [global options] command [command options] [arguments...]
VERSION:
0.1.0
AUTHOR:
Elliot <admin@elliot404.com>
COMMANDS:
list, ls list available ssh configs
add add new ssh config
print print ssh config
edit, e edit ssh config
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--help, -h show help
--version, -v print the version
```

## TODO

- [ ] Remove config
- [ ] Add support for password authentication
- [ ] ssh-keygen wrapper

## License

MIT License
9 changes: 5 additions & 4 deletions main.go → cmd/ssm/main.go
Original file line number Diff line number Diff line change
@@ -4,18 +4,19 @@ import (
"log"
"os"

"github.com/elliot40404/ssm/commands"
"github.com/elliot40404/ssm/pkg/commands"
"github.com/urfave/cli/v2"
)

func main() {
app := &cli.App{
Name: "ssm",
Usage: "ssh config manager",
Version: "0.1.0",
Usage: "simple ssh manager",
Version: "0.2.0",
Authors: []*cli.Author{
{
Name: "Elliot",
Name: "Elliot",
Email: "admin@elliot404.com",
},
},
Commands: []*cli.Command{
87 changes: 0 additions & 87 deletions commands/add.go

This file was deleted.

10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ module github.com/elliot40404/ssm
go 1.20

require (
github.com/go-playground/validator/v10 v10.15.3
github.com/manifoldco/promptui v0.9.0
github.com/urfave/cli/v2 v2.25.7
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
@@ -11,7 +12,14 @@ require (
require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
)
37 changes: 35 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -6,16 +6,49 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.15.3 h1:S+sSpunYjNPDuXkWbK+x+bA7iXiW296KG4dL3X7xUZo=
github.com/go-playground/validator/v10 v10.15.3/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
54 changes: 54 additions & 0 deletions pkg/commands/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package commands

import (
"fmt"

"github.com/elliot40404/ssm/pkg/model"
"github.com/elliot40404/ssm/pkg/utils"
"github.com/urfave/cli/v2"
)

func Add(cCtx *cli.Context) error {
var name string
for {
name = utils.BasicPrompt("Name your config", false)
if !utils.CheckExisting(name) {
break
}
fmt.Println("Config with same name already exists")
}
var config model.Config
config.Name = name
config.Hostname = utils.BasicPrompt("Hostname", false)
config.User = utils.BasicPrompt("User", false)
port := utils.BasicPrompt("Port (Enter to use Default 22)", true)
if port != "" {
config.Port = utils.ParseInt(port)
}
config.Port = 22
// ADD SSH KEY
usekey := utils.AskYesNo("Use SSH Key [Y|n]: ", "y")
if usekey {
result := utils.SelectMenu("Select SSH Key", utils.GetSSHKeys(), true)
if result == "Add New" {
config.SshKey = utils.BasicPrompt("Full path to ssh key", false)
} else {
config.SshKey = "~/.ssh/" + result
}
}
// ADD CATEGORY
result := utils.SelectMenu("Select Category", utils.GetCategories(), true)
if result == "Add New" {
config.Category = utils.BasicPrompt("Enter New Category (without #)", false)
} else {
config.Category = result
}
// VALIDATE CONFIG
err := config.Validate()
if err != nil {
fmt.Println(err)
return nil
}
config.Save(usekey, cCtx.Bool("dry-run"))
return nil
}
2 changes: 1 addition & 1 deletion commands/edit.go → pkg/commands/edit.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
func Edit(cCtx *cli.Context) error {
configName := cCtx.Args().First()
if configName == "" {
configName = selectMenu("Select Config", utils.GetSSHConfigs(false), false)
configName = utils.SelectMenu("Select Config", utils.GetSSHConfigs(false), false)
}
utils.OpenWithDefaultTextEditor(utils.GetSSHDir(true) + "/" + configName)
return nil
File renamed without changes.
2 changes: 1 addition & 1 deletion commands/print.go → pkg/commands/print.go
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ import (
func Print(cCtx *cli.Context) error {
configName := cCtx.Args().First()
if configName == "" {
configName = selectMenu("Select Config", utils.GetSSHConfigs(false), false)
configName = utils.SelectMenu("Select Config", utils.GetSSHConfigs(false), false)
}
// get config
config := utils.GetSSHConfig(configName)
File renamed without changes.
Loading

0 comments on commit b13b01e

Please sign in to comment.