Documentation ¶
Index ¶
- Constants
- Variables
- func AutoEnable()
- func BlankLineStrip(data []string) []string
- func CheckFiletoWrite(filename, checksum string)
- func CheckFullFilename(file string)
- func CheckFullPath(file string)
- func CheckLastFile(file string, perms int, owner string)
- func ChecksumCompare(data string, checksum string) bool
- func ChownFile(filepath string, owner string) (bool, int, int)
- func CompareFilename(file string) string
- func CompressData(data string) ([]byte, uint64)
- func ComputeChecksum(data string) string
- func Connect(server string, token string) (*consul.Client, error)
- func DDAPIConnect(api, app string) *datadog.Client
- func DDCopyDataEvent(dd *datadog.Client, keyFrom, keyTo string)
- func DDLengthEvent(dd *datadog.Client, key, value string)
- func DDSaveDataEvent(dd *datadog.Client, key, value string)
- func DDSaveStopEvent(dd *datadog.Client, key, value string)
- func DDStopEvent(dd *datadog.Client, key, value string)
- func DecompressData(data []byte, compressFlags uint64) string
- func Del(c *consul.Client, key string) bool
- func FileLockPath(file string) string
- func GenerateLockReason() string
- func Get(c *consul.Client, key string) string
- func GetCurrentUsername() string
- func GetGroupID(owner string) int
- func GetHostname() string
- func GetOwnerID(owner string) int
- func GetRaw(c *consul.Client, key string) ([]byte, uint64)
- func GetStringConfig(c *simpleyaml.Yaml, configValue string) string
- func KeyPath(key string, suffix string) string
- func LastFilename(file string) string
- func LengthCheck(data string, minLength int) bool
- func LineCount(data string) int
- func LoadConfig(filename string)
- func LockFile(key string) bool
- func LockFilePath(file string) string
- func LockFileRemove(file string)
- func LockFileWrite(file string)
- func Log(message, priority string)
- func LogFatal(message string, id string, location string)
- func ParseConfig(data []byte) *simpleyaml.Yaml
- func ParseStatsdAddress(address string) (string, int)
- func RandomTmpFile() string
- func ReadFile(filepath string) string
- func ReadURL(url string) string
- func RemoveFile(filename string)
- func Retry(callback func() error, tries int)
- func ReturnCurrentUTC() string
- func RunCommand(command string) bool
- func RunTime(start time.Time, key string, location string)
- func Set(c *consul.Client, key string, value string) bool
- func SetDirection() string
- func SetRaw(c *consul.Client, key string, value []byte, flags uint64) bool
- func SortFile(file string) string
- func StatsdChecksum(key string)
- func StatsdConsul(key, location string)
- func StatsdIn(key string, dataLength int, data string)
- func StatsdLength(key string)
- func StatsdLock(key string)
- func StatsdLocked(file string)
- func StatsdOut(key string)
- func StatsdPanic(key, location string)
- func StatsdRaw(key string)
- func StatsdReconnect(times int)
- func StatsdRunTime(key string, location string, msec int64)
- func StatsdSetup() *godspeed.Godspeed
- func StatsdUnlock(key string)
- func UnixDiff(old, new string) string
- func UnlockFile(key string) bool
- func WriteFile(data string, filepath string, perms int, owner string)
Constants ¶
const ( GZIPb64 = iota BROTLI )
Variables ¶
var ( // KeyFrom is the key in the Consul KV data store where we want to pull data. // This configuration variable will pull data from: // /PrefixLocation/KeyFrom/data // /PrefixLocation/KeyFrom/checksum KeyFrom string // KeyTo is the key in the Consul KV data store where we want to send data to. // This configuration variable will save data into: // /PrefixLocation/KeyTo/data // /PrefixLocation/KeyTo/checksum KeyTo string )
var ( // KeyInLocation is the key in the Consul KV data store where we want to store the data. // This configuration variable will save data into: // /PrefixLocation/KeyInLocation/data // /PrefixLocation/KeyInLocation/checksum KeyInLocation string // FiletoRead is the file to read to get the data. FiletoRead string // Sorted is an option to sort the file alphabetically. Doesn't work on many types // of files. But works great on files with many blank lines where ordering doesn't matter. Sorted bool // UrltoRead is an HTTP URL to read data from using ReadURL(). UrltoRead string )
var ( // FiletoLock is the location we want to write the data to. FiletoLock string // LockReason is the reason why you are locking the file. LockReason string )
var ( // KeyOutLocation This Consul key is the location we want to pull data from. // This data MUST be in the standard kvexpress structure of: // /PrefixLocation/KeyOutLocation/data // /PrefixLocation/KeyOutLocation/checksum KeyOutLocation string // FiletoWrite is the location we want to write the data to. FiletoWrite string // IgnoreStop is a special command to pull data EVEN if there's a stop key present. IgnoreStop bool )
var ( // RawKeyOutLocation This Consul key is the location we want to pull data from. // This data can be ANY Consul key and doesn't have to be in any particular format or structure. // It doesn't have to have a Checksum either - it can be any Consul key at all. // Give the complete path - does not use PrefixLocation. RawKeyOutLocation string // RawFiletoWrite is the location we want to write the data to. RawFiletoWrite string )
var ( // Token is used by the Consul API and references an ACL that Consul uses // to control access the KV store: https://www.consul.io/docs/internals/acl.html Token string // PostExec refers to an optional command to run upon // successful completion of the command's task. An example: // kvexpress out -k hosts -f /etc/hosts -e "sudo pkill -HUP dnsmasq" PostExec string // ConsulServer if you are not talking to a Consul node on localhost - this is for you. ConsulServer string // PrefixLocation all Consul KV data related to kvexpress is stored underneath // this path. Defaults to `kvexpress` which PrefixLocation string // MinFileLength is the minimum number of lines a file is expected to have. // Keeps blank or truncated files out of the KV store. MinFileLength int // FilePermissions are the permissions for the files that are written to the filesystem. FilePermissions int // DogStatsd enables reporting of tagged statsd metrics to the local Datadog Agent. // http://docs.datadoghq.com/guides/dogstatsd/ DogStatsd bool // Owner will be the owner of any file that's been written to the filesystem. Owner string // ConfigFile is the path to a yaml encoded configuration file. // Loaded with LoadConfig. ConfigFile string // DogStatsdAddress if you're not running a local Datadog agent. DogStatsdAddress string DogStatsdHost string DogStatsdPort int // DatadogAPIKey is for sending events to Datadog through the HTTP api. DatadogAPIKey string // DatadogAPPKey is for sending events to Datadog through the HTTP api. DatadogAPPKey string // Compress is for compressing data on the way in and out of Consul. Compress bool // Direction adds information about which command is running to the logs. Direction string // Verbose logs all output to stdout. Verbose bool )
var ( // KeyStopLocation This Consul key is the one we want to halt all updates and distribution of. KeyStopLocation string // KeyStopReason This is the reason that we are stopping distribution of the key. KeyStopReason string )
var ( // FiletoClean is the file we want to erase. FiletoClean string )
var ( // FiletoUnlock is the location we want to write the data to. FiletoUnlock string )
var RootCmd = &cobra.Command{ Use: "kvexpress", Short: "Configuration data -> Consul KV -> Filesytem", Long: `Small Go program to put and pull configuration data out of Consul and write to filesystem.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("`kvexpress -h` for help information.") fmt.Println("`kvexpress -v` for version information.") }, }
RootCmd is the default Cobra struct that starts it all off. https://github.com/spf13/cobra
Functions ¶
func AutoEnable ¶
func AutoEnable()
AutoEnable helps to automatically enable flags based on cues from the environment.
func BlankLineStrip ¶
BlankLineStrip takes a slice of strings, ranges over them and only returns a slice of strings where the lines weren't blank.
func CheckFiletoWrite ¶
func CheckFiletoWrite(filename, checksum string)
CheckFiletoWrite takes a filename and checksum and stops execution if there is a directory OR the file has the same checksum.
func CheckFullFilename ¶
func CheckFullFilename(file string)
CheckFullFilename makes sure that the filename begins with a slash.
func CheckFullPath ¶
func CheckFullPath(file string)
CheckFullPath will check the path and recursively create directories if they don't exist.
func CheckLastFile ¶
CheckLastFile creates a .last file if it doesn't exist.
func ChecksumCompare ¶
ChecksumCompare takes a string, generates a SHA256 checksum and compares against the passed checksum to see if they match.
func CompareFilename ¶
CompareFilename returns a .compare filename based on the passed file.
func CompressData ¶
CompressData compresses a string to place into Consul's KV store.
func ComputeChecksum ¶
ComputeChecksum takes a string and computes a SHA256 checksum.
func DDAPIConnect ¶
func DDAPIConnect(api, app string) *datadog.Client
DDAPIConnect connects to the Datadog API and returns a client object.
func DDCopyDataEvent ¶
func DDCopyDataEvent(dd *datadog.Client, keyFrom, keyTo string)
DDCopyDataEvent sends a Datadog event to the API when we have used `kvexpress copy` to copy a Consul key.
func DDLengthEvent ¶
func DDLengthEvent(dd *datadog.Client, key, value string)
DDLengthEvent sends a Datadog event to the API when the file/url is too short.
func DDSaveDataEvent ¶
func DDSaveDataEvent(dd *datadog.Client, key, value string)
DDSaveDataEvent sends a Datadog event to the API when we have updated a Consul key.
func DDSaveStopEvent ¶
func DDSaveStopEvent(dd *datadog.Client, key, value string)
DDSaveStopEvent sends a Datadog event when we have added a stop key to Consul.
func DDStopEvent ¶
func DDStopEvent(dd *datadog.Client, key, value string)
DDStopEvent sends a Datadog event to the API when there's a stop key present.
func DecompressData ¶
DecompressData decompresses a string taken from Consul's KV store.
func FileLockPath ¶
FileLockPath generates the path for the KV store for a particular file.
func GenerateLockReason ¶
func GenerateLockReason() string
GenerateLockReason creates a reason with filename, username and date.
func GetCurrentUsername ¶
func GetCurrentUsername() string
GetCurrentUsername grabs the current user running the kvexpress binary.
func GetGroupID ¶
GetGroupID looks up the Group Id for the owner passed.
func GetOwnerID ¶
GetOwnerID looks up the User Id for the owner passed.
func GetStringConfig ¶
func GetStringConfig(c *simpleyaml.Yaml, configValue string) string
GetStringConfig grabs the string from the config object.
func LastFilename ¶
LastFilename returns a .last filename based on the passed file.
func LengthCheck ¶
LengthCheck makes sure a string has at least minLength lines.
func LoadConfig ¶
func LoadConfig(filename string)
LoadConfig opens a file and reads the yaml formatted configuration data. It will set configuration globals and/or ENV variables as required.
func LockFile ¶
LockFile sets a key in Consul so that a particular file won't be updated. See commands/lock.go
func LockFilePath ¶
LockFilePath generates a filename for the `$filename.locked` files used by `kvexpress lock` and `kvexpress unlock`
func LockFileRemove ¶
func LockFileRemove(file string)
LockFileRemove removes a `$filename.locked` when running `kvexpress unlock`.
func LockFileWrite ¶
func LockFileWrite(file string)
LockFileWrite writes a `$filename.locked` file with instructions for how to unlock.
func Log ¶
func Log(message, priority string)
Log adds the global Direction to a message and sends to syslog. Syslog is setup in main.go
func ParseConfig ¶
func ParseConfig(data []byte) *simpleyaml.Yaml
ParseConfig takes the data from a file and parses the config.
func ParseStatsdAddress ¶
func RandomTmpFile ¶
func RandomTmpFile() string
RandomTmpFile is used to create a .compare or .last file for UrltoRead()
func RemoveFile ¶
func RemoveFile(filename string)
RemoveFile takes a filename and stops if it's a directory. It will log success or failure of removal.
func ReturnCurrentUTC ¶
func ReturnCurrentUTC() string
ReturnCurrentUTC returns the current UTC time in RFC3339 format.
func RunCommand ¶
RunCommand runs a cli command with arguments.
func RunTime ¶
RunTime sends time coded logs and dogstatsd metrics when called. Location is set when the RunTime function is called.
func SortFile ¶
SortFile takes a string, splits it into lines, removes all blank lines using BlankLineStrip() and then sorts the remaining lines.
func StatsdChecksum ¶
func StatsdChecksum(key string)
StatsdChecksum sends metrics to Dogstatsd on a `kvexpress out` operation where the checksum doesn't match.
func StatsdConsul ¶
func StatsdConsul(key, location string)
StatsdConsul sends metrics to DogStatsd when Consul has a KV write or delete error.
func StatsdLength ¶
func StatsdLength(key string)
StatsdLength sends metrics to Dogstatsd on a `kvexpress out` operation where the file isn't long enough.
func StatsdLock ¶
func StatsdLock(key string)
StatsdLock sends metrics to Dogstatsd on a `kvexpress lock` operation.
func StatsdLocked ¶
func StatsdLocked(file string)
StatsdLocked sends metrics to Dogstatsd on a `kvexpress out` operation that is blocked by a locked file.
func StatsdOut ¶
func StatsdOut(key string)
StatsdOut sends metrics to Dogstatsd on a `kvexpress out` operation.
func StatsdPanic ¶
func StatsdPanic(key, location string)
StatsdPanic sends metrics to Dogstatsd when something really bad happens. It also stops the execution of kvexpress.
func StatsdRaw ¶
func StatsdRaw(key string)
StatsdRaw sends metrics to Dogstatsd on a `kvexpress raw` operation.
func StatsdReconnect ¶
func StatsdReconnect(times int)
StatsdReconnect sends metrics when we have Consul connection retries.
func StatsdRunTime ¶
StatsdRunTime sends metrics to Dogstatsd on various operations.
func StatsdSetup ¶
StatsdSetup sets up the connection to dogstatsd.
func StatsdUnlock ¶
func StatsdUnlock(key string)
StatsdUnlock sends metrics to Dogstatsd on a `kvexpress unlock` operation.
func UnlockFile ¶
UnlockFile removes a key in Consul so that a particular file can be updated. See commands/unlock.go
Types ¶
This section is empty.