host

package
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingProfile when the profile is mandatory
	ErrMissingProfile = errors.New("missing profile name")

	// ErrUnknownProfile when the profile is not present
	ErrUnknownProfile = errors.New("unknown profile name")

	// ErrDefaultProfileError when trying to edit default content
	ErrDefaultProfileError = errors.New("'default' profile should not be handled by hostctl")

	// ErrMissingDomainsError when trying to set/add domains and none were given
	ErrMissingDomainsError = errors.New("no domains provided")

	// ErrMissingDestError when trying to write to a file
	ErrMissingDestError = errors.New("missing destination file")

	// ErrMissingSourceError when trying to read from a file
	ErrMissingSourceError = errors.New("missing source file")

	// ErrSnapConfinement when trying to read files on snap installation
	ErrSnapConfinement = errors.New("can't use --from or --host-file. " +
		"Snap confinement restrictions doesn't allow to read other than /etc/hosts file")
)
View Source
var DefaultColumns = []string{"profile", "status", "ip", "domain"}

DefaultColumns is the list of default columns to use when showing table list

View Source
var ProfilesOnlyColumns = []string{"profile", "status"}

ProfilesOnlyColumns are the columns used for profile status list

Functions

This section is empty.

Types

type Content added in v1.0.0

type Content struct {
	DefaultProfile DefaultProfile
	ProfileNames   []string
	Profiles       map[string]*Profile
}

Content contains complete data of all profiles

func Parse added in v1.0.0

func Parse(r io.Reader) (*Content, error)

Parse reads content from reader into Data struct.

type DefaultProfile added in v1.0.0

type DefaultProfile []*tableRow

DefaultProfile contains data for the default profile

func (DefaultProfile) Render added in v1.0.0

func (d DefaultProfile) Render(w io.StringWriter) error

Render writes the default profile content to the given StringWriter

type DockerOptions added in v0.7.0

type DockerOptions struct {
	Domain      string
	Network     string
	ComposeFile string
	ProjectName string
	KeepPrefix  bool
	Cli         *client.Client
}

DockerOptions contains parameters to sync with docker and docker-compose

type File added in v1.0.0

type File struct {
	// contains filtered or unexported fields
}

File container to handle a hosts file

func NewFile added in v1.0.0

func NewFile(src string) (*File, error)

NewFile creates a new File from the given src on default OS filesystem

func NewWithFs added in v1.0.0

func NewWithFs(src string, fs afero.Fs) (*File, error)

NewWithFs creates a new File with src and an existing filesystem

func (*File) AddProfile added in v1.0.0

func (f *File) AddProfile(profile Profile) error

AddProfile adds a profile to the list

func (*File) AddRoutes added in v1.0.0

func (f *File) AddRoutes(name, ip string, hostnames []string) error

AddRoutes add route information to a given profile

func (*File) Backup added in v1.0.0

func (f *File) Backup(dst string) (string, error)

Backup creates a copy of your hosts file to a new location with the date as extension

func (*File) Close added in v1.0.0

func (f *File) Close()

Close closes the underlying file

func (*File) Disable added in v1.0.0

func (f *File) Disable(profiles []string) error

Disable marks profiles as disable by commenting all hosts lines. The content remains on the file and can be enabled later.

func (*File) DisableAll added in v1.0.0

func (f *File) DisableAll() error

DisableAll marks all profiles as disable by commenting all hosts lines. The content remains on the file and can be enabled later.

func (*File) DisableOnly added in v1.0.8

func (f *File) DisableOnly(profiles []string) error

DisableOnly marks profiles as disable and enable all other profiles

func (*File) Enable added in v1.0.0

func (f *File) Enable(profiles []string) error

Enable marks profiles as enable by uncommenting all hosts lines making the routing work again.

func (*File) EnableAll added in v1.0.0

func (f *File) EnableAll() error

EnableAll marks all profiles as enable by uncommenting all hosts lines making the routing work again.

func (*File) EnableOnly added in v1.0.0

func (f *File) EnableOnly(profiles []string) error

EnableOnly marks profiles as enable and disable all other profiles

func (*File) Flush added in v1.0.0

func (f *File) Flush() error

Flush overwrite file with hosts info

func (*File) GetDisabled added in v1.0.0

func (f *File) GetDisabled() []string

GetDisabled returns a list of profiles that are Enabled

func (*File) GetEnabled added in v1.0.0

func (f *File) GetEnabled() []string

GetEnabled returns a list of profiles that are Enabled

func (*File) GetProfile added in v1.0.0

