From 8eb041014382aa7cda7023a1b9770dc3c77c1cde Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 23 Jul 2023 16:34:27 +0000 Subject: [PATCH] Bump github.com/txn2/txeh from 1.4.0 to 1.5.2 Bumps [github.com/txn2/txeh](https://github.com/txn2/txeh) from 1.4.0 to 1.5.2. - [Release notes](https://github.com/txn2/txeh/releases) - [Changelog](https://github.com/txn2/txeh/blob/master/.goreleaser.yml) - [Commits](https://github.com/txn2/txeh/compare/v1.4.0...v1.5.2) --- updated-dependencies: - dependency-name: github.com/txn2/txeh dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/txn2/txeh/README.md | 10 +- vendor/github.com/txn2/txeh/goreleaser.yml | 125 --------------------- vendor/github.com/txn2/txeh/txeh.go | 82 ++++++++++---- vendor/modules.txt | 4 +- 6 files changed, 73 insertions(+), 154 deletions(-) delete mode 100644 vendor/github.com/txn2/txeh/goreleaser.yml diff --git a/go.mod b/go.mod index 585884a9..8c73d701 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/radovskyb/watcher v1.0.7 github.com/spf13/cobra v1.7.0 github.com/stretchr/testify v1.8.4 - github.com/txn2/txeh v1.4.0 + github.com/txn2/txeh v1.5.2 gopkg.in/yaml.v2 v2.4.0 k8s.io/api v0.26.3 k8s.io/apimachinery v0.27.4 diff --git a/go.sum b/go.sum index 4a254036..5111b14d 100644 --- a/go.sum +++ b/go.sum @@ -155,8 +155,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/txn2/txeh v1.4.0 h1:0tdvpA4HGJrj8X3kmrU6o/JFStI009nKxwDpMK5CnRU= -github.com/txn2/txeh v1.4.0/go.mod h1:Mgq0hY184zCrDBLgvkIp+9NYGHoYbJcu4xKqUcx1shc= +github.com/txn2/txeh v1.5.2 h1:ny1K6ycI0YP2TEZXwvfQ5ckXzRHOX9OWpbKv29ZqXH8= +github.com/txn2/txeh v1.5.2/go.mod h1:qYzGG9kCzeVEI12geK4IlanHWY8X4uy/I3NcW7mk8g4= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= diff --git a/vendor/github.com/txn2/txeh/README.md b/vendor/github.com/txn2/txeh/README.md index 233617d4..886a6106 100644 --- a/vendor/github.com/txn2/txeh/README.md +++ b/vendor/github.com/txn2/txeh/README.md @@ -35,10 +35,10 @@ The txeh CLI application allows command line or scripted access to /etc/hosts fi | |___ _____| |__ | __\ \/ / _ \ '_ \ | |_ > < __/ | | | - \__/_/\_\___|_| |_| v1.1.0 + \__/_/\_\___|_| |_| v1.5.0 Add, remove and re-associate hostname entries in your /etc/hosts file. -Read more including useage as a Go library at https://github.com/txn2/txeh +Read more including usage as a Go library at https://github.com/txn2/txeh Usage: txeh [flags] @@ -46,10 +46,14 @@ Usage: Available Commands: add Add hostnames to /etc/hosts + completion Generate the autocompletion script for the specified shell help Help about any command + list List hostnames or IP addresses remove Remove a hostname or ip address + show Show hostnames in /etc/hosts version Print the version number of txeh + Flags: -d, --dryrun dry run, output to stdout (ignores quiet) -h, --help help for txeh @@ -93,7 +97,7 @@ sudo txeh add 127.1.27.100 dev.example.com -q -d > hosts.test # default to the specified read path. txeh add 127.1.27.100 dev2.example.com -q -r ./hosts.test -# specify a seperate read and write oath +# specify a separate read and write oath txeh add 127.1.27.100 dev3.example.com -r ./hosts.test -w ./hosts.test2 ``` diff --git a/vendor/github.com/txn2/txeh/goreleaser.yml b/vendor/github.com/txn2/txeh/goreleaser.yml deleted file mode 100644 index f5e6b2c1..00000000 --- a/vendor/github.com/txn2/txeh/goreleaser.yml +++ /dev/null @@ -1,125 +0,0 @@ -# Build customization -build: - # Path to main.go file. - # Default is `main.go` - main: ./util/txeh.go - binary: txeh - - env: - - CGO_ENABLED=0 - - # GOOS list to build in. - # For more info refer to https://golang.org/doc/install/source#environment - # Defaults are darwin and linux - goos: - - linux - - darwin - - arm - - windows - - # GOARCH to build in. - # For more info refer to https://golang.org/doc/install/source#environment - # Defaults are 386 and amd64 - goarch: - - amd64 - - arm - - ldflags: "-s -w -X github.com/txn2/txeh/util/cmd.Version={{.Version}}" - -release: - # Repo in which the release will be created. - # Default is extracted from the origin remote URL. - github: - owner: txn2 - name: txeh - - # If set to true, will not auto-publish the release. - # Default is false. - draft: false - - # If set to true, will mark the release as not ready for production. - # Default is false. - prerelease: false - - # You can change the name of the GitHub release. - # Default is `` - name_template: "{{.ProjectName}}-v{{.Version}} {{.Env.USER}}" - - # You can disable this pipe in order to not upload any artifacts to - # GitHub. - # Defaults to false. - disable: false - -nfpm: - name_template: '{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' - homepage: https://github.com/txn2/txeh - description: Etc Hosts Management Utility. - maintainer: Craig Johnston - license: Apache 2.0 - vendor: TXN2 - formats: - - deb - - rpm - recommends: - - rpm - -# Archive customization -archive: - # You can change the name of the archive. - # This is parsed with Golang template engine and the following variables. - name_template: "{{.ProjectName}}_{{.Os}}_{{.Arch}}" - - # Archive format. Valid options are `tar.gz` and `zip`. - # Default is `zip` - format: tar.gz - - # Replacements for GOOS and GOARCH on the archive name. - # The keys should be valid GOOS or GOARCH values followed by your custom - # replacements. - # By default, `replacements` replace GOOS and GOARCH values with valid outputs - # of `uname -s` and `uname -m` respectively. - replacements: - amd64: amd64 - 386: 386 - darwin: macOS - linux: linux - - format_overrides: - - goos: windows - format: zip - - # Additional files you want to add to the archive. - # Defaults are any files matching `LICENCE*`, `LICENSE*`, - # `README*` and `CHANGELOG*` (case-insensitive) - files: - - LICENSE - -brew: - name: txeh - - github: - owner: txn2 - name: homebrew-tap - - commit_author: - name: Craig Johnston - email: cjimti@gmail.com - - folder: Formula - - homepage: https://github.com/txn2/txeh - - description: "Etc Hosts Management Utility." - - skip_upload: false - - test: |- - txeh version - -snapcraft: - name_template: '{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' - summary: Etc Hosts Management Utility. - description: | - Kubernetes bulk port forwarding utility. - grade: stable - confinement: classic \ No newline at end of file diff --git a/vendor/github.com/txn2/txeh/txeh.go b/vendor/github.com/txn2/txeh/txeh.go index 80368f54..e6647fe9 100644 --- a/vendor/github.com/txn2/txeh/txeh.go +++ b/vendor/github.com/txn2/txeh/txeh.go @@ -2,8 +2,8 @@ package txeh import ( "fmt" - "io/ioutil" "net" + "os" "regexp" "runtime" "strings" @@ -22,13 +22,11 @@ const ( IPFamilyV6 ) -// HostsConfig type HostsConfig struct { ReadFilePath string WriteFilePath string } -// Hosts type Hosts struct { sync.Mutex *HostsConfig @@ -42,10 +40,8 @@ type AddressLocations map[string]int // to an original line number type HostLocations map[string]int -// HostFileLines type HostFileLines []HostFileLine -// HostFileLine type HostFileLine struct { OriginalLineNum int LineType int @@ -53,7 +49,7 @@ type HostFileLine struct { Parts []string Hostnames []string Raw string - Trimed string + Trimmed string Comment string } @@ -105,7 +101,7 @@ func (h *Hosts) SaveAs(fileName string) error { h.Lock() defer h.Unlock() - err := ioutil.WriteFile(fileName, hfData, 0644) + err := os.WriteFile(fileName, hfData, 0644) if err != nil { return err } @@ -175,7 +171,7 @@ func (h *Hosts) RemoveHost(host string) { } } -// RemoveHost the first hostname entry found and returns true if successful +// RemoveFirstHost the first hostname entry found and returns true if successful func (h *Hosts) RemoveFirstHost(host string) bool { h.Lock() defer h.Unlock() @@ -228,7 +224,7 @@ func (h *Hosts) AddHost(addressRaw string, hostRaw string) { // if the hostname is at a different address, go and remove it from the address for hidx, hst := range h.hostFileLines[hflIdx].Hostnames { - //for localhost we can match more than one host + // for localhost, we can match more than one host if isLocalhost(address) { break } @@ -271,7 +267,54 @@ func (h *Hosts) AddHost(addressRaw string, hostRaw string) { h.Unlock() } -// HostAddressLookup returns true is the host is found, a string +// ListHostsByIP returns a list of hostnames associated with a given IP address +func (h *Hosts) ListHostsByIP(address string) []string { + var hosts []string + + for _, hsl := range h.hostFileLines { + if hsl.Address == address { + hosts = append(hosts, hsl.Hostnames...) + } + } + + return hosts +} + +// ListAddressesByHost returns a list of IPs associated with a given hostname +func (h *Hosts) ListAddressesByHost(hostname string, exact bool) [][]string { + var addresses [][]string + + for _, hsl := range h.hostFileLines { + for _, hst := range hsl.Hostnames { + if hst == hostname { + addresses = append(addresses, []string{hsl.Address, hst}) + } + if exact == false && hst != hostname && strings.Contains(hst, hostname) { + addresses = append(addresses, []string{hsl.Address, hst}) + } + } + } + + return addresses +} + +// ListHostsByCIDR returns a list of IPs and hostnames associated with a given CIDR +func (h *Hosts) ListHostsByCIDR(cidr string) [][]string { + var ipHosts [][]string + + _, subnet, _ := net.ParseCIDR(cidr) + for _, hsl := range h.hostFileLines { + if subnet.Contains(net.ParseIP(hsl.Address)) { + for _, hst := range hsl.Hostnames { + ipHosts = append(ipHosts, []string{hsl.Address, hst}) + } + } + } + + return ipHosts +} + +// HostAddressLookup returns true if the host is found, a string // containing the address and the index of the hfl func (h *Hosts) HostAddressLookup(host string, ipFamily IPFamily) (bool, string, int) { h.Lock() @@ -295,7 +338,6 @@ func (h *Hosts) HostAddressLookup(host string, ipFamily IPFamily) (bool, string, return false, "", 0 } -// RenderHostsFile func (h *Hosts) RenderHostsFile() string { h.Lock() defer h.Unlock() @@ -309,7 +351,6 @@ func (h *Hosts) RenderHostsFile() string { return hf } -// GetHostFileLines func (h *Hosts) GetHostFileLines() *HostFileLines { h.Lock() defer h.Unlock() @@ -317,9 +358,8 @@ func (h *Hosts) GetHostFileLines() *HostFileLines { return &h.hostFileLines } -// ParseHosts func ParseHosts(path string) ([]HostFileLine, error) { - input, err := ioutil.ReadFile(path) + input, err := os.ReadFile(path) if err != nil { return nil, err } @@ -332,33 +372,33 @@ func ParseHosts(path string) ([]HostFileLine, error) { hostFileLines := make([]HostFileLine, len(dataLines)) - // trim leading an trailing whitespace + // trim leading and trailing whitespace for i, l := range dataLines { curLine := &hostFileLines[i] curLine.OriginalLineNum = i curLine.Raw = l // trim line - curLine.Trimed = strings.TrimSpace(l) + curLine.Trimmed = strings.TrimSpace(l) // check for comment - if strings.HasPrefix(curLine.Trimed, "#") { + if strings.HasPrefix(curLine.Trimmed, "#") { curLine.LineType = COMMENT continue } - if curLine.Trimed == "" { + if curLine.Trimmed == "" { curLine.LineType = EMPTY continue } - curLineSplit := strings.SplitN(curLine.Trimed, "#", 2) + curLineSplit := strings.SplitN(curLine.Trimmed, "#", 2) if len(curLineSplit) > 1 { curLine.Comment = curLineSplit[1] } - curLine.Trimed = curLineSplit[0] + curLine.Trimmed = curLineSplit[0] - curLine.Parts = strings.Fields(curLine.Trimed) + curLine.Parts = strings.Fields(curLine.Trimmed) if len(curLine.Parts) > 1 { curLine.LineType = ADDRESS diff --git a/vendor/modules.txt b/vendor/modules.txt index 3d6ae983..eea979b1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -124,8 +124,8 @@ github.com/stretchr/objx ## explicit; go 1.20 github.com/stretchr/testify/assert github.com/stretchr/testify/mock -# github.com/txn2/txeh v1.4.0 -## explicit; go 1.19 +# github.com/txn2/txeh v1.5.2 +## explicit; go 1.20 github.com/txn2/txeh # golang.org/x/net v0.8.0 ## explicit; go 1.17