utils

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFile string

ConfigFile is the currently loaded config file

Functions

func AddDefaultFlagCompletion added in v0.1.3

func AddDefaultFlagCompletion() cmd.Option

AddDefaultFlagCompletion adds the default completion for most used flags

func ChangeViperValues

func ChangeViperValues(key string, value interface{}) error

ChangeViperValues - changes the values of the viper configuration and saves it in the config file of inspr, if the file is not created it will return an error.

func CheckEmptyArgs

func CheckEmptyArgs(args map[string]string) error

CheckEmptyArgs receives the args of a cli command and returns a error in case any of them are empty

func ExistingKeys

func ExistingKeys() []string

ExistingKeys - returns to the user all available keys in viper's configs.

func ExistsKey

func ExistsKey(key string) bool

ExistsKey - informs to the user if the key passed exists in the default keys that are saved in the insprctl config file

func GetCliClient

func GetCliClient() controller.Interface

GetCliClient returns the default controller client for cli.

func GetCliOutput

func GetCliOutput() io.Writer

GetCliOutput returns the default output for cli.

func GetConfiguredHost added in v0.1.3

func GetConfiguredHost() string

GetConfiguredHost is responsible for returning config value for host. Avoids having public constants

func GetConfiguredScope

func GetConfiguredScope() string

GetConfiguredScope is responsible for returning config value for scope. Avoids having public constants

func GetConfiguredServerIP

func GetConfiguredServerIP() string

GetConfiguredServerIP is responsible for returning config value for serverIp. Avoids having public constants

func GetScope

func GetScope() (string, error)

GetScope retreives the path to be used as base scope for an Insprd request. Takes into consideration viper config and scope flag.

func GetToken

func GetToken(path string) []byte

GetToken gets a token from a filepath, returns an empty token if file does not exist.

func InitViperConfig

func InitViperConfig()

InitViperConfig - sets defaults values and where is the file in which new values can be read

func ProcessAliasArg

func ProcessAliasArg(arg, scope string) (string, string, error)

ProcessAliasArg is responsible for separating a path into an alias name and it's parent's path. < path, name, error >

func ProcessArg

func ProcessArg(arg, scope string) (string, string, error)

ProcessArg is responsible for separating a path into an component name and it's parent's path. < path, name, error >

func ReadConfigFromFile

func ReadConfigFromFile(file string) error

ReadConfigFromFile reads a config from a file

func ReadDefaultConfig

func ReadDefaultConfig() error

ReadDefaultConfig reads the default insprctl configuration

func ReadViperConfig

func ReadViperConfig(basePath string) error

ReadViperConfig - reads the inspr's viper config, in case it didn't found any, it creates one with the defaults values

func ServerIpKey added in v0.1.3

func ServerIpKey() string

ServetIpKey returns the key value of ConfigServerIP Avoids having public constants

func SetClient

func SetClient(url string, host string)

SetClient sets the default server IP of CLI

func SetMockedClient

func SetMockedClient(err error)

SetMockedClient configures singleton's client as a mocked client given a error

func SetOutput

func SetOutput(out io.Writer)

SetOutput sets the default output of CLI

Types

type Authenticator

type Authenticator struct {
	TokenPath string
}

Authenticator is responsible for implementing the interface methods defined in the rest/request pkg.

func (Authenticator) GetToken

func (a Authenticator) GetToken() ([]byte, error)

GetToken read the token from the file specified in the struct TokenPath and returns it's bytes

func (Authenticator) SetToken

func (a Authenticator) SetToken(token []byte) error

SetToken receives a new token as a parameter and then writes it in the file specified in the TokenPath

Jump to

Keyboard shortcuts

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