Misha ssh - kernel

This package acts as the core for an ssh client written in go
Made using data from packages:
π Features
- Connection Management: Commands for creating, connecting, deleting, and updating your connection
- Download & Upload files: Commands for working with sftp file transfer
- Data encryption: Your connection is securely encrypted
- Configurations: Possibility of connection configuration
- The local environment There is an environment for testing the connection
- Flexibility The ability to embed in any client on go
β¨ Install
install this package in your repository
go get github.com/misha-ssh/kernel
π Examples & Usage
You will be provided with a list of commands that you can use in your projects
The code with the commands will be on the way - link
π Connect
The command to connect to the remote server
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
err := kernel.Connect(connection)
if err != nil {
panic(err)
}
}
π Download
The command to connect to the remote server
this command downloads the file from the server
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
remoteFile := "/remote.txt"
localFile := "~/local.txt"
err := kernel.Download(connection, remoteFile, localFile)
if err != nil {
panic(err)
}
}
π Upload
The command to connect to the remote server
this command is to upload a file to a remote server
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
remoteFile := "/upload.txt"
localFile := "/absolute/path/your_local_file.txt"
err := kernel.Upload(connection, localFile, remoteFile)
if err != nil {
panic(err)
}
}
βοΈ Create
The command to create a connection
this command saves the connection to a file and goes through the dependency initialization cycle
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
err := kernel.Create(connection)
if err != nil {
panic(err)
}
}
πͺ Update
The command to update the connection
This command also updates the connection data if you need to resave the private key
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
err := kernel.Update(connection, "test")
if err != nil {
panic(err)
}
}
π Delete
The command to delete the connection
This command removes the connection from the file and also deletes the private key if it has been saved
package main
import (
"github.com/misha-ssh/kernel/pkg/connect"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connection := &connect.Connect{...}
err := kernel.Delete(connection)
if err != nil {
panic(err)
}
}
π List
The command to get a list of connections
This command will list the connections from the previously created connections
package main
import (
"fmt"
"github.com/misha-ssh/kernel/pkg/kernel"
)
func main() {
connections, err := kernel.List()
if err != nil {
panic(err)
}
fmt.Println(connections)
}
π₯ Struct Connection
This structure describes our connection
We pass this structure to the commands:
- Connect
- Create
- Update
- Delete
Description of fields:
Alias - unique name (we use it when selecting an exception from the list and create unique connections to identify
them)
Login - the user's login on the remote device
Password - if you have a password connection, then fill in this field, if with a key, then leave an empty line.
Address - the address of the remote device
Type - there is only one connection type so far - connect.TypeSSH
CreatedAt - the creation time is filled in manually
UpdatedAt - the update time is filled in manually
SshOptions - this is a structure with additional fields for creating software - connect.TypeSSH
Port - the port is filled in manually
PrivateKey - the path along with the name of the private key
package main
import (
"time"
"github.com/misha-ssh/kernel/pkg/connect"
)
func main() {
connection := &connect.Connect{
Alias: "test",
Login: "root",
Password: "password",
Address: "localhost",
Type: connect.TypeSSH,
CreatedAt: time.Now().Format("2006.01.02 15:04:05"),
UpdatedAt: time.Now().Format("2006.01.02 15:04:05"),
SshOptions: &connect.SshOptions{
Port: 22,
PrivateKey: "/path/to/private/key",
},
}
}
π€ Run ssh server
for local testing, you can raise your ssh servers - there are three types of them.
- password connection
to run, write the command:
make up-ssh
to install and remove the server:
make down-ssh
Server accesses:
login - root
address - localhost
password - password
port - 22
- connect with a private key
to run, write the command:
make up-ssh-key
to install and remove the server:
make down-ssh-key
Server accesses:
login - root
address - localhost
private key - ./dockerkey
port - 22
- connecting via a non-standard port
to run, write the command:
make up-ssh-port
to install and remove the server:
make down-ssh-port
Server accesses:
login - root
address - localhost
password - password
port - 2222
π Description variable
The variables that the application uses are located here:
App values (the values that are used in the application and also in the config):
AppName - project name & project directory
Theme - The theme is an application, there is no implementation at this stage.
DirectionPrivateKeys - the name of the directory where the keys will be saved
FilenameConnections - the name of the connection file
FilenameConfig - the name of the file with the application configs
NameServiceCryptKey - the names of the service that will store the private key for encryption
TypeConsoleLogger - type for console logging
TypeStorageLogger - the type for logging to a file
TypeCombinedLogger - type for all types of logging
Config keys (these keys are located in the application configuration):
Theme - stores the application's theme, in this case there is no implementation
Logger - stores the type of application logging
π§ͺ Testing
You can run the command for testing after the step with local installation
The command to launch the linter:
make lint
Run Unit tests:
make tests
Run test coverage:
make test-coverage
Run test e2e:
make tests-integration
π€ Feedback
We appreciate your support and look forward to making our product even better with your help!
@Denis Korbakov