Documentation
¶
Index ¶
- Variables
- func CTEqual[S interface{ ... }](a, b S) bool
- func Closer(o any) io.ReadWriteCloser
- func CloserWrap(o any, err error) (io.ReadWriteCloser, error)
- func ConfigIP2LocationApiKey() string
- func ConfigProxyOTPSecret() string
- func ConfigProxyPass() string
- func ConfigProxyRedirectLoginURL() string
- func ConfigProxySessionDuration() time.Duration
- func ConfigProxySessionSecret() string
- func ConfigProxyUser() string
- func ConfigSessionToken() string
- func DecodeFromQuery(in string, secret []byte, session sessions.Session) (map[string]any, error)
- func EncodeForQuery(in map[string]any, secret []byte, session sessions.Session) (string, error)
- func FatalOnError(msg string, err error)
- func GetNonce() (string, error)
- func Getenv[T any](key string, fallback T) (out T)
- func Logger() *zap.Logger
- func MakeKeyPair(in []byte) ([]byte, []byte)
- func NewUUID() string
- func QuickGet[T, M any](m M, key string) (val T)
- func SetIP2LocationApiKey(apiKey string)
- func SetProxyGuardPolicy(policy Policy)
- func SetProxyOTPSecret(secret string)
- func SetProxyPass(pass string)
- func SetProxyPublicDomains(domains Domains)
- func SetProxyRedirectLoginURL(url string)
- func SetProxySessionDuration(duration time.Duration)
- func SetProxySessionSecret(secret string)
- func SetProxyTargetHosts(hosts HostMap)
- func SetProxyUser(user string)
- func SetSessionToken(token string)
- type Diff
- type Domains
- type Effect
- type HostMap
- type PathType
- type Policy
- type Rule
- type Ruleset
- func (rules Ruleset) Compare(other Ruleset) Diff
- func (rules Ruleset) Contains(other Rule) bool
- func (rules Ruleset) Evaluate(req *http.Request, noMatchEffect Effect) Effect
- func (rules Ruleset) JsSelectors() []string
- func (rules Ruleset) Len() int
- func (rules Ruleset) Merge(other Ruleset) Ruleset
- func (rules Ruleset) RegexList() []string
Constants ¶
This section is empty.
Variables ¶
var ( // B64StdWithPadding is a base64 encoding with standard padding. B64StdWithPadding = base64.StdEncoding.WithPadding(base64.StdPadding) // B64URLWithPadding is a base64 URL safe encoding without padding. B64URLNoPadding = base64.URLEncoding.WithPadding(base64.NoPadding) // B32StdNoPadding is a base32 encoding without padding. B32StdNoPadding = base32.StdEncoding.WithPadding(base32.NoPadding) )
Functions ¶
func Closer ¶
func Closer(o any) io.ReadWriteCloser
Closer builds a ReadWriteCloser interface around the given object.
func CloserWrap ¶
func CloserWrap(o any, err error) (io.ReadWriteCloser, error)
CloserWrap is a convenience function that wraps the given object and error into a ReadWriteCloser interface. Useful to catch return values from functions that return an error.
func ConfigIP2LocationApiKey ¶ added in v0.0.15
func ConfigIP2LocationApiKey() string
ConfigIP2LocationApiKey returns the IP2Location API key.
func ConfigProxyOTPSecret ¶
func ConfigProxyOTPSecret() string
ConfigProxyOTPSecret returns the proxy OTP secret.
func ConfigProxyRedirectLoginURL ¶
func ConfigProxyRedirectLoginURL() string
ConfigProxyRedirectLoginURL returns the proxy redirect login URL.
func ConfigProxySessionDuration ¶ added in v0.0.14
ConfigProxySessionDuration returns the proxy session duration.
func ConfigProxySessionSecret ¶ added in v0.0.11
func ConfigProxySessionSecret() string
ConfigProxySessionSecret returns the CSRF secret.
func ConfigSessionToken ¶
func ConfigSessionToken() string
ConfigSessionToken returns the session token.
func DecodeFromQuery ¶ added in v0.0.8
DecodeFromQuery decodes a URL query parameter into a map. It uses the HMAC checksum stored in the session to verify the integrity of the data. The session has to be saved after calling this function.
func EncodeForQuery ¶ added in v0.0.8
EncodeForQuery encodes the input map into a URL query parameter. It uses JSON encoding and base64 URL safe encoding without padding. It also calculates the HMAC checksum of the JSON data using the provided secret and stores it in the session. Checksum is used to verify the integrity of the data. The session has to be saved after calling this function.
func FatalOnError ¶ added in v0.0.15
FatalOnError logs the error and exits the program if the error is not nil.
func GetNonce ¶ added in v0.0.7
GetNonce generates a random nonce. It returns a base64 encoded string. If the random number generator fails, it uses the current time for randomness.
func MakeKeyPair ¶ added in v0.0.7
MakeKeyPair generates a pair of 32-byte keys. If the input is empty, it generates a random key. If the input is 64 bytes, it splits it into two keys. If the input is less than 64 bytes, it fills just the first key and leaves the second key empty.
func QuickGet ¶ added in v0.0.8
QuickGet is a type assertion helper for getting values from a map or an interface. It supports the following types: - map[string]T - map[string]any - interface{ Get(string) T } - interface{ Get(string) any } - interface{ Get(string) (T, bool) } - interface{ Get(string) (any, bool) } - interface{ Get(any) T } - interface{ Get(any) any } - interface{ Get(any) (T, bool) } - interface{ Get(any) (any, bool) }
func SetIP2LocationApiKey ¶ added in v0.0.15
func SetIP2LocationApiKey(apiKey string)
SetIP2LocationApiKey sets the IP2Location API key.
func SetProxyGuardPolicy ¶ added in v0.0.14
func SetProxyGuardPolicy(policy Policy)
SetProxyGuardPolicy sets the proxy guard rules.
func SetProxyOTPSecret ¶ added in v0.0.14
func SetProxyOTPSecret(secret string)
SetProxyOTPSecret sets the proxy OTP secret.
func SetProxyPass ¶ added in v0.0.14
func SetProxyPass(pass string)
SetProxyPass sets the proxy password.
func SetProxyPublicDomains ¶ added in v0.0.14
func SetProxyPublicDomains(domains Domains)
SetProxyPublicDomains sets the public domains.
func SetProxyRedirectLoginURL ¶ added in v0.0.14
func SetProxyRedirectLoginURL(url string)
SetProxyRedirectLoginURL sets the proxy redirect login URL.
func SetProxySessionDuration ¶ added in v0.0.14
SetProxySessionDuration sets the proxy session duration.
func SetProxySessionSecret ¶ added in v0.0.14
func SetProxySessionSecret(secret string)
SetProxySessionSecret sets the CSRF secret.
func SetProxyTargetHosts ¶ added in v0.0.14
func SetProxyTargetHosts(hosts HostMap)
SetProxyTargetHosts sets the proxy target hosts.
func SetProxyUser ¶ added in v0.0.14
func SetProxyUser(user string)
SetProxyUser sets the proxy user.
func SetSessionToken ¶ added in v0.0.14
func SetSessionToken(token string)
SetSessionToken sets the session token.
Types ¶
type Domains ¶ added in v0.0.16
type Domains []string
Domains is a list of domains.
func ConfigProxyPublicDomains ¶ added in v0.0.13
func ConfigProxyPublicDomains() Domains
ConfigProxyPublicDomains returns the public domains.
type Effect ¶ added in v0.0.16
type Effect bool
func (Effect) MarshalText ¶ added in v0.0.16
MarshalText implements the encoding.TextMarshaler interface.
func (*Effect) UnmarshalText ¶ added in v0.0.16
UnmarshalText implements the encoding.TextUnmarshaler interface.
type HostMap ¶ added in v0.0.14
HostMap is a map of proxy host domains to target host domains.
func ConfigProxyTargetHosts ¶
func ConfigProxyTargetHosts() HostMap
ConfigProxyTargetHosts returns the proxy target hosts.
type PathType ¶ added in v0.0.16
type PathType int
func (PathType) MarshalText ¶ added in v0.0.16
MarshalText implements the encoding.TextMarshaler interface.
func (*PathType) UnmarshalText ¶ added in v0.0.16
UnmarshalText implements the encoding.TextUnmarshaler interface.
type Policy ¶ added in v0.0.12
type Policy struct { // Allow is the list of allow rules. // All allowed requests are publicly accessible without proxy authentication. Allow Ruleset `json:"allow,omitempty"` // Deny is the list of deny rules. // All denied requests are explicitly denied and not accessible via the proxy at all. Deny Ruleset `json:"deny,omitempty"` // Override is the list of form data override rules. // The override rules are applied to matching form data requests // to ensure the form data does not get altered. Override Ruleset `json:"override,omitempty"` }
Policy is the access control policy. If effect is allow, the request is allowed publicly without proxy authentication. If effect is deny, the request is explicit denied and not accessible via the proxy.
func ConfigProxyGuardPolicy ¶ added in v0.0.12
func ConfigProxyGuardPolicy() Policy
ConfigProxyGuardPolicy returns the proxy guard rules.
func LoadPolicyFromFile ¶ added in v0.0.15
LoadPolicyFromFile loads a policy from a file. If the path is empty, it returns an empty policy.
type Rule ¶ added in v0.0.10
type Rule struct { // FormData is the form data to patch the request with. FormData url.Values `json:"form_data,omitempty"` // JsSelectors is a list of JavaScript selectors. JsSelectors []string `json:"js_selectors,omitempty"` // Path is the URL path. Path string `json:"path"` // PathType is the type of the path. It can be exact, prefix, or regex. PathType PathType `json:"path_type"` // Query is the URL query parameters. Query url.Values `json:"query,omitempty"` }
Rule is an access control rule.
type Ruleset ¶ added in v0.0.10
type Ruleset []Rule
Ruleset is a set of rules.
func (Ruleset) Evaluate ¶ added in v0.0.10
Evaluate returns the effect of the first matching rule. If no rule matches, it returns noMatchEffect.
func (Ruleset) JsSelectors ¶ added in v0.0.15
JsSelectors returns a list of JavaScript selectors for all rules.