confopt

package
v0.0.0-...-df395c8 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyFilePerms        fs.FileMode = 0600
	PubKeyFilePerms     fs.FileMode = 0644
	KeyFilePermsMask    fs.FileMode = 0177
	PubKeyFilePermsMask fs.FileMode = 0133
)

Verifying and setting file permissions for public/private keys and certificates use the following file mode masks. The *Perms modes are the desired permissions, while the *PermsMask consts are such that perms && mask should always be 0. The mask is only needed because _technically_ I suppose you could make a public key mode 600 or something if you really wanted.

View Source
const DEFAULT_TIME_FORMAT string = time.RFC3339

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool struct {
	optional.Option[bool]
}

func NoBool

func NoBool() Bool

func SomeBool

func SomeBool(value bool) Bool

func (Bool) MarshalText

func (o Bool) MarshalText() (text []byte, err error)

func (*Bool) Set

func (o *Bool) Set(str string) error

func (Bool) String

func (o Bool) String() string

func (Bool) Type

func (o Bool) Type() string

func (*Bool) UnmarshalText

func (o *Bool) UnmarshalText(text []byte) error

type Cert

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

Cert wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing CERTIFICATE blocks.

func NoCert

func NoCert() Cert

func SomeCert

func SomeCert(path string) (Cert, error)

func (Cert) FilePermsValid

func (o Cert) FilePermsValid() (bool, error)

func (Cert) ReadBlocks

func (o Cert) ReadBlocks() (blocks []*pem.Block, err error)

func (Cert) ReadCerts

func (o Cert) ReadCerts() (certs []*x509.Certificate, err error)

func (*Cert) Replace

func (o *Cert) Replace(path string) (optional.Optional[string], error)

Override the inner Replace() method to ensure we only save absolute paths to our certificates

func (*Cert) Set

func (o *Cert) Set(str string) error

func (Cert) SetFilePerms

func (o Cert) SetFilePerms() error

func (Cert) String

func (o Cert) String() string

func (Cert) Type

func (o Cert) Type() string

func (*Cert) UnmarshalText

func (o *Cert) UnmarshalText(text []byte) error

func (Cert) WriteBlocks

func (o Cert) WriteBlocks(blocks []*pem.Block) error

func (Cert) WriteCerts

func (o Cert) WriteCerts(certs []*x509.Certificate) error

type ConfigOptional

type ConfigOptional[T primatives] interface {
	optional.MutableOptional[T]

	// Along with String() and Set(string) error from, implements pflag.Value
	Type() string
	Set(string) error
	// Satisfies fmt.Stringer interface
	String() string
	// Satisfies encoding.TextUnmarshaler
	UnmarshalText(text []byte) error
	// Satisfies encoding.TextMarshaler
	MarshalText() (text []byte, err error)
}

ConfigOptional is an extension of the Optional interface meant to make it more useful for loading confopturations.

type File

type File struct {
	Str
}

func NoFile

func NoFile() File

func SomeFile

func SomeFile(path string) File

func (File) Abs

func (o File) Abs() (opt File, err error)

func (File) Create

func (o File) Create() (*os.File, error)

func (File) Exists

func (o File) Exists() bool

func (File) FilePermsValid

func (o File) FilePermsValid(badBits fs.FileMode) (bool, error)

func (File) Match

func (o File) Match(probe string) bool

Overrides Option.Match to account for relative paths potentially being different strings but representing the same file.

func (File) Open

func (o File) Open() (*os.File, error)

func (File) SetFilePerms

func (o File) SetFilePerms(mode fs.FileMode) error

func (File) Stat

func (o File) Stat() (stat fs.FileInfo, err error)

func (File) String

func (o File) String() string

Override the String() method from the inner Str just so we return the correct None[Type] string.

func (File) Type

func (o File) Type() string

Override the Type() method from the inner Str. Part of the flag.Value interface.

type Float32

type Float32 struct {
	optional.Option[float32]
}

32bit sized floats

