client

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package client provides the core HTTP client for making API requests.

Index

Constants

View Source
const (
	// NonceLength defines the length of the cryptographic nonce used in
	// authentication headers.
	NonceLength = 64
	// AuthCharset is the character set used for generating the nonce.
	AuthCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	// ValidateAPIKeyEndpoint is the path for the API key validation
	// endpoint.
	ValidateAPIKeyEndpoint = "api_keys/validate"
)
View Source
const (
	// Max value for limit in pagination queries.
	MaxLimit = 2000
)

Variables

View Source
var (
	GitCommit           = "NOCOMMIT"
	CortexServerVersion = "UNKNOWN"
	CortexPAPIVersion   = "UNKNOWN"
	GoVersion           = "UNKNOWN"
	BuildDate           = "UNKNOWN"
)

Functions

func NewTransport

func NewTransport(t http.RoundTripper, client InternalClient) *transport

NewTransport creates a wrapper around an http.RoundTripper, designed to be used for the `Transport` field of http.Client.

This logs each pair of HTTP request/response that it handles. The logging is done via the `InternalClient` interface.

Types

type Client

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

Client is the core HTTP client for interacting with the Cortex Cloud API.

This client is intended for internal use by higher-level SDK modules. All configuration is passed during its creation via a Config object.

func NewClientFromConfig

func NewClientFromConfig(cfg *config.Config) (*Client, error)

NewClientFromConfig creates and initializes a new core HTTP client from a config object. It takes a pointer to a Config, which should be fully configured.

func (*Client) APIKeyType

func (c *Client) APIKeyType() string

APIKeyType returns the Cortex API key type.

func (*Client) APIURL

func (c *Client) APIURL() string

APIURL returns the API URL for the Cortex.

func (*Client) CrashStackDir

func (c *Client) CrashStackDir() string

CrashStackDir returns the crash stack directory.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method string, endpoint string, pathParams *[]string, queryParams *url.Values, input, output any, opts *DoOptions) ([]byte, error)

Do performs the given API request.

This is the core method for making authenticated HTTP calls to the Cortex Cloud API. It returns the raw response body and a structured SDK error if any error occurs.

func (*Client) FQDN

func (c *Client) FQDN() string

FQDN returns the FQDN of the Cortex tenant.

func (Client) IsCortexClient

func (Client) IsCortexClient()

Marker method for CortexClient interface compliance.

func (*Client) LogLevel

func (c *Client) LogLevel() string

LogLevel returns the log level.

func (*Client) Logger

func (c *Client) Logger() log.Logger

Logger returns the logger.

func (*Client) MaxRetries

func (c *Client) MaxRetries() int

MaxRetries returns the maximum number of retries.

func (*Client) RetryMaxDelay

func (c *Client) RetryMaxDelay() time.Duration

RetryMaxDelay returns the maximum retry delay.

func (*Client) SkipLoggingTransport

func (c *Client) SkipLoggingTransport() bool

SkipLoggingTransport returns whether to skip logging transport.

func (*Client) SkipSSLVerify

func (c *Client) SkipSSLVerify() bool

SkipSSLVerify returns whether to skip TLS certificate verification.

func (*Client) Timeout

func (c *Client) Timeout() time.Duration

Timeout returns the HTTP timeout.

func (*Client) ValidateAPIKey

func (c *Client) ValidateAPIKey(ctx context.Context) (bool, error)

ValidateAPIKey validates the configured API Key against the target Cortex tenant.

type DoOptions

type DoOptions struct {
	RequestWrapperKeys  []string
	ResponseWrapperKeys []string
}

type InternalClient

type InternalClient interface {
	LogLevelIsSetTo(string) bool
	Log(ctx context.Context, level, msg string)
}

InternalClient is an interface that the transport layer uses to interact with the core client's logging and validation settings. This interface allows for a clean separation of concerns and avoids direct dependency on the concrete Client struct, promoting testability.

Jump to

Keyboard shortcuts

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