helpers

package
v1.13.4-0...-6675bf8 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2020 License: CC0-1.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// InviteEmailTemplate is the template key for the invite email.
	InviteEmailTemplate = "INVITE_EMAIL_TEMPLATE"
	// IndexTemplate is the template key for the index.html.
	IndexTemplate = "INDEX_HTML_TEMPLATE"
)

Variables

View Source
var (
	// ClientIDEnvVar is the environment variable key that represents the registered
	// Client ID for this web app.
	ClientIDEnvVar = "CONSOLE_CLIENT_ID"
	// ClientSecretEnvVar is the environment variable key that represents the
	// Client Secret associated with the registered Client ID for this web app.
	ClientSecretEnvVar = "CONSOLE_CLIENT_SECRET"
	// HostnameEnvVar is the environment variable key that represents the hostname
	// of this web app.
	HostnameEnvVar = "CONSOLE_HOSTNAME"
	// LoginURLEnvVar is the environment variable key that represents the
	// base login URL endpoint that this app should use to authenticate users.
	LoginURLEnvVar = "CONSOLE_LOGIN_URL"
	// UAAURLEnvVar is the environment variable key that represents the
	//  base uaa URL endpoint that this app should use to get tokens.
	UAAURLEnvVar = "CONSOLE_UAA_URL"
	// APIURLEnvVar is the environment variable key that represents the
	// base api URL endpoint that this app should use to access Cloud Foundry data.
	APIURLEnvVar = "CONSOLE_API_URL"
	// LogURLEnvVar is the environment variable key that represents the
	// endpoint to the loggregator.
	LogURLEnvVar = "CONSOLE_LOG_URL"
	// PProfEnabledEnvVar is the environment variable key that represents if the pprof routes
	// should be enabled. If no value is specified, it is assumed to be false.
	PProfEnabledEnvVar = "PPROF_ENABLED"
	// BuildInfoEnvVar is the environment variable key that represents the particular build number
	BuildInfoEnvVar = "BUILD_INFO"
	// NewRelicLicenseEnvVar is the New Relic License key so it can collect data.
	NewRelicLicenseEnvVar = "CONSOLE_NEW_RELIC_LICENSE"
	// SecureCookiesEnvVar is set to true or 1, then set the Secure flag be set on session coookies
	SecureCookiesEnvVar = "SECURE_COOKIES"
	// LocalCFEnvVar is set to true or 1, then we indicate that we are using a local CF env.
	LocalCFEnvVar = "LOCAL_CF"
	// TemplatesPathEnvVar is the path to the templates directory.
	TemplatesPathEnvVar = "TEMPLATES_PATH"
	// SMTPHostEnvVar is SMTP host for UAA invites
	SMTPHostEnvVar = "SMTP_HOST"
	// SMTPPortEnvVar is SMTP post for UAA invites
	SMTPPortEnvVar = "SMTP_PORT"
	// SMTPUserEnvVar is SMTP user for UAA invites
	SMTPUserEnvVar = "SMTP_USER"
	// SMTPPassEnvVar is SMTP password for UAA invites
	SMTPPassEnvVar = "SMTP_PASS"
	// SMTPFromEnvVar is SMTP from address for UAA invites
	SMTPFromEnvVar = "SMTP_FROM"
	// SMTPCertEnvVar is cert for TLS connection
	SMTPCertEnvVar = "SMTP_CERT"
	// TICSecretEnvVar is the shared secret with CF API proxy for forwarding client IPs
	TICSecretEnvVar = "TIC_SECRET"
	// CSRFKeyEnvVar is used for CSRF token. Must be 32 bytes, hex-encoded, e.g. openssl rand -hex 32
	CSRFKeyEnvVar = "CSRF_KEY"
	// SessionAuthenticationEnvVar used to sign user sessions. Must be 32 or 64 hex-encoded bytes, e.g. openssl rand -hex 64
	SessionAuthenticationEnvVar = "SESSION_AUTHENTICATION_KEY"
	// SessionEncryptionEnvVar used to encrypt user sessions. Must be 16, 24 or 32 hex-encoded bytes, e.g. openssl rand -hex 32
	SessionEncryptionEnvVar = "SESSION_ENCRYPTION_KEY"
)
View Source
var TimeoutConstant = time.Second * 20

TimeoutConstant is a constant which holds how long any incoming request should wait until we timeout. This is useful as some calls from the Go backend to the external API may take a long time. If the user decides to refresh or if the client is polling, multiple requests might build up. This timecaps them.

Functions

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. Borrowed from https://elithrar.github.io/article/generating-secure-random-numbers-crypto-rand/

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. Borrowed from https://elithrar.github.io/article/generating-secure-random-numbers-crypto-rand/

func GetValidToken

func GetValidToken(req *http.Request, rw http.ResponseWriter, settings *Settings) *oauth2.Token

GetValidToken is a helper function that returns a token struct only if it finds a non expired token for the session.

Types

type Settings

type Settings struct {
	// OAuthConfig is the OAuth client with all the parameters to talk with CF's UAA OAuth Provider.
	OAuthConfig *oauth2.Config
	// Console API
	ConsoleAPI string
	// Login URL - used to redirect users to the logout page
	LoginURL string
	// Sessions is the session store for all connected users.
	Sessions sessions.Store
	// Generate secure random state
	StateGenerator func() (string, error)
	// UAA API
	UaaURL string
	// Log API
	LogURL string
	// TemplatesPath is the path to the templates directory.
	TemplatesPath string
	// High Privileged OauthConfig
	HighPrivilegedOauthConfig *clientcredentials.Config
	// A flag to indicate whether profiling should be included (debug purposes).
	PProfEnabled bool
	// Build Info
	BuildInfo string
	// Set the secure flag on session cookies
	SecureCookies bool
	// Inidicates if targeting a local CF environment.
	LocalCF bool
	// URL where this app is hosted
	AppURL string
	// SMTP host for UAA invites
	SMTPHost string
	// SMTP post for UAA invites
	SMTPPort string
	// SMTP user for UAA invites
	SMTPUser string
	// SMTP password for UAA invites
	SMTPPass string
	// SMTP from address for UAA invites
	SMTPFrom string
	// SMTPCert is x509 TLS cert
	SMTPCert string
	// Shared secret with CF API proxy
	TICSecret string
	// CSRFKey used for gorilla CSRF validation
	CSRFKey []byte
}

Settings is the object to hold global values and objects for the service.

func (*Settings) CreateContext

func (s *Settings) CreateContext() context.Context

CreateContext returns a new context to be used for http connections.

func (*Settings) InitSettings

func (s *Settings) InitSettings(envVars *env.VarSet) (retErr error)

InitSettings attempts to populate all the fields of the Settings struct. It will return an error if it fails, otherwise it returns nil for success.

type Templates

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

Templates serve as a mapping to various templates. Each entry can be a compilation of multiple files mapped to a string entry. This works if we ever want to use the .define blocks which are good for creating a main template with swappable content. Similar to https://hackernoon.com/golang-template-2-template-composition-and-how-to-organize-template-files-4cb40bcdf8f6

func InitTemplates

func InitTemplates(basePath string) (*Templates, error)

InitTemplates will try to parse the templates.

func (*Templates) GetIndex

func (t *Templates) GetIndex(rw io.Writer, csrfToken, gaTrackingID, newRelicID,
	newRelicBrowserLicenseKey string) error

GetIndex gets the filled in index.html

func (*Templates) GetInviteEmail

func (t *Templates) GetInviteEmail(rw io.Writer, url string) error

GetInviteEmail gets the filled in invite email template.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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