func NoFloat32

func NoFloat32() Float32

func SomeFloat32

func SomeFloat32(value float32) Float32

func (Float32) MarshalText

func (o Float32) MarshalText() (text []byte, err error)

func (*Float32) Set

func (o *Float32) Set(str string) error

func (Float32) String

func (o Float32) String() string

func (Float32) Type

func (o Float32) Type() string

func (*Float32) UnmarshalText

func (o *Float32) UnmarshalText(text []byte) error

type Float64

type Float64 struct {
	optional.Option[float64]
}

64bit sized floats

func NoFloat64

func NoFloat64() Float64

func SomeFloat64

func SomeFloat64(value float64) Float64

func (Float64) MarshalText

func (o Float64) MarshalText() (text []byte, err error)

func (*Float64) Set

func (o *Float64) Set(str string) error

func (Float64) String

func (o Float64) String() string

func (Float64) Type

func (o Float64) Type() string

func (*Float64) UnmarshalText

func (o *Float64) UnmarshalText(text []byte) error

type Int

type Int struct {
	optional.Option[int]
}

default sized int

func NoInt

func NoInt() Int

func SomeInt

func SomeInt(value int) Int

func (Int) MarshalText

func (o Int) MarshalText() (text []byte, err error)

func (*Int) Set

func (o *Int) Set(str string) error

func (Int) String

func (o Int) String() string

func (Int) Type

func (o Int) Type() string

func (*Int) UnmarshalText

func (o *Int) UnmarshalText(text []byte) error

type Int16

type Int16 struct {
	optional.Option[int16]
}

16bit sized int

func NoInt16

func NoInt16() Int16

func SomeInt16

func SomeInt16(value int16) Int16

func (Int16) MarshalText

func (o Int16) MarshalText() (text []byte, err error)

func (*Int16) Set

func (o *Int16) Set(str string) error

func (Int16) String

func (o Int16) String() string

func (Int16) Type

func (o Int16) Type() string

func (*Int16) UnmarshalText

func (o *Int16) UnmarshalText(text []byte) error

type Int32

type Int32 struct {
	optional.Option[int32]
}

32bit sized int

func NoInt32

func NoInt32() Int32

func SomeInt32

func SomeInt32(value int32) Int32

func (Int32) MarshalText

func (o Int32) MarshalText() (text []byte, err error)

func (*Int32) Set

func (o *Int32) Set(str string) error

func (Int32) String

func (o Int32) String() string

func (Int32) Type

func (o Int32) Type() string

func (*Int32) UnmarshalText

func (o *Int32) UnmarshalText(text []byte) error

type Int64

type Int64 struct {
	optional.Option[int64]
}

64bit sized int

func NoInt64

func NoInt64() Int64

func SomeInt64

func SomeInt64(value int64) Int64

func (Int64) MarshalText

func (o Int64) MarshalText() (text []byte, err error)

func (*Int64) Set

func (o *Int64) Set(str string) error

func (Int64) String

func (o Int64) String() string

func (Int64) Type

func (o Int64) Type() string

func (*Int64) UnmarshalText

func (o *Int64) UnmarshalText(text []byte) error

type Int8

type Int8 struct {
	optional.Option[int8]
}

8bit sized int

func NoInt8

func NoInt8() Int8

func SomeInt8

func SomeInt8(value int8) Int8

func (Int8) MarshalText

func (o Int8) MarshalText() (text []byte, err error)

func (*Int8) Set

func (o *Int8) Set(str string) error

func (Int8) String

func (o Int8) String() string

func (Int8) Type

func (o Int8) Type() string

func (*Int8) UnmarshalText

func (o *Int8) UnmarshalText(text []byte) error

type PrivateKey

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

PubKey wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing "* PRIVATE KEY" blocks.

func NoPrivateKey

func NoPrivateKey() PrivateKey

func SomePrivateKey

func SomePrivateKey(path string) (PrivateKey, error)

func (PrivateKey) FilePermsValid

