Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
09c2cc5
fix: delete extra var err
deniskorbakov Nov 10, 2025
3c00e3b
feat: add todo
deniskorbakov Nov 10, 2025
85727f1
fix: rename variable
deniskorbakov Nov 10, 2025
9febce4
feat: add logic for get file data from ssh config
deniskorbakov Nov 10, 2025
8cfb812
feat: add new const for ssh config
deniskorbakov Nov 10, 2025
815d651
feat: delete extra method and add logic on get direction ssh
deniskorbakov Nov 10, 2025
4520c30
fix: delete extra method
deniskorbakov Nov 10, 2025
db095dd
feat: add example func for get connection from config
deniskorbakov Nov 10, 2025
f883bbf
feat: add todo
deniskorbakov Nov 10, 2025
722ee07
feat: test commit
deniskorbakov Nov 11, 2025
aea83b8
fix: delet elogic test commit
deniskorbakov Nov 11, 2025
0a5c462
feat: delete extra files
deniskorbakov Nov 14, 2025
e0e9dc1
fix: update logic storage
deniskorbakov Nov 14, 2025
4f2fa5d
feat: add new config name
deniskorbakov Nov 14, 2025
07d12e5
feat: add base logic space struct
deniskorbakov Nov 14, 2025
6fcc311
feat: add const type storage
deniskorbakov Nov 14, 2025
1deb8ba
feat: add maybe files
deniskorbakov Nov 14, 2025
35f59e1
fix: delete extra link on interface
deniskorbakov Nov 14, 2025
8e16b2a
feat: add default logic
deniskorbakov Nov 14, 2025
8dc2817
fix: put validate private key in connection pkg
deniskorbakov Nov 15, 2025
64ea016
fix: delete extra code
deniskorbakov Nov 15, 2025
c1e8d0d
fix: add new var in config
deniskorbakov Nov 15, 2025
7f799ea
fix: delete extra files
deniskorbakov Nov 15, 2025
59f9f09
fix: delete extra files
deniskorbakov Nov 15, 2025
2590934
feat: add struct for work with ssh config
deniskorbakov Nov 15, 2025
d8f501a
fix: delete extra type
deniskorbakov Nov 15, 2025
da2a5a4
feat: add params
deniskorbakov Nov 15, 2025
35064f4
fix: rename variable
deniskorbakov Nov 15, 2025
5c3a760
feat: add todo
deniskorbakov Nov 15, 2025
c99ae62
fix: delete extra params from method
deniskorbakov Nov 15, 2025
26e96f5
feat: create file with var for key Space in config
deniskorbakov Nov 15, 2025
5bbfe7e
feat: add ssh config param in struct
deniskorbakov Nov 15, 2025
aeb8077
fix: delete extra params
deniskorbakov Nov 15, 2025
0ad94e0
fix: put in new pkg
deniskorbakov Nov 15, 2025
cf4850e
fix: update usage pkg - auto
deniskorbakov Nov 15, 2025
0057378
fix: update validate
deniskorbakov Nov 15, 2025
2a36a14
fix: update pkg usage
deniskorbakov Nov 15, 2025
3916ee9
fix: delete extra todo
deniskorbakov Nov 15, 2025
ffa8298
feat: add method for create sctruct
deniskorbakov Nov 15, 2025
8f34c48
feat: add base method
deniskorbakov Nov 15, 2025
68a534f
feat: add bse logic
deniskorbakov Nov 17, 2025
b734768
feat: add base test
deniskorbakov Nov 17, 2025
e61c31a
fix: change visible path
deniskorbakov Nov 17, 2025
167fcc3
fix: change logic storage on local storage
deniskorbakov Nov 17, 2025
a840d05
feat: add method set and get default struct for pkg
deniskorbakov Nov 18, 2025
302e6df
feat: create struct for space interface
deniskorbakov Nov 18, 2025
343f55b
feat: add const type for storage
deniskorbakov Nov 18, 2025
8c6e633
fix: update logic used connection arg
deniskorbakov Nov 18, 2025
54922ff
fix: delete extra const
deniskorbakov Nov 18, 2025
95ab404
fix: update logic read private key
deniskorbakov Nov 18, 2025
0f408ce
feat: add const name - storage
deniskorbakov Nov 18, 2025
f27ee66
fix: update test for view error
deniskorbakov Nov 18, 2025
5d85db9
feat: add new init logic
deniskorbakov Nov 18, 2025
d49a530
feat: add base logic for set alias
deniskorbakov Nov 19, 2025
642ca83
feat: add todo
deniskorbakov Nov 19, 2025
7c6a8a9
feat: add base logic add data from config
deniskorbakov Nov 20, 2025
a48904d
feat: add base logic add data from config
deniskorbakov Nov 21, 2025
807b428
feat: add new method for parse connection
deniskorbakov Nov 21, 2025
c4c0971
fix: update view methods
deniskorbakov Nov 21, 2025
b73f7e6
fix: delete extra logic
deniskorbakov Nov 21, 2025
220608b
feat: add todo
deniskorbakov Nov 21, 2025
bb73fb4
fix: rename method
deniskorbakov Nov 23, 2025
56dcf47
fix: update logic parsing data form config
deniskorbakov Nov 23, 2025
2067243
fix: delete extra struct with her logic
deniskorbakov Nov 23, 2025
974525c
feat: create test util method
deniskorbakov Nov 29, 2025
07ddff5
fix: update logic parse connection
deniskorbakov Nov 29, 2025
4196fdf
fix: rename make command
deniskorbakov Nov 29, 2025
57c10ef
fix: change visibility method
deniskorbakov Nov 29, 2025
301b428
fix: update logic validate connection
deniskorbakov Nov 29, 2025
7a9adb0
feat: add test data for config
deniskorbakov Nov 29, 2025
c43a8ae
fix: update return data
deniskorbakov Nov 29, 2025
63bd17b
feat: add example logic for create config from testdata
deniskorbakov Nov 29, 2025
d18fea8
feat: add todo
deniskorbakov Nov 30, 2025
cbe4411
feat: add test data
deniskorbakov Nov 30, 2025
18394f1
feat: add new test case
deniskorbakov Nov 30, 2025
9b37d49
fix: update config
deniskorbakov Nov 30, 2025
317ad52
feat: create empty config
deniskorbakov Nov 30, 2025
c6cdd20
feat: add new test cases
deniskorbakov Nov 30, 2025
1d3a967
fix: update key
deniskorbakov Nov 30, 2025
635d99c
fix: delete extra log
deniskorbakov Nov 30, 2025
b9d7a41
feat: add logic for save connection
deniskorbakov Nov 30, 2025
318c45a
feat: add logic for add connection
deniskorbakov Nov 30, 2025
c216473
feat: add new test
deniskorbakov Nov 30, 2025
4678fa2
fix: update flag
deniskorbakov Nov 30, 2025
9b54aa2
fix: add logic for check is exists alias
deniskorbakov Nov 30, 2025
9770ddd
fix: delete extra code
deniskorbakov Nov 30, 2025
025fcbb
fix: update order pkg
deniskorbakov Nov 30, 2025
8616da8
fix: update order pkg
deniskorbakov Nov 30, 2025
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ test-coverage:

