client

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MPL-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// RateLimitUnset is what the Admin API reports for a bucket with no
	// endpoint-level override.
	RateLimitUnset = -1

	SourcePlanDefault  = "plan_default"
	SourceUserOverride = "user_override"

	BucketRPS = "rps"
	BucketRPM = "rpm"
	BucketRPD = "rpd"
)
View Source
const (
	StreamStatusActive     = "active"
	StreamStatusPaused     = "paused"
	StreamStatusTerminated = "terminated"
	StreamStatusCompleted  = "completed"
)
View Source
const (
	DestinationWebhook  = "webhook"
	DestinationS3       = "s3"
	DestinationAzure    = "azure"
	DestinationPostgres = "postgres"
	DestinationKafka    = "kafka"
)
View Source
const DefaultBaseURL = "https://api.quicknode.com"
View Source
const KVBatchLimit = 1500

KVBatchLimit is the most items one list write may add and remove together. Larger changes are split into several writes, so a failure part way through leaves some of them applied.

View Source
const StreamRangeUnset int64 = -1

StreamRangeUnset is what the API reports for an end_range that runs forever, and what it accepts as a start_range meaning the latest block.

View Source
const URLTokenPlaceholder = "REPLACE_WITH_TOKEN"

URLTokenPlaceholder stands in for the auth token in SafeHTTPURL and SafeWSSURL. It keeps the shape of the real URL, including any path suffix the chain appends, so the token's position stays visible and a caller can substitute one without guessing where it goes.

Variables

View Source
var KVKeyPattern = regexp.MustCompile(`^[A-Za-z0-9 ._:$-]+$`)

KVKeyPattern matches the list and value keys the Key-Value API accepts.

Functions

func EndpointURLWithToken added in v0.2.0

func EndpointURLWithToken(raw, token string) string

EndpointURLWithToken puts token in the credential's position of an endpoint URL, whether that position holds a real token or URLTokenPlaceholder.

func IsAlreadyExists added in v0.3.0

