Documentation ¶
Overview ¶
Package gcp provides utilities for working with GCP
Index ¶
- Constants
- type CachedCredentialHelper
- type CredentialHelper
- type FileTokenCache
- type SecretCache
- type TokenCache
- type WebFlowHelper
- func (h *WebFlowHelper) Address() string
- func (s *WebFlowHelper) AuthStartURL() string
- func (h *WebFlowHelper) GetOAuthConfig() *oauth2.Config
- func (h *WebFlowHelper) GetTokenSource(ctx context.Context) (oauth2.TokenSource, error)
- func (h *WebFlowHelper) HealthCheck(w http.ResponseWriter, r *http.Request)
- func (h *WebFlowHelper) NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func (h *WebFlowHelper) Run() (oauth2.TokenSource, error)
Constants ¶
const (
// CredentialDirPermMode unix permission max suitable for directory storing credentials
CredentialDirPermMode = 0700
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedCredentialHelper ¶
type CachedCredentialHelper struct { CredentialHelper CredentialHelper TokenCache TokenCache Log logr.Logger }
CachedCredentialHelper is a credential helper that will cache the credential.
func (*CachedCredentialHelper) GetOAuthConfig ¶
func (h *CachedCredentialHelper) GetOAuthConfig() *oauth2.Config
func (*CachedCredentialHelper) GetTokenSource ¶
func (c *CachedCredentialHelper) GetTokenSource(ctx context.Context) (oauth2.TokenSource, error)
type CredentialHelper ¶
type CredentialHelper interface { GetTokenSource(ctx context.Context) (oauth2.TokenSource, error) // GetOAuthConfig returns the OAuth2 client configuration GetOAuthConfig() *oauth2.Config }
CredentialHelper defines an interface for getting tokens.
type FileTokenCache ¶
FileTokenCache implements caching to a file.
type SecretCache ¶
type SecretCache struct { Project string Secret string Version string Log logr.Logger // contains filtered or unexported fields }
SecretCache implements a cache for an OAuth2 credential using GCP secret manager
func NewSecretCache ¶
func NewSecretCache(project string, secret string, version string) (*SecretCache, error)
type TokenCache ¶
TokenCache defines an interface for caching tokens
type WebFlowHelper ¶
WebFlowHelper helps get credentials using the webflow. It is intended for desktop applications. It runs a local server to handle the callback from the OAuth server to get the authorization code and return a token source.
References: https://developers.google.com/identity/protocols/oauth2/native-app#request-parameter-redirect_uri GCP still supports using the loopback device 127.0.0.1 for OAuth credentials for desktop applications. It looks like in that case you don't actually have to specify your redirect URI when configuring the OAuth Client in the developer console. However, when you specify your OAuth configuration in the code you need to specify the redirect URI and it needs to be 127.0.0.1 not localhost.
func NewWebFlowHelper ¶
func NewWebFlowHelper(oAuthClientFile string, scopes []string) (*WebFlowHelper, error)
NewWebFlowHelper constructs a new web flow helper. oAuthClientFile should be the path to a credentials.json downloaded from the API console.
func (*WebFlowHelper) Address ¶
func (h *WebFlowHelper) Address() string
func (*WebFlowHelper) AuthStartURL ¶
func (s *WebFlowHelper) AuthStartURL() string
AuthStartURL returns the URL to kickoff the oauth login flow.
func (*WebFlowHelper) GetOAuthConfig ¶
func (h *WebFlowHelper) GetOAuthConfig() *oauth2.Config
func (*WebFlowHelper) GetTokenSource ¶
func (h *WebFlowHelper) GetTokenSource(ctx context.Context) (oauth2.TokenSource, error)
GetTokenSource requests a token from the web, then returns the retrieved token. TODO(jeremy): Deprecate this method in favor of Run.
func (*WebFlowHelper) HealthCheck ¶
func (h *WebFlowHelper) HealthCheck(w http.ResponseWriter, r *http.Request)
func (*WebFlowHelper) NotFoundHandler ¶
func (h *WebFlowHelper) NotFoundHandler(w http.ResponseWriter, r *http.Request)
func (*WebFlowHelper) Run ¶
func (h *WebFlowHelper) Run() (oauth2.TokenSource, error)
Run runs the flow to create a tokensource. It starts a server in order to provide a callback that the OAuthFlow can redirect to in order to pass the authorization code. The server is shutdown after the flow is complete. Since the flow should return a refresh token it shouldn't be necessary to keep it running.