# use tests-integration for check integration tests cases
# you need an installed docker to work
.PHONY: tests-integration
tests-integration:
.PHONY: test-e2e
test-e2e:
GO_TESTING=true go test -tags=integration ./...
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ make test-coverage
Run test e2e:

```bash
make tests-integration
make test-e2e
```

## 🤝 Feedback
Expand Down
1 change: 1 addition & 0 deletions configs/envconst/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package envconst

const (
FilenameConnections = "connection.json"
FilenameConfigSSH = "config"
FilenameConfig = "configs"
FilenameLogger = "log.log"
)
6 changes: 6 additions & 0 deletions configs/envconst/space.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package envconst

const (
TypeStorageSpace = "storage"
TypeConfigSpace = "config"
)
7 changes: 7 additions & 0 deletions configs/envconst/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package envconst

const (
TypeLocalStorage = "local"
TypeGitStorage = "git"
TypeS3Storage = "s3"
)
2 changes: 2 additions & 0 deletions configs/envname/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ const (
Theme = "THEME"
Logger = "LOGGER"
Testing = "GO_TESTING"
Space = "SPACE"
Storage = "STORAGE"
)
7 changes: 4 additions & 3 deletions e2e/kernel/connect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package kernel

import (
"context"
ssh2 "github.com/misha-ssh/kernel/pkg/ssh"
"os/exec"
"testing"
"time"
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestIntegrationDefaultConnect(t *testing.T) {
},
}

sshConnector := &connect.Ssh{
sshConnector := &ssh2.Ssh{
Connection: connection,
}

Expand Down Expand Up @@ -127,7 +128,7 @@ func TestIntegrationPrivateKeyConnect(t *testing.T) {
},
}

sshConnector := &connect.Ssh{
sshConnector := &ssh2.Ssh{
Connection: connection,
}
session, err := sshConnector.Session()
Expand Down Expand Up @@ -193,7 +194,7 @@ func TestIntegrationPrivateKeyConnectWithPassphrase(t *testing.T) {
},
}

