specfile

package
v0.0.0-...-4dccf2e Latest Latest
Warning

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

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

Documentation

Overview

Copyright © 2020 Joseph Saylor <doug@saylorsolutions.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright © 2020 Joseph Saylor <doug@saylorsolutions.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const DEFAULT_SSH_PORT int = 22

Variables

This section is empty.

Functions

func DefaultSSHKeyPath

func DefaultSSHKeyPath() string

DefaultSSHKeyPath returns the config specified value or the default path of ~/.ssh/id_rsa

func LoadKey

func LoadKey(path string) (ssh.AuthMethod, error)

LoadKey reads a key from file

func NewSpecTemplate

func NewSpecTemplate(config *SpecTemplateConfig) (string, error)

NewSpecTemplate creates a new spec template with the given configuration parameters.

Types

type ClientFilePair

type ClientFilePair struct {
	Client  *ssh.Client
	HostTag string
	File    string
}

ClientFilePair associates a Client connection with a host tag and file

type ConfigFileData

type ConfigFileData struct {
	DefaultKey KeySpec `json:"defaultKey" yaml:"defaultKey"`
}

ConfigFileData is the format for the home config file.

func ConfigFile

func ConfigFile() (*ConfigFileData, error)

ConfigFile reads the default config from the active user's home directory.

type ConsolidatedWriter

type ConsolidatedWriter struct {
	// contains filtered or unexported fields
}

ConsolidatedWriter receives messages from all of its tail session instances and writes them to its output stream.

func NewConsolidatedWriter

func NewConsolidatedWriter(specData *SpecData, out *os.File) (*ConsolidatedWriter, error)

NewConsolidatedWriter creates tail sessions that are ready to start and write to the provided writer.

func (*ConsolidatedWriter) AddOutputFile

func (c *ConsolidatedWriter) AddOutputFile(file *os.File) error

AddOutputFile adds a file to the list of files that should have output appended to them.

func (*ConsolidatedWriter) Close

func (c *ConsolidatedWriter) Close() error

Close closes all tail sessions as well as the connected clients.

func (*ConsolidatedWriter) Start

func (c *ConsolidatedWriter) Start() error

Start starts all tail sessions. In the event of an error, all already opened sessions are closed and an error is returned.

type HostSpec

type HostSpec struct {
	Hostname string `json:"hostname" yaml:"hostname"`
	Username string `json:"username" yaml:"username"`
	File     string `json:"file" yaml:"file"`
	Port     int    `json:"port" yaml:"port"`
}

HostSpec identifies the hostname and port to connect to, as well as the file to tail.

func (*HostSpec) Validate

func (h *HostSpec) Validate() error

Validate checks the HostSpec for errors and sets reasonable defaults.

type KeySpec

type KeySpec struct {
	Path string `json:"path" yaml:"path"`
}

KeySpec specifies the path to the SSH key to be used for the host named by the SpecData.Keys map key.

func (*KeySpec) Validate

func (k *KeySpec) Validate() error

Validate checks the KeySpec for errors and sets reasonable defaults.

type SpecData

type SpecData struct {
	Hosts map[string]*HostSpec `json:"hosts" yaml:"hosts"`
	Keys  map[string]*KeySpec  `json:"keys" yaml:"keys"`
}

SpecData encapsulates runtime parameters for SSH tailing.

func ReadSpecFile

func ReadSpecFile(filename string) (*SpecData, error)

ReadSpecFile attempts to read SpecData from the specified file.

func (*SpecData) Validate

func (s *SpecData) Validate() error

Validate checks the SpecData for errors and sets reasonable defaults.

type SpecTemplateConfig

type SpecTemplateConfig struct {
	WithComments bool
	ExcludeKeys  bool
}

SpecTemplateConfig config

type TailChannelWriter

type TailChannelWriter struct {
	// contains filtered or unexported fields
}

func (TailChannelWriter) Write

func (t TailChannelWriter) Write(b []byte) (n int, err error)

type TailSession

type TailSession struct {
	// contains filtered or unexported fields
}

TailSession represents

func NewTailSession

func NewTailSession(client *ClientFilePair) (ts *TailSession, err error)

NewTailSession creates a new TailSession instance that is ready to be started.

func (*TailSession) Close

func (s *TailSession) Close() (err error)

Close stops the running tail session and disconnects the client.

func (*TailSession) Closed

func (s *TailSession) Closed() bool

Closed returns whether the tail session has been previously closed. A closed tail session cannot be restarted.

func (*TailSession) Started

func (s *TailSession) Started() bool

Started returns whether the tail session has already been started.

Jump to

Keyboard shortcuts

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