func (o PrivateKey) FilePermsValid() (bool, error)

func (PrivateKey) ReadBlocks

func (o PrivateKey) ReadBlocks() (blocks []*pem.Block, err error)

func (PrivateKey) ReadCert

func (o PrivateKey) ReadCert(in Cert) (cert tls.Certificate, err error)

ReadCert accepts a Cert struct and returns a tls.Certificate for the keypair if both Optionals are Some. This is going to be the most used case for anyone loading

func (PrivateKey) ReadPrivateKey

func (o PrivateKey) ReadPrivateKey() (key any, err error)

ReadPrivateKey will return the first private key found in the given filepath or error. This may return an *rsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey (Note: that is not a pointer), or *ecdh.PrivateKey, depending on the contents of the file.

func (*PrivateKey) Replace

func (o *PrivateKey) Replace(path string) (optional.Optional[string], error)

Override the inner Replace() method to ensure we only save absolute paths to our certificates

func (*PrivateKey) Set

func (o *PrivateKey) Set(str string) error

func (PrivateKey) SetFilePerms

func (o PrivateKey) SetFilePerms() error

func (PrivateKey) String

func (o PrivateKey) String() string

func (PrivateKey) Type

func (o PrivateKey) Type() string

func (*PrivateKey) UnmarshalText

func (o *PrivateKey) UnmarshalText(text []byte) error

func (PrivateKey) WriteBlocks

func (o PrivateKey) WriteBlocks(blocks []*pem.Block) error

func (PrivateKey) WritePrivateKey

func (o PrivateKey) WritePrivateKey(key any) error

WritePrivateKey will accept any of an *rsa.PrivateKey, *dsa.PrivateKey, *ecdsa.PrivateKey, ed25519.PrivateKey (Note: a pointer), or *ecdh.PrivateKey. The key will be encoded and written to the path the PrivateKey option is set to with file permissions set appropriately.

type PubKey

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

PubKey wraps an optional path string and provides extra methods for reading, decoding, and writing pem files containing "* PUBLIC KEY" blocks.

func NoPubKey

func NoPubKey() PubKey

func SomePubKey

func SomePubKey(path string) (PubKey, error)

func (PubKey) FilePermsValid

func (o PubKey) FilePermsValid() (bool, error)

func (PubKey) ReadBlocks

func (o PubKey) ReadBlocks() (blocks []*pem.Block, err error)

func (PubKey) ReadPublicKeys

func (o PubKey) ReadPublicKeys() (pub []any, err error)

ReadPublicKeys will return all public keys found in the given filepath or error. The keys may be of type *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (Note: that is not a pointer), or *ecdh.PublicKey, depending on the contents of the file.

func (*PubKey) Replace

func (o *PubKey) Replace(path string) (optional.Optional[string], error)

Override the inner Replace() method to ensure we only save absolute paths to our certificates

func (*PubKey) Set

func (o *PubKey) Set(str string) error

func (PubKey) SetFilePerms

func (o PubKey) SetFilePerms() error

func (PubKey) String

func (o PubKey) String() string

func (PubKey) Type

func (o PubKey) Type() string

func (*PubKey) UnmarshalText

func (o *PubKey) UnmarshalText(text []byte) error

func (PubKey) WriteBlocks

func (o PubKey) WriteBlocks(blocks []*pem.Block) error

func (PubKey) WritePublicKeys

func (o PubKey) WritePublicKeys(pubs []any) error

WritePublicKey will accept any of an *rsa.PublicKey, *dsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey (Note: a pointer), or *ecdh.PublicKey. The key will be encoded and written to the path the PubKey option is set to with file permissions set appropriately.

type Str

type Str struct {
	optional.Option[string]
}

Str implements ConfigOptional and Optional for the string type.

func NoStr

func NoStr() Str

func SomeStr

func SomeStr(value string) Str

func (Str) MarshalText

func (o Str) MarshalText() (text []byte, err error)

func (*Str) Set

