config

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2026 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// providers
	ProviderGoogle = "google"
	ProviderLinode = "linode"
)

Functions

func PublicIP

func PublicIP() (string, error)

PublicIP fetches the current public IP from the URL defined by ipURL. On error, it will return an empty string and error.

func WithFirewall

func WithFirewall(name string) configOpts

WithFirewall sets the Firewall's name in the fwsync configuration.

func WithIPLimit

func WithIPLimit(limit int) configOpts

WithIPLimit sets the number of allowed IPs.

func WithProject

func WithProject(project string) configOpts

WithProject sets the Project for the fwsync configuration.

func WithProvider

func WithProvider(provider string) configOpts

WithProvider sets the Provider for the fwsync configuration.

func WithSourceIPs

func WithSourceIPs(sourceIPs ...string) configOpts

WithSourceIPs sets the allowed IPs in the fwsync configuration.

Types

type Config

type Config struct {
	Provider  string   `yaml:"provider"`
	Project   string   `yaml:"project,omitempty"`
	IPLimit   int      `yaml:"ip_limit,omitempty"`
	Name      string   `yaml:"name"`
	SourceIPs []string `yaml:"ips"`
}

Config describes the fwsync configuration. It is used to hold basic information about the firewall and the desired IPs that are to be allowed.

func LoadFromFile

func LoadFromFile(r io.Reader) (*Config, error)

LoadFromFile creates a new Config from the .fwsync configuration file.

func New

func New(opts ...configOpts) *Config

New creates a new Config and returns a pointer to it.

func (*Config) Add

func (c *Config) Add(ip string)

Add will add the given IP to the configuration file. If the new IP puts the number of IPs held in the configuration file over the limit defined by ipLimit then the oldest IP is removed.

func (*Config) AuthForProvider

func (c *Config) AuthForProvider() (generic.Provider, error)

AuthForProvider authenticates for a given supported Cloud Provider and returns the provider's implementation of generic.Provider.

func (*Config) HasIP

func (c *Config) HasIP(ip string) (int, bool)

HasIP checks if the current configuration has a given IP. Returns the index of the IP and true if found. Returns -1 and false if not found.

func (*Config) Remove

func (c *Config) Remove(ip string)

Remove will remove an IP from the configuration.

func (*Config) Write

func (c *Config) Write(w io.Writer) error

Write will write the fwsync configuration from memory to disk.

Jump to

Keyboard shortcuts

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