moseutils

package
v0.0.0-...-23bdcb8 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMsg outputs red text to signify an error
	ErrMsg = color.Red
	// Info outputs yellow text to signify an informational message
	Info = color.Yellow
	// Msg outputs green text to signify success
	Msg = color.Green
)
View Source
var (
	// Cli contains input from the command line
	Cli CliArgs
	// JSONSettings contains settings that are specified in settings.json
	JSONSettings Settings
)

Functions

func AskUserQuestion

func AskUserQuestion(question string, osTarget string) (bool, error)

AskUserQuestion takes a question from a user and returns true or false based on the input. The operating system must be specified as an input in order to handle the line ending properly; Windows uses a different line ending scheme than Unix systems Loosely based on https://tutorialedge.net/golang/reading-console-input-golang/

func Cd

func Cd(dir string)

Cd changes the directory to the one specified with dir

func CpFile

func CpFile(src string, dst string)

CpFile is used to copy a file from a source (src) to a destination (dst)

func CreateFolders

func CreateFolders(folders []string) bool

CreateFolders creates folders specified in an input slice (folders) It returns true if it is able to create all of the folders Otherwise it returns false

func File2lines

func File2lines(filePath string) ([]string, error)

File2lines returns a slice that contains all of the lines of the file specified with filePath Resource: https://siongui.github.io/2017/01/30/go-insert-line-or-string-to-file/

func FileExists

func FileExists(fileLoc string) bool

FileExists returns true if a file input (fileLoc) exists on the filesystem Otherwise it returns false

func FindFile

func FindFile(fileName string, dirs []string) (bool, string)

FindFile locates a file (fileName) in a list of input directories (dir) If the file is found, then it returns true along with the file location Otherwise it returns false with an empty string

func FindFiles

func FindFiles(locations []string, extensionList []string, fileNames []string, dirNames []string, debug bool) ([]string, []string)

FindFiles finds based on their file extension in specified directories locations: slice with locations to search for files extensionList: slice with file extensions to check for fileNames: slice with filenames to search for Returns files found that meet the input criteria

func GetFileAndDirList

func GetFileAndDirList(searchDirs []string) ([]string, []string)

GetFileAndDirList gets all of the files and directories specified the initial search location (searchDirs) It returns a list of files and a list of directories found

func GetHostname

func GetHostname() string

GetHostname returns the hostname of the local system

func GetLocalIP

func GetLocalIP() (string, error)

GetLocalIP returns the IP address of the local system

func GrepFile

func GrepFile(filePath string, regex *regexp.Regexp) []string

GrepFile looks for patterns in a file (filePath) using an input regex (regex) It will return any matches that are found in the file in a slice

func InsertStringToFile

func InsertStringToFile(path, str string, index int) error

InsertStringToFile with insert a string (str) into the n-th line (index) of a specified file (path) Resource: https://siongui.github.io/2017/01/30/go-insert-line-or-string-to-file/

func LinesFromReader

func LinesFromReader(r io.Reader) ([]string, error)

LinesFromReader will return the lines read from a reader Resource: https://siongui.github.io/2017/01/30/go-insert-line-or-string-to-file/

func RemoveTracker

func RemoveTracker(filePath string, osTarget string, destroy bool)

RemoveTracker removes a file created with TrackChanges

func ReplLineInFile

func ReplLineInFile(filePath string, delim string, replStr string) (bool, string)

ReplLineInFile will replace a line in a file (filePath) with the specified replStr and delimiter (delim) It will return true with the path to the file if successful Otherwise it will return false and an empty string

func SliceUniqMap

func SliceUniqMap(s []string) []string

SliceUniqMap is an idiomatic way to remove duplicates in a slice Resource: https://www.reddit.com/r/golang/comments/5ia523/idiomatic_way_to_remove_duplicates_in_a_slice/

func StartServer

func StartServer(port int, webDir string, ssl bool, cert string, key string, waitTime time.Duration, singleServe bool) *http.Server

StartServer stands up a web server that can be used to serve files

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice can be used to determine if a string exists in a slice

func TarFiles

func TarFiles(files []string, tarLocation string)

TarFiles will create a tar file at a specific location (tarLocation) with the files specified (files)

func TrackChanges

func TrackChanges(filePath string, content string) (bool, error)

TrackChanges is used to track changes in a file

Types

type CliArgs

type CliArgs struct {
	OSArch               string
	Cmd                  string
	Debug                bool
	ExfilPort            int
	FilePath             string
	FileUpload           string
	LocalIP              string
	PayloadName          string
	OSTarget             string
	WebSrvPort           int
	RemoteUploadFilePath string
	SettingsPath         string
	ServeSSL             bool
	CMTarget             string
	TimeToServe          int
	Rhost                string
}

CliArgs holds command line arguments specified through user input

func ParseCLIArgs

func ParseCLIArgs() CliArgs

ParseCLIArgs parses all specified command line arguments

type Settings

type Settings struct {
	AnsibleBackupLoc    string
	ChefClientKey       string
	ChefNodeName        string
	ChefValidationKey   string
	CleanupFile         string
	ContainerName       string
	ImageName           string
	PuppetBackupLoc     string
	RemoteHost          string
	SSLCertPath         string
	SSLKeyPath          string
	SaltBackupLoc       string
	TargetChefServer    string
	TargetOrgName       string
	TargetValidatorName string
	UploadFilePath      string
}

Settings represents the configuration information found in settings.json

type UserInput

type UserInput struct {
	// CLI
	OSArch               string
	Cmd                  string
	Debug                bool
	ExfilPort            int
	FilePath             string
	FileUpload           string
	LocalIP              string
	PayloadName          string
	NoServe              bool
	OSTarget             string
	WebSrvPort           int
	RemoteUploadFilePath string
	Rhost                string
	SettingsPath         string
	ServeSSL             bool
	CMTarget             string
	TimeToServe          int

	// Settings
	AnsibleBackupLoc    string
	ChefClientKey       string
	ChefNodeName        string
	ChefValidationKey   string
	CleanupFile         string
	ContainerName       string
	ImageName           string
	PuppetBackupLoc     string
	RemoteHost          string
	SaltBackupLoc       string
	SSLCertPath         string
	SSLKeyPath          string
	TargetChefServer    string
	TargetOrgName       string
	TargetValidatorName string
	UploadFilePath      string
}

UserInput holds all values from command line arguments and the settings.json This is a necessity resulting from templates needing to take values from a single struct, and MOSE taking user input from multiple sources

func GetUserInput

func GetUserInput() UserInput

GetUserInput returns all user input parameters specified through command line arguments and the settings.json file

Jump to

Keyboard shortcuts

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