func (o *Str) Set(str string) error

func (Str) String

func (o Str) String() string

func (Str) Type

func (o Str) Type() string

func (*Str) UnmarshalText

func (o *Str) UnmarshalText(text []byte) error

type Time

type Time struct {
	optional.Option[time.Time]
	// contains filtered or unexported fields
}

func NoTime

func NoTime(formats ...string) Time

func SomeTime

func SomeTime(value time.Time, formats ...string) Time

func (Time) Formats

func (o Time) Formats() []string

func (Time) MarshalJSON

func (o Time) MarshalJSON() ([]byte, error)

func (Time) MarshalText

func (o Time) MarshalText() (text []byte, err error)

func (*Time) Set

func (o *Time) Set(str string) error

func (Time) String

func (o Time) String() string

func (Time) Type

func (o Time) Type() string

func (*Time) UnmarshalJSON

func (o *Time) UnmarshalJSON(data []byte) error

Unmarshaller interface

func (*Time) UnmarshalText

func (o *Time) UnmarshalText(text []byte) error

func (Time) WithFormats

func (o Time) WithFormats(formats ...string) Time

type Uint

type Uint struct {
	optional.Option[uint]
}

default sized uint

func NoUint

func NoUint() Uint

func SomeUint

func SomeUint(value uint) Uint

func (Uint) MarshalText

func (o Uint) MarshalText() (text []byte, err error)

func (*Uint) Set

func (o *Uint) Set(str string) error

func (Uint) String

func (o Uint) String() string

func (Uint) Type

func (o Uint) Type() string

func (*Uint) UnmarshalText

func (o *Uint) UnmarshalText(text []byte) error

type Uint16

type Uint16 struct {
	optional.Option[uint16]
}

16bit sized uint

func NoUint16

func NoUint16() Uint16

func SomeUint16

func SomeUint16(value uint16) Uint16

func (Uint16) MarshalText

func (o Uint16) MarshalText() (text []byte, err error)

func (*Uint16) Set

func (o *Uint16) Set(str string) error

func (Uint16) String

func (o Uint16) String() string

func (Uint16) Type

func (o Uint16) Type() string

func (*Uint16) UnmarshalText

func (o *Uint16) UnmarshalText(text []byte) error

type Uint32

type Uint32 struct {
	optional.Option[uint32]
}

32bit sized uint

func NoUint32

func NoUint32() Uint32

func SomeUint32

func SomeUint32(value uint32) Uint32

func (Uint32) MarshalText

func (o Uint32) MarshalText() (text []byte, err error)

func (*Uint32) Set

func (o *Uint32) Set(str string) error

func (Uint32) String

func (o Uint32) String() string

func (Uint32) Type

func (o Uint32) Type() string

func (*Uint32) UnmarshalText

func (o *Uint32) UnmarshalText(text []byte) error

type Uint64

type Uint64 struct {
	optional.Option[uint64]
}

64bit sized uint

func NoUint64

func NoUint64() Uint64

func SomeUint64

func SomeUint64(value uint64) Uint64

func (Uint64) MarshalText

func (o Uint64) MarshalText() (text []byte, err error)

func (*Uint64) Set

func (o *Uint64) Set(str string) error

func (Uint64) String

func (o Uint64) String() string

func (Uint64) Type

func (o Uint64) Type() string

func (*Uint64) UnmarshalText

func (o *Uint64) UnmarshalText(text []byte) error

type Uint8

type Uint8 struct {
	optional.Option[uint8]
}

8bit sized uint

func NoUint8

func NoUint8() Uint8

func SomeUint8

func SomeUint8(value uint8) Uint8

func (Uint8) MarshalText

func (o Uint8) MarshalText() (text []byte, err error)

func (*Uint8) Set

func (o *Uint8) Set(str string) error

func (Uint8) String

func (o Uint8) String() string

func (Uint8) Type

func (o Uint8) Type() string

func (*Uint8) UnmarshalText

func (o *Uint8) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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