func IsAlreadyExists(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsUnauthorized

func IsUnauthorized(err error) bool

IsUnauthorized reports the two ways the Admin API rejects a key: an invalid key, and a key on a plan without Admin API access.

func RedactEndpointURL

func RedactEndpointURL(raw string) string

RedactEndpointURL replaces the credential in an endpoint URL with URLTokenPlaceholder. The Admin API returns URLs shaped https://<subdomain>.quiknode.pro/<token>[/<suffix>], and the suffix differs by chain, so the placeholder goes in the token's position and nothing is cut out. The result keeps the real URL's shape and is safe to log.

Types

type AzureDestination added in v0.4.0

type AzureDestination struct {
	StorageAccount      string `json:"storage_account"`
	Container           string `json:"container"`
	BlobPrefix          string `json:"blob_prefix"`
	FileType            string `json:"file_type"`
	FileCompressionType string `json:"file_compression_type"`
	SASToken            string `json:"sas_token,omitempty"`
	MaxRetry            int64  `json:"max_retry"`
	RetryIntervalSec    int64  `json:"retry_interval_sec"`
}

type Chain

type Chain struct {
	Slug          string
	IsSelectChain bool
	Networks      []Network
}

type Client

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

func New

func New(apiKey string, opts ...Option) (*Client, error)

func (*Client) ActivateStream added in v0.4.0

func (c *Client) ActivateStream(ctx context.Context, id string) error

func (*Client) AddDomainMask

func (c *Client) AddDomainMask(ctx context.Context, endpointID, domainMask string) (*SecurityEntry, error)

func (*Client) AddEndpointIP

func (c *Client) AddEndpointIP(ctx context.Context, endpointID, ip string) (*SecurityEntry, error)

func (*Client) AddEndpointTag

func (c *Client) AddEndpointTag(ctx context.Context, id, label string) error

func (*Client) AddEndpointToken

func (c *Client) AddEndpointToken(ctx context.Context, endpointID string) (*EndpointToken, error)

func (*Client) AddJWT

func (c *Client) AddJWT(ctx context.Context, endpointID string, jwt JWT) (*JWT, error)

func (*Client) AddMethodRateLimit

func (c *Client) AddMethodRateLimit(ctx context.Context, endpointID string, limiter MethodRateLimit) (*MethodRateLimit, error)

func (*Client) AddReferrer

func (c *Client) AddReferrer(ctx context.Context, endpointID, referrer string) (*SecurityEntry, error)

func (*Client) AddRequestFilter

func (c *Client) AddRequestFilter(ctx context.Context, endpointID string, methods []string) (*RequestFilter, error)

func (*Client) CreateEndpoint

func (c *Client) CreateEndpoint(ctx context.Context, chain, network string) (*Endpoint, error)

func (*Client) CreateKVList added in v0.4.0

func (c *Client) CreateKVList(ctx context.Context, key string, items []string) error

CreateKVList writes a new list. Creating a list whose key already exists adds the items to it rather than replacing it, so callers check first.

func (*Client) CreateStream added in v0.4.0

func (c *Client) CreateStream(ctx context.Context, input StreamInput) (*Stream, error)

func (*Client) DeleteEndpoint

func (c *Client) DeleteEndpoint(ctx context.Context, id string) error

func (*Client) DeleteIPCustomHeader

func (c *Client) DeleteIPCustomHeader(ctx context.Context, endpointID string) error

func (*Client) DeleteKVList added in v0.4.0

func (c *Client) DeleteKVList(ctx context.Context, key string) error

func (*Client) DeleteKVValue added in v0.4.0

func (c *Client) DeleteKVValue(ctx context.Context, key string) error

func (*Client) DeleteRateLimitOverride

func (c *Client) DeleteRateLimitOverride(ctx context.Context, endpointID, overrideID string) error

DeleteRateLimitOverride drops one bucket back to the plan default. A 404 is success, since an absent override is the state the caller asked for.

func (*Client) DeleteStream added in v0.4.0

func (c *Client) DeleteStream(ctx context.Context, id string) error

func (*Client) FindEndpointByLabel

func (c *Client) FindEndpointByLabel(ctx context.Context, label string) (*EndpointSummary, error)

FindEndpointByLabel resolves a label to a single endpoint. Labels are not unique, so more than one match is an error.

func (*Client) GetEndpoint

func (c *Client) GetEndpoint(ctx context.Context, id string) (*Endpoint, error)

func (*Client) GetEndpointSecurity

func (c *Client) GetEndpointSecurity(ctx context.Context, endpointID string) (*EndpointSecurity, error)

func (*Client) GetEndpointURLs added in v0.2.0

func (c *Client) GetEndpointURLs(ctx context.Context, id string) (*EndpointURLs, error)

func (*Client) GetKVList added in v0.4.0

func (c *Client) GetKVList(ctx context.Context, key string) ([]string, error)

GetKVList returns every item in the list, in the API's sorted order. A list that does not exist reads the same as an empty one, so both return no items and no error.

func (*Client) GetKVValue added in v0.4.0

func (c *Client) GetKVValue(ctx context.Context, key string) (string, error)

GetKVValue returns an error that satisfies IsNotFound when the key has no value.

func (*Client) GetRateLimits

func (c *Client) GetRateLimits(ctx context.Context, endpointID string) ([]RateLimit, error)

func (*Client) GetStream added in v0.4.0

func (c *Client) GetStream(ctx context.Context, id string) (*Stream, error)

func (*Client) ListChains

func (c *Client) ListChains(ctx context.Context) ([]Chain, error)

func (*Client) ListEndpoints

func (c *Client) ListEndpoints(ctx context.Context, filter EndpointFilter) ([]EndpointSummary, error)

ListEndpoints walks every page, so a caller gets the whole account rather than the first twenty rows.

func (*Client) ListMethodRateLimits

func (c *Client) ListMethodRateLimits(ctx context.Context, endpointID string) ([]MethodRateLimit, error)

func (*Client) PauseStream added in v0.4.0

func (c *Client) PauseStream(ctx context.Context, id string) error

func (*Client) RemoveDomainMask

func (c *Client) RemoveDomainMask(ctx context.Context, endpointID, domainMaskID string) error

func (*Client) RemoveEndpointIP

func (c *Client) RemoveEndpointIP(ctx context.Context, endpointID, ipID string) error

func (*Client) RemoveEndpointTag

func (c *Client) RemoveEndpointTag(ctx context.Context, id string, tagID int64) error

func (*Client) RemoveEndpointToken

func (c *Client) RemoveEndpointToken(ctx context.Context, endpointID, tokenID string) error

func (*Client) RemoveJWT

func (c *Client) RemoveJWT(ctx context.Context, endpointID, jwtID string) error

func (*Client) RemoveMethodRateLimit

func (c *Client) RemoveMethodRateLimit(ctx context.Context, endpointID, limiterID string) error

func (*Client) RemoveReferrer

func (c *Client) RemoveReferrer(ctx context.Context, endpointID, referrerID string) error

func (*Client) RemoveRequestFilter

func (c *Client) RemoveRequestFilter(ctx context.Context, endpointID, filterID string) error

func (*Client) SetEndpointLabel

func (c *Client) SetEndpointLabel(ctx context.Context, id, label string) error

func (*Client) SetEndpointMultichain

func (c *Client) SetEndpointMultichain(ctx context.Context, id string, enabled bool) error

func (*Client) SetEndpointStatus

func (c *Client) SetEndpointStatus(ctx context.Context, id, status string) error

func (*Client) SetIPCustomHeader

func (c *Client) SetIPCustomHeader(ctx context.Context, endpointID, headerName string) error

func (*Client) SetKVValue added in v0.4.0

func (c *Client) SetKVValue(ctx context.Context, key, value string) error

SetKVValue stores the value, replacing any value the key already has.

func (*Client) SetRateLimits

func (c *Client) SetRateLimits(ctx context.Context, endpointID string, overrides RateLimitOverrides) error

SetRateLimits writes the buckets the caller manages. Managing none sends no request at all.

func (*Client) SetSecurityOptions

func (c *Client) SetSecurityOptions(ctx context.Context, endpointID string, patch SecurityOptionsPatch) error

SetSecurityOptions writes the settable toggles. The read path reports them as booleans and the write path takes the strings "enabled" and "disabled", so the conversion happens here once, for every caller. A patch that manages nothing sends no request at all.

func (*Client) UpdateKVList added in v0.4.0

func (c *Client) UpdateKVList(ctx context.Context, key string, add, remove []string) error

UpdateKVList adds and removes items in batches of at most KVBatchLimit.

func (*Client) UpdateMethodRateLimit

func (c *Client) UpdateMethodRateLimit(ctx context.Context, endpointID, limiterID string, limiter MethodRateLimit) error

UpdateMethodRateLimit edits a limiter in place. The route takes the whole object, not a delta, and it does not accept interval, so a changed interval has to replace the limiter.

func (*Client) UpdateRequestFilter

func (c *Client) UpdateRequestFilter(ctx context.Context, endpointID, filterID string, methods []string) error

func (*Client) UpdateStream added in v0.4.0

func (c *Client) UpdateStream(ctx context.Context, id string, update StreamUpdate) (*Stream, error)

type Endpoint

type Endpoint struct {
	ID      string
	Chain   string
	Network string
	Label   string
	Status  string

	// SafeHTTPURL and SafeWSSURL carry URLTokenPlaceholder where the token
	// belongs, so they can be logged or displayed. HTTPURLWithToken and
	// WSSURLWithToken are what the API returned, credential included.
	SafeHTTPURL      string
	SafeWSSURL       string
	HTTPURLWithToken string
	WSSURLWithToken  string

	Multichain bool
	Tokens     []EndpointToken
	Tags       []Tag
	Security   SecurityOptions
}

type EndpointFilter

type EndpointFilter struct {
	Search    string
	Networks  []string
	Statuses  []string
	Labels    []string
	TagLabels []string
}

EndpointFilter narrows a listing. Empty fields are left off the query, and the API treats several values in one field as "any of".

type EndpointSecurity

type EndpointSecurity struct {
	Options        SecurityOptions
	IPs            []SecurityEntry
	DomainMasks    []SecurityEntry
	Referrers      []SecurityEntry
	JWTs           []JWT
	RequestFilters []RequestFilter
	Tokens         []EndpointToken
}

type EndpointSummary

type EndpointSummary struct {
	ID          string
	Name        string
	Label       string
	Chain       string
	Network     string
	Status      string
	SafeHTTPURL string
	SafeWSSURL  string
	Dedicated   bool
	FlatRate    bool
	Multichain  bool
	Tags        []Tag
}

EndpointSummary is one row of the list route. It carries less than a full endpoint read: no tokens, no security and no rate limits. The list route returns credentialed URLs, so the URLs here are redacted on the way in and the working form is only available from a full endpoint read.

type EndpointToken

type EndpointToken struct {
	ID    string
	Value string
}

EndpointToken is one of an endpoint's auth tokens. An endpoint can carry several, so this is a list.

type EndpointURLs added in v0.2.0

type EndpointURLs struct {
	NetworkURLs
	Multichain map[string]NetworkURLs
}

EndpointURLs is what the URLs route returns: the endpoint's own network, and for a multichain endpoint every network it serves, keyed by network slug.

type Error

type Error struct {
	Operation string
	Status    int
	Message   string
}

Error carries an Admin API failure. The Admin API can report a failure either through the HTTP status or through the "error" field of a 200 response body, so both paths produce this type.

func (*Error) Error

func (e *Error) Error() string

type HeaderMap added in v0.4.0

type HeaderMap map[string]string

HeaderMap is a webhook's extra request headers. The API stores header values as strings or numbers, so decoding accepts both, and it rejects a missing headers object, so a nil map encodes as an empty one.

func (HeaderMap) MarshalJSON added in v0.4.0

func (h HeaderMap) MarshalJSON() ([]byte, error)

func (*HeaderMap) UnmarshalJSON added in v0.4.0

func (h *HeaderMap) UnmarshalJSON(raw []byte) error

type JWT

type JWT struct {
	ID        string
	Name      string
	KID       string
	PublicKey string
}

type KafkaDestination added in v0.4.0

type KafkaDestination struct {
	BootstrapServers  string `json:"bootstrap_servers"`
	TopicName         string `json:"topic_name"`
	Username          string `json:"username,omitempty"`
	Password          string `json:"password,omitempty"`
	Mechanisms        string `json:"mechanisms,omitempty"`
	Protocol          string `json:"protocol,omitempty"`
	CompressionType   string `json:"compression_type"`
	BatchSize         int64  `json:"batch_size"`
	LingerMs          int64  `json:"linger_ms"`
	MaxMessageBytes   int64  `json:"max_message_bytes"`
	TimeoutSec        int64  `json:"timeout_sec"`
	MaxRetry          int64  `json:"max_retry"`
	RetryIntervalSec  int64  `json:"retry_interval_sec"`
	SSLCAPEM          string `json:"ssl_ca_pem,omitempty"`
	SSLCertificatePEM string `json:"ssl_certificate_pem,omitempty"`
	SSLKeyPEM         string `json:"ssl_key_pem,omitempty"`
}

type MethodRateLimit

type MethodRateLimit struct {
	ID       string
	Methods  []string
	Rate     int
	Interval string
	Status   string
	Created  string
}

MethodRateLimit throttles a named set of RPC methods independently of the endpoint-wide buckets.

type Network

type Network struct {
	Slug    string
	Name    string
	ChainID *int64
}

type NetworkURLs added in v0.2.0

type NetworkURLs struct {
	SafeHTTPURL      string
	SafeWSSURL       string
	HTTPURLWithToken string
	WSSURLWithToken  string
}

NetworkURLs is one network's URLs, in the same safe and credentialed forms as Endpoint's.

type Option

type Option func(*options)

func WithBaseURL

func WithBaseURL(baseURL string) Option

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

func WithRequestsPerSecond

func WithRequestsPerSecond(requestsPerSecond int) Option

WithRequestsPerSecond throttles outbound calls. A terraform apply over a large workspace bursts many Admin API calls at once, so the provider paces itself and does not lean on the API to reject the excess.

func WithUserAgent added in v0.4.0

func WithUserAgent(userAgent string) Option

WithUserAgent sets the User-Agent header on every request.

type PostgresDestination added in v0.4.0

type PostgresDestination struct {
	Host             string `json:"host"`
	Port             int64  `json:"port"`
	Database         string `json:"database"`
	TableName        string `json:"table_name"`
	Username         string `json:"username"`
	Password         string `json:"password"`
	SSLMode          string `json:"sslmode"`
	MaxRetry         int64  `json:"max_retry"`
	RetryIntervalSec int64  `json:"retry_interval_sec"`
}

type RateLimit

type RateLimit struct {
	Bucket string
	Value  int
	Source string
	ID     string
}

RateLimit is one bucket as the API reports it. A plan_default carries no id, because only an override can be deleted.

type RateLimitOverrides

type RateLimitOverrides struct {
	RPS *int
	RPM *int
	RPD *int
}

RateLimitOverrides names the buckets a write can set. A nil field is left alone, so a configuration that manages only one bucket does not disturb the others.

type RequestFilter

type RequestFilter struct {
	ID      string
	Methods []string
}

type S3Destination added in v0.4.0

type S3Destination struct {
	Endpoint            string `json:"endpoint"`
	Bucket              string `json:"bucket"`
	Region              string `json:"region,omitempty"`
	ObjectPrefix        string `json:"object_prefix"`
	FileType            string `json:"file_type"`
	FileCompressionType string `json:"file_compression_type"`
	UseSSL              bool   `json:"use_ssl"`
	AccessKey           string `json:"access_key"`
	SecretKey           string `json:"secret_key"`
	MaxRetry            int64  `json:"max_retry"`
	RetryIntervalSec    int64  `json:"retry_interval_sec"`
}

type SecurityEntry

type SecurityEntry struct {
	ID    string
	Value string
}

type SecurityOptions

type SecurityOptions struct {
	Tokens      bool
	Referrers   bool
	JWTs        bool
	IPs         bool
	DomainMasks bool
	HSTS        bool
	Cors        bool

	RequestFilters  bool
	ResponseLogging bool

	IPCustomHeader string
}

SecurityOptions carries the toggles the Admin API reports for an endpoint. Tokens through Cors are settable. RequestFilters and ResponseLogging are reported but cannot be written, so the provider surfaces them read-only.

type SecurityOptionsPatch

type SecurityOptionsPatch struct {
	Tokens      *bool
	Referrers   *bool
	JWTs        *bool
	IPs         *bool
	DomainMasks *bool
	HSTS        *bool
	Cors        *bool
}

SecurityOptionsPatch names the settable toggles. A nil field is left alone, which keeps a write from clobbering a toggle the configuration does not manage.

type Stream added in v0.4.0

type Stream struct {
	ID      string
	Name    string
	Status  string
	Network string
	Dataset string
	Region  string

	// FilterFunction is the filter's source code. The API carries it base64
	// encoded; the client encodes and decodes it.
	FilterFunction string
	FilterLanguage string

	StartRange           int64
	EndRange             int64
	DatasetBatchSize     int64
	ElasticBatchEnabled  bool
	RestreamBatchOnReorg bool
	FixBlockReorgs       int64
	KeepDistanceFromTip  int64
	NotificationEmail    string

	// Sequence is the last block delivered. It moves on its own while the
	// stream runs.
	Sequence int64

	Destination       StreamDestination
	ExtraDestinations []StreamDestination
}

type StreamDestination added in v0.4.0

type StreamDestination struct {
	Webhook  *WebhookDestination
	S3       *S3Destination
	Azure    *AzureDestination
	Postgres *PostgresDestination
	Kafka    *KafkaDestination
	// contains filtered or unexported fields
}

StreamDestination holds exactly one destination type. A type the API reports but the client does not model, such as one configured in the dashboard, leaves every field nil and is named by Type.

func (StreamDestination) MarshalJSON added in v0.4.0

func (d StreamDestination) MarshalJSON() ([]byte, error)

func (StreamDestination) Type added in v0.4.0

func (d StreamDestination) Type() string

func (*StreamDestination) UnmarshalJSON added in v0.4.0

func (d *StreamDestination) UnmarshalJSON(raw []byte) error

type StreamInput added in v0.4.0

type StreamInput struct {
	Name           string
	Network        string
	Dataset        string
	Region         string
	Status         string
	FilterFunction string
	FilterLanguage string

	StartRange           *int64
	EndRange             *int64
	DatasetBatchSize     int64
	ElasticBatchEnabled  bool
	RestreamBatchOnReorg *bool
	FixBlockReorgs       *int64
	KeepDistanceFromTip  *int64
	NotificationEmail    *string

	Destination       StreamDestination
	ExtraDestinations []StreamDestination
}

type StreamUpdate added in v0.4.0

type StreamUpdate struct {
	Name           *string
	FilterFunction *string
	FilterLanguage *string

	StartRange           *int64
	EndRange             *int64
	DatasetBatchSize     *int64
	ElasticBatchEnabled  *bool
	RestreamBatchOnReorg *bool
	FixBlockReorgs       *int64
	KeepDistanceFromTip  *int64
	NotificationEmail    *string

	Destination       *StreamDestination
	ExtraDestinations *[]StreamDestination
}

StreamUpdate sends only the fields that are set. Network, dataset and region cannot change after creation, and status changes go through PauseStream and ActivateStream, which run the plan checks a PATCH skips.

type Tag

type Tag struct {
	ID    int64
	Label string
}

type WebhookDestination added in v0.4.0

type WebhookDestination struct {
	URL              string    `json:"url"`
	Compression      string    `json:"compression"`
	Headers          HeaderMap `json:"headers"`
	MaxRetry         int64     `json:"max_retry"`
	RetryIntervalSec int64     `json:"retry_interval_sec"`
	PostTimeoutSec   int64     `json:"post_timeout_sec"`
	SecurityToken    string    `json:"security_token,omitempty"`
	MTLS             *bool     `json:"mtls,omitempty"`
	SSLCAPEM         string    `json:"ssl_ca_pem,omitempty"`
}

Jump to

Keyboard shortcuts

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