Documentation
¶
Overview ¶
Package clientcredentials helps with oauth2 client-credentials flow.
Index ¶
Constants ¶
const DefaultGroupCacheSizeBytes = 10_000_000
DefaultGroupCacheSizeBytes is default group cache size when unspecified.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is context for invokations with client-credentials flow.
func (*Client) Do ¶
Do sends an HTTP request and returns an HTTP response. The actual HTTPClient provided in the Options is used to make the requests and also to retrieve the required client_credentials token. Do retrieves the token and renews it as necessary for making the request.
func (*Client) MetricsExporter ¶ added in v0.0.2
func (c *Client) MetricsExporter() *modernprogram.Group
MetricsExporter creates a metrics exporter for Prometheus.
Usage example
exporter := client.MetricsExporter() labels := map[string]string{ "app": "app1", } namespace := "" collector := groupcache_exporter.NewExporter(namespace, labels, exporter) prometheus.MustRegister(collector) go func() { http.Handle(metricsRoute, promhttp.Handler()) log.Fatal(http.ListenAndServe(metricsPort, nil)) }()
type HTTPClientDoer ¶ added in v0.1.0
HTTPClientDoer interface allows the caller to easily plug in a custom http client.
type Options ¶
type Options struct { // TokenURL is the resource server's token endpoint // URL. This is a constant specific to each server. TokenURL string // ClientID is the application's ID. ClientID string // ClientSecret is the application's secret. ClientSecret string // Scope specifies optional space-separated requested permissions. Scope string // HTTPClient provides the actual HTTP client to use. // If unspecified, defaults to http.DefaultClient. HTTPClient HTTPClientDoer // HTTPStatusOkMin is the minimum token server response status code accepted as Ok. // If undefined, defaults to 200. HTTPStatusOkMin int // HTTPStatusOkMax is the maximum token server response status code accepted as Ok. // If undefined, defaults to 299. HTTPStatusOkMax int // SoftExpireInSeconds specifies how early before hard expiration the // token should be considered expired to trigger renewal. This // prevents from using an expired token due to clock // differences. // // 0 defaults to 10 seconds. Set to -1 to no soft expire. // // Example: consider expire_in = 30 seconds and soft expire = 10 seconds. // The token will hard expire after 30 seconds, but we will consider it // expired after (30-10) = 20 seconds, in order to attempt renewal before // hard expiration. // SoftExpireInSeconds int // GroupcacheWorkspace is required groupcache workspace. GroupcacheWorkspace *groupcache.Workspace // GroupcacheName gives a unique cache name. If unspecified, defaults to oauth2. GroupcacheName string // GroupcacheSizeBytes limits the cache size. If unspecified, defaults to 10MB. GroupcacheSizeBytes int64 // Logf provides logging function, if undefined defaults to log.Printf Logf func(format string, v ...any) // Debug enables debug logging. Debug bool // DisablePurgeExpired disables removing all expired items when the oldest item is removed. DisablePurgeExpired bool }
Options define client options.