client

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeForm = "application/x-www-form-urlencoded"
	ContentTypeJSON = "application/json"
)
View Source
const (
	ServiceAccountLoginURLSuffix = "/oauth/token"
	EngineUrlByAccountName       = "/web/v3/account/%s/engineUrl"
	//API v0
	UsernamePasswordURLSuffix  = "/auth/v1/login"
	DefaultAccountURL          = "/iam/v2/account"
	AccountIdByNameURL         = "/iam/v2/accounts:getIdByName"
	EngineIdByNameURL          = "/core/v1/accounts/%s/engines:getIdByName"
	EngineByIdURL              = "/core/v1/accounts/%s/engines/%s"
	EngineUrlByDatabaseNameURL = "/core/v1/accounts/%s/engines:getURLByDatabaseName"
)
View Source
const AuthAudienceValue = "https://api.firebolt.io"

Variables

This section is empty.

Functions

func ConstructUserAgentString

func ConstructUserAgentString() (ua_string string)

ConstructUserAgentString returns a string with go, GoSDK and os type and versions additionally user can set "FIREBOLT_GO_DRIVERS" and "FIREBOLT_GO_CLIENTS" env variable, and they will be concatenated with the final user-agent string

func DefaultTransport added in v1.18.0

func DefaultTransport() *http.Transport

DefaultTransport returns a new *http.Transport with the SDK's default settings. Callers can customize the returned transport and pass it via WithTransport when creating a connector.

transport := client.DefaultTransport()
transport.DialContext = (&net.Dialer{
    Timeout:   60 * time.Second,
    KeepAlive: 60 * time.Second,
}).DialContext
transport.IdleConnTimeout = 2 * time.Minute

func GetHostNameURL

func GetHostNameURL() string

GetHostNameURL returns a hostname url, either default or overwritten with the environment variable

func MakeCanonicalUrl

func MakeCanonicalUrl(url string) string

MakeCanonicalUrl checks whether url starts with https:// and if not prepends it

func NewHttpClient added in v1.16.0

func NewHttpClient() *http.Client

NewHttpClient creates an *http.Client with DefaultTransport().

func NewHttpClientForLB added in v1.17.0

func NewHttpClientForLB(tlsServerName string) *http.Client

NewHttpClientForLB creates an *http.Client suitable for client-side load balancing. When the resolver rewrites URLs to use raw IP addresses, tlsServerName ensures TLS certificate verification still uses the original hostname. Pass an empty string if TLS is not used (plain HTTP).

func NewHttpClientForLBWithTransport added in v1.18.0

func NewHttpClientForLBWithTransport(rt http.RoundTripper, tlsServerName string) *http.Client

NewHttpClientForLBWithTransport is like NewHttpClientForLB but uses the given RoundTripper instead of DefaultTransport(). When rt is an *http.Transport, TLSClientConfig.ServerName is set directly; otherwise the caller is responsible for TLS configuration in their custom RoundTripper. If rt is nil, DefaultTransport() is used.

func NewHttpClientWithTransport added in v1.18.0

func NewHttpClientWithTransport(rt http.RoundTripper) *http.Client

NewHttpClientWithTransport creates an *http.Client with the given RoundTripper. If rt is nil, DefaultTransport() is used.

Types

type AuthenticationResponse

type AuthenticationResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int    `json:"expires_in"`
	TokenType    string `json:"token_type"`
	Scope        string `json:"scope"`
}

type BaseClient

type BaseClient struct {
	ClientID          string
	ClientSecret      string
	ApiEndpoint       string
	UserAgent         string
	HttpClient        *http.Client
	ParameterGetter   func(context.Context, map[string]string) (map[string]string, error)
	AccessTokenGetter func() (string, error)
	URLResolver       *RoundRobinResolver // nil disables client-side load balancing
}

func (*BaseClient) Close added in v1.16.0

func (c *BaseClient) Close() error

Close releases resources held by the client, including idle HTTP connections.

