service

package
v1.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2019 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecuteCommands

func ExecuteCommands(ctx context.Context, d Service, commands []schema.Command) (err error)

ExecuteCommands executes provided list of commands using specified service.

func GenerateCA

func GenerateCA(config *schema.GeneralConfig) error

GenerateCA generates CA key and certificate needed for sign device/client certificates.

func GenerateCerts

func GenerateCerts(config *schema.GeneralConfig, subject string) error

GenerateCerts generates and sign using CA certificate generic key and certificate.

Types

type ApplicationStatus

type ApplicationStatus struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ApplicationStatus stores final execution status that should be returned to OS.

func (*ApplicationStatus) Get

func (app *ApplicationStatus) Get() int

Get returns application status code.

func (*ApplicationStatus) SetCode

func (app *ApplicationStatus) SetCode(status int)

SetCode sets application status code.

type CopyFiler

type CopyFiler interface {
	CopyFile(ctx context.Context, local, remote string) error
}

type GenericDevice

type GenericDevice struct {
	AppConfig *schema.GeneralConfig
	Host      schema.Host
	// contains filtered or unexported fields
}

GenericDevice defines basic setup for device instance.

func (*GenericDevice) SetConfig

func (d *GenericDevice) SetConfig(config *schema.GeneralConfig)

func (*GenericDevice) SetHost

func (d *GenericDevice) SetHost(host schema.Host)

type HandlerFunc

type HandlerFunc func(service Service) error

HandlerFunc executes sequence of operations in context of service using established already connection and passed by context into handler.

type MTAPI

type MTAPI struct {
	GenericDevice
	// contains filtered or unexported fields
}

MTAPI defines Mikrotik secure API service by extending generic device with Routeros connection.

func (*MTAPI) Close

func (d *MTAPI) Close() error

Close used session

func (MTAPI) GetDevice

func (d MTAPI) GetDevice() *GenericDevice

func (*MTAPI) GetPasswords

func (d *MTAPI) GetPasswords() []string

func (*MTAPI) GetPort

func (d *MTAPI) GetPort() string

func (*MTAPI) GetUser

func (d *MTAPI) GetUser() string

TODO refactor!!

func (*MTAPI) HandleSequence

func (d *MTAPI) HandleSequence(ctx context.Context, handler HandlerFunc) error

func (MTAPI) RunCmd

func (d MTAPI) RunCmd(body string, expect *regexp.Regexp) (result string, err error)

type NewServiceFunc

type NewServiceFunc func(config *schema.GeneralConfig, host schema.Host) Service

NewServiceFunc creates new service for handle given host and configuration.

type SSH

type SSH struct {
	GenericDevice
	// contains filtered or unexported fields
}

SSH defines SSH service by extending generic device with ssh specific client connection details.

func (*SSH) Close

func (d *SSH) Close() error

Close used session

func (*SSH) CopyFile

func (d *SSH) CopyFile(ctx context.Context, local, remote string) error

CopyFile copies file over SFTP.

func (*SSH) GetDevice

func (d *SSH) GetDevice() *GenericDevice

func (*SSH) GetPasswords

func (d *SSH) GetPasswords() []string

func (*SSH) GetPort

func (d *SSH) GetPort() string

func (*SSH) GetUser

func (d *SSH) GetUser() string

func (*SSH) HandleSequence

func (d *SSH) HandleSequence(ctx context.Context, handler HandlerFunc) (err error)

HandleSequence establish connection and executes handler function with sequence of tasks/commands to do.

func (*SSH) RunCmd

func (d *SSH) RunCmd(body string, expect *regexp.Regexp) (result string, err error)

RunCmd runs a command using SSH and returns result.

type Service

type Service interface {
	GetUser() string
	GetPasswords() []string
	GetPort() string
	GetDevice() *GenericDevice

	SetHost(schema.Host)
	SetConfig(*schema.GeneralConfig)

	HandleSequence(ctx context.Context, handler HandlerFunc) error
	RunCmd(string, *regexp.Regexp) (string, error)

	Close() error
}

Service represents common interface for all supported services.

func NewMTAPIService

func NewMTAPIService(config *schema.GeneralConfig, host schema.Host) Service

func NewSSHService

func NewSSHService(config *schema.GeneralConfig, host schema.Host) Service

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL