cfcommon

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2017 License: MIT Imports: 15 Imported by: 0

README

Overview

Contains utility classes for interacting with our CloudFoundry environments and related services.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvLookup

type EnvLookup func(key string) (string, bool)

EnvLookup must return the value for the given key and whether it was found or not

func NewEnvLookupFromCFAppNamedService

func NewEnvLookupFromCFAppNamedService(cfApp *cfenv.App, namedService string) EnvLookup

NewEnvLookupFromCFAppNamedService looks for a CloudFoundry bound service with the given name, and will allow sourcing of environment variables from there. If no service is found, a warning is printed, but no error thrown.

type EnvVars

type EnvVars struct {
	// contains filtered or unexported fields
}

EnvVars provides a convenient method to access environment variables

func NewDefaultEnvLookup

func NewDefaultEnvLookup() *EnvVars

NewDefaultEnvLookup will detect if running in a CloudFoundry app, and if so will look for an env variable named UPS_PATH which if specified, must be a ":" separated list of user-provided-services that will be searched in that order. If any are missing, a warning is printed, but no error occurs. In any case, env variables are always sourced from your local environment variables first.

func NewEnvVarsFromPath

func NewEnvVarsFromPath(path ...EnvLookup) *EnvVars

NewEnvVarsFromPath create an EnvVars object, where the elements in the path are searched in order to load a given variable.

func (*EnvVars) Bool

func (el *EnvVars) Bool(key string) bool

Bool looks for the key, and if found, parses it using strconv.ParseBool and returns the result. If not found, returns false. If found and won't parse, panics.

func (*EnvVars) MustHexEncodedByteArray

func (el *EnvVars) MustHexEncodedByteArray(key string, decodedByteLength int) []byte

MustHexEncodedByteArray will panic if value is not a hex-encoded by array of given length, else return it

func (*EnvVars) MustString

func (el *EnvVars) MustString(key string) string

MustString will panic if value is not set, otherwise it returns the value.

func (*EnvVars) String

func (el *EnvVars) String(key, defaultVal string) string

String returns value for key if present, else returns defaultVal if not found

type ErrMissingEnvVar

type ErrMissingEnvVar struct {
	// Name of the key that was not found
	Name string
}

ErrMissingEnvVar is panicked if a MustGet fails.

func (*ErrMissingEnvVar) Error

func (err *ErrMissingEnvVar) Error() string

Error returns an error string

type UAAClient

type UAAClient struct {
	// UAAURL is the URL to UAA, e.g. https://uaa.system.example.com
	UAAURL string
	// contains filtered or unexported fields
}

UAAClient will validate access tokens against a UAA instance, caching keys as required

func NewUAAClientFromAPIURL

func NewUAAClientFromAPIURL(apiEndpoint string) (*UAAClient, error)

NewUAAClientFromAPIURL looks up, via the apiEndpoint, the correct UAA address and returns a client

func (*UAAClient) ExchangeBearerTokenForClientToken

func (lh *UAAClient) ExchangeBearerTokenForClientToken(clientID, clientSecret, bearerLine string) (*UAAOAuthGrant, error)

ExchangeBearerTokenForClientToken takes a bearer token (such as that returned by CF), and exchanges via the API auth flow, for an OAuthGrant for the specified clientID. The clientSecret here is really not a secret.

func (*UAAClient) FetchAccessToken

func (lh *UAAClient) FetchAccessToken(clientID, clientSecret string, postData url.Values) (*UAAOAuthGrant, error)

FetchAccessToken sends data to endpoint to fetch a token Return grant object.

func (*UAAClient) GetAuthorizeEndpoint

func (lh *UAAClient) GetAuthorizeEndpoint() string

func (*UAAClient) GetTokenEndpoint

func (lh *UAAClient) GetTokenEndpoint() string

func (*UAAClient) ValidateAccessToken

func (lh *UAAClient) ValidateAccessToken(at, expectedClientID string) (jwt.MapClaims, error)

ValidateAccessToken will validate the given access token, ensure it matches the client ID, and return the claims reported within.

type UAAOAuthGrant

type UAAOAuthGrant struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	Scope        string `json:"scope"`
	RefreshToken string `json:"refresh_token"`
	JTI          string `json:"jti"`
}

UAAOAuthGrant used to parse JSON for an access token from UAA server

Jump to

Keyboard shortcuts

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