Documentation
¶
Overview ¶
Package promoauth is for instrumenting oauth2 flows with prometheus metrics. Specifically, it is intended to count the number of external requests made by the underlying oauth2 exchanges.
Index ¶
- type Config
- func (c *Config) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
- func (c *Config) Do(ctx context.Context, source Oauth2Source, req *http.Request) (*http.Response, error)
- func (c *Config) Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error)
- func (c *Config) InstrumentHTTPClient(hc *http.Client, source Oauth2Source) *http.Client
- func (c *Config) TokenSource(ctx context.Context, token *oauth2.Token) oauth2.TokenSource
- type Factory
- type InstrumentedOAuth2Config
- type OAuth2Config
- type Oauth2Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) AuthCodeURL ¶
func (c *Config) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
func (*Config) InstrumentHTTPClient ¶ added in v2.8.0
InstrumentHTTPClient will always return a new http client. The new client will match the one passed in, but will have an instrumented round tripper.
func (*Config) TokenSource ¶
type Factory ¶
type Factory struct { // optional replace now func Now func() time.Time // contains filtered or unexported fields }
Factory allows us to have 1 set of metrics for all oauth2 providers. Primarily to avoid any prometheus errors registering duplicate metrics.
func NewFactory ¶
func NewFactory(registry prometheus.Registerer) *Factory
type InstrumentedOAuth2Config ¶
type InstrumentedOAuth2Config interface { OAuth2Config // Do is provided as a convenience method to make a request with the oauth2 client. // It mirrors `http.Client.Do`. Do(ctx context.Context, source Oauth2Source, req *http.Request) (*http.Response, error) }
InstrumentedOAuth2Config extends OAuth2Config with a `Do` method that allows external oauth related calls to be instrumented. This is to support "ValidateToken" which is not an oauth2 specified method. These calls still count against the api rate limit, and should be instrumented.
type OAuth2Config ¶
type OAuth2Config interface { AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string Exchange(ctx context.Context, code string, opts ...oauth2.AuthCodeOption) (*oauth2.Token, error) TokenSource(context.Context, *oauth2.Token) oauth2.TokenSource }
OAuth2Config exposes a subset of *oauth2.Config functions for easier testing. *oauth2.Config should be used instead of implementing this in production.
type Oauth2Source ¶
type Oauth2Source string
const ( SourceValidateToken Oauth2Source = "ValidateToken" SourceExchange Oauth2Source = "Exchange" SourceTokenSource Oauth2Source = "TokenSource" SourceAppInstallations Oauth2Source = "AppInstallations" SourceAuthorizeDevice Oauth2Source = "AuthorizeDevice" SourceGitAPIAuthUser Oauth2Source = "GitAPIAuthUser" SourceGitAPIListEmails Oauth2Source = "GitAPIListEmails" SourceGitAPIOrgMemberships Oauth2Source = "GitAPIOrgMemberships" SourceGitAPITeamMemberships Oauth2Source = "GitAPITeamMemberships" )