func (f *File) GetProfile(name string) (*Profile, error)

GetProfile return a Profile from the list

func (*File) GetProfileNames added in v1.0.0

func (f *File) GetProfileNames() []string

GetProfileNames return a list of all profile names

func (*File) GetStatus added in v1.0.0

func (f *File) GetStatus(profiles []string) map[string]ProfileStatus

GetStatus returns a map with the status of the given profiles

func (*File) List added in v1.0.0

func (f *File) List(opts *ListOptions)

List shows a table with profile names status and routing information

func (*File) MergeProfiles added in v1.0.0

func (f *File) MergeProfiles(content *Content)

MergeProfiles joins new content with existing content

func (*File) ProfileStatus added in v1.0.0

func (f *File) ProfileStatus(opts *ListOptions)

ProfileStatus shows a table only with profile names status

func (*File) RemoveProfile added in v1.0.0

func (f *File) RemoveProfile(name string) error

RemoveProfile removes given profile from the list

func (*File) RemoveProfiles added in v1.0.0

func (f *File) RemoveProfiles(profiles []string) error

RemoveProfiles removes given profiles from the list

func (*File) RemoveRoutes added in v1.0.0

func (f *File) RemoveRoutes(name string, routes []string) (bool, error)

RemoveRoutes removes route information from a given profile. also removes the profile if gets empty.

func (*File) ReplaceProfile added in v1.0.0

func (f *File) ReplaceProfile(p Profile) error

ReplaceProfile removes previous profile with same name and add new profile to the list

func (*File) Restore added in v1.0.0

func (f *File) Restore(from string) error

Restore overwrite content of a hosts file with the content of a backup.

func (*File) Toggle added in v1.0.0

func (f *File) Toggle(profiles []string) error

Toggle alternates between enable and disable status of a profile.

func (*File) WriteTo added in v1.0.0

func (f *File) WriteTo(src string) error

WriteTo overwrite file with hosts info

type ListOptions

type ListOptions struct {
	Profiles     []string
	Columns      []string
	RawTable     bool
	ProfilesOnly bool
	StatusFilter ProfileStatus
	Writer       io.Writer
}

ListOptions contains available options for listing.

type Profile added in v1.0.0

type Profile struct {
	Name   string
	Status ProfileStatus
	IPList []string
	Routes map[string]*Route
}

Profile contains all data of a single profile

func NewProfileFromDocker added in v1.0.0

func NewProfileFromDocker(ctx context.Context, opts *DockerOptions) (*Profile, error)

NewProfileFromDocker creates a new profile from docker info

func NewProfileFromReader added in v1.0.0

func NewProfileFromReader(r io.Reader, uniq bool) (*Profile, error)

NewProfileFromReader creates a new profile reading lines from a reader

func (*Profile) AddRoute added in v1.0.0

func (p *Profile) AddRoute(ip, hostname string)

AddRoute adds a single route to the profile

func (*Profile) AddRoutes added in v1.0.0

func (p *Profile) AddRoutes(ip string, hostnames []string)

AddRoutes adds multiple routes to the profile

func (*Profile) GetAllHostNames added in v1.0.0

func (p *Profile) GetAllHostNames() ([]string, error)

GetAllHostNames returns all hostnames of the profile.

func (*Profile) GetHostNames added in v1.0.0

func (p *Profile) GetHostNames(ip string) ([]string, error)

GetHostNames returns a list of all hostnames of the given ip.

func (*Profile) GetStatus added in v1.0.0

func (p *Profile) GetStatus() string

GetStatus returns a string value of ProfileStatus

func (*Profile) RemoveRoutes added in v1.0.0

func (p *Profile) RemoveRoutes(hostnames []string)

RemoveRoutes removes multiple hostnames of a profile

func (*Profile) Render added in v1.0.0

func (p *Profile) Render(w io.StringWriter) error

Render writes the profile content to the given StringWriter

func (*Profile) String added in v1.0.0

func (p *Profile) String() string

String returns a string representation of the profile

type ProfileStatus added in v0.9.1

type ProfileStatus string

ProfileStatus represents the status of a Profile

const (
	// Enabled marks a profile active on your hosts file.
	Enabled ProfileStatus = "on"
	// Disabled marks a profile not active on your hosts file.
	Disabled ProfileStatus = "off"

	// Default is the name of the default profile
	Default = "default"
)

type Route added in v1.0.0

type Route struct {
	IP        net.IP
	HostNames []string
}

Route contains hostnames of all routes with the same IP

Jump to

Keyboard shortcuts

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