cloud

package
v0.0.0-...-a3746d0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented is an error that can be returned to indicate that the requested functionality is not implemented.

View Source
var LogIDRegexp = regexp.MustCompile(`^[A-Za-z0-9/_\-\.]{0,512}$`)

LogIDRegexp is a regular expression that can be used to validate a Log ID.

From: https://godoc.org/cloud.google.com/go/logging#Client.Logger

Functions

func WithLogger

func WithLogger(c context.Context, l *cloudLogging.Logger, labels map[string]string) context.Context

WithLogger installs an instance of a logging.Logger that forwards logs to an underlying StackDriver Logger into the supplied Context.

The given labels will be applied to each log entry. This allows to reuse Logger instance between requests, even if they have different default labels.

An alternative is to construct Logger per request, setting request labels via CommonLabels(...) option. But it is more heavy solution, and at the time of writing it leads to memory leaks: https://github.com/GoogleCloudPlatform/google-cloud-go/issues/720#issuecomment-346199870

Types

type Config

type Config struct {
	// IsDev is true if this is a development execution.
	IsDev bool

	// ProjectID, if not empty, is the project ID returned by the "info" service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	ProjectID string

	// ServiceName, if not empty, is the service (module) name returned by the
	// "info" service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	ServiceName string

	// VersionName, if not empty, is the version name returned by the "info"
	// service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	VersionName string

	// InstanceID, if not empty, is the instance ID returned by the "info"
	// service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	InstanceID string

	// ServiceAccountName, if not empty, is the service account name returned by
	// the "info" service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	ServiceAccountName string

	// ServiceProvider, if not nil, is the system service provider to use for
	// non-cloud external resources and services.
	//
	// If nil, the service will treat requests for services as not implemented.
	ServiceProvider ServiceProvider

	// DS is the cloud datastore client. If populated, the datastore service will
	// be installed.
	DS *datastore.Client

	// MC is the memcache service client. If populated, the memcache service will
	// be installed.
	MC *memcache.Client

	// L is the Cloud Logging logger to use for requests. If populated, the
	// logging service will be installed.
	L *cloudLogging.Logger
}

Config is a full-stack cloud service configuration. A user can selectively populate its fields, and services for the populated fields will be installed in the Context and available.

Because the "impl/cloud" service collection is a composite set of cloud services, the user can choose services based on their configuration.

The parameters of Config are mostly consumed by the "service/info" service implementation, which describes the environment in which the service is run.

func (*Config) Use

func (cfg *Config) Use(c context.Context, req *Request) context.Context

Use installs the Config into the supplied Context. Services will be installed based on the fields that are populated in Config.

req is optional. If not nil, its fields will be used to initialize the services installed into the Context.

Any services that are missing will have "impl/dummy" stubs installed. These stubs will panic if called.

type Flex

type Flex struct {
	// Cache is the process-global LRU cache instance that Flexi services can use
	// to cache data.
	//
	// If Cache is nil, a default cache will be used.
	Cache *lru.Cache
}

Flex defines a Google AppEngine Flex Environment platform.

func (*Flex) Configure

func (f *Flex) Configure(c context.Context, opts ...option.ClientOption) (cfg *Config, err error)

Configure constructs a Config based on the current Flex environment.

Configure will instantiate some cloud clients. It is the responsibility of the client to close those instances when finished.

opts is the optional set of client options to pass to cloud platform clients that are instantiated.

func (*Flex) Request

func (*Flex) Request(req *http.Request) *Request

Request probes Request parameters from a AppEngine Flex Environment HTTP request.

type GoogleServiceProvider

type GoogleServiceProvider struct {
	// ServiceAccount is the name of the system's service account.
	ServiceAccount string

	// Cache is the LRU cache to use to store values that are fetched from remote
	// services.
	Cache *lru.Cache
}

GoogleServiceProvider is a ServiceProvider implementation that uses Google services.

func (*GoogleServiceProvider) PublicCertificates

func (gsp *GoogleServiceProvider) PublicCertificates(c context.Context) (certs []infoS.Certificate, err error)

PublicCertificates implements ServiceProvider's PublicCertificates using Google's public certificate endpoint.

func (*GoogleServiceProvider) SignBytes

func (gsp *GoogleServiceProvider) SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error)

SignBytes implements ServiceProvider's SignBytes using Google Cloud IAM's "SignBlob" endpoint.

The SignBlob RPC request that the GAE/Flex service account account is granted the "iam.serviceAccountActor" role, which is NOT default.

https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts/signBlob

func (*GoogleServiceProvider) TokenSource

func (gsp *GoogleServiceProvider) TokenSource(c context.Context, scopes ...string) (oauth2.TokenSource, error)

TokenSource implements ServiceProvider's TokenSource API using the default Google token source.

The way TokenSource is implemented, the service is vulnerable to a "cache stampede" effect where multiple access tokens invalidate at the same time and need to be refreshed.

TokenSource instances for a set of scopes are cached so that their access tokens will similarly be cached.

type Request

type Request struct {
	// TraceID, if not empty, is the request's trace ID returned by the "info"
	// service.
	//
	// If empty, the service will treat requests for this field as not
	// implemented.
	TraceID string
}

Request is the set of request-specific parameters.

type ServiceProvider

type ServiceProvider interface {
	// PublicCertificates returns the set of public certificates belonging to the
	// current service's service account.
	PublicCertificates(c context.Context) ([]infoS.Certificate, error)

	// TokenSource returns a token source for the specified combination of scopes.
	TokenSource(c context.Context, scopes ...string) (oauth2.TokenSource, error)

	// SignBytes signs the specified bytes with a private key belonging to the
	// current system service.
	SignBytes(c context.Context, bytes []byte) (keyName string, signature []byte, err error)
}

ServiceProvider is a set of functionality which can be used to fetch system data.

Service methods should implement their own caching as appropriate.

Service methods should return ErrNotImplemented if a given function is not implemented.

Jump to

Keyboard shortcuts

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