Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add listmode #51

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/omni-socat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"context"
"encoding/json"
"flag"
"fmt"
"log"
"os"
"path/filepath"

"github.com/kelseyhightower/envconfig"
"github.com/masahide/OmniSSHAgent/pkg/namedpipe"
"github.com/masahide/OmniSSHAgent/pkg/npipe2stdin"
"github.com/masahide/OmniSSHAgent/pkg/store"
"github.com/masahide/OmniSSHAgent/pkg/store/local"
Expand All @@ -19,6 +21,7 @@ import (
type specification struct {
Debug bool
LogFile string `default:"omni-socat.log"`
List bool `default:"false"`
}

const (
Expand Down Expand Up @@ -49,6 +52,7 @@ func main() {
log.Fatal(err)
}
flag.BoolVar(&s.Debug, "debug", s.Debug, "Output debug log")
flag.BoolVar(&s.List, "l", s.List, "list ssh-agent keys")
flag.Parse()
if s.Debug {
home, err := os.UserHomeDir()
Expand All @@ -62,6 +66,10 @@ func main() {
log.SetOutput(f)
defer f.Close()
}
if s.List {
listMode()
return
}
settings := store.NewSettings(getExeName(), local.NewLocalCred(appName))
if err := settings.Load(); err != nil {
log.Fatal(err.Error())
Expand All @@ -74,6 +82,17 @@ func main() {
log.Fatal("Failed to connect to OmniSSHAgent. Enable the Named pipe interface for OmniSSHAgent.")
}

func listMode() {
k := &namedpipe.NamedPipeClient{}
keys, err := k.List()
if err != nil {
fmt.Println(err)
}
for i, k := range keys {
fmt.Printf("#%d: %s\n", i+1, k)
}
}

func jsonDump(data interface{}) string {
b, err := json.Marshal(data)
if err != nil {
Expand Down