Loading repository data…
Loading repository data…
misha-ssh / repository
⚡️ The core for ssh client on go
This package acts as the core for an ssh client written in go
Made using data from packages:
install this package in your repository
go get github.com/misha-ssh/kernel
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
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)
}
}
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)
}
}
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)
}
}
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)
}
}
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)
}
}
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)
}
}
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)
}
This structure describes our connection
We pass this structure to the commands:
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 devicePassword - 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 deviceType - there is only one connection type so far - connect.TypeSSHCreatedAt - the creation time is filled in manuallyUpdatedAt - the update time is filled in manuallySshOptions - this is a structure with additional fields for creating software - connect.TypeSSHPort - the port is filled in manuallyPrivateKey - the path along with the name of the private keyPassphrase - the pass for private keypackage 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(time.RFC3339),
UpdatedAt: time.Now().Format(time.RFC3339),
SshOptions: &connect.SshOptions{
Port: 22,
PrivateKey: "/path/to/private/key",
Passphrase: "",
},
}
}
for local testing, you can raise your ssh servers - there are three types of them.
to run, write the command:
make up-ssh
to install and remove the server:
make down-ssh
Server accesses:
login - rootaddress - localhostpassword - passwordport - 22to run, write the command:
make up-ssh-key
to install and remove the server:
make down-ssh-key
Server accesses:
login - rootaddress - localhostprivate key - ./dockerkeyport - 22to run, write the command:
make up-ssh-port
to install and remove the server:
make down-ssh-port
Server accesses:
login - rootaddress - localhostpassword - passwordport - 2222to run, write the command:
make up-ssh-key-pass
to install and remove the server:
make down-ssh-key-pass
Server accesses:
login - rootaddress - localhostprivate key - ./dockerkeyWithPassport - 22passphrase - passwordThe 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 directoryTheme - The theme is an application, there is no implementation at this stage.DirectionPrivateKeys - the name of the directory where the keys will be savedFilenameConnections - the name of the connection fileFilenameConfig - the name of the file with the application configsNameServiceCryptKey - the names of the service that will store the private key for encryptionTypeConsoleLogger - type for console loggingTypeStorageLogger - the type for logging to a fileTypeCombinedLogger - type for all types of loggingConfig keys (these keys are located in the application configuration):
Theme - stores the application's theme, in this case there is no implementationLogger - stores the type of application loggingYou 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
We appreciate your support and look forward to making our product even better with your help!