gcp

package
v0.0.0-...-814ce2b Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package gcp provides utilities for working with GCP

Index

Constants

View Source
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

type FileTokenCache struct {
	CacheFile string
	Log       logr.Logger
}

FileTokenCache implements caching to a file.

func (*FileTokenCache) GetToken

func (c *FileTokenCache) GetToken() (*oauth2.Token, error)

func (*FileTokenCache) Save

func (c *FileTokenCache) Save(token *oauth2.Token) error

Save saves a token to a file path.

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)

func (*SecretCache) GetToken

func (c *SecretCache) GetToken() (*oauth2.Token, error)

func (*SecretCache) Save

func (c *SecretCache) Save(token *oauth2.Token) error

Save saves a token to a file path.

type TokenCache

type TokenCache interface {
	GetToken() (*oauth2.Token, error)
	Save(token *oauth2.Token) error
}

TokenCache defines an interface for caching tokens

type WebFlowHelper

type WebFlowHelper struct {
	Log logr.Logger
	// contains filtered or unexported fields
}

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.

Verzeichnisse

Path Synopsis
package gcs provides useful utilities for GCS This package isn't specific to our groups sync.
package gcs provides useful utilities for GCS This package isn't specific to our groups sync.

Jump to

Keyboard shortcuts

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