packer-cn/vendor/github.com/hashicorp/go-sockaddr
Adrien Delorme 9f82b75e57 Use the hashicorp/go-getter to download files
* removed packer.Cache and references since packer.Cache is never used except in the download step. The download step now uses the new func packer.CachePath(targetPath) for this, the behavior is the same.
* removed download code from packer that was reimplemented into the go-getter library: progress bar, http download restart, checksuming from file, skip already downloaded files, symlinking, make a download cancellable by context.
* on windows if packer is running without symlinking rights and we are getting a local file, the file will be copied instead to avoid errors.
* added unit tests for step_download that are now CI tested on windows, mac & linux.
* files are now downloaded under cache dir `sha1(filename + "?checksum=" + checksum) + file_extension`
* since the output dir is based on the source url and the checksum, when the checksum fails, the file is auto deleted.
* a download file is protected and locked by a file lock,
* updated docs
* updated go modules and vendors
2019-03-13 12:11:58 +01:00
..
.gitignore Use the hashicorp/go-getter to download files 2019-03-13 12:11:58 +01:00
GNUmakefile add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
LICENSE add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
README.md add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
doc.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ifaddr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ifaddrs.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ifattr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ipaddr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ipaddrs.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ipv4addr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
ipv6addr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
rfc.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info_bsd.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info_default.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info_linux.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info_solaris.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
route_info_windows.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
sockaddr.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
sockaddrs.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00
unixsock.go add template function allowing user to read keys from vault 2018-08-28 11:23:47 -07:00

README.md

go-sockaddr

sockaddr Library

Socket address convenience functions for Go. go-sockaddr is a convenience library that makes doing the right thing with IP addresses easy. go-sockaddr is loosely modeled after the UNIX sockaddr_t and creates a union of the family of sockaddr_t types (see below for an ascii diagram). Library documentation is available at https://godoc.org/github.com/hashicorp/go-sockaddr. The primary intent of the library was to make it possible to define heuristics for selecting the correct IP addresses when a configuration is evaluated at runtime. See the docs, template package, tests, and CLI utility for details and hints as to how to use this library.

For example, with this library it is possible to find an IP address that:

Or any combination or variation therein.

There are also a few simple helper functions such as GetPublicIP and GetPrivateIP which both return strings and select the first public or private IP address on the default interface, respectively. Similarly, there is also a helper function called GetInterfaceIP which returns the first usable IP address on the named interface.

sockaddr CLI

Given the possible complexity of the sockaddr library, there is a CLI utility that accompanies the library, also called sockaddr. The sockaddr utility exposes nearly all of the functionality of the library and can be used either as an administrative tool or testing tool. To install the sockaddr, run:

$ go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr

If you're familiar with UNIX's sockaddr struct's, the following diagram mapping the C sockaddr (top) to go-sockaddr structs (bottom) and interfaces will be helpful:

+-------------------------------------------------------+
|                                                       |
|                        sockaddr                       |
|                        SockAddr                       |
|                                                       |
| +--------------+ +----------------------------------+ |
| | sockaddr_un  | |                                  | |
| | SockAddrUnix | |           sockaddr_in{,6}        | |
| +--------------+ |                IPAddr            | |
|                  |                                  | |
|                  | +-------------+ +--------------+ | |
|                  | | sockaddr_in | | sockaddr_in6 | | |
|                  | |   IPv4Addr  | |   IPv6Addr   | | |
|                  | +-------------+ +--------------+ | |
|                  |                                  | |
|                  +----------------------------------+ |
|                                                       |
+-------------------------------------------------------+

Inspiration and Design

There were many subtle inspirations that led to this design, but the most direct inspiration for the filtering syntax was OpenBSD's pf.conf(5) firewall syntax that lets you select the first IP address on a given named interface. The original problem stemmed from:

  • needing to create immutable images using Packer that ran the Consul process (Consul can only use one IP address at a time);
  • images that may or may not have multiple interfaces or IP addresses at runtime; and
  • we didn't want to rely on configuration management to render out the correct IP address if the VM image was being used in an auto-scaling group.

Instead we needed some way to codify a heuristic that would correctly select the right IP address but the input parameters were not known when the image was created.