Sprint 6: JSON file persistence + real SSH terminal + V1 crypto/knownhosts integration

- go.mod replace directive for git.tukangketik.id/swanadiva/hostkeeper → ../../v1
- store/ package: JSON file persistence for hosts, snippets, keys, settings
  (~/Library/Application Support/hostkeeper/v2/)
- model SSH fields: Hostname, Port, Username, AuthType, Password, KeyID
- sshconn/ package: real SSH client via golang.org/x/crypto/ssh
- Terminal WS: real SSH connection with fallback to mock shell
- Dynamic host list in terminal (server-rendered JSON script tag)
- All mock data defaults removed from model packages
- Settings persist via store/settings.go
This commit is contained in:
swanadiva
2026-07-07 13:53:50 +07:00
parent 04d9cfb096
commit fd7361aa14
21 changed files with 746 additions and 306 deletions
+1 -68
View File
@@ -1,78 +1,11 @@
package model
import "time"
type Key struct {
ID string `json:"id"`
Name string `json:"name"`
Username string `json:"username"`
URL string `json:"url"`
Passphrase string `json:"passphrase"`
Strength string `json:"strength"` // weak | moderate | secure
Strength string `json:"strength"`
CreatedAt string `json:"createdAt"`
}
type KeyStore struct {
Keys []Key
}
func NewKeyStore() *KeyStore {
return &KeyStore{Keys: defaultKeys()}
}
func (s *KeyStore) All() []Key { return s.Keys }
func (s *KeyStore) Search(q string) []Key {
if q == "" { return s.Keys }
var res []Key
for _, k := range s.Keys {
if contains(k.Name, q) || contains(k.Username, q) || contains(k.URL, q) {
res = append(res, k)
}
}
return res
}
func (s *KeyStore) Add(name, username, url, passphrase string) Key {
k := Key{
ID: randString(8),
Name: name,
Username: username,
URL: url,
Passphrase: passphrase,
Strength: calcStrength(passphrase),
CreatedAt: time.Now().Format("Jan 2, 2006"),
}
s.Keys = append(s.Keys, k)
return k
}
func (s *KeyStore) Delete(id string) {
for i, k := range s.Keys {
if k.ID == id { s.Keys = append(s.Keys[:i], s.Keys[i+1:]...); return }
}
}
func calcStrength(p string) string {
l, d, u, s := 0, 0, 0, 0
for _, c := range p {
switch {
case c >= 'a' && c <= 'z': l++
case c >= 'A' && c <= 'Z': u++
case c >= '0' && c <= '9': d++
default: s++
}
}
if len(p) >= 12 && u >= 1 && d >= 1 && s >= 1 { return "secure" }
if len(p) >= 8 && u+d+s >= 2 { return "moderate" }
return "weak"
}
func defaultKeys() []Key {
return []Key{
{ID: "k1", Name: "AWS Prod Root", Username: "ec2-user", URL: "aws-console.amazon.com", Passphrase: "••••••••••", Strength: "secure", CreatedAt: "Mar 15, 2026"},
{ID: "k2", Name: "GitHub Deploy", Username: "git", URL: "github.com", Passphrase: "••••••••", Strength: "secure", CreatedAt: "Apr 2, 2026"},
{ID: "k3", Name: "Dev DB Access", Username: "admin", URL: "dev-db.internal:5432", Passphrase: "••••••", Strength: "moderate", CreatedAt: "May 10, 2026"},
{ID: "k4", Name: "Old Server", Username: "root", URL: "192.168.1.100", Passphrase: "••••", Strength: "weak", CreatedAt: "Jan 5, 2026"},
{ID: "k5", Name: "Staging API Key", Username: "api-user", URL: "staging.api.company.com", Passphrase: "•••••••••••", Strength: "secure", CreatedAt: "Jun 1, 2026"},
}
}