func (*BaseClient) Query

func (c *BaseClient) Query(ctx context.Context, engineUrl, query string, parameters map[string]string, control ConnectionControl) (*Response, error)

Query sends a query to the engine URL and populates queryResponse, if query was successful

func (*BaseClient) UploadBatch added in v1.20.1

func (c *BaseClient) UploadBatch(ctx context.Context, engineUrl, sql string, payload BatchPayload, fileName, fileExt string, parameters map[string]string, control ConnectionControl) (*Response, error)

UploadBatch sends a serialised file via multipart form upload for batch INSERT. The form has two parts:

"sql"       — the INSERT query
"<fileName>"— the file bytes (e.g. Parquet)

fileExt is the extension including the dot (e.g. ".parquet") used in the Content-Disposition header.

type BatchPayload added in v1.20.1

type BatchPayload interface {
	NewReader() (io.Reader, error)
}

BatchPayload can produce a fresh io.Reader over the serialised batch body. NewReader may be called more than once (e.g. on auth retry), and each call must return an independent reader starting from the beginning.

type Client

type Client interface {
	GetConnectionParameters(ctx context.Context, engineName string, databaseName string) (string, map[string]string, error)
	Query(ctx context.Context, engineUrl, query string, parameters map[string]string, control ConnectionControl) (*Response, error)
	UploadBatch(ctx context.Context, engineUrl, sql string, payload BatchPayload, fileName, fileExt string, parameters map[string]string, control ConnectionControl) (*Response, error)
}

func ClientFactory

func ClientFactory(settings *types.FireboltSettings, apiEndpoint string) (Client, error)

ClientFactory sends an authentication request, and returns a newly constructed client object

type ClientImpl

type ClientImpl struct {
	ConnectedToSystemEngine bool
	AccountName             string
	BaseClient
}

func MakeClient

func MakeClient(settings *types.FireboltSettings, apiEndpoint string) (*ClientImpl, error)

func (*ClientImpl) GetConnectionParameters

func (c *ClientImpl) GetConnectionParameters(ctx context.Context, engineName, databaseName string) (string, map[string]string, error)

GetConnectionParameters returns engine URL and parameters based on engineName and databaseName

func (*ClientImpl) GetQueryParams

func (c *ClientImpl) GetQueryParams(ctx context.Context, setStatements map[string]string) (map[string]string, error)

type ClientImplCore added in v1.10.0

type ClientImplCore struct {
	AccountName string
	BaseClient
}

func MakeClientCore added in v1.10.0

func MakeClientCore(settings *types.FireboltSettings) (*ClientImplCore, error)

func (*ClientImplCore) GetConnectionParameters added in v1.10.0

func (c *ClientImplCore) GetConnectionParameters(_ context.Context, _, databaseName string) (string, map[string]string, error)

GetConnectionParameters returns engine URL and parameters based on engineName and databaseName

func (*ClientImplCore) GetQueryParams added in v1.10.0

func (c *ClientImplCore) GetQueryParams(ctx context.Context, setStatements map[string]string) (map[string]string, error)

type ClientImplV0

type ClientImplV0 struct {
	AccountID string
	BaseClient
}

func MakeClientV0

func MakeClientV0(settings *types.FireboltSettings, apiEndpoint string) (*ClientImplV0, error)

func (*ClientImplV0) GetAccountID added in v1.8.0

func (c *ClientImplV0) GetAccountID(ctx context.Context, accountName string) (string, error)

func (*ClientImplV0) GetConnectionParameters

func (c *ClientImplV0) GetConnectionParameters(ctx context.Context, engineName, databaseName string) (string, map[string]string, error)

GetConnectionParameters returns engine URL and engine name based on engineName and accountId

type ConnectionControl

type ConnectionControl struct {
	UpdateParameters func(string, string)
	ResetParameters  func(*[]string) // if list is nil, reset all parameters
	SetEngineURL     func(string)
}

