client

package
v5.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDNSResolver        = errors.New("invalid DNS resolver specified. Required format is {proto}://{ip}:{port}")
	ErrInvalidDNSResolverPort    = errors.New("invalid DNS resolver port")
	ErrInvalidClientOAuth2Config = errors.New("invalid oauth2 configuration: must define all fields for client credentials flow (token-url, client-id, client-secret, scopes)")
	ErrInvalidClientIAPConfig    = errors.New("invalid Identity-Aware-Proxy configuration: must define all fields for Google Identity-Aware-Proxy programmatic authentication (audience)")
	ErrInvalidClientTLSConfig    = errors.New("invalid TLS configuration: certificate-file and private-key-file must be specified")
)

Functions

func CanCreateSCTPConnection

func CanCreateSCTPConnection(address string, config *Config) bool

CanCreateSCTPConnection checks whether a connection can be established with a SCTP endpoint

func CanCreateSSHConnection added in v5.6.0

func CanCreateSSHConnection(address, username, password string, config *Config) (bool, *ssh.Client, error)

CanCreateSSHConnection checks whether a connection can be established and a command can be executed to an address using the SSH protocol.

func CanCreateTCPConnection

func CanCreateTCPConnection(address string, config *Config) bool

CanCreateTCPConnection checks whether a connection can be established with a TCP endpoint

func CanCreateUDPConnection

func CanCreateUDPConnection(address string, config *Config) bool

CanCreateUDPConnection checks whether a connection can be established with a UDP endpoint

func CanPerformStartTLS

func CanPerformStartTLS(address string, config *Config) (connected bool, certificate *x509.Certificate, err error)

CanPerformStartTLS checks whether a connection can be established to an address using the STARTTLS protocol

func CanPerformTLS

func CanPerformTLS(address string, config *Config) (connected bool, certificate *x509.Certificate, err error)

CanPerformTLS checks whether a connection can be established to an address using the TLS protocol

func ExecuteSSHCommand added in v5.6.0

func ExecuteSSHCommand(sshClient *ssh.Client, body string, config *Config) (bool, int, error)

ExecuteSSHCommand executes a command to an address using the SSH protocol.

func GetDomainExpiration

func GetDomainExpiration(hostname string) (domainExpiration time.Duration, err error)

GetDomainExpiration retrieves the duration until the domain provided expires

func GetHTTPClient

func GetHTTPClient(config *Config) *http.Client

GetHTTPClient returns the shared HTTP client, or the client from the configuration passed

func InjectHTTPClient

func InjectHTTPClient(httpClient *http.Client)

InjectHTTPClient is used to inject a custom HTTP client for testing purposes

func Ping

func Ping(address string, config *Config) (bool, time.Duration)

Ping checks if an address can be pinged and returns the round-trip time if the address can be pinged

Note that this function takes at least 100ms, even if the address is 127.0.0.1

func QueryWebSocket added in v5.6.0

func QueryWebSocket(address, body string, config *Config) (bool, []byte, error)

QueryWebSocket opens a websocket connection, write `body` and return a message from the server

Types

type Config

type Config struct {
	// ProxyURL is the URL of the proxy to use for the client
	ProxyURL string `yaml:"proxy-url,omitempty"`

	// Insecure determines whether to skip verifying the server's certificate chain and host name
	Insecure bool `yaml:"insecure,omitempty"`

	// IgnoreRedirect determines whether to ignore redirects (true) or follow them (false, default)
	IgnoreRedirect bool `yaml:"ignore-redirect,omitempty"`

	// Timeout for the client
	Timeout time.Duration `yaml:"timeout"`

	// DNSResolver override for the HTTP client
	// Expected format is {protocol}://{host}:{port}, e.g. tcp://8.8.8.8:53
	DNSResolver string `yaml:"dns-resolver,omitempty"`

	// OAuth2Config is the OAuth2 configuration used for the client.
	//
	// If non-nil, the http.Client returned by getHTTPClient will automatically retrieve a token if necessary.
	// See configureOAuth2 for more details.
	OAuth2Config *OAuth2Config `yaml:"oauth2,omitempty"`

	// IAPConfig is the Google Cloud Identity-Aware-Proxy configuration used for the client. (e.g. audience)
	IAPConfig *IAPConfig `yaml:"identity-aware-proxy,omitempty"`

	// Network (ip, ip4 or ip6) for the ICMP client
	Network string `yaml:"network"`

	// TLS configuration (optional)
	TLS *TLSConfig `yaml:"tls,omitempty"`
	// contains filtered or unexported fields
}

Config is the configuration for clients

func GetDefaultConfig

func GetDefaultConfig() *Config

GetDefaultConfig returns a copy of the default configuration

func (*Config) HasCustomDNSResolver

func (c *Config) HasCustomDNSResolver() bool

HasCustomDNSResolver returns whether a custom DNSResolver is configured

func (*Config) HasIAPConfig added in v5.8.0

func (c *Config) HasIAPConfig() bool

HasIAPConfig returns true if the client has IAP configuration parameters

func (*Config) HasOAuth2Config

func (c *Config) HasOAuth2Config() bool

HasOAuth2Config returns true if the client has OAuth2 configuration parameters

func (*Config) HasTlsConfig added in v5.9.0

func (c *Config) HasTlsConfig() bool

HasTlsConfig returns true if the client has client certificate parameters

func (*Config) ValidateAndSetDefaults

func (c *Config) ValidateAndSetDefaults() error

ValidateAndSetDefaults validates the client configuration and sets the default values if necessary

type DNSResolverConfig

type DNSResolverConfig struct {
	Protocol string
	Host     string
	Port     string
}

DNSResolverConfig is the parsed configuration from the DNSResolver config string.

type IAPConfig added in v5.8.0

type IAPConfig struct {
	Audience string `yaml:"audience"` // e.g. "toto.apps.googleusercontent.com"
}

IAPConfig is the configuration for the Google Cloud Identity-Aware-Proxy

type OAuth2Config

type OAuth2Config struct {
	TokenURL     string   `yaml:"token-url"` // e.g. https://dev-12345678.okta.com/token
	ClientID     string   `yaml:"client-id"`
	ClientSecret string   `yaml:"client-secret"`
	Scopes       []string `yaml:"scopes"` // e.g. ["openid"]
}

OAuth2Config is the configuration for the OAuth2 client credentials flow

type TLSConfig added in v5.9.0

type TLSConfig struct {
	// CertificateFile is the public certificate for TLS in PEM format.
	CertificateFile string `yaml:"certificate-file,omitempty"`

	// PrivateKeyFile is the private key file for TLS in PEM format.
	PrivateKeyFile string `yaml:"private-key-file,omitempty"`

	RenegotiationSupport string `yaml:"renegotiation,omitempty"`
}

TLSConfig is the configuration for mTLS configurations

Jump to

Keyboard shortcuts

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