networking

package
v0.0.0-...-f412c9c Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogRequest

func LogRequest(r *http.Request, logger *zerolog.Logger)

func LogResponse

func LogResponse(response *http.Response, logger *zerolog.Logger)

Types

type DynamicHeaderFunc

type DynamicHeaderFunc func([]string) []string

type NetworkAccess

type NetworkAccess interface {
	// AddHeaders adds all the custom and authentication headers to the request.
	AddHeaders(request *http.Request) error
	// GetRoundTripper returns the http.RoundTripper that is used by the http.Client.
	GetRoundTripper() http.RoundTripper
	// GetHttpClient returns the http client.
	GetHttpClient() *http.Client
	// GetUnauthorizedHttpClient returns an HTTP client that does not use authentication headers.
	GetUnauthorizedHttpClient() *http.Client
	// AddHeaderField adds a header field to the default header.
	AddHeaderField(key, value string)
	// AddDynamicHeaderField adds a dynamic header field to the request.
	AddDynamicHeaderField(key string, f DynamicHeaderFunc)
	// AddRootCAs adds the root CAs from the given PEM file.
	AddRootCAs(pemFileLocation string) error
	// AddErrorHandler registers an error handler for the underlying http.RoundTripper.
	AddErrorHandler(networktypes.ErrorHandlerFunc)
	// GetErrorHandler returns the registered error handler.
	GetErrorHandler() networktypes.ErrorHandlerFunc
	// GetAuthenticator returns the authenticator.
	GetAuthenticator() auth.Authenticator

	SetLogger(logger *zerolog.Logger)
	SetConfiguration(configuration configuration.Configuration)
	GetLogger() *zerolog.Logger
	GetConfiguration() configuration.Configuration

	Clone() NetworkAccess
}

NetworkAccess is the interface for network access. It provides methods to get an HTTP client with default behaviors that handle authentication headers for Snyk API calls.

func NewNetworkAccess

func NewNetworkAccess(config configuration.Configuration) NetworkAccess

NewNetworkAccess returns a networkImpl instance.

type UserAgentInfo

type UserAgentInfo struct {
	App                           string
	AppVersion                    string
	Integration                   string
	IntegrationVersion            string
	IntegrationEnvironment        string
	IntegrationEnvironmentVersion string
	OS                            string
	Arch                          string
}

func UserAgent

func UserAgent(opts ...UserAgentOptions) UserAgentInfo

func UserAgentFromConfig

func UserAgentFromConfig(config configuration.Configuration, app string, appVersion string) UserAgentInfo

func (UserAgentInfo) String

func (s UserAgentInfo) String() string

ToUserAgentHeader returns a string that can be used as a User-Agent header. The string is following this format: <app>/<appVer> (<os>;<arch>;<procName>) <integration>/<integrationVersion> (<integrationEnv>/<integrationEnvVersion>) Everything other than the app, app version and system information (os/arch/process name) is optional. The integration environment is only added if the integration is set.

type UserAgentOptions

type UserAgentOptions func(ua *UserAgentInfo)

func UaWithApplication

func UaWithApplication(app string, appVersion string) UserAgentOptions

func UaWithOS

func UaWithOS(osName string) UserAgentOptions

func UaWithRuntimeInfo

func UaWithRuntimeInfo(ri runtimeinfo.RuntimeInfo) UserAgentOptions

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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