ConnectionControl is a struct that holds methods for updating connection properties it's passed to Query method to allow it to update connection parameters and engine URL

type LookupHostFunc added in v1.17.0

type LookupHostFunc func(ctx context.Context, host string) ([]string, error)

LookupHostFunc resolves a hostname to a list of IP addresses. Its signature matches net.Resolver.LookupHost.

type MockClient

type MockClient struct {
	ParametersCalled []map[string]string
	// contains filtered or unexported fields
}

MockClient rudimentary mocks Client and tracks the parameters passed to Query

func MakeMockClient

func MakeMockClient() *MockClient

func MakeMockClientWithError

func MakeMockClientWithError(errorToRaise error) *MockClient

func (*MockClient) GetConnectionParameters

func (m *MockClient) GetConnectionParameters(ctx context.Context, engineName string, databaseName string) (string, map[string]string, error)

func (*MockClient) IsNewVersion

func (m *MockClient) IsNewVersion() bool

func (*MockClient) Query

func (m *MockClient) Query(ctx context.Context, engineUrl, query string, parameters map[string]string, control ConnectionControl) (*Response, error)

func (*MockClient) UploadBatch added in v1.20.1

func (m *MockClient) UploadBatch(ctx context.Context, engineUrl, sql string, payload BatchPayload, fileName, fileExt string, parameters map[string]string, control ConnectionControl) (*Response, error)

type Response

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

func DoHttpRequest

func DoHttpRequest(httpClient *http.Client, reqParams requestParameters) *Response

DoHttpRequest sends a request using "POST" or "GET" method on a specified url additionally it passes the parameters and a bodyStr as a payload if accessToken is passed, it is used for authorization returns Response struct. httpClient may be nil, in which case http.DefaultClient is used.

func DoHttpRequestMultipart added in v1.16.0

func DoHttpRequestMultipart(httpClient *http.Client, reqParams requestParametersMultipart) *Response

DoHttpRequestMultipart sends a multipart form POST with an "sql" text field and a file attachment whose body is streamed from reqParams.payload.

The multipart framing (boundary, headers, closing boundary) is pre-built as byte slices and concatenated with the payload via io.MultiReader. This means the HTTP body is streamed directly from the blockReader — no pipe, no goroutine, no extra copy. Content-Length is not set (chunked transfer). httpClient may be nil, in which case http.DefaultClient is used.

func MakeResponse

func MakeResponse(body io.ReadCloser, statusCode int, headers http.Header, err error) *Response

func (*Response) Body

func (r *Response) Body() io.ReadCloser

func (*Response) Content

func (r *Response) Content() ([]byte, error)

func (*Response) IsAsyncResponse added in v1.11.0

func (r *Response) IsAsyncResponse() bool

type RoundRobinResolver added in v1.17.0

type RoundRobinResolver struct {
	TTL time.Duration
	// contains filtered or unexported fields
}

RoundRobinResolver resolves a service hostname to its underlying IP addresses and cycles through them in round-robin order on each call to Next. This distributes HTTP requests across all pods behind a Kubernetes (headless) service.

DNS results are cached for a configurable TTL and refreshed lazily. If a refresh fails, the previously cached addresses are kept.

func NewRoundRobinResolver added in v1.17.0

func NewRoundRobinResolver(rawURL string, lookupHost LookupHostFunc) (*RoundRobinResolver, error)

NewRoundRobinResolver creates a resolver that will cycle through the IPs returned by lookupHost for the given URL. If lookupHost is nil, net.DefaultResolver.LookupHost is used.

func (*RoundRobinResolver) Next added in v1.17.0

func (r *RoundRobinResolver) Next(ctx context.Context) (resolvedURL string, originalHostWithPort string, err error)

Next returns the URL rewritten with the next IP in round-robin rotation, along with the original host (with port) for use as the HTTP Host header. Each successive call advances to the next IP.

Jump to

Keyboard shortcuts

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