sshConnector := &connect.Ssh{
sshConnector := &ssh2.Ssh{
Connection: connection,
}
session, err := sshConnector.Session()
Expand Down
3 changes: 2 additions & 1 deletion examples/ssh/external_port/main.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package main

import (
"github.com/misha-ssh/kernel/pkg/ssh"
"time"

"github.com/misha-ssh/kernel/pkg/connect"
)

// main for success connect start make command: up-ssh-port
func main() {
ssh := &connect.Ssh{
ssh := &ssh.Ssh{

Check failure on line 12 in examples/ssh/external_port/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ssh.Ssh
Connection: &connect.Connect{
Alias: "test",
Login: "root",
Password: "password",
Address: "localhost",
Type: connect.TypeSSH,

Check failure on line 18 in examples/ssh/external_port/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: connect.TypeSSH

Check failure on line 18 in examples/ssh/external_port/main.go

View workflow job for this annotation

GitHub Actions / lint

unknown field Type in struct literal of type connect.Connect
CreatedAt: time.Now().Format(time.RFC3339),
UpdatedAt: time.Now().Format(time.RFC3339),
SshOptions: &connect.SshOptions{

Check failure on line 21 in examples/ssh/external_port/main.go

View workflow job for this annotation

GitHub Actions / lint

undefined: connect.SshOptions (typecheck)

Check failure on line 21 in examples/ssh/external_port/main.go

View workflow job for this annotation

GitHub Actions / lint

unknown field SshOptions in struct literal of type connect.Connect
Port: 2222,
PrivateKey: "",
Passphrase: "",
Expand Down
3 changes: 2 additions & 1 deletion examples/ssh/password/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"github.com/misha-ssh/kernel/pkg/ssh"
"time"

"github.com/misha-ssh/kernel/pkg/connect"
)

// main for success connect start make command: up-ssh
func main() {
ssh := &connect.Ssh{
ssh := &ssh.Ssh{
Connection: &connect.Connect{
Alias: "test",
Login: "root",
Expand Down
3 changes: 2 additions & 1 deletion examples/ssh/private_key/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"github.com/misha-ssh/kernel/pkg/ssh"
"time"

"github.com/misha-ssh/kernel/pkg/connect"
)

// main for success connect start make command: up-ssh-key
func main() {
ssh := &connect.Ssh{
ssh := &ssh.Ssh{
Connection: &connect.Connect{
Alias: "test",
Login: "root",
Expand Down
3 changes: 2 additions & 1 deletion examples/ssh/private_key_passphare/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main

import (
"github.com/misha-ssh/kernel/pkg/ssh"
"time"

"github.com/misha-ssh/kernel/pkg/connect"
)

// main for success connect start make command: up-ssh-key-pass
func main() {
ssh := &connect.Ssh{
ssh := &ssh.Ssh{
Connection: &connect.Connect{
Alias: "test",
Login: "root",
Expand Down
40 changes: 21 additions & 19 deletions internal/logger/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ import (
"github.com/misha-ssh/kernel/internal/storage"
)

const FileName = envconst.FilenameLogger
const Filename = envconst.FilenameLogger

var (
DirectionApp = storage.GetAppDir()

ErrGetStorageInfo = errors.New("err get info use log - storage")
ErrCreateStorage = errors.New("err at created log file")
ErrGetOpenFile = errors.New("err get open log file")
)

type StorageLogger struct{}
type StorageLogger struct {
storage *storage.Local
}

func NewStorageLogger() *StorageLogger {
return &StorageLogger{}
return &StorageLogger{
storage: storage.NewLocal(),
}
}

func (sl *StorageLogger) createLogFile() error {
if !storage.Exists(DirectionApp, FileName) {
err := storage.Create(DirectionApp, FileName)
func (s *StorageLogger) createLogFile() error {
if !s.storage.Exists(Filename) {
err := s.storage.Create(Filename)
if err != nil {
return err
}
Expand All @@ -38,8 +40,8 @@ func (sl *StorageLogger) createLogFile() error {
return nil
}

func (sl *StorageLogger) log(value any, status StatusLog) error {
err := sl.createLogFile()
func (s *StorageLogger) log(value any, status StatusLog) error {
err := s.createLogFile()
if err != nil {
return ErrCreateStorage
}
Expand All @@ -51,7 +53,7 @@ func (sl *StorageLogger) log(value any, status StatusLog) error {

logInfo := fmt.Sprintf("|%v| file: %s, line: %v, message: %#v", status, calledFile, line, value)

openLogFile, err := storage.GetOpenFile(DirectionApp, FileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE)
openLogFile, err := s.storage.GetOpenFile(Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE)
defer func(openLogFile *os.File) {
err = openLogFile.Close()
}(openLogFile)
Expand All @@ -65,29 +67,29 @@ func (sl *StorageLogger) log(value any, status StatusLog) error {
return nil
}

func (sl *StorageLogger) Error(value any) {
err := sl.log(value, ErrorStatus)
func (s *StorageLogger) Error(value any) {
err := s.log(value, ErrorStatus)
if err != nil {
panic(err)
}
}

func (sl *StorageLogger) Debug(value any) {
err := sl.log(value, DebugStatus)
func (s *StorageLogger) Debug(value any) {
err := s.log(value, DebugStatus)
if err != nil {
panic(err)
}
}

func (sl *StorageLogger) Info(value any) {
err := sl.log(value, InfoStatus)
func (s *StorageLogger) Info(value any) {
err := s.log(value, InfoStatus)
if err != nil {
panic(err)
}
}

func (sl *StorageLogger) Warn(value any) {
err := sl.log(value, WarnStatus)
func (s *StorageLogger) Warn(value any) {
err := s.log(value, WarnStatus)
if err != nil {
panic(err)
}
Expand Down
58 changes: 55 additions & 3 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package setup
import (
"encoding/json"
"errors"
"github.com/misha-ssh/kernel/internal/space"
"github.com/misha-ssh/kernel/pkg/ssh"
"os/user"

"github.com/misha-ssh/kernel/configs/envconst"
Expand All @@ -17,7 +19,9 @@ import (

var (
ErrCreateFileConnection = errors.New("err create file connection")
ErrSetLoggerFromConfig = errors.New("err set logger from configs")
ErrSetLoggerFromConfig = errors.New("err set logger from config")
ErrSetStorageFromConfig = errors.New("err set storage from config")
ErrSetSpaceFromConfig = errors.New("err set space from config")
ErrSetDefaultValue = errors.New("err set default value")
ErrMarshalJson = errors.New("failed to marshal json")
ErrWriteJson = errors.New("failed to write json")
Expand Down Expand Up @@ -92,8 +96,10 @@ func initFileConfig() error {
}

defaultValues := map[string]string{
envname.Theme: envconst.Theme,
envname.Logger: envconst.TypeStorageLogger,
envname.Theme: envconst.Theme,
envname.Logger: envconst.TypeStorageLogger,
envname.Space: envconst.TypeStorageSpace,
envname.Storage: envconst.TypeLocalStorage,
}

for key, value := range defaultValues {
Expand Down Expand Up @@ -163,6 +169,42 @@ func initLoggerFromConfig() error {
return nil
}

func initStorageFromConfig() error {
storageType := config.Get(envname.Storage)

switch storageType {
case envconst.TypeLocalStorage:
storage.Set(storage.NewLocal())
default:
return ErrSetStorageFromConfig
}

return nil
}

func initSpaceFromConfig() error {
storageType := config.Get(envname.Space)

switch storageType {
case envconst.TypeStorageSpace:
space.Set(
&space.Storage{
Storage: storage.Get(),
},
)
case envconst.TypeConfigSpace:
space.Set(
&space.SSHConfig{
Config: ssh.NewConfig(),
},
)
default:
return ErrSetSpaceFromConfig
}

return nil
}

// Init performs complete application initialization:
// 1. Config file setup
// 2. Logger configuration
Expand All @@ -187,6 +229,16 @@ func Init() {
panic(err)
}

err = initStorageFromConfig()
if err != nil {
panic(err)
}

err = initSpaceFromConfig()
if err != nil {
panic(err)
}

err = initFileConnections()
if err != nil {
panic(err)
Expand Down
29 changes: 29 additions & 0 deletions internal/space/space.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package space

import (
"github.com/misha-ssh/kernel/internal/storage"
"github.com/misha-ssh/kernel/pkg/connect"
)

type Space interface {
GetConnections() (*connect.Connections, error)
SaveConnection(connection *connect.Connect) error
UpdateConnection(connection *connect.Connect) (*connect.Connect, error)
DeleteConnection(connection *connect.Connect) error
}

var defaultSpace Space

func Get() Space {
if defaultSpace == nil {
defaultSpace = &Storage{
Storage: storage.Get(),
}
}

return defaultSpace
}

func Set(space Space) {
defaultSpace = space
}
26 changes: 26 additions & 0 deletions internal/space/ssh_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package space

import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/ssh"
)

type SSHConfig struct {
Config *ssh.Config
}

func (s *SSHConfig) GetConnections() (*connect.Connections, error) {
return nil, nil
}

func (s *SSHConfig) SaveConnection(connection *connect.Connect) error {
return nil
}

func (s *SSHConfig) UpdateConnection(connection *connect.Connect) (*connect.Connect, error) {
return nil, nil
}

func (s *SSHConfig) DeleteConnection(connection *connect.Connect) error {
return nil
